From 57c475ed168e905443eb2e34cc12a3d03fc355f6 Mon Sep 17 00:00:00 2001
From: zrg <z1873@LAPTOP-EAVL132E>
Date: 星期四, 31 七月 2025 14:12:45 +0800
Subject: [PATCH] 增加九菱和凯贝的数据采集

---
 WFormSynchronizeData_SMR/WFormSynchronizeData_SMR/Form1.cs |  202 ++++++++++++++++++++++++--------------------------
 1 files changed, 97 insertions(+), 105 deletions(-)

diff --git a/WFormSynchronizeData_SMR/WFormSynchronizeData_SMR/Form1.cs b/WFormSynchronizeData_SMR/WFormSynchronizeData_SMR/Form1.cs
index 0ce1777..b36209a 100644
--- a/WFormSynchronizeData_SMR/WFormSynchronizeData_SMR/Form1.cs
+++ b/WFormSynchronizeData_SMR/WFormSynchronizeData_SMR/Form1.cs
@@ -31,7 +31,7 @@
             CustomWriteLog("1.璁℃椂鍣ㄥ紑濮�:"+timer.Elapsed, DateTime.Now.ToString("yyyy-MM-dd"));
 
             //鏍规嵁鏃堕棿姝e簭鎺掑簭鑾峰彇鍓�150鏉℃暟鎹�
-            DataTable list = oCN.RunProcReturn("select top 150 * from Sb_EquipMentCollection_SN  WITH(NOLOCK) where HFlag=0  order by HCreateTime", "Sb_EquipMentCollection_SN").Tables[0];
+            DataTable list = oCN.RunProcReturn("select top 150 HResult,HBarCode,HCreateTime from Sb_EquipMentCollection_SN  WITH(NOLOCK) where HFlag=0  order by HCreateTime", "Sb_EquipMentCollection_SN").Tables[0];
           
             //寰幆闆嗗悎
             for (int i = 0; i < list.Rows.Count; i++)
@@ -75,7 +75,7 @@
 
                 bool flag = false;
                 string HBadCodeSN = dic["HBarCode"].ToString();
-                HBadCodeSN = TM_ZH(HBadCodeSN);
+                //HBadCodeSN = TM_ZH(HBadCodeSN);
                 //鍒ゆ柇褰撳ぉ鏉$爜鏈夋病鏈夊瓨鍌ㄥ湪鏉$爜琛ㄩ噷 濡傛灉娌℃湁 鍒欎繚瀛樻暟鎹� 骞惰繑鍥�0
                 //濡傛灉宸插瓨鍦� 鍒欒繑鍥� 1
                 //濡傛灉鏉′欢涓嶆弧瓒崇殑 鍒欒繑鍥� 2
@@ -101,9 +101,9 @@
 
                     //鏌ヨ杩欎釜宸ュ簭瀵瑰簲鐨勬潯鐮� 鍑虹珯鍗曟槸鍚﹀凡缁忓瓨鍦�
                     DataSet ds1 = oCN.RunProcReturn(@"select a.HProcID from Sc_StationOutBillMain a WITH(NOLOCK)
-inner join Sc_StationOutBillSub_SN sn WITH(NOLOCK) on a.HInterID=sn.HInterID
-left join Gy_Process p WITH(NOLOCK) on a.HProcID=p.HItemID
-where  p.HNumber='" + dic["HProcNumber"].ToString() + "' and sn.HBarCode='" + HBadCodeSN + "'", "Sc_StationOutBillSub_SN");
+                                                    inner join Sc_StationOutBillSub_SN sn WITH(NOLOCK) on a.HInterID=sn.HInterID
+                                                    left join Gy_Process p WITH(NOLOCK) on a.HProcID=p.HItemID
+                                                    where  p.HNumber='" + dic["HProcNumber"].ToString() + "' and sn.HBarCode='" + HBadCodeSN + "'", "Sc_StationOutBillSub_SN");
 
                     //鍒ゆ柇鏉$爜涔嬪墠鏄惁涓篘G  鍚屾椂 鍒ゆ柇鍑虹珯鍗曠殑鏉$爜鏁版嵁鏄笉瀛樺湪
                     if (ds.Tables[0].Rows.Count > 0 && ds1.Tables[0].Rows.Count == 0)
@@ -151,7 +151,7 @@
                 bool flag = false;
                 int num = 0;
                 string HBadCodeSN = dic["HBarCode"].ToString();
-                HBadCodeSN = TM_ZH(HBadCodeSN);
+                //HBadCodeSN = TM_ZH(HBadCodeSN);
                 //鍒ゆ柇褰撳ぉ鏉$爜鏈夋病鏈夊瓨鍌ㄥ湪鏉$爜琛ㄩ噷 濡傛灉娌℃湁 鍒欎繚瀛樻暟鎹� 骞惰繑鍥�0
                 //濡傛灉宸插瓨鍦� 鍒欒繑鍥� 1
                 //濡傛灉鏉′欢涓嶆弧瓒崇殑 鍒欒繑鍥� 2
@@ -192,16 +192,17 @@
             {
                 Stopwatch timer = new Stopwatch();
                 timer.Start();
+                string HMakers = ""; //鍒跺崟浜�
                 CustomWriteLog("2.1.1.鍑虹珯鍗曟柊澧炲紑濮�:" + timer.Elapsed, DateTime.Now.ToString("yyyy-MM-dd"));
                 //鑾峰彇缁戝畾娴佽浆鍗�
-                DataSet ds = oCN.RunProcReturn(@"select * from Gy_BarCodeBill WITH(NOLOCK) where HBarCode='" + HBadCodeSN + "'", "Gy_BarCodeBill");
+                DataSet ds = oCN.RunProcReturn(@"select HSourceBillNo, from Gy_BarCodeBill WITH(NOLOCK) where HBarCode='" + HBadCodeSN + "'", "Gy_BarCodeBill");
                 string HProcExchBillNo = ds.Tables[0].Rows[0]["HSourceBillNo"].ToString();
                 string HProcNumber = dic["HProcNumber"].ToString();
 
                 CustomWriteLog("2.1.2.缁戝畾娴佽浆鍗�:"+ HProcNumber+"----" + timer.Elapsed, DateTime.Now.ToString("yyyy-MM-dd"));
 
                 //鏌ヨ鐢熶骇璧勬簮
-                ds = oCN.RunProcReturn("select * from Gy_Source WITH(NOLOCK) where HNumber='" + dic["HSourceCode"].ToString() + "' ", "Gy_Source");
+                ds = oCN.RunProcReturn("select HItemID from Gy_Source WITH(NOLOCK) where HNumber='" + dic["HSourceCode"].ToString() + "' ", "Gy_Source");
                 long HSourceID = 0;
                 if (ds.Tables[0].Rows.Count != 0)
                 {
@@ -211,13 +212,14 @@
                 CustomWriteLog("2.1.3.鑾峰彇鐢熶骇璧勬簮:" + HProcNumber + "----" + timer.Elapsed, DateTime.Now.ToString("yyyy-MM-dd"));
 
                 //鏌ヨ鑱屽憳
-                ds = oCN.RunProcReturn("select * from Gy_Employee WITH(NOLOCK) where HNumber='" + dic["HEmpCode"].ToString() + "' ", "Gy_Employee");
+                ds = oCN.RunProcReturn("select HItemID,HName  from Gy_Employee WITH(NOLOCK) where HNumber='" + dic["HEmpCode"].ToString() + "' ", "Gy_Employee");
                 long HEmpIDs = 0;
                 string HEmpName = "";
                 if (ds.Tables[0].Rows.Count != 0)
                 {
                     HEmpIDs = long.Parse(ds.Tables[0].Rows[0]["HItemID"].ToString());//鑱屽憳ID
                     HEmpName = ds.Tables[0].Rows[0]["HName"].ToString();
+                    HMakers = ds.Tables[0].Rows[0]["HName"].ToString();
                 }
 
                 CustomWriteLog("2.1.4.鏌ヨ鑱屽憳淇℃伅:" + HProcNumber + "----" + timer.Elapsed, DateTime.Now.ToString("yyyy-MM-dd"));
@@ -245,9 +247,9 @@
 
                 //鏍规嵁娴佽浆鍗″拰宸ュ簭 鏌ヨ鍑虹珯鍗曢渶瑕佷繚瀛樼殑淇℃伅
                 ds = oCN.RunProcReturn(@"select   a.HWorkShopID,b.HProcNo,b.HProcID,a.HMaterID,a.HQty,a.HInterID,HEntryID,a.HICMOInterID,a.HICMOEntryID,a.HICMOBillNo,b.HCenterID  from Sc_ProcessExchangeBillMain a WITH(NOLOCK)
-inner join Sc_ProcessExchangeBillSub b WITH(NOLOCK) on a.HInterID=b.HInterID
-left join Gy_Process p WITH(NOLOCK) on  b.HProcID=p.HItemID 
-where a.HBillNo='" + HProcExchBillNo + "'  and p.HNumber='" + HProcNumber + "'", "Sc_ProcessExchangeBillMain");
+                                        inner join Sc_ProcessExchangeBillSub b WITH(NOLOCK) on a.HInterID=b.HInterID
+                                        left join Gy_Process p WITH(NOLOCK) on  b.HProcID=p.HItemID 
+                                        where a.HBillNo='" + HProcExchBillNo + "'  and p.HNumber='" + HProcNumber + "'", "Sc_ProcessExchangeBillMain");
 
                 CustomWriteLog("2.1.6.鏌ヨ娴佽浆鍗′俊鎭�:" + HProcNumber + "----" + timer.Elapsed, DateTime.Now.ToString("yyyy-MM-dd"));
 
@@ -346,9 +348,10 @@
 
 
                 //鍒ゆ柇褰撳墠娴佽浆鍗$殑鍑虹珯鍗� 鏄惁鏈夋暟鎹�
-                ds = oCN.RunProcReturn(@"select  * from Sc_StationOutBillMain a WITH(NOLOCK)
-left join Gy_Process p WITH(NOLOCK) on  a.HProcID=p.HItemID
-where HProcExchBillNo='" + HProcExchBillNo + "' and p.HNumber='" + HProcNumber + "' and CONVERT(varchar(10),HDate,20) ='" + DateTime.Now.ToString("yyyy-MM-dd") + "'", "Sc_StationOutBillMain");
+                ds = oCN.RunProcReturn(@"select  HInterID,HBillNo from Sc_StationOutBillMain a WITH(NOLOCK)
+                                        left join Gy_Process p WITH(NOLOCK) on  a.HProcID=p.HItemID
+                                        where HProcExchBillNo='" + HProcExchBillNo + "' and p.HNumber='" + HProcNumber + "'" +
+                                        " and CONVERT(varchar(10),HDate,20) ='" + DateTime.Now.ToString("yyyy-MM-dd") + "'", "Sc_StationOutBillMain");
 
                 CustomWriteLog("2.1.9鑾峰彇鏄惁鏈夊嚭绔欏崟 :" + HProcNumber + "----" + timer.Elapsed, DateTime.Now.ToString("yyyy-MM-dd"));
 
@@ -388,6 +391,7 @@
                  "," + HmaterOutqty + "," + HProcPriceRate + "," + HTemporaryAreaID + ","+ HShiftsID + ") ");
                 }
 
+               
                 CustomWriteLog("2.1.10 鍑虹珯鍗曟柊澧� :" + HProcNumber + "----" + timer.Elapsed, DateTime.Now.ToString("yyyy-MM-dd"));
 
                 if (HResult == "OK")
@@ -395,27 +399,28 @@
                     CustomWriteLog("2.1.11 鏉$爜鍙嶅啓 :" + HProcNumber + "----" + timer.Elapsed, DateTime.Now.ToString("yyyy-MM-dd"));
 
                     //鏌ヨ 鍑虹珯鍗曞瓙琛� 鏉$爜琛ㄧ殑鏁版嵁
-                    ds = oCN.RunProcReturn("select  * from Sc_StationOutBillSub_SN WITH(NOLOCK) where HInterID='" + HInterID + "' order by HEntryID desc", "Sc_StationOutBillSub_SN");
+                    ds = oCN.RunProcReturn("select  HEntryID, from Sc_StationOutBillSub_SN WITH(NOLOCK) where HInterID='" + HInterID + "' order by HEntryID desc", "Sc_StationOutBillSub_SN");
 
                     string HMakeTime = dic["HCreateTime"].ToString();
                     oCN.RunProc($@"insert into Sc_StationOutBillSub_SN(HInterID,HBillNo_bak,HEntryID,HBarCode,HBarCodeQty,HMakeTime,HRemark,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney)
-values({ HInterID}, '{ HBillNo}', {(ds.Tables[0].Rows.Count == 0 ? 1 : int.Parse(ds.Tables[0].Rows[0]["HEntryID"].ToString()) + 1)}, '{HBadCodeSN}', 1, '"+ HMakeTime + "', '', " + HProcExchInterID + "," + HProcExchEntryID + ", '" + HProcExchBillNo + "', '', 0, 0)");
+                    values({ HInterID}, '{ HBillNo}', {(ds.Tables[0].Rows.Count == 0 ? 1 : int.Parse(ds.Tables[0].Rows[0]["HEntryID"].ToString()) + 1)}, '{HBadCodeSN}', 1, '"+ HMakeTime + "', '', " + HProcExchInterID + "," + HProcExchEntryID + ", '" + HProcExchBillNo + "', '', 0, 0)");
 
                     CustomWriteLog("鏉$爜:" + HBadCodeSN + "宸ュ簭:" + HProcNumber + ",鍑虹珯鏃堕棿:" + HMakeTime, "TM" + DateTime.Now.ToString("yyyy-MM-dd"));
                     //鍙嶅啓宸ュ簭鍑虹珯鍗曠殑鍚堟牸鏁伴噺
                     oCN.RunProc("update Sc_StationOutBillMain  set HQty+=1  where HInterID='" + HInterID + "'");
+                    CustomWriteLog("鍙嶅啓鍚堟牸鏁伴噺!鏉$爜:" + HBadCodeSN + ",宸ュ簭:" + HProcNumber + ",鍑虹珯鍗旾D" + HInterID, DateTime.Now.ToString("yyyy-MM-dd"));
                     CustomWriteLog("2.1.12 鏉$爜鍙嶅啓 :" + HProcNumber + "----" + timer.Elapsed, DateTime.Now.ToString("yyyy-MM-dd"));
                 }
                 else if (HResult == "NG")
                 {
                     CustomWriteLog("2.1.13 涓嶅悎鏍煎弽鍐� :" + HProcNumber + "----" + timer.Elapsed, DateTime.Now.ToString("yyyy-MM-dd"));
                     //閫氳繃鏉$爜鏌ヨ鐢熶骇璐ㄩ噺姹囨姤鍗曟暟鎹�
-                    ds = oCN.RunProcReturn("select  * from Sc_QualityReportBillSub WITH(NOLOCK) where HBarCode='" + HBadCodeSN + "' order by HMakeDate desc", "Sc_QualityReportBillSub");
+                    ds = oCN.RunProcReturn("select  HMakeDate from Sc_QualityReportBillSub WITH(NOLOCK) where HBarCode='" + HBadCodeSN + "' order by HMakeDate desc", "Sc_QualityReportBillSub");
 
                     if (ds.Tables[0].Rows.Count > 0) {
                         string HBadDate = ds.Tables[0].Rows[0]["HMakeDate"].ToString();
                         //閫氳繃鏉$爜鏌ヨ杩斾慨璁板綍鍗曠殑鏁版嵁
-                        ds = oCN.RunProcReturn("select  * from Sc_SourceLineRepairBillMain WITH(NOLOCK) where HBarCode='" + HBadCodeSN + "' order by HMakeDate desc", "Sc_SourceLineRepairBillMain");
+                        ds = oCN.RunProcReturn("select  HMakeDate from Sc_SourceLineRepairBillMain WITH(NOLOCK) where HBarCode='" + HBadCodeSN + "' order by HMakeDate desc", "Sc_SourceLineRepairBillMain");
 
                         if (ds.Tables[0].Rows.Count > 0) {
                             string HRepairDate = ds.Tables[0].Rows[0]["HMakeDate"].ToString();
@@ -425,12 +430,14 @@
                             if (DateTime.Parse(HBadDate) < DateTime.Parse(HRepairDate)) {
                                 //鍙嶅啓宸ュ簭鍑虹珯鍗曠殑涓嶈壇鏁伴噺
                                 oCN.RunProc("update Sc_StationOutBillMain  set HBadCount+=1,HWasterQty_Work+=1 where HInterID='" + HInterID + "'");
+                                CustomWriteLog("鍙嶅啓涓嶅悎鏍兼暟閲�!鏉$爜:"+ HBadCodeSN+",宸ュ簭:"+ HProcNumber+",鍑虹珯鍗旾D"+ HInterID, DateTime.Now.ToString("yyyy-MM-dd"));
                             }
                         }
 
                     } else {
                         //鍙嶅啓宸ュ簭鍑虹珯鍗曠殑涓嶈壇鏁伴噺
                         oCN.RunProc("update Sc_StationOutBillMain  set HBadCount+=1,HWasterQty_Work+=1 where HInterID='" + HInterID + "'");
+                        CustomWriteLog("鍙嶅啓涓嶅悎鏍兼暟閲�!鏉$爜:" + HBadCodeSN + ",宸ュ簭:" + HProcNumber + ",鍑虹珯鍗旾D" + HInterID, DateTime.Now.ToString("yyyy-MM-dd"));
                     }
 
                     CustomWriteLog("2.1.14 涓嶅悎鏍煎弽鍐� :" + HProcNumber + "----" + timer.Elapsed, DateTime.Now.ToString("yyyy-MM-dd"));
@@ -442,7 +449,7 @@
                     return false;
                 }
 
-                //                //鏌ヨ鍑虹珯鏁伴噺鏄惁瓒呰繃娴佽浆鍗℃暟閲�
+                //鏌ヨ鍑虹珯鏁伴噺鏄惁瓒呰繃娴佽浆鍗℃暟閲�
                 //                ds = oCN.RunProcReturn($@"select (b.HQty -sum(isnull(ou.HQty,0))-sum(isnull(ou.HBadCount,0))) HQty from Sc_ProcessExchangeBillSub b WITH(NOLOCK)
                 //left join Sc_StationOutBillMain ou WITH(NOLOCK) on b.HInterID=ou.HProcExchInterID and b.HEntryID=ou.HProcExchEntryID
                 //where b.HInterID={HProcExchInterID} and b.HEntryID={HProcExchEntryID}
@@ -457,7 +464,7 @@
 
                 CustomWriteLog("2.1.15 鍙嶅啓缁撴潫 :" + HProcNumber + "----" + timer.Elapsed, DateTime.Now.ToString("yyyy-MM-dd"));
 
-                //澧炲姞宸ュ簭鍒ゆ柇
+                //澧炲姞宸ュ簭鍒ゆ柇 鎷嶇収宸ュ簭璺宠繃宸ヨ壓鍙傛暟缁戝畾 涓嶈蛋涓嬮潰娴佺▼锛岀洿鎺ョ粨鏉熸湰娆℃柊澧�
                 if (HProcNumber == "013")
                 {
                     return true;
@@ -504,13 +511,13 @@
 
 
                     //鏌ヨ鑱屽憳
-                    ds = oCN.RunProcReturn("select * from Gy_Employee WITH(NOLOCK) where HNumber='" + dic["HEmpCode"].ToString() + "' ", "Gy_Employee");
-                    string HMakers = "";
-                    if (ds.Tables[0].Rows.Count != 0)
-                    {
-                        HEmpIDs = long.Parse(ds.Tables[0].Rows[0]["HItemID"].ToString());//鑱屽憳ID
-                        HMakers = ds.Tables[0].Rows[0]["HName"].ToString();
-                    }
+                    //ds = oCN.RunProcReturn("select HItemID,HName  from Gy_Employee WITH(NOLOCK) where HNumber='" + dic["HEmpCode"].ToString() + "' ", "Gy_Employee");
+                   
+                    //if (ds.Tables[0].Rows.Count != 0)
+                    //{
+                    //    HEmpIDs = long.Parse(ds.Tables[0].Rows[0]["HItemID"].ToString());//鑱屽憳ID
+                    //    HMakers = ds.Tables[0].Rows[0]["HName"].ToString();
+                    //}
 
                     CustomWriteLog("2.1.21 鑱屽憳鏌ヨ :" + HProcNumber + "----" + timer.Elapsed, DateTime.Now.ToString("yyyy-MM-dd"));
 
@@ -519,11 +526,13 @@
 
                     //淇濆瓨鐢熶骇缁勮鍗曚富琛�
                     string sql = $@"Insert Into Sc_AssemblyBillMain(HYear,HPeriod,HBillType,HBillSubType,HInterID,HDate
-,HBillNo,HBillStatus,HMaker,HMakeDate,HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo
-,HICMOInterID,HICMOBillNo,HBarCode_P,HMaterID,HUnitID,HAssemblyStatus,HProdOrgID)
-values('{DateTime.Now.Year}','{DateTime.Now.Month}','3727','3727',{HInterID1},getdate()
-,'{HBillNo1}','1','{HMakers}',getdate(),{HProcExchInterID},{HProcExchEntryID},'{HProcExchBillNo}'
-,{HICMOInterID},'{HICMOBillNo}','{HBadCodeSN}',{HMaterID},0,'姹囨姤',{HPRDOrgIDs})";
+                            ,HBillNo,HBillStatus,HMaker,HMakeDate,HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo
+                            ,HICMOInterID,HICMOBillNo,HBarCode_P,HMaterID,HUnitID,HAssemblyStatus,HProdOrgID)
+                            values('{DateTime.Now.Year}','{DateTime.Now.Month}','3727','3727',{HInterID1},getdate()
+                            ,'{HBillNo1}','1','{HMakers}',getdate(),{HProcExchInterID},{HProcExchEntryID},'{HProcExchBillNo}'
+                            ,{HICMOInterID},'{HICMOBillNo}','{HBadCodeSN}',{HMaterID},0,'姹囨姤',{HPRDOrgIDs})";
+
+                    CustomWriteLog("2.1.21 sql璇彞 :" + sql + "----" + timer.Elapsed, DateTime.Now.ToString("yyyy-MM-dd"));
                     oCN.RunProc(sql);
 
                     CustomWriteLog("2.1.22 淇濆瓨涓昏〃 :" + HProcNumber + "----" + timer.Elapsed, DateTime.Now.ToString("yyyy-MM-dd"));
@@ -535,11 +544,11 @@
                         string HBarCodes =  dataSet.Tables[0].Rows[i]["HBarCode"].ToString();
                         //瀛愯〃瀛樺偍
                         string sq2 = $@"Insert Into Sc_AssemblyBillSub(HInterID,HBillNo_bak,HEntryID,HSourceInterID,HSourceEntryID,HSourceBillNo
-                ,HSourceBillType,HMaterID,HSourceID,HEquipID,HUnitID,HQty
-                ,HGroupID,HWorkerID,HScanDate,HBarCode,HBarCode_P,HSNNumber)
-                values({HInterID1},'{HBillNo1}',{(i + 1)},0,0,''
-                ,'',{ HMaterIDs},0,0,0,1
-                ,0,0,getdate(),'{HBarCodes}','{HBadCodeSN}','') ";
+                                        ,HSourceBillType,HMaterID,HSourceID,HEquipID,HUnitID,HQty
+                                        ,HGroupID,HWorkerID,HScanDate,HBarCode,HBarCode_P,HSNNumber)
+                                        values({HInterID1},'{HBillNo1}',{(i + 1)},0,0,''
+                                        ,'',{ HMaterIDs},0,0,0,1
+                                        ,0,0,getdate(),'{HBarCodes}','{HBadCodeSN}','') ";
                         oCN.RunProc(sq2);
                     }
 
@@ -708,7 +717,6 @@
             string sql = "";
             try
             {
-
                 //鏌ヨ鍑虹珯鍗曠殑淇℃伅 鏂逛究鍙傛暟淇濆瓨
                  DataSet ds = oCN.RunProcReturn(@"select a.HProcExchInterID,a.HProcExchEntryID,a.HProcExchBillNo,a.HProcID,p.HNumber from Sc_StationOutBillMain a WITH(NOLOCK) 
 left join Gy_Process p WITH(NOLOCK)  on a.HProcID=p.HItemID where HInterID=" + HInterID + " and HBillNo='" + HBillNo + "'", "Sc_StationOutBillMain");
@@ -737,7 +745,7 @@
                             string HGetTime = ds.Tables[0].Rows[i]["HCreateTime"].ToString();
                             string HResult = ds.Tables[0].Rows[i]["HResult"].ToString();
 
-                            DataSet dataSet = oCN.RunProcReturn("select * from Sc_StationOutBillSub_TechParam WITH(NOLOCK) where HInterID=" + HInterID + " and HBillNo_bak='" + HBillNo + "'", "Sc_StationOutBillSub_TechParam");
+                            DataSet dataSet = oCN.RunProcReturn("select HInterID,HEntryID from Sc_StationOutBillSub_TechParam WITH(NOLOCK) where HInterID=" + HInterID + " and HBillNo_bak='" + HBillNo + "'", "Sc_StationOutBillSub_TechParam");
 
                             sql = "insert into Sc_StationOutBillSub_TechParam(HInterID,HBillNo_bak,HEntryID ,HSourceInterID,HSourceEntryID,HSourceBillNo,HTechParamID,HRelValue,HGetTime,HBarCode,HMouldID,HRemark)" +
                                 $"values({HInterID},'{HBillNo}',{(dataSet.Tables[0].Rows.Count + 1)},{HProcExchInterID},{HProcExchEntryID},'{HProcExchBillNo}',{HTechParamID},{HCount},'{HGetTime}','{HBadCodeSN}',{HMouldID},'{HResult}')";
@@ -763,78 +771,48 @@
         {
             try
             {
-               
-                DataSet ds = oCN.RunProcReturn(@"select * from Gy_BarCodeBill where HBarCode='" + HBadCodeSN + "'", "Gy_BarCodeBill");
-                //鍒ゆ柇鏉$爜鏄惁瀛樺湪鏉$爜妗f
-                if (ds.Tables[0].Rows.Count > 0)
-                {
-                    string HSourceBillNo = ds.Tables[0].Rows[0]["HSourceBillNo"].ToString();
-                    DataSet dataTable = oCN.RunProcReturn(@"select * from Sc_ProcessExchangeBillMain where HBillNo='" + HSourceBillNo + "'", "Sc_ProcessExchangeBillMain");
-                    //鍒ゆ柇鏉$爜鐨勬簮鍗� 娴佽浆鍗℃槸鍚﹁鍒犻櫎
-                    if (dataTable.Tables[0].Rows.Count == 0)
-                    {
-                        //濡傛灉婧愬崟宸茬粡鍒犻櫎  鍒欐潯鐮佷篃鍒犻櫎閲嶆柊鐢熸垚
-                        oCN.RunProc("delete from Gy_BarCodeBill where HBarCode='" + HBadCodeSN + "'");
+                // 鏌ヨ鏉$爜鏄惁瀛樺湪鏉$爜妗f
+                DataSet barCodeDs = oCN.RunProcReturn(@"select HSourceBillNo from Gy_BarCodeBill WITH(NOLOCK) where HBarCode='" + HBadCodeSN + "'", "Gy_BarCodeBill");
 
-                        //閲嶆柊鏌ヨ鏉$爜妗f 杩涘叆鏂板鏂规硶
-                        ds = oCN.RunProcReturn(@"select * from Gy_BarCodeBill where HBarCode='" + HBadCodeSN + "'", "Gy_BarCodeBill");
+                if (barCodeDs.Tables[0].Rows.Count > 0)
+                {
+                    string HSourceBillNo = barCodeDs.Tables[0].Rows[0]["HSourceBillNo"].ToString();
+                    DataSet processExchangeDs = oCN.RunProcReturn(@"select HInterID from Sc_ProcessExchangeBillMain WITH(NOLOCK) where HBillNo='" + HSourceBillNo + "'", "Sc_ProcessExchangeBillMain");
+                    if (processExchangeDs.Tables[0].Rows.Count == 0)
+                    {
+                        oCN.RunProc("delete from Gy_BarCodeBill WITH(NOLOCK) where HBarCode='" + HBadCodeSN + "'");
+                        // 閲嶆柊鏌ヨ鏉$爜妗f
+                        barCodeDs = oCN.RunProcReturn(@"select HSourceBillNo from Gy_BarCodeBill WITH(NOLOCK) where HBarCode='" + HBadCodeSN + "'", "Gy_BarCodeBill");
                     }
                 }
 
-                //鍒ゆ柇鏉$爜鏄惁鍦ㄦ暟鎹簱閲�
-                if (ds.Tables[0].Rows.Count == 0)
+                //鍒ゆ柇鏉$爜鏄惁鍦ㄦ暟鎹簱閲� 濡傛灉鏈夊垪娌℃湁鏁版嵁杩斿洖閭e氨鏄繘鍘讳繚瀛�
+                if (barCodeDs.Tables[0].Rows.Count == 0)
                 {
-                    //鍒ゆ柇闀垮害鏄惁涓�29浣� 鏃犲皹杞﹂棿
-                    if (HBadCodeSN.Length == 29)
+                    //鍒ゆ柇鏉$爜闀垮害鏄�29浣嶈繕鏄�50浣�   29 鏃犲皹杞﹂棿    50 15杞﹂棿
+                    if (HBadCodeSN.Length == 29 || HBadCodeSN.Length == 50)
                     {
-                        string str1 = HBadCodeSN.Substring(18, 8);
-                        ds = oCN.RunProcReturn("select  * from Sc_ProcessExchangeBillMain where HProjectNum like'" + str1 + "-1%'", "Sc_ProcessExchangeBillMain");
-                        //鍒ゆ柇鏄惁鑳芥壘鍒板搴旂殑娴佽浆鍗�
-                        if (ds.Tables[0].Rows.Count > 0)
+                        string str1 = HBadCodeSN.Length == 29 ? HBadCodeSN.Substring(18, 8) : HBadCodeSN.Substring(42, 8);
+                        string HProcExchBillNo = GetProcExchBillNo(str1);
+
+                        if (HProcExchBillNo == null && HBadCodeSN.Length == 29)
                         {
-                            string HProcExchBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString();
-                            get_HBardBillSave(HBadCodeSN, HProcExchBillNo);
+                            // 绗竴娆℃埅鍙栨湭鎵惧埌锛岃繘琛岀浜屾鎴彇
+                            str1 = HBadCodeSN.Substring(0, 8);  // 绀轰緥鐨勯噸鏂版埅鍙栨柟娉�
+                            HProcExchBillNo = GetProcExchBillNo(str1);
                         }
-                        else
+
+                        if (HProcExchBillNo == null)
                         {
-                            str1 = HBadCodeSN.Substring(23, 3);
-                            ds = oCN.RunProcReturn("select  * from Sc_ProcessExchangeBillMain where HProjectNum like'" + str1 + "-1%'", "Sc_ProcessExchangeBillMain");
-                            //鍒ゆ柇鏄惁鑳芥壘鍒板搴旂殑娴佽浆鍗�
-                            if (ds.Tables[0].Rows.Count > 0)
-                            {
-                                string HProcExchBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString();
-                                get_HBardBillSave(HBadCodeSN, HProcExchBillNo);
-                            }
-                            else
-                            {
-                                oCN.RollBack();
-                                CustomWriteLog("鏉$爜:" + HBadCodeSN + ",娴佽浆鍗′笉瀛樺湪!", DateTime.Now.ToString("yyyy-MM-dd"));
-                                return 2;
-                            }
-                        }
-                    }
-                    //鍒ゆ柇闀垮害鏄惁涓�50浣�  15杞﹂棿
-                    else if (HBadCodeSN.Length == 50)
-                    {
-                        string str1 = HBadCodeSN.Substring(42, 8);
-                        ds = oCN.RunProcReturn("select  * from Sc_ProcessExchangeBillMain where HProjectNum like'" + str1 + "-1%'", "Sc_ProcessExchangeBillMain");
-                        //鍒ゆ柇鏄惁鑳芥壘鍒板搴旂殑娴佽浆鍗�
-                        if (ds.Tables[0].Rows.Count > 0)
-                        {
-                            string HProcExchBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString();
-                            get_HBardBillSave(HBadCodeSN, HProcExchBillNo);
-                        }
-                        else
-                        {
-                            oCN.RollBack();
                             CustomWriteLog("鏉$爜:" + HBadCodeSN + ",娴佽浆鍗′笉瀛樺湪!", DateTime.Now.ToString("yyyy-MM-dd"));
                             return 2;
                         }
+                        //淇濆瓨鏉$爜
+                        get_HBardBillSave(HBadCodeSN, HProcExchBillNo);
                     }
                     else
                     {
-                        oCN.RollBack();
-                        CustomWriteLog("鏉$爜:" + HBadCodeSN + ",闀垮害涓嶇瓑浜�29浣�!", DateTime.Now.ToString("yyyy-MM-dd"));
+                        CustomWriteLog("鏉$爜:" + HBadCodeSN + ",闀垮害涓嶇瓑浜�29浣嶆垨50浣�!", DateTime.Now.ToString("yyyy-MM-dd"));
                         return 2;
                     }
                 }
@@ -852,6 +830,20 @@
             }
         }
 
+        // 鏍规嵁鏉$爜 鑾峰彇娴佽浆鍗$紪鍙�
+        public string GetProcExchBillNo(string str1)
+        {
+
+            DataSet ds = oCN.RunProcReturn("select HBillNo from Sc_ProcessExchangeBillMain WITH(NOLOCK) where HProjectNum like'" + str1 + "-1%'", "Sc_ProcessExchangeBillMain");
+
+            if (ds.Tables[0].Rows.Count > 0)
+            {
+                return ds.Tables[0].Rows[0]["HBillNo"].ToString();
+            }
+            return null;
+        }
+
+
         //鏂板鏉$爜鏁版嵁
         public void get_HBardBillSave(string HBarCode, string HProcExchBillNo)
         {
@@ -859,10 +851,10 @@
             {
                 //鏌ヨ娴佽浆鍗℃暟鎹�
                 DataSet dataSet = oCN.RunProcReturn(@"select  a.HPRDORGID, m.HModel 鐗╂枡瑙勬牸,m.HName 鍚嶇墿鏂欑О,a.HBillNo,a.HInterID,a.HMaterID,m.HNumber 鐗╂枡浠g爜,o.HNumber 缁勭粐浠g爜,a.HUnitID,u.HNumber 鍗曚綅浠g爜 from Sc_ProcessExchangeBillMain a WITH(NOLOCK)
-left join Gy_Material m WITH(NOLOCK) on a.HMaterID=m.HItemID
-left join Xt_ORGANIZATIONS o WITH(NOLOCK) on a.HPRDORGID=o.HItemID
-left join Gy_Unit u WITH(NOLOCK) on a.HUnitID=u.HItemID 
-where HBillNo='" + HProcExchBillNo + "'", "Sc_ProcessExchangeBillMain");
+                                    left join Gy_Material m WITH(NOLOCK) on a.HMaterID=m.HItemID
+                                    left join Xt_ORGANIZATIONS o WITH(NOLOCK) on a.HPRDORGID=o.HItemID
+                                    left join Gy_Unit u WITH(NOLOCK) on a.HUnitID=u.HItemID 
+                                    where HBillNo='" + HProcExchBillNo + "'", "Sc_ProcessExchangeBillMain");
 
 
                 //鍒ゆ柇娴佽浆鍗′笉鑳戒负绌�
@@ -871,7 +863,7 @@
                     oCN.RollBack();
                     CustomWriteLog("鏉$爜:" + HBarCode + ",娴佽浆鍗′笉鑳戒负绌�!", DateTime.Now.ToString("yyyy-MM-dd"));
                 }
-              
+
                 //鏃ユ湡鑾峰彇鏂瑰紡
                 string sDate = DateTime.Now.ToString();
                 string HWei = "0";      //灏炬暟
@@ -963,7 +955,7 @@
         //瀹氭椂璇诲彇鏁版嵁
         private void timer1_Tick(object sender, EventArgs e)
         {
-            DataTable list = oCN.RunProcReturn("select top 100 * from Sb_EquipMentCollection_SN WITH(NOLOCK) where HFlag=0  order by HCreateTime asc", "Sb_EquipMentCollection_SN").Tables[0];
+            DataTable list = oCN.RunProcReturn("select top 100 HResult,HBarCode,HCreateTime from Sb_EquipMentCollection_SN WITH(NOLOCK) where HFlag=0  order by HCreateTime asc", "Sb_EquipMentCollection_SN").Tables[0];
 
             //寰幆闆嗗悎
             for (int i = 0; i < list.Rows.Count; i++)
@@ -977,7 +969,7 @@
                 //HResult = "OK";
                 //寮�濮嬩簨鍔�
                 oCN.BeginTran();
-
+                
                  if (HResult == "OK")
                 {
                     flag = HResultOK(list.Rows[i]);
@@ -1003,7 +995,7 @@
             {
 
                 //鏌ヨ鑱屽憳
-                DataSet ds = oCN.RunProcReturn("select * from Gy_Employee WITH(NOLOCK) where HNumber='" + dic["HEmpCode"].ToString() + "' ", "Gy_Employee");
+                DataSet ds = oCN.RunProcReturn("select HItemID,HName from Gy_Employee WITH(NOLOCK) where HNumber='" + dic["HEmpCode"].ToString() + "' ", "Gy_Employee");
                 long HEmpIDs = 0;
                 string HMakers = "";
                 if (ds.Tables[0].Rows.Count != 0)

--
Gitblit v1.9.1