GoodsAuto.cs 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720
  1. 
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using Curtain.DataAccess;
  7. using Curtain.Extension.ExObjectConvert;
  8. using Curtain.Extension.ExSystemData;
  9. using Curtain.Framework.Json;
  10. using Curtain.Helpers;
  11. using Curtain.Log;
  12. using Curtain.Net.Sockets.PLC;
  13. using Curtain.Net.Sockets.PLC.Model;
  14. using Curtain.Net.Sockets.PLC.Model.Siemens;
  15. using PLC_S.Proxy;
  16. namespace PLC_S.ServerModel
  17. {
  18. /// <summary>
  19. /// 自动返回产品型号等信息 xuwei add 2022-01-10
  20. /// </summary>
  21. public class GoodsAuto : SocketServer<SimpleSocketServerModel>, IShowFormLog, IWindowsServer
  22. {
  23. public Dictionary<string, PLC_S_GA> PLC_FLAGS = new Dictionary<string, PLC_S_GA>();
  24. public const string M_NAME = "GA";
  25. private MES_S _mes_s = null;
  26. private readonly Logger logger = Logger.CreateLogger(M_NAME);
  27. private readonly LogInfo logger_t = new LogInfo();
  28. private readonly LogInfo logger_e = new LogInfo();
  29. private bool _S_STOP = false;
  30. public int Interval
  31. {
  32. get;
  33. set;
  34. }
  35. public string EPTS_CODE
  36. {
  37. get;
  38. set;
  39. }
  40. public GoodsAuto()
  41. {
  42. logger.FileExistDays = 30;
  43. logger.FilePrefix = "";
  44. logger.FileSuffix = M_NAME;
  45. logger.LevelOneFile = true;
  46. logger.FileNameWithoutDate = true;
  47. logger_t.SubFolderFormat = "<name>";
  48. logger_t.FileExistDays = 30;
  49. logger_t.LevelOneFile = true;
  50. logger_e.FileExistDays = 10;
  51. this.Model.FormatType = CommandFormatType.StartStopChar;
  52. this.ServerStarting += ServerSocket_ServerStarting;
  53. this.ServerStarted += ServerSocket_ServerStarted;
  54. this.ServerStoping += ServerSocket_ServerStoping;
  55. this.ServerStoped += ServerSocket_ServerStoped;
  56. this.ServerMessage += ServerSocket_ServerMessage;
  57. this.Received += ServerSocket_Received;
  58. _mes_s = MES_S.Get();
  59. }
  60. #region Server
  61. public IFormLogShow FormLogShow
  62. {
  63. get;
  64. set;
  65. }
  66. private void ServerSocket_ServerStarting(object sender, CancelEventArgs e)
  67. {
  68. try
  69. {
  70. _S_STOP = false;
  71. logger.OutputTrace($"{M_NAME}_ServerStarting");
  72. }
  73. catch { }
  74. }
  75. private void ServerSocket_ServerStarted(object sender, EventArgs e)
  76. {
  77. try
  78. {
  79. _S_STOP = false;
  80. logger.OutputTrace($"{M_NAME}_ServerStarted");
  81. }
  82. catch { }
  83. }
  84. private void ServerSocket_ServerStoping(object sender, CancelEventArgs e)
  85. {
  86. try
  87. {
  88. _S_STOP = false;
  89. logger.OutputTrace($"{M_NAME}_ServerStoping");
  90. }
  91. catch { }
  92. }
  93. private void ServerSocket_ServerStoped(object sender, EventArgs e)
  94. {
  95. try
  96. {
  97. _S_STOP = false;
  98. logger.OutputTrace($"{M_NAME}_ServerStoped");
  99. }
  100. catch { }
  101. }
  102. private void ServerSocket_ServerMessage(object sender, ServerMessageEventArgs e)
  103. {
  104. try
  105. {
  106. _S_STOP = false;
  107. string message = e.ToString();
  108. string cip = e?.Client?.IP;
  109. if (e.Type == ServerMessageType.Debug)
  110. {
  111. Logger.Debug(message, $"{M_NAME}-T[{cip}]", logger_t);
  112. }
  113. if (e.Type == ServerMessageType.Error)
  114. {
  115. Logger.Error(e.Exception, message, $"{M_NAME}-E[{cip}]", logger_e);
  116. }
  117. if (e.Type == ServerMessageType.Trace)
  118. {
  119. Logger.Trace(message, $"{M_NAME}-T[{cip}]", logger_t);
  120. }
  121. if (e.Type == ServerMessageType.Warning)
  122. {
  123. Logger.Warn(message, $"{M_NAME}-E[{cip}]", logger_e);
  124. }
  125. FormLogShow?.ShowLog("ServerMessage=" + message);
  126. }
  127. catch { }
  128. }
  129. #endregion
  130. /// <summary>
  131. /// 返回产品型号
  132. /// </summary>
  133. /// <param name="sender"></param>
  134. /// <param name="e"></param>
  135. private void ServerSocket_Received(object sender, ReceiveSession e)
  136. {
  137. PLC_S_GA plc_s = null;
  138. string cIP = e?.Client?.IP;
  139. string logKeyT = $"{M_NAME}-T[{cIP}]";
  140. string logKeyE = $"{M_NAME}-E[{cIP}]";
  141. _S_STOP = false;
  142. SocketClient<SiemensS7_1200Model> plc = null;
  143. Logger LoggerT = null;
  144. try
  145. {
  146. LoggerT = Logger.CreateLogger(logKeyT, logger_t);
  147. lock (LoggerT)
  148. {
  149. LoggerT.BeginTracking();
  150. string outputMessage = e.ToString();
  151. Logger.Trace(outputMessage, logKeyT, logger_t);
  152. FormLogShow?.ShowLog(outputMessage);
  153. #region 【必须】判断接收数据是否为空
  154. if (string.IsNullOrWhiteSpace(e.Content))
  155. {
  156. outputMessage = "接收数据为空";
  157. Logger.Warn(outputMessage, logKeyT, logger_t);
  158. Logger.Warn(outputMessage, logKeyE, logger_e);
  159. FormLogShow?.ShowLog(outputMessage);
  160. return;
  161. }
  162. #endregion
  163. #region 【必须】判断接收设备代码是否为空
  164. outputMessage = e.Content;
  165. Logger.Trace(outputMessage, logKeyT, logger_t);
  166. FormLogShow?.ShowLog(outputMessage);
  167. string[] c = e.Content.Split('#');
  168. string flag = null;
  169. if (c.Length > 0)
  170. {
  171. flag = c[0];
  172. }
  173. string barCode = null;
  174. if (c.Length > 1)
  175. {
  176. barCode = c[1];
  177. }
  178. if (string.IsNullOrWhiteSpace(flag))
  179. {
  180. outputMessage = $"[{e.Content}]接收设备代码为空";
  181. Logger.Warn(outputMessage, logKeyT, logger_t);
  182. Logger.Warn(outputMessage, logKeyE, logger_e);
  183. FormLogShow?.ShowLog(outputMessage);
  184. return;
  185. }
  186. #endregion
  187. #region 【必须】读取INI配置文件
  188. plc_s = GetPLC_S_GA(flag, e, logKeyE);
  189. if (plc_s == null)
  190. {
  191. outputMessage = $"[{e.Content}]设备代码[{flag}]未找到ini配置或有错误";
  192. Logger.Error(null, outputMessage, logKeyT, logger_t);
  193. Logger.Error(null, outputMessage, logKeyE, logger_e);
  194. FormLogShow?.ShowLog(outputMessage);
  195. return;
  196. }
  197. #endregion
  198. #region 【必须】建立PLC连接
  199. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  200. {
  201. outputMessage = $"[{e.Content}]PLC_Connect={JsonHelper.FromObject(plc_s)}";
  202. Logger.Trace(outputMessage, logKeyT, logger_t);
  203. FormLogShow?.ShowLog(outputMessage);
  204. plc = new SocketClient<SiemensS7_1200Model>();
  205. plc.Connect(plc_s.PLC_IP, plc_s.PLC_PORT);
  206. }
  207. else
  208. {
  209. Logger.Trace("PLC地址未设置,测试数据使用!", logKeyT, logger_t);
  210. }
  211. PLCResult p_r;
  212. #endregion
  213. #region 【必须】判断接收条码格式是否正确
  214. if (string.IsNullOrWhiteSpace(barCode) ||
  215. barCode == "0" ||
  216. barCode.Length != 11 ||
  217. barCode.StartsWith("0") ||
  218. barCode.StartsWith("ERROR")
  219. )
  220. {
  221. outputMessage = $"[{e.Content}]接收条码格式错误";
  222. Logger.Warn(outputMessage, logKeyT, logger_t);
  223. Logger.Warn(outputMessage, logKeyE, logger_e);
  224. FormLogShow?.ShowLog(outputMessage);
  225. SendCode(plc_s, e, logKeyT, logKeyE, plc, 2);
  226. return;
  227. }
  228. #endregion
  229. #region 【可选】产品型号写入
  230. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSCODE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSCODE_CODENUM))
  231. {
  232. string goodsCode = GetGoodsCode(barCode, e, logKeyE);
  233. if (goodsCode == null)
  234. {
  235. outputMessage = $"[{e.Content}]此条码[{barCode}]不存在";
  236. Logger.Warn(outputMessage, logKeyT, logger_t);
  237. Logger.Warn(outputMessage, logKeyE, logger_e);
  238. FormLogShow?.ShowLog(outputMessage);
  239. if (!string.IsNullOrEmpty(plc_s.PLC_IP)) SendCode(plc_s, e, logKeyT, logKeyE, plc, 2);
  240. return;
  241. }
  242. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  243. {
  244. outputMessage = $"[{e.Content}]SET_GOODSCODE=[{goodsCode}]{plc_s.PLC_GOODSCODE_CODE + plc_s.PLC_GOODSCODE_CODENUM}";
  245. Logger.Trace(outputMessage, logKeyT, logger_t);
  246. FormLogShow?.ShowLog(outputMessage);
  247. p_r = plc.Write<string>(plc_s.PLC_GOODSCODE_CODE, plc_s.PLC_GOODSCODE_CODENUM, goodsCode);
  248. outputMessage = $"[{e.Content}]END_GOODSCODE=[{p_r}]{plc_s.PLC_GOODSCODE_CODE + plc_s.PLC_GOODSCODE_CODENUM}";
  249. Logger.Trace(outputMessage, logKeyT, logger_t);
  250. FormLogShow?.ShowLog(outputMessage);
  251. }
  252. else
  253. {
  254. outputMessage = $"[{e.Content}]产品型号=[{goodsCode}]";
  255. Logger.Trace(outputMessage, logKeyT, logger_t);
  256. FormLogShow?.ShowLog(outputMessage);
  257. }
  258. }
  259. #endregion
  260. #region 【可选】产品型号代码写入
  261. if (!string.IsNullOrEmpty(plc_s.PLC_SEATCOVER_CODE) && !string.IsNullOrEmpty(plc_s.PLC_SEATCOVER_CODENUM))
  262. {
  263. string intCode = GetSeatCoverCode(barCode, e, logKeyE);
  264. if (intCode == null)
  265. {
  266. outputMessage = $"[{e.Content}]此条码[{barCode}]不存在";
  267. Logger.Warn(outputMessage, logKeyT, logger_t);
  268. Logger.Warn(outputMessage, logKeyE, logger_e);
  269. FormLogShow?.ShowLog(outputMessage);
  270. if (!string.IsNullOrEmpty(plc_s.PLC_IP)) SendCode(plc_s, e, logKeyT, logKeyE, plc, 2);
  271. return;
  272. }
  273. if (string.IsNullOrWhiteSpace(intCode))
  274. {
  275. outputMessage = $"[{e.Content}]此条码[{barCode}]未设置型号代码";
  276. Logger.Error(null, outputMessage, logKeyT, logger_t);
  277. Logger.Error(null, outputMessage, logKeyE, logger_e);
  278. FormLogShow?.ShowLog(outputMessage);
  279. if (!string.IsNullOrEmpty(plc_s.PLC_IP)) SendCode(plc_s, e, logKeyT, logKeyE, plc, 2);
  280. return;
  281. }
  282. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  283. {
  284. outputMessage = $"[{e.Content}]SET_SEATCOVER=[{intCode}]{plc_s.PLC_SEATCOVER_CODE + plc_s.PLC_SEATCOVER_CODENUM}";
  285. Logger.Trace(outputMessage, logKeyT, logger_t);
  286. FormLogShow?.ShowLog(outputMessage);
  287. p_r = plc.Write<short>(plc_s.PLC_SEATCOVER_CODE, plc_s.PLC_SEATCOVER_CODENUM, (short)(intCode.ToInt32()));
  288. outputMessage = $"[{e.Content}]END_SEATCOVER=[{p_r}]{plc_s.PLC_SEATCOVER_CODE + plc_s.PLC_SEATCOVER_CODENUM}";
  289. Logger.Trace(outputMessage, logKeyT, logger_t);
  290. FormLogShow?.ShowLog(outputMessage);
  291. }
  292. else
  293. {
  294. outputMessage = $"[{e.Content}]产品型号=[{intCode}]";
  295. Logger.Trace(outputMessage, logKeyT, logger_t);
  296. FormLogShow?.ShowLog(outputMessage);
  297. }
  298. }
  299. #endregion
  300. #region 【可选】产品类型写入
  301. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSTYPE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSTYPE_CODENUM))
  302. {
  303. Int16 goodsType = Convert.ToInt16(GetGoodsType(barCode, e, logKeyT));
  304. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  305. {
  306. outputMessage = $"[{e.Content}]SET_GoodsType=[{goodsType}]{plc_s.PLC_GOODSTYPE_CODE + plc_s.PLC_GOODSTYPE_CODENUM}";
  307. Logger.Trace(outputMessage, logKeyT, logger_t);
  308. FormLogShow?.ShowLog(outputMessage);
  309. p_r = plc?.Write<short>(plc_s.PLC_GOODSTYPE_CODE, plc_s.PLC_GOODSTYPE_CODENUM, goodsType);
  310. outputMessage = $"[{e.Content}]END_GoodsType=[{p_r.ToString()}]{plc_s.PLC_GOODSTYPE_CODE + plc_s.PLC_GOODSTYPE_CODENUM}";
  311. Logger.Trace(outputMessage, logKeyT, logger_t);
  312. FormLogShow?.ShowLog(outputMessage);
  313. }
  314. else
  315. {
  316. outputMessage = $"[{e.Content}]产品类型=[{goodsType}]";
  317. Logger.Trace(outputMessage, logKeyT, logger_t);
  318. FormLogShow?.ShowLog(outputMessage);
  319. }
  320. }
  321. #endregion
  322. #region 【可选】产品条码写入(字符串)
  323. if (!string.IsNullOrEmpty(plc_s.PLC_BARCODE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_BARCODE_CODENUM))
  324. {
  325. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  326. {
  327. outputMessage = $"[{e.Content}]SET_BarCode=[{barCode}]{plc_s.PLC_BARCODE_CODE + plc_s.PLC_BARCODE_CODENUM}";
  328. Logger.Trace(outputMessage, logKeyT, logger_t);
  329. FormLogShow?.ShowLog(outputMessage);
  330. p_r = plc.Write<string>(plc_s.PLC_BARCODE_CODE, plc_s.PLC_BARCODE_CODENUM, barCode);
  331. outputMessage = $"[{e.Content}]END_BarCode=[{p_r}]{plc_s.PLC_BARCODE_CODE + plc_s.PLC_BARCODE_CODENUM}";
  332. Logger.Trace(outputMessage, logKeyT, logger_t);
  333. FormLogShow?.ShowLog(outputMessage);
  334. }
  335. else
  336. {
  337. outputMessage = $"[{e.Content}]产品条码=[{barCode}]";
  338. Logger.Trace(outputMessage, logKeyT, logger_t);
  339. FormLogShow?.ShowLog(outputMessage);
  340. }
  341. }
  342. #endregion
  343. #region 【可选】产品条码写入(长数字)
  344. if (!string.IsNullOrEmpty(plc_s.PLC_BARCODENUM_CODE) && !string.IsNullOrEmpty(plc_s.PLC_BARCODENUM_CODENUM))
  345. {
  346. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  347. {
  348. outputMessage = $"[{e.Content}]SET_BarCodeNum=[{barCode}]{plc_s.PLC_BARCODENUM_CODE + plc_s.PLC_BARCODENUM_CODENUM}";
  349. Logger.Trace(outputMessage, logKeyT, logger_t);
  350. FormLogShow?.ShowLog(outputMessage);
  351. p_r = plc.Write<float>(plc_s.PLC_BARCODENUM_CODE, plc_s.PLC_BARCODENUM_CODENUM, Convert.ToSingle(barCode));
  352. outputMessage = $"[{e.Content}]END_BarCodeNum=[{p_r}]{plc_s.PLC_BARCODENUM_CODE + plc_s.PLC_BARCODENUM_CODENUM}";
  353. Logger.Trace(outputMessage, logKeyT, logger_t);
  354. FormLogShow?.ShowLog(outputMessage);
  355. }
  356. else
  357. {
  358. outputMessage = $"[{e.Content}]产品条码=[{barCode}]";
  359. Logger.Trace(outputMessage, logKeyT, logger_t);
  360. FormLogShow?.ShowLog(outputMessage);
  361. }
  362. }
  363. #endregion
  364. #region 【可选】半检返工标识写入
  365. if (!string.IsNullOrEmpty(plc_s.PLC_SEMIREWORK_CODE) && !string.IsNullOrEmpty(plc_s.PLC_SEMIREWORK_CODENUM))
  366. {
  367. Int16 goodsType = Convert.ToInt16(GetSemiReWork(barCode, e, logKeyT));
  368. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  369. {
  370. outputMessage = $"[{e.Content}]SET_SemiRework=[{goodsType}]{plc_s.PLC_SEMIREWORK_CODE + plc_s.PLC_SEMIREWORK_CODENUM}";
  371. Logger.Trace(outputMessage, logKeyT, logger_t);
  372. FormLogShow?.ShowLog(outputMessage);
  373. p_r = plc?.Write<short>(plc_s.PLC_SEMIREWORK_CODE, plc_s.PLC_SEMIREWORK_CODENUM, goodsType);
  374. outputMessage = $"[{e.Content}]END_SemiRework=[{p_r.ToString()}]{plc_s.PLC_SEMIREWORK_CODE + plc_s.PLC_SEMIREWORK_CODENUM}";
  375. Logger.Trace(outputMessage, logKeyT, logger_t);
  376. FormLogShow?.ShowLog(outputMessage);
  377. }
  378. else
  379. {
  380. outputMessage = $"[{e.Content}]半检返工标识=[{goodsType}]";
  381. Logger.Trace(outputMessage, logKeyT, logger_t);
  382. FormLogShow?.ShowLog(outputMessage);
  383. }
  384. }
  385. #endregion
  386. #region 【可选】产品等级写入
  387. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSLEVEL_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSLEVEL_CODENUM))
  388. {
  389. Int16 goodsLevel = Convert.ToInt16(GetGoodsLevel(barCode, e, logKeyT));
  390. //如果有裸瓷标识,那么产品等级区分是否为裸瓷正品,裸瓷标识1+正品=91;裸瓷+副品=92 。非裸瓷为原逻辑
  391. if (!string.IsNullOrEmpty(plc_s.PLC_LUOCI) && plc_s.PLC_LUOCI == "1")
  392. {
  393. Int16 luoci = Convert.ToInt16(GetLuociFlag(barCode, e, logKeyT));
  394. if (luoci == 1 && goodsLevel == 4)
  395. {
  396. goodsLevel = 91;
  397. }
  398. if (luoci == 1 && goodsLevel == 5)
  399. {
  400. goodsLevel = 92;
  401. }
  402. }
  403. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  404. {
  405. outputMessage = $"[{e.Content}]SET_GoodsLevel=[{goodsLevel}]{plc_s.PLC_GOODSLEVEL_CODE + plc_s.PLC_GOODSLEVEL_CODENUM}";
  406. Logger.Trace(outputMessage, logKeyT, logger_t);
  407. FormLogShow?.ShowLog(outputMessage);
  408. p_r = plc?.Write<short>(plc_s.PLC_GOODSLEVEL_CODE, plc_s.PLC_GOODSLEVEL_CODENUM, goodsLevel);
  409. outputMessage = $"[{e.Content}]END_GoodsLevel=[{p_r.ToString()}]{plc_s.PLC_GOODSLEVEL_CODE + plc_s.PLC_GOODSLEVEL_CODENUM}";
  410. Logger.Trace(outputMessage, logKeyT, logger_t);
  411. FormLogShow?.ShowLog(outputMessage);
  412. }
  413. else
  414. {
  415. outputMessage = $"[{e.Content}]产品等级=[{goodsLevel}]";
  416. Logger.Trace(outputMessage, logKeyT, logger_t);
  417. FormLogShow?.ShowLog(outputMessage);
  418. }
  419. }
  420. #endregion
  421. #region 【可选】半检补土(适用于官塘)
  422. if (!string.IsNullOrEmpty(plc_s.PLC_SEMIREPAIR_CODE) && !string.IsNullOrEmpty(plc_s.PLC_SEMIREPAIR_CODENUM))
  423. {
  424. Int16 semiRepair = Convert.ToInt16(GetSemiRepair(barCode, e, logKeyT));
  425. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  426. {
  427. outputMessage = $"[{e.Content}]SET_SemiRepair=[{semiRepair}]{plc_s.PLC_SEMIREPAIR_CODE + plc_s.PLC_SEMIREPAIR_CODENUM}";
  428. Logger.Trace(outputMessage, logKeyT, logger_t);
  429. FormLogShow?.ShowLog(outputMessage);
  430. p_r = plc?.Write<short>(plc_s.PLC_SEMIREPAIR_CODE, plc_s.PLC_SEMIREPAIR_CODENUM, semiRepair);
  431. outputMessage = $"[{e.Content}]END_SemiRepair=[{p_r.ToString()}]{plc_s.PLC_SEMIREPAIR_CODE + plc_s.PLC_SEMIREPAIR_CODENUM}";
  432. Logger.Trace(outputMessage, logKeyT, logger_t);
  433. FormLogShow?.ShowLog(outputMessage);
  434. }
  435. else
  436. {
  437. outputMessage = $"[{e.Content}]半检补土=[{semiRepair}]";
  438. Logger.Trace(outputMessage, logKeyT, logger_t);
  439. FormLogShow?.ShowLog(outputMessage);
  440. }
  441. }
  442. #endregion
  443. #region 【可选】产品等级写入(重烧过的产品写6,非重烧的写4)(适用于官塘)
  444. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSLEVEL2_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSLEVEL2_CODENUM))
  445. {
  446. Int16 goodsLevel = Convert.ToInt16(GetGoodsLevel(barCode, e, logKeyT));
  447. //如果判定为重烧不算重烧品,暂时当副品,重烧过才真正算重烧
  448. if (goodsLevel == 6) goodsLevel = 5;
  449. goodsLevel = Convert.ToInt16(GetAutoFireID(barCode, goodsLevel.ToString(), "6", e, logKeyT));
  450. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  451. {
  452. outputMessage = $"[{e.Content}]SET_GoodsLevel2=[{goodsLevel}]{plc_s.PLC_GOODSLEVEL2_CODE + plc_s.PLC_GOODSLEVEL2_CODENUM}";
  453. Logger.Trace(outputMessage, logKeyT, logger_t);
  454. FormLogShow?.ShowLog(outputMessage);
  455. p_r = plc?.Write<short>(plc_s.PLC_GOODSLEVEL2_CODE, plc_s.PLC_GOODSLEVEL2_CODENUM, goodsLevel);
  456. outputMessage = $"[{e.Content}]END_GoodsLevel2=[{p_r.ToString()}]{plc_s.PLC_GOODSLEVEL2_CODE + plc_s.PLC_GOODSLEVEL2_CODENUM}";
  457. Logger.Trace(outputMessage, logKeyT, logger_t);
  458. FormLogShow?.ShowLog(outputMessage);
  459. }
  460. else
  461. {
  462. outputMessage = $"[{e.Content}]产品等级=[{goodsLevel}]";
  463. Logger.Trace(outputMessage, logKeyT, logger_t);
  464. FormLogShow?.ShowLog(outputMessage);
  465. }
  466. }
  467. #endregion
  468. #region 【可选】产品重烧标识写入
  469. if (!string.IsNullOrEmpty(plc_s.PLC_ISREFIRE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_ISREFIRE_CODENUM))
  470. {
  471. Int16 isRefire = Convert.ToInt16(GetAutoFireID(barCode, "1", "6", e, logKeyT));
  472. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  473. {
  474. outputMessage = $"[{e.Content}]SET_IsRefire=[{isRefire}]{plc_s.PLC_ISREFIRE_CODE + plc_s.PLC_ISREFIRE_CODENUM}";
  475. Logger.Trace(outputMessage, logKeyT, logger_t);
  476. FormLogShow?.ShowLog(outputMessage);
  477. p_r = plc?.Write<short>(plc_s.PLC_ISREFIRE_CODE, plc_s.PLC_ISREFIRE_CODENUM, isRefire);
  478. outputMessage = $"[{e.Content}]END_IsRefire=[{p_r.ToString()}]{plc_s.PLC_ISREFIRE_CODE + plc_s.PLC_ISREFIRE_CODENUM}";
  479. Logger.Trace(outputMessage, logKeyT, logger_t);
  480. FormLogShow?.ShowLog(outputMessage);
  481. }
  482. else
  483. {
  484. outputMessage = $"[{e.Content}]产品重烧=[{isRefire}]";
  485. Logger.Trace(outputMessage, logKeyT, logger_t);
  486. FormLogShow?.ShowLog(outputMessage);
  487. }
  488. }
  489. #endregion
  490. #region 【可选】质量登记返修写入(官塘厂)
  491. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSREPAIR_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSREPAIR_CODENUM))
  492. {
  493. Int16 goodsRepair = Convert.ToInt16(GetGoodsRepair(barCode, e, logKeyT));
  494. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  495. {
  496. outputMessage = $"[{e.Content}]SET_GoodsLevel=[{goodsRepair}]{plc_s.PLC_GOODSREPAIR_CODE + plc_s.PLC_GOODSREPAIR_CODENUM}";
  497. Logger.Trace(outputMessage, logKeyT, logger_t);
  498. FormLogShow?.ShowLog(outputMessage);
  499. p_r = plc?.Write<short>(plc_s.PLC_GOODSREPAIR_CODE, plc_s.PLC_GOODSREPAIR_CODENUM, goodsRepair);
  500. outputMessage = $"[{e.Content}]END_GoodsLevel=[{p_r.ToString()}]{plc_s.PLC_GOODSREPAIR_CODE + plc_s.PLC_GOODSREPAIR_CODENUM}";
  501. Logger.Trace(outputMessage, logKeyT, logger_t);
  502. FormLogShow?.ShowLog(outputMessage);
  503. }
  504. else
  505. {
  506. outputMessage = $"[{e.Content}]返修=[{goodsRepair}]";
  507. Logger.Trace(outputMessage, logKeyT, logger_t);
  508. FormLogShow?.ShowLog(outputMessage);
  509. }
  510. }
  511. #endregion
  512. #region 【可选】智能连体重烧写入,智能重烧253,连体重烧254,其他返回立库配置代码,未配置返回252(官塘厂)
  513. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSTYPEISREFIRE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSTYPEISREFIRE_CODENUM))
  514. {
  515. //产品代码读取
  516. string intCode = GetWareHouse(barCode, e, logKeyE);
  517. if (intCode == "") intCode = "252";
  518. //2022-10-13 xuwei modify
  519. /* 取消重烧分类(智能连体重烧写入,智能重烧253,连体重烧254)
  520. //重烧识别读取
  521. Int16 isRefire = Convert.ToInt16(GetAutoFireID(barCode, "1", "6", e, logKeyT));
  522. //重烧产品返回 智能253,连体254
  523. if (isRefire == 6)
  524. {
  525. //智能连体读取
  526. Int16 goodsType = Convert.ToInt16(GetGoodsType(barCode, e, logKeyT));
  527. if (goodsType == 1) intCode = "253";
  528. if (goodsType == 2) intCode = "254";
  529. }
  530. */
  531. //写入智能连体重烧标识
  532. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  533. {
  534. outputMessage = $"[{e.Content}]SET_GOODSTYPEISREFIRE=[{intCode}]{plc_s.PLC_GOODSTYPEISREFIRE_CODE + plc_s.PLC_GOODSTYPEISREFIRE_CODENUM}";
  535. Logger.Trace(outputMessage, logKeyT, logger_t);
  536. FormLogShow?.ShowLog(outputMessage);
  537. p_r = plc.Write<short>(plc_s.PLC_GOODSTYPEISREFIRE_CODE, plc_s.PLC_GOODSTYPEISREFIRE_CODENUM, (short)(intCode.ToInt32()));
  538. outputMessage = $"[{e.Content}]END_GOODSTYPEISREFIRE=[{p_r}]{plc_s.PLC_GOODSTYPEISREFIRE_CODE + plc_s.PLC_GOODSTYPEISREFIRE_CODENUM}";
  539. Logger.Trace(outputMessage, logKeyT, logger_t);
  540. FormLogShow?.ShowLog(outputMessage);
  541. }
  542. else
  543. {
  544. outputMessage = $"[{e.Content}]智能连体重烧=[{intCode}]";
  545. Logger.Trace(outputMessage, logKeyT, logger_t);
  546. FormLogShow?.ShowLog(outputMessage);
  547. }
  548. }
  549. #endregion
  550. #region 【可选】产品缺陷类别写入
  551. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSDEFECTTYPE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSDEFECTTYPE_CODENUM))
  552. {
  553. Int16 goodsDefectType = Convert.ToInt16(GetDefectTypeId(barCode, e, logKeyT));
  554. //如果是重烧产品写入 16 代替产品缺陷类别
  555. //goodsDefectType = Convert.ToInt16(GetAutoFireID(barCode, goodsDefectType.ToString(), "16", e, logKeyT));
  556. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  557. {
  558. outputMessage = $"[{e.Content}]SET_DefectType=[{goodsDefectType}]{plc_s.PLC_GOODSDEFECTTYPE_CODE + plc_s.PLC_GOODSDEFECTTYPE_CODENUM}";
  559. Logger.Trace(outputMessage, logKeyT, logger_t);
  560. FormLogShow?.ShowLog(outputMessage);
  561. p_r = plc?.Write<short>(plc_s.PLC_GOODSDEFECTTYPE_CODE, plc_s.PLC_GOODSDEFECTTYPE_CODENUM, goodsDefectType);
  562. outputMessage = $"[{e.Content}]END_DefectType=[{p_r.ToString()}]{plc_s.PLC_GOODSDEFECTTYPE_CODE + plc_s.PLC_GOODSDEFECTTYPE_CODENUM}";
  563. Logger.Trace(outputMessage, logKeyT, logger_t);
  564. FormLogShow?.ShowLog(outputMessage);
  565. }
  566. else
  567. {
  568. outputMessage = $"[{e.Content}]缺陷类别=[{goodsDefectType}]";
  569. Logger.Trace(outputMessage, logKeyT, logger_t);
  570. FormLogShow?.ShowLog(outputMessage);
  571. }
  572. }
  573. #endregion
  574. #region 【可选】成型工号写入
  575. if (!string.IsNullOrEmpty(plc_s.PLC_GROUTINGUSER_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GROUTINGUSER_CODENUM))
  576. {
  577. Int16 groutinguserCode = Convert.ToInt16(GetGroutingUserCode(barCode, e, logKeyT));
  578. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  579. {
  580. outputMessage = $"[{e.Content}]SET_GROUTINGUSER=[{groutinguserCode}]{plc_s.PLC_GROUTINGUSER_CODE + plc_s.PLC_GROUTINGUSER_CODENUM}";
  581. Logger.Trace(outputMessage, logKeyT, logger_t);
  582. FormLogShow?.ShowLog(outputMessage);
  583. p_r = plc?.Write<short>(plc_s.PLC_GROUTINGUSER_CODE, plc_s.PLC_GROUTINGUSER_CODENUM, groutinguserCode);
  584. outputMessage = $"[{e.Content}]END_GROUTINGUSER=[{p_r.ToString()}]{plc_s.PLC_GROUTINGUSER_CODE + plc_s.PLC_GROUTINGUSER_CODENUM}";
  585. Logger.Trace(outputMessage, logKeyT, logger_t);
  586. FormLogShow?.ShowLog(outputMessage);
  587. }
  588. else
  589. {
  590. outputMessage = $"[{e.Content}]成型工号=[{groutinguserCode}]";
  591. Logger.Trace(outputMessage, logKeyT, logger_t);
  592. FormLogShow?.ShowLog(outputMessage);
  593. }
  594. }
  595. #endregion
  596. #region 【可选】工序验证
  597. if (!string.IsNullOrEmpty(plc_s.PROCEDURE_CHECKID))
  598. {
  599. Int16 plc_flag = Convert.ToInt16(GetProcedureCheck(barCode, plc_s.PROCEDURE_CHECKID, e, logKeyT, logKeyE));
  600. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  601. {
  602. SendCode(plc_s, e, logKeyT, logKeyE, plc, plc_flag);
  603. }
  604. else
  605. {
  606. outputMessage = $"[{e.Content}]工序=[{plc_s.PROCEDURE_CHECKID}]工序验证=[{plc_flag}]";
  607. Logger.Trace(outputMessage, logKeyT, logger_t);
  608. FormLogShow?.ShowLog(outputMessage);
  609. }
  610. return;
  611. }
  612. #endregion
  613. #region 【可选】工序计件
  614. if (!string.IsNullOrEmpty(plc_s.PROCEDURE_ID) && (!string.IsNullOrEmpty(plc_s.PROCEDURE_USERCODE) || !string.IsNullOrEmpty(plc_s.WORKSTATION_ID)) )
  615. {
  616. //如果是重烧产品使用重烧ID
  617. if (!string.IsNullOrEmpty(plc_s.PROCEDURE_AUTOREFIRE_ID))
  618. {
  619. plc_s.PROCEDURE_ID = GetAutoFireID(barCode, plc_s.PROCEDURE_ID, plc_s.PROCEDURE_AUTOREFIRE_ID, e, logKeyE);
  620. }
  621. string p_id = GetFlowId(barCode, e, logKeyE);
  622. Int16 plc_flag = 0;
  623. if (p_id != plc_s.PROCEDURE_ID.ToString())
  624. {
  625. string userCode = "";
  626. //默认读取userCode
  627. if(!string.IsNullOrEmpty(plc_s.PROCEDURE_USERCODE))
  628. {
  629. userCode = plc_s.PROCEDURE_USERCODE;
  630. }
  631. //优先从工位取userCode
  632. if (!string.IsNullOrEmpty(plc_s.WORKSTATION_ID))
  633. {
  634. userCode = GetUserCodeFromWorkStation(plc_s.WORKSTATION_ID, e, logKeyE);
  635. outputMessage = $"[{e.Content}]DB_UserCode=[{userCode}]";
  636. Logger.Trace(outputMessage, logKeyT, logger_t);
  637. FormLogShow?.ShowLog(outputMessage);
  638. }
  639. //工序计件
  640. string result = SmartDeviceProxy.Instance.Invoke<string>(
  641. p => p.AddWorkPieceByStatus3(
  642. _mes_s.AccountCode,
  643. userCode,
  644. null,
  645. Convert.ToInt32(plc_s.PROCEDURE_ID),
  646. barCode,
  647. null));
  648. outputMessage = $"[{e.Content}]工序=[{plc_s.PROCEDURE_ID}]工号=[{userCode}]工序计件=[{result}]";
  649. Logger.Trace(outputMessage, logKeyT, logger_t);
  650. FormLogShow?.ShowLog(outputMessage);
  651. // 返回状态(成功、失败)
  652. if (result != "OK")
  653. {
  654. plc_flag = 3;
  655. if (result == "EE")
  656. {
  657. plc_flag = 4;
  658. outputMessage = $"MES服务端异常(详情参见MES端日志)";
  659. }
  660. else if (result == "EU-01")
  661. {
  662. outputMessage = $"无效的帐套或工号(详情参见MES端日志)";
  663. }
  664. else
  665. {
  666. outputMessage = $"其他错误(详情参见MES端日志)[{result}]";
  667. }
  668. Logger.Error(null, outputMessage, logKeyT, logger_t);
  669. Logger.Error(null, outputMessage, logKeyE, logger_e);
  670. FormLogShow?.ShowLog(outputMessage);
  671. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  672. {
  673. SendCode(plc_s, e, logKeyT, logKeyE, plc, plc_flag);
  674. }
  675. return;
  676. }
  677. }
  678. }
  679. #endregion
  680. #region 【可选】工序计件,二检交接,干补过给6,未干补过正常计件
  681. if (!string.IsNullOrEmpty(plc_s.PROCEDURE_DRYREPAIR_ID) && (!string.IsNullOrEmpty(plc_s.PROCEDURE_USERCODE) || !string.IsNullOrEmpty(plc_s.WORKSTATION_ID)))
  682. {
  683. string dryRepair = GetDryRepair(barCode, e, logKeyE);
  684. if(dryRepair == "0")
  685. {
  686. string p_id = GetFlowId(barCode, e, logKeyE);
  687. Int16 plc_flag = 0;
  688. if (p_id != plc_s.PROCEDURE_DRYREPAIR_ID.ToString())
  689. {
  690. string userCode = "";
  691. //默认读取userCode
  692. if (!string.IsNullOrEmpty(plc_s.PROCEDURE_USERCODE))
  693. {
  694. userCode = plc_s.PROCEDURE_USERCODE;
  695. }
  696. //优先从工位取userCode
  697. if (!string.IsNullOrEmpty(plc_s.WORKSTATION_ID))
  698. {
  699. userCode = GetUserCodeFromWorkStation(plc_s.WORKSTATION_ID, e, logKeyE);
  700. outputMessage = $"[{e.Content}]DB_UserCode=[{userCode}]";
  701. Logger.Trace(outputMessage, logKeyT, logger_t);
  702. FormLogShow?.ShowLog(outputMessage);
  703. }
  704. //工序计件
  705. string result = SmartDeviceProxy.Instance.Invoke<string>(
  706. p => p.AddWorkPieceByStatus3(
  707. _mes_s.AccountCode,
  708. userCode,
  709. null,
  710. Convert.ToInt32(plc_s.PROCEDURE_DRYREPAIR_ID),
  711. barCode,
  712. null));
  713. outputMessage = $"[{e.Content}]工序=[{plc_s.PROCEDURE_DRYREPAIR_ID}]工号=[{userCode}]工序计件=[{result}]";
  714. Logger.Trace(outputMessage, logKeyT, logger_t);
  715. FormLogShow?.ShowLog(outputMessage);
  716. // 返回状态(成功、失败)
  717. if (result != "OK")
  718. {
  719. plc_flag = 3;
  720. if (result == "EE")
  721. {
  722. plc_flag = 4;
  723. outputMessage = $"MES服务端异常(详情参见MES端日志)";
  724. }
  725. else if (result == "EU-01")
  726. {
  727. outputMessage = $"无效的帐套或工号(详情参见MES端日志)";
  728. }
  729. else
  730. {
  731. outputMessage = $"其他错误(详情参见MES端日志)[{result}]";
  732. }
  733. Logger.Error(null, outputMessage, logKeyT, logger_t);
  734. Logger.Error(null, outputMessage, logKeyE, logger_e);
  735. FormLogShow?.ShowLog(outputMessage);
  736. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  737. {
  738. SendCode(plc_s, e, logKeyT, logKeyE, plc, plc_flag);
  739. }
  740. return;
  741. }
  742. }
  743. }
  744. if(dryRepair == "1")
  745. {
  746. SendCode(plc_s, e, logKeyT, logKeyE, plc, 6);
  747. return;
  748. }
  749. }
  750. #endregion
  751. #region 【可选】工序计件(产品等级判定为重烧的产品自动重烧交接工序计件)(官塘厂)
  752. if (!string.IsNullOrEmpty(plc_s.PROCEDURE_REFIRE_RECIVE_ID) && (!string.IsNullOrEmpty(plc_s.PROCEDURE_REFIRE_RECIVE_USERCODE) ))
  753. {
  754. //识别是否判定为重烧的产品
  755. Int16 goodsLevel = Convert.ToInt16(GetGoodsLevel(barCode, e, logKeyT));
  756. if(goodsLevel == 6)
  757. {
  758. string p_id = GetFlowId(barCode, e, logKeyE);
  759. Int16 plc_flag = 0;
  760. if (p_id != plc_s.PROCEDURE_REFIRE_RECIVE_ID.ToString())
  761. {
  762. string userCode = "";
  763. //默认读取userCode
  764. if (!string.IsNullOrEmpty(plc_s.PROCEDURE_REFIRE_RECIVE_USERCODE))
  765. {
  766. userCode = plc_s.PROCEDURE_REFIRE_RECIVE_USERCODE;
  767. }
  768. //工序计件
  769. string result = SmartDeviceProxy.Instance.Invoke<string>(
  770. p => p.AddWorkPieceByStatus3(
  771. _mes_s.AccountCode,
  772. userCode,
  773. null,
  774. Convert.ToInt32(plc_s.PROCEDURE_REFIRE_RECIVE_ID),
  775. barCode,
  776. null));
  777. outputMessage = $"[{e.Content}]工序=[{plc_s.PROCEDURE_REFIRE_RECIVE_ID}]工号=[{userCode}]工序计件=[{result}]";
  778. Logger.Trace(outputMessage, logKeyT, logger_t);
  779. FormLogShow?.ShowLog(outputMessage);
  780. // 返回状态(成功、失败)
  781. if (result != "OK")
  782. {
  783. plc_flag = 3;
  784. if (result == "EE")
  785. {
  786. plc_flag = 4;
  787. outputMessage = $"MES服务端异常(详情参见MES端日志)";
  788. }
  789. else if (result == "EU-01")
  790. {
  791. outputMessage = $"无效的帐套或工号(详情参见MES端日志)";
  792. }
  793. else
  794. {
  795. outputMessage = $"其他错误(详情参见MES端日志)[{result}]";
  796. }
  797. Logger.Error(null, outputMessage, logKeyT, logger_t);
  798. Logger.Error(null, outputMessage, logKeyE, logger_e);
  799. FormLogShow?.ShowLog(outputMessage);
  800. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  801. {
  802. SendCode(plc_s, e, logKeyT, logKeyE, plc, plc_flag);
  803. }
  804. return;
  805. }
  806. }
  807. }
  808. }
  809. #endregion
  810. #region 【可选】(传入其他PLC数据)
  811. if (!string.IsNullOrEmpty(plc_s.PLC_IP_NEW))
  812. {
  813. //创建新的PLC连接
  814. SocketClient<SiemensS7_1200Model> plcnew = new SocketClient<SiemensS7_1200Model>();
  815. plcnew.Connect(plc_s.PLC_IP_NEW, plc_s.PLC_PORT);
  816. string intCode = "";
  817. //产品型号代码
  818. if (!string.IsNullOrEmpty(plc_s.PLC_SEATCOVER_CODE_OTHER) && !string.IsNullOrEmpty(plc_s.PLC_SEATCOVER_CODENUM_OTHER))
  819. {
  820. intCode = GetSeatCoverCode(barCode, e, logKeyE);
  821. if (string.IsNullOrWhiteSpace(intCode))
  822. {
  823. outputMessage = $"[{e.Content}]此条码[{barCode}]未设置型号代码";
  824. Logger.Error(null, outputMessage, logKeyT, logger_t);
  825. Logger.Error(null, outputMessage, logKeyE, logger_e);
  826. FormLogShow?.ShowLog(outputMessage);
  827. string outputMessages = $"[{e.Content}]SET_FLAG_CODE_OTHER[{2}]{plc_s.PLC_FLAG_CODE_OTHER + plc_s.PLC_FLAG_CODENUM_OTHER}";
  828. Logger.Trace(outputMessages, logKeyT, logger_t);
  829. FormLogShow?.ShowLog(outputMessages);
  830. plcnew?.Write<short>(plc_s.PLC_FLAG_CODE_OTHER, plc_s.PLC_FLAG_CODENUM_OTHER, 2);
  831. Logger.Trace(outputMessages, logKeyT, logger_t);
  832. FormLogShow?.ShowLog(outputMessage);
  833. return;
  834. }
  835. outputMessage = $"[{e.Content}]SET_SEATCOVER_OTHER=[{intCode}]{plc_s.PLC_SEATCOVER_CODE_OTHER + plc_s.PLC_SEATCOVER_CODENUM_OTHER}";
  836. Logger.Trace(outputMessage, logKeyT, logger_t);
  837. FormLogShow?.ShowLog(outputMessage);
  838. p_r = plcnew.Write<short>(plc_s.PLC_SEATCOVER_CODE_OTHER, plc_s.PLC_SEATCOVER_CODENUM_OTHER, (short)(intCode.ToInt32()));
  839. p_r = plcnew.Write<short>(plc_s.PLC_SEATCOVER_CODE_OTHER, plc_s.PLC_SEATCOVER_CODENUM_OTHER, intCode.ToInt16());
  840. outputMessage = $"[{e.Content}]END_SEATCOVER_OTHER=[{p_r.ToString()}]{plc_s.PLC_SEATCOVER_CODE_OTHER + plc_s.PLC_SEATCOVER_CODENUM_OTHER}";
  841. Logger.Trace(outputMessage, logKeyT, logger_t);
  842. FormLogShow?.ShowLog(outputMessage);
  843. }
  844. //产品型号
  845. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSCODE_CODE_OTHER) && !string.IsNullOrEmpty(plc_s.PLC_GOODSCODE_CODENUM_OTHER))
  846. {
  847. string goodsCode = GetGoodsCode(barCode, e, logKeyE);
  848. outputMessage = $"[{e.Content}]SET_GOODSCODE_OTHER=[{goodsCode}]{plc_s.PLC_GOODSCODE_CODE_OTHER + plc_s.PLC_GOODSCODE_CODENUM_OTHER}";
  849. Logger.Trace(outputMessage, logKeyT, logger_t);
  850. FormLogShow?.ShowLog(outputMessage);
  851. p_r = plcnew.Write<string>(plc_s.PLC_GOODSCODE_CODE_OTHER, plc_s.PLC_GOODSCODE_CODENUM_OTHER, goodsCode);
  852. //再传一遍
  853. p_r = plcnew.Write<short>(plc_s.PLC_SEATCOVER_CODE_OTHER, plc_s.PLC_SEATCOVER_CODENUM_OTHER, intCode.ToInt16());
  854. outputMessage = $"[{e.Content}]END_GOODSCODE_OTHER=[{p_r}]{plc_s.PLC_GOODSCODE_CODE_OTHER + plc_s.PLC_GOODSCODE_CODENUM_OTHER}";
  855. Logger.Trace(outputMessage, logKeyT, logger_t);
  856. FormLogShow?.ShowLog(outputMessage);
  857. }
  858. //当前条码
  859. if (!string.IsNullOrEmpty(plc_s.PLC_BARCODE_CODE_OTHER) && !string.IsNullOrEmpty(plc_s.PLC_BARCODE_CODENUM_OTHER))
  860. {
  861. outputMessage = $"[{e.Content}]SET_BarCode_OTHER=[{barCode}]{plc_s.PLC_BARCODE_CODE_OTHER + plc_s.PLC_BARCODE_CODENUM_OTHER}";
  862. Logger.Trace(outputMessage, logKeyT, logger_t);
  863. FormLogShow?.ShowLog(outputMessage);
  864. p_r = plcnew.Write<string>(plc_s.PLC_BARCODE_CODE_OTHER, plc_s.PLC_BARCODE_CODENUM_OTHER, barCode);
  865. outputMessage = $"[{e.Content}]END_BarCode_OTHER=[{p_r}]{plc_s.PLC_BARCODE_CODE_OTHER + plc_s.PLC_BARCODE_CODENUM_OTHER}";
  866. Logger.Trace(outputMessage, logKeyT, logger_t);
  867. FormLogShow?.ShowLog(outputMessage);
  868. }
  869. //产品等级
  870. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSLEVEL_CODE_OTHER) && !string.IsNullOrEmpty(plc_s.PLC_GOODSLEVEL_CODENUM_OTHER))
  871. {
  872. Int16 goodsLevel = Convert.ToInt16(GetGoodsLevel(barCode, e, logKeyT));
  873. //如果有裸瓷标识,那么产品等级区分是否为裸瓷正品,裸瓷标识1+正品=91;裸瓷+副品=92 。非裸瓷为原逻辑
  874. if (!string.IsNullOrEmpty(plc_s.PLC_LUOCI_OTHER) && plc_s.PLC_LUOCI_OTHER == "1")
  875. {
  876. Int16 luoci = Convert.ToInt16(GetLuociFlag(barCode, e, logKeyT));
  877. if (luoci == 1 && goodsLevel == 4)
  878. {
  879. goodsLevel = 91;
  880. }
  881. if (luoci == 1 && goodsLevel == 5)
  882. {
  883. goodsLevel = 92;
  884. }
  885. }
  886. outputMessage = $"[{e.Content}]SET_GoodsLevel_OTHER=[{goodsLevel}]{plc_s.PLC_GOODSLEVEL_CODE_OTHER + plc_s.PLC_GOODSLEVEL_CODENUM_OTHER}";
  887. Logger.Trace(outputMessage, logKeyT, logger_t);
  888. FormLogShow?.ShowLog(outputMessage);
  889. p_r = plc?.Write<short>(plc_s.PLC_GOODSLEVEL_CODE_OTHER, plc_s.PLC_GOODSLEVEL_CODENUM_OTHER, goodsLevel);
  890. outputMessage = $"[{e.Content}]END_GoodsLevel_OTHER=[{p_r.ToString()}]{plc_s.PLC_GOODSLEVEL_CODE_OTHER + plc_s.PLC_GOODSLEVEL_CODENUM_OTHER}";
  891. Logger.Trace(outputMessage, logKeyT, logger_t);
  892. FormLogShow?.ShowLog(outputMessage);
  893. }
  894. //扫码结果
  895. if (!string.IsNullOrEmpty(plc_s.PLC_FLAG_CODE_OTHER) && !string.IsNullOrEmpty(plc_s.PLC_FLAG_CODENUM_OTHER))
  896. {
  897. string outputMessages = $"[{e.Content}]SET_FLAG_CODE_OTHER[{1}]{plc_s.PLC_FLAG_CODE_OTHER + plc_s.PLC_FLAG_CODENUM_OTHER}";
  898. Logger.Trace(outputMessages, logKeyT, logger_t);
  899. FormLogShow?.ShowLog(outputMessages);
  900. p_r = plcnew?.Write<short>(plc_s.PLC_FLAG_CODE_OTHER, plc_s.PLC_FLAG_CODENUM_OTHER, 1);
  901. outputMessage = $"[{e.Content}]SET_FLAG_CODE_OTHER=[{p_r}]{plc_s.PLC_FLAG_CODE_OTHER + plc_s.PLC_FLAG_CODENUM_OTHER}";
  902. Logger.Trace(outputMessages, logKeyT, logger_t);
  903. FormLogShow?.ShowLog(outputMessage);
  904. }
  905. plcnew.Close();
  906. }
  907. #endregion
  908. #region 【可选】写入PLC扫码结果 【1:通过,2:扫码异常,3:工序异常,0:复位】
  909. if (!string.IsNullOrEmpty(plc_s.PLC_FLAG_CODE) && !string.IsNullOrEmpty(plc_s.PLC_FLAG_CODENUM))
  910. {
  911. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  912. {
  913. SendCode(plc_s, e, logKeyT, logKeyE, plc, 1);
  914. }
  915. else
  916. {
  917. outputMessage = $"[{e.Content}]PLC标识=[1]";
  918. Logger.Trace(outputMessage, logKeyT, logger_t);
  919. FormLogShow?.ShowLog(outputMessage);
  920. }
  921. }
  922. #endregion
  923. }
  924. }
  925. catch (Exception ex)
  926. {
  927. FormLogShow?.ShowLog($"[{e.Content}]ERROR={ex.Message}");
  928. if (plc_s != null)
  929. {
  930. Logger.Error(ex, $"[{e.Content}]ERROR", logKeyT, logger_t);
  931. Logger.Error(ex, $"[{e.Content}]ERROR", logKeyE, logger_e);
  932. SendCode(plc_s, e, logKeyT, logKeyE, plc, 2);
  933. }
  934. else
  935. {
  936. Logger.Error(ex, $"[{e.Content}]ERROR-NOFLAG", logKeyT, logger_t);
  937. Logger.Error(ex, $"[{e.Content}]ERROR-NOFLAG", logKeyE, logger_e);
  938. }
  939. }
  940. finally
  941. {
  942. LoggerT?.EndTracking();
  943. plc?.Disconnect();
  944. plc?.Close();
  945. }
  946. }
  947. private void SendCode(PLC_S_GA plc_s, ReceiveSession e, string loggerNameT, string loggerNameE, SocketClient<SiemensS7_1200Model> plc, short code)
  948. {
  949. try
  950. {
  951. string outputMessage = $"[{e.Content}]SET_FLAG_CODE=[{code}]{plc_s.PLC_FLAG_CODE + plc_s.PLC_FLAG_CODENUM}";
  952. Logger.Trace(outputMessage, loggerNameT, logger_t);
  953. FormLogShow?.ShowLog(outputMessage);
  954. PLCResult p_r = plc?.Write<short>(plc_s.PLC_FLAG_CODE, plc_s.PLC_FLAG_CODENUM, (short)code);
  955. outputMessage = $"[{e.Content}]SET_FLAG_CODE=[{p_r}]{plc_s.PLC_FLAG_CODE + plc_s.PLC_FLAG_CODENUM}";
  956. Logger.Trace(outputMessage, loggerNameT, logger_t);
  957. FormLogShow?.ShowLog(outputMessage);
  958. }
  959. catch (Exception ex)
  960. {
  961. Logger.Error(ex, $"[{e.Content}]ERROR-SendCode", loggerNameT, logger_t);
  962. Logger.Error(ex, $"[{e.Content}]ERROR-SendCode", loggerNameE, logger_e);
  963. FormLogShow?.ShowLog($"[{e.Content}]ERROR-SendCode={ex.Message}");
  964. }
  965. }
  966. private string GetGoodsCode(string barCode, ReceiveSession e, string loggerName)
  967. {
  968. try
  969. {
  970. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  971. {
  972. string sqlStr = @"
  973. SELECT
  974. GDD.GOODSCODE
  975. FROM
  976. TP_PM_GROUTINGDAILYDETAIL GDD
  977. WHERE
  978. GDD.BARCODE = :BARCODE
  979. ";
  980. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  981. return result == null ? "" : result.ToString();
  982. }
  983. }
  984. catch (Exception ex)
  985. {
  986. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsCode", loggerName, logger_e);
  987. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsCode={ex.Message}");
  988. return null;
  989. }
  990. }
  991. private string GetSeatCoverCode(string barCode, ReceiveSession e, string loggerName)
  992. {
  993. try
  994. {
  995. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  996. {
  997. string sqlStr = @"
  998. SELECT
  999. G.SEATCOVERCODE
  1000. FROM
  1001. TP_PM_GROUTINGDAILYDETAIL GDD
  1002. INNER JOIN TP_MST_GOODS G ON G.GOODSID = GDD.GOODSID
  1003. WHERE
  1004. GDD.BARCODE = :BARCODE
  1005. ";
  1006. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  1007. return result == null ? "" : result.ToString();
  1008. }
  1009. }
  1010. catch (Exception ex)
  1011. {
  1012. Logger.Error(ex, $"[{e.Content}]ERROR-GetSeatCoverCode", loggerName, logger_e);
  1013. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetSeatCoverCode={ex.Message}");
  1014. return null;
  1015. }
  1016. }
  1017. private string GetGoodsType(string barCode, ReceiveSession e, string loggerName)
  1018. {
  1019. try
  1020. {
  1021. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  1022. {
  1023. string sqlStr = @"
  1024. SELECT
  1025. -- G.GOODSCODE,
  1026. -- G.SEATCOVERCODE,
  1027. CASE
  1028. WHEN T.GOODSTYPECODE = '001001001' THEN 2 --连体
  1029. WHEN T.GOODSTYPECODE = '001001002' THEN 3 --分体
  1030. WHEN T.GOODSTYPECODE = '001001003' THEN 1 --智能
  1031. WHEN T.GOODSTYPECODE = '001001004' THEN 1 --智能高压
  1032. ELSE 0 --其他
  1033. END AS GOODSTYPE
  1034. FROM
  1035. TP_PM_GROUTINGDAILYDETAIL GDD
  1036. INNER JOIN TP_MST_GOODS G ON G.GOODSID = GDD.GOODSID
  1037. INNER JOIN TP_MST_GOODSTYPE T ON G.GOODSTYPEID = T.GOODSTYPEID
  1038. WHERE
  1039. GDD.BARCODE = :BARCODE --'10006800247'
  1040. ";
  1041. string goodsType = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode)).ToString();
  1042. return goodsType;
  1043. }
  1044. }
  1045. catch (Exception ex)
  1046. {
  1047. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsType", loggerName, logger_e);
  1048. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsType={ex.Message}");
  1049. return "0";
  1050. }
  1051. }
  1052. private string GetFlowId(string barCode, ReceiveSession e, string loggerName)
  1053. {
  1054. try
  1055. {
  1056. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  1057. {
  1058. string sqlStr = @"
  1059. SELECT
  1060. GDD.FLOWPROCEDUREID
  1061. FROM
  1062. TP_PM_INPRODUCTION GDD
  1063. WHERE
  1064. GDD.BARCODE = :BARCODE
  1065. ";
  1066. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  1067. return result == null ? "0" : result.ToString();
  1068. }
  1069. }
  1070. catch (Exception ex)
  1071. {
  1072. Logger.Error(ex, $"[{e.Content}]ERROR-GetFlowId", loggerName, logger_e);
  1073. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetFlowId={ex.Message}");
  1074. return "0";
  1075. }
  1076. }
  1077. private string GetAutoFireID(string barCode, string procedureId, string autoFireId, ReceiveSession e, string loggerName)
  1078. {
  1079. try
  1080. {
  1081. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  1082. {
  1083. string sqlStr = @"
  1084. SELECT T.ISREFIRE
  1085. FROM TP_PM_INPRODUCTION T
  1086. WHERE T.BARCODE = :BARCODE
  1087. UNION
  1088. SELECT T.ISREFIRE
  1089. FROM TP_PM_INPRODUCTIONTRASH T
  1090. WHERE T.BARCODE = :BARCODE
  1091. ";
  1092. string result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode)).ToString();
  1093. if (result == "6")
  1094. return autoFireId;
  1095. else
  1096. return procedureId;
  1097. }
  1098. }
  1099. catch (Exception ex)
  1100. {
  1101. Logger.Error(ex, $"[{e.Content}]ERROR-GetAutoFireID", loggerName, logger_e);
  1102. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetAutoFireID={ex.Message}");
  1103. return "0";
  1104. }
  1105. }
  1106. private string GetUserCodeFromWorkStation(string workStationId, ReceiveSession e, string loggerName)
  1107. {
  1108. try
  1109. {
  1110. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  1111. {
  1112. string sqlStr = @"
  1113. SELECT
  1114. T.USERCODE
  1115. FROM
  1116. TP_MST_WORKSTATION T
  1117. INNER JOIN TP_MST_USER U ON U.USERCODE = T.USERCODE
  1118. WHERE
  1119. T.WORKSTATIONID = :WORKSTATIONID
  1120. ";
  1121. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":WORKSTATIONID", workStationId));
  1122. return result == null ? "0" : result.ToString();
  1123. }
  1124. }
  1125. catch (Exception ex)
  1126. {
  1127. Logger.Error(ex, $"[{e.Content}]ERROR-GetUserCodeFromWorkStation", loggerName, logger_e);
  1128. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetUserCodeFromWorkStation={ex.Message}");
  1129. return "0";
  1130. }
  1131. }
  1132. private string GetSemiReWork(string barCode, ReceiveSession e, string loggerName)
  1133. {
  1134. try
  1135. {
  1136. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  1137. {
  1138. string sqlStr = @"
  1139. SELECT
  1140. P.ISREWORKFLAG
  1141. FROM
  1142. TP_PM_INPRODUCTION P
  1143. WHERE
  1144. P.BARCODE = :BARCODE
  1145. ";
  1146. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  1147. //返工标识(0:正常,1:半检返工中, 2:半检返修)
  1148. //没找到记录表明产品报废写 3
  1149. string resultFlag = "0";
  1150. if(result !=null)
  1151. {
  1152. if (result.ToString() == "0") resultFlag = "1"; //正常
  1153. if (result.ToString() == "1" || result.ToString() == "2") resultFlag = "2";//返工
  1154. }
  1155. else
  1156. {
  1157. resultFlag = "3";//报废
  1158. }
  1159. return resultFlag;
  1160. }
  1161. }
  1162. catch (Exception ex)
  1163. {
  1164. Logger.Error(ex, $"[{e.Content}]ERROR-GetSemiReWork", loggerName, logger_e);
  1165. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetSemiReWork={ex.Message}");
  1166. return "0";
  1167. }
  1168. }
  1169. private string GetGoodsLevel(string barCode, ReceiveSession e, string loggerName)
  1170. {
  1171. try
  1172. {
  1173. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  1174. {
  1175. string sqlStr = @"
  1176. SELECT GL.GOODSLEVELTYPEID
  1177. FROM TP_PM_GROUTINGDAILYDETAIL GDD
  1178. LEFT JOIN TP_MST_GOODSLEVEL GL
  1179. ON GDD.GOODSLEVELTYPEID = GL.GOODSLEVELTYPEID
  1180. WHERE GDD.BARCODE = :BARCODE
  1181. ";
  1182. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  1183. return result == null ? "0" : result.ToString();
  1184. }
  1185. }
  1186. catch (Exception ex)
  1187. {
  1188. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsLevel", loggerName, logger_e);
  1189. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsLevel={ex.Message}");
  1190. return "0";
  1191. }
  1192. }
  1193. private string GetLuociFlag(string barCode, ReceiveSession e, string loggerName)
  1194. {
  1195. try
  1196. {
  1197. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  1198. {
  1199. string sqlStr = @"
  1200. SELECT TO_CHAR(DECODE(GDD.LUOCIFLAG , '1', '1','0')) LUOCIFLAG
  1201. FROM TP_PM_GROUTINGDAILYDETAIL GDD
  1202. WHERE GDD.BARCODE = :BARCODE
  1203. ";
  1204. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  1205. return result == null ? "0" : result.ToString();
  1206. }
  1207. }
  1208. catch (Exception ex)
  1209. {
  1210. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsLevel", loggerName, logger_e);
  1211. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsLevel={ex.Message}");
  1212. return "0";
  1213. }
  1214. }
  1215. private string GetGoodsRepair(string barCode, ReceiveSession e, string loggerName)
  1216. {
  1217. try
  1218. {
  1219. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  1220. {
  1221. string sqlStr = @"
  1222. SELECT
  1223. DECODE( GR.REPAIRPATH, NULL, GDD.GOODSLEVELTYPEID, 0, GDD.GOODSLEVELTYPEID, GR.REPAIRPATH )
  1224. FROM
  1225. TP_PM_GROUTINGDAILYDETAIL GDD
  1226. LEFT JOIN TP_PM_GOODSREPAIR GR ON GDD.BARCODE = GR.BARCODE
  1227. AND GR.VALUEFLAG = 1
  1228. WHERE
  1229. GDD.VALUEFLAG = 1
  1230. AND GDD.BARCODE = @BARCODE@
  1231. ";
  1232. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  1233. return result == null ? "0" : result.ToString();
  1234. }
  1235. }
  1236. catch (Exception ex)
  1237. {
  1238. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsRepair", loggerName, logger_e);
  1239. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsRepair={ex.Message}");
  1240. return "0";
  1241. }
  1242. }
  1243. private string GetProcedureCheck(string barCode,string procedureId, ReceiveSession e, string loggerNameT, string loggerNameE)
  1244. {
  1245. try
  1246. {
  1247. using (IDataAccess dataAccess = PLC_S_DataAccess.GetDataAccess())
  1248. {
  1249. CDAParameter[] parameters = new CDAParameter[]
  1250. {
  1251. new CDAParameter("in_procedureid", procedureId),
  1252. new CDAParameter("in_barcode", barCode),
  1253. new CDAParameter("out_errType",DataType.Int32, ParameterDirection.Output),
  1254. new CDAParameter("out_errMsg",DataType.VarChar, 4000, ParameterDirection.Output),
  1255. new CDAParameter("out_goodsID",DataType.Int32, ParameterDirection.Output),
  1256. new CDAParameter("out_goodsCode",DataType.VarChar, 400, ParameterDirection.Output),
  1257. new CDAParameter("out_goodsType",DataType.Int32, ParameterDirection.Output),
  1258. };
  1259. int ii = dataAccess.ExecuteSPNonQuery("PRO_PM_CheckBarcode_PLC", parameters);
  1260. Int16 plc_flag = 0;
  1261. if (!int.TryParse(parameters[2].Value + "", out int errtype))
  1262. {
  1263. errtype = 4;
  1264. }
  1265. // 其他情况显示MES异常
  1266. if (errtype == 4)
  1267. {
  1268. plc_flag = 4;
  1269. }
  1270. else if (errtype == 0)
  1271. {
  1272. plc_flag = 1;
  1273. }
  1274. else // errtype == 1 || errtype == 2 || errtype == 3
  1275. {
  1276. // 无效条码,显示不可到达
  1277. plc_flag = 3;
  1278. }
  1279. string outputMessage = $"[{e.Content}]MESSAGE=[{errtype}][{parameters[3].Value}]";
  1280. Logger.Trace(outputMessage, loggerNameT, logger_t);
  1281. FormLogShow?.ShowLog(outputMessage);
  1282. return plc_flag.ToString();
  1283. }
  1284. }
  1285. catch (Exception ex)
  1286. {
  1287. Logger.Error(ex, $"[{e.Content}]ERROR-GetProcedureCheck", loggerNameE, logger_e);
  1288. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetProcedureCheck={ex.Message}");
  1289. return "0";
  1290. }
  1291. }
  1292. private string GetDefectTypeId(string barCode, ReceiveSession e, string loggerName)
  1293. {
  1294. try
  1295. {
  1296. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  1297. {
  1298. string sqlStr = @"
  1299. SELECT D.DEFECTCODE, D.DEFECTNAME, DT.DEFECTTYPENAME, DT.DEFECTTYPEID, DT.REMARKS
  1300. FROM TP_PM_DEFECT PD
  1301. LEFT JOIN TP_MST_DEFECT D
  1302. ON PD.DEFECTID = D.DEFECTID
  1303. LEFT JOIN TP_MST_DEFECTTYPE DT
  1304. ON D.DEFECTTYPEID = DT.DEFECTTYPEID
  1305. WHERE D.VALUEFLAG = 1
  1306. AND PD.VALUEFLAG = 1
  1307. AND DT.DEFECTTYPEID <> 21
  1308. AND BARCODE = :BARCODE
  1309. ORDER BY D.CREATETIME DESC
  1310. ";
  1311. DataTable dt = conn.ExecuteDatatable(sqlStr, new CDAParameter(":BARCODE", barCode));
  1312. if (dt.Rows.Count > 0)
  1313. {
  1314. return dt.Rows[0]["REMARKS"].ToString();
  1315. }
  1316. else
  1317. {
  1318. return "0";
  1319. }
  1320. }
  1321. }
  1322. catch (Exception ex)
  1323. {
  1324. Logger.Error(ex, $"[{e.Content}]ERROR-GetDefectTypeId", loggerName, logger_e);
  1325. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetDefectTypeId={ex.Message}");
  1326. return "0";
  1327. }
  1328. }
  1329. //查询成型工号
  1330. private int GetGroutingUserCode(string barCode, ReceiveSession e, string loggerName)
  1331. {
  1332. try
  1333. {
  1334. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  1335. {
  1336. string sqlStr = @"
  1337. SELECT substr(GDD.USERCODE,2 ) USERCODE
  1338. FROM TP_PM_GROUTINGDAILYDETAIL GDD
  1339. WHERE GDD.BARCODE = :BARCODE
  1340. ";
  1341. DataTable dt = conn.ExecuteDatatable(sqlStr, new CDAParameter(":BARCODE", barCode));
  1342. if (dt.Rows.Count > 0)
  1343. {
  1344. string usercode = dt.Rows[0]["USERCODE"].ToString();
  1345. return Convert.ToInt16(usercode);
  1346. }
  1347. else
  1348. {
  1349. return 0;
  1350. }
  1351. }
  1352. }
  1353. catch (Exception ex)
  1354. {
  1355. Logger.Error(ex, $"[{e.Content}]ERROR-GetDefectTypeId", loggerName, logger_e);
  1356. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetDefectTypeId={ex.Message}");
  1357. return 0;
  1358. }
  1359. }
  1360. private string GetSemiRepair(string barCode,ReceiveSession e,string loggerName)
  1361. {
  1362. try
  1363. {
  1364. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  1365. {
  1366. string sqlStr = @"
  1367. SELECT GL.GOODSLEVELTYPEID
  1368. FROM TP_PM_GROUTINGDAILYDETAIL GDD
  1369. LEFT JOIN TP_MST_GOODSLEVEL GL
  1370. ON GDD.GOODSLEVELTYPEID = GL.GOODSLEVELTYPEID
  1371. WHERE GDD.BARCODE = :BARCODE
  1372. ";
  1373. object goodsLevel = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  1374. sqlStr = @"
  1375. SELECT
  1376. 99
  1377. FROM
  1378. TP_PM_INPRODUCTION
  1379. WHERE
  1380. BARCODE = :BARCODE
  1381. AND PROCEDUREID = 64 --完成的最后一个工序是1#二检补土时直接return 99(作为二检补土识别)
  1382. ";
  1383. object semiRepair = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  1384. if (semiRepair != null)
  1385. {
  1386. return semiRepair.ToString();
  1387. }
  1388. else
  1389. {
  1390. return goodsLevel.ToString();
  1391. }
  1392. }
  1393. }
  1394. catch (Exception ex)
  1395. {
  1396. Logger.Error(ex, $"[{e.Content}]ERROR-GetSemiReWork", loggerName, logger_e);
  1397. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetSemiReWork={ex.Message}");
  1398. return "0";
  1399. }
  1400. }
  1401. private string GetWareHouse(string barCode, ReceiveSession e, string loggerName)
  1402. {
  1403. try
  1404. {
  1405. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  1406. {
  1407. string sqlStr = @"
  1408. SELECT
  1409. PART
  1410. FROM
  1411. (
  1412. SELECT
  1413. T.PART,','
  1414. || LISTAGG ( T.GOODSID1, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
  1415. || LISTAGG ( T.GOODSID2, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
  1416. || LISTAGG ( T.GOODSID3, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
  1417. || LISTAGG ( T.GOODSID4, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
  1418. || LISTAGG ( T.GOODSID5, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
  1419. || LISTAGG ( T.GOODSID6, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
  1420. || LISTAGG ( T.GOODSID7, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
  1421. || LISTAGG ( T.GOODSID8, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
  1422. || LISTAGG ( T.GOODSID9, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
  1423. || LISTAGG ( T.GOODSID10, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ',' AS SQLSTR
  1424. FROM
  1425. (
  1426. SELECT
  1427. m.SETTINGNO AS part,
  1428. M.GOODSID1,
  1429. M.GOODSID2,
  1430. M.GOODSID3,
  1431. M.GOODSID4,
  1432. M.GOODSID5,
  1433. M.GOODSID6,
  1434. M.GOODSID7,
  1435. M.GOODSID8,
  1436. M.GOODSID9,
  1437. M.GOODSID10
  1438. FROM
  1439. TP_MST_WAREHOUSESETTING M
  1440. ) T
  1441. GROUP BY
  1442. T.PART
  1443. ) TT
  1444. WHERE
  1445. INSTR( TT.SQLSTR, ',' || ( SELECT GOODSID FROM TP_PM_GROUTINGDAILYDETAIL WHERE BARCODE = :BARCODE) || ',' ) > 0
  1446. ";
  1447. string wareHouse = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode)).ToString();
  1448. return wareHouse;
  1449. }
  1450. }
  1451. catch (Exception ex)
  1452. {
  1453. Logger.Error(ex, $"[{e.Content}]ERROR-GetWareHouse", loggerName, logger_e);
  1454. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetWareHouse={ex.Message}");
  1455. return "0";
  1456. }
  1457. }
  1458. private string GetDryRepair(string barCode, ReceiveSession e, string loggerName)
  1459. {
  1460. try
  1461. {
  1462. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  1463. {
  1464. string sqlStr = @"
  1465. SELECT
  1466. CASE WHEN PROCEDUREID = 65 THEN '1' ELSE '0' END AS DRY
  1467. FROM
  1468. TP_PM_PRODUCTIONDATA
  1469. WHERE
  1470. BARCODE = @BARCODE@
  1471. AND ROWNUM = 1
  1472. ORDER BY
  1473. PRODUCTIONDATAID DESC
  1474. ";
  1475. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  1476. return result == null ? "0" : result.ToString();
  1477. }
  1478. }
  1479. catch (Exception ex)
  1480. {
  1481. Logger.Error(ex, $"[{e.Content}]ERROR-GetDryRepair", loggerName, logger_e);
  1482. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetDryRepair={ex.Message}");
  1483. return "0";
  1484. }
  1485. }
  1486. private PLC_S_GA GetPLC_S_GA(string flag, ReceiveSession e, string loggerName)
  1487. {
  1488. try
  1489. {
  1490. flag = M_NAME + flag;
  1491. if (PLC_FLAGS.ContainsKey(flag))
  1492. {
  1493. return PLC_FLAGS[flag];
  1494. }
  1495. else
  1496. {
  1497. PLC_S_GA plc_s = new PLC_S_GA();
  1498. INIHelper ini = INIHelper.Create($@"PLC_S_INI\PLC_S_{M_NAME}.ini");
  1499. plc_s.PLC_IP = ini.Read(flag, "PLC_IP");
  1500. plc_s.PLC_PORT = ini.Read(flag, "PLC_PORT").ToInt32();
  1501. plc_s.PLC_FLAG_CODE = ini.Read(flag, "PLC_FLAG_CODE");
  1502. plc_s.PLC_FLAG_CODENUM = ini.Read(flag, "PLC_FLAG_CODENUM");
  1503. plc_s.PLC_SEATCOVER_CODE = ini.Read(flag, "PLC_SEATCOVER_CODE");
  1504. plc_s.PLC_SEATCOVER_CODENUM = ini.Read(flag, "PLC_SEATCOVER_CODENUM");
  1505. plc_s.PLC_BARCODE_CODE = ini.Read(flag, "PLC_BARCODE_CODE");
  1506. plc_s.PLC_BARCODE_CODENUM = ini.Read(flag, "PLC_BARCODE_CODENUM");
  1507. plc_s.PLC_BARCODENUM_CODE = ini.Read(flag, "PLC_BARCODENUM_CODE");
  1508. plc_s.PLC_BARCODENUM_CODENUM = ini.Read(flag, "PLC_BARCODENUM_CODENUM");
  1509. plc_s.PLC_GOODSCODE_CODE = ini.Read(flag, "PLC_GOODSCODE_CODE");
  1510. plc_s.PLC_GOODSCODE_CODENUM = ini.Read(flag, "PLC_GOODSCODE_CODENUM");
  1511. plc_s.PLC_GOODSTYPE_CODE = ini.Read(flag, "PLC_GOODSTYPE_CODE");
  1512. plc_s.PLC_GOODSTYPE_CODENUM = ini.Read(flag, "PLC_GOODSTYPE_CODENUM");
  1513. plc_s.PLC_SEMIREWORK_CODE = ini.Read(flag, "PLC_SEMIREWORK_CODE");
  1514. plc_s.PLC_SEMIREWORK_CODENUM = ini.Read(flag, "PLC_SEMIREWORK_CODENUM");
  1515. plc_s.PLC_SEMIREPAIR_CODE = ini.Read(flag, "PLC_SEMIREPAIR_CODE");
  1516. plc_s.PLC_SEMIREPAIR_CODENUM = ini.Read(flag, "PLC_SEMIREPAIR_CODENUM");
  1517. plc_s.PLC_GOODSLEVEL_CODE = ini.Read(flag, "PLC_GOODSLEVEL_CODE");
  1518. plc_s.PLC_GOODSLEVEL_CODENUM = ini.Read(flag, "PLC_GOODSLEVEL_CODENUM");
  1519. plc_s.PLC_GOODSLEVEL2_CODE = ini.Read(flag, "PLC_GOODSLEVEL2_CODE");
  1520. plc_s.PLC_GOODSLEVEL2_CODENUM = ini.Read(flag, "PLC_GOODSLEVEL2_CODENUM");
  1521. plc_s.PLC_ISREFIRE_CODE = ini.Read(flag, "PLC_ISREFIRE_CODE");
  1522. plc_s.PLC_ISREFIRE_CODENUM = ini.Read(flag, "PLC_ISREFIRE_CODENUM");
  1523. plc_s.PLC_GOODSTYPEISREFIRE_CODE = ini.Read(flag, "PLC_GOODSTYPEISREFIRE_CODE");
  1524. plc_s.PLC_GOODSTYPEISREFIRE_CODENUM = ini.Read(flag, "PLC_GOODSTYPEISREFIRE_CODENUM");
  1525. plc_s.PLC_GOODSREPAIR_CODE = ini.Read(flag, "PLC_GOODSREPAIR_CODE");
  1526. plc_s.PLC_GOODSREPAIR_CODENUM = ini.Read(flag, "PLC_GOODSREPAIR_CODENUM");
  1527. plc_s.PLC_GOODSDEFECTTYPE_CODE = ini.Read(flag, "PLC_GOODSDEFECTTYPE_CODE");
  1528. plc_s.PLC_GOODSDEFECTTYPE_CODENUM = ini.Read(flag, "PLC_GOODSDEFECTTYPE_CODENUM");
  1529. plc_s.PROCEDURE_ID = ini.Read(flag, "PROCEDURE_ID");
  1530. plc_s.PROCEDURE_USERCODE = ini.Read(flag, "PROCEDURE_USERCODE");
  1531. plc_s.PROCEDURE_DRYREPAIR_ID = ini.Read(flag, "PROCEDURE_DRYREPAIR_ID");
  1532. plc_s.PROCEDURE_REFIRE_RECIVE_ID = ini.Read(flag, "PROCEDURE_REFIRE_RECIVE_ID");
  1533. plc_s.PROCEDURE_REFIRE_RECIVE_USERCODE = ini.Read(flag, "PROCEDURE_REFIRE_RECIVE_USERCODE");
  1534. plc_s.WORKSTATION_ID = ini.Read(flag, "WORKSTATION_ID");
  1535. plc_s.WORKSTATION_NAME = ini.Read(flag, "WORKSTATION_NAME");
  1536. plc_s.PLC_IP_NEW = ini.Read(flag, "PLC_IP_NEW");
  1537. plc_s.PLC_SEATCOVER_CODE_OTHER = ini.Read(flag, "PLC_SEATCOVER_CODE_OTHER");
  1538. plc_s.PLC_SEATCOVER_CODENUM_OTHER = ini.Read(flag, "PLC_SEATCOVER_CODENUM_OTHER");
  1539. plc_s.PLC_GOODSCODE_CODE_OTHER = ini.Read(flag, "PLC_GOODSCODE_CODE_OTHER");
  1540. plc_s.PLC_GOODSCODE_CODENUM_OTHER = ini.Read(flag, "PLC_GOODSCODE_CODENUM_OTHER");
  1541. plc_s.PLC_BARCODE_CODE_OTHER = ini.Read(flag, "PLC_BARCODE_CODE_OTHER");
  1542. plc_s.PLC_BARCODE_CODENUM_OTHER = ini.Read(flag, "PLC_BARCODE_CODENUM_OTHER");
  1543. plc_s.PLC_FLAG_CODE_OTHER = ini.Read(flag, "PLC_FLAG_CODE_OTHER");
  1544. plc_s.PLC_FLAG_CODENUM_OTHER = ini.Read(flag, "PLC_FLAG_CODENUM_OTHER");
  1545. plc_s.PLC_GROUTINGUSER_CODE = ini.Read(flag, "PLC_GROUTINGUSER_CODE");
  1546. plc_s.PLC_GROUTINGUSER_CODENUM = ini.Read(flag, "PLC_GROUTINGUSER_CODENUM");
  1547. plc_s.PLC_LUOCI = ini.Read(flag, "PLC_LUOCI");
  1548. plc_s.PLC_GOODSLEVEL_CODE_OTHER = ini.Read(flag, "PLC_GOODSLEVEL_CODE_OTHER");
  1549. plc_s.PLC_GOODSLEVEL_CODENUM_OTHER = ini.Read(flag, "PLC_GOODSLEVEL_CODENUM_OTHER");
  1550. plc_s.PLC_LUOCI_OTHER = ini.Read(flag, "PLC_LUOCI_OTHER");
  1551. PLC_FLAGS.Add(flag, plc_s);
  1552. return plc_s;
  1553. }
  1554. }
  1555. catch (Exception ex)
  1556. {
  1557. Logger.Error(ex, $"[{e.Content}]ERROR-GetPLC_S_GA", loggerName, logger_e);
  1558. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetPLC_S_GA={ex.Message}");
  1559. return null;
  1560. }
  1561. }
  1562. }
  1563. }