1
yangle
2024-07-09 a239a07d5ba48791a20af5d1b4473c61c62eb95e
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();
                }
@@ -267,6 +268,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)
@@ -316,6 +331,7 @@
                    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 + "'");
                }
@@ -328,6 +344,19 @@
                {
                    oCN.RollBack();
                    CustomWriteLog("结果不为OK或NG!", 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;
                }
@@ -352,9 +381,10 @@
                    {
                        double SYHQty = double.Parse(dataSet.Tables[0].Rows[i]["配件数量"].ToString());
                        string HMaterNamePJ = dataSet.Tables[0].Rows[i]["配件代码"].ToString();
                        string HMaterBarCode = dataSet.Tables[0].Rows[i]["HBarCode"].ToString();
                        if (SYHQty == 0) {
                            oCN.RollBack();
                            CustomWriteLog("配件代码:" + HMaterNamePJ + ",数量为0!", DateTime.Now.ToString("yyyy-MM-dd"));
                            CustomWriteLog("配件条码:"+ HMaterBarCode + ",配件代码:" + HMaterNamePJ + ",数量为0!", DateTime.Now.ToString("yyyy-MM-dd"));
                            return false;
                        }
                    }
@@ -466,6 +496,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;
                //当产品没有配件的时候 查询 不良记录
@@ -510,6 +554,8 @@
                    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 + "'");
                    //反写条码状态
@@ -543,30 +589,34 @@
                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)
                string HProcID = ds.Tables[0].Rows[0]["HProcID"].ToString();
                //注:因为 组装 拍照 时间间隔比较短  所以目前只明确组装工序才可以保存工艺参数 之后如果有其他工序的话  需要增加工序字段
                if (HProcID == "88") {
                    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++)
                    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 + "'", "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();
                        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})";
                            DataSet dataSet = oCN.RunProcReturn("select * from Sc_StationOutBillSub_TechParam WITH(NOLOCK) where HInterID=" + HInterID + " and HBillNo_bak='" + HBillNo + "'", "Sc_StationOutBillSub_TechParam");
                        oCN.RunProc(sql);
                            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 + "'");
                    }
                    oCN.RunProc("update Sb_EquipMentCollectionTechParam_SN set HFlag=1 where HBarCode='" + HBadCodeSN + "'");
                }
                return true;
@@ -746,6 +796,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();
@@ -760,7 +811,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();
                }
@@ -1083,5 +1134,13 @@
            }
        }
        #endregion
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("确定要关闭吗?", "确认", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                e.Cancel = true;
            }
        }
    }
}