GoodsAuto.cs 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644
  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. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  391. {
  392. outputMessage = $"[{e.Content}]SET_GoodsLevel=[{goodsLevel}]{plc_s.PLC_GOODSLEVEL_CODE + plc_s.PLC_GOODSLEVEL_CODENUM}";
  393. Logger.Trace(outputMessage, logKeyT, logger_t);
  394. FormLogShow?.ShowLog(outputMessage);
  395. p_r = plc?.Write<short>(plc_s.PLC_GOODSLEVEL_CODE, plc_s.PLC_GOODSLEVEL_CODENUM, goodsLevel);
  396. outputMessage = $"[{e.Content}]END_GoodsLevel=[{p_r.ToString()}]{plc_s.PLC_GOODSLEVEL_CODE + plc_s.PLC_GOODSLEVEL_CODENUM}";
  397. Logger.Trace(outputMessage, logKeyT, logger_t);
  398. FormLogShow?.ShowLog(outputMessage);
  399. }
  400. else
  401. {
  402. outputMessage = $"[{e.Content}]产品等级=[{goodsLevel}]";
  403. Logger.Trace(outputMessage, logKeyT, logger_t);
  404. FormLogShow?.ShowLog(outputMessage);
  405. }
  406. }
  407. #endregion
  408. #region 【可选】半检补土(适用于官塘)
  409. if (!string.IsNullOrEmpty(plc_s.PLC_SEMIREPAIR_CODE) && !string.IsNullOrEmpty(plc_s.PLC_SEMIREPAIR_CODENUM))
  410. {
  411. Int16 semiRepair = Convert.ToInt16(GetSemiRepair(barCode, e, logKeyT));
  412. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  413. {
  414. outputMessage = $"[{e.Content}]SET_SemiRepair=[{semiRepair}]{plc_s.PLC_SEMIREPAIR_CODE + plc_s.PLC_SEMIREPAIR_CODENUM}";
  415. Logger.Trace(outputMessage, logKeyT, logger_t);
  416. FormLogShow?.ShowLog(outputMessage);
  417. p_r = plc?.Write<short>(plc_s.PLC_SEMIREPAIR_CODE, plc_s.PLC_SEMIREPAIR_CODENUM, semiRepair);
  418. outputMessage = $"[{e.Content}]END_SemiRepair=[{p_r.ToString()}]{plc_s.PLC_SEMIREPAIR_CODE + plc_s.PLC_SEMIREPAIR_CODENUM}";
  419. Logger.Trace(outputMessage, logKeyT, logger_t);
  420. FormLogShow?.ShowLog(outputMessage);
  421. }
  422. else
  423. {
  424. outputMessage = $"[{e.Content}]半检补土=[{semiRepair}]";
  425. Logger.Trace(outputMessage, logKeyT, logger_t);
  426. FormLogShow?.ShowLog(outputMessage);
  427. }
  428. }
  429. #endregion
  430. #region 【可选】产品等级写入(重烧过的产品写6,非重烧的写4)(适用于官塘)
  431. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSLEVEL2_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSLEVEL2_CODENUM))
  432. {
  433. Int16 goodsLevel = Convert.ToInt16(GetGoodsLevel(barCode, e, logKeyT));
  434. //如果判定为重烧不算重烧品,暂时当副品,重烧过才真正算重烧
  435. if (goodsLevel == 6) goodsLevel = 5;
  436. goodsLevel = Convert.ToInt16(GetAutoFireID(barCode, goodsLevel.ToString(), "6", e, logKeyT));
  437. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  438. {
  439. outputMessage = $"[{e.Content}]SET_GoodsLevel2=[{goodsLevel}]{plc_s.PLC_GOODSLEVEL2_CODE + plc_s.PLC_GOODSLEVEL2_CODENUM}";
  440. Logger.Trace(outputMessage, logKeyT, logger_t);
  441. FormLogShow?.ShowLog(outputMessage);
  442. p_r = plc?.Write<short>(plc_s.PLC_GOODSLEVEL2_CODE, plc_s.PLC_GOODSLEVEL2_CODENUM, goodsLevel);
  443. outputMessage = $"[{e.Content}]END_GoodsLevel2=[{p_r.ToString()}]{plc_s.PLC_GOODSLEVEL2_CODE + plc_s.PLC_GOODSLEVEL2_CODENUM}";
  444. Logger.Trace(outputMessage, logKeyT, logger_t);
  445. FormLogShow?.ShowLog(outputMessage);
  446. }
  447. else
  448. {
  449. outputMessage = $"[{e.Content}]产品等级=[{goodsLevel}]";
  450. Logger.Trace(outputMessage, logKeyT, logger_t);
  451. FormLogShow?.ShowLog(outputMessage);
  452. }
  453. }
  454. #endregion
  455. #region 【可选】产品重烧标识写入
  456. if (!string.IsNullOrEmpty(plc_s.PLC_ISREFIRE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_ISREFIRE_CODENUM))
  457. {
  458. Int16 isRefire = Convert.ToInt16(GetAutoFireID(barCode, "1", "6", e, logKeyT));
  459. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  460. {
  461. outputMessage = $"[{e.Content}]SET_IsRefire=[{isRefire}]{plc_s.PLC_ISREFIRE_CODE + plc_s.PLC_ISREFIRE_CODENUM}";
  462. Logger.Trace(outputMessage, logKeyT, logger_t);
  463. FormLogShow?.ShowLog(outputMessage);
  464. p_r = plc?.Write<short>(plc_s.PLC_ISREFIRE_CODE, plc_s.PLC_ISREFIRE_CODENUM, isRefire);
  465. outputMessage = $"[{e.Content}]END_IsRefire=[{p_r.ToString()}]{plc_s.PLC_ISREFIRE_CODE + plc_s.PLC_ISREFIRE_CODENUM}";
  466. Logger.Trace(outputMessage, logKeyT, logger_t);
  467. FormLogShow?.ShowLog(outputMessage);
  468. }
  469. else
  470. {
  471. outputMessage = $"[{e.Content}]产品重烧=[{isRefire}]";
  472. Logger.Trace(outputMessage, logKeyT, logger_t);
  473. FormLogShow?.ShowLog(outputMessage);
  474. }
  475. }
  476. #endregion
  477. #region 【可选】质量登记返修写入(官塘厂)
  478. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSREPAIR_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSREPAIR_CODENUM))
  479. {
  480. Int16 goodsRepair = Convert.ToInt16(GetGoodsRepair(barCode, e, logKeyT));
  481. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  482. {
  483. outputMessage = $"[{e.Content}]SET_GoodsLevel=[{goodsRepair}]{plc_s.PLC_GOODSREPAIR_CODE + plc_s.PLC_GOODSREPAIR_CODENUM}";
  484. Logger.Trace(outputMessage, logKeyT, logger_t);
  485. FormLogShow?.ShowLog(outputMessage);
  486. p_r = plc?.Write<short>(plc_s.PLC_GOODSREPAIR_CODE, plc_s.PLC_GOODSREPAIR_CODENUM, goodsRepair);
  487. outputMessage = $"[{e.Content}]END_GoodsLevel=[{p_r.ToString()}]{plc_s.PLC_GOODSREPAIR_CODE + plc_s.PLC_GOODSREPAIR_CODENUM}";
  488. Logger.Trace(outputMessage, logKeyT, logger_t);
  489. FormLogShow?.ShowLog(outputMessage);
  490. }
  491. else
  492. {
  493. outputMessage = $"[{e.Content}]返修=[{goodsRepair}]";
  494. Logger.Trace(outputMessage, logKeyT, logger_t);
  495. FormLogShow?.ShowLog(outputMessage);
  496. }
  497. }
  498. #endregion
  499. #region 【可选】智能连体重烧写入,智能重烧253,连体重烧254,其他返回立库配置代码,未配置返回252(官塘厂)
  500. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSTYPEISREFIRE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSTYPEISREFIRE_CODENUM))
  501. {
  502. //产品代码读取
  503. string intCode = GetWareHouse(barCode, e, logKeyE);
  504. if (intCode == "") intCode = "252";
  505. //2022-10-13 xuwei modify
  506. /* 取消重烧分类(智能连体重烧写入,智能重烧253,连体重烧254)
  507. //重烧识别读取
  508. Int16 isRefire = Convert.ToInt16(GetAutoFireID(barCode, "1", "6", e, logKeyT));
  509. //重烧产品返回 智能253,连体254
  510. if (isRefire == 6)
  511. {
  512. //智能连体读取
  513. Int16 goodsType = Convert.ToInt16(GetGoodsType(barCode, e, logKeyT));
  514. if (goodsType == 1) intCode = "253";
  515. if (goodsType == 2) intCode = "254";
  516. }
  517. */
  518. //写入智能连体重烧标识
  519. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  520. {
  521. outputMessage = $"[{e.Content}]SET_GOODSTYPEISREFIRE=[{intCode}]{plc_s.PLC_GOODSTYPEISREFIRE_CODE + plc_s.PLC_GOODSTYPEISREFIRE_CODENUM}";
  522. Logger.Trace(outputMessage, logKeyT, logger_t);
  523. FormLogShow?.ShowLog(outputMessage);
  524. p_r = plc.Write<short>(plc_s.PLC_GOODSTYPEISREFIRE_CODE, plc_s.PLC_GOODSTYPEISREFIRE_CODENUM, (short)(intCode.ToInt32()));
  525. outputMessage = $"[{e.Content}]END_GOODSTYPEISREFIRE=[{p_r}]{plc_s.PLC_GOODSTYPEISREFIRE_CODE + plc_s.PLC_GOODSTYPEISREFIRE_CODENUM}";
  526. Logger.Trace(outputMessage, logKeyT, logger_t);
  527. FormLogShow?.ShowLog(outputMessage);
  528. }
  529. else
  530. {
  531. outputMessage = $"[{e.Content}]智能连体重烧=[{intCode}]";
  532. Logger.Trace(outputMessage, logKeyT, logger_t);
  533. FormLogShow?.ShowLog(outputMessage);
  534. }
  535. }
  536. #endregion
  537. #region 【可选】产品缺陷类别写入
  538. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSDEFECTTYPE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSDEFECTTYPE_CODENUM))
  539. {
  540. Int16 goodsDefectType = Convert.ToInt16(GetDefectTypeId(barCode, e, logKeyT));
  541. //如果是重烧产品写入 16 代替产品缺陷类别
  542. //goodsDefectType = Convert.ToInt16(GetAutoFireID(barCode, goodsDefectType.ToString(), "16", e, logKeyT));
  543. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  544. {
  545. outputMessage = $"[{e.Content}]SET_DefectType=[{goodsDefectType}]{plc_s.PLC_GOODSDEFECTTYPE_CODE + plc_s.PLC_GOODSDEFECTTYPE_CODENUM}";
  546. Logger.Trace(outputMessage, logKeyT, logger_t);
  547. FormLogShow?.ShowLog(outputMessage);
  548. p_r = plc?.Write<short>(plc_s.PLC_GOODSDEFECTTYPE_CODE, plc_s.PLC_GOODSDEFECTTYPE_CODENUM, goodsDefectType);
  549. outputMessage = $"[{e.Content}]END_DefectType=[{p_r.ToString()}]{plc_s.PLC_GOODSDEFECTTYPE_CODE + plc_s.PLC_GOODSDEFECTTYPE_CODENUM}";
  550. Logger.Trace(outputMessage, logKeyT, logger_t);
  551. FormLogShow?.ShowLog(outputMessage);
  552. }
  553. else
  554. {
  555. outputMessage = $"[{e.Content}]缺陷类别=[{goodsDefectType}]";
  556. Logger.Trace(outputMessage, logKeyT, logger_t);
  557. FormLogShow?.ShowLog(outputMessage);
  558. }
  559. }
  560. #endregion
  561. #region 【可选】成型工号写入
  562. if (!string.IsNullOrEmpty(plc_s.PLC_GROUTINGUSER_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GROUTINGUSER_CODENUM))
  563. {
  564. Int16 groutinguserCode = Convert.ToInt16(GetGroutingUserCode(barCode, e, logKeyT));
  565. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  566. {
  567. outputMessage = $"[{e.Content}]SET_GROUTINGUSER=[{groutinguserCode}]{plc_s.PLC_GROUTINGUSER_CODE + plc_s.PLC_GROUTINGUSER_CODENUM}";
  568. Logger.Trace(outputMessage, logKeyT, logger_t);
  569. FormLogShow?.ShowLog(outputMessage);
  570. p_r = plc?.Write<short>(plc_s.PLC_GROUTINGUSER_CODE, plc_s.PLC_GROUTINGUSER_CODENUM, groutinguserCode);
  571. outputMessage = $"[{e.Content}]END_GROUTINGUSER=[{p_r.ToString()}]{plc_s.PLC_GROUTINGUSER_CODE + plc_s.PLC_GROUTINGUSER_CODENUM}";
  572. Logger.Trace(outputMessage, logKeyT, logger_t);
  573. FormLogShow?.ShowLog(outputMessage);
  574. }
  575. else
  576. {
  577. outputMessage = $"[{e.Content}]成型工号=[{groutinguserCode}]";
  578. Logger.Trace(outputMessage, logKeyT, logger_t);
  579. FormLogShow?.ShowLog(outputMessage);
  580. }
  581. }
  582. #endregion
  583. #region 【可选】工序验证
  584. if (!string.IsNullOrEmpty(plc_s.PROCEDURE_CHECKID))
  585. {
  586. Int16 plc_flag = Convert.ToInt16(GetProcedureCheck(barCode, plc_s.PROCEDURE_CHECKID, e, logKeyT, logKeyE));
  587. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  588. {
  589. SendCode(plc_s, e, logKeyT, logKeyE, plc, plc_flag);
  590. }
  591. else
  592. {
  593. outputMessage = $"[{e.Content}]工序=[{plc_s.PROCEDURE_CHECKID}]工序验证=[{plc_flag}]";
  594. Logger.Trace(outputMessage, logKeyT, logger_t);
  595. FormLogShow?.ShowLog(outputMessage);
  596. }
  597. return;
  598. }
  599. #endregion
  600. #region 【可选】工序计件
  601. if (!string.IsNullOrEmpty(plc_s.PROCEDURE_ID) && (!string.IsNullOrEmpty(plc_s.PROCEDURE_USERCODE) || !string.IsNullOrEmpty(plc_s.WORKSTATION_ID)) )
  602. {
  603. //如果是重烧产品使用重烧ID
  604. if (!string.IsNullOrEmpty(plc_s.PROCEDURE_AUTOREFIRE_ID))
  605. {
  606. plc_s.PROCEDURE_ID = GetAutoFireID(barCode, plc_s.PROCEDURE_ID, plc_s.PROCEDURE_AUTOREFIRE_ID, e, logKeyE);
  607. }
  608. string p_id = GetFlowId(barCode, e, logKeyE);
  609. Int16 plc_flag = 0;
  610. if (p_id != plc_s.PROCEDURE_ID.ToString())
  611. {
  612. string userCode = "";
  613. //默认读取userCode
  614. if(!string.IsNullOrEmpty(plc_s.PROCEDURE_USERCODE))
  615. {
  616. userCode = plc_s.PROCEDURE_USERCODE;
  617. }
  618. //优先从工位取userCode
  619. if (!string.IsNullOrEmpty(plc_s.WORKSTATION_ID))
  620. {
  621. userCode = GetUserCodeFromWorkStation(plc_s.WORKSTATION_ID, e, logKeyE);
  622. outputMessage = $"[{e.Content}]DB_UserCode=[{userCode}]";
  623. Logger.Trace(outputMessage, logKeyT, logger_t);
  624. FormLogShow?.ShowLog(outputMessage);
  625. }
  626. //工序计件
  627. string result = SmartDeviceProxy.Instance.Invoke<string>(
  628. p => p.AddWorkPieceByStatus3(
  629. _mes_s.AccountCode,
  630. userCode,
  631. null,
  632. Convert.ToInt32(plc_s.PROCEDURE_ID),
  633. barCode,
  634. null));
  635. outputMessage = $"[{e.Content}]工序=[{plc_s.PROCEDURE_ID}]工号=[{userCode}]工序计件=[{result}]";
  636. Logger.Trace(outputMessage, logKeyT, logger_t);
  637. FormLogShow?.ShowLog(outputMessage);
  638. // 返回状态(成功、失败)
  639. if (result != "OK")
  640. {
  641. plc_flag = 3;
  642. if (result == "EE")
  643. {
  644. plc_flag = 4;
  645. outputMessage = $"MES服务端异常(详情参见MES端日志)";
  646. }
  647. else if (result == "EU-01")
  648. {
  649. outputMessage = $"无效的帐套或工号(详情参见MES端日志)";
  650. }
  651. else
  652. {
  653. outputMessage = $"其他错误(详情参见MES端日志)[{result}]";
  654. }
  655. Logger.Error(null, outputMessage, logKeyT, logger_t);
  656. Logger.Error(null, outputMessage, logKeyE, logger_e);
  657. FormLogShow?.ShowLog(outputMessage);
  658. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  659. {
  660. SendCode(plc_s, e, logKeyT, logKeyE, plc, plc_flag);
  661. }
  662. return;
  663. }
  664. }
  665. }
  666. #endregion
  667. #region 【可选】工序计件,二检交接,干补过给6,未干补过正常计件
  668. if (!string.IsNullOrEmpty(plc_s.PROCEDURE_DRYREPAIR_ID) && (!string.IsNullOrEmpty(plc_s.PROCEDURE_USERCODE) || !string.IsNullOrEmpty(plc_s.WORKSTATION_ID)))
  669. {
  670. string dryRepair = GetDryRepair(barCode, e, logKeyE);
  671. if(dryRepair == "0")
  672. {
  673. string p_id = GetFlowId(barCode, e, logKeyE);
  674. Int16 plc_flag = 0;
  675. if (p_id != plc_s.PROCEDURE_DRYREPAIR_ID.ToString())
  676. {
  677. string userCode = "";
  678. //默认读取userCode
  679. if (!string.IsNullOrEmpty(plc_s.PROCEDURE_USERCODE))
  680. {
  681. userCode = plc_s.PROCEDURE_USERCODE;
  682. }
  683. //优先从工位取userCode
  684. if (!string.IsNullOrEmpty(plc_s.WORKSTATION_ID))
  685. {
  686. userCode = GetUserCodeFromWorkStation(plc_s.WORKSTATION_ID, e, logKeyE);
  687. outputMessage = $"[{e.Content}]DB_UserCode=[{userCode}]";
  688. Logger.Trace(outputMessage, logKeyT, logger_t);
  689. FormLogShow?.ShowLog(outputMessage);
  690. }
  691. //工序计件
  692. string result = SmartDeviceProxy.Instance.Invoke<string>(
  693. p => p.AddWorkPieceByStatus3(
  694. _mes_s.AccountCode,
  695. userCode,
  696. null,
  697. Convert.ToInt32(plc_s.PROCEDURE_DRYREPAIR_ID),
  698. barCode,
  699. null));
  700. outputMessage = $"[{e.Content}]工序=[{plc_s.PROCEDURE_DRYREPAIR_ID}]工号=[{userCode}]工序计件=[{result}]";
  701. Logger.Trace(outputMessage, logKeyT, logger_t);
  702. FormLogShow?.ShowLog(outputMessage);
  703. // 返回状态(成功、失败)
  704. if (result != "OK")
  705. {
  706. plc_flag = 3;
  707. if (result == "EE")
  708. {
  709. plc_flag = 4;
  710. outputMessage = $"MES服务端异常(详情参见MES端日志)";
  711. }
  712. else if (result == "EU-01")
  713. {
  714. outputMessage = $"无效的帐套或工号(详情参见MES端日志)";
  715. }
  716. else
  717. {
  718. outputMessage = $"其他错误(详情参见MES端日志)[{result}]";
  719. }
  720. Logger.Error(null, outputMessage, logKeyT, logger_t);
  721. Logger.Error(null, outputMessage, logKeyE, logger_e);
  722. FormLogShow?.ShowLog(outputMessage);
  723. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  724. {
  725. SendCode(plc_s, e, logKeyT, logKeyE, plc, plc_flag);
  726. }
  727. return;
  728. }
  729. }
  730. }
  731. if(dryRepair == "1")
  732. {
  733. SendCode(plc_s, e, logKeyT, logKeyE, plc, 6);
  734. return;
  735. }
  736. }
  737. #endregion
  738. #region 【可选】工序计件(产品等级判定为重烧的产品自动重烧交接工序计件)(官塘厂)
  739. if (!string.IsNullOrEmpty(plc_s.PROCEDURE_REFIRE_RECIVE_ID) && (!string.IsNullOrEmpty(plc_s.PROCEDURE_REFIRE_RECIVE_USERCODE) ))
  740. {
  741. //识别是否判定为重烧的产品
  742. Int16 goodsLevel = Convert.ToInt16(GetGoodsLevel(barCode, e, logKeyT));
  743. if(goodsLevel == 6)
  744. {
  745. string p_id = GetFlowId(barCode, e, logKeyE);
  746. Int16 plc_flag = 0;
  747. if (p_id != plc_s.PROCEDURE_REFIRE_RECIVE_ID.ToString())
  748. {
  749. string userCode = "";
  750. //默认读取userCode
  751. if (!string.IsNullOrEmpty(plc_s.PROCEDURE_REFIRE_RECIVE_USERCODE))
  752. {
  753. userCode = plc_s.PROCEDURE_REFIRE_RECIVE_USERCODE;
  754. }
  755. //工序计件
  756. string result = SmartDeviceProxy.Instance.Invoke<string>(
  757. p => p.AddWorkPieceByStatus3(
  758. _mes_s.AccountCode,
  759. userCode,
  760. null,
  761. Convert.ToInt32(plc_s.PROCEDURE_REFIRE_RECIVE_ID),
  762. barCode,
  763. null));
  764. outputMessage = $"[{e.Content}]工序=[{plc_s.PROCEDURE_REFIRE_RECIVE_ID}]工号=[{userCode}]工序计件=[{result}]";
  765. Logger.Trace(outputMessage, logKeyT, logger_t);
  766. FormLogShow?.ShowLog(outputMessage);
  767. // 返回状态(成功、失败)
  768. if (result != "OK")
  769. {
  770. plc_flag = 3;
  771. if (result == "EE")
  772. {
  773. plc_flag = 4;
  774. outputMessage = $"MES服务端异常(详情参见MES端日志)";
  775. }
  776. else if (result == "EU-01")
  777. {
  778. outputMessage = $"无效的帐套或工号(详情参见MES端日志)";
  779. }
  780. else
  781. {
  782. outputMessage = $"其他错误(详情参见MES端日志)[{result}]";
  783. }
  784. Logger.Error(null, outputMessage, logKeyT, logger_t);
  785. Logger.Error(null, outputMessage, logKeyE, logger_e);
  786. FormLogShow?.ShowLog(outputMessage);
  787. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  788. {
  789. SendCode(plc_s, e, logKeyT, logKeyE, plc, plc_flag);
  790. }
  791. return;
  792. }
  793. }
  794. }
  795. }
  796. #endregion
  797. #region 【可选】(传入其他PLC数据)
  798. if (!string.IsNullOrEmpty(plc_s.PLC_IP_NEW))
  799. {
  800. //创建新的PLC连接
  801. SocketClient<SiemensS7_1200Model> plcnew = new SocketClient<SiemensS7_1200Model>();
  802. plcnew.Connect(plc_s.PLC_IP_NEW, plc_s.PLC_PORT);
  803. string intCode = "";
  804. //产品型号代码
  805. if (!string.IsNullOrEmpty(plc_s.PLC_SEATCOVER_CODE_OTHER) && !string.IsNullOrEmpty(plc_s.PLC_SEATCOVER_CODENUM_OTHER))
  806. {
  807. intCode = GetSeatCoverCode(barCode, e, logKeyE);
  808. if (string.IsNullOrWhiteSpace(intCode))
  809. {
  810. outputMessage = $"[{e.Content}]此条码[{barCode}]未设置型号代码";
  811. Logger.Error(null, outputMessage, logKeyT, logger_t);
  812. Logger.Error(null, outputMessage, logKeyE, logger_e);
  813. FormLogShow?.ShowLog(outputMessage);
  814. string outputMessages = $"[{e.Content}]SET_FLAG_CODE_OTHER[{2}]{plc_s.PLC_FLAG_CODE_OTHER + plc_s.PLC_FLAG_CODENUM_OTHER}";
  815. Logger.Trace(outputMessages, logKeyT, logger_t);
  816. FormLogShow?.ShowLog(outputMessages);
  817. plcnew?.Write<short>(plc_s.PLC_FLAG_CODE_OTHER, plc_s.PLC_FLAG_CODENUM_OTHER, 2);
  818. Logger.Trace(outputMessages, logKeyT, logger_t);
  819. FormLogShow?.ShowLog(outputMessage);
  820. return;
  821. }
  822. outputMessage = $"[{e.Content}]SET_SEATCOVER_OTHER=[{intCode}]{plc_s.PLC_SEATCOVER_CODE_OTHER + plc_s.PLC_SEATCOVER_CODENUM_OTHER}";
  823. Logger.Trace(outputMessage, logKeyT, logger_t);
  824. FormLogShow?.ShowLog(outputMessage);
  825. p_r = plcnew.Write<short>(plc_s.PLC_SEATCOVER_CODE_OTHER, plc_s.PLC_SEATCOVER_CODENUM_OTHER, (short)(intCode.ToInt32()));
  826. p_r = plcnew.Write<short>(plc_s.PLC_SEATCOVER_CODE_OTHER, plc_s.PLC_SEATCOVER_CODENUM_OTHER, intCode.ToInt16());
  827. outputMessage = $"[{e.Content}]END_SEATCOVER_OTHER=[{p_r.ToString()}]{plc_s.PLC_SEATCOVER_CODE_OTHER + plc_s.PLC_SEATCOVER_CODENUM_OTHER}";
  828. Logger.Trace(outputMessage, logKeyT, logger_t);
  829. FormLogShow?.ShowLog(outputMessage);
  830. }
  831. //产品型号
  832. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSCODE_CODE_OTHER) && !string.IsNullOrEmpty(plc_s.PLC_GOODSCODE_CODENUM_OTHER))
  833. {
  834. string goodsCode = GetGoodsCode(barCode, e, logKeyE);
  835. outputMessage = $"[{e.Content}]SET_GOODSCODE_OTHER=[{goodsCode}]{plc_s.PLC_GOODSCODE_CODE_OTHER + plc_s.PLC_GOODSCODE_CODENUM_OTHER}";
  836. Logger.Trace(outputMessage, logKeyT, logger_t);
  837. FormLogShow?.ShowLog(outputMessage);
  838. p_r = plcnew.Write<string>(plc_s.PLC_GOODSCODE_CODE_OTHER, plc_s.PLC_GOODSCODE_CODENUM_OTHER, goodsCode);
  839. //再传一遍
  840. p_r = plcnew.Write<short>(plc_s.PLC_SEATCOVER_CODE_OTHER, plc_s.PLC_SEATCOVER_CODENUM_OTHER, intCode.ToInt16());
  841. outputMessage = $"[{e.Content}]END_GOODSCODE_OTHER=[{p_r}]{plc_s.PLC_GOODSCODE_CODE_OTHER + plc_s.PLC_GOODSCODE_CODENUM_OTHER}";
  842. Logger.Trace(outputMessage, logKeyT, logger_t);
  843. FormLogShow?.ShowLog(outputMessage);
  844. }
  845. //当前条码
  846. if (!string.IsNullOrEmpty(plc_s.PLC_BARCODE_CODE_OTHER) && !string.IsNullOrEmpty(plc_s.PLC_BARCODE_CODENUM_OTHER))
  847. {
  848. outputMessage = $"[{e.Content}]SET_BarCode_OTHER=[{barCode}]{plc_s.PLC_BARCODE_CODE_OTHER + plc_s.PLC_BARCODE_CODENUM_OTHER}";
  849. Logger.Trace(outputMessage, logKeyT, logger_t);
  850. FormLogShow?.ShowLog(outputMessage);
  851. p_r = plcnew.Write<string>(plc_s.PLC_BARCODE_CODE_OTHER, plc_s.PLC_BARCODE_CODENUM_OTHER, barCode);
  852. outputMessage = $"[{e.Content}]END_BarCode_OTHER=[{p_r}]{plc_s.PLC_BARCODE_CODE_OTHER + plc_s.PLC_BARCODE_CODENUM_OTHER}";
  853. Logger.Trace(outputMessage, logKeyT, logger_t);
  854. FormLogShow?.ShowLog(outputMessage);
  855. }
  856. //扫码结果
  857. if (!string.IsNullOrEmpty(plc_s.PLC_FLAG_CODE_OTHER) && !string.IsNullOrEmpty(plc_s.PLC_FLAG_CODENUM_OTHER))
  858. {
  859. string outputMessages = $"[{e.Content}]SET_FLAG_CODE_OTHER[{1}]{plc_s.PLC_FLAG_CODE_OTHER + plc_s.PLC_FLAG_CODENUM_OTHER}";
  860. Logger.Trace(outputMessages, logKeyT, logger_t);
  861. FormLogShow?.ShowLog(outputMessages);
  862. p_r = plcnew?.Write<short>(plc_s.PLC_FLAG_CODE_OTHER, plc_s.PLC_FLAG_CODENUM_OTHER, 1);
  863. outputMessage = $"[{e.Content}]SET_FLAG_CODE_OTHER=[{p_r}]{plc_s.PLC_FLAG_CODE_OTHER + plc_s.PLC_FLAG_CODENUM_OTHER}";
  864. Logger.Trace(outputMessages, logKeyT, logger_t);
  865. FormLogShow?.ShowLog(outputMessage);
  866. }
  867. plcnew.Close();
  868. }
  869. #endregion
  870. #region 【可选】写入PLC扫码结果 【1:通过,2:扫码异常,3:工序异常,0:复位】
  871. if (!string.IsNullOrEmpty(plc_s.PLC_FLAG_CODE) && !string.IsNullOrEmpty(plc_s.PLC_FLAG_CODENUM))
  872. {
  873. if (!string.IsNullOrEmpty(plc_s.PLC_IP))
  874. {
  875. SendCode(plc_s, e, logKeyT, logKeyE, plc, 1);
  876. }
  877. else
  878. {
  879. outputMessage = $"[{e.Content}]PLC标识=[1]";
  880. Logger.Trace(outputMessage, logKeyT, logger_t);
  881. FormLogShow?.ShowLog(outputMessage);
  882. }
  883. }
  884. #endregion
  885. }
  886. }
  887. catch (Exception ex)
  888. {
  889. FormLogShow?.ShowLog($"[{e.Content}]ERROR={ex.Message}");
  890. if (plc_s != null)
  891. {
  892. Logger.Error(ex, $"[{e.Content}]ERROR", logKeyT, logger_t);
  893. Logger.Error(ex, $"[{e.Content}]ERROR", logKeyE, logger_e);
  894. SendCode(plc_s, e, logKeyT, logKeyE, plc, 2);
  895. }
  896. else
  897. {
  898. Logger.Error(ex, $"[{e.Content}]ERROR-NOFLAG", logKeyT, logger_t);
  899. Logger.Error(ex, $"[{e.Content}]ERROR-NOFLAG", logKeyE, logger_e);
  900. }
  901. }
  902. finally
  903. {
  904. LoggerT?.EndTracking();
  905. plc?.Disconnect();
  906. plc?.Close();
  907. }
  908. }
  909. private void SendCode(PLC_S_GA plc_s, ReceiveSession e, string loggerNameT, string loggerNameE, SocketClient<SiemensS7_1200Model> plc, short code)
  910. {
  911. try
  912. {
  913. string outputMessage = $"[{e.Content}]SET_FLAG_CODE=[{code}]{plc_s.PLC_FLAG_CODE + plc_s.PLC_FLAG_CODENUM}";
  914. Logger.Trace(outputMessage, loggerNameT, logger_t);
  915. FormLogShow?.ShowLog(outputMessage);
  916. PLCResult p_r = plc?.Write<short>(plc_s.PLC_FLAG_CODE, plc_s.PLC_FLAG_CODENUM, (short)code);
  917. outputMessage = $"[{e.Content}]SET_FLAG_CODE=[{p_r}]{plc_s.PLC_FLAG_CODE + plc_s.PLC_FLAG_CODENUM}";
  918. Logger.Trace(outputMessage, loggerNameT, logger_t);
  919. FormLogShow?.ShowLog(outputMessage);
  920. }
  921. catch (Exception ex)
  922. {
  923. Logger.Error(ex, $"[{e.Content}]ERROR-SendCode", loggerNameT, logger_t);
  924. Logger.Error(ex, $"[{e.Content}]ERROR-SendCode", loggerNameE, logger_e);
  925. FormLogShow?.ShowLog($"[{e.Content}]ERROR-SendCode={ex.Message}");
  926. }
  927. }
  928. private string GetGoodsCode(string barCode, ReceiveSession e, string loggerName)
  929. {
  930. try
  931. {
  932. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  933. {
  934. string sqlStr = @"
  935. SELECT
  936. GDD.GOODSCODE
  937. FROM
  938. TP_PM_GROUTINGDAILYDETAIL GDD
  939. WHERE
  940. GDD.BARCODE = :BARCODE
  941. ";
  942. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  943. return result == null ? "" : result.ToString();
  944. }
  945. }
  946. catch (Exception ex)
  947. {
  948. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsCode", loggerName, logger_e);
  949. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsCode={ex.Message}");
  950. return null;
  951. }
  952. }
  953. private string GetSeatCoverCode(string barCode, ReceiveSession e, string loggerName)
  954. {
  955. try
  956. {
  957. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  958. {
  959. string sqlStr = @"
  960. SELECT
  961. G.SEATCOVERCODE
  962. FROM
  963. TP_PM_GROUTINGDAILYDETAIL GDD
  964. INNER JOIN TP_MST_GOODS G ON G.GOODSID = GDD.GOODSID
  965. WHERE
  966. GDD.BARCODE = :BARCODE
  967. ";
  968. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  969. return result == null ? "" : result.ToString();
  970. }
  971. }
  972. catch (Exception ex)
  973. {
  974. Logger.Error(ex, $"[{e.Content}]ERROR-GetSeatCoverCode", loggerName, logger_e);
  975. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetSeatCoverCode={ex.Message}");
  976. return null;
  977. }
  978. }
  979. private string GetGoodsType(string barCode, ReceiveSession e, string loggerName)
  980. {
  981. try
  982. {
  983. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  984. {
  985. string sqlStr = @"
  986. SELECT
  987. -- G.GOODSCODE,
  988. -- G.SEATCOVERCODE,
  989. CASE
  990. WHEN T.GOODSTYPECODE = '001001001' THEN 2 --连体
  991. WHEN T.GOODSTYPECODE = '001001002' THEN 3 --分体
  992. WHEN T.GOODSTYPECODE = '001001003' THEN 1 --智能
  993. WHEN T.GOODSTYPECODE = '001001004' THEN 1 --智能高压
  994. ELSE 0 --其他
  995. END AS GOODSTYPE
  996. FROM
  997. TP_PM_GROUTINGDAILYDETAIL GDD
  998. INNER JOIN TP_MST_GOODS G ON G.GOODSID = GDD.GOODSID
  999. INNER JOIN TP_MST_GOODSTYPE T ON G.GOODSTYPEID = T.GOODSTYPEID
  1000. WHERE
  1001. GDD.BARCODE = :BARCODE --'10006800247'
  1002. ";
  1003. string goodsType = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode)).ToString();
  1004. return goodsType;
  1005. }
  1006. }
  1007. catch (Exception ex)
  1008. {
  1009. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsType", loggerName, logger_e);
  1010. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsType={ex.Message}");
  1011. return "0";
  1012. }
  1013. }
  1014. private string GetFlowId(string barCode, ReceiveSession e, string loggerName)
  1015. {
  1016. try
  1017. {
  1018. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  1019. {
  1020. string sqlStr = @"
  1021. SELECT
  1022. GDD.FLOWPROCEDUREID
  1023. FROM
  1024. TP_PM_INPRODUCTION GDD
  1025. WHERE
  1026. GDD.BARCODE = :BARCODE
  1027. ";
  1028. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  1029. return result == null ? "0" : result.ToString();
  1030. }
  1031. }
  1032. catch (Exception ex)
  1033. {
  1034. Logger.Error(ex, $"[{e.Content}]ERROR-GetFlowId", loggerName, logger_e);
  1035. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetFlowId={ex.Message}");
  1036. return "0";
  1037. }
  1038. }
  1039. private string GetAutoFireID(string barCode, string procedureId, string autoFireId, ReceiveSession e, string loggerName)
  1040. {
  1041. try
  1042. {
  1043. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  1044. {
  1045. string sqlStr = @"
  1046. SELECT T.ISREFIRE
  1047. FROM TP_PM_INPRODUCTION T
  1048. WHERE T.BARCODE = :BARCODE
  1049. UNION
  1050. SELECT T.ISREFIRE
  1051. FROM TP_PM_INPRODUCTIONTRASH T
  1052. WHERE T.BARCODE = :BARCODE
  1053. ";
  1054. string result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode)).ToString();
  1055. if (result == "6")
  1056. return autoFireId;
  1057. else
  1058. return procedureId;
  1059. }
  1060. }
  1061. catch (Exception ex)
  1062. {
  1063. Logger.Error(ex, $"[{e.Content}]ERROR-GetAutoFireID", loggerName, logger_e);
  1064. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetAutoFireID={ex.Message}");
  1065. return "0";
  1066. }
  1067. }
  1068. private string GetUserCodeFromWorkStation(string workStationId, ReceiveSession e, string loggerName)
  1069. {
  1070. try
  1071. {
  1072. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  1073. {
  1074. string sqlStr = @"
  1075. SELECT
  1076. T.USERCODE
  1077. FROM
  1078. TP_MST_WORKSTATION T
  1079. INNER JOIN TP_MST_USER U ON U.USERCODE = T.USERCODE
  1080. WHERE
  1081. T.WORKSTATIONID = :WORKSTATIONID
  1082. ";
  1083. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":WORKSTATIONID", workStationId));
  1084. return result == null ? "0" : result.ToString();
  1085. }
  1086. }
  1087. catch (Exception ex)
  1088. {
  1089. Logger.Error(ex, $"[{e.Content}]ERROR-GetUserCodeFromWorkStation", loggerName, logger_e);
  1090. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetUserCodeFromWorkStation={ex.Message}");
  1091. return "0";
  1092. }
  1093. }
  1094. private string GetSemiReWork(string barCode, ReceiveSession e, string loggerName)
  1095. {
  1096. try
  1097. {
  1098. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  1099. {
  1100. string sqlStr = @"
  1101. SELECT
  1102. P.ISREWORKFLAG
  1103. FROM
  1104. TP_PM_INPRODUCTION P
  1105. WHERE
  1106. P.BARCODE = :BARCODE
  1107. ";
  1108. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  1109. //返工标识(0:正常,1:半检返工中, 2:半检返修)
  1110. //没找到记录表明产品报废写 3
  1111. string resultFlag = "0";
  1112. if(result !=null)
  1113. {
  1114. if (result.ToString() == "0") resultFlag = "1"; //正常
  1115. if (result.ToString() == "1" || result.ToString() == "2") resultFlag = "2";//返工
  1116. }
  1117. else
  1118. {
  1119. resultFlag = "3";//报废
  1120. }
  1121. return resultFlag;
  1122. }
  1123. }
  1124. catch (Exception ex)
  1125. {
  1126. Logger.Error(ex, $"[{e.Content}]ERROR-GetSemiReWork", loggerName, logger_e);
  1127. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetSemiReWork={ex.Message}");
  1128. return "0";
  1129. }
  1130. }
  1131. private string GetGoodsLevel(string barCode, ReceiveSession e, string loggerName)
  1132. {
  1133. try
  1134. {
  1135. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  1136. {
  1137. string sqlStr = @"
  1138. SELECT GL.GOODSLEVELTYPEID
  1139. FROM TP_PM_GROUTINGDAILYDETAIL GDD
  1140. LEFT JOIN TP_MST_GOODSLEVEL GL
  1141. ON GDD.GOODSLEVELTYPEID = GL.GOODSLEVELTYPEID
  1142. WHERE GDD.BARCODE = :BARCODE
  1143. ";
  1144. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  1145. return result == null ? "0" : result.ToString();
  1146. }
  1147. }
  1148. catch (Exception ex)
  1149. {
  1150. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsLevel", loggerName, logger_e);
  1151. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsLevel={ex.Message}");
  1152. return "0";
  1153. }
  1154. }
  1155. private string GetGoodsRepair(string barCode, ReceiveSession e, string loggerName)
  1156. {
  1157. try
  1158. {
  1159. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  1160. {
  1161. string sqlStr = @"
  1162. SELECT
  1163. DECODE( GR.REPAIRPATH, NULL, GDD.GOODSLEVELTYPEID, 0, GDD.GOODSLEVELTYPEID, GR.REPAIRPATH )
  1164. FROM
  1165. TP_PM_GROUTINGDAILYDETAIL GDD
  1166. LEFT JOIN TP_PM_GOODSREPAIR GR ON GDD.BARCODE = GR.BARCODE
  1167. AND GR.VALUEFLAG = 1
  1168. WHERE
  1169. GDD.VALUEFLAG = 1
  1170. AND GDD.BARCODE = @BARCODE@
  1171. ";
  1172. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  1173. return result == null ? "0" : result.ToString();
  1174. }
  1175. }
  1176. catch (Exception ex)
  1177. {
  1178. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsRepair", loggerName, logger_e);
  1179. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsRepair={ex.Message}");
  1180. return "0";
  1181. }
  1182. }
  1183. private string GetProcedureCheck(string barCode,string procedureId, ReceiveSession e, string loggerNameT, string loggerNameE)
  1184. {
  1185. try
  1186. {
  1187. using (IDataAccess dataAccess = PLC_S_DataAccess.GetDataAccess())
  1188. {
  1189. CDAParameter[] parameters = new CDAParameter[]
  1190. {
  1191. new CDAParameter("in_procedureid", procedureId),
  1192. new CDAParameter("in_barcode", barCode),
  1193. new CDAParameter("out_errType",DataType.Int32, ParameterDirection.Output),
  1194. new CDAParameter("out_errMsg",DataType.VarChar, 4000, ParameterDirection.Output),
  1195. new CDAParameter("out_goodsID",DataType.Int32, ParameterDirection.Output),
  1196. new CDAParameter("out_goodsCode",DataType.VarChar, 400, ParameterDirection.Output),
  1197. new CDAParameter("out_goodsType",DataType.Int32, ParameterDirection.Output),
  1198. };
  1199. int ii = dataAccess.ExecuteSPNonQuery("PRO_PM_CheckBarcode_PLC", parameters);
  1200. Int16 plc_flag = 0;
  1201. if (!int.TryParse(parameters[2].Value + "", out int errtype))
  1202. {
  1203. errtype = 4;
  1204. }
  1205. // 其他情况显示MES异常
  1206. if (errtype == 4)
  1207. {
  1208. plc_flag = 4;
  1209. }
  1210. else if (errtype == 0)
  1211. {
  1212. plc_flag = 1;
  1213. }
  1214. else // errtype == 1 || errtype == 2 || errtype == 3
  1215. {
  1216. // 无效条码,显示不可到达
  1217. plc_flag = 3;
  1218. }
  1219. string outputMessage = $"[{e.Content}]MESSAGE=[{errtype}][{parameters[3].Value}]";
  1220. Logger.Trace(outputMessage, loggerNameT, logger_t);
  1221. FormLogShow?.ShowLog(outputMessage);
  1222. return plc_flag.ToString();
  1223. }
  1224. }
  1225. catch (Exception ex)
  1226. {
  1227. Logger.Error(ex, $"[{e.Content}]ERROR-GetProcedureCheck", loggerNameE, logger_e);
  1228. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetProcedureCheck={ex.Message}");
  1229. return "0";
  1230. }
  1231. }
  1232. private string GetDefectTypeId(string barCode, ReceiveSession e, string loggerName)
  1233. {
  1234. try
  1235. {
  1236. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  1237. {
  1238. string sqlStr = @"
  1239. SELECT D.DEFECTCODE, D.DEFECTNAME, DT.DEFECTTYPENAME, DT.DEFECTTYPEID, DT.REMARKS
  1240. FROM TP_PM_DEFECT PD
  1241. LEFT JOIN TP_MST_DEFECT D
  1242. ON PD.DEFECTID = D.DEFECTID
  1243. LEFT JOIN TP_MST_DEFECTTYPE DT
  1244. ON D.DEFECTTYPEID = DT.DEFECTTYPEID
  1245. WHERE D.VALUEFLAG = 1
  1246. AND PD.VALUEFLAG = 1
  1247. AND DT.DEFECTTYPEID <> 21
  1248. AND BARCODE = :BARCODE
  1249. ORDER BY D.CREATETIME DESC
  1250. ";
  1251. DataTable dt = conn.ExecuteDatatable(sqlStr, new CDAParameter(":BARCODE", barCode));
  1252. if (dt.Rows.Count > 0)
  1253. {
  1254. return dt.Rows[0]["REMARKS"].ToString();
  1255. }
  1256. else
  1257. {
  1258. return "0";
  1259. }
  1260. }
  1261. }
  1262. catch (Exception ex)
  1263. {
  1264. Logger.Error(ex, $"[{e.Content}]ERROR-GetDefectTypeId", loggerName, logger_e);
  1265. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetDefectTypeId={ex.Message}");
  1266. return "0";
  1267. }
  1268. }
  1269. //查询成型工号
  1270. private int GetGroutingUserCode(string barCode, ReceiveSession e, string loggerName)
  1271. {
  1272. try
  1273. {
  1274. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  1275. {
  1276. string sqlStr = @"
  1277. SELECT substr(GDD.USERCODE,2 ) USERCODE
  1278. FROM TP_PM_GROUTINGDAILYDETAIL GDD
  1279. WHERE GDD.BARCODE = :BARCODE
  1280. ";
  1281. DataTable dt = conn.ExecuteDatatable(sqlStr, new CDAParameter(":BARCODE", barCode));
  1282. if (dt.Rows.Count > 0)
  1283. {
  1284. string usercode = dt.Rows[0]["USERCODE"].ToString();
  1285. return Convert.ToInt16(usercode);
  1286. }
  1287. else
  1288. {
  1289. return 0;
  1290. }
  1291. }
  1292. }
  1293. catch (Exception ex)
  1294. {
  1295. Logger.Error(ex, $"[{e.Content}]ERROR-GetDefectTypeId", loggerName, logger_e);
  1296. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetDefectTypeId={ex.Message}");
  1297. return 0;
  1298. }
  1299. }
  1300. private string GetSemiRepair(string barCode,ReceiveSession e,string loggerName)
  1301. {
  1302. try
  1303. {
  1304. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  1305. {
  1306. string sqlStr = @"
  1307. SELECT GL.GOODSLEVELTYPEID
  1308. FROM TP_PM_GROUTINGDAILYDETAIL GDD
  1309. LEFT JOIN TP_MST_GOODSLEVEL GL
  1310. ON GDD.GOODSLEVELTYPEID = GL.GOODSLEVELTYPEID
  1311. WHERE GDD.BARCODE = :BARCODE
  1312. ";
  1313. object goodsLevel = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  1314. sqlStr = @"
  1315. SELECT
  1316. 99
  1317. FROM
  1318. TP_PM_INPRODUCTION
  1319. WHERE
  1320. BARCODE = :BARCODE
  1321. AND PROCEDUREID = 64 --完成的最后一个工序是1#二检补土时直接return 99(作为二检补土识别)
  1322. ";
  1323. object semiRepair = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  1324. if (semiRepair != null)
  1325. {
  1326. return semiRepair.ToString();
  1327. }
  1328. else
  1329. {
  1330. return goodsLevel.ToString();
  1331. }
  1332. }
  1333. }
  1334. catch (Exception ex)
  1335. {
  1336. Logger.Error(ex, $"[{e.Content}]ERROR-GetSemiReWork", loggerName, logger_e);
  1337. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetSemiReWork={ex.Message}");
  1338. return "0";
  1339. }
  1340. }
  1341. private string GetWareHouse(string barCode, ReceiveSession e, string loggerName)
  1342. {
  1343. try
  1344. {
  1345. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  1346. {
  1347. string sqlStr = @"
  1348. SELECT
  1349. PART
  1350. FROM
  1351. (
  1352. SELECT
  1353. T.PART,','
  1354. || LISTAGG ( T.GOODSID1, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
  1355. || LISTAGG ( T.GOODSID2, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
  1356. || LISTAGG ( T.GOODSID3, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
  1357. || LISTAGG ( T.GOODSID4, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
  1358. || LISTAGG ( T.GOODSID5, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
  1359. || LISTAGG ( T.GOODSID6, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
  1360. || LISTAGG ( T.GOODSID7, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
  1361. || LISTAGG ( T.GOODSID8, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
  1362. || LISTAGG ( T.GOODSID9, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
  1363. || LISTAGG ( T.GOODSID10, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ',' AS SQLSTR
  1364. FROM
  1365. (
  1366. SELECT
  1367. m.SETTINGNO AS part,
  1368. M.GOODSID1,
  1369. M.GOODSID2,
  1370. M.GOODSID3,
  1371. M.GOODSID4,
  1372. M.GOODSID5,
  1373. M.GOODSID6,
  1374. M.GOODSID7,
  1375. M.GOODSID8,
  1376. M.GOODSID9,
  1377. M.GOODSID10
  1378. FROM
  1379. TP_MST_WAREHOUSESETTING M
  1380. ) T
  1381. GROUP BY
  1382. T.PART
  1383. ) TT
  1384. WHERE
  1385. INSTR( TT.SQLSTR, ',' || ( SELECT GOODSID FROM TP_PM_GROUTINGDAILYDETAIL WHERE BARCODE = :BARCODE) || ',' ) > 0
  1386. ";
  1387. string wareHouse = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode)).ToString();
  1388. return wareHouse;
  1389. }
  1390. }
  1391. catch (Exception ex)
  1392. {
  1393. Logger.Error(ex, $"[{e.Content}]ERROR-GetWareHouse", loggerName, logger_e);
  1394. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetWareHouse={ex.Message}");
  1395. return "0";
  1396. }
  1397. }
  1398. private string GetDryRepair(string barCode, ReceiveSession e, string loggerName)
  1399. {
  1400. try
  1401. {
  1402. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  1403. {
  1404. string sqlStr = @"
  1405. SELECT
  1406. CASE WHEN PROCEDUREID = 65 THEN '1' ELSE '0' END AS DRY
  1407. FROM
  1408. TP_PM_PRODUCTIONDATA
  1409. WHERE
  1410. BARCODE = @BARCODE@
  1411. AND ROWNUM = 1
  1412. ORDER BY
  1413. PRODUCTIONDATAID DESC
  1414. ";
  1415. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  1416. return result == null ? "0" : result.ToString();
  1417. }
  1418. }
  1419. catch (Exception ex)
  1420. {
  1421. Logger.Error(ex, $"[{e.Content}]ERROR-GetDryRepair", loggerName, logger_e);
  1422. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetDryRepair={ex.Message}");
  1423. return "0";
  1424. }
  1425. }
  1426. private PLC_S_GA GetPLC_S_GA(string flag, ReceiveSession e, string loggerName)
  1427. {
  1428. try
  1429. {
  1430. flag = M_NAME + flag;
  1431. if (PLC_FLAGS.ContainsKey(flag))
  1432. {
  1433. return PLC_FLAGS[flag];
  1434. }
  1435. else
  1436. {
  1437. PLC_S_GA plc_s = new PLC_S_GA();
  1438. INIHelper ini = INIHelper.Create($@"PLC_S_INI\PLC_S_{M_NAME}.ini");
  1439. plc_s.PLC_IP = ini.Read(flag, "PLC_IP");
  1440. plc_s.PLC_PORT = ini.Read(flag, "PLC_PORT").ToInt32();
  1441. plc_s.PLC_FLAG_CODE = ini.Read(flag, "PLC_FLAG_CODE");
  1442. plc_s.PLC_FLAG_CODENUM = ini.Read(flag, "PLC_FLAG_CODENUM");
  1443. plc_s.PLC_SEATCOVER_CODE = ini.Read(flag, "PLC_SEATCOVER_CODE");
  1444. plc_s.PLC_SEATCOVER_CODENUM = ini.Read(flag, "PLC_SEATCOVER_CODENUM");
  1445. plc_s.PLC_BARCODE_CODE = ini.Read(flag, "PLC_BARCODE_CODE");
  1446. plc_s.PLC_BARCODE_CODENUM = ini.Read(flag, "PLC_BARCODE_CODENUM");
  1447. plc_s.PLC_BARCODENUM_CODE = ini.Read(flag, "PLC_BARCODENUM_CODE");
  1448. plc_s.PLC_BARCODENUM_CODENUM = ini.Read(flag, "PLC_BARCODENUM_CODENUM");
  1449. plc_s.PLC_GOODSCODE_CODE = ini.Read(flag, "PLC_GOODSCODE_CODE");
  1450. plc_s.PLC_GOODSCODE_CODENUM = ini.Read(flag, "PLC_GOODSCODE_CODENUM");
  1451. plc_s.PLC_GOODSTYPE_CODE = ini.Read(flag, "PLC_GOODSTYPE_CODE");
  1452. plc_s.PLC_GOODSTYPE_CODENUM = ini.Read(flag, "PLC_GOODSTYPE_CODENUM");
  1453. plc_s.PLC_SEMIREWORK_CODE = ini.Read(flag, "PLC_SEMIREWORK_CODE");
  1454. plc_s.PLC_SEMIREWORK_CODENUM = ini.Read(flag, "PLC_SEMIREWORK_CODENUM");
  1455. plc_s.PLC_SEMIREPAIR_CODE = ini.Read(flag, "PLC_SEMIREPAIR_CODE");
  1456. plc_s.PLC_SEMIREPAIR_CODENUM = ini.Read(flag, "PLC_SEMIREPAIR_CODENUM");
  1457. plc_s.PLC_GOODSLEVEL_CODE = ini.Read(flag, "PLC_GOODSLEVEL_CODE");
  1458. plc_s.PLC_GOODSLEVEL_CODENUM = ini.Read(flag, "PLC_GOODSLEVEL_CODENUM");
  1459. plc_s.PLC_GOODSLEVEL2_CODE = ini.Read(flag, "PLC_GOODSLEVEL2_CODE");
  1460. plc_s.PLC_GOODSLEVEL2_CODENUM = ini.Read(flag, "PLC_GOODSLEVEL2_CODENUM");
  1461. plc_s.PLC_ISREFIRE_CODE = ini.Read(flag, "PLC_ISREFIRE_CODE");
  1462. plc_s.PLC_ISREFIRE_CODENUM = ini.Read(flag, "PLC_ISREFIRE_CODENUM");
  1463. plc_s.PLC_GOODSTYPEISREFIRE_CODE = ini.Read(flag, "PLC_GOODSTYPEISREFIRE_CODE");
  1464. plc_s.PLC_GOODSTYPEISREFIRE_CODENUM = ini.Read(flag, "PLC_GOODSTYPEISREFIRE_CODENUM");
  1465. plc_s.PLC_GOODSREPAIR_CODE = ini.Read(flag, "PLC_GOODSREPAIR_CODE");
  1466. plc_s.PLC_GOODSREPAIR_CODENUM = ini.Read(flag, "PLC_GOODSREPAIR_CODENUM");
  1467. plc_s.PLC_GOODSDEFECTTYPE_CODE = ini.Read(flag, "PLC_GOODSDEFECTTYPE_CODE");
  1468. plc_s.PLC_GOODSDEFECTTYPE_CODENUM = ini.Read(flag, "PLC_GOODSDEFECTTYPE_CODENUM");
  1469. plc_s.PROCEDURE_ID = ini.Read(flag, "PROCEDURE_ID");
  1470. plc_s.PROCEDURE_USERCODE = ini.Read(flag, "PROCEDURE_USERCODE");
  1471. plc_s.PROCEDURE_DRYREPAIR_ID = ini.Read(flag, "PROCEDURE_DRYREPAIR_ID");
  1472. plc_s.PROCEDURE_REFIRE_RECIVE_ID = ini.Read(flag, "PROCEDURE_REFIRE_RECIVE_ID");
  1473. plc_s.PROCEDURE_REFIRE_RECIVE_USERCODE = ini.Read(flag, "PROCEDURE_REFIRE_RECIVE_USERCODE");
  1474. plc_s.WORKSTATION_ID = ini.Read(flag, "WORKSTATION_ID");
  1475. plc_s.WORKSTATION_NAME = ini.Read(flag, "WORKSTATION_NAME");
  1476. plc_s.PLC_IP_NEW = ini.Read(flag, "PLC_IP_NEW");
  1477. plc_s.PLC_SEATCOVER_CODE_OTHER = ini.Read(flag, "PLC_SEATCOVER_CODE_OTHER");
  1478. plc_s.PLC_SEATCOVER_CODENUM_OTHER = ini.Read(flag, "PLC_SEATCOVER_CODENUM_OTHER");
  1479. plc_s.PLC_GOODSCODE_CODE_OTHER = ini.Read(flag, "PLC_GOODSCODE_CODE_OTHER");
  1480. plc_s.PLC_GOODSCODE_CODENUM_OTHER = ini.Read(flag, "PLC_GOODSCODE_CODENUM_OTHER");
  1481. plc_s.PLC_BARCODE_CODE_OTHER = ini.Read(flag, "PLC_BARCODE_CODE_OTHER");
  1482. plc_s.PLC_BARCODE_CODENUM_OTHER = ini.Read(flag, "PLC_BARCODE_CODENUM_OTHER");
  1483. plc_s.PLC_FLAG_CODE_OTHER = ini.Read(flag, "PLC_FLAG_CODE_OTHER");
  1484. plc_s.PLC_FLAG_CODENUM_OTHER = ini.Read(flag, "PLC_FLAG_CODENUM_OTHER");
  1485. plc_s.PLC_GROUTINGUSER_CODE = ini.Read(flag, "PLC_GROUTINGUSER_CODE");
  1486. plc_s.PLC_GROUTINGUSER_CODENUM = ini.Read(flag, "PLC_GROUTINGUSER_CODENUM");
  1487. PLC_FLAGS.Add(flag, plc_s);
  1488. return plc_s;
  1489. }
  1490. }
  1491. catch (Exception ex)
  1492. {
  1493. Logger.Error(ex, $"[{e.Content}]ERROR-GetPLC_S_GA", loggerName, logger_e);
  1494. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetPLC_S_GA={ex.Message}");
  1495. return null;
  1496. }
  1497. }
  1498. }
  1499. }