From 1d9f82659dbfdfd6ac0ddbb33f1fd5af1164d939 Mon Sep 17 00:00:00 2001
From: yangle <admin@YINMOU>
Date: 星期五, 29 十一月 2024 16:52:14 +0800
Subject: [PATCH] 浸渍 铁芯检测 无尘 单品过站 不能开工不能过站控制

---
 WFormSynchronizeData_SMR/WFormSynchronizeData_SMR/Form1.cs |  243 +++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 187 insertions(+), 56 deletions(-)

diff --git a/WFormSynchronizeData_SMR/WFormSynchronizeData_SMR/Form1.cs b/WFormSynchronizeData_SMR/WFormSynchronizeData_SMR/Form1.cs
index e896c25..44c5b82 100644
--- a/WFormSynchronizeData_SMR/WFormSynchronizeData_SMR/Form1.cs
+++ b/WFormSynchronizeData_SMR/WFormSynchronizeData_SMR/Form1.cs
@@ -33,6 +33,7 @@
                 bool flag = false;
                 string HResult = list.Rows[i]["HResult"].ToString();
                 string HBadCodeSN = list.Rows[i]["HBarCode"].ToString();
+                string HCreateTime = list.Rows[i]["HCreateTime"].ToString();
                 //寮�濮嬩簨鍔�
                 oCN.BeginTran();
 
@@ -46,7 +47,7 @@
                 }
 
                 if (flag) {
-                    oCN.RunProc("update Sb_EquipMentCollection_SN set HFlag=1 where HBarCode='" + HBadCodeSN + "'");
+                    oCN.RunProc("update Sb_EquipMentCollection_SN set HFlag=1 where HBarCode='" + HBadCodeSN + "' and HCreateTime='"+ HCreateTime + "'");
                     //缁撴潫浜嬪姟
                     oCN.Commit();
                 }
@@ -70,8 +71,9 @@
                 else if (num == 1)
                 {
                     //鍒ゆ柇杩欎釜鏉$爜涔嬪墠鐨勭姸鎬佹槸鍚︿负NG
-                    DataSet ds = oCN.RunProcReturn(@"select * from Sb_EquipMentCollection_SN  WITH(NOLOCK) where HBarCode='" + HBadCodeSN + "' and HCreateTime<'" + dic["HCreateTime"].ToString() + "' and HResult='NG'  and HProcNumber='" + dic["HProcNumber"].ToString() + "'", "Sb_EquipMentCollection_SN");
+                    DataSet ds = oCN.RunProcReturn(@"select * from Sb_EquipMentCollection_SN  WITH(NOLOCK) where HBarCode='" + HBadCodeSN + "' and HCreateTime<'" + dic["HCreateTime"].ToString() + "' and HResult='NG'", "Sb_EquipMentCollection_SN");
 
+                    //鏌ヨ鍑虹珯鍗曟槸鍚﹀寘鍚潯鐮�
                     DataSet ds1 = oCN.RunProcReturn(@"select a.HSourceID,a.HProcID,* from Sc_StationOutBillMain a WITH(NOLOCK)
 inner join Sc_StationOutBillSub_SN sn WITH(NOLOCK) on a.HInterID=sn.HInterID
 left join Gy_Source s WITH(NOLOCK) on a.HSourceID=s.HItemID
@@ -104,9 +106,9 @@
             }
             catch (Exception e)
             {
+                oCN.RollBack();
                 string HBadCodeSN = dic["HBarCode"].ToString();
                 CustomWriteLog("鏉$爜:" + HBadCodeSN + ",閿欒鍘熷洜:" + e.Message, DateTime.Now.ToString("yyyy-MM-dd"));
-                oCN.RollBack();
                 return false;
             }
         }
@@ -121,7 +123,7 @@
                 HBadCodeSN = TM_ZH(HBadCodeSN);
                 num = SNHBardCodeList(HBadCodeSN);
 
-                if (num == 0)
+                if (num == 0 || num == 1)
                 {
                     flag = getOutBillAdd(dic, HBadCodeSN, "NG");
 
@@ -133,13 +135,6 @@
                         oCN.RunProc("update Gy_BarCodeBill set HStatus='涓嶈壇',HRemark='" + dic["HType"].ToString() + "' where HBarCode='" + HBadCodeSN + "'");
                     }
                 }
-                else if (num == 1)
-                {
-                    //鏉$爜瀛樺湪 鐢熸垚涓嶈壇姹囨姤鍗�
-                    flag = getBadBillAdd(dic);
-                    //鍙嶅啓鏉$爜鐘舵��
-                    oCN.RunProc("update Gy_BarCodeBill set HStatus='涓嶈壇',HRemark='" + dic["HType"].ToString() + "' where HBarCode='" + HBadCodeSN + "'");
-                }
                 else if (num == 2)
                 {
                     flag = false;
@@ -148,10 +143,10 @@
             }
             catch (Exception e)
             {
-                string HBadCodeSN = dic["HBarCode"].ToString();
-                CustomWriteLog("鏉$爜:" + HBadCodeSN + ",閿欒鍘熷洜:"+e.Message, DateTime.Now.ToString("yyyy-MM-dd"));
                 //鍥炴粴浜嬪姟
                 oCN.RollBack();
+                string HBadCodeSN = dic["HBarCode"].ToString();
+                CustomWriteLog("鏉$爜:" + HBadCodeSN + ",閿欒鍘熷洜:"+e.Message, DateTime.Now.ToString("yyyy-MM-dd"));
                 return false;
             }
         }
@@ -176,9 +171,11 @@
                 //鏌ヨ鑱屽憳
                 ds = oCN.RunProcReturn("select * 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();
                 }
 
                 long HDeptID = 0;
@@ -212,7 +209,7 @@
                 string HBillSubType = "3791";
 
                 int HBillStatus = 1;
-                string HMaker = "";//鍒跺崟浜�
+                string HMaker = HEmpName;//鍒跺崟浜�
                 string HMouldNum = "";//妯$┐鍙�
                 int HYear = DateTime.Now.Year;
                 double HPeriod = DateTime.Now.Month;
@@ -274,6 +271,20 @@
                 long HInterID = 0;
                 string HBillNo = "";
 
+                ds = oCN.RunProcReturn("exec h_p_Sc_SNBarcodeProcCtrl_S '" + HBadCodeSN + "'," + HProcID, "h_v_Gy_QualifiedRecordsList");
+                if (ds.Tables[0].Rows.Count == 0)
+                {
+                    oCN.RollBack();
+                    CustomWriteLog("鏉$爜:" + HBadCodeSN + "宸ュ簭:" + HProcID + ",宸ュ簭鎺у埗鏌ユ棤鏁版嵁!", DateTime.Now.ToString("yyyy-MM-dd"));
+                    return false;
+                }
+                else if (ds.Tables[0].Rows[0]["HBack"].ToString() == "2")
+                {
+                    oCN.RollBack();
+                    CustomWriteLog("鏉$爜:" + HBadCodeSN + "宸ュ簭:" + HProcID + "," + ds.Tables[0].Rows[0]["HBackRemark"].ToString() + "!", DateTime.Now.ToString("yyyy-MM-dd"));
+                    return false;
+                }
+
 
                 //鍒ゆ柇褰撳墠娴佽浆鍗$殑鍑虹珯鍗� 鏄惁鏈夋暟鎹�
                 ds = oCN.RunProcReturn(@"select  * from Sc_StationOutBillMain a WITH(NOLOCK)
@@ -323,30 +334,63 @@
                     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)");
 
+                    CustomWriteLog("鏉$爜:" + HBadCodeSN + "宸ュ簭:" + HProcNumber + ",鍑虹珯鏃堕棿:" + HMakeTime, "TM" + DateTime.Now.ToString("yyyy-MM-dd"));
                     //鍙嶅啓宸ュ簭鍑虹珯鍗曠殑鍚堟牸鏁伴噺
                     oCN.RunProc("update Sc_StationOutBillMain  set HQty+=1  where HInterID='" + HInterID + "'");
                 }
                 else if (HResult == "NG")
                 {
-                    //鍙嶅啓宸ュ簭鍑虹珯鍗曠殑涓嶈壇鏁伴噺
-                    oCN.RunProc("update Sc_StationOutBillMain  set HBadCount+=1 where HInterID='" + HInterID + "'");
+                    ds = oCN.RunProcReturn("select  * 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");
+
+                        if (ds.Tables[0].Rows.Count > 0) {
+                            string HRepairDate = ds.Tables[0].Rows[0]["HMakeDate"].ToString();
+
+                            if (DateTime.Parse(HBadDate) < DateTime.Parse(HRepairDate)) {
+                                //鍙嶅啓宸ュ簭鍑虹珯鍗曠殑涓嶈壇鏁伴噺
+                                oCN.RunProc("update Sc_StationOutBillMain  set HBadCount+=1 where HInterID='" + HInterID + "'");
+                            }
+                        }
+
+                    } else {
+                        //鍙嶅啓宸ュ簭鍑虹珯鍗曠殑涓嶈壇鏁伴噺
+                        oCN.RunProc("update Sc_StationOutBillMain  set HBadCount+=1 where HInterID='" + HInterID + "'");
+                    }
                 }
                 else
                 {
-                    CustomWriteLog("缁撴灉涓嶄负OK鎴朜G!", DateTime.Now.ToString("yyyy-MM-dd"));
                     oCN.RollBack();
+                    CustomWriteLog("缁撴灉涓嶄负OK鎴朜G!", DateTime.Now.ToString("yyyy-MM-dd"));
+                    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}
+group by b.HInterID,b.HEntryID,b.HQty", "Sc_ProcessExchangeBill_Out");
+
+                if (double.Parse(ds.Tables[0].Rows[0][0].ToString()) < 0)
+                {
+                    oCN.RollBack();
+                    CustomWriteLog("娴佽浆鍗�:"+ HProcExchBillNo + ",鍑虹珯鏁伴噺瓒呰繃娴佽浆鍗℃暟閲�!", DateTime.Now.ToString("yyyy-MM-dd"));
                     return false;
                 }
 
                 bool flag = false;
 
-                //flag = AddXt_XtRoutBill(HInterID, HBillNo, HBadCodeSN);
+                flag = AddXt_XtRoutBill(HInterID, HBillNo, HBadCodeSN);
 
-                //if (!flag) {
-                //    CustomWriteLog("绯荤粺鍙傛暟淇濆瓨澶辫触,鏉$爜:" + HBadCodeSN , DateTime.Now.ToString("yyyy-MM-dd"));
-                //    oCN.RollBack();
-                //    return false;
-                //}
+                if (!flag)
+                {
+                    oCN.RollBack();
+                    CustomWriteLog("绯荤粺鍙傛暟淇濆瓨澶辫触,鏉$爜:" + HBadCodeSN, DateTime.Now.ToString("yyyy-MM-dd"));
+                    return false;
+                }
 
                 //澧炲姞浜х嚎缁勮杩芥函鍗�
                 DataSet dataSet = oCN.RunProcReturn("exec h_p_Gy_BarCodeBillBomList '" + HProcExchBillNo + "'," + HProcID, "h_p_Gy_BarCodeBillBomList");
@@ -358,9 +402,10 @@
                     {
                         double SYHQty = double.Parse(dataSet.Tables[0].Rows[i]["閰嶄欢鏁伴噺"].ToString());
                         string HMaterNamePJ = dataSet.Tables[0].Rows[i]["閰嶄欢浠g爜"].ToString();
+                        string HMaterBarCode = dataSet.Tables[0].Rows[i]["HBarCode"].ToString();
                         if (SYHQty == 0) {
-                            CustomWriteLog("閰嶄欢浠g爜:" + HMaterNamePJ + ",鏁伴噺涓�0!", DateTime.Now.ToString("yyyy-MM-dd"));
                             oCN.RollBack();
+                            CustomWriteLog("閰嶄欢鏉$爜:"+ HMaterBarCode + ",閰嶄欢浠g爜:" + HMaterNamePJ + ",鏁伴噺涓�0!", DateTime.Now.ToString("yyyy-MM-dd"));
                             return false;
                         }
                     }
@@ -406,8 +451,8 @@
             }
             catch (Exception e)
             {
-                CustomWriteLog(e.Message, DateTime.Now.ToString("yyyy-MM-dd"));
                 oCN.RollBack();
+                CustomWriteLog(e.Message, DateTime.Now.ToString("yyyy-MM-dd"));
                 return false;
             }
         }
@@ -472,6 +517,20 @@
                 long HInterID = 0;
                 string HBillNo = "";
 
+                ds = oCN.RunProcReturn("exec h_p_Sc_SNBarcodeProcCtrl_S '" + HBadCodeSN + "'," + HProcID, "h_v_Gy_QualifiedRecordsList");
+                if (ds.Tables[0].Rows.Count == 0)
+                {
+                    oCN.RollBack();
+                    CustomWriteLog("鏉$爜:" + HBadCodeSN + "宸ュ簭:" + HProcID + ",宸ュ簭鎺у埗鏌ユ棤鏁版嵁!", DateTime.Now.ToString("yyyy-MM-dd"));
+                    return false;
+                }
+                else if (ds.Tables[0].Rows[0]["HBack"].ToString() == "2")
+                {
+                    oCN.RollBack();
+                    CustomWriteLog("鏉$爜:" + HBadCodeSN + "宸ュ簭:" + HProcID + "," + ds.Tables[0].Rows[0]["HBackRemark"].ToString() + "!", DateTime.Now.ToString("yyyy-MM-dd"));
+                    return false;
+                }
+
                 ds = oCN.RunProcReturn("select  * from Sc_AssemblyBillMain WITH(NOLOCK) where HMainSourceInterID=" + HProcExchInterID + " and HMainSourceEntryID=" + HProcExchEntryID, "Sc_AssemblyBillMain");
                 DateTime HDate=DateTime.Now;
                 //褰撲骇鍝佹病鏈夐厤浠剁殑鏃跺�� 鏌ヨ 涓嶈壇璁板綍
@@ -492,8 +551,8 @@
 
                 if (ds.Tables[0].Rows.Count == 0)
                 {
-                    CustomWriteLog("鏉$爜:" + HBadCodeSN + ",鏃犺繑淇褰�", DateTime.Now.ToString("yyyy-MM-dd"));
                     oCN.RollBack();
+                    CustomWriteLog("鏉$爜:" + HBadCodeSN + ",鏃犺繑淇褰�", DateTime.Now.ToString("yyyy-MM-dd"));
                     return false;
                 }
 
@@ -516,15 +575,18 @@
                     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)");
 
+                    CustomWriteLog("鏉$爜:" + HBadCodeSN + "宸ュ簭:"+ HProcNumber + ",鍑虹珯鏃堕棿:" + HMakeTime, "TM" + DateTime.Now.ToString("yyyy-MM-dd"));
+
                     //鍙嶅啓宸ュ簭鍑虹珯鍗曠殑鍚堟牸鏁伴噺
-                    oCN.RunProc("update Sc_StationOutBillMain set HQty+=1,HBadCount-=1  where HInterID='" + HInterID + "'");
+                    //oCN.RunProc("update Sc_StationOutBillMain set HQty+=1,HBadCount-=1  where HInterID='" + HInterID + "'");
+                    oCN.RunProc("update Sc_StationOutBillMain set HQty+=1  where HInterID='" + HInterID + "'");
                     //鍙嶅啓鏉$爜鐘舵��
                     oCN.RunProc("update Gy_BarCodeBill set HStatus=''  where HBarCode='" + HBadCodeSN + "'");
                 }
                 else
                 {
-                    CustomWriteLog("缁撴灉涓嶄负OK!", DateTime.Now.ToString("yyyy-MM-dd"));
                     oCN.RollBack();
+                    CustomWriteLog("缁撴灉涓嶄负OK!", DateTime.Now.ToString("yyyy-MM-dd"));
                     return false;
                 }
 
@@ -532,42 +594,53 @@
             }
             catch (Exception e)
             {
-                CustomWriteLog(e.Message, DateTime.Now.ToString("yyyy-MM-dd"));
                 oCN.RollBack();
+                CustomWriteLog(e.Message, DateTime.Now.ToString("yyyy-MM-dd"));
                 return false;
             }
         }
 
         //淇濆瓨绯荤粺鍙傛暟鍒板嚭绔欏崟
         public bool AddXt_XtRoutBill(long HInterID, string HBillNo,string HBadCodeSN) {
+            string sql = "";
             try
             {
 
 
-                DataSet ds = oCN.RunProcReturn("select  * from Sc_StationOutBillMain WITH(NOLOCK) where HInterID=" + HInterID + " and HBillNo='" + HBillNo + "'", "Sc_StationOutBillMain");
+                 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");
                 string HProcExchInterID = ds.Tables[0].Rows[0]["HProcExchInterID"].ToString();
                 string HProcExchEntryID = ds.Tables[0].Rows[0]["HProcExchEntryID"].ToString();
                 string HProcExchBillNo = ds.Tables[0].Rows[0]["HProcExchBillNo"].ToString();
-
-                ds = oCN.RunProcReturn(@"select  s.HItemID HMouldID,t.HItemID HTechParamID,HCount,HCreateTime from  Sb_EquipMentCollectionTechParam_SN a WITH(NOLOCK)
-left join Gy_Source s WITH(NOLOCK) on a.HSourceCode=s.HNumber
-left join Gy_TechnologyParameter t WITH(NOLOCK) on a.HType=t.HNumber
+                string HProcID = ds.Tables[0].Rows[0]["HProcID"].ToString();
+                string HProcNum = ds.Tables[0].Rows[0]["HNumber"].ToString();
+                //娉�:鍥犱负 缁勮 鎷嶇収 鏃堕棿闂撮殧姣旇緝鐭�  鎵�浠ョ洰鍓嶅彧鏄庣‘缁勮宸ュ簭鎵嶅彲浠ヤ繚瀛樺伐鑹哄弬鏁� 涔嬪悗濡傛灉鏈夊叾浠栧伐搴忕殑璇�  闇�瑕佸鍔犲伐搴忓瓧娈�
+                if (HProcID == "88"|| HProcNum=="005") {
+                    ds = oCN.RunProcReturn(@"select  s.HItemID HMouldID,t.HItemID HTechParamID,HCount,HCreateTime,a.HResult from  Sb_EquipMentCollectionTechParam_SN a WITH(NOLOCK)
+inner join Gy_Source s WITH(NOLOCK) on a.HSourceCode=s.HNumber
+inner join Gy_TechnologyParameter t WITH(NOLOCK) on a.HType=t.HName
 where a.HFlag=0 and a.HBarCode='" + HBadCodeSN + "'", "Sb_EquipMentCollectionTechParam_SN");
+                    //娉�:褰撳墠鍙湁涓�閬撳伐搴忔湁鍙傛暟 濡傛灉鏈夊閬撳伐搴忕殑璇� 闇�瑕佸鍔� 宸ュ簭鐨勮繃婊�
 
-                if (ds.Tables[0].Rows.Count != 0) {
-
-                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
+                    if (ds.Tables[0].Rows.Count != 0)
                     {
-                        string HMouldID = ds.Tables[0].Rows[i]["HMouldID"].ToString();
-                        string HTechParamID = ds.Tables[0].Rows[i]["HTechParamID"].ToString();
-                        string HCount = ds.Tables[0].Rows[i]["HCount"].ToString();
-                        string HGetTime = ds.Tables[0].Rows[i]["HCreateTime"].ToString();
 
-                        DataSet dataSet = oCN.RunProcReturn("select * from Sc_StationOutBillSub_TechParam WITH(NOLOCK) where HInterID=" + HInterID + " and HBillNo_bak='" + HBillNo + "' and HBarCode='" + HBadCodeSN + "'", "Sc_StationOutBillSub_TechParam");
+                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
+                        {
+                            string HMouldID = ds.Tables[0].Rows[i]["HMouldID"].ToString();
+                            string HTechParamID = ds.Tables[0].Rows[i]["HTechParamID"].ToString();
+                            string HCount = ds.Tables[0].Rows[i]["HCount"].ToString();
+                            string HGetTime = ds.Tables[0].Rows[i]["HCreateTime"].ToString();
+                            string HResult = ds.Tables[0].Rows[i]["HResult"].ToString();
 
-                        oCN.RunProc("insert into Sc_StationOutBillSub_TechParam(HInterID,HBillNo_bak,HEntryID ,HSourceInterID,HSourceEntryID,HSourceBillNo,HTechParamID,HRelValue,HGetTime,HBarCode,HMouldID)" +
-                            $"values({HInterID},'{HBillNo}',{(dataSet.Tables[0].Rows.Count + 1)},{HProcExchInterID},{HProcExchEntryID},'{HProcExchBillNo}',{HTechParamID},{HCount},'{HGetTime}','{HBadCodeSN}',{HMouldID})");
+                            DataSet dataSet = oCN.RunProcReturn("select * 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}')";
+
+                            oCN.RunProc(sql);
+                        }
+                        oCN.RunProc("update Sb_EquipMentCollectionTechParam_SN set HFlag=1 where HBarCode='" + HBadCodeSN + "'");
                     }
                 }
 
@@ -575,8 +648,8 @@
             }
             catch (Exception e)
             {
-                CustomWriteLog("宸ヨ壓鍙傛暟淇濆瓨:" + e.Message, DateTime.Now.ToString("yyyy-MM-dd"));
                 oCN.RollBack();
+                CustomWriteLog("宸ヨ壓鍙傛暟淇濆瓨:" + sql + e.Message, DateTime.Now.ToString("yyyy-MM-dd"));
                 return false;
             }
         }
@@ -586,14 +659,31 @@
         {
             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 杩涘叆鏂板鏂规硶
+                        ds = oCN.RunProcReturn(@"select * from Gy_BarCodeBill where HBarCode='" + HBadCodeSN + "'", "Gy_BarCodeBill");
+                    }
+                }
+
                 //鍒ゆ柇鏉$爜鏄惁鍦ㄦ暟鎹簱閲�
                 if (ds.Tables[0].Rows.Count == 0)
                 {
-                    //鍒ゆ柇闀垮害鏄惁涓�29浣�
+                    //鍒ゆ柇闀垮害鏄惁涓�29浣� 鏃犲皹杞﹂棿
                     if (HBadCodeSN.Length == 29)
                     {
-                        string str1 = HBadCodeSN.Substring(23, 3);
+                        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)
@@ -603,15 +693,44 @@
                         }
                         else
                         {
-                            CustomWriteLog("鏉$爜:" + HBadCodeSN + ",娴佽浆鍗′笉瀛樺湪!", DateTime.Now.ToString("yyyy-MM-dd"));
+                            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;
                         }
                     }
                     else
                     {
-                        CustomWriteLog("鏉$爜:" + HBadCodeSN + ",闀垮害涓嶇瓑浜�29浣�!", DateTime.Now.ToString("yyyy-MM-dd"));
                         oCN.RollBack();
+                        CustomWriteLog("鏉$爜:" + HBadCodeSN + ",闀垮害涓嶇瓑浜�29浣�!", DateTime.Now.ToString("yyyy-MM-dd"));
                         return 2;
                     }
                 }
@@ -623,8 +742,8 @@
             }
             catch (Exception e)
             {
-                CustomWriteLog("鏉$爜:" + HBadCodeSN + "," + e.Message, DateTime.Now.ToString("yyyy-MM-dd"));
                 oCN.RollBack();
+                CustomWriteLog("鏉$爜:" + HBadCodeSN + "," + e.Message, DateTime.Now.ToString("yyyy-MM-dd"));
                 return 2;
             }
         }
@@ -645,8 +764,8 @@
                 //鍒ゆ柇娴佽浆鍗′笉鑳戒负绌�
                 if (HBarCode.Trim() == "")
                 {
-                    CustomWriteLog("鏉$爜:" + HBarCode + ",娴佽浆鍗′笉鑳戒负绌�!", DateTime.Now.ToString("yyyy-MM-dd"));
                     oCN.RollBack();
+                    CustomWriteLog("鏉$爜:" + HBarCode + ",娴佽浆鍗′笉鑳戒负绌�!", DateTime.Now.ToString("yyyy-MM-dd"));
                 }
               
                 //鏃ユ湡鑾峰彇鏂瑰紡
@@ -715,8 +834,8 @@
             }
             catch (Exception e)
             {
-                CustomWriteLog("鏉$爜:" + HBarCode + "," + e.Message, DateTime.Now.ToString("yyyy-MM-dd"));
                 oCN.RollBack();
+                CustomWriteLog("鏉$爜:" + HBarCode + "," + e.Message, DateTime.Now.ToString("yyyy-MM-dd"));
             }
         }
 
@@ -740,7 +859,7 @@
         //瀹氭椂璇诲彇鏁版嵁
         private void timer1_Tick(object sender, EventArgs e)
         {
-            DataTable list = oCN.RunProcReturn("select  * from Sb_EquipMentCollection_SN WITH(NOLOCK) where HFlag=0  order by HCreateTime", "Sb_EquipMentCollection_SN").Tables[0];
+            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];
 
             //寰幆闆嗗悎
             for (int i = 0; i < list.Rows.Count; i++)
@@ -748,10 +867,14 @@
                 bool flag = false;
                 string HResult = list.Rows[i]["HResult"].ToString();
                 string HBadCodeSN = list.Rows[i]["HBarCode"].ToString();
+                string HCreateTime = list.Rows[i]["HCreateTime"].ToString();
+
+                //HBadCodeSN = "P1099081-00-E:SDU324292189300";
+                //HResult = "OK";
                 //寮�濮嬩簨鍔�
                 oCN.BeginTran();
 
-                if (HResult == "OK")
+                 if (HResult == "OK")
                 {
                     flag = HResultOK(list.Rows[i]);
                 }
@@ -762,7 +885,7 @@
 
                 if (flag)
                 {
-                    oCN.RunProc("update Sb_EquipMentCollection_SN set HFlag=1 where HBarCode='" + HBadCodeSN + "'");
+                    oCN.RunProc("update Sb_EquipMentCollection_SN set HFlag=1 where HBarCode='" + HBadCodeSN + "' and HCreateTime='" + HCreateTime + "'");
                     //缁撴潫浜嬪姟
                     oCN.Commit();
                 }
@@ -872,8 +995,8 @@
             }
             catch (Exception e)
             {
-                CustomWriteLog("鎶ラ敊鍘熷洜:" + e.Message + "!", DateTime.Now.ToString("yyyy-MM-dd"));
                 oCN.RollBack();
+                CustomWriteLog("鎶ラ敊鍘熷洜:" + e.Message + "!", DateTime.Now.ToString("yyyy-MM-dd"));
                 return false;
             }
         }
@@ -1085,5 +1208,13 @@
             }
         }
         #endregion
+
+        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
+        {
+            if (MessageBox.Show("纭畾瑕佸叧闂悧锛�", "纭", MessageBoxButtons.YesNo) == DialogResult.No)
+            {
+                e.Cancel = true;
+            }
+        }
     }
 }

--
Gitblit v1.9.1