From f4575e9e43ee9d1ce4d6a5c7c507c6d9c824c806 Mon Sep 17 00:00:00 2001
From: yangle <admin@YINMOU>
Date: 星期五, 10 五月 2024 15:24:07 +0800
Subject: [PATCH] 读取数据 复制一份读取 单品过站数量管控

---
 WFormSynchronizeData_SMR/WFormSynchronizeData_SMR/Form1.cs |  834 ++++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 599 insertions(+), 235 deletions(-)

diff --git a/WFormSynchronizeData_SMR/WFormSynchronizeData_SMR/Form1.cs b/WFormSynchronizeData_SMR/WFormSynchronizeData_SMR/Form1.cs
index b67db5d..9409baf 100644
--- a/WFormSynchronizeData_SMR/WFormSynchronizeData_SMR/Form1.cs
+++ b/WFormSynchronizeData_SMR/WFormSynchronizeData_SMR/Form1.cs
@@ -15,175 +15,195 @@
 {
     public partial class Form1 : Form
     {
-       public DBHelper oCN = new DBHelper();
+        public DBHelper oCN = new DBHelper();
         public Form1()
         {
             InitializeComponent();
         }
 
         //璇诲彇鏁版嵁
-        private void  btnReadData_Click(object sender, EventArgs e)
+        private void btnReadData_Click(object sender, EventArgs e)
         {
-            int year = DateTime.Now.Year;
-            string month = DateTime.Now.Month.ToString();
-            string day = DateTime.Now.Day.ToString();
-           
-
-            //if (month.Length < 2) {
-            //    month = "0" + month;
-            //}
-            //if (day.Length < 2)
-            //{
-            //    day = "0" + day;
-            //}
-
-            string dataTime = DateTime.Now.ToString("yyyyMMdd");
-            //CustomWriteLog("1:" + dataTime, DateTime.Now.ToString("yyyy-MM-dd"));
-            ////鍒ゆ柇鏄惁鏈夎繖涓枃浠�
-            bool flag = File.Exists($@"D:\{year}\{month}\{day}\{dataTime}.txt");
-            //bool flag = File.Exists($@"C:\Users\admin\Desktop\鏂板缓鏂囦欢澶� (2)\20231123.txt");
-            //CustomWriteLog("2:" + flag, DateTime.Now.ToString("yyyy-MM-dd"));
-            if (flag)
+            
+            DataTable list = oCN.RunProcReturn("select  * 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++)
             {
-                StreamReader stream = new StreamReader($@"D:\{year}\{month}\{day}\{dataTime}.txt", Encoding.GetEncoding("gb2312"));
-                //CustomWriteLog("3:"+ $@"D:\{year}\{month}\{day}\{dataTime}.txt", DateTime.Now.ToString("yyyy-MM-dd"));
-                //StreamReader stream = new StreamReader($@"C:\Users\admin\Desktop\鏂板缓鏂囦欢澶� (2)\20231123.txt",Encoding.GetEncoding("gb2312"));
-                string FileData = stream.ReadToEnd();
-                stream.Close();
-                FileData = FileData.Substring(0, FileData.Length - 1);
-                FileData = "[" + FileData + "]";
-                //CustomWriteLog("4:" + FileData, DateTime.Now.ToString("yyyy-MM-dd"));
-                //JSON搴忓垪鍖栬浆鎹㈠瓧鍏搁泦鍚�
-                List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
-                List<object> DataList = JsonConvert.DeserializeObject<List<object>>(FileData);
-                foreach (JObject item in DataList)
-                {
-                    Dictionary<string, string> dic = new Dictionary<string, string>();
-                    foreach (var itm in item.Properties())
-                    {
-                        dic.Add(itm.Name, itm.Value.ToString());
-                    }
-                    list.Add(dic);
-                }
-                //CustomWriteLog("5:" + list.Count, DateTime.Now.ToString("yyyy-MM-dd"));
-                //鑾峰彇褰撳墠鏃堕棿
-                DateTime ActionTime = DateTime.Parse(DateTime.Now.AddMinutes(-1).ToString("yyyy-MM-dd  HH:mm:ss"));
-                DateTime EndTime = DateTime.Parse(DateTime.Now.AddMinutes(1).ToString("yyyy-MM-dd  HH:mm:00"));
-                //寰幆闆嗗悎
-                for (int i = 0; i < list.Count; i++)
-                {
-                    DateTime NowTime = DateTime.Parse(list[i]["HDate"].ToString());
-                    if (NowTime >= ActionTime && NowTime < EndTime)
-                    {
-                        string HResult = list[i]["HResult"].ToString();
+                bool flag = false;
+                string HResult = list.Rows[i]["HResult"].ToString();
+                string HBadCodeSN = list.Rows[i]["HBarCode"].ToString();
+                //寮�濮嬩簨鍔�
+                oCN.BeginTran();
 
-                        //CustomWriteLog("6:" + HResult, DateTime.Now.ToString("yyyy-MM-dd"));
-                        if (HResult == "OK")
-                        {
-                            HResultOK(list[i]);
-                        }
-                        else if (HResult == "NG")
-                        {
-                            HResultNG(list[i]);
-                        }
-                    }
-                    else
-                    {
-                        //CustomWriteLog("鏃堕棿涓嶅湪淇濆瓨鑼冨洿鍐�", DateTime.Now.ToString("yyyy-MM-dd"));
-                    }
+                if (HResult == "OK")
+                {
+                    flag=HResultOK(list.Rows[i]);
                 }
+                else if (HResult == "NG")
+                {
+                    flag = HResultNG(list.Rows[i]);
+                }
+
+                if (flag) {
+                    oCN.RunProc("update Sb_EquipMentCollection_SN set HFlag=1 where HBarCode='" + HBadCodeSN + "'");
+                    //缁撴潫浜嬪姟
+                    oCN.Commit();
+                }
+              
             }
         }
 
-        public void HResultOK(Dictionary<string, string> dic)
+        public bool HResultOK(DataRow dic)
         {
             try
             {
-                string HBadCodeSN = dic["HBadCodeSN"].ToString();
+                bool flag = false;
+                string HBadCodeSN = dic["HBarCode"].ToString();
                 HBadCodeSN = TM_ZH(HBadCodeSN);
-                bool flag = SNHBardCodeList(HBadCodeSN);
+                int num = SNHBardCodeList(HBadCodeSN);
 
-                if (flag)
+                if (num == 0)
                 {
-                    getAdd(dic, HBadCodeSN, "OK");
+                    flag = getOutBillAdd(dic, HBadCodeSN, "OK");
                 }
-               
+                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 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
+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");
+
+                    if (ds.Tables[0].Rows.Count > 0 && ds1.Tables[0].Rows.Count == 0)
+                    {
+                        flag = getOKOutBillAdd(dic, HBadCodeSN, "OK");
+                    }
+                    else
+                    {
+                        if (ds1.Tables[0].Rows.Count > 0)
+                        {
+                            flag = true;
+                            //oCN.RollBack();
+                        }
+                        else
+                        {
+                            flag = getOutBillAdd(dic, HBadCodeSN, "OK");
+                        }
+                    }
+                }
+                else if (num == 2)
+                {
+                    flag = false;
+                }
+                return flag;
+
             }
             catch (Exception e)
             {
                 oCN.RollBack();
-                //objJsonResult.code = "0";
-                //objJsonResult.count = 0;
-                //objJsonResult.Message = "娌℃湁杩斿洖浠讳綍璁板綍锛�" + e.ToString();
-                //objJsonResult.data = null;
-                //return objJsonResult;
+                string HBadCodeSN = dic["HBarCode"].ToString();
+                CustomWriteLog("鏉$爜:" + HBadCodeSN + ",閿欒鍘熷洜:" + e.Message, DateTime.Now.ToString("yyyy-MM-dd"));
+                return false;
             }
         }
 
-        public void HResultNG(Dictionary<string, string> dic)
+        public bool HResultNG(DataRow dic)
         {
             try
             {
-                string HBadCodeSN = dic["HBadCodeSN"].ToString();
+                bool flag = false;
+                int num = 0;
+                string HBadCodeSN = dic["HBarCode"].ToString();
                 HBadCodeSN = TM_ZH(HBadCodeSN);
-                bool flag = SNHBardCodeList(HBadCodeSN);
+                num = SNHBardCodeList(HBadCodeSN);
 
-                if (flag)
+                if (num == 0 || num == 1)
                 {
-                    getAdd(dic, HBadCodeSN, "NG");
-                    //寮�濮嬩簨鍔�
-                    oCN.BeginTran();
+                    flag = getOutBillAdd(dic, HBadCodeSN, "NG");
 
-                    //鍙嶅啓鏉$爜鐘舵��
-                    oCN.RunProc("update Gy_BarCodeBill set HStatus='涓嶈壇',HRemark='"+dic["HBadReason"].ToString()+"' where HBarCode='" + HBadCodeSN + "'");
-
-                    //缁撴潫浜嬪姟
-                    oCN.Commit();
+                    if (flag)
+                    {
+                        //鏂板涓嶈壇姹囨姤
+                        flag = getBadBillAdd(dic);
+                        //鍙嶅啓鏉$爜鐘舵��
+                        oCN.RunProc("update Gy_BarCodeBill set HStatus='涓嶈壇',HRemark='" + dic["HType"].ToString() + "' where HBarCode='" + HBadCodeSN + "'");
+                    }
                 }
+                else if (num == 2)
+                {
+                    flag = false;
+                }
+                return flag;
             }
             catch (Exception e)
             {
                 //鍥炴粴浜嬪姟
                 oCN.RollBack();
-                //objJsonResult.code = "0";
-                //objJsonResult.count = 0;
-                //objJsonResult.Message = "娌℃湁杩斿洖浠讳綍璁板綍锛�" + e.ToString();
-                //objJsonResult.data = null;
-                //return objJsonResult;
+                string HBadCodeSN = dic["HBarCode"].ToString();
+                CustomWriteLog("鏉$爜:" + HBadCodeSN + ",閿欒鍘熷洜:"+e.Message, DateTime.Now.ToString("yyyy-MM-dd"));
+                return false;
             }
         }
 
-        public bool getAdd(Dictionary<string, string> dic,string HBadCodeSN,string HResult) {
+        //鏂板鍑虹珯姹囨姤鍗�
+        public bool getOutBillAdd(DataRow dic, string HBadCodeSN, string HResult)
+        {
             try
             {
                 //鑾峰彇缁戝畾娴佽浆鍗�
-                DataSet ds = oCN.RunProcReturn(@"select * from Gy_BarCodeBill where HBarCode='" + HBadCodeSN + "'", "Gy_BarCodeBill");
+                DataSet ds = oCN.RunProcReturn(@"select * from Gy_BarCodeBill WITH(NOLOCK) where HBarCode='" + HBadCodeSN + "'", "Gy_BarCodeBill");
                 string HProcExchBillNo = ds.Tables[0].Rows[0]["HSourceBillNo"].ToString();
                 string HProcNumber = dic["HProcNumber"].ToString();
 
-                ds = oCN.RunProcReturn("select * from Gy_Source where HNumber='" + dic["HSouceNumber"].ToString() + "' ", "Gy_Source");
+                ds = oCN.RunProcReturn("select * from Gy_Source WITH(NOLOCK) where HNumber='" + dic["HSourceCode"].ToString() + "' ", "Gy_Source");
                 long HSourceID = 0;
-                if (ds.Tables[0].Rows.Count != 0) {
+                if (ds.Tables[0].Rows.Count != 0)
+                {
                     HSourceID = long.Parse(ds.Tables[0].Rows[0]["HItemID"].ToString());//鐢熶骇璧勬簮ID
                 }
 
-                ds = oCN.RunProcReturn("select * from Gy_Department where HNumber='" + dic["HDeptNumber"].ToString() + "' ", "Gy_Department");
-                long HDeptID = 0;
+                //鏌ヨ鑱屽憳
+                ds = oCN.RunProcReturn("select * from Gy_Employee WITH(NOLOCK) where HNumber='" + dic["HEmpCode"].ToString() + "' ", "Gy_Employee");
+                long HEmpIDs = 0;
                 if (ds.Tables[0].Rows.Count != 0)
                 {
-                    HDeptID = long.Parse(ds.Tables[0].Rows[0]["HItemID"].ToString());//鐢熶骇閮ㄩ棬
+                    HEmpIDs = long.Parse(ds.Tables[0].Rows[0]["HItemID"].ToString());//鑱屽憳ID
                 }
 
-                ds = oCN.RunProcReturn(@"select   b.HProcNo,b.HProcID,a.HMaterID,a.HQty,a.HInterID,HEntryID,a.HICMOInterID,a.HICMOEntryID,a.HICMOBillNo from Sc_ProcessExchangeBillMain a
-inner join Sc_ProcessExchangeBillSub b on a.HInterID=b.HInterID
-left join Gy_Process p on  b.HProcID=p.HItemID 
+                long HDeptID = 0;
+                long HPRDOrgIDs = 0;
+                string sReturn = "";
+                if (GetSingleSystemParameter("WMS_CampanyName", ref sReturn) == "鏉窞鏂帿灏�")
+                {
+                    HDeptID = 389499;
+                    HPRDOrgIDs = 100199;
+                }
+                else {
+                    //ds = oCN.RunProcReturn("select * from Gy_Department where HNumber='" + dic["HDeptNumber"].ToString() + "' ", "Gy_Department");
+
+                    //if (ds.Tables[0].Rows.Count != 0)
+                    //{
+                    //    HDeptID = long.Parse(ds.Tables[0].Rows[0]["HItemID"].ToString());//鐢熶骇閮ㄩ棬
+                    //}
+                    HDeptID = 0;
+                }
+
+             
+
+                ds = oCN.RunProcReturn(@"select   b.HProcNo,b.HProcID,a.HMaterID,a.HQty,a.HInterID,HEntryID,a.HICMOInterID,a.HICMOEntryID,a.HICMOBillNo 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");
 
                 string sExeReturnInfo = "";
                 long HMainInterID = 0;
                 string BillType = "3791";
                 string HBillSubType = "3791";
-            
+
                 int HBillStatus = 1;
                 string HMaker = "";//鍒跺崟浜�
                 string HMouldNum = "";//妯$┐鍙�
@@ -212,8 +232,8 @@
                 long HPayProcID = 0;//鏍哥畻宸ュ簭ID
                 long HGroupID = 22;//鐝粍ID 鐧界彮
 
-                long HEmpID = 0;//鎿嶄綔鍛業D
-                long HEmpID2 = 0;////鎿嶄綔鍛�2ID
+                long HEmpID = HEmpIDs;//鎿嶄綔鍛業D
+                long HEmpID2 = HEmpIDs;////鎿嶄綔鍛�2ID
                 string HBarCode = HProcExchBillNo;//鏉″舰鐮�
                 string HAddr = "";
                 string HBarCodeMaker = "";
@@ -240,26 +260,25 @@
                 double HPriceRate = 0;//绯绘暟
                 double HWorkTimes = 0;//宸ユ椂
                 long HQCCheckID = 0;//妫�楠屽憳ID
-                long HPRDOrgID = 100199;//缁勭粐ID
+                long HPRDOrgID = HPRDOrgIDs;//缁勭粐ID
                 double HmaterOutqty = 0;//鐧藉澂鍙戝竷
                 double HProcPriceRate = 0;//宸ヤ环绯绘暟
                 int HTemporaryAreaID = 0;//鏆傛斁鍖�
                 long HInterID = 0;
                 string HBillNo = "";
 
-                oCN.BeginTran();
 
                 //鍒ゆ柇褰撳墠娴佽浆鍗$殑鍑虹珯鍗� 鏄惁鏈夋暟鎹�
-                ds = oCN.RunProcReturn(@"select  * from Sc_StationOutBillMain a
-left join Gy_Process p on  a.HProcID=p.HItemID
-where HProcExchBillNo='" + HProcExchBillNo + "' and p.HNumber='" + HProcNumber + "'", "Sc_StationOutBillMain");
+                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");
 
                 if (ds.Tables[0].Rows.Count != 0)
                 {
                     HInterID = long.Parse(ds.Tables[0].Rows[0]["HInterID"].ToString());
                     HBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString();//閫掑叆type寰楀埌鐨勫崟鎹彿
                 }
-               
+
                 if (ds.Tables[0].Rows.Count == 0)
                 {
                     HInterID = CreateBillID("3791", ref sExeReturnInfo);//閫掑叆type寰楀埌鐨勫崟鎹甀D
@@ -291,37 +310,290 @@
 
                 if (HResult == "OK")
                 {
-                    ds = oCN.RunProcReturn("select  * from Sc_StationOutBillSub_SN where HInterID='" + HInterID + "' order by HEntryID desc", "Sc_StationOutBillSub_SN");
+                    ds = oCN.RunProcReturn("select  * 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, GETDATE(), '', " + 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)");
 
                     //鍙嶅啓宸ュ簭鍑虹珯鍗曠殑鍚堟牸鏁伴噺
-                    oCN.RunProc("update Sc_StationOutBillMain set HQty+=1  where HProcExchInterID='" + HProcExchInterID + "' and HProcExchEntryID=" + HProcExchEntryID);
+                    oCN.RunProc("update Sc_StationOutBillMain  set HQty+=1  where HInterID='" + HInterID + "'");
                 }
                 else if (HResult == "NG")
                 {
                     //鍙嶅啓宸ュ簭鍑虹珯鍗曠殑涓嶈壇鏁伴噺
-                    oCN.RunProc("update Sc_StationOutBillMain set HBadCount+=1  where HProcExchInterID='" + HProcExchInterID + "' and HProcExchEntryID=" + HProcExchEntryID);
+                    oCN.RunProc("update Sc_StationOutBillMain  set HBadCount+=1 where HInterID='" + HInterID + "'");
                 }
                 else
                 {
+                    oCN.RollBack();
                     CustomWriteLog("缁撴灉涓嶄负OK鎴朜G!", DateTime.Now.ToString("yyyy-MM-dd"));
                     return false;
                 }
-                oCN.Commit();
+
+                //鏌ヨ鍑虹珯鏁伴噺鏄惁瓒呰繃娴佽浆鍗℃暟閲�
+                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);
+
+                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");
+
+                if (dataSet.Tables[0].Rows.Count > 0)
+                {
+                    //鍒ら厤浠舵暟閲忔槸鍚︾瓑浜�0
+                    for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
+                    {
+                        double SYHQty = double.Parse(dataSet.Tables[0].Rows[i]["閰嶄欢鏁伴噺"].ToString());
+                        string HMaterNamePJ = dataSet.Tables[0].Rows[i]["閰嶄欢浠g爜"].ToString();
+                        if (SYHQty == 0) {
+                            oCN.RollBack();
+                            CustomWriteLog("閰嶄欢浠g爜:" + HMaterNamePJ + ",鏁伴噺涓�0!", DateTime.Now.ToString("yyyy-MM-dd"));
+                            return false;
+                        }
+                    }
+
+
+                    //鏌ヨ鑱屽憳
+                    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();
+                    }
+
+                    Int64 HInterID1 = CreateBillID("3727", ref sExeReturnInfo);
+                    string HBillNo1 = CreateBillCode_Prod("3727", ref sExeReturnInfo, true);
+
+                    //淇濆瓨鐢熶骇缁勮鍗曚富琛�
+                    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})";
+                    oCN.RunProc(sql);
+
+                    for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
+                    {
+                        string HMaterIDs = dataSet.Tables[0].Rows[i]["HMaterID"].ToString();
+                        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}','') ";
+                        oCN.RunProc(sq2);
+                    }
+                }
 
                 return true;
             }
             catch (Exception e)
             {
+                oCN.RollBack();
                 CustomWriteLog(e.Message, DateTime.Now.ToString("yyyy-MM-dd"));
                 return false;
             }
         }
 
+        //鏂板杩斾慨OK鍑虹珯姹囨姤鍗�
+        public bool getOKOutBillAdd(DataRow dic, string HBadCodeSN, string HResult)
+        {
+            try
+            {
+                //鑾峰彇缁戝畾娴佽浆鍗�
+                DataSet ds = oCN.RunProcReturn(@"select * from Gy_BarCodeBill WITH(NOLOCK) where HBarCode='" + HBadCodeSN + "'", "Gy_BarCodeBill");
+                string HProcExchBillNo = ds.Tables[0].Rows[0]["HSourceBillNo"].ToString();
+                string HProcNumber = dic["HProcNumber"].ToString();
+
+                ds = oCN.RunProcReturn("select * from Gy_Source WITH(NOLOCK) where HNumber='" + dic["HSourceCode"].ToString() + "' ", "Gy_Source");
+                long HSourceID = 0;
+                if (ds.Tables[0].Rows.Count != 0)
+                {
+                    HSourceID = long.Parse(ds.Tables[0].Rows[0]["HItemID"].ToString());//鐢熶骇璧勬簮ID
+                }
+
+                //鏌ヨ鑱屽憳
+                ds = oCN.RunProcReturn("select * from Gy_Employee WITH(NOLOCK) where HNumber='" + dic["HEmpCode"].ToString() + "' ", "Gy_Employee");
+                long HEmpIDs = 0;
+                if (ds.Tables[0].Rows.Count != 0)
+                {
+                    HEmpIDs = long.Parse(ds.Tables[0].Rows[0]["HItemID"].ToString());//鑱屽憳ID
+                }
+
+                long HDeptID = 0;
+                long HPRDOrgIDs = 0;
+                string sReturn = "";
+                if (GetSingleSystemParameter("WMS_CampanyName", ref sReturn) == "鏉窞鏂帿灏�")
+                {
+                    HDeptID = 389499;
+                    HPRDOrgIDs = 100199;
+                }
+                else
+                {
+                    //ds = oCN.RunProcReturn("select * from Gy_Department where HNumber='" + dic["HDeptNumber"].ToString() + "' ", "Gy_Department");
+
+                    //if (ds.Tables[0].Rows.Count != 0)
+                    //{
+                    //    HDeptID = long.Parse(ds.Tables[0].Rows[0]["HItemID"].ToString());//鐢熶骇閮ㄩ棬
+                    //}
+                    HDeptID = 0;
+                }
+
+                ds = oCN.RunProcReturn(@"select   b.HProcNo,b.HProcID,a.HMaterID,a.HQty,a.HInterID,HEntryID,a.HICMOInterID,a.HICMOEntryID,a.HICMOBillNo 
+                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");
+
+                long HICMOInterID = long.Parse(ds.Tables[0].Rows[0]["HICMOInterID"].ToString());//浠诲姟鍗旾D
+                long HICMOEntryID = long.Parse(ds.Tables[0].Rows[0]["HICMOEntryID"].ToString());//浠诲姟鍗旾D
+                string HICMOBillNo = ds.Tables[0].Rows[0]["HICMOBillNo"].ToString();//浠诲姟鍗�
+                long HProcExchInterID = long.Parse(ds.Tables[0].Rows[0]["HInterID"].ToString());
+                long HProcExchEntryID = long.Parse(ds.Tables[0].Rows[0]["HEntryID"].ToString());
+                long HMaterID = long.Parse(ds.Tables[0].Rows[0]["HMaterID"].ToString());//浜у搧ID
+                long HProcID = long.Parse(ds.Tables[0].Rows[0]["HProcID"].ToString());//褰撳墠宸ュ簭ID
+                long HInterID = 0;
+                string HBillNo = "";
+
+                ds = oCN.RunProcReturn("select  * from Sc_AssemblyBillMain WITH(NOLOCK) where HMainSourceInterID=" + HProcExchInterID + " and HMainSourceEntryID=" + HProcExchEntryID, "Sc_AssemblyBillMain");
+                DateTime HDate=DateTime.Now;
+                //褰撲骇鍝佹病鏈夐厤浠剁殑鏃跺�� 鏌ヨ 涓嶈壇璁板綍
+                if (ds.Tables[0].Rows.Count == 0)
+                {
+                    ds = oCN.RunProcReturn("select  * from Sc_QualityReportBillSub WITH(NOLOCK) where HProcExchInterID=" + HProcExchInterID + " and HProcExchEntryID=" + HProcExchEntryID+ " and HBarCode='" + HBadCodeSN + "'", "Sc_AssemblyBillMain");
+                    HDate = DateTime.Parse(ds.Tables[0].Rows[0]["HMakeDate"].ToString());
+                }
+                else {
+                    HDate = DateTime.Parse(ds.Tables[0].Rows[0]["HDate"].ToString());
+                }
+
+                //鏌ヨ鏄惁鏈夎繑淇褰�
+                ds = oCN.RunProcReturn(@"select a.HBarCode,a.HProcess,b.HSourceInterID,b.HSourceEntryID,b.HRepairResult from Sc_SourceLineRepairBillMain a WITH(NOLOCK)
+inner join Sc_SourceLineRepairBillSub b WITH(NOLOCK) on a.HInterID = b.HInterID
+where a.HBarCode = '" + HBadCodeSN + "' and  a.HProcess ="+ HProcID + " and  b.HSourceInterID ="+ HProcExchInterID + " " +
+"and b.HSourceEntryID="+ HProcExchEntryID + " and b.HRepairResult = 'OK'", "Sc_SourceLineRepairBillMain");
+
+                if (ds.Tables[0].Rows.Count == 0)
+                {
+                    oCN.RollBack();
+                    CustomWriteLog("鏉$爜:" + HBadCodeSN + ",鏃犺繑淇褰�", DateTime.Now.ToString("yyyy-MM-dd"));
+                    return false;
+                }
+
+                //鍒ゆ柇褰撳墠娴佽浆鍗$殑鍑虹珯鍗� 鏄惁鏈夋暟鎹�
+                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) ='" + HDate.ToString("yyyy-MM-dd") + "'", "Sc_StationOutBillMain");
+
+                if (ds.Tables[0].Rows.Count != 0)
+                {
+                    HInterID = long.Parse(ds.Tables[0].Rows[0]["HInterID"].ToString());
+                    HBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString();//閫掑叆type寰楀埌鐨勫崟鎹彿
+                }
+
+                if (HResult == "OK")
+                {
+                    ds = oCN.RunProcReturn("select  * 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)");
+
+                    //鍙嶅啓宸ュ簭鍑虹珯鍗曠殑鍚堟牸鏁伴噺
+                    oCN.RunProc("update Sc_StationOutBillMain set HQty+=1,HBadCount-=1  where HInterID='" + HInterID + "'");
+                    //鍙嶅啓鏉$爜鐘舵��
+                    oCN.RunProc("update Gy_BarCodeBill set HStatus=''  where HBarCode='" + HBadCodeSN + "'");
+                }
+                else
+                {
+                    oCN.RollBack();
+                    CustomWriteLog("缁撴灉涓嶄负OK!", DateTime.Now.ToString("yyyy-MM-dd"));
+                    return false;
+                }
+
+                return true;
+            }
+            catch (Exception e)
+            {
+                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");
+                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)
+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++)
+                    {
+                        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 + "'", "Sc_StationOutBillSub_TechParam");
+
+                        sql = "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})";
+
+                        oCN.RunProc(sql);
+                    }
+                    oCN.RunProc("update Sb_EquipMentCollectionTechParam_SN set HFlag=1 where HBarCode='" + HBadCodeSN + "'");
+                }
+
+                return true;
+            }
+            catch (Exception e)
+            {
+                oCN.RollBack();
+                CustomWriteLog("宸ヨ壓鍙傛暟淇濆瓨:" + sql + e.Message, DateTime.Now.ToString("yyyy-MM-dd"));
+                return false;
+            }
+        }
+
         //鏉$爜瑙f瀽
-        public  bool SNHBardCodeList(string HBadCodeSN)
+        public int SNHBardCodeList(string HBadCodeSN)
         {
             try
             {
@@ -342,55 +614,52 @@
                         }
                         else
                         {
-                            CustomWriteLog("鏉$爜:"+ HBadCodeSN + ",娴佽浆鍗′笉瀛樺湪!", DateTime.Now.ToString("yyyy-MM-dd"));
-                            return false;
+                            oCN.RollBack();
+                            CustomWriteLog("鏉$爜:" + HBadCodeSN + ",娴佽浆鍗′笉瀛樺湪!", DateTime.Now.ToString("yyyy-MM-dd"));
+                            return 2;
                         }
                     }
-                    else {
+                    else
+                    {
+                        oCN.RollBack();
                         CustomWriteLog("鏉$爜:" + HBadCodeSN + ",闀垮害涓嶇瓑浜�29浣�!", DateTime.Now.ToString("yyyy-MM-dd"));
-                        return false;
+                        return 2;
                     }
                 }
                 else
                 {
-                    CustomWriteLog("鏉$爜:" + HBadCodeSN + ",鏉$爜宸插瓨鍦ㄦ暟鎹簱!", DateTime.Now.ToString("yyyy-MM-dd"));
-                    return false;
+                    return 1;
                 }
-                return true;
+                return 0;
             }
             catch (Exception e)
             {
+                oCN.RollBack();
                 CustomWriteLog("鏉$爜:" + HBadCodeSN + "," + e.Message, DateTime.Now.ToString("yyyy-MM-dd"));
-                return false;
+                return 2;
             }
         }
 
-        //淇濆瓨鏉$爜鏁版嵁
+        //鏂板鏉$爜鏁版嵁
         public void get_HBardBillSave(string HBarCode, string HProcExchBillNo)
         {
             try
             {
                 //鏌ヨ娴佽浆鍗℃暟鎹�
-                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
-left join Gy_Material m on a.HMaterID=m.HItemID
-left join Xt_ORGANIZATIONS o on a.HPRDORGID=o.HItemID
-left join Gy_Unit u on a.HUnitID=u.HItemID 
+                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");
 
-                string HMaterNumber = dataSet.Tables[0].Rows[0]["鐗╂枡浠g爜"].ToString();
-                string HOrgNumber = dataSet.Tables[0].Rows[0]["缁勭粐浠g爜"].ToString();
 
                 //鍒ゆ柇娴佽浆鍗′笉鑳戒负绌�
                 if (HBarCode.Trim() == "")
                 {
+                    oCN.RollBack();
                     CustomWriteLog("鏉$爜:" + HBarCode + ",娴佽浆鍗′笉鑳戒负绌�!", DateTime.Now.ToString("yyyy-MM-dd"));
-                    //objJsonResult.code = "0";
-                    //objJsonResult.count = 0;
-                    //objJsonResult.Message = "鏉″舰鐮佷笉鑳戒负绌猴紝涓嶈兘鐢熸垚鏉$爜锛�";
-                    //return objJsonResult;
                 }
-
-                oCN.BeginTran();
+              
                 //鏃ユ湡鑾峰彇鏂瑰紡
                 string sDate = DateTime.Now.ToString();
                 string HWei = "0";      //灏炬暟
@@ -426,7 +695,7 @@
                 bool HGiveAwayFlag = false;
                 Int64 HEntryID = 1;
                 string sExeReturnInfo = "";
-                Int64 HInterID =  CreateBillID_Prod("85", ref sExeReturnInfo);
+                Int64 HInterID = CreateBillID_Prod("85", ref sExeReturnInfo);
                 int HOrgID = int.Parse(dataSet.Tables[0].Rows[0]["HPRDORGID"].ToString());
                 string HCoilNO2 = "";
                 string HFurnaceNO2 = "";
@@ -454,12 +723,197 @@
                                    + ", " + BoolToString(HGiveAwayFlag)
                                    + ",'" + HMaterName + "','" + HMaterModel + "','" + HPinfan + "'," + HAuxPropID.ToString() + ",'" + HMTONo + "','" + HInnerBillNo + "','','')");
 
-                oCN.Commit();
             }
             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"));
+            }
+        }
+
+        //鏉$爜琛ュ厖
+        public string TM_ZH(string HBadCodeSN)
+        {
+            try
+            {
+                //HBadCodeSN = "P1" + HBadCodeSN;
+                //HBadCodeSN = HBadCodeSN.Substring(0, 13) + ":" + HBadCodeSN.Substring(13, 15);
+                return HBadCodeSN;
+            }
+            catch (Exception e)
+            {
+                CustomWriteLog("鏉$爜:" + HBadCodeSN + "," + e.Message, DateTime.Now.ToString("yyyy-MM-dd"));
+                return "";
+            }
+
+        }
+
+        //瀹氭椂璇诲彇鏁版嵁
+        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];
+
+            //寰幆闆嗗悎
+            for (int i = 0; i < list.Rows.Count; i++)
+            {
+                bool flag = false;
+                string HResult = list.Rows[i]["HResult"].ToString();
+                string HBadCodeSN = list.Rows[i]["HBarCode"].ToString();
+                //寮�濮嬩簨鍔�
+                oCN.BeginTran();
+
+                if (HResult == "OK")
+                {
+                    flag = HResultOK(list.Rows[i]);
+                }
+                else if (HResult == "NG")
+                {
+                    flag = HResultNG(list.Rows[i]);
+                }
+
+                if (flag)
+                {
+                    oCN.RunProc("update Sb_EquipMentCollection_SN set HFlag=1 where HBarCode='" + HBadCodeSN + "'");
+                    //缁撴潫浜嬪姟
+                    oCN.Commit();
+                }
+
+            }
+        }
+
+        //鏂板涓嶈壇姹囨姤鍗�
+        public bool getBadBillAdd(DataRow dic) {
+            try
+            {
+
+                //鏌ヨ鑱屽憳
+                DataSet ds = oCN.RunProcReturn("select * from Gy_Employee WITH(NOLOCK) where HNumber='" + dic["HEmpCode"].ToString() + "' ", "Gy_Employee");
+                long HEmpIDs = 0;
+                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();
+                }
+
+                long HDeptID = 0;//杞﹂棿
+                string sReturn = "";
+                if (GetSingleSystemParameter("WMS_CampanyName", ref sReturn) == "鏉窞鏂帿灏�")
+                {
+                    HDeptID = 389499;
+                }
+                else
+                {
+                    //ds = oCN.RunProcReturn("select * from Gy_Department where HNumber='" + dic["HDeptNumber"].ToString() + "' ", "Gy_Department");
+
+                    //if (ds.Tables[0].Rows.Count != 0)
+                    //{
+                    //    HDeptID = long.Parse(ds.Tables[0].Rows[0]["HItemID"].ToString());//鐢熶骇閮ㄩ棬
+                    //}
+                    HDeptID = 0;
+                }
+
+                string HProcExchInterID = "0";
+                string HProcExchEntryID = "0";
+                string HProcExchBillNo = "";
+                long HMaterID = 0;
+                long HUnitID = 0;
+                long HICMOInterID = 0;
+                long HICMOEntryID = 0;
+                string HICMOBillNo = "";
+                ds = oCN.RunProcReturn(@"select  HMaterID,HUnitID,a.HICMOInterID,a.HICMOEntryID,a.HICMOBillNo,HBillNo,a.HInterID,b.HEntryID,a.HBillNo 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 HBillNo=(select HSourceBillNo from Gy_BarCodeBill WITH(NOLOCK) where HBarCode='" + dic["HBarCode"].ToString() + "') and p.HNumber='" + dic["HProcNumber"].ToString() + "'  ", "Sc_ProcessExchangeBillMain");
+                if (ds.Tables[0].Rows.Count != 0)
+                {
+                    HMaterID = int.Parse(ds.Tables[0].Rows[0]["HMaterID"].ToString());
+                    HUnitID = int.Parse(ds.Tables[0].Rows[0]["HUnitID"].ToString());
+                    HICMOInterID = int.Parse(ds.Tables[0].Rows[0]["HICMOInterID"].ToString());
+                    HICMOEntryID = int.Parse(ds.Tables[0].Rows[0]["HICMOEntryID"].ToString());
+                    HICMOBillNo = ds.Tables[0].Rows[0]["HICMOBillNo"].ToString();
+                    HProcExchInterID = ds.Tables[0].Rows[0]["HInterID"].ToString();
+                    HProcExchEntryID = ds.Tables[0].Rows[0]["HEntryID"].ToString();
+                    HProcExchBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString();
+                }
+
+
+                ds = oCN.RunProcReturn("select * from Gy_Source WITH(NOLOCK) where HNumber='" + dic["HSourceCode"].ToString() + "' ", "Gy_Source");
+                long HSourceID = 0;
+                if (ds.Tables[0].Rows.Count != 0)
+                {
+                    HSourceID = long.Parse(ds.Tables[0].Rows[0]["HItemID"].ToString());//鐢熶骇璧勬簮ID
+                }
+
+                string sExeReturnInfo = "";
+                long HInterID = CreateBillID("3717", ref sExeReturnInfo);//閫掑叆type寰楀埌鐨勫崟鎹甀D
+                string HBillNo = CreateBillCode_Prod("3717", ref sExeReturnInfo, true);//閫掑叆type寰楀埌鐨勫崟鎹彿
+                DateTime HDate = DateTime.Parse(dic["HCreateTime"].ToString());//鏃ユ湡
+                string HRemark = "";//澶囨敞
+                long HEmpID = HEmpIDs;//璐ㄦ鍛�
+                long HGroupID = 22;//鐝粍ID 鐧界彮
+                string HMaker = HMakers;//鍒跺崟浜�
+                long HMainSourceInterID = HICMOInterID;
+                long HMainSourceEntryID = HICMOEntryID;
+                string HMainSourceBillNo = HICMOBillNo;
+
+                //涓昏〃
+                oCN.RunProc(@"Insert Into Sc_QualityReportBillMain   
+(HBillType,HBillSubType,HBillStatus,HInterID,HBillNo,HDate
+,HYear,HPeriod,HRemark,HMaker,HMakeDate
+,HEmpID,HGroupID,HDeptID,HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo)
+                        values('3717','3717',1," + HInterID + ",'" + HBillNo + "','" + HDate + "'" +
+                "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + HRemark + "','" + HMaker + "',getdate()" +
+                ",'" + HEmpID + "'," + HGroupID + "," + HDeptID + "," + HMainSourceInterID + "," + HMainSourceEntryID + ",'" + HMainSourceBillNo + "') ");
+
+                string HBarCode = dic["HBarCode"].ToString();
+                string HMakeDate = dic["HCreateTime"].ToString();
+                string HResult = dic["HResult"].ToString();
+                oCN.RunProc($@"Insert into Sc_QualityReportBillSub 
+(HInterID,HENTRYID,HBillNo_bak,HEmpID,HBarCode,HBadReasonID,HAddr,HMaker,HMakeDate
+,HMaterID,HUnitID,HRemark,HSourceID,HICMOInterID,HICMOEntryID,HICMOBillNo,HReportType
+,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney
+,HQty,HResult,HProcExchInterID,HProcExchEntryID,HProcExchBillNo) 
+values({HInterID},1,'{HBillNo}',{HEmpID},'{HBarCode}',0,'','{HMaker}','{HMakeDate}'
+,{HMaterID},{ HUnitID},'',{HSourceID},{ HICMOInterID},{ HICMOEntryID},'{HICMOBillNo}',0
+,0,0,'','',0,0
+,0,'{HResult}',{ HProcExchInterID},{ HProcExchEntryID},'{ HProcExchBillNo}')");
+
+                return true;
+            }
+            catch (Exception e)
+            {
+                oCN.RollBack();
+                CustomWriteLog("鎶ラ敊鍘熷洜:" + e.Message + "!", DateTime.Now.ToString("yyyy-MM-dd"));
+                return false;
+            }
+        }
+
+        #region 鍩虹鏂规硶
+
+        //鏌ヨ绯荤粺鍙傛暟
+        public string GetSingleSystemParameter(string sKey, ref string sReturn)
+        {
+            try
+            {
+                //鏌ヨ涓昏〃
+                DataSet DsSub;
+                //寰幆 
+                DsSub = oCN.RunProcReturn("Select  HValue from Xt_SystemParameter with(nolock) Where HKey='" + sKey + "'  ", "Xt_SystemParameter");
+                if (DsSub == null || DsSub.Tables[0].Rows.Count == 0)
+                {
+                    sReturn = "鎵句笉鍒拌鍙傛暟!";
+                    return "";
+                }
+                else
+                {
+                    return isStrNull(DsSub.Tables[0].Rows[0]["HValue"]);
+                }
+            }
+            catch (Exception e)
+            {
+                sReturn = e.Message;
+                throw (e);
             }
         }
 
@@ -491,23 +945,6 @@
                 return -2;
             }
         }
-
-        //鏉$爜琛ュ厖
-        public string TM_ZH(string HBadCodeSN) {
-            try
-            {
-                //HBadCodeSN = "P1" + HBadCodeSN;
-                //HBadCodeSN = HBadCodeSN.Substring(0, 13) + ":" + HBadCodeSN.Substring(13, 15);
-                return HBadCodeSN;
-            }
-            catch (Exception e)
-            {
-                CustomWriteLog("鏉$爜:" + HBadCodeSN + "," + e.Message, DateTime.Now.ToString("yyyy-MM-dd"));
-                return "";
-            }
-      
-        }
-
         //鍒ゆ柇鏄惁鏄疘NT64
         public static Int64 isLong(object message)
         {
@@ -658,79 +1095,6 @@
             {
             }
         }
-
-        //瀹氭椂璇诲彇鏁版嵁
-        private void timer1_Tick(object sender, EventArgs e)
-        {
-            int year = DateTime.Now.Year;
-            string month = DateTime.Now.Month.ToString();
-            string day = DateTime.Now.Day.ToString();
-
-
-            //if (month.Length < 2) {
-            //    month = "0" + month;
-            //}
-            //if (day.Length < 2)
-            //{
-            //    day = "0" + day;
-            //}
-
-            string dataTime = DateTime.Now.ToString("yyyyMMdd");
-            //CustomWriteLog("1:" + dataTime, DateTime.Now.ToString("yyyy-MM-dd"));
-            ////鍒ゆ柇鏄惁鏈夎繖涓枃浠�
-            bool flag = File.Exists($@"D:\{year}\{month}\{day}\{dataTime}.txt");
-            //bool flag = File.Exists($@"C:\Users\admin\Desktop\鏂板缓鏂囦欢澶� (2)\20231123.txt");
-            //CustomWriteLog("2:" + flag, DateTime.Now.ToString("yyyy-MM-dd"));
-            if (flag)
-            {
-                StreamReader stream = new StreamReader($@"D:\{year}\{month}\{day}\{dataTime}.txt", Encoding.GetEncoding("gb2312"));
-                //CustomWriteLog("3:"+ $@"D:\{year}\{month}\{day}\{dataTime}.txt", DateTime.Now.ToString("yyyy-MM-dd"));
-                //StreamReader stream = new StreamReader($@"C:\Users\admin\Desktop\鏂板缓鏂囦欢澶� (2)\20231123.txt",Encoding.GetEncoding("gb2312"));
-                string FileData = stream.ReadToEnd();
-                stream.Close();
-                FileData = FileData.Substring(0, FileData.Length - 1);
-                FileData = "[" + FileData + "]";
-                //CustomWriteLog("4:" + FileData, DateTime.Now.ToString("yyyy-MM-dd"));
-                //JSON搴忓垪鍖栬浆鎹㈠瓧鍏搁泦鍚�
-                List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
-                List<object> DataList = JsonConvert.DeserializeObject<List<object>>(FileData);
-                foreach (JObject item in DataList)
-                {
-                    Dictionary<string, string> dic = new Dictionary<string, string>();
-                    foreach (var itm in item.Properties())
-                    {
-                        dic.Add(itm.Name, itm.Value.ToString());
-                    }
-                    list.Add(dic);
-                }
-                //CustomWriteLog("5:" + list.Count, DateTime.Now.ToString("yyyy-MM-dd"));
-                //鑾峰彇褰撳墠鏃堕棿
-                DateTime ActionTime = DateTime.Parse(DateTime.Now.AddMinutes(-1).ToString("yyyy-MM-dd  HH:mm:ss"));
-                DateTime EndTime = DateTime.Parse(DateTime.Now.AddMinutes(1).ToString("yyyy-MM-dd  HH:mm:00"));
-                //寰幆闆嗗悎
-                for (int i = 0; i < list.Count; i++)
-                {
-                    DateTime NowTime = DateTime.Parse(list[i]["HDate"].ToString());
-                    if (NowTime >= ActionTime && NowTime < EndTime)
-                    {
-                        string HResult = list[i]["HResult"].ToString();
-
-                        //CustomWriteLog("6:" + HResult, DateTime.Now.ToString("yyyy-MM-dd"));
-                        if (HResult == "OK")
-                        {
-                            HResultOK(list[i]);
-                        }
-                        else if (HResult == "NG")
-                        {
-                            HResultNG(list[i]);
-                        }
-                    }
-                    else
-                    {
-                        //CustomWriteLog("鏃堕棿涓嶅湪淇濆瓨鑼冨洿鍐�", DateTime.Now.ToString("yyyy-MM-dd"));
-                    }
-                }
-            }
-        }
+        #endregion
     }
 }

--
Gitblit v1.9.1