Ver Fonte

2#施釉后,绑定防伪码

chenxy há 4 anos atrás
pai
commit
479b82804d
2 ficheiros alterados com 126 adições e 0 exclusões
  1. 33 0
      PCLCommunication/ConnSetting.cs
  2. 93 0
      PCLCommunication/FrmMelsecA1EAscii.cs

+ 33 - 0
PCLCommunication/ConnSetting.cs

@@ -459,6 +459,8 @@ namespace PCLCommunication
                     return id;
                 }
 
+                dataAccess.ExecuteNonQuery("update tp_mst_workstation t set t.usercode = '"+ usercode + "' where t.workstationid = 2215");
+
                 MESInfo.UserCode = usercode;
                 INIUtil ini = INIUtil.IniFile(INI_PATH);
                 ini.Write("iBOSS.MES", "UserCode", usercode);
@@ -509,6 +511,37 @@ namespace PCLCommunication
                 dataAccess?.Close();
             }
         }
+        /// <summary>
+        /// 查询条码的防伪码标识和型号
+        /// </summary>
+        /// <param name="barcode"></param>
+        /// <returns></returns>
+        public static DataRow GetGoodsInfo(string barcode)
+        {
+            IDataAccess dataAccess = null;
+            try
+            {
+                dataAccess = DataAccessFactory.CreateDataAccess(_oracleString, DataBaseType.Oracle);
+                string sqlString = "select gdd.barcode, g.goodsid, g.goodstypeid, g.securitycodebindflag, g.securitycodecheckflag\n" +
+                "  from tp_pm_groutingdailydetail gdd\n" +
+                " inner join tp_mst_goods g\n" +
+                "    on g.goodsid = gdd.goodsid\n" +
+                " where gdd.barcode = '"+ barcode + "'";
+
+                DataTable dt = dataAccess.ExecuteDatatable(sqlString);
+                return (dt != null && dt.Rows.Count > 0) ? dt.Rows[0] : null;
+            }
+            catch (Exception ex)
+            {
+                // todo log
+                LogOut.Error(null, ex, barcode + " :: " + _oracleString);
+                return null;
+            }
+            finally
+            {
+                dataAccess?.Close();
+            }
+        }
 
         public static bool GetSystemSetting()
         {

+ 93 - 0
PCLCommunication/FrmMelsecA1EAscii.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Collections.Generic;
 using System.Data;
+using System.ServiceModel.Channels;
 using System.Text;
 using System.Windows.Forms;
 using Curtain.DataAccess;
@@ -50,6 +51,8 @@ namespace PCLCommunication
                 {
                     Start(false);
                 }
+
+                //SimplifyServer_ReceivedBytesEvent(new AppSession(), (HslCommunication.NetHandle)2,null);
             }
             catch (Exception ex)
             {
@@ -656,6 +659,17 @@ namespace PCLCommunication
 
                         m = ConnSetting.PLC_ConnServer[flag.ToString()];
 
+                        //byte[] byteCode11 = Encoding.ASCII.GetBytes(barcode + "$");
+                        //result = m.SetData("D", 496, 6, byteCode11);
+                        //LogNet_BeforeSaveToFile(JsonUtil.FromObject(m));
+                        //lbl.AppendLine(JsonUtil.FromObject(m));
+                        //if (!result)
+                        //{
+                        //    LogNet_BeforeSaveToFile("PLC操作失败");
+                        //    lbl.AppendLine("PLC操作失败");
+                        //    return;
+                        //}
+
                         try
                         {
                             m.Always = true;
@@ -744,6 +758,7 @@ namespace PCLCommunication
                         lbl.AppendLine(roomcode);
 
                         #region 防伪码
+                        /*
                         if (ConnSetting.SE_CODE_FLAG)
                         {
                             // ==================================================================
@@ -858,6 +873,84 @@ namespace PCLCommunication
                                 lbl.AppendLine($"绑定 防伪码[{se_result}] ");
                             }
                         }
+                        */
+                        // 1 获取条码对应的产品型号,是否需要绑定防伪码
+                        DataRow dr = ConnSetting.GetGoodsInfo(barcode);
+                        if (dr == null)
+                        {
+                            //LogNet_BeforeSaveToFile("写入 D281 错误标识 : 0 条码不存在" + barcode);
+                            //lbl.AppendLine("写入 D281 错误标识 : 0 条码不存在" + barcode);
+                            //// 写入 D281 错误标识
+                            //bool result = m.SetData("D", 281, 1, "0001");
+                            //LogNet_BeforeSaveToFile(JsonUtil.FromObject(m));
+                            //lbl.AppendLine(JsonUtil.FromObject(m));
+                            //if (!result)
+                            //{
+                            //    LogNet_BeforeSaveToFile("PLC操作失败");
+                            //    lbl.AppendLine("PLC操作失败");
+                            //}
+
+                            ConnSetting.SetPLCError2(m, lbl, "条码不存在:" + barcode);
+                            return;
+                        }
+                        string SECURITYCODEBINDFLAG = dr["SECURITYCODEBINDFLAG"] + "";
+                        string goodstypeid = dr["goodstypeid"] + "";
+                        // 1. 扫码类型(int)【0:无动作,1:启动智能扫码枪 2:启动连体扫码枪】
+                        string gt_code = "0000";
+                        if (SECURITYCODEBINDFLAG == "1")
+                        {
+                            if (goodstypeid == "3" || goodstypeid == "4")
+                            {
+                                // 非智能
+                                gt_code = "0002";
+                            }
+                            else
+                            {
+                                // 智能
+                                gt_code = "0001";
+                            }
+                            LogNet_BeforeSaveToFile("写入 D492 : " + gt_code + " 条码型号 " + barcode);
+                            lbl.AppendLine("写入 D492 : " + gt_code + " 条码型号 " + barcode);
+                            // 写入 D281 错误标识
+                            result = m.SetData("D", 492, 1, gt_code);
+                            LogNet_BeforeSaveToFile(JsonUtil.FromObject(m));
+                            lbl.AppendLine(JsonUtil.FromObject(m));
+                            if (!result)
+                            {
+                                LogNet_BeforeSaveToFile("PLC操作失败");
+                                lbl.AppendLine("PLC操作失败");
+                                return;
+                            }
+
+                            LogNet_BeforeSaveToFile("写入 D496 条码 : " + barcode);
+                            lbl.AppendLine("写入 D496 条码 : " + barcode);
+                            // 写入 D150 当前工号
+                            byte[] byteCode1 = Encoding.ASCII.GetBytes(barcode + "$");
+                            result = m.SetData("D", 496, 6, byteCode1);
+                            LogNet_BeforeSaveToFile(JsonUtil.FromObject(m));
+                            lbl.AppendLine(JsonUtil.FromObject(m));
+                            if (!result)
+                            {
+                                LogNet_BeforeSaveToFile("PLC操作失败");
+                                lbl.AppendLine("PLC操作失败");
+                                return;
+                            }
+                        }
+                        else
+                        {
+                            LogNet_BeforeSaveToFile("写入 D492 : 条码不需要绑定 " + barcode);
+                            lbl.AppendLine("写入 D492 : 条码不需要绑定 " + barcode);
+                            // 写入 D281 错误标识
+                            result = m.SetData("D", 492, 1, gt_code);
+                            LogNet_BeforeSaveToFile(JsonUtil.FromObject(m));
+                            lbl.AppendLine(JsonUtil.FromObject(m));
+                            if (!result)
+                            {
+                                LogNet_BeforeSaveToFile("PLC操作失败");
+                                lbl.AppendLine("PLC操作失败");
+                                return;
+                            }
+                        }
                         #endregion
 
                         // 自动工序计件