zrg
2025-05-22 cd7a1182c004bfcc705f28b0a306a9855f3af059
WFormSynchronizeData_SMR/WFormReadData_SMR/ReadCSV.cs
@@ -37,14 +37,14 @@
        {
            try
            {
                DataSet ds = oCN.RunProcReturn("select  * from Sc_ProcessExchangeBillMain where HBillNo='" + HBillNo + "' ", "Sc_ProcessExchangeBillMain");
                DataSet ds = oCN.RunProcReturn("select  HProjectNum from Sc_ProcessExchangeBillMain  WITH(NOLOCK) where HBillNo='" + HBillNo + "' ", "Sc_ProcessExchangeBillMain");
                if (ds.Tables[0].Rows.Count == 0)
                {
                    MessageBox.Show("查无数据!");
                }
                else
                {
                    DataSet dataSet= oCN.RunProcReturn("select  * from Sc_ICMOBillStatus_Tmp where HSourceBillNo='" + HBillNo + "' and HICMOStatus<>'0'", "Sc_ICMOBillStatus_Tmp");
                    DataSet dataSet = oCN.RunProcReturn("select HICMOStatus  HICMOStatus from Sc_ICMOBillStatus_Tmp  WITH(NOLOCK) where HSourceBillNo='" + HBillNo + "' and HICMOStatus<>'0'", "Sc_ICMOBillStatus_Tmp");
                    if (dataSet.Tables[0].Rows.Count > 0)
                    {
                        string HProjectNum = ds.Tables[0].Rows[0]["HProjectNum"].ToString();
@@ -52,7 +52,8 @@
                        this.txtHBardCode.ReadOnly = true;
                        list.Clear();
                    }
                    else {
                    else
                    {
                        MessageBox.Show(HBillNo + ",流转卡未开工!");
                    }
                }
@@ -85,7 +86,7 @@
        {
            try
            {
                DataSet ds = oCN.RunProcReturn("select  * from Gy_Employee where HNumber='" + HNumber + "' ", "Gy_Employee");
                DataSet ds = oCN.RunProcReturn("select  HName,HNumber from Gy_Employee  WITH(NOLOCK) where HNumber='" + HNumber + "' ", "Gy_Employee");
                if (ds.Tables[0].Rows.Count == 0)
                {
                    MessageBox.Show("查无数据!");
@@ -123,12 +124,13 @@
        private void btnReadData_Click(object sender, EventArgs e)
        {
            if (this.HEmpCode.Text == "" || this.txtHBath.Text == ""|| this.HSouceName.Text == "")
            if (this.HEmpCode.Text == "" || this.txtHBath.Text == "" || this.HSouceName.Text == "")
            {
                MessageBox.Show("请输入生产资源,员工编码,者条形码!");
            }
            else {
            else
            {
                if (num == 0)
                {
                    this.btnReadData.Text = "暂停";
@@ -151,7 +153,7 @@
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (this.HEmpCode.Text == ""|| this.txtHBath.Text == "")
            if (this.HEmpCode.Text == "" || this.txtHBath.Text == "")
            {
                MessageBox.Show("请输入员工编码或者流转卡!");
            }
@@ -204,7 +206,7 @@
                File.Copy(csv_file_path, csv_file_path_Read, true);
                string contents = File.ReadAllText(csv_file_path_Read, Encoding.GetEncoding("gb2312"));
                TextFieldParser parser = new TextFieldParser(new StringReader(contents));
                parser.HasFieldsEnclosedInQuotes = true;
@@ -242,7 +244,7 @@
                        DateTime NowTime = DateTime.Parse(item["测试时间"].ToString());
                        string HBadCodeSN = item["序号"].ToString();
                        if (((NowTime >= ActionTime && NowTime < EndTime) || dt.Rows.Count <= 20) && HBadCodeSN != "" && list.Contains(HBadCodeSN)==false)
                        if (((NowTime >= ActionTime && NowTime < EndTime) || dt.Rows.Count <= 20) && HBadCodeSN != "" && list.Contains(HBadCodeSN) == false)
                        {
                            string HSourceCode = this.HSouce.Text; //设备编号 组装1 9994 组装2 9995 组装3 9996
@@ -264,10 +266,10 @@
                                if (true)
                                {
                                    if (Get_AllowLoadData(HBarCode, HProcNumber, flag_1,out flag_2))
                                    if (Get_AllowLoadData(HBarCode, HProcNumber, flag_1, out flag_2))
                                    {
                                        string sql = $@"insert into Sb_EquipMentCollection_SN(HSourceCode,HEmpCode,HType,HBarCode,HCount,HCreateTime,HDate,HResult,HProcNumber,HFlag)
                    values('{HSourceCode}','{HEmpCode}','{HType}','{HBarCode}','{HCount}','{HCreateTime}','{HDate}','{HResult}','{HProcNumber}','{HFlag}')";
                                        values('{HSourceCode}','{HEmpCode}','{HType}','{HBarCode}','{HCount}','{HCreateTime}',GETDATE(),'{HResult}','{HProcNumber}','{HFlag}')";
                                        oCN.RunProc(sql);
                                        ListSelect.Items.Add("条码:" + HBarCode + ",当前日期:" + DateTime.Now.ToString() + ",日期:" + HCreateTime + ",结果:" + HResult);
                                        list.Add(HBarCode);
@@ -281,19 +283,20 @@
                                                string HCount_1 = item[HType].ToString();
                                                //查询当天条码 对应的工艺参数有没有插入到里面 如果没有则新增
                                                DataSet ds1 = oCN.RunProcReturn(@"select * from Sb_EquipMentCollectionTechParam_SN where HBarCode='" + HBarCode + "' and HType='" + HType + "'", "Sb_EquipMentCollectionTechParam_SN");
                                                DataSet ds1 = oCN.RunProcReturn(@"select HBarCode from Sb_EquipMentCollectionTechParam_SN  WITH(NOLOCK)  where HBarCode='" + HBarCode + "' and HType='" + HType + "'", "Sb_EquipMentCollectionTechParam_SN");
                                                if (ds1.Tables[0].Rows.Count == 0)
                                                {
                                                    string sql1 = $@"insert into Sb_EquipMentCollectionTechParam_SN(HSourceCode,HEmpCode,HType,HBarCode,HCount,HCreateTime,HDate,HResult,HProcNumber,HFlag)
values('{HSourceCode}','{HEmpCode}','{HType}','{HBarCode}','{HCount_1}','{HCreateTime}','{HDate}','{HResult}','{HProcNumber}','{HFlag}')";
                                                    values('{HSourceCode}','{HEmpCode}','{HType}','{HBarCode}','{HCount_1}','{HCreateTime}',GETDATE(),'{HResult}','{HProcNumber}','{HFlag}')";
                                                    oCN.RunProc(sql1);
                                                    //ListSelect.Items.Add("条码:" + HBarCode + ",日期:" + HCreateTime + ",结果:" + HResult);
                                                }
                                            }
                                        }
                                    }
                                    else {
                                    else
                                    {
                                        flag_1 = flag_2;
                                    }
                                }
@@ -318,13 +321,14 @@
                            string HProcNumber = "005";
                            int HFlag = 0;
                            if (HResult != "") {
                            if (HResult != "")
                            {
                                if (HBadCodeSN != "")
                                {
                                    string HType = "";
                                    int HCount = 1;
                                    DataSet ds = oCN.RunProcReturn(@"select * from Sb_EquipMentCollection_SN where HBarCode='" + HBarCode + "' and HCreateTime='" + HCreateTime + "'", "Sb_EquipMentCollection_SN");
                                    DataSet ds = oCN.RunProcReturn(@"select HBarCode from Sb_EquipMentCollectionTechParam_SN  WITH(NOLOCK)  where HBarCode='" + HBarCode + "' and HCreateTime='" + HCreateTime + "'", "Sb_EquipMentCollection_SN");
                                    if (ds.Tables[0].Rows.Count == 0)
@@ -332,7 +336,7 @@
                                        if (Get_AllowLoadData(HBarCode, HProcNumber, flag_1, out flag_2))
                                        {
                                            string sql = $@"insert into Sb_EquipMentCollection_SN(HSourceCode,HEmpCode,HType,HBarCode,HCount,HCreateTime,HDate,HResult,HProcNumber,HFlag)
                    values('{HSourceCode}','{HEmpCode}','{HType}','{HBarCode}','{HCount}','{HCreateTime}','{HDate}','{HResult}','{HProcNumber}','{HFlag}')";
                                            values('{HSourceCode}','{HEmpCode}','{HType}','{HBarCode}','{HCount}','{HCreateTime}',GETDATE(),'{HResult}','{HProcNumber}','{HFlag}')";
                                            oCN.RunProc(sql);
                                            ListSelect.Items.Add("条码:" + HBarCode + ",日期:" + HCreateTime + ",结果:" + HResult);
@@ -352,12 +356,12 @@
                                                            HCount_1 = "0";
                                                        }
                                                        DataSet ds1 = oCN.RunProcReturn(@"select * from Sb_EquipMentCollectionTechParam_SN where HBarCode='" + HBarCode + "' and HType='" + HType + "'", "Sb_EquipMentCollectionTechParam_SN");
                                                        DataSet ds1 = oCN.RunProcReturn(@"select HBarCode from Sb_EquipMentCollectionTechParam_SN  WITH(NOLOCK)  where HBarCode='" + HBarCode + "' and HType='" + HType + "'", "Sb_EquipMentCollectionTechParam_SN");
                                                        if (ds1.Tables[0].Rows.Count == 0)
                                                        {
                                                            string sql1 = $@"insert into Sb_EquipMentCollectionTechParam_SN(HSourceCode,HEmpCode,HType,HBarCode,HCount,HCreateTime,HDate,HResult,HProcNumber,HFlag)
values('{HSourceCode}','{HEmpCode}','{HType}','{HBarCode}','{(HCount_1 == "" ? " 0" : HCount_1)}','{HCreateTime}','{HDate}','{HResult_TechParam}','{HProcNumber}','{HFlag}')";
                                                            values('{HSourceCode}','{HEmpCode}','{HType}','{HBarCode}','{(HCount_1 == "" ? " 0" : HCount_1)}','{HCreateTime}',GETDATE(),'{HResult_TechParam}','{HProcNumber}','{HFlag}')";
                                                            oCN.RunProc(sql1);
                                                            //ListSelect.Items.Add("条码:" + HBarCode + ",日期:" + HCreateTime + ",结果:" + HResult);
                                                        }
@@ -386,7 +390,7 @@
        public static string AllHProName = "";
        public static double AllHQty = 0;
        //根据条码 判断是否保存
        public bool Get_AllowLoadData(string HBarCode,string HProcNumber,bool flag_1,out bool flag_2)
        public bool Get_AllowLoadData(string HBarCode, string HProcNumber, bool flag_1, out bool flag_2)
        {
            decimal hqty = 2;
            if (HBarCode.Length != 29 && HBarCode.Length != 50)
@@ -402,8 +406,9 @@
            {
                string str1 = HBarCode.Substring(18, 8);
                //string str2 = HBarCode.Substring(23, 3);
                if (AllProcessExchange != str1) {
                    DataSet ds = oCN.RunProcReturn("select  HInterID,HBillNo from Sc_ProcessExchangeBillMain where HProjectNum like'" + str1 + "-1%' order by HMakeDate desc", "Sc_ProcessExchangeBillMain");
                if (AllProcessExchange != str1)
                {
                    DataSet ds = oCN.RunProcReturn("select  HInterID,HBillNo from Sc_ProcessExchangeBillMain WITH(NOLOCK)  where HProjectNum like'" + str1 + "-1%' order by HMakeDate desc", "Sc_ProcessExchangeBillMain");
                    //判断是否能找到对应的流转卡
                    if (ds.Tables[0].Rows.Count > 0)
                    {
@@ -430,13 +435,14 @@
            else if (HBarCode.Length == 50)
            {
                string str1 = HBarCode.Substring(42, 8);
                DataSet ds = oCN.RunProcReturn("select  HBillNo from Sc_ProcessExchangeBillMain where HProjectNum like'" + str1 + "-1%'", "Sc_ProcessExchangeBillMain");
                DataSet ds = oCN.RunProcReturn("select  HBillNo from Sc_ProcessExchangeBillMain WITH(NOLOCK)  where HProjectNum like'" + str1 + "-1%'", "Sc_ProcessExchangeBillMain");
                //判断是否能找到对应的流转卡
                if (ds.Tables[0].Rows.Count > 0)
                {
                    AllProcessExchangeHProcExchBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString();
                }
                else {
                else
                {
                    //flag_1=只有第一次进来才会弹出 错误信息弹出框 定时超过2分钟弹一次
                    if (!flag_1 && (DateTime.Now - time).Minutes > hqty)
                    {
@@ -444,7 +450,7 @@
                        MessageBox.Show("条码:" + HBarCode + ",流转卡不存在!");
                    }
                    DBHelper.CustomWriteLog("条码:" + HBarCode + ",流转卡不存在!", DateTime.Now.ToString("yyyy-MM-dd"));
                    flag_2 = true;
                    return false;
                }
@@ -457,9 +463,10 @@
            DataSet ds1;
            //第一次流转卡+工序和后面的做对比 如果是同一个流转卡就不进行判断
            if ((HProcExchBillNo + HProcNumber) != AllSNBarcodeProcCtrl) {
            if ((HProcExchBillNo + HProcNumber) != AllSNBarcodeProcCtrl)
            {
                //查询工序
                ds1 = oCN.RunProcReturn(@"SELECT  HItemID,HName FROM Gy_Process WHERE HNumber='" + HProcNumber + "'", "Gy_Process");
                ds1 = oCN.RunProcReturn(@"SELECT  HItemID,HName FROM Gy_Process WITH(NOLOCK)  WHERE HNumber='" + HProcNumber + "'", "Gy_Process");
                if (ds1.Tables[0].Rows.Count > 0)
                {
                    AllHProcID = ds1.Tables[0].Rows[0]["HItemID"].ToString();
@@ -467,7 +474,7 @@
                }
                //查询流转卡数量
                ds1 = oCN.RunProcReturn(@"SELECT  HQty FROM Sc_ProcessExchangeBillSub  where HInterID=" + HProcExchInterID + " and HProcID=" + AllHProcID, "Sc_ProcessExchangeBillSub");
                ds1 = oCN.RunProcReturn(@"SELECT  HQty FROM Sc_ProcessExchangeBillSub WITH(NOLOCK)   where HInterID=" + HProcExchInterID + " and HProcID=" + AllHProcID, "Sc_ProcessExchangeBillSub");
                if (ds1.Tables[0].Rows.Count > 0)
                {
                    AllHQty = double.Parse(ds1.Tables[0].Rows[0]["HQty"].ToString());
@@ -475,47 +482,47 @@
                AllSNBarcodeProcCtrl = HProcExchBillNo + HProcNumber;
            }
            string HProcID = AllHProcID;
            string HProName = AllHProName;
            ////第一次流转卡+工序和后面的做对比 如果是同一个流转卡就不进行判断
            //if ((HProcExchBillNo + HProcNumber) == AllSNBarcodeProcCtrl)
            //{
                //判断 当前工序 条码 的上一道工序有没有过站
                ds1 = oCN.RunProcReturn("exec h_p_Sc_SNBarcodeProcCtrl_S '" + HBarCode + "'," + HProcID, "h_v_Gy_QualifiedRecordsList");
            //判断 当前工序 条码 的上一道工序有没有过站
            ds1 = oCN.RunProcReturn("exec h_p_Sc_SNBarcodeProcCtrl_S '" + HBarCode + "'," + HProcID, "h_p_Sc_SNBarcodeProcCtrl_S");
                if (ds1.Tables[0].Rows.Count == 0)
            if (ds1.Tables[0].Rows.Count == 0)
            {
                //flag_1=只有第一次进来才会弹出 错误信息弹出框 定时超过2分钟弹一次
                if (!flag_1 && (DateTime.Now - time).Minutes > hqty)
                {
                    //flag_1=只有第一次进来才会弹出 错误信息弹出框 定时超过2分钟弹一次
                    if (!flag_1 && (DateTime.Now - time).Minutes > hqty)
                    {
                        time = DateTime.Now;
                        MessageBox.Show("条码:" + HBarCode + "工序:" + HProName + ",工序控制查无数据!");
                    }
                    DBHelper.CustomWriteLog("条码:" + HBarCode + "工序:" + HProName + ",工序控制查无数据!", DateTime.Now.ToString("yyyy-MM-dd"));
                    flag_2 = true;
                    return false;
                    time = DateTime.Now;
                    MessageBox.Show("条码:" + HBarCode + "工序:" + HProName + ",工序控制查无数据!");
                }
                else if (ds1.Tables[0].Rows[0]["HBack"].ToString() == "2")
                DBHelper.CustomWriteLog("条码:" + HBarCode + "工序:" + HProName + ",工序控制查无数据!", DateTime.Now.ToString("yyyy-MM-dd"));
                flag_2 = true;
                return false;
            }
            else if (ds1.Tables[0].Rows[0]["HBack"].ToString() == "2")
            {
                //flag_1=只有第一次进来才会弹出 错误信息弹出框 定时超过2分钟弹一次
                if (!flag_1 && (DateTime.Now - time).Minutes > hqty)
                {
                    //flag_1=只有第一次进来才会弹出 错误信息弹出框 定时超过2分钟弹一次
                    if (!flag_1 && (DateTime.Now - time).Minutes > hqty)
                    {
                        time = DateTime.Now;
                        MessageBox.Show("条码:" + HBarCode + "工序:" + HProcID + "," + ds1.Tables[0].Rows[0]["HBackRemark"].ToString() + "!");
                    }
                    DBHelper.CustomWriteLog("条码:" + HBarCode + "工序:" + HProcID + "," + ds1.Tables[0].Rows[0]["HBackRemark"].ToString() + "!", DateTime.Now.ToString("yyyy-MM-dd"));
                    flag_2 = true;
                    return false;
                    time = DateTime.Now;
                    MessageBox.Show("条码:" + HBarCode + "工序:" + HProcID + "," + ds1.Tables[0].Rows[0]["HBackRemark"].ToString() + "!");
                }
                DBHelper.CustomWriteLog("条码:" + HBarCode + "工序:" + HProcID + "," + ds1.Tables[0].Rows[0]["HBackRemark"].ToString() + "!", DateTime.Now.ToString("yyyy-MM-dd"));
                flag_2 = true;
                return false;
            }
            //}
            //查询出站数量是否超过流转卡数量
            ds1 = oCN.RunProcReturn($@"select ({AllHQty}-sum(isnull(ou.HQty,0))-sum(isnull(ou.HBadCount,0))) HQty from Sc_StationOutBillMain ou WITH(NOLOCK)
where ou.HProcExchInterID={HProcExchInterID} and ou.HProcID={AllHProcID}
group by  ou.HProcExchInterID,ou.HProcExchEntryID,ou.HQty", "Sc_StationOutBillMain");
                                    where ou.HProcExchInterID={HProcExchInterID} and ou.HProcID={AllHProcID}
                                    group by  ou.HProcExchInterID,ou.HProcExchEntryID,ou.HQty", "Sc_StationOutBillMain");
            //获取流转卡数量
            double hqtyOut = AllHQty;
@@ -541,7 +548,8 @@
            }
            //拍照工序除外
            if (HProcNumber != "013") {
            if (HProcNumber != "013")
            {
                //增加产线组装追溯单
                //查询当前流转卡对应的工序有没有配件信息,如果有 则判断配件单的数量是否为0
                DataSet dataSet = oCN.RunProcReturn("exec h_p_Gy_BarCodeBillBomList '" + HProcExchBillNo + "'," + HProcID, "h_p_Gy_BarCodeBillBomList");
@@ -568,7 +576,7 @@
                    }
                }
            }
            flag_2 = false;
            return true;
        }
@@ -587,7 +595,7 @@
        {
            try
            {
                DataSet ds = oCN.RunProcReturn("select  * from Gy_Source where HNumber='" + HNumber + "' ", "Gy_Source");
                DataSet ds = oCN.RunProcReturn("select HName,HNumber from Gy_Source  WITH(NOLOCK) where HNumber='" + HNumber + "' ", "Gy_Source");
                if (ds.Tables[0].Rows.Count == 0)
                {
                    MessageBox.Show("查无数据!");