| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- <%@ WebHandler Language="C#" Class="plc_led_data_print3124" %>
- using System;
- using System.Web;
- using System.Collections.Generic;
- using Curtain.Net.Sockets;
- using DK.XuWei.WebMes;
- using Curtain.DataAccess;
- using Curtain.Log;
- using System.Data;
- using Newtonsoft.Json.Linq;
- using System.Collections;
- /// <summary>
- /// 对接LED看板,用于成检显示产品属性信息,打印包装2线
- /// xuwei
- /// 2026-08-19
- /// </summary>
- public class plc_led_data_print3124 : IHttpHandler
- {
- public struct LedData
- {
- public int goodscode;
- public int goodsspecification;
- public int goodstype;
- public string barcode;
- }
- //输入参数 【条码】
- public string barCode = "";
- string procedure_no;
- string fentiprocedure_no;
- string procedure_in;
- string road_no;
- string rack;
- string position;
- //返回失败提示
- public string message = "";
- public void ProcessRequest(HttpContext context)
- {
- try
- {
- context.Response.ContentType = "text/plain";
- //输入输出参数初始化 计件
- barCode = context.Request["barcode"] is object ? context.Request["barcode"] : "";
- procedure_no = context.Request["procedure_no"] is object ? context.Request["procedure_no"] : "1_1_3";
- fentiprocedure_no = "1_1_4";
- procedure_in = "1";
- road_no = "0";
- rack = "";
- position = "";
- DataTable infoDt = new DataTable();
- //写入PLC
- //正式
- SiemensS7.Open("172.19.26.152", 102);
- if (context.Request["barcode"] is object)
- {
- using (IDataAccess conn = DataAccess.Create())
- {
- infoDt = conn.ExecuteDatatable(@"
- SELECT g.seatcovercode
- ,CASE
- WHEN instr(g.goodsspecification, '305') = 1 THEN 1
- WHEN instr(g.goodsspecification, '400') = 1 THEN 2
- WHEN instr(g.goodsspecification, '地排') = 1 THEN 3
- WHEN instr(g.goodsspecification, '横排') = 1 THEN 4
- WHEN instr(g.goodsspecification, '295') = 1 THEN 5
- WHEN instr(g.goodsspecification, '220') = 1 THEN 6
- WHEN instr(g.goodsspecification, '300') = 1 THEN 7
- END AS goodsspecification
- ,CASE
- WHEN instr(gt.goodstypename, '连体') = 1 THEN 1
- WHEN instr(gt.goodstypename, '智能') = 1 THEN 2
- END AS goodstypename
- ,CASE WHEN g.goodsid in (178,177,164,163,166,150,149,182,183,190,191,186,187) THEN '分体'
- when g.goodsid in(158,159,167) and gdd.logoid in (7,14) THEN '分体'
- when g.goodsid in(188,189) and gdd.logoid in (7,17) THEN '分体'
- when g.goodsid in(146,147) and gdd.logoid in (1) THEN '分体'
- ELSE '大件' END AS pritetype
- ,gdd.barcode
- ,g.goodscode
- FROM tp_pm_groutingdailydetail gdd
- LEFT JOIN tp_mst_goods g
- ON gdd.goodsid = g.goodsid
- LEFT JOIN tp_mst_goodstype gt
- ON gt.goodstypeid = g.goodstypeid
- WHERE gdd.barcode = @barcode@
- ",
- new CDAParameter("barcode", context.Request["barcode"])
- );
- if (infoDt != null && infoDt.Rows.Count > 0 && infoDt.Rows[0] != null)
- {
- SiemensS7.Write<short>("31.2", Convert.ToInt16(infoDt.Rows[0]["seatcovercode"]));
- SiemensS7.Write<short>("31.4", Convert.ToInt16(infoDt.Rows[0]["goodsspecification"]));
- SiemensS7.Write<short>("31.6", Convert.ToInt16(infoDt.Rows[0]["goodstypename"]));
- SiemensS7.Write<string>("31.10", infoDt.Rows[0]["barcode"].ToString());
- SiemensS7.Write<string>("31.24", infoDt.Rows[0]["goodscode"].ToString());
- //写标识位-扫描结果
- //写标识位-扫描结果
- SiemensS7.Write<short>("31.0", Convert.ToInt16(1));
- }
- context.Response.Write(SiemensS7.Read<short>("31.0"));
- context.Response.Write(SiemensS7.Read<short>("31.2"));
- context.Response.Write(SiemensS7.Read<short>("31.4"));
- context.Response.Write(SiemensS7.Read<short>("31.6"));
- context.Response.Write(SiemensS7.Read<string>("31.24", 11));
- if (infoDt != null && infoDt.Rows.Count > 0 && infoDt.Rows[0] != null)
- {
- if (Convert.ToInt16(infoDt.Rows[0]["seatcovercode"]) != Convert.ToInt16(SiemensS7.Read<short>("31.2"))
- || Convert.ToInt16(infoDt.Rows[0]["goodsspecification"]) != Convert.ToInt16(SiemensS7.Read<short>("31.4"))
- || Convert.ToInt16(infoDt.Rows[0]["goodstypename"]) != Convert.ToInt16(SiemensS7.Read<short>("31.6"))
- || Convert.ToInt16(1) != Convert.ToInt16(SiemensS7.Read<short>("31.0")))
- {
- SiemensS7.Write<short>("31.2", Convert.ToInt16(infoDt.Rows[0]["seatcovercode"]));
- SiemensS7.Write<short>("31.4", Convert.ToInt16(infoDt.Rows[0]["goodsspecification"]));
- SiemensS7.Write<short>("31.6", Convert.ToInt16(infoDt.Rows[0]["goodstypename"]));
- SiemensS7.Write<string>("31.10", infoDt.Rows[0]["barcode"].ToString());
- SiemensS7.Write<string>("31.24", infoDt.Rows[0]["goodscode"].ToString());
- //写标识位-扫描结果
- SiemensS7.Write<short>("31.0", Convert.ToInt16(1));
- }
- }
- Logger.Info("写入数据完成!barcode:" + context.Request["barcode"].ToString() + "五位数据位:" + SiemensS7.Read<short>("31.0") + "," + SiemensS7.Read<short>("31.2")
- + "," + SiemensS7.Read<short>("31.4") + "," + SiemensS7.Read<short>("31.6") + "," + SiemensS7.Read<short>("31.10") + "," + SiemensS7.Read<string>("31.24", 11) + ";数据:" + new JsonResult(infoDt).ToJson());
- }
- //调用标准计件方法===============================
- if (infoDt != null && infoDt.Rows.Count > 0 && infoDt.Rows[0] != null)
- {
- if (infoDt.Rows[0]["pritetype"].ToString() == "分体")
- {
- procedure_no = fentiprocedure_no;
- }
- WCF wcf = new WCF();
- wcf.Para.Add(new JProperty("barcode", barCode.ToString()));
- wcf.Para.Add(new JProperty("procedure_no", procedure_no));
- wcf.Para.Add(new JProperty("road_no", road_no));
- wcf.Para.Add(new JProperty("rack", rack));
- wcf.Para.Add(new JProperty("position", position));
- wcf.Para.Add(new JProperty("procedure_in", procedure_in));
- string jsonStr = wcf.Get("/DKService/ExHGS3QR/AddWorkInfoHGS3_QR");
- //这个接口很小的机率会带出html标签===============================================
- if (jsonStr.IndexOf("<html>") > 0) jsonStr = jsonStr.Substring(0, jsonStr.IndexOf("<html>"));
- if (jsonStr.IndexOf("<!DOCTYPEhtml>") > 0) jsonStr = jsonStr.Substring(0, jsonStr.IndexOf("<!DOCTYPEhtml>"));
- //xuwei fix 2022-05-28 有时会带出 DOCTYPEhtml标签
- jsonStr = jsonStr.Replace("<!DOCTYPEhtml>", "");
- jsonStr = jsonStr.Replace("\\u000d\\u000a", "")
- .Replace("\\n", "").Replace("\\", "").Replace(" ", "")
- .Replace("产品编码:", " 产品编码 ")
- .Replace("当前工序:", " 当前工序 ")
- .Replace("可到工序:", " 可到工序 ")
- .Replace("{\"d\":\"", "")
- .Replace("\"}\"}", "\"}")
- .Replace("<!DOCTYPEhtml>", "")
- ;
- Curtain.Log.Logger.Debug(context.Request.UserHostAddress + "\r\n" + context.Request.Url + "\r\n" + jsonStr);
- string apiResult = "";
- //处理输出结果 OK开头成功 NOK开头失败
- JObject json = JObject.Parse(jsonStr);
- bool apiStatus = false;
- apiStatus = Convert.ToBoolean(json["success"]);
- apiResult = jsonStr;
- //HttpContext.Current.Response.Write(apiResult);
- //记录接口调用日志
- Hashtable ht = new Hashtable();
- ht.Add("barcode", barCode.ToString());
- ht.Add("procedure_no", procedure_no);
- ht.Add("road_no", road_no);
- ht.Add("rack", rack);
- ht.Add("position", position);
- ht.Add("procedure_in", procedure_in);
- int apiId = Convert.ToInt32(procedure_no.Replace("_", "") + road_no + Math.Abs(Convert.ToInt32(procedure_in)));
- barCode = barCode.Replace("2c%", ",");
- int apiBarcodeCount = barCode.Split(',').Length;
- string apiUrl = "http://" + HttpContext.Current.Request.Url.Host + ":" + HttpContext.Current.Request.Url.Port.ToString() + "/api/DKService/ExHGS3QR/AddWorkInfoHGS3_QR/?" + JsonClient.ParaToString(ht);
- ApiLog.WriteApiLog("PLC_扫码", apiUrl, apiStatus, apiResult, apiId, apiBarcodeCount);
- //===============================================
- }
- }
- else
- {
- //写标识位-扫描结果
- SiemensS7.Write<short>("31.0", Convert.ToInt16(2));
- context.Response.Write(SiemensS7.Read<short>("31.0"));
- Logger.Info("无条码!");
- }
- context.Response.Write(new JsonResult(infoDt).ToJson());
- SiemensS7.Close();
- }
- catch (Exception ex )
- {
- Logger.Info("异常!:"+ex);
- throw ex ;
- }
- }
- public bool IsReusable
- {
- get
- {
- return false;
- }
- }
- }
|