qinqi пре 1 година
родитељ
комит
b9929901fe

BIN
wwwroot/Bin/DK.XuWei.WebMes.dll


+ 15 - 13
wwwroot/api/plc/plc_led_data.ashx

@@ -107,20 +107,22 @@ public class plc_led_data : IHttpHandler
                     context.Response.Write(SiemensS7.Read<short>("400.6"));
                     context.Response.Write(SiemensS7.Read<short>("400.6"));
                     context.Response.Write(SiemensS7.Read<string>("400.24", 11));
                     context.Response.Write(SiemensS7.Read<string>("400.24", 11));
 
 
-
-                    if (Convert.ToInt16(infoDt.Rows[0]["seatcovercode"]) != Convert.ToInt16(SiemensS7.Read<short>("400.2"))
-                            || Convert.ToInt16(infoDt.Rows[0]["goodsspecification"]) != Convert.ToInt16(SiemensS7.Read<short>("400.4"))
-                            || Convert.ToInt16(infoDt.Rows[0]["goodstypename"]) != Convert.ToInt16(SiemensS7.Read<short>("400.6"))
-                            || Convert.ToInt16(1) != Convert.ToInt16(SiemensS7.Read<short>("400.0")))
+                    if (infoDt != null && infoDt.Rows.Count > 0 && infoDt.Rows[0] != null)
                     {
                     {
-                        SiemensS7.Write<short>("400.2", Convert.ToInt16(infoDt.Rows[0]["seatcovercode"]));
-                        SiemensS7.Write<short>("400.4", Convert.ToInt16(infoDt.Rows[0]["goodsspecification"]));
-                        SiemensS7.Write<short>("400.6", Convert.ToInt16(infoDt.Rows[0]["goodstypename"]));
-                        SiemensS7.Write<string>("400.10", infoDt.Rows[0]["barcode"].ToString());
-                        SiemensS7.Write<string>("400.24", infoDt.Rows[0]["goodscode"].ToString());
-
-                        //写标识位-扫描结果
-                        SiemensS7.Write<short>("400.0", Convert.ToInt16(1));
+                        if (Convert.ToInt16(infoDt.Rows[0]["seatcovercode"]) != Convert.ToInt16(SiemensS7.Read<short>("400.2"))
+                                || Convert.ToInt16(infoDt.Rows[0]["goodsspecification"]) != Convert.ToInt16(SiemensS7.Read<short>("400.4"))
+                                || Convert.ToInt16(infoDt.Rows[0]["goodstypename"]) != Convert.ToInt16(SiemensS7.Read<short>("400.6"))
+                                || Convert.ToInt16(1) != Convert.ToInt16(SiemensS7.Read<short>("400.0")))
+                        {
+                            SiemensS7.Write<short>("400.2", Convert.ToInt16(infoDt.Rows[0]["seatcovercode"]));
+                            SiemensS7.Write<short>("400.4", Convert.ToInt16(infoDt.Rows[0]["goodsspecification"]));
+                            SiemensS7.Write<short>("400.6", Convert.ToInt16(infoDt.Rows[0]["goodstypename"]));
+                            SiemensS7.Write<string>("400.10", infoDt.Rows[0]["barcode"].ToString());
+                            SiemensS7.Write<string>("400.24", infoDt.Rows[0]["goodscode"].ToString());
+
+                            //写标识位-扫描结果
+                            SiemensS7.Write<short>("400.0", Convert.ToInt16(1));
+                        }
                     }
                     }
                     Logger.Info("写入数据完成!barcode:" + context.Request["barcode"].ToString() + "五位数据位:" + SiemensS7.Read<short>("400.0") + "," + SiemensS7.Read<short>("400.2")
                     Logger.Info("写入数据完成!barcode:" + context.Request["barcode"].ToString() + "五位数据位:" + SiemensS7.Read<short>("400.0") + "," + SiemensS7.Read<short>("400.2")
                         + "," + SiemensS7.Read<short>("400.4") + "," + SiemensS7.Read<short>("400.6") + "," + SiemensS7.Read<short>("400.10") + "," + SiemensS7.Read<string>("400.24", 11) + ";数据:" + new JsonResult(infoDt).ToJson());
                         + "," + SiemensS7.Read<short>("400.4") + "," + SiemensS7.Read<short>("400.6") + "," + SiemensS7.Read<short>("400.10") + "," + SiemensS7.Read<string>("400.24", 11) + ";数据:" + new JsonResult(infoDt).ToJson());

+ 10 - 8
wwwroot/api/plc/plc_led_goodslogo.ashx

@@ -79,16 +79,18 @@ public class plc_led_goodslogo : IHttpHandler
                     context.Response.Write(SiemensS7.Read<string>("100.6",11));
                     context.Response.Write(SiemensS7.Read<string>("100.6",11));
                     context.Response.Write(SiemensS7.Read<string>("100.20",11));
                     context.Response.Write(SiemensS7.Read<string>("100.20",11));
 
 
-
-                    if (Convert.ToInt16(infoDt.Rows[0]["ACCESSORIESCODE"]) != Convert.ToInt16(SiemensS7.Read<short>("100.2"))
-                            || Convert.ToInt16(1) != Convert.ToInt16(SiemensS7.Read<short>("100.0")))
+                    if (infoDt != null && infoDt.Rows.Count > 0 && infoDt.Rows[0] != null)
                     {
                     {
-                        SiemensS7.Write<short>("100.2", Convert.ToInt16(infoDt.Rows[0]["ACCESSORIESCODE"])); 
-                        SiemensS7.Write<string>("100.6", infoDt.Rows[0]["BARCODE"].ToString());
-                        SiemensS7.Write<string>("100.20", infoDt.Rows[0]["GOODSCODE"].ToString());
+                        if (Convert.ToInt16(infoDt.Rows[0]["ACCESSORIESCODE"]) != Convert.ToInt16(SiemensS7.Read<short>("100.2"))
+                                || Convert.ToInt16(1) != Convert.ToInt16(SiemensS7.Read<short>("100.0")))
+                        {
+                            SiemensS7.Write<short>("100.2", Convert.ToInt16(infoDt.Rows[0]["ACCESSORIESCODE"])); 
+                            SiemensS7.Write<string>("100.6", infoDt.Rows[0]["BARCODE"].ToString());
+                            SiemensS7.Write<string>("100.20", infoDt.Rows[0]["GOODSCODE"].ToString());
 
 
-                        //写标识位-扫描结果
-                        SiemensS7.Write<short>("100.0", Convert.ToInt16(1));
+                            //写标识位-扫描结果
+                            SiemensS7.Write<short>("100.0", Convert.ToInt16(1));
+                        }
                     }
                     }
                     Logger.Info("写入数据完成!barcode:" + context.Request["barcode"].ToString() + "4位数据位:" + SiemensS7.Read<short>("100.0") + ",辅件编码:" + SiemensS7.Read<short>("100.2")
                     Logger.Info("写入数据完成!barcode:" + context.Request["barcode"].ToString() + "4位数据位:" + SiemensS7.Read<short>("100.0") + ",辅件编码:" + SiemensS7.Read<short>("100.2")
                         + ",条码:" + SiemensS7.Read<string>("100.6",11)+ ",产品编码:" + SiemensS7.Read<string>("100.20",11)  + ";数据:" + new JsonResult(infoDt).ToJson());
                         + ",条码:" + SiemensS7.Read<string>("100.6",11)+ ",产品编码:" + SiemensS7.Read<string>("100.20",11)  + ";数据:" + new JsonResult(infoDt).ToJson());

+ 62 - 33
wwwroot/api/plc/plc_led_goodslogo_dj.ashx

@@ -6,7 +6,7 @@ using DK.XuWei.WebMes;
 using Curtain.DataAccess;
 using Curtain.DataAccess;
 using Curtain.Log;
 using Curtain.Log;
 using System.Data;
 using System.Data;
-
+using Newtonsoft.Json.Linq;
 
 
 /// <summary>
 /// <summary>
 /// 对接包装LED 扫描产品提示对应辅件
 /// 对接包装LED 扫描产品提示对应辅件
@@ -23,8 +23,32 @@ public class plc_led_goodslogo_dj : IHttpHandler
         public string barcode;
         public string barcode;
     }
     }
 
 
+    public static class PLC
+    {
+        public static string plcIp = "172.19.26.237";
+        public static int plcPort = 102;
+    }
+
     //输入参数 【条码】
     //输入参数 【条码】
     public string barCode = "";
     public string barCode = "";
+    public JArray result = new JArray();
+    public static  S7 s7 = new S7();
+
+    //打开PLC
+    public int PlcOpen()
+    {
+        try
+        {
+            s7.Open(PLC.plcIp, PLC.plcPort);
+            result.Add(new JObject(new JProperty("PLC连接", PLC.plcIp + ":" + PLC.plcPort + " 连接成功!")));
+        }
+        catch (Exception e)
+        {
+            result.Add(new JObject(new JProperty("PLC连接", PLC.plcIp + ":" + PLC.plcPort + " 连接失败!")));
+            result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
+        }
+        return 1;
+    }
 
 
     public void ProcessRequest(HttpContext context)
     public void ProcessRequest(HttpContext context)
     {
     {
@@ -37,13 +61,15 @@ public class plc_led_goodslogo_dj : IHttpHandler
             DataTable infoDt = new DataTable();
             DataTable infoDt = new DataTable();
             //写入PLC
             //写入PLC
             //正式
             //正式
-            SiemensS7.Open("172.19.26.237", 102);
+            //SiemensS7.Open("172.19.26.237", 102);
 
 
             if (context.Request["barcode"] is object)
             if (context.Request["barcode"] is object)
             {
             {
-                using (IDataAccess conn = DataAccess.Create())
+                if (PlcOpen() == 1)
                 {
                 {
-                    infoDt = conn.ExecuteDatatable(@"
+                    using (IDataAccess conn = DataAccess.Create())
+                    {
+                        infoDt = conn.ExecuteDatatable(@"
                             SELECT
                             SELECT
                                 TPGL.BARCODE,
                                 TPGL.BARCODE,
                                 TPGL.GOODSCODE,
                                 TPGL.GOODSCODE,
@@ -62,48 +88,51 @@ public class plc_led_goodslogo_dj : IHttpHandler
                                 AND TMD.DICTIONARYVALUE = '水件'
                                 AND TMD.DICTIONARYVALUE = '水件'
                                 AND TPGL.BARCODE = @barcode@
                                 AND TPGL.BARCODE = @barcode@
                             ",
                             ",
-                        new CDAParameter("barcode", context.Request["barcode"])
-                    );
-                    if (infoDt != null && infoDt.Rows.Count > 0 && infoDt.Rows[0] != null)
-                    {
-                        SiemensS7.Write<short>("100.2", Convert.ToInt16(infoDt.Rows[0]["ACCESSORIESCODE"])); 
-                        SiemensS7.Write<string>("100.6", infoDt.Rows[0]["BARCODE"].ToString());
-                        SiemensS7.Write<string>("100.20", infoDt.Rows[0]["GOODSCODE"].ToString());
-
-                        //写标识位-扫描结果
-                        SiemensS7.Write<short>("100.0", Convert.ToInt16(1));
-                    }
+                            new CDAParameter("barcode", context.Request["barcode"])
+                        );
+                        if (infoDt != null && infoDt.Rows.Count > 0 && infoDt.Rows[0] != null)
+                        {
+                            s7.Write<short>("100.2", Convert.ToInt16(infoDt.Rows[0]["ACCESSORIESCODE"]));
+                            s7.Write<string>("100.6", infoDt.Rows[0]["BARCODE"].ToString());
+                            s7.Write<string>("100.20", infoDt.Rows[0]["GOODSCODE"].ToString());
 
 
-                    context.Response.Write(SiemensS7.Read<short>("100.0"));
-                    context.Response.Write(SiemensS7.Read<short>("100.2"));
-                    context.Response.Write(SiemensS7.Read<string>("100.6",11));
-                    context.Response.Write(SiemensS7.Read<string>("100.20",11));
+                            //写标识位-扫描结果
+                            s7.Write<short>("100.0", Convert.ToInt16(1));
+                        }
 
 
+                        context.Response.Write(s7.Read<short>("100.0"));
+                        context.Response.Write(s7.Read<short>("100.2"));
+                        context.Response.Write(s7.Read<string>("100.6", 11));
+                        context.Response.Write(s7.Read<string>("100.20", 11));
 
 
-                    if (Convert.ToInt16(infoDt.Rows[0]["ACCESSORIESCODE"]) != Convert.ToInt16(SiemensS7.Read<short>("100.2"))
-                            || Convert.ToInt16(1) != Convert.ToInt16(SiemensS7.Read<short>("100.0")))
-                    {
-                        SiemensS7.Write<short>("100.2", Convert.ToInt16(infoDt.Rows[0]["ACCESSORIESCODE"])); 
-                        SiemensS7.Write<string>("100.6", infoDt.Rows[0]["BARCODE"].ToString());
-                        SiemensS7.Write<string>("100.20", infoDt.Rows[0]["GOODSCODE"].ToString());
+                        if (infoDt != null && infoDt.Rows.Count > 0 && infoDt.Rows[0] != null)
+                        {
+                            if (Convert.ToInt16(infoDt.Rows[0]["ACCESSORIESCODE"]) != Convert.ToInt16(s7.Read<short>("100.2"))
+                                    || Convert.ToInt16(1) != Convert.ToInt16(s7.Read<short>("100.0")))
+                            {
+                                s7.Write<short>("100.2", Convert.ToInt16(infoDt.Rows[0]["ACCESSORIESCODE"]));
+                                s7.Write<string>("100.6", infoDt.Rows[0]["BARCODE"].ToString());
+                                s7.Write<string>("100.20", infoDt.Rows[0]["GOODSCODE"].ToString());
 
 
-                        //写标识位-扫描结果
-                        SiemensS7.Write<short>("100.0", Convert.ToInt16(1));
+                                //写标识位-扫描结果
+                                s7.Write<short>("100.0", Convert.ToInt16(1));
+                            }
+                        }
+                        Logger.Info("写入数据完成!barcode:" + context.Request["barcode"].ToString() + "4位数据位:" + s7.Read<short>("100.0") + ",辅件编码:" + s7.Read<short>("100.2")
+                            + ",条码:" + s7.Read<string>("100.6", 11) + ",产品编码:" + s7.Read<string>("100.20", 11) + ";数据:" + new JsonResult(infoDt).ToJson());
                     }
                     }
-                    Logger.Info("写入数据完成!barcode:" + context.Request["barcode"].ToString() + "4位数据位:" + SiemensS7.Read<short>("100.0") + ",辅件编码:" + SiemensS7.Read<short>("100.2")
-                        + ",条码:" + SiemensS7.Read<string>("100.6",11)+ ",产品编码:" + SiemensS7.Read<string>("100.20",11)  + ";数据:" + new JsonResult(infoDt).ToJson());
                 }
                 }
             }
             }
-           else
+            else
             {
             {
                 //写标识位-扫描结果
                 //写标识位-扫描结果
-                SiemensS7.Write<short>("100.0", Convert.ToInt16(2));
-                context.Response.Write(SiemensS7.Read<short>("100.0"));
+                s7.Write<short>("100.0", Convert.ToInt16(2));
+                context.Response.Write(s7.Read<short>("100.0"));
                 Logger.Info("无条码!");
                 Logger.Info("无条码!");
             }
             }
 
 
             context.Response.Write(new JsonResult(infoDt).ToJson());
             context.Response.Write(new JsonResult(infoDt).ToJson());
-            SiemensS7.Close();
+            //SiemensS7.Close();
         }
         }
         catch (Exception ex)
         catch (Exception ex)
         {
         {

+ 61 - 32
wwwroot/api/plc/plc_led_goodslogo_dj2.ashx

@@ -6,7 +6,7 @@ using DK.XuWei.WebMes;
 using Curtain.DataAccess;
 using Curtain.DataAccess;
 using Curtain.Log;
 using Curtain.Log;
 using System.Data;
 using System.Data;
-
+using Newtonsoft.Json.Linq;
 
 
 /// <summary>
 /// <summary>
 /// 对接包装LED 扫描产品提示对应辅件
 /// 对接包装LED 扫描产品提示对应辅件
@@ -23,8 +23,32 @@ public class plc_led_goodslogo_dj2 : IHttpHandler
         public string barcode;
         public string barcode;
     }
     }
 
 
+    public static class PLC
+    {
+        public static string plcIp = "172.19.26.237";
+        public static int plcPort = 102;
+    }
+
     //输入参数 【条码】
     //输入参数 【条码】
     public string barCode = "";
     public string barCode = "";
+    public JArray result = new JArray();
+    public static  S7 s7 = new S7();
+
+    //打开PLC
+    public int PlcOpen()
+    {
+        try
+        {
+            s7.Open(PLC.plcIp, PLC.plcPort);
+            result.Add(new JObject(new JProperty("PLC连接", PLC.plcIp + ":" + PLC.plcPort + " 连接成功!")));
+        }
+        catch (Exception e)
+        {
+            result.Add(new JObject(new JProperty("PLC连接", PLC.plcIp + ":" + PLC.plcPort + " 连接失败!")));
+            result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
+        }
+        return 1;
+    }
 
 
     public void ProcessRequest(HttpContext context)
     public void ProcessRequest(HttpContext context)
     {
     {
@@ -37,13 +61,15 @@ public class plc_led_goodslogo_dj2 : IHttpHandler
             DataTable infoDt = new DataTable();
             DataTable infoDt = new DataTable();
             //写入PLC
             //写入PLC
             //正式
             //正式
-            SiemensS7.Open("172.19.26.237", 102);
+            //SiemensS7.Open("172.19.26.237", 102);
 
 
             if (context.Request["barcode"] is object)
             if (context.Request["barcode"] is object)
             {
             {
-                using (IDataAccess conn = DataAccess.Create())
+                if (PlcOpen() == 1)
                 {
                 {
-                    infoDt = conn.ExecuteDatatable(@"
+                    using (IDataAccess conn = DataAccess.Create())
+                    {
+                        infoDt = conn.ExecuteDatatable(@"
                             SELECT
                             SELECT
                                 TPGL.BARCODE,
                                 TPGL.BARCODE,
                                 TPGL.GOODSCODE,
                                 TPGL.GOODSCODE,
@@ -62,48 +88,51 @@ public class plc_led_goodslogo_dj2 : IHttpHandler
                                 AND TMD.DICTIONARYVALUE = '水件'
                                 AND TMD.DICTIONARYVALUE = '水件'
                                 AND TPGL.BARCODE = @barcode@
                                 AND TPGL.BARCODE = @barcode@
                             ",
                             ",
-                        new CDAParameter("barcode", context.Request["barcode"])
-                    );
-                    if (infoDt != null && infoDt.Rows.Count > 0 && infoDt.Rows[0] != null)
-                    {
-                        SiemensS7.Write<short>("101.2", Convert.ToInt16(infoDt.Rows[0]["ACCESSORIESCODE"])); 
-                        SiemensS7.Write<string>("101.6", infoDt.Rows[0]["BARCODE"].ToString());
-                        SiemensS7.Write<string>("101.20", infoDt.Rows[0]["GOODSCODE"].ToString());
-
-                        //写标识位-扫描结果
-                        SiemensS7.Write<short>("101.0", Convert.ToInt16(1));
-                    }
+                            new CDAParameter("barcode", context.Request["barcode"])
+                        );
+                        if (infoDt != null && infoDt.Rows.Count > 0 && infoDt.Rows[0] != null)
+                        {
+                            s7.Write<short>("101.2", Convert.ToInt16(infoDt.Rows[0]["ACCESSORIESCODE"]));
+                            s7.Write<string>("101.6", infoDt.Rows[0]["BARCODE"].ToString());
+                            s7.Write<string>("101.20", infoDt.Rows[0]["GOODSCODE"].ToString());
 
 
-                    context.Response.Write(SiemensS7.Read<short>("101.0"));
-                    context.Response.Write(SiemensS7.Read<short>("101.2"));
-                    context.Response.Write(SiemensS7.Read<string>("101.6",11));
-                    context.Response.Write(SiemensS7.Read<string>("101.20",11));
+                            //写标识位-扫描结果
+                            s7.Write<short>("101.0", Convert.ToInt16(1));
+                        }
 
 
+                        context.Response.Write(s7.Read<short>("101.0"));
+                        context.Response.Write(s7.Read<short>("101.2"));
+                        context.Response.Write(s7.Read<string>("101.6", 11));
+                        context.Response.Write(s7.Read<string>("101.20", 11));
 
 
-                    if (Convert.ToInt16(infoDt.Rows[0]["ACCESSORIESCODE"]) != Convert.ToInt16(SiemensS7.Read<short>("101.2"))
-                            || Convert.ToInt16(1) != Convert.ToInt16(SiemensS7.Read<short>("101.0")))
-                    {
-                        SiemensS7.Write<short>("101.2", Convert.ToInt16(infoDt.Rows[0]["ACCESSORIESCODE"])); 
-                        SiemensS7.Write<string>("101.6", infoDt.Rows[0]["BARCODE"].ToString());
-                        SiemensS7.Write<string>("101.20", infoDt.Rows[0]["GOODSCODE"].ToString());
+                        if (infoDt != null && infoDt.Rows.Count > 0 && infoDt.Rows[0] != null)
+                        {
+                            if (Convert.ToInt16(infoDt.Rows[0]["ACCESSORIESCODE"]) != Convert.ToInt16(s7.Read<short>("101.2"))
+                                    || Convert.ToInt16(1) != Convert.ToInt16(s7.Read<short>("101.0")))
+                            {
+                                s7.Write<short>("101.2", Convert.ToInt16(infoDt.Rows[0]["ACCESSORIESCODE"]));
+                                s7.Write<string>("101.6", infoDt.Rows[0]["BARCODE"].ToString());
+                                s7.Write<string>("101.20", infoDt.Rows[0]["GOODSCODE"].ToString());
 
 
-                        //写标识位-扫描结果
-                        SiemensS7.Write<short>("101.0", Convert.ToInt16(1));
+                                //写标识位-扫描结果
+                                s7.Write<short>("101.0", Convert.ToInt16(1));
+                            }
+                        }
+                        Logger.Info("写入数据完成!barcode:" + context.Request["barcode"].ToString() + "4位数据位:" + s7.Read<short>("101.0") + ",辅件编码:" + s7.Read<short>("101.2")
+                            + ",条码:" + s7.Read<string>("101.6", 11) + ",产品编码:" + s7.Read<string>("101.20", 11) + ";数据:" + new JsonResult(infoDt).ToJson());
                     }
                     }
-                    Logger.Info("写入数据完成!barcode:" + context.Request["barcode"].ToString() + "4位数据位:" + SiemensS7.Read<short>("101.0") + ",辅件编码:" + SiemensS7.Read<short>("101.2")
-                        + ",条码:" + SiemensS7.Read<string>("101.6",11)+ ",产品编码:" + SiemensS7.Read<string>("101.20",11)  + ";数据:" + new JsonResult(infoDt).ToJson());
                 }
                 }
             }
             }
             else
             else
             {
             {
                 //写标识位-扫描结果
                 //写标识位-扫描结果
-                SiemensS7.Write<short>("101.0", Convert.ToInt16(2));
-                context.Response.Write(SiemensS7.Read<short>("101.0"));
+                s7.Write<short>("101.0", Convert.ToInt16(2));
+                context.Response.Write(s7.Read<short>("101.0"));
                 Logger.Info("无条码!");
                 Logger.Info("无条码!");
             }
             }
 
 
             context.Response.Write(new JsonResult(infoDt).ToJson());
             context.Response.Write(new JsonResult(infoDt).ToJson());
-            SiemensS7.Close();
+            //SiemensS7.Close();
         }
         }
         catch (Exception ex)
         catch (Exception ex)
         {
         {

+ 400 - 0
wwwroot/api/plc/plc_shiyou3227.ashx

@@ -0,0 +1,400 @@
+<%@ WebHandler Language="C#" Class="plc_shiyou3227" %>
+
+using System;
+using System.Web;
+using DK.XuWei.WebMes;
+using Curtain.DataAccess;
+using Curtain.Log;
+using System.Data;
+using Newtonsoft.Json.Linq;
+
+
+/// <summary>
+/// 对接机械施釉(水箱)(一期)
+/// qq
+/// 2024-07-15
+/// </summary>
+public class plc_shiyou3227 : IHttpHandler
+{  
+    public static class PLC
+    {
+        public static string plcIp = "172.19.24.31";
+        public static int plcPort = 102;
+        public static string dbResult = "1000.0";   //结果;扫码结果(1:通过,2:条码错误,3:产品不可到达,4:MES异常,0:复位)
+        public static string dbGoodsCode = "1000.2";//产品编码(数值写入,产品型号)
+        public static string dbGoodsType = "1000.4";//产品类型(1:智能、2:连体)
+        public static string dbBarcode = "1000.8";  //产品条码 
+    }
+
+    //输入参数 【条码】
+    public string barCode = "";
+
+    public JArray result = new JArray();
+    public static  S7 s7 = new S7();
+
+    //打开PLC
+    public int PlcOpen()
+    {
+        try
+        {
+            s7.Open(PLC.plcIp, PLC.plcPort);
+            result.Add(new JObject(new JProperty("PLC连接", PLC.plcIp + ":" + PLC.plcPort + " 连接成功!")));
+        }
+        catch (Exception e)
+        {
+            result.Add(new JObject(new JProperty("PLC连接", PLC.plcIp + ":" + PLC.plcPort + " 连接失败!")));
+            result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
+        }
+        return 1;
+    }
+
+    //关闭PLC
+    public int PlcClose()
+    {
+        s7.Close();
+        result.Add(new JObject(new JProperty("PLC关闭", PLC.plcIp + ":" + PLC.plcPort + " 关闭成功!")));
+        return 1;
+    }
+
+    public static class API
+    {
+        public static string accountCode = "dongke";
+        public static string userId = "8";
+        public static string userCode = "DK03";
+        public static string userName = "东科刘世奇";
+        public static string userPassword = "5D3EF95E2716E4FB83E2639DC385A58B";
+        public static string sessionKey = "CD806C4D-D4EC-4F6A-B4F4-720F8F780FF0";
+        public static int procedureID = 80; //1#机械施釉(水箱)
+    }
+
+    //主程序入口
+    public void ProcessRequest(HttpContext context)
+    {
+        context.Response.ContentType = "text/plain";
+        //输入产品条码参数
+        barCode = context.Request["barcode"] is object ? context.Request["barcode"].ToString() : "";
+
+        DataTable infoDt = new DataTable();
+        //写入PLC
+        //正式
+
+        if (context.Request["barcode"] is object)
+        {
+            //string barCode = context.Request["barcode"].ToString();
+            if (PlcOpen() == 1)
+            {
+                //读取工号
+                string userCode = "JSA";
+                if (userCode != "")
+                {
+                    GetUserinfo(userCode);
+
+                    //接口验证可到达
+                    int check = ApiCheckBarcode(barCode);
+
+                    if (check == 1)
+                    {
+                        int addWorkPiece = ApiAddWorkPiece(barCode);
+
+                        if (addWorkPiece == 1)
+                        {
+                            DataTable goodsType = GetGoodinfo(barCode);
+
+                            if (goodsType != null  && goodsType.Rows.Count > 0)
+                            {
+                                bool goodscodeflag = PlcWriteRepeat<short>(PLC.dbGoodsCode, Convert.ToInt16(goodsType.Rows[0]["SEATCOVERCODE"].ToString()));
+                                bool goodstypeflag = PlcWriteRepeat<short>(PLC.dbGoodsType, Convert.ToInt16(goodsType.Rows[0]["GOODSTYPENAME"].ToString()));
+                                bool barcodeflag = PlcWriteRepeat<string>(PLC.dbBarcode, barCode);
+                                bool resultflag = PlcWriteRepeat<short>(PLC.dbResult, Convert.ToInt16(1));
+                                result.Add(new JObject(new JProperty("PLC读出(核对)", PLC.dbResult + " = " + s7.Read<short>(PLC.dbResult) + ";" + PLC.dbGoodsCode + " = " + s7.Read<short>(PLC.dbGoodsCode) + ";"+ PLC.dbGoodsType + " = " + s7.Read<short>(PLC.dbGoodsType) + ";" + PLC.dbBarcode + " = " + s7.Read<string>(PLC.dbBarcode, 11))));
+                            }
+                            else
+                            {
+                                s7.Write<short>(PLC.dbResult, Convert.ToInt16(2));
+                            }
+                        }
+                        else
+                        {
+                            s7.Write<short>(PLC.dbResult, Convert.ToInt16(4));
+                        }
+                    }
+                    else
+                    {
+                        s7.Write<short>(PLC.dbResult, Convert.ToInt16(3));
+                    }
+
+                }
+            }
+            context.Response.Write(new JsonResult(JsonStatus.success) { rows = result }.ToJson());
+
+        }
+        else
+        {
+            context.Response.Write(new JsonResult(JsonStatus.error) { rows = new JObject(new JProperty("MES读取(条码信息:ERR)", "无条码")) }.ToJson());
+
+
+        }
+        //SiemensS7.Close();
+    }
+
+    //xuwei add begin 2024-01-19 增加多次写入容错方法===============
+    public bool PlcWriteRepeat<T>(string db,object value,int repeat = 5)
+    {
+        try
+        {
+            bool isSuccess = false;
+            isSuccess = s7.Write<T>(db, (T)(value));
+            result.Add(new JObject(new JProperty("PLC写入数据成功标识:", isSuccess)));
+            result.Add(new JObject(new JProperty("PLC写入数据:", db + "=" + value.ToString())));
+            int i = 0;
+            while ( !isSuccess && i<repeat )
+            {
+                s7.IS_OPEN = false;
+                isSuccess = s7.Write<T>(db, (T)(value));
+                result.Add(new JObject(new JProperty("PLC写入数据(重写第" + i.ToString() + "次):", db + "=" + value.ToString())));
+                i++;
+            }
+             
+            return isSuccess;
+        }
+        catch (Exception)
+        {
+
+            throw;
+        }
+    }
+
+    //读取用户信息
+    public DataRow GetUserinfo(string userCode)
+    {
+        try
+        {
+            using (IDataAccess conn = DataAccess.Create())
+            {
+                DataTable dt = conn.ExecuteDatatable(@"
+                    SELECT
+	                    u.ACCOUNTCODE,
+	                    u.USERID,
+	                    u.USERCODE,
+	                    u.USERNAME,
+	                    u.PASSWORD,
+	                    l.SESSIONKEY
+                    FROM
+	                    TP_MST_USER u
+	                    LEFT JOIN TP_MST_USERLOGIN l ON u.USERID = l.USERID 
+                    WHERE
+                        u.USERCODE = @USERCODE@ 
+				    ",
+                    new CDAParameter("USERCODE", userCode)
+                );
+                if (dt.Rows.Count > 0)
+                {
+                    API.accountCode = dt.Rows[0]["ACCOUNTCODE"].ToString();
+                    API.userId = dt.Rows[0]["USERID"].ToString();
+                    API.userCode = dt.Rows[0]["USERCODE"].ToString();
+                    API.userName = dt.Rows[0]["USERNAME"].ToString();
+                    API.userPassword = dt.Rows[0]["PASSWORD"].ToString();
+                    API.sessionKey = dt.Rows[0]["SESSIONKEY"].ToString();
+                    JObject obj = new JObject();
+                    obj.Add(new JProperty("accountCode", dt.Rows[0]["ACCOUNTCODE"].ToString()));
+                    obj.Add(new JProperty("userId", dt.Rows[0]["USERID"].ToString()));
+                    obj.Add(new JProperty("userCode", dt.Rows[0]["USERCODE"].ToString()));
+                    obj.Add(new JProperty("userName", dt.Rows[0]["USERNAME"].ToString()));
+                    obj.Add(new JProperty("userPassword", dt.Rows[0]["PASSWORD"].ToString()));
+                    obj.Add(new JProperty("sessionKey", dt.Rows[0]["SESSIONKEY"].ToString()));
+                    result.Add(new JObject(new JProperty("MES读取(用户信息:OK)", obj)));
+                    return dt.Rows[0];
+                }
+                else
+                {
+                    result.Add(new JObject(new JProperty("MES读取(用户信息:ERR)", "用户未找到!")));
+                    return null;
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            result.Add(new JObject(new JProperty("系统异常:ERROR", e.Message)));
+            return null;
+        }
+    }
+
+    //读取产品信息
+    public DataTable GetGoodinfo(string barcode)
+    {
+        try
+        {
+            using (IDataAccess conn = DataAccess.Create())
+            {
+                DataTable dt = conn.ExecuteDatatable(@"
+                    SELECT G.SEATCOVERCODE 
+                                    ,CASE
+                                        WHEN INSTR(GT.GOODSTYPENAME, '智能') = 1 THEN 1
+                                        WHEN INSTR(GT.GOODSTYPENAME, '连体') = 1 THEN 2  
+                                    END AS GOODSTYPENAME
+                                    ,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", barcode)
+                );
+                if (dt.Rows.Count > 0)
+                {
+
+                    result.Add(new JObject(new JProperty("MES读取(产品信息:OK)", barcode + ";产品类型:" + dt.Rows[0]["GOODSTYPENAME"].ToString())));
+                    return dt;
+                }
+                else
+                {
+                    result.Add(new JObject(new JProperty("MES读取(用户信息:ERR)", "产品未找到!")));
+                    return null;
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            result.Add(new JObject(new JProperty("系统异常:ERROR", e.Message)));
+            return null;
+        }
+    }
+
+    //加载默认参数
+    public static JObject ApiLoadDefaultPara()
+    {
+        JObject userPara = new JObject();
+        userPara.Add(new JProperty("accountCode", API.accountCode));
+        userPara.Add(new JProperty("userCode", API.userCode));
+        userPara.Add(new JProperty("userPassword", API.userPassword));
+        userPara.Add(new JProperty("sessionKey", API.sessionKey));
+        return userPara;
+    }
+
+    public int ApiCheckBarcode(string barCode)
+    {
+        try
+        {
+            WCF wcf = new WCF();
+            wcf.Para = ApiLoadDefaultPara();
+            wcf.Para.Add(new JProperty("procedureID", API.procedureID));
+            wcf.Para.Add(new JProperty("barcode", barCode));
+
+            string jsonStr = wcf.Post("/DKService/PDAModuleService/CheckBarcode");
+
+            JObject json = JObject.Parse(jsonStr);
+            JArray jsonArray = JArray.Parse(json["d"]["Result"].ToString());
+            if (json["d"]["Status"].ToString() == "0" && jsonArray[0]["out_errMsg"].ToString() == "")
+            {
+                result.Add(new JObject(
+                    new JProperty("API调用(条码验证:OK)", "操作成功!"),
+                    new JProperty("接口", "/DKService/PDAModuleService/CheckBarcode"),
+                    new JProperty("参数(procedureID)", API.procedureID),
+                    new JProperty("参数(barcode)", barCode)
+                    //,new JProperty("结果", jsonStr)
+                    )
+                );
+                return 1;
+            }
+            else
+            {
+                result.Add(new JObject(
+                    new JProperty("API调用(条码验证:ERR)", json["d"]["Message"].ToString()),
+                    new JProperty("接口", "/DKService/PDAModuleService/CheckBarcode"),
+                    new JProperty("参数(procedureID)", API.procedureID),
+                    new JProperty("参数(barcode)", barCode)
+                    , new JProperty("结果", jsonStr)
+                    )
+                );
+                return -1;
+            }
+        }
+        catch (Exception e)
+        {
+            result.Add(new JObject(
+                new JProperty("API调用(条码验证:ERROR)", "系统异常!"),
+                new JProperty("接口", "/DKService/PDAModuleService/CheckBarcode"),
+                new JProperty("参数(procedureID)", API.procedureID),
+                new JProperty("参数(barcode)", barCode),
+                new JProperty("异常", e.Message)
+                )
+            );
+            return -1;
+        }
+
+    }
+
+    public int ApiAddWorkPiece(string barCode)
+    {
+        JArray productionDataEntitys = new JArray();
+
+        JObject obj = new JObject(
+            new JProperty("UserID", API.userId),
+            new JProperty("UserCode", API.userCode),
+            new JProperty("UserName", API.userName),
+            new JProperty("Barcode", barCode)
+            );
+        productionDataEntitys.Add(obj);
+
+        try
+        {
+            WCF wcf = new WCF();
+            wcf.Para = ApiLoadDefaultPara();
+            wcf.Para.Add(new JProperty("procedureID", API.procedureID));
+            wcf.Para.Add(new JProperty("productionDataEntitys", productionDataEntitys));
+
+            //正式用
+            string jsonStr = wcf.Post("/DKService/PDAModuleService/AddWorkPiece");
+
+            JObject json = JObject.Parse(jsonStr);
+            JArray jsonArray = JArray.Parse(json["d"]["Result"].ToString());
+            if (json["d"]["Status"].ToString() == "0" && (jsonArray[0]["out_errMsg"].ToString() == ""))
+            {
+                result.Add(new JObject(
+                    new JProperty("API调用(1#机械施釉(水箱):OK)", "操作成功!"),
+                    new JProperty("接口", "/DKService/PDAModuleService/AddWorkPiece"),
+                    new JProperty("参数(procedureID)", API.procedureID),
+                    new JProperty("参数(productionDataEntitys)", productionDataEntitys)
+                    )
+                );
+                return 1;
+            }
+            else
+            {
+                result.Add(new JObject(
+                    new JProperty("API调用(1#机械施釉(水箱):ERR)", json["d"]["Message"].ToString()),
+                    new JProperty("接口", "/DKService/PDAModuleService/AddWorkPiece"),
+                    new JProperty("参数(procedureID)", API.procedureID),
+                    new JProperty("参数(productionDataEntitys)", productionDataEntitys)
+                    , new JProperty("结果", jsonStr)
+                    )
+                );
+                return -1;
+            }
+        }
+        catch (Exception e)
+        {
+            result.Add(new JObject(
+                new JProperty("API调用(1#机械施釉(水箱):ERROR)", "系统异常!"),
+                new JProperty("接口", "/DKService/PDAModuleService/AddWorkPiece"),
+                new JProperty("参数(procedureID)", API.procedureID),
+                new JProperty("参数(productionDataEntitys)", productionDataEntitys),
+                new JProperty("异常", e.Message)
+                )
+            );
+            return -1;
+        }
+    }
+
+    public bool IsReusable
+    {
+        get
+        {
+            return false;
+        }
+    }
+
+}

+ 401 - 0
wwwroot/api/plc/plc_shiyou3228.ashx

@@ -0,0 +1,401 @@
+<%@ WebHandler Language="C#" Class="plc_shiyou3228" %>
+
+using System;
+using System.Web;
+using DK.XuWei.WebMes;
+using Curtain.DataAccess;
+using Curtain.Log;
+using System.Data;
+using Newtonsoft.Json.Linq;
+
+
+/// <summary>
+/// 对接机械施釉(水箱)(二期)
+/// qq
+/// 2024-07-15
+/// </summary>
+public class plc_shiyou3228 : IHttpHandler
+{
+    public static class PLC
+    {
+        public static string plcIp = "172.19.24.65";
+        public static int plcPort = 102;
+        public static string dbResult = "1000.0";   //结果;扫码结果(1:通过,2:条码错误,3:产品不可到达,4:MES异常,0:复位)
+        public static string dbGoodsCode = "1000.2";//产品编码(数值写入,产品型号)
+        public static string dbGoodsType = "1000.4";//产品类型(1:智能、2:连体)
+        public static string dbBarcode = "1000.8";  //产品条码 
+    }
+
+    //输入参数 【条码】
+    public string barCode = "";
+
+    public JArray result = new JArray();
+    public static  S7 s7 = new S7();
+
+    //打开PLC
+    public int PlcOpen()
+    {
+        try
+        {
+            s7.Open(PLC.plcIp, PLC.plcPort);
+            result.Add(new JObject(new JProperty("PLC连接", PLC.plcIp + ":" + PLC.plcPort + " 连接成功!")));
+        }
+        catch (Exception e)
+        {
+            result.Add(new JObject(new JProperty("PLC连接", PLC.plcIp + ":" + PLC.plcPort + " 连接失败!")));
+            result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
+        }
+        return 1;
+    }
+
+    //关闭PLC
+    public int PlcClose()
+    {
+        s7.Close();
+        result.Add(new JObject(new JProperty("PLC关闭", PLC.plcIp + ":" + PLC.plcPort + " 关闭成功!")));
+        return 1;
+    }
+
+    public static class API
+    {
+        public static string accountCode = "dongke";
+        public static string userId = "8";
+        public static string userCode = "DK03";
+        public static string userName = "东科刘世奇";
+        public static string userPassword = "5D3EF95E2716E4FB83E2639DC385A58B";
+        public static string sessionKey = "CD806C4D-D4EC-4F6A-B4F4-720F8F780FF0";
+        public static int procedureID = 80; //1#机械施釉(水箱)
+    }
+
+    //主程序入口
+    public void ProcessRequest(HttpContext context)
+    {
+        context.Response.ContentType = "text/plain";
+        //输入产品条码参数
+        barCode = context.Request["barcode"] is object ? context.Request["barcode"].ToString() : "";
+
+        DataTable infoDt = new DataTable();
+        //写入PLC
+        //正式
+        //SiemensS7.Open("172.19.24.65", 102);
+
+        if (context.Request["barcode"] is object)
+        {
+            //string barCode = context.Request["barcode"].ToString();
+            if (PlcOpen() == 1)
+            {
+                //读取工号
+                string userCode = "JSB";
+                if (userCode != "")
+                {
+                    GetUserinfo(userCode);
+
+                    //接口验证可到达
+                    int check = ApiCheckBarcode(barCode);
+
+                    if (check == 1)
+                    {
+                        int addWorkPiece = ApiAddWorkPiece(barCode);
+
+                        if (addWorkPiece == 1)
+                        {
+                            DataTable goodsType = GetGoodinfo(barCode);
+
+                            if (goodsType != null  && goodsType.Rows.Count > 0)
+                            {
+                                bool goodscodeflag = PlcWriteRepeat<short>(PLC.dbGoodsCode, Convert.ToInt16(goodsType.Rows[0]["SEATCOVERCODE"].ToString()));
+                                bool goodstypeflag = PlcWriteRepeat<short>(PLC.dbGoodsType, Convert.ToInt16(goodsType.Rows[0]["GOODSTYPENAME"].ToString()));
+                                bool barcodeflag = PlcWriteRepeat<string>(PLC.dbBarcode, barCode);
+                                bool resultflag = PlcWriteRepeat<short>(PLC.dbResult, Convert.ToInt16(1));
+                                result.Add(new JObject(new JProperty("PLC读出(核对)", PLC.dbResult + " = " + s7.Read<short>(PLC.dbResult) + ";" + PLC.dbGoodsCode + " = " + s7.Read<short>(PLC.dbGoodsCode) + ";"+ PLC.dbGoodsType + " = " + s7.Read<short>(PLC.dbGoodsType) + ";" + PLC.dbBarcode + " = " + s7.Read<string>(PLC.dbBarcode, 11))));
+                            }
+                            else
+                            {
+                                s7.Write<short>(PLC.dbResult, Convert.ToInt16(2));
+                            }
+                        }
+                        else
+                        {
+                            s7.Write<short>(PLC.dbResult, Convert.ToInt16(4));
+                        }
+                    }
+                    else
+                    {
+                        s7.Write<short>(PLC.dbResult, Convert.ToInt16(3));
+                    }
+
+                }
+            }
+            context.Response.Write(new JsonResult(JsonStatus.success) { rows = result }.ToJson());
+
+        }
+        else
+        {
+            context.Response.Write(new JsonResult(JsonStatus.error) { rows = new JObject(new JProperty("MES读取(条码信息:ERR)", "无条码")) }.ToJson());
+
+
+        }
+        //SiemensS7.Close();
+    }
+
+    //xuwei add begin 2024-01-19 增加多次写入容错方法===============
+    public bool PlcWriteRepeat<T>(string db,object value,int repeat = 5)
+    {
+        try
+        {
+            bool isSuccess = false;
+            isSuccess = s7.Write<T>(db, (T)(value));
+            result.Add(new JObject(new JProperty("PLC写入数据成功标识:", isSuccess)));
+            result.Add(new JObject(new JProperty("PLC写入数据:", db + "=" + value.ToString())));
+            int i = 0;
+            while ( !isSuccess && i<repeat )
+            {
+                s7.IS_OPEN = false;
+                isSuccess = s7.Write<T>(db, (T)(value));
+                result.Add(new JObject(new JProperty("PLC写入数据(重写第" + i.ToString() + "次):", db + "=" + value.ToString())));
+                i++;
+            }
+             
+            return isSuccess;
+        }
+        catch (Exception)
+        {
+
+            throw;
+        }
+    }
+
+    //读取用户信息
+    public DataRow GetUserinfo(string userCode)
+    {
+        try
+        {
+            using (IDataAccess conn = DataAccess.Create())
+            {
+                DataTable dt = conn.ExecuteDatatable(@"
+                    SELECT
+	                    u.ACCOUNTCODE,
+	                    u.USERID,
+	                    u.USERCODE,
+	                    u.USERNAME,
+	                    u.PASSWORD,
+	                    l.SESSIONKEY
+                    FROM
+	                    TP_MST_USER u
+	                    LEFT JOIN TP_MST_USERLOGIN l ON u.USERID = l.USERID 
+                    WHERE
+                        u.USERCODE = @USERCODE@ 
+				    ",
+                    new CDAParameter("USERCODE", userCode)
+                );
+                if (dt.Rows.Count > 0)
+                {
+                    API.accountCode = dt.Rows[0]["ACCOUNTCODE"].ToString();
+                    API.userId = dt.Rows[0]["USERID"].ToString();
+                    API.userCode = dt.Rows[0]["USERCODE"].ToString();
+                    API.userName = dt.Rows[0]["USERNAME"].ToString();
+                    API.userPassword = dt.Rows[0]["PASSWORD"].ToString();
+                    API.sessionKey = dt.Rows[0]["SESSIONKEY"].ToString();
+                    JObject obj = new JObject();
+                    obj.Add(new JProperty("accountCode", dt.Rows[0]["ACCOUNTCODE"].ToString()));
+                    obj.Add(new JProperty("userId", dt.Rows[0]["USERID"].ToString()));
+                    obj.Add(new JProperty("userCode", dt.Rows[0]["USERCODE"].ToString()));
+                    obj.Add(new JProperty("userName", dt.Rows[0]["USERNAME"].ToString()));
+                    obj.Add(new JProperty("userPassword", dt.Rows[0]["PASSWORD"].ToString()));
+                    obj.Add(new JProperty("sessionKey", dt.Rows[0]["SESSIONKEY"].ToString()));
+                    result.Add(new JObject(new JProperty("MES读取(用户信息:OK)", obj)));
+                    return dt.Rows[0];
+                }
+                else
+                {
+                    result.Add(new JObject(new JProperty("MES读取(用户信息:ERR)", "用户未找到!")));
+                    return null;
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            result.Add(new JObject(new JProperty("系统异常:ERROR", e.Message)));
+            return null;
+        }
+    }
+
+    //读取产品信息
+    public DataTable GetGoodinfo(string barcode)
+    {
+        try
+        {
+            using (IDataAccess conn = DataAccess.Create())
+            {
+                DataTable dt = conn.ExecuteDatatable(@"
+                    SELECT G.SEATCOVERCODE 
+                                    ,CASE
+                                        WHEN INSTR(GT.GOODSTYPENAME, '智能') = 1 THEN 1
+                                        WHEN INSTR(GT.GOODSTYPENAME, '连体') = 1 THEN 2  
+                                    END AS GOODSTYPENAME
+                                    ,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", barcode)
+                );
+                if (dt.Rows.Count > 0)
+                {
+
+                    result.Add(new JObject(new JProperty("MES读取(产品信息:OK)", barcode + ";产品类型:" + dt.Rows[0]["GOODSTYPENAME"].ToString())));
+                    return dt;
+                }
+                else
+                {
+                    result.Add(new JObject(new JProperty("MES读取(用户信息:ERR)", "产品未找到!")));
+                    return null;
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            result.Add(new JObject(new JProperty("系统异常:ERROR", e.Message)));
+            return null;
+        }
+    }
+
+    //加载默认参数
+    public static JObject ApiLoadDefaultPara()
+    {
+        JObject userPara = new JObject();
+        userPara.Add(new JProperty("accountCode", API.accountCode));
+        userPara.Add(new JProperty("userCode", API.userCode));
+        userPara.Add(new JProperty("userPassword", API.userPassword));
+        userPara.Add(new JProperty("sessionKey", API.sessionKey));
+        return userPara;
+    }
+
+    public int ApiCheckBarcode(string barCode)
+    {
+        try
+        {
+            WCF wcf = new WCF();
+            wcf.Para = ApiLoadDefaultPara();
+            wcf.Para.Add(new JProperty("procedureID", API.procedureID));
+            wcf.Para.Add(new JProperty("barcode", barCode));
+
+            string jsonStr = wcf.Post("/DKService/PDAModuleService/CheckBarcode");
+
+            JObject json = JObject.Parse(jsonStr);
+            JArray jsonArray = JArray.Parse(json["d"]["Result"].ToString());
+            if (json["d"]["Status"].ToString() == "0" && jsonArray[0]["out_errMsg"].ToString() == "")
+            {
+                result.Add(new JObject(
+                    new JProperty("API调用(条码验证:OK)", "操作成功!"),
+                    new JProperty("接口", "/DKService/PDAModuleService/CheckBarcode"),
+                    new JProperty("参数(procedureID)", API.procedureID),
+                    new JProperty("参数(barcode)", barCode)
+                    //,new JProperty("结果", jsonStr)
+                    )
+                );
+                return 1;
+            }
+            else
+            {
+                result.Add(new JObject(
+                    new JProperty("API调用(条码验证:ERR)", json["d"]["Message"].ToString()),
+                    new JProperty("接口", "/DKService/PDAModuleService/CheckBarcode"),
+                    new JProperty("参数(procedureID)", API.procedureID),
+                    new JProperty("参数(barcode)", barCode)
+                    , new JProperty("结果", jsonStr)
+                    )
+                );
+                return -1;
+            }
+        }
+        catch (Exception e)
+        {
+            result.Add(new JObject(
+                new JProperty("API调用(条码验证:ERROR)", "系统异常!"),
+                new JProperty("接口", "/DKService/PDAModuleService/CheckBarcode"),
+                new JProperty("参数(procedureID)", API.procedureID),
+                new JProperty("参数(barcode)", barCode),
+                new JProperty("异常", e.Message)
+                )
+            );
+            return -1;
+        }
+
+    }
+
+    public int ApiAddWorkPiece(string barCode)
+    {
+        JArray productionDataEntitys = new JArray();
+
+        JObject obj = new JObject(
+            new JProperty("UserID", API.userId),
+            new JProperty("UserCode", API.userCode),
+            new JProperty("UserName", API.userName),
+            new JProperty("Barcode", barCode)
+            );
+        productionDataEntitys.Add(obj);
+
+        try
+        {
+            WCF wcf = new WCF();
+            wcf.Para = ApiLoadDefaultPara();
+            wcf.Para.Add(new JProperty("procedureID", API.procedureID));
+            wcf.Para.Add(new JProperty("productionDataEntitys", productionDataEntitys));
+
+            //正式用
+            string jsonStr = wcf.Post("/DKService/PDAModuleService/AddWorkPiece");
+
+            JObject json = JObject.Parse(jsonStr);
+            JArray jsonArray = JArray.Parse(json["d"]["Result"].ToString());
+            if (json["d"]["Status"].ToString() == "0" && (jsonArray[0]["out_errMsg"].ToString() == ""))
+            {
+                result.Add(new JObject(
+                    new JProperty("API调用(1#机械施釉(水箱):OK)", "操作成功!"),
+                    new JProperty("接口", "/DKService/PDAModuleService/AddWorkPiece"),
+                    new JProperty("参数(procedureID)", API.procedureID),
+                    new JProperty("参数(productionDataEntitys)", productionDataEntitys)
+                    )
+                );
+                return 1;
+            }
+            else
+            {
+                result.Add(new JObject(
+                    new JProperty("API调用(1#机械施釉(水箱):ERR)", json["d"]["Message"].ToString()),
+                    new JProperty("接口", "/DKService/PDAModuleService/AddWorkPiece"),
+                    new JProperty("参数(procedureID)", API.procedureID),
+                    new JProperty("参数(productionDataEntitys)", productionDataEntitys)
+                    , new JProperty("结果", jsonStr)
+                    )
+                );
+                return -1;
+            }
+        }
+        catch (Exception e)
+        {
+            result.Add(new JObject(
+                new JProperty("API调用(1#机械施釉(水箱):ERROR)", "系统异常!"),
+                new JProperty("接口", "/DKService/PDAModuleService/AddWorkPiece"),
+                new JProperty("参数(procedureID)", API.procedureID),
+                new JProperty("参数(productionDataEntitys)", productionDataEntitys),
+                new JProperty("异常", e.Message)
+                )
+            );
+            return -1;
+        }
+    }
+
+    public bool IsReusable
+    {
+        get
+        {
+            return false;
+        }
+    }
+
+}