autoPacking6151.ashx 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. <%@ WebHandler Language="C#" Class="autoPacking6151" %>
  2. using System;
  3. using System.Web;
  4. using System.Data;
  5. using DK.XuWei.WebMes;
  6. using Curtain.DataAccess;
  7. using Newtonsoft.Json.Linq;
  8. /// <summary>
  9. /// PLC对接使用
  10. /// 带参数barcode,扫描头处理逻辑;
  11. /// 不带参数barcode,轮询处理逻辑;
  12. /// xuwei add 2023-12-31
  13. /// </summary>
  14. public class autoPacking6151 : IHttpHandler
  15. {
  16. public static class PLC
  17. {
  18. public static string plcIp = "172.18.36.95";
  19. public static int plcPort = 102;
  20. public static string dbBarcode = "151.2"; //151.0 => 151.2
  21. public static string dbGoodsId = "151.14";
  22. public static string dbGoodsNum = "151.16";
  23. public static string dbResult = "151.18";
  24. public static string dbLogoId = "151.22";//替换产品等级
  25. public static string dbMaterialcode = "151.30";
  26. public static string dbRead = "151.26";
  27. public static string[] dbBarcodeBlock = { "150.2", "150.32", "150.62", "150.92", "150.122", "150.152", "150.182", "150.212", "150.242", "150.272", "150.302", "150.332" };
  28. public static string dbBanMa = "150.362";//150.360 => 150.362
  29. }
  30. public static class API
  31. {
  32. public static string accountCode = "dongke";
  33. public static string userId = "1529";
  34. public static string userCode = "DONGKEXW";
  35. public static string userName = "徐伟";
  36. public static string userPassword = "D63AC55256F8048265387A2B0388F1D2";
  37. public static string sessionKey = "924D8A5B-D55B-4436-AE57-26EE5E435639";
  38. public static string procedureID = "107"; //3#包装
  39. public static bool debug = true;
  40. }
  41. public bool resultFlag = false;
  42. public JArray result = new JArray();
  43. //打开PLC
  44. public int PlcOpen()
  45. {
  46. try
  47. {
  48. SiemensS7.Open(PLC.plcIp, PLC.plcPort);
  49. resultFlag = true;
  50. result.Add(new JObject(new JProperty("PLC连接", PLC.plcIp + ":" + PLC.plcPort + " 连接成功!")));
  51. }
  52. catch (Exception e)
  53. {
  54. resultFlag = false;
  55. result.Add(new JObject(new JProperty("PLC连接", PLC.plcIp + ":" + PLC.plcPort + " 连接失败!")));
  56. result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
  57. }
  58. return 1;
  59. }
  60. //关闭PLC
  61. public int PlcClose()
  62. {
  63. SiemensS7.Close();
  64. result.Add(new JObject(new JProperty("PLC关闭", PLC.plcIp + ":" + PLC.plcPort + " 关闭成功!")));
  65. return 1;
  66. }
  67. //读取PLC标识
  68. public int PlcReadReadFlag()
  69. {
  70. if (!resultFlag) return -1;
  71. try
  72. {
  73. int read = Convert.ToInt16(SiemensS7.Read<short>(PLC.dbRead));
  74. result.Add(new JObject(new JProperty("PLC读取(读取标识)", PLC.dbRead + " = " + read.ToString())));
  75. resultFlag = true;
  76. return read;
  77. }
  78. catch (Exception e)
  79. {
  80. result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
  81. resultFlag = false;
  82. return -1;
  83. }
  84. }
  85. //读取PLC产品ID
  86. public int PlcReadGoodsid()
  87. {
  88. if (!resultFlag) return -1;
  89. try
  90. {
  91. int read = Convert.ToInt16(SiemensS7.Read<short>(PLC.dbGoodsId));
  92. result.Add(new JObject(new JProperty("PLC读取(产品ID)", PLC.dbGoodsId + " = " + read.ToString())));
  93. resultFlag = true;
  94. return read;
  95. }
  96. catch (Exception e)
  97. {
  98. result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
  99. resultFlag = false;
  100. return -1;
  101. }
  102. }
  103. //读取装板数量
  104. public int PlcReadGoodsnum()
  105. {
  106. if (!resultFlag) return -1;
  107. try
  108. {
  109. int read = Convert.ToInt16(SiemensS7.Read<short>(PLC.dbGoodsNum));
  110. result.Add(new JObject(new JProperty("PLC读取(装板数量)", PLC.dbGoodsNum + " = " + read.ToString())));
  111. resultFlag = true;
  112. return read;
  113. }
  114. catch (Exception e)
  115. {
  116. result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
  117. resultFlag = false;
  118. return -1;
  119. }
  120. }
  121. //读取PLC商标ID
  122. public int PlcReadLogoid()
  123. {
  124. if (!resultFlag) return -1;
  125. try
  126. {
  127. int read = Convert.ToInt16(SiemensS7.Read<short>(PLC.dbLogoId));
  128. result.Add(new JObject(new JProperty("PLC读取(产品ID)", PLC.dbLogoId + " = " + read.ToString())));
  129. resultFlag = true;
  130. return read;
  131. }
  132. catch (Exception e)
  133. {
  134. result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
  135. resultFlag = false;
  136. return -1;
  137. }
  138. }
  139. public string[] PlcReadBarcodes(int goodsNum)
  140. {
  141. if (!resultFlag) return null;
  142. try
  143. {
  144. string[] barCodes = new string[12];
  145. JObject obj = new JObject();
  146. for (int i = 0; i < goodsNum; i++)
  147. {
  148. barCodes[i] = SiemensS7.Read<string>(PLC.dbBarcodeBlock[i], 11).ToString();
  149. obj.Add(new JProperty("条码" + (i + 1).ToString().PadLeft(2, '0') + "(" + PLC.dbBarcodeBlock[i] + ")", barCodes[i]));
  150. }
  151. result.Add(new JObject(new JProperty("PLC读取(产品条码)", obj)));
  152. resultFlag = true;
  153. return barCodes;
  154. }
  155. catch (Exception e)
  156. {
  157. result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
  158. resultFlag = false;
  159. return null;
  160. }
  161. }
  162. //读取板码
  163. public string PlcReadBanma()
  164. {
  165. if (!resultFlag) return "";
  166. try
  167. {
  168. string read = SiemensS7.Read<string>(PLC.dbBanMa, 8).ToString();
  169. result.Add(new JObject(new JProperty("PLC读取(板码)", PLC.dbBanMa + " = " + read.ToString())));
  170. resultFlag = true;
  171. return read;
  172. }
  173. catch (Exception e)
  174. {
  175. result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
  176. resultFlag = false;
  177. return "";
  178. }
  179. }
  180. //写入条码
  181. public int PlcWriteBarcode(string barCode)
  182. {
  183. if (!resultFlag) return -1;
  184. try
  185. {
  186. SiemensS7.Write<string>(PLC.dbBarcode, barCode);
  187. result.Add(new JObject(new JProperty("PLC写入(条码)", PLC.dbBarcode + " = " + barCode)));
  188. resultFlag = true;
  189. return 1;
  190. }
  191. catch (Exception e)
  192. {
  193. result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
  194. resultFlag = false;
  195. return -1;
  196. }
  197. }
  198. //写入物料码
  199. public int PlcWriteMaterialcode(string materialCode)
  200. {
  201. if (!resultFlag) return -1;
  202. try
  203. {
  204. SiemensS7.Write<string>(PLC.dbMaterialcode, materialCode);
  205. result.Add(new JObject(new JProperty("PLC写入(物料码)", PLC.dbMaterialcode + " = " + materialCode)));
  206. resultFlag = true;
  207. return 1;
  208. }
  209. catch (Exception e)
  210. {
  211. result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
  212. resultFlag = false;
  213. return -1;
  214. }
  215. }
  216. //写入产品ID
  217. public int PlcWriteGoodsid(Int16 goodsId)
  218. {
  219. if (!resultFlag) return -1;
  220. try
  221. {
  222. SiemensS7.Write<short>(PLC.dbGoodsId, goodsId);
  223. result.Add(new JObject(new JProperty("PLC写入(产品ID)", PLC.dbGoodsId + " = " + goodsId)));
  224. resultFlag = true;
  225. return 1;
  226. }
  227. catch (Exception e)
  228. {
  229. result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
  230. resultFlag = false;
  231. return -1;
  232. }
  233. }
  234. //写入商标ID
  235. public int PlcWriteLogoid(Int16 logoId)
  236. {
  237. if (!resultFlag) return -1;
  238. try
  239. {
  240. SiemensS7.Write<short>(PLC.dbLogoId, logoId);
  241. result.Add(new JObject(new JProperty("PLC写入(商标ID)", PLC.dbLogoId + " = " + logoId)));
  242. resultFlag = true;
  243. return 1;
  244. }
  245. catch (Exception e)
  246. {
  247. result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
  248. resultFlag = false;
  249. return -1;
  250. }
  251. }
  252. //写入装板数量
  253. public int PlcWriteGoodsnum(Int16 goodsNum)
  254. {
  255. if (!resultFlag) return -1;
  256. try
  257. {
  258. SiemensS7.Write<short>(PLC.dbGoodsNum, goodsNum);
  259. result.Add(new JObject(new JProperty("PLC写入(装板数量)", PLC.dbGoodsNum + " = " + goodsNum)));
  260. resultFlag = true;
  261. return 1;
  262. }
  263. catch (Exception e)
  264. {
  265. result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
  266. resultFlag = false;
  267. return -1;
  268. }
  269. }
  270. //写入执行结果
  271. public int PlcWriteResult(Int16 flag)
  272. {
  273. try
  274. {
  275. SiemensS7.Write<short>(PLC.dbResult, flag);
  276. result.Add(new JObject(new JProperty("PLC写入(执行结果)", PLC.dbResult + " = " + flag.ToString())));
  277. return 1;
  278. }
  279. catch (Exception e)
  280. {
  281. result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
  282. return -1;
  283. }
  284. }
  285. //加载默认参数
  286. public static JObject ApiLoadDefaultPara()
  287. {
  288. JObject userPara = new JObject();
  289. userPara.Add(new JProperty("accountCode", API.accountCode));
  290. userPara.Add(new JProperty("userCode", API.userCode));
  291. userPara.Add(new JProperty("userPassword", API.userPassword));
  292. userPara.Add(new JProperty("sessionKey", API.sessionKey));
  293. return userPara;
  294. }
  295. //PDA接口验证条码
  296. public int ApiGetStatusBarcode(string barCode)
  297. {
  298. if (!resultFlag) return -1;
  299. try
  300. {
  301. WCF wcf = new WCF();
  302. wcf.Para = ApiLoadDefaultPara();
  303. wcf.Para.Add(new JProperty("procedureID", API.procedureID));
  304. wcf.Para.Add(new JProperty("barCode", barCode));
  305. //测试用
  306. string jsonStr = @"
  307. {
  308. 'd': {
  309. '__type': 'ActionResult:#Dongke.IBOSS.PRD.WCF.DataModels',
  310. 'Message': '读取成功!',
  311. 'Result': '{\'data\':[{\'STATUS\':0.0}]}',
  312. 'Status': 0
  313. }
  314. }
  315. ".Replace("'","\"");
  316. //正式调用
  317. if (!API.debug) jsonStr = wcf.Post("/DKService/PDAModuleService/GetStatusByBarcode");
  318. JObject json = JObject.Parse(jsonStr);
  319. if (json["d"]["Status"].ToString() == "0")
  320. {
  321. result.Add(new JObject(
  322. new JProperty("API调用(条码状态)", "操作成功!"),
  323. new JProperty("接口", "/DKService/PDAModuleService/GetStatusByBarcode"),
  324. new JProperty("参数(procedureID)", API.procedureID),
  325. new JProperty("参数(barCode)", barCode)
  326. //,new JProperty("结果", jsonStr)
  327. )
  328. );
  329. return 1;
  330. }
  331. else
  332. {
  333. resultFlag = false;
  334. result.Add(new JObject(
  335. new JProperty("API调用(条码状态)", "操作失败!"),
  336. new JProperty("接口", "/DKService/PDAModuleService/GetStatusByBarcode"),
  337. new JProperty("参数(procedureID)", API.procedureID),
  338. new JProperty("参数(barCode)", barCode)
  339. //,new JProperty("结果", jsonStr)
  340. )
  341. );
  342. return -1;
  343. }
  344. }
  345. catch (Exception e)
  346. {
  347. resultFlag = false;
  348. result.Add(new JObject(
  349. new JProperty("API调用(条码状态)", "系统异常!"),
  350. new JProperty("接口", "/DKService/PDAModuleService/GetStatusByBarcode"),
  351. new JProperty("参数(procedureID)", API.procedureID),
  352. new JProperty("参数(barCode)", barCode),
  353. new JProperty("异常", e.Message)
  354. )
  355. );
  356. return -1;
  357. }
  358. }
  359. public int ApiCheckBarcode(string barCode)
  360. {
  361. if (!resultFlag) return -1;
  362. try
  363. {
  364. WCF wcf = new WCF();
  365. wcf.Para = ApiLoadDefaultPara();
  366. wcf.Para.Add(new JProperty("procedureID", API.procedureID));
  367. wcf.Para.Add(new JProperty("barCode", barCode));
  368. //测试用
  369. string jsonStr = @"
  370. {
  371. 'd': {
  372. '__type': 'ActionResult:#Dongke.IBOSS.PRD.WCF.DataModels',
  373. 'Message': '操作成功',
  374. 'Result': '[{\'out_errMsg\':\'\',\'out_goodsID\':\'179\',\'out_goodsCode\':\'H0175M\',\'out_goodsName\':\'HC0175PT-305\',\'out_groutingUserCode\':\'SFC035\',\'out_groutingUserName\':null,\'out_groutingUserID\':null,\'out_groutingNum\':\'73\',\'out_mouldCode\':\'C06B11-001\',\'out_ispublicbody\':\'0\',\'out_ispublicbodyTrach\':\'\',\'out_groutingdate\':\'2023/12/30 0:00:00\',\'out_specialRepairFlag\':\'0\',\'out_isReFire\':\'0\',\'out_isLengBu\':\'0\',\'out_missFlag\':\'0\',\'out_logoID\':\'15\',\'out_logoCode\':\'020\',\'out_logoName\':\'HEGII(新)\',\'out_MaterialCode\':\'CT175PD2210B01\',\'out_glazeName\':\'智洁釉\',\'out_deliverLimitCycle\':null,\'out_barcode\':\'00000000001\',\'out_WaterLabelCode\':null,\'out_CodeCheckFlag\':null,\'out_LeakFlag1\':\'\',\'out_LeakFlag2\':\'\',\'out_LeakFlag3\':\'\',\'out_specialRepairFlagName\':\'否\',\'out_isReFireName\':\'否\',\'out_LeakFlag1Name\':\'未检测\',\'out_LeakFlag2Name\':\'未检测\',\'out_LeakFlag3Name\':\'未检测\',\'out_lengBuName\':\'否\',\'out_LeakFlag4\':\'\',\'out_LeakFlag5\':\'\',\'out_LeakFlag4Name\':\'未检测\',\'out_LeakFlag5Name\':\'未检测\',\'GOODSMODELforCheck\':\'CT175PD2210B01#0\',\'PlateLimitNum\':12,\'DefectFlagID\':null,\'pdid\':null,\'InspectionLevel\':\'\',\'PackingDefect\':\'\',\'InspectionGoodsLevel\':\'\',\'offlineFlag\':\'0\',\'recyclingFlag\':\'0\',\'waterLabelCode\':\'http://wl.bbqk.com/2bwta/0.html\',\'PLCWeight\':0.0}]',
  375. 'Status': 0
  376. }
  377. }
  378. ".Replace("'","\"");
  379. //正式用
  380. if (!API.debug) jsonStr = wcf.Post("/DKService/PDAModuleService/CheckBarcode");
  381. JObject json = JObject.Parse(jsonStr);
  382. if (json["d"]["Status"].ToString() == "0")
  383. {
  384. result.Add(new JObject(
  385. new JProperty("API调用(条码验证)", "操作成功!"),
  386. new JProperty("接口", "/DKService/PDAModuleService/CheckBarcode"),
  387. new JProperty("参数(procedureID)", API.procedureID),
  388. new JProperty("参数(barCode)", barCode)
  389. //,new JProperty("结果", jsonStr)
  390. )
  391. );
  392. return 1;
  393. }
  394. else
  395. {
  396. resultFlag = false;
  397. result.Add(new JObject(
  398. new JProperty("API调用(条码验证)", "操作失败!"),
  399. new JProperty("接口", "/DKService/PDAModuleService/CheckBarcode"),
  400. new JProperty("参数(procedureID)", API.procedureID),
  401. new JProperty("参数(barCode)", barCode)
  402. //,new JProperty("结果", jsonStr)
  403. )
  404. );
  405. return -1;
  406. }
  407. }
  408. catch (Exception e)
  409. {
  410. resultFlag = false;
  411. result.Add(new JObject(
  412. new JProperty("API调用(条码验证)", "系统异常!"),
  413. new JProperty("接口", "/DKService/PDAModuleService/CheckBarcode"),
  414. new JProperty("参数(procedureID)", API.procedureID),
  415. new JProperty("参数(barCode)", barCode),
  416. new JProperty("异常", e.Message)
  417. )
  418. );
  419. return -1;
  420. }
  421. }
  422. public int ApiFinishedLoadingCar(string barCode,int logoId,int goodsId)
  423. {
  424. if (!resultFlag) return -1;
  425. string jsonData = "{\"logoID\":\"" + logoId.ToString() + "\",\"GoodsID\":\"" + goodsId.ToString() + "\"}";
  426. try
  427. {
  428. WCF wcf = new WCF();
  429. wcf.Para = ApiLoadDefaultPara();
  430. wcf.Para.Add(new JProperty("procedureID", API.procedureID));
  431. wcf.Para.Add(new JProperty("barcode", barCode));
  432. wcf.Para.Add(new JProperty("module", "FinishedLoadingCar"));
  433. wcf.Para.Add(new JProperty("action", "GetSetting"));
  434. wcf.Para.Add(new JProperty("jsonData", jsonData));
  435. //测试用
  436. string jsonStr = @"
  437. {
  438. 'd': {
  439. '__type': 'ActionResult:#Dongke.IBOSS.PRD.WCF.DataModels',
  440. 'Message': '操作成功',
  441. 'Result': '{\'GoodsID\':\'179\',\'logoID\':\'15\',\'S_PM_011\':\'1\',\'S_PM_012\':\'1\',\'S_PM_013\':\'1\',\'PlatelitNum\':12,\'PlatelitNumNew\':2}',
  442. 'Status': 0
  443. }
  444. }
  445. ".Replace("'","\"");
  446. //正式用
  447. if (!API.debug) jsonStr = wcf.Post("/DKService/PDAModuleService/DoAction");
  448. JObject json = JObject.Parse(jsonStr);
  449. if (json["d"]["Status"].ToString() == "0")
  450. {
  451. JObject goods = JObject.Parse(json["d"]["Result"].ToString());
  452. int goodsNum = Convert.ToInt32(goods["PlatelitNum"]);
  453. //int goodsNum = Convert.ToInt32(goods["PlatelitNumNew"]);
  454. result.Add(new JObject(
  455. new JProperty("API调用(装板数量)", goodsNum.ToString() + "操作成功!"),
  456. new JProperty("接口", "/DKService/PDAModuleService/DoAction"),
  457. new JProperty("参数(ACTION)", "GetSetting"),
  458. new JProperty("参数(MODULE)", "FinishedLoadingCar"),
  459. new JProperty("参数(jsonData)",jsonData)
  460. //,new JProperty("结果", jsonStr)
  461. )
  462. );
  463. return goodsNum;
  464. }
  465. else
  466. {
  467. resultFlag = false;
  468. result.Add(new JObject(
  469. new JProperty("API调用(装板数量)", "操作失败!"),
  470. new JProperty("接口", "/DKService/PDAModuleService/DoAction"),
  471. new JProperty("参数(ACTION)", "GetSetting"),
  472. new JProperty("参数(MODULE)", "FinishedLoadingCar"),
  473. new JProperty("参数(jsonData)",jsonData)
  474. //,new JProperty("结果", jsonStr)
  475. )
  476. );
  477. return -1;
  478. }
  479. }
  480. catch (Exception e)
  481. {
  482. resultFlag = false;
  483. result.Add(new JObject(
  484. new JProperty("API调用(装板数量)", "系统异常!"),
  485. new JProperty("接口", "/DKService/PDAModuleService/DoAction"),
  486. new JProperty("参数(ACTION)", "GetSetting"),
  487. new JProperty("参数(MODULE)", "FinishedLoadingCar"),
  488. new JProperty("参数(jsonData)",jsonData),
  489. new JProperty("异常", e.Message)
  490. )
  491. );
  492. return -1;
  493. }
  494. }
  495. public int ApiAddWorkPiece(string[] barCodes, string banMa, int goodsNum)
  496. {
  497. if (!resultFlag) return -1;
  498. JArray productionDataEntitys = new JArray();
  499. for (int i = 0; i < goodsNum; i++)
  500. {
  501. JObject obj = new JObject(
  502. new JProperty("UserID", API.userId),
  503. new JProperty("UserCode", API.userCode),
  504. new JProperty("UserName", API.userName),
  505. new JProperty("Barcode", barCodes[i]),
  506. new JProperty("BanMa", banMa)
  507. );
  508. productionDataEntitys.Add(obj);
  509. }
  510. try
  511. {
  512. WCF wcf = new WCF();
  513. wcf.Para = ApiLoadDefaultPara();
  514. wcf.Para.Add(new JProperty("procedureID", API.procedureID));
  515. wcf.Para.Add(new JProperty("productionDataEntitys", productionDataEntitys));
  516. //测试用
  517. string jsonStr = @"
  518. {
  519. 'd': {
  520. '__type': 'ActionResult:#Dongke.IBOSS.PRD.WCF.DataModels',
  521. 'Message': '操作成功',
  522. 'Result': '[{\'out_errMsg\':\'\',\'out_goodsID\':\'179\',\'out_goodsCode\':\'H0175M\',\'out_goodsName\':\'HC0175PT-305\',\'out_groutingUserCode\':\'SFC035\',\'out_groutingUserName\':null,\'out_groutingUserID\':null,\'out_groutingNum\':null,\'out_mouldCode\':null,\'out_ispublicbody\':null,\'out_ispublicbodyTrach\':null,\'out_groutingdate\':\'\',\'out_specialRepairFlag\':null,\'out_isReFire\':null,\'out_isLengBu\':null,\'out_missFlag\':null,\'out_logoID\':null,\'out_logoCode\':\'\',\'out_logoName\':\'\',\'out_MaterialCode\':null,\'out_glazeName\':null,\'out_deliverLimitCycle\':null,\'out_barcode\':null,\'out_WaterLabelCode\':null,\'out_CodeCheckFlag\':null,\'out_LeakFlag1\':null,\'out_LeakFlag2\':null,\'out_LeakFlag3\':null,\'out_specialRepairFlagName\':null,\'out_isReFireName\':null,\'out_LeakFlag1Name\':null,\'out_LeakFlag2Name\':null,\'out_LeakFlag3Name\':null,\'out_lengBuName\':null,\'out_LeakFlag4\':null,\'out_LeakFlag5\':null,\'out_LeakFlag4Name\':null,\'out_LeakFlag5Name\':null,\'GOODSMODELforCheck\':null,\'PlateLimitNum\':null,\'DefectFlagID\':null,\'pdid\':null,\'InspectionLevel\':null,\'PackingDefect\':null,\'InspectionGoodsLevel\':null,\'offlineFlag\':null,\'recyclingFlag\':null,\'waterLabelCode\':null}]',
  523. 'Status': 0
  524. }
  525. }
  526. ".Replace("'","\"");
  527. //正式用
  528. if (!API.debug) jsonStr = wcf.Post("/DKService/PDAModuleService/AddWorkPiece");
  529. JObject json = JObject.Parse(jsonStr);
  530. if (json["d"]["Status"].ToString() == "0")
  531. {
  532. result.Add(new JObject(
  533. new JProperty("API调用(包装码垛)", "操作成功!"),
  534. new JProperty("接口", "/DKService/PDAModuleService/AddWorkPiece"),
  535. new JProperty("参数(procedureID)", API.procedureID),
  536. new JProperty("参数(productionDataEntitys)", productionDataEntitys)
  537. //,new JProperty("结果", jsonStr)
  538. )
  539. );
  540. return 1;
  541. }
  542. else
  543. {
  544. resultFlag = false;
  545. result.Add(new JObject(
  546. new JProperty("API调用(包装码垛)", "操作失败!"),
  547. new JProperty("接口", "/DKService/PDAModuleService/AddWorkPiece"),
  548. new JProperty("参数(procedureID)", API.procedureID),
  549. new JProperty("参数(productionDataEntitys)", productionDataEntitys)
  550. //,new JProperty("结果", jsonStr)
  551. )
  552. );
  553. return -1;
  554. }
  555. }
  556. catch (Exception e)
  557. {
  558. resultFlag = false;
  559. result.Add(new JObject(
  560. new JProperty("API调用(包装码垛)", "系统异常!"),
  561. new JProperty("接口", "/DKService/PDAModuleService/AddWorkPiece"),
  562. new JProperty("参数(procedureID)", API.procedureID),
  563. new JProperty("参数(productionDataEntitys)", productionDataEntitys),
  564. new JProperty("异常", e.Message)
  565. )
  566. );
  567. return -1;
  568. }
  569. }
  570. public DataRow GetGoods(string outCode)
  571. {
  572. try
  573. {
  574. using (IDataAccess conn = DataAccess.Create())
  575. {
  576. DataTable dt = conn.ExecuteDatatable(@"
  577. SELECT
  578. gd.OUTLABELCODE,gd.BARCODE,gd.GOODSID,gd.LOGOID,gd.MATERIALCODE
  579. FROM
  580. TP_PM_GROUTINGDAILYDETAIL gd
  581. WHERE
  582. gd.VALUEFLAG = '1'
  583. AND gd.OUTLABELCODE = @OUTLABELCODE@
  584. ",
  585. new CDAParameter("OUTLABELCODE", outCode)
  586. );
  587. if(dt.Rows.Count >0 )
  588. {
  589. JObject obj = new JObject();
  590. obj.Add(new JProperty("OUTLABELCODE", dt.Rows[0]["OUTLABELCODE"].ToString()));
  591. obj.Add(new JProperty("BARCODE", dt.Rows[0]["BARCODE"].ToString()));
  592. obj.Add(new JProperty("MATERIALCODE", dt.Rows[0]["MATERIALCODE"].ToString()));
  593. obj.Add(new JProperty("GOODSID", dt.Rows[0]["GOODSID"].ToString()));
  594. obj.Add(new JProperty("LOGOID", dt.Rows[0]["LOGOID"].ToString()));
  595. obj.Add(new JProperty("GOODSNUM", dt.Rows[0]["GOODSNUM"].ToString()));
  596. result.Add(new JObject(new JProperty("MES读取(产品信息)", obj)));
  597. return dt.Rows[0];
  598. }
  599. else
  600. {
  601. resultFlag = false;
  602. result.Add(new JObject(new JProperty("MES读取(产品信息)","产品未找到!")));
  603. return null;
  604. }
  605. }
  606. }
  607. catch (Exception e)
  608. {
  609. resultFlag = false;
  610. result.Add(new JObject(new JProperty("系统异常", e.Message)));
  611. return null;
  612. }
  613. }
  614. //主程序入口
  615. public void ProcessRequest(HttpContext context)
  616. {
  617. context.Response.ContentType = "text/plain";
  618. if (context.Request["barcode"] is object)
  619. {
  620. BarcodeRead(context);
  621. }
  622. else
  623. {
  624. BarcodeDo(context);
  625. }
  626. }
  627. // 读取条码,对接扫描头使用
  628. public void BarcodeRead(HttpContext context)
  629. {
  630. if (PlcOpen() == 1)
  631. {
  632. int readFlag = PlcReadReadFlag();
  633. string barCode = "";
  634. string materialCode = "";
  635. Int16 goodsId = 0;
  636. Int16 logoId = 0;
  637. Int16 goodsNum = 0;
  638. //条码处理
  639. if(readFlag == 1 || readFlag == 0)
  640. {
  641. DataRow dr = GetGoods(context.Request["barcode"].ToString());
  642. if (resultFlag)
  643. {
  644. barCode = dr["BARCODE"].ToString();
  645. materialCode = dr["MATERIALCODE"].ToString();
  646. goodsId = Convert.ToInt16(dr["GOODSID"]);
  647. logoId = Convert.ToInt16(dr["LOGOID"]);
  648. //接口验证条码状态
  649. int status = ApiGetStatusBarcode(barCode);
  650. //接口验证可到达
  651. int check = ApiCheckBarcode(barCode);
  652. //写验证结果
  653. if (status == -1 || check == -1) PlcWriteResult(3);
  654. //获取装板数量
  655. goodsNum = Convert.ToInt16(ApiFinishedLoadingCar(barCode, logoId, goodsId));
  656. }
  657. }
  658. //首个条码处理
  659. if (readFlag == 1 && resultFlag)
  660. {
  661. //写PLC
  662. PlcWriteBarcode(barCode);
  663. PlcWriteMaterialcode(materialCode);
  664. //PlcWriteGoodsid(goodsId);
  665. //PlcWriteLogoid(logoId);
  666. PlcWriteGoodsnum(goodsNum);
  667. //写结果
  668. if (resultFlag) PlcWriteResult(1); else PlcWriteResult(4);
  669. }
  670. //过程条码处理
  671. if (readFlag == 0 && resultFlag)
  672. {
  673. //写PLC
  674. PlcWriteBarcode(barCode);
  675. PlcWriteMaterialcode(materialCode);
  676. //PlcWriteGoodsid(goodsId);
  677. //PlcWriteLogoid(logoId);
  678. //PlcWriteGoodsnum(goodsNum);
  679. //写结果
  680. if (resultFlag) PlcWriteResult(1); else PlcWriteResult(4);
  681. }
  682. PlcClose();
  683. }
  684. context.Response.Write(new JsonResult(resultFlag ? JsonStatus.success : JsonStatus.error) { rows = result }.ToJson());
  685. }
  686. // 绑板处理,轮询到标识,绑板处理
  687. public void BarcodeDo(HttpContext context)
  688. {
  689. if (PlcOpen() == 1)
  690. {
  691. int readFlag = PlcReadReadFlag();
  692. int goodsNum = PlcReadGoodsnum();
  693. //绑板处理
  694. if(readFlag == 2 || readFlag == 3)
  695. {
  696. String[] barCodes = PlcReadBarcodes(goodsNum);
  697. string banMa = "";
  698. if (readFlag == 3) banMa = PlcReadBanma();
  699. //绑板处理
  700. ApiAddWorkPiece(barCodes, banMa, goodsNum);
  701. //写入结果
  702. PlcWriteResult(6);
  703. }
  704. //强制绑板完成
  705. if(readFlag == 4)
  706. {
  707. PlcWriteResult(6);
  708. }
  709. PlcClose();
  710. }
  711. context.Response.Write(new JsonResult(resultFlag ? JsonStatus.success : JsonStatus.error) { rows = result }.ToJson());
  712. }
  713. public bool IsReusable
  714. {
  715. get
  716. {
  717. return false;
  718. }
  719. }
  720. }