plc_led_data_old.ashx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <%@ WebHandler Language="C#" Class="plc_led_data_old" %>
  2. using System;
  3. using System.Web;
  4. using System.Collections.Generic;
  5. using Curtain.Net.Sockets;
  6. using DK.XuWei.WebMes;
  7. using Curtain.DataAccess;
  8. using Curtain.Log;
  9. using System.Data;
  10. /// <summary>
  11. /// 对接LED看板,用于成检显示产品属性信息
  12. /// xuwei
  13. /// 2023-08-08
  14. /// </summary>
  15. public class plc_led_data_old : IHttpHandler
  16. {
  17. public struct LedData
  18. {
  19. public int goodscode;
  20. public int goodsspecification;
  21. public int goodstype;
  22. public string barcode;
  23. }
  24. public void ProcessRequest(HttpContext context)
  25. {
  26. context.Response.ContentType = "text/plain";
  27. List<LedData> ledData = new List<LedData>();
  28. int scanFlag = 0;
  29. //写入PLC
  30. //SiemensS7.Open("172.19.26.241", 102);
  31. ////移位标识
  32. //int moveFlag = Convert.ToInt16(SiemensS7.Read<short>("1.2"));
  33. //context.Response.Write(SiemensS7.Read<short>("1.2"));
  34. //context.Response.Write(moveFlag);
  35. //Logger.Info("moveFlag: " + moveFlag +" ;barcode: " + context.Request["barcode"]);
  36. //if (context.Application["led_data"] is object)
  37. //{
  38. // ledData = (List<LedData>)context.Application["led_data"];
  39. //}
  40. ////条码转换生产数据
  41. //if (moveFlag == 1 && ledData.Count > 0)
  42. //{
  43. // ledData.RemoveAt(0);
  44. // //写业务数据
  45. // if (ledData.Count > 0)
  46. // {
  47. // for (int i = 0; i < ledData.Count; i++)
  48. // {
  49. // if (i == 0)
  50. // {
  51. // SiemensS7.Write<short>("1.6", Convert.ToInt16(ledData[i].goodscode));
  52. // SiemensS7.Write<short>("1.8", Convert.ToInt16(ledData[i].goodsspecification));
  53. // SiemensS7.Write<short>("1.10", Convert.ToInt16(ledData[i].goodstype));
  54. // SiemensS7.Write<string>("1.14", ledData[i].barcode);
  55. // }
  56. // //context.Response.Write(SiemensS7.Read<string>("1.14",11));
  57. // if (i == 1)
  58. // {
  59. // SiemensS7.Write<short>("1.26", Convert.ToInt16(ledData[i].goodscode));
  60. // SiemensS7.Write<short>("1.28", Convert.ToInt16(ledData[i].goodsspecification));
  61. // SiemensS7.Write<short>("1.30", Convert.ToInt16(ledData[i].goodstype));
  62. // SiemensS7.Write<string>("1.34", ledData[i].barcode);
  63. // }
  64. // if (i == 2)
  65. // {
  66. // SiemensS7.Write<short>("1.46", Convert.ToInt16(ledData[i].goodscode));
  67. // SiemensS7.Write<short>("1.48", Convert.ToInt16(ledData[i].goodsspecification));
  68. // SiemensS7.Write<short>("1.50", Convert.ToInt16(ledData[i].goodstype));
  69. // SiemensS7.Write<string>("1.54", ledData[i].barcode);
  70. // }
  71. // if (i == 3)
  72. // {
  73. // SiemensS7.Write<short>("1.66", Convert.ToInt16(ledData[i].goodscode));
  74. // SiemensS7.Write<short>("1.68", Convert.ToInt16(ledData[i].goodsspecification));
  75. // SiemensS7.Write<short>("1.70", Convert.ToInt16(ledData[i].goodstype));
  76. // SiemensS7.Write<string>("1.74", ledData[i].barcode);
  77. // }
  78. // if (i == 4)
  79. // {
  80. // SiemensS7.Write<short>("1.86", Convert.ToInt16(ledData[i].goodscode));
  81. // SiemensS7.Write<short>("1.88", Convert.ToInt16(ledData[i].goodsspecification));
  82. // SiemensS7.Write<short>("1.90", Convert.ToInt16(ledData[i].goodstype));
  83. // SiemensS7.Write<string>("1.94", ledData[i].barcode);
  84. // }
  85. // }
  86. // }
  87. // else
  88. // {
  89. // //写业务数据
  90. // SiemensS7.Write<short>("1.6", Convert.ToInt16(0));
  91. // SiemensS7.Write<short>("1.8", Convert.ToInt16(0));
  92. // SiemensS7.Write<short>("1.10", Convert.ToInt16(0));
  93. // SiemensS7.Write<string>("1.14", "00000000000");
  94. // SiemensS7.Write<short>("1.26", Convert.ToInt16(0));
  95. // SiemensS7.Write<short>("1.28", Convert.ToInt16(0));
  96. // SiemensS7.Write<short>("1.30", Convert.ToInt16(0));
  97. // SiemensS7.Write<string>("1.34", "00000000000");
  98. // SiemensS7.Write<short>("1.46", Convert.ToInt16(0));
  99. // SiemensS7.Write<short>("1.48", Convert.ToInt16(0));
  100. // SiemensS7.Write<short>("1.50", Convert.ToInt16(0));
  101. // SiemensS7.Write<string>("1.54", "00000000000");
  102. // SiemensS7.Write<short>("1.66", Convert.ToInt16(0));
  103. // SiemensS7.Write<short>("1.68", Convert.ToInt16(0));
  104. // SiemensS7.Write<short>("1.70", Convert.ToInt16(0));
  105. // SiemensS7.Write<string>("1.74", "00000000000");
  106. // SiemensS7.Write<short>("1.86", Convert.ToInt16(0));
  107. // SiemensS7.Write<short>("1.88", Convert.ToInt16(0));
  108. // SiemensS7.Write<short>("1.90", Convert.ToInt16(0));
  109. // SiemensS7.Write<string>("1.94", "00000000000");
  110. // }
  111. // //写标识位-扫描结果
  112. // SiemensS7.Write<short>("1.0", Convert.ToInt16(0));
  113. // SiemensS7.Write<short>("1.2", Convert.ToInt16(0));
  114. // SiemensS7.Write<short>("1.4", Convert.ToInt16(1));
  115. // context.Application["led_data"] = ledData;
  116. //}
  117. //else if (moveFlag == 2)
  118. //{
  119. // ledData = new List<LedData>();
  120. // //写业务数据
  121. // SiemensS7.Write<short>("1.6", Convert.ToInt16(0));
  122. // SiemensS7.Write<short>("1.8", Convert.ToInt16(0));
  123. // SiemensS7.Write<short>("1.10", Convert.ToInt16(0));
  124. // SiemensS7.Write<string>("1.14", "00000000000");
  125. // SiemensS7.Write<short>("1.26", Convert.ToInt16(0));
  126. // SiemensS7.Write<short>("1.28", Convert.ToInt16(0));
  127. // SiemensS7.Write<short>("1.30", Convert.ToInt16(0));
  128. // SiemensS7.Write<string>("1.34", "00000000000");
  129. // SiemensS7.Write<short>("1.46", Convert.ToInt16(0));
  130. // SiemensS7.Write<short>("1.48", Convert.ToInt16(0));
  131. // SiemensS7.Write<short>("1.50", Convert.ToInt16(0));
  132. // SiemensS7.Write<string>("1.54", "00000000000");
  133. // SiemensS7.Write<short>("1.66", Convert.ToInt16(0));
  134. // SiemensS7.Write<short>("1.68", Convert.ToInt16(0));
  135. // SiemensS7.Write<short>("1.70", Convert.ToInt16(0));
  136. // SiemensS7.Write<string>("1.74", "00000000000");
  137. // SiemensS7.Write<short>("1.86", Convert.ToInt16(0));
  138. // SiemensS7.Write<short>("1.88", Convert.ToInt16(0));
  139. // SiemensS7.Write<short>("1.90", Convert.ToInt16(0));
  140. // SiemensS7.Write<string>("1.94", "00000000000");
  141. // //写标识位-扫描结果
  142. // SiemensS7.Write<short>("1.0", Convert.ToInt16(0));
  143. // SiemensS7.Write<short>("1.2", Convert.ToInt16(0));
  144. // SiemensS7.Write<short>("1.4", Convert.ToInt16(1));
  145. // context.Application["led_data"] = ledData;
  146. //}
  147. //else if (moveFlag == 0)
  148. //{
  149. // if (context.Request["barcode"] is object)
  150. // {
  151. // using (IDataAccess conn = DataAccess.Create())
  152. // {
  153. // DataTable infoDt = conn.ExecuteDatatable(@"
  154. // SELECT lgi.ledgoodsid
  155. // ,CASE
  156. // WHEN instr(g.goodsspecification, '305') = 1 THEN 1
  157. // WHEN instr(g.goodsspecification, '400') = 1 THEN 2
  158. // WHEN instr(g.goodsspecification, '地排') = 1 THEN 3
  159. // WHEN instr(g.goodsspecification, '横排') = 1 THEN 4
  160. // END AS goodsspecification
  161. // ,CASE
  162. // WHEN instr(gt.goodstypename, '连体') = 1 THEN 1
  163. // WHEN instr(gt.goodstypename, '智能') = 1 THEN 2
  164. // END AS goodstypename
  165. // ,gdd.barcode
  166. // FROM tp_pm_groutingdailydetail gdd
  167. // LEFT JOIN tp_mst_goods g
  168. // ON gdd.goodsid = g.goodsid
  169. // LEFT JOIN tp_mst_goodstype gt
  170. // ON gt.goodstypeid = g.goodstypeid
  171. // LEFT JOIN tp_mst_ledgoodsinfo lgi
  172. // ON lgi.goodscode = g.goodscode
  173. // WHERE gdd.barcode = @barcode@
  174. // ",
  175. // new CDAParameter("barcode", context.Request["barcode"])
  176. // );
  177. // if (infoDt != null && infoDt.Rows.Count > 0 && infoDt.Rows[0] != null)
  178. // {
  179. // if (ledData.Count < 5)
  180. // {
  181. // //for (int i = 0; i < ledData.Count; i++)
  182. // //{
  183. // // if (ledData[i].barcode == infoDt.Rows[0]["barcode"].ToString())
  184. // // {
  185. // // scanFlag = 1;
  186. // // }
  187. // //}
  188. // if (scanFlag == 0)
  189. // {
  190. // ledData.Add(new LedData()
  191. // {
  192. // goodscode = Convert.ToInt32(infoDt.Rows[0]["ledgoodsid"]),
  193. // goodsspecification = Convert.ToInt32(infoDt.Rows[0]["goodsspecification"]),
  194. // goodstype = Convert.ToInt32(infoDt.Rows[0]["goodstypename"]),
  195. // barcode = infoDt.Rows[0]["barcode"].ToString()
  196. // });
  197. // }
  198. // }
  199. // else
  200. // {
  201. // scanFlag = 1;
  202. // }
  203. // }
  204. // }
  205. // context.Application["led_data"] = ledData;
  206. // if (scanFlag == 0) {
  207. // //写业务数据
  208. // for (int i = 0; i < ledData.Count; i++)
  209. // {
  210. // if (i == 0)
  211. // {
  212. // SiemensS7.Write<short>("1.6", Convert.ToInt16(ledData[i].goodscode));
  213. // SiemensS7.Write<short>("1.8", Convert.ToInt16(ledData[i].goodsspecification));
  214. // SiemensS7.Write<short>("1.10", Convert.ToInt16(ledData[i].goodstype));
  215. // SiemensS7.Write<string>("1.14", ledData[i].barcode);
  216. // }
  217. // //context.Response.Write(SiemensS7.Read<string>("1.14",11));
  218. // if (i == 1)
  219. // {
  220. // SiemensS7.Write<short>("1.26", Convert.ToInt16(ledData[i].goodscode));
  221. // SiemensS7.Write<short>("1.28", Convert.ToInt16(ledData[i].goodsspecification));
  222. // SiemensS7.Write<short>("1.30", Convert.ToInt16(ledData[i].goodstype));
  223. // SiemensS7.Write<string>("1.34", ledData[i].barcode);
  224. // }
  225. // if (i == 2)
  226. // {
  227. // SiemensS7.Write<short>("1.46", Convert.ToInt16(ledData[i].goodscode));
  228. // SiemensS7.Write<short>("1.48", Convert.ToInt16(ledData[i].goodsspecification));
  229. // SiemensS7.Write<short>("1.50", Convert.ToInt16(ledData[i].goodstype));
  230. // SiemensS7.Write<string>("1.54", ledData[i].barcode);
  231. // }
  232. // if (i == 3)
  233. // {
  234. // SiemensS7.Write<short>("1.66", Convert.ToInt16(ledData[i].goodscode));
  235. // SiemensS7.Write<short>("1.68", Convert.ToInt16(ledData[i].goodsspecification));
  236. // SiemensS7.Write<short>("1.70", Convert.ToInt16(ledData[i].goodstype));
  237. // SiemensS7.Write<string>("1.74", ledData[i].barcode);
  238. // }
  239. // if (i == 4)
  240. // {
  241. // SiemensS7.Write<short>("1.86", Convert.ToInt16(ledData[i].goodscode));
  242. // SiemensS7.Write<short>("1.88", Convert.ToInt16(ledData[i].goodsspecification));
  243. // SiemensS7.Write<short>("1.90", Convert.ToInt16(ledData[i].goodstype));
  244. // SiemensS7.Write<string>("1.94", ledData[i].barcode);
  245. // }
  246. // }
  247. // //写标识位-扫描结果
  248. // SiemensS7.Write<short>("1.0", Convert.ToInt16(1));
  249. // SiemensS7.Write<short>("1.2", Convert.ToInt16(0));
  250. // SiemensS7.Write<short>("1.4", Convert.ToInt16(0));
  251. // }
  252. // else if (scanFlag == 1)
  253. // {
  254. // //写标识位-扫描结果
  255. // SiemensS7.Write<short>("1.0", Convert.ToInt16(2));
  256. // SiemensS7.Write<short>("1.2", Convert.ToInt16(0));
  257. // }
  258. // }
  259. // else
  260. // {
  261. // //写标识位-扫描结果
  262. // SiemensS7.Write<short>("1.0", Convert.ToInt16(2));
  263. // }
  264. //}
  265. //context.Response.Write(new JsonResult(ledData).ToJson());
  266. //SiemensS7.Close();
  267. }
  268. public bool IsReusable
  269. {
  270. get
  271. {
  272. return false;
  273. }
  274. }
  275. }