GoodsAuto.cs 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  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. outputMessage = $"[{e.Content}]PLC_Connect={JsonHelper.FromObject(plc_s)}";
  200. Logger.Trace(outputMessage, logKeyT, logger_t);
  201. FormLogShow?.ShowLog(outputMessage);
  202. plc = new SocketClient<SiemensS7_1200Model>();
  203. plc.Connect(plc_s.PLC_IP, plc_s.PLC_PORT);
  204. PLCResult p_r;
  205. #endregion
  206. //接收到条码后,先给标识位复位为0,后面再写入(6371+6375)
  207. SendCode(plc_s, e, logKeyT, logKeyE, plc, 0);
  208. //产品等级、产品类型 的清零
  209. //if (!string.IsNullOrEmpty(plc_s.PLC_GOODSTYPE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSTYPE_CODENUM) && !string.IsNullOrEmpty(plc_s.PLC_SEMIREWORK_CODE) && !string.IsNullOrEmpty(plc_s.PLC_SEMIREWORK_CODENUM))
  210. //{
  211. // plc?.Write<short>(plc_s.PLC_GOODSTYPE_CODE, plc_s.PLC_GOODSTYPE_CODENUM, 0);
  212. // plc?.Write<short>(plc_s.PLC_SEMIREWORK_CODE, plc_s.PLC_SEMIREWORK_CODENUM, 0);
  213. //}
  214. //延迟一秒
  215. System.Threading.Thread.Sleep(1000);
  216. #region 【必须】判断接收条码格式是否正确
  217. if (string.IsNullOrWhiteSpace(barCode) ||
  218. barCode == "0" ||
  219. barCode.Length != 11 ||
  220. barCode.StartsWith("0") ||
  221. barCode.StartsWith("ERROR")
  222. )
  223. {
  224. outputMessage = $"[{e.Content}]接收条码格式错误";
  225. Logger.Warn(outputMessage, logKeyT, logger_t);
  226. Logger.Warn(outputMessage, logKeyE, logger_e);
  227. FormLogShow?.ShowLog(outputMessage);
  228. SendCode(plc_s, e, logKeyT, logKeyE, plc, 2);
  229. return;
  230. }
  231. #endregion
  232. #region 【可选】产品型号写入
  233. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSCODE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSCODE_CODENUM))
  234. {
  235. string intCode = GetSeatCoverCode(barCode, e, logKeyE);
  236. if (intCode == null)
  237. {
  238. outputMessage = $"[{e.Content}]此条码[{barCode}]不存在";
  239. Logger.Warn(outputMessage, logKeyT, logger_t);
  240. Logger.Warn(outputMessage, logKeyE, logger_e);
  241. FormLogShow?.ShowLog(outputMessage);
  242. SendCode(plc_s, e, logKeyT, logKeyE, plc, 2);
  243. return;
  244. }
  245. outputMessage = $"[{e.Content}]产品条码={barCode}[{intCode}]";
  246. Logger.Trace(outputMessage, logKeyT, logger_t);
  247. FormLogShow?.ShowLog(outputMessage);
  248. if (string.IsNullOrWhiteSpace(intCode))
  249. {
  250. outputMessage = $"[{e.Content}]此条码[{barCode}]未设置型号代码";
  251. Logger.Error(null, outputMessage, logKeyT, logger_t);
  252. Logger.Error(null, outputMessage, logKeyE, logger_e);
  253. FormLogShow?.ShowLog(outputMessage);
  254. SendCode(plc_s, e, logKeyT, logKeyE, plc, 2);
  255. return;
  256. }
  257. outputMessage = $"[{e.Content}]SET_GOODSCODE=[{intCode}]{plc_s.PLC_GOODSCODE_CODE + plc_s.PLC_GOODSCODE_CODENUM}";
  258. Logger.Trace(outputMessage, logKeyT, logger_t);
  259. FormLogShow?.ShowLog(outputMessage);
  260. p_r = plc.Write<short>(plc_s.PLC_GOODSCODE_CODE, plc_s.PLC_GOODSCODE_CODENUM, (short)(intCode.ToInt32()));
  261. outputMessage = $"[{e.Content}]END_GOODSCODE=[{p_r}]{plc_s.PLC_GOODSCODE_CODE + plc_s.PLC_GOODSCODE_CODENUM}";
  262. Logger.Trace(outputMessage, logKeyT, logger_t);
  263. FormLogShow?.ShowLog(outputMessage);
  264. }
  265. #endregion
  266. #region 【可选】产品类型写入
  267. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSTYPE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSTYPE_CODENUM))
  268. {
  269. Int16 goodsType = Convert.ToInt16(GetGoodsType(barCode, e, logKeyT));
  270. outputMessage = $"[{e.Content}]SET_GoodsType=[{goodsType}]{plc_s.PLC_GOODSTYPE_CODE + plc_s.PLC_GOODSTYPE_CODENUM}";
  271. Logger.Trace(outputMessage, logKeyT, logger_t);
  272. FormLogShow?.ShowLog(outputMessage);
  273. p_r = plc?.Write<short>(plc_s.PLC_GOODSTYPE_CODE, plc_s.PLC_GOODSTYPE_CODENUM, goodsType);
  274. outputMessage = $"[{e.Content}]END_GoodsType=[{p_r.ToString()}]{plc_s.PLC_GOODSTYPE_CODE + plc_s.PLC_GOODSTYPE_CODENUM}";
  275. Logger.Trace(outputMessage, logKeyT, logger_t);
  276. FormLogShow?.ShowLog(outputMessage);
  277. System.Threading.Thread.Sleep(2);
  278. }
  279. #endregion
  280. #region 【可选】产品下线写入 2023-05-19
  281. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSDISABLED_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSDISABLED_CODENUM))
  282. {
  283. Int16 goodsDisabled = Convert.ToInt16(GetGoodsDisabled(barCode, e, logKeyT));
  284. outputMessage = $"[{e.Content}]SET_GoodsDisabled=[{goodsDisabled}]{plc_s.PLC_GOODSDISABLED_CODE + plc_s.PLC_GOODSDISABLED_CODENUM}";
  285. Logger.Trace(outputMessage, logKeyT, logger_t);
  286. FormLogShow?.ShowLog(outputMessage);
  287. p_r = plc?.Write<short>(plc_s.PLC_GOODSDISABLED_CODE, plc_s.PLC_GOODSDISABLED_CODENUM, goodsDisabled);
  288. outputMessage = $"[{e.Content}]END_GoodsDisabled=[{p_r.ToString()}]{plc_s.PLC_GOODSDISABLED_CODE + plc_s.PLC_GOODSDISABLED_CODENUM}";
  289. Logger.Trace(outputMessage, logKeyT, logger_t);
  290. FormLogShow?.ShowLog(outputMessage);
  291. }
  292. #endregion
  293. #region 【可选】养水标识(用于三水厂) 2024-01-29
  294. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSWATER_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSWATER_CODENUM))
  295. {
  296. Int16 goodsWater = Convert.ToInt16(GetGoodsWater(barCode, e, logKeyT));
  297. outputMessage = $"[{e.Content}]SET_GoodsWater=[{goodsWater}]{plc_s.PLC_GOODSWATER_CODE + plc_s.PLC_GOODSWATER_CODENUM}";
  298. Logger.Trace(outputMessage, logKeyT, logger_t);
  299. FormLogShow?.ShowLog(outputMessage);
  300. p_r = plc?.Write<short>(plc_s.PLC_GOODSWATER_CODE, plc_s.PLC_GOODSWATER_CODENUM, goodsWater);
  301. outputMessage = $"[{e.Content}]END_GoodsWater=[{p_r.ToString()}]{plc_s.PLC_GOODSWATER_CODE + plc_s.PLC_GOODSWATER_CODENUM}";
  302. Logger.Trace(outputMessage, logKeyT, logger_t);
  303. FormLogShow?.ShowLog(outputMessage);
  304. }
  305. #endregion
  306. #region 【可选】产品型号#物料号写入(用于三水厂) 2023-05-19
  307. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSCODESKU_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSCODESKU_CODENUM))
  308. {
  309. Int16 goodsCodeSku = Convert.ToInt16(GetGoodsCodeSku(barCode, e, logKeyT));
  310. outputMessage = $"[{e.Content}]SET_GoodsCodeSku=[{goodsCodeSku}]{plc_s.PLC_GOODSCODESKU_CODE + plc_s.PLC_GOODSCODESKU_CODENUM}";
  311. Logger.Trace(outputMessage, logKeyT, logger_t);
  312. FormLogShow?.ShowLog(outputMessage);
  313. p_r = plc?.Write<short>(plc_s.PLC_GOODSCODESKU_CODE, plc_s.PLC_GOODSCODESKU_CODENUM, goodsCodeSku);
  314. outputMessage = $"[{e.Content}]END_GoodsDisabled=[{p_r.ToString()}]{plc_s.PLC_GOODSCODESKU_CODE + plc_s.PLC_GOODSCODESKU_CODENUM}";
  315. Logger.Trace(outputMessage, logKeyT, logger_t);
  316. FormLogShow?.ShowLog(outputMessage);
  317. }
  318. #endregion
  319. #region 【可选】产品补裂写入(用于三水厂) 2023-05-19
  320. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSBREAK_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSBREAK_CODENUM))
  321. {
  322. Int16 goodsBreak = Convert.ToInt16(GetGoodsBreak(barCode, e, logKeyT));
  323. outputMessage = $"[{e.Content}]SET_GoodsBreak=[{goodsBreak}]{plc_s.PLC_GOODSBREAK_CODE + plc_s.PLC_GOODSBREAK_CODENUM}";
  324. Logger.Trace(outputMessage, logKeyT, logger_t);
  325. FormLogShow?.ShowLog(outputMessage);
  326. p_r = plc?.Write<short>(plc_s.PLC_GOODSBREAK_CODE, plc_s.PLC_GOODSBREAK_CODENUM, goodsBreak);
  327. outputMessage = $"[{e.Content}]END_GoodsBreak=[{p_r.ToString()}]{plc_s.PLC_GOODSBREAK_CODE + plc_s.PLC_GOODSBREAK_CODENUM}";
  328. Logger.Trace(outputMessage, logKeyT, logger_t);
  329. FormLogShow?.ShowLog(outputMessage);
  330. }
  331. #endregion
  332. #region 【可选】成型线号写入(只写第3位,用于三水厂)
  333. if (!string.IsNullOrEmpty(plc_s.PLC_GROUTINGLINE3_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GROUTINGLINE3_CODENUM))
  334. {
  335. Int16 goodsType = Convert.ToInt16(GetGroutingLine3(barCode, e, logKeyT));
  336. outputMessage = $"[{e.Content}]SET_GROUTINGLINE3=[{goodsType}]{plc_s.PLC_GROUTINGLINE3_CODE + plc_s.PLC_GROUTINGLINE3_CODENUM}";
  337. Logger.Trace(outputMessage, logKeyT, logger_t);
  338. FormLogShow?.ShowLog(outputMessage);
  339. p_r = plc?.Write<short>(plc_s.PLC_GROUTINGLINE3_CODE, plc_s.PLC_GROUTINGLINE3_CODENUM, goodsType);
  340. outputMessage = $"[{e.Content}]END_GROUTINGLINE3=[{p_r.ToString()}]{plc_s.PLC_GROUTINGLINE3_CODE + plc_s.PLC_GROUTINGLINE3_CODENUM}";
  341. Logger.Trace(outputMessage, logKeyT, logger_t);
  342. FormLogShow?.ShowLog(outputMessage);
  343. }
  344. #endregion
  345. #region 【可选】产品条码写入
  346. if (!string.IsNullOrEmpty(plc_s.PLC_BARCODE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_BARCODE_CODENUM))
  347. {
  348. outputMessage = $"[{e.Content}]SET_BarCode=[{barCode}]{plc_s.PLC_BARCODE_CODE + plc_s.PLC_BARCODE_CODENUM}";
  349. Logger.Trace(outputMessage, logKeyT, logger_t);
  350. FormLogShow?.ShowLog(outputMessage);
  351. p_r = plc.Write<string>(plc_s.PLC_BARCODE_CODE, plc_s.PLC_BARCODE_CODENUM, barCode);
  352. outputMessage = $"[{e.Content}]END_BarCode=[{p_r}]{plc_s.PLC_BARCODE_CODE + plc_s.PLC_BARCODE_CODENUM}";
  353. Logger.Trace(outputMessage, logKeyT, logger_t);
  354. FormLogShow?.ShowLog(outputMessage);
  355. }
  356. #endregion
  357. #region 【可选】半检返工标识写入
  358. if (!string.IsNullOrEmpty(plc_s.PLC_SEMIREWORK_CODE) && !string.IsNullOrEmpty(plc_s.PLC_SEMIREWORK_CODENUM))
  359. {
  360. Int16 goodsType = Convert.ToInt16(GetSemiReWork(barCode, e, logKeyT));
  361. outputMessage = $"[{e.Content}]SET_SemiRework=[{goodsType}]{plc_s.PLC_SEMIREWORK_CODE + plc_s.PLC_SEMIREWORK_CODENUM}";
  362. Logger.Trace(outputMessage, logKeyT, logger_t);
  363. FormLogShow?.ShowLog(outputMessage);
  364. p_r = plc?.Write<short>(plc_s.PLC_SEMIREWORK_CODE, plc_s.PLC_SEMIREWORK_CODENUM, goodsType);
  365. outputMessage = $"[{e.Content}]END_SemiRework=[{p_r.ToString()}]{plc_s.PLC_SEMIREWORK_CODE + plc_s.PLC_SEMIREWORK_CODENUM}";
  366. Logger.Trace(outputMessage, logKeyT, logger_t);
  367. FormLogShow?.ShowLog(outputMessage);
  368. System.Threading.Thread.Sleep(2);
  369. }
  370. #endregion
  371. #region 【可选】产品等级写入
  372. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSLEVEL_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSLEVEL_CODENUM))
  373. {
  374. Int16 goodsLevel = Convert.ToInt16(GetGoodsLevel(barCode, e, logKeyT));
  375. outputMessage = $"[{e.Content}]SET_GoodsLevel=[{goodsLevel}]{plc_s.PLC_GOODSLEVEL_CODE + plc_s.PLC_GOODSLEVEL_CODENUM}";
  376. Logger.Trace(outputMessage, logKeyT, logger_t);
  377. FormLogShow?.ShowLog(outputMessage);
  378. p_r = plc?.Write<short>(plc_s.PLC_GOODSLEVEL_CODE, plc_s.PLC_GOODSLEVEL_CODENUM, goodsLevel);
  379. outputMessage = $"[{e.Content}]END_GoodsLevel=[{p_r.ToString()}]{plc_s.PLC_GOODSLEVEL_CODE + plc_s.PLC_GOODSLEVEL_CODENUM}";
  380. Logger.Trace(outputMessage, logKeyT, logger_t);
  381. FormLogShow?.ShowLog(outputMessage);
  382. }
  383. #endregion
  384. #region 【可选】产品漏气合格写入
  385. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSLEAKFLAG1_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSLEAKFLAG1_CODENUM))
  386. {
  387. Int16 goodsLeakFlag1 = Convert.ToInt16(GetGoodsLeakFlag1(barCode, e, logKeyT));
  388. outputMessage = $"[{e.Content}]SET_GoodsLeakFlag1=[{goodsLeakFlag1}]{plc_s.PLC_GOODSLEAKFLAG1_CODE + plc_s.PLC_GOODSLEAKFLAG1_CODENUM}";
  389. Logger.Trace(outputMessage, logKeyT, logger_t);
  390. FormLogShow?.ShowLog(outputMessage);
  391. p_r = plc?.Write<short>(plc_s.PLC_GOODSLEAKFLAG1_CODE, plc_s.PLC_GOODSLEAKFLAG1_CODENUM, goodsLeakFlag1);
  392. outputMessage = $"[{e.Content}]END_GoodsLeakFlag1=[{p_r.ToString()}]{plc_s.PLC_GOODSLEAKFLAG1_CODE + plc_s.PLC_GOODSLEAKFLAG1_CODENUM}";
  393. Logger.Trace(outputMessage, logKeyT, logger_t);
  394. FormLogShow?.ShowLog(outputMessage);
  395. }
  396. #endregion
  397. #region 【可选】工序验证
  398. if (!string.IsNullOrEmpty(plc_s.PROCEDURE_CHECKID))
  399. {
  400. Int16 plc_flag = Convert.ToInt16(GetProcedureCheck(barCode, plc_s.PROCEDURE_CHECKID, e, logKeyT, logKeyE));
  401. SendCode(plc_s, e, logKeyT, logKeyE, plc, plc_flag);
  402. return;
  403. }
  404. #endregion
  405. #region 【可选】工序计件
  406. if (!string.IsNullOrEmpty(plc_s.PROCEDURE_ID) && (!string.IsNullOrEmpty(plc_s.PROCEDURE_USERCODE) || !string.IsNullOrEmpty(plc_s.WORKSTATION_ID)) )
  407. {
  408. string p_id = GetFlowId(barCode, e, logKeyE);
  409. Int16 plc_flag = 0;
  410. if (p_id != plc_s.PROCEDURE_ID.ToString())
  411. {
  412. string userCode = "";
  413. //默认读取userCode
  414. if(!string.IsNullOrEmpty(plc_s.PROCEDURE_USERCODE))
  415. {
  416. userCode = plc_s.PROCEDURE_USERCODE;
  417. }
  418. //优先从工位取userCode
  419. if (!string.IsNullOrEmpty(plc_s.WORKSTATION_ID))
  420. {
  421. userCode = GetUserCodeFromWorkStation(plc_s.WORKSTATION_ID, e, logKeyE);
  422. outputMessage = $"[{e.Content}]DB_UserCode=[{userCode}]";
  423. Logger.Trace(outputMessage, logKeyT, logger_t);
  424. FormLogShow?.ShowLog(outputMessage);
  425. }
  426. //工序计件
  427. string result = SmartDeviceProxy.Instance.Invoke<string>(
  428. p => p.AddWorkPieceByStatus3(
  429. _mes_s.AccountCode,
  430. userCode,
  431. null,
  432. Convert.ToInt32(plc_s.PROCEDURE_ID),
  433. barCode,
  434. null));
  435. outputMessage = $"[{e.Content}]MES_Result=[{result}]";
  436. Logger.Trace(outputMessage, logKeyT, logger_t);
  437. FormLogShow?.ShowLog(outputMessage);
  438. // 返回状态(成功、失败)
  439. if (result != "OK")
  440. {
  441. plc_flag = 3;
  442. if (result == "EE")
  443. {
  444. plc_flag = 4;
  445. outputMessage = $"MES服务端异常(详情参见MES端日志)";
  446. }
  447. else if (result == "EU-01")
  448. {
  449. outputMessage = $"无效的帐套或工号(详情参见MES端日志)";
  450. }
  451. else
  452. {
  453. outputMessage = $"其他错误(详情参见MES端日志)[{result}]";
  454. }
  455. Logger.Error(null, outputMessage, logKeyT, logger_t);
  456. Logger.Error(null, outputMessage, logKeyE, logger_e);
  457. FormLogShow?.ShowLog(outputMessage);
  458. SendCode(plc_s, e, logKeyT, logKeyE, plc, plc_flag);
  459. return;
  460. }
  461. }
  462. }
  463. #endregion
  464. #region 【可选】工序计件(计件第2工序,用于扫描1个点连续计件2道工序)
  465. if (!string.IsNullOrEmpty(plc_s.PROCEDURE_ID2) && (!string.IsNullOrEmpty(plc_s.PROCEDURE_USERCODE2) || !string.IsNullOrEmpty(plc_s.WORKSTATION_ID2)))
  466. {
  467. string p_id = GetFlowId(barCode, e, logKeyE);
  468. Int16 plc_flag = 0;
  469. if (p_id != plc_s.PROCEDURE_ID2.ToString())
  470. {
  471. string userCode = "";
  472. //默认读取userCode
  473. if (!string.IsNullOrEmpty(plc_s.PROCEDURE_USERCODE2))
  474. {
  475. userCode = plc_s.PROCEDURE_USERCODE2;
  476. }
  477. //优先从工位取userCode
  478. if (!string.IsNullOrEmpty(plc_s.WORKSTATION_ID2))
  479. {
  480. userCode = GetUserCodeFromWorkStation(plc_s.WORKSTATION_ID2, e, logKeyE);
  481. outputMessage = $"[{e.Content}]DB_UserCode=[{userCode}]";
  482. Logger.Trace(outputMessage, logKeyT, logger_t);
  483. FormLogShow?.ShowLog(outputMessage);
  484. }
  485. //工序计件
  486. string result = SmartDeviceProxy.Instance.Invoke<string>(
  487. p => p.AddWorkPieceByStatus3(
  488. _mes_s.AccountCode,
  489. userCode,
  490. null,
  491. Convert.ToInt32(plc_s.PROCEDURE_ID2),
  492. barCode,
  493. null));
  494. outputMessage = $"[{e.Content}]MES_Result=[{result}]";
  495. Logger.Trace(outputMessage, logKeyT, logger_t);
  496. FormLogShow?.ShowLog(outputMessage);
  497. // 返回状态(成功、失败)
  498. if (result != "OK")
  499. {
  500. plc_flag = 3;
  501. if (result == "EE")
  502. {
  503. plc_flag = 4;
  504. outputMessage = $"MES服务端异常(详情参见MES端日志)";
  505. }
  506. else if (result == "EU-01")
  507. {
  508. outputMessage = $"无效的帐套或工号(详情参见MES端日志)";
  509. }
  510. else
  511. {
  512. outputMessage = $"其他错误(详情参见MES端日志)[{result}]";
  513. }
  514. Logger.Error(null, outputMessage, logKeyT, logger_t);
  515. Logger.Error(null, outputMessage, logKeyE, logger_e);
  516. FormLogShow?.ShowLog(outputMessage);
  517. SendCode(plc_s, e, logKeyT, logKeyE, plc, plc_flag);
  518. return;
  519. }
  520. }
  521. }
  522. #endregion
  523. #region 【必须】写入PLC扫码结果 【1:通过,2:扫码异常,3:工序异常,0:复位】
  524. SendCode(plc_s, e, logKeyT, logKeyE, plc, 1);
  525. #endregion
  526. }
  527. }
  528. catch (Exception ex)
  529. {
  530. FormLogShow?.ShowLog($"[{e.Content}]ERROR={ex.Message}");
  531. if (plc_s != null)
  532. {
  533. Logger.Error(ex, $"[{e.Content}]ERROR", logKeyT, logger_t);
  534. Logger.Error(ex, $"[{e.Content}]ERROR", logKeyE, logger_e);
  535. SendCode(plc_s, e, logKeyT, logKeyE, plc, 2);
  536. }
  537. else
  538. {
  539. Logger.Error(ex, $"[{e.Content}]ERROR-NOFLAG", logKeyT, logger_t);
  540. Logger.Error(ex, $"[{e.Content}]ERROR-NOFLAG", logKeyE, logger_e);
  541. }
  542. }
  543. finally
  544. {
  545. LoggerT?.EndTracking();
  546. plc?.Disconnect();
  547. plc?.Close();
  548. }
  549. }
  550. private void SendCode(PLC_S_GA plc_s, ReceiveSession e, string loggerNameT, string loggerNameE, SocketClient<SiemensS7_1200Model> plc, short code)
  551. {
  552. try
  553. {
  554. string outputMessage = $"[{e.Content}]SET_FLAG_CODE=[{code}]{plc_s.PLC_FLAG_CODE + plc_s.PLC_FLAG_CODENUM}";
  555. Logger.Trace(outputMessage, loggerNameT, logger_t);
  556. FormLogShow?.ShowLog(outputMessage);
  557. PLCResult p_r = plc?.Write<short>(plc_s.PLC_FLAG_CODE, plc_s.PLC_FLAG_CODENUM, (short)code);
  558. outputMessage = $"[{e.Content}]SET_FLAG_CODE=[{p_r}]{plc_s.PLC_FLAG_CODE + plc_s.PLC_FLAG_CODENUM}";
  559. Logger.Trace(outputMessage, loggerNameT, logger_t);
  560. FormLogShow?.ShowLog(outputMessage);
  561. }
  562. catch (Exception ex)
  563. {
  564. Logger.Error(ex, $"[{e.Content}]ERROR-SendCode", loggerNameT, logger_t);
  565. Logger.Error(ex, $"[{e.Content}]ERROR-SendCode", loggerNameE, logger_e);
  566. FormLogShow?.ShowLog($"[{e.Content}]ERROR-SendCode={ex.Message}");
  567. }
  568. }
  569. private string GetGoodsCode(string barCode, ReceiveSession e, string loggerName)
  570. {
  571. try
  572. {
  573. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  574. {
  575. string sqlStr = @"
  576. SELECT
  577. G.GOODSCODE
  578. FROM
  579. TP_PM_GROUTINGDAILYDETAIL GDD
  580. WHERE
  581. GDD.BARCODE = :BARCODE
  582. ";
  583. object result = conn.ExecuteDatatable(sqlStr, new CDAParameter(":BARCODE", barCode));
  584. return result == null ? "" : result.ToString();
  585. }
  586. }
  587. catch (Exception ex)
  588. {
  589. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsCode", loggerName, logger_e);
  590. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsCode={ex.Message}");
  591. return null;
  592. }
  593. }
  594. private string GetGroutingLine3(string barCode, ReceiveSession e, string loggerName)
  595. {
  596. try
  597. {
  598. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  599. {
  600. string sqlStr = @"
  601. SELECT
  602. SUBSTR(GDD.GROUTINGLINECODE,3,1) AS GROUTINGLINECODE
  603. FROM
  604. TP_PM_GROUTINGDAILYDETAIL GDD
  605. WHERE
  606. GDD.BARCODE = :BARCODE
  607. ";
  608. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  609. return result == null ? "" : result.ToString();
  610. }
  611. }
  612. catch (Exception ex)
  613. {
  614. Logger.Error(ex, $"[{e.Content}]ERROR-GetGroutingLine3", loggerName, logger_e);
  615. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGroutingLine3={ex.Message}");
  616. return null;
  617. }
  618. }
  619. private string GetSeatCoverCode(string barCode, ReceiveSession e, string loggerName)
  620. {
  621. try
  622. {
  623. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  624. {
  625. string sqlStr = @"
  626. SELECT
  627. G.SEATCOVERCODE
  628. FROM
  629. TP_PM_GROUTINGDAILYDETAIL GDD
  630. INNER JOIN TP_MST_GOODS G ON G.GOODSID = GDD.GOODSID
  631. WHERE
  632. GDD.BARCODE = :BARCODE
  633. ";
  634. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  635. return result == null ? "" : result.ToString();
  636. }
  637. }
  638. catch (Exception ex)
  639. {
  640. Logger.Error(ex, $"[{e.Content}]ERROR-GetSeatCoverCode", loggerName, logger_e);
  641. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetSeatCoverCode={ex.Message}");
  642. return null;
  643. }
  644. }
  645. private string GetGoodsType(string barCode, ReceiveSession e, string loggerName)
  646. {
  647. try
  648. {
  649. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  650. {
  651. string sqlStr = @"
  652. SELECT
  653. -- G.GOODSCODE,
  654. -- G.SEATCOVERCODE,
  655. CASE
  656. WHEN T.GOODSTYPECODE = '001001001' THEN 2 --连体
  657. WHEN T.GOODSTYPECODE = '001001002' THEN 3 --分体
  658. WHEN T.GOODSTYPECODE = '001001003' THEN 1 --智能
  659. WHEN T.GOODSTYPECODE = '001001004' THEN 1 --智能高压
  660. ELSE 0 --其他
  661. END AS GOODSTYPE
  662. FROM
  663. TP_PM_GROUTINGDAILYDETAIL GDD
  664. INNER JOIN TP_MST_GOODS G ON G.GOODSID = GDD.GOODSID
  665. INNER JOIN TP_MST_GOODSTYPE T ON G.GOODSTYPEID = T.GOODSTYPEID
  666. WHERE
  667. GDD.BARCODE = :BARCODE --'10006800247'
  668. ";
  669. string goodsType = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode)).ToString();
  670. return goodsType;
  671. }
  672. }
  673. catch (Exception ex)
  674. {
  675. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsType", loggerName, logger_e);
  676. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsType={ex.Message}");
  677. return "0";
  678. }
  679. }
  680. private string GetGoodsDisabled(string barCode, ReceiveSession e, string loggerName)
  681. {
  682. try
  683. {
  684. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  685. {
  686. //判断单品下线
  687. string sqlStr = @"
  688. SELECT
  689. CASE WHEN GDD.OFFLINEFLAG = 0 AND OL.GOODSID IS NULL THEN 1 ELSE 2 END AS OFFLINEFLAG
  690. FROM
  691. TP_PM_GROUTINGDAILYDETAIL GDD
  692. LEFT JOIN TP_PM_OFFLINE OL ON GDD.GOODSID = OL.GOODSID
  693. WHERE
  694. GDD.BARCODE = :BARCODE --'10017193389'
  695. ";
  696. string goodsDisabled = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode)).ToString();
  697. return goodsDisabled;
  698. }
  699. }
  700. catch (Exception ex)
  701. {
  702. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsDisabled", loggerName, logger_e);
  703. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsDisabled={ex.Message}");
  704. return "0";
  705. }
  706. }
  707. private string GetGoodsWater(string barCode, ReceiveSession e, string loggerName)
  708. {
  709. try
  710. {
  711. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  712. {
  713. //取养水标识
  714. string sqlStr = @"
  715. SELECT
  716. NVL( GDD.LEAKFLAG4, 0 ) AS WATER
  717. FROM
  718. TP_PM_GROUTINGDAILYDETAIL GDD
  719. WHERE
  720. GDD.BARCODE = :BARCODE --'10016123244'
  721. ";
  722. string goodsWater = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode)).ToString();
  723. return goodsWater;
  724. }
  725. }
  726. catch (Exception ex)
  727. {
  728. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsWater", loggerName, logger_e);
  729. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsWater={ex.Message}");
  730. return "0";
  731. }
  732. }
  733. private string GetGoodsCodeSku(string barCode, ReceiveSession e, string loggerName)
  734. {
  735. try
  736. {
  737. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  738. {
  739. string sqlStr = @"
  740. SELECT
  741. GDD.GOODSCODE || '#' || GDD.MATERIALCODE
  742. FROM
  743. TP_PM_GROUTINGDAILYDETAIL GDD
  744. WHERE
  745. GDD.BARCODE = :BARCODE
  746. ";
  747. string goodsCodeSku = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode)).ToString();
  748. return goodsCodeSku;
  749. }
  750. }
  751. catch (Exception ex)
  752. {
  753. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsCodeSku", loggerName, logger_e);
  754. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsCodeSku={ex.Message}");
  755. return "0";
  756. }
  757. }
  758. private string GetGoodsBreak(string barCode, ReceiveSession e, string loggerName)
  759. {
  760. try
  761. {
  762. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  763. {
  764. string sqlStr = @"
  765. SELECT
  766. LEAKFLAG6
  767. FROM
  768. TP_PM_GROUTINGDAILYDETAIL GDD
  769. WHERE
  770. GDD.BARCODE = :BARCODE
  771. ";
  772. string goodsBreak = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode)).ToString();
  773. if (goodsBreak == "0") goodsBreak = "2"; //补裂
  774. return goodsBreak;
  775. }
  776. }
  777. catch (Exception ex)
  778. {
  779. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsBreak", loggerName, logger_e);
  780. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsBreak={ex.Message}");
  781. return "0";
  782. }
  783. }
  784. private string GetFlowId(string barCode, ReceiveSession e, string loggerName)
  785. {
  786. try
  787. {
  788. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  789. {
  790. string sqlStr = @"
  791. SELECT
  792. GDD.FLOWPROCEDUREID
  793. FROM
  794. TP_PM_INPRODUCTION GDD
  795. WHERE
  796. GDD.BARCODE = :BARCODE
  797. ";
  798. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  799. return result == null ? "0" : result.ToString();
  800. }
  801. }
  802. catch (Exception ex)
  803. {
  804. Logger.Error(ex, $"[{e.Content}]ERROR-GetFlowId", loggerName, logger_e);
  805. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetFlowId={ex.Message}");
  806. return "0";
  807. }
  808. }
  809. private string GetUserCodeFromWorkStation(string workStationId, ReceiveSession e, string loggerName)
  810. {
  811. try
  812. {
  813. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  814. {
  815. string sqlStr = @"
  816. SELECT
  817. T.USERCODE
  818. FROM
  819. TP_MST_WORKSTATION T
  820. INNER JOIN TP_MST_USER U ON U.USERCODE = T.USERCODE
  821. WHERE
  822. T.WORKSTATIONID = :WORKSTATIONID
  823. ";
  824. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":WORKSTATIONID", workStationId));
  825. return result == null ? "0" : result.ToString();
  826. }
  827. }
  828. catch (Exception ex)
  829. {
  830. Logger.Error(ex, $"[{e.Content}]ERROR-GetUserCodeFromWorkStation", loggerName, logger_e);
  831. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetUserCodeFromWorkStation={ex.Message}");
  832. return "0";
  833. }
  834. }
  835. private string GetSemiReWork(string barCode, ReceiveSession e, string loggerName)
  836. {
  837. try
  838. {
  839. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  840. {
  841. string sqlStr = @"
  842. SELECT
  843. P.ISREWORKFLAG
  844. FROM
  845. TP_PM_INPRODUCTION P
  846. WHERE
  847. P.BARCODE = :BARCODE
  848. ";
  849. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  850. //返工标识(0:正常,1:半检返工中, 2:半检返修)
  851. //没找到记录表明产品报废写 3
  852. string resultFlag = "0";
  853. if(result !=null)
  854. {
  855. if (result.ToString() == "0") resultFlag = "1"; //正常
  856. if (result.ToString() == "1" || result.ToString() == "2") resultFlag = "2";//返工
  857. }
  858. else
  859. {
  860. resultFlag = "3";//报废
  861. }
  862. return resultFlag;
  863. }
  864. }
  865. catch (Exception ex)
  866. {
  867. Logger.Error(ex, $"[{e.Content}]ERROR-GetSemiReWork", loggerName, logger_e);
  868. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetSemiReWork={ex.Message}");
  869. return "0";
  870. }
  871. }
  872. private string GetGoodsLevel(string barCode, ReceiveSession e, string loggerName)
  873. {
  874. try
  875. {
  876. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  877. {
  878. string sqlStr = @"
  879. SELECT
  880. GDD.GOODSLEVELTYPEID
  881. FROM
  882. TP_PM_GROUTINGDAILYDETAIL GDD
  883. WHERE
  884. GDD.BARCODE = :BARCODE
  885. ";
  886. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  887. return result == null ? "0" : result.ToString();
  888. }
  889. }
  890. catch (Exception ex)
  891. {
  892. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsLevel", loggerName, logger_e);
  893. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsLevel={ex.Message}");
  894. return "0";
  895. }
  896. }
  897. private string GetGoodsLeakFlag1(string barCode, ReceiveSession e, string loggerName)
  898. {
  899. try
  900. {
  901. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  902. {
  903. string sqlStr = @"
  904. SELECT
  905. DECODE(GDD.LEAKFLAG1,NULL,2,0,2,GDD.LEAKFLAG1)
  906. FROM
  907. TP_PM_GROUTINGDAILYDETAIL GDD
  908. WHERE
  909. GDD.BARCODE = :BARCODE
  910. ";
  911. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  912. return result == null ? "0" : result.ToString();
  913. }
  914. }
  915. catch (Exception ex)
  916. {
  917. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsLeakFlag1", loggerName, logger_e);
  918. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsLeakFlag1={ex.Message}");
  919. return "0";
  920. }
  921. }
  922. private string GetProcedureCheck(string barCode,string procedureId, ReceiveSession e, string loggerNameT, string loggerNameE)
  923. {
  924. try
  925. {
  926. using (IDataAccess dataAccess = PLC_S_DataAccess.GetDataAccess())
  927. {
  928. CDAParameter[] parameters = new CDAParameter[]
  929. {
  930. new CDAParameter("in_procedureid", procedureId),
  931. new CDAParameter("in_barcode", barCode),
  932. new CDAParameter("out_errType",DataType.Int32, ParameterDirection.Output),
  933. new CDAParameter("out_errMsg",DataType.VarChar, 4000, ParameterDirection.Output),
  934. new CDAParameter("out_goodsID",DataType.Int32, ParameterDirection.Output),
  935. new CDAParameter("out_goodsCode",DataType.VarChar, 400, ParameterDirection.Output),
  936. new CDAParameter("out_goodsType",DataType.Int32, ParameterDirection.Output),
  937. };
  938. int ii = dataAccess.ExecuteSPNonQuery("PRO_PM_CheckBarcode_PLC", parameters);
  939. Int16 plc_flag = 0;
  940. if (!int.TryParse(parameters[2].Value + "", out int errtype))
  941. {
  942. errtype = 4;
  943. }
  944. // 其他情况显示MES异常
  945. if (errtype == 4)
  946. {
  947. plc_flag = 4;
  948. }
  949. else if (errtype == 0)
  950. {
  951. plc_flag = 1;
  952. }
  953. else // errtype == 1 || errtype == 2 || errtype == 3
  954. {
  955. // 无效条码,显示不可到达
  956. plc_flag = 3;
  957. }
  958. string outputMessage = $"[{e.Content}]MESSAGE=[{errtype}][{parameters[3].Value}]";
  959. Logger.Trace(outputMessage, loggerNameT, logger_t);
  960. FormLogShow?.ShowLog(outputMessage);
  961. return plc_flag.ToString();
  962. }
  963. }
  964. catch (Exception ex)
  965. {
  966. Logger.Error(ex, $"[{e.Content}]ERROR-GetProcedureCheck", loggerNameE, logger_e);
  967. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetProcedureCheck={ex.Message}");
  968. return "0";
  969. }
  970. }
  971. private PLC_S_GA GetPLC_S_GA(string flag, ReceiveSession e, string loggerName)
  972. {
  973. try
  974. {
  975. flag = M_NAME + flag;
  976. if (PLC_FLAGS.ContainsKey(flag))
  977. {
  978. return PLC_FLAGS[flag];
  979. }
  980. else
  981. {
  982. PLC_S_GA plc_s = new PLC_S_GA();
  983. INIHelper ini = INIHelper.Create($@"PLC_S_INI\PLC_S_{M_NAME}.ini");
  984. plc_s.PLC_IP = ini.Read(flag, "PLC_IP");
  985. plc_s.PLC_PORT = ini.Read(flag, "PLC_PORT").ToInt32();
  986. plc_s.PLC_FLAG_CODE = ini.Read(flag, "PLC_FLAG_CODE");
  987. plc_s.PLC_FLAG_CODENUM = ini.Read(flag, "PLC_FLAG_CODENUM");
  988. plc_s.PLC_GOODSCODE_CODE = ini.Read(flag, "PLC_GOODSCODE_CODE");
  989. plc_s.PLC_GOODSCODE_CODENUM = ini.Read(flag, "PLC_GOODSCODE_CODENUM");
  990. plc_s.PLC_GROUTINGLINE3_CODE = ini.Read(flag, "PLC_GROUTINGLINE3_CODE");
  991. plc_s.PLC_GROUTINGLINE3_CODENUM = ini.Read(flag, "PLC_GROUTINGLINE3_CODENUM");
  992. plc_s.PLC_GOODSTYPE_CODE = ini.Read(flag, "PLC_GOODSTYPE_CODE");
  993. plc_s.PLC_GOODSTYPE_CODENUM = ini.Read(flag, "PLC_GOODSTYPE_CODENUM");
  994. plc_s.PLC_GOODSDISABLED_CODE = ini.Read(flag, "PLC_GOODSDISABLED_CODE");
  995. plc_s.PLC_GOODSDISABLED_CODENUM = ini.Read(flag, "PLC_GOODSDISABLED_CODENUM");
  996. plc_s.PLC_SEMIREWORK_CODE = ini.Read(flag, "PLC_SEMIREWORK_CODE");
  997. plc_s.PLC_SEMIREWORK_CODENUM = ini.Read(flag, "PLC_SEMIREWORK_CODENUM");
  998. plc_s.PLC_GOODSLEVEL_CODE = ini.Read(flag, "PLC_GOODSLEVEL_CODE");
  999. plc_s.PLC_GOODSLEVEL_CODENUM = ini.Read(flag, "PLC_GOODSLEVEL_CODENUM");
  1000. plc_s.PLC_GOODSLEAKFLAG1_CODE = ini.Read(flag, "PLC_GOODSLEAKFLAG1_CODE");
  1001. plc_s.PLC_GOODSLEAKFLAG1_CODENUM = ini.Read(flag, "PLC_GOODSLEAKFLAG1_CODENUM");
  1002. plc_s.PLC_GOODSWATER_CODE = ini.Read(flag, "PLC_GOODSWATER_CODE");
  1003. plc_s.PLC_GOODSWATER_CODENUM = ini.Read(flag, "PLC_GOODSWATER_CODENUM");
  1004. plc_s.PROCEDURE_ID = ini.Read(flag, "PROCEDURE_ID");
  1005. plc_s.PROCEDURE_USERCODE = ini.Read(flag, "PROCEDURE_USERCODE");
  1006. plc_s.WORKSTATION_ID = ini.Read(flag, "WORKSTATION_ID");
  1007. plc_s.WORKSTATION_NAME = ini.Read(flag, "WORKSTATION_NAME");
  1008. plc_s.PROCEDURE_ID2 = ini.Read(flag, "PROCEDURE_ID2");
  1009. plc_s.PROCEDURE_USERCODE2 = ini.Read(flag, "PROCEDURE_USERCODE2");
  1010. plc_s.WORKSTATION_ID2 = ini.Read(flag, "WORKSTATION_ID2");
  1011. plc_s.WORKSTATION_NAME2 = ini.Read(flag, "WORKSTATION_NAME2");
  1012. PLC_FLAGS.Add(flag, plc_s);
  1013. return plc_s;
  1014. }
  1015. }
  1016. catch (Exception ex)
  1017. {
  1018. Logger.Error(ex, $"[{e.Content}]ERROR-GetPLC_S_GA", loggerName, logger_e);
  1019. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetPLC_S_GA={ex.Message}");
  1020. return null;
  1021. }
  1022. }
  1023. }
  1024. }