yangle
2023-12-29 a71757967fbaf9d300c81e7502ff455d4a482564
WFormSynchronizeData_SMR/WFormSynchronizeData_SMR/Form1.cs
@@ -24,8 +24,8 @@
        //读取数据
        private void btnReadData_Click(object sender, EventArgs e)
        {
            DataTable list = oCN.RunProcReturn("select  * from Sb_EquipMentCollection_SN where HFlag=0 order by HCreateTime", "Sb_EquipMentCollection_SN").Tables[0];
            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++)
@@ -70,15 +70,29 @@
                else if (num == 1)
                {
                    //判断这个条码之前的状态是否为NG
                    DataSet ds = oCN.RunProcReturn(@"select * from Sb_EquipMentCollection_SN where HBarCode='" + HBadCodeSN + "' and HCreateTime<'" + dic["HCreateTime"].ToString() + "' and HResult='NG'", "Gy_BarCodeBill");
                    if (ds.Tables[0].Rows.Count > 0)
                    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
                    {
                        flag = false;
                        oCN.RollBack();
                        if (ds1.Tables[0].Rows.Count > 0)
                        {
                            flag = true;
                            //oCN.RollBack();
                        }
                        else
                        {
                            flag = getOutBillAdd(dic, HBadCodeSN, "OK");
                        }
                    }
                }
                else if (num == 2)
@@ -148,11 +162,11 @@
            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["HSourceCode"].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)
                {
@@ -160,7 +174,7 @@
                }
                //查询职员
                ds = oCN.RunProcReturn("select * from Gy_Employee where HNumber='" + dic["HEmpCode"].ToString() + "' ", "Gy_Employee");
                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)
                {
@@ -187,9 +201,9 @@
             
                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
                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 = "";
@@ -226,7 +240,7 @@
                long HGroupID = 22;//班组ID 白班
                long HEmpID = HEmpIDs;//操作员ID
                long HEmpID2 = 0;////操作员2ID
                long HEmpID2 = HEmpIDs;////操作员2ID
                string HBarCode = HProcExchBillNo;//条形码
                string HAddr = "";
                string HBarCodeMaker = "";
@@ -262,8 +276,8 @@
                //判断当前流转卡的出站单 是否有数据
                ds = oCN.RunProcReturn(@"select  * from Sc_StationOutBillMain a
left join Gy_Process p on  a.HProcID=p.HItemID
                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)
@@ -303,19 +317,19 @@
                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, '"+ HMakeTime + "', '', " + HProcExchInterID + "," + HProcExchEntryID + ", '" + HProcExchBillNo + "', '', 0, 0)");
                    //反写工序出站单的合格数量
                    oCN.RunProc("update Sc_StationOutBillMain set HQty+=1  where HInterID='" + HInterID + "'");
                    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 + "'");
                    oCN.RunProc("update Sc_StationOutBillMain  set HBadCount+=1 where HInterID='" + HInterID + "'");
                }
                else
                {
@@ -353,7 +367,7 @@
                    //查询职员
                    ds = oCN.RunProcReturn("select * from Gy_Employee where HNumber='" + dic["HEmpCode"].ToString() + "' ", "Gy_Employee");
                    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)
                    {
@@ -404,11 +418,11 @@
            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["HSourceCode"].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)
                {
@@ -416,7 +430,7 @@
                }
                //查询职员
                ds = oCN.RunProcReturn("select * from Gy_Employee where HNumber='" + dic["HEmpCode"].ToString() + "' ", "Gy_Employee");
                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)
                {
@@ -443,9 +457,9 @@
                }
                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
                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());//任务单ID
@@ -458,12 +472,12 @@
                long HInterID = 0;
                string HBillNo = "";
                ds = oCN.RunProcReturn("select  * from Sc_AssemblyBillMain where HMainSourceInterID=" + HProcExchInterID + " and HMainSourceEntryID=" + HProcExchEntryID, "Sc_AssemblyBillMain");
                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 where HProcExchInterID=" + HProcExchInterID + " and HProcExchEntryID=" + HProcExchEntryID, "Sc_AssemblyBillMain");
                    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 {
@@ -471,9 +485,9 @@
                }
                //查询是否有返修记录
                ds = oCN.RunProcReturn(@"select a.HBarCode,a.HProcess,b.HSourceInterID,b.HSourceEntryID,b.HRepairResult from Sc_SourceLineRepairBillMain a
inner join Sc_SourceLineRepairBillSub b on a.HInterID = b.HInterID
where a.HBarCode = '"+ HBadCodeSN + "' and  a.HProcess ="+ HProcID + " and  b.HSourceInterID ="+ HProcExchInterID + " " +
                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)
@@ -484,8 +498,8 @@
                }
                //判断当前流转卡的出站单 是否有数据
                ds = oCN.RunProcReturn(@"select  * from Sc_StationOutBillMain a
left join Gy_Process p on  a.HProcID=p.HItemID
                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)
@@ -496,7 +510,7 @@
                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)
@@ -530,14 +544,14 @@
            {
                DataSet ds = oCN.RunProcReturn("select  * from Sc_StationOutBillMain where HInterID=" + HInterID + " and HBillNo='" + HBillNo + "'", "Sc_StationOutBillMain");
                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
left join Gy_Source s on a.HSourceCode=s.HNumber
left join Gy_TechnologyParameter t on a.HType=t.HName
                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
where a.HFlag=0 and a.HBarCode='" + HBadCodeSN + "'", "Sb_EquipMentCollectionTechParam_SN");
                if (ds.Tables[0].Rows.Count != 0) {
@@ -549,7 +563,7 @@
                        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 where HInterID=" + HInterID + " and HBillNo_bak='" + HBillNo + "' and HBarCode='" + HBadCodeSN + "'", "Sc_StationOutBillSub_TechParam");
                        DataSet dataSet = oCN.RunProcReturn("select * from Sc_StationOutBillSub_TechParam WITH(NOLOCK) where HInterID=" + HInterID + " and HBillNo_bak='" + HBillNo + "' and HBarCode='" + HBadCodeSN + "'", "Sc_StationOutBillSub_TechParam");
                        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})");
@@ -621,10 +635,10 @@
            try
            {
                //查询流转卡数据
                DataSet dataSet = oCN.RunProcReturn(@"select  a.HPRDORGID, m.HModel 物料规格,m.HName 名物料称,a.HBillNo,a.HInterID,a.HMaterID,m.HNumber 物料代码,o.HNumber 组织代码,a.HUnitID,u.HNumber 单位代码 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 物料代码,o.HNumber 组织代码,a.HUnitID,u.HNumber 单位代码 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");
@@ -726,7 +740,7 @@
        //定时读取数据
        private void timer1_Tick(object sender, EventArgs e)
        {
            DataTable list = oCN.RunProcReturn("select  * from Sb_EquipMentCollection_SN where HFlag=0", "Sb_EquipMentCollection_SN").Tables[0];
            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++)
@@ -762,7 +776,7 @@
            {
                //查询职员
                DataSet ds = oCN.RunProcReturn("select * from Gy_Employee where HNumber='" + dic["HEmpCode"].ToString() + "' ", "Gy_Employee");
                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)
@@ -796,10 +810,10 @@
                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
inner join Sc_ProcessExchangeBillSub b on a.HInterID=b.HInterID
left join Gy_Process p on b.HProcID=p.HItemID
where HBillNo=(select HSourceBillNo from Gy_BarCodeBill where HBarCode='" + dic["HBarCode"].ToString() + "') and p.HNumber='" + dic["HProcNumber"].ToString() + "'  ", "Sc_ProcessExchangeBillMain");
                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());
@@ -813,7 +827,7 @@
                }
                ds = oCN.RunProcReturn("select * from Gy_Source where HNumber='" + dic["HSourceCode"].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)
                {
@@ -840,7 +854,6 @@
                        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();