yangle
2025-04-07 0d59b3fd8050b0f0766be47ed5527d96bd4bf2f7
WFormSynchronizeData_SMR/WFormReadData_SMR/ReadCSV.cs
@@ -22,8 +22,7 @@
            InitializeComponent();
        }
        public static int num = 0;
        public static DateTime time = DateTime.Now.AddMinutes(-5);
        //更换条形码
        private void btnGH_Click(object sender, EventArgs e)
@@ -45,12 +44,13 @@
                }
                else
                {
                    DataSet dataSet= oCN.RunProcReturn("select  * from Sc_ICMOBillStatus_Tmp where HSourceBillNo='" + HBillNo + "' and HICMOStatus='1'", "Sc_ICMOBillStatus_Tmp");
                    DataSet dataSet= oCN.RunProcReturn("select  * from Sc_ICMOBillStatus_Tmp 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();
                        this.txtHBath.Text = HProjectNum.Split('-')[0];
                        this.txtHBardCode.ReadOnly = true;
                        list.Clear();
                    }
                    else {
                        MessageBox.Show(HBillNo + ",流转卡未开工!");
@@ -160,6 +160,7 @@
                ReadCsv();
            }
        }
        public static List<string> list = new List<string>();
        //读取csv格式文件
        private void ReadCsv()
@@ -176,7 +177,7 @@
            //注:斯莫尔组装3 在E盘  _332009
            //其余在D盘 _C332001_2M
            //string csv_file_path = $@"C:\Users\admin\Desktop\新建文件夹 (2)\20231123.csv";
            //string csv_file_path = $@"C:\Users\admin\Desktop\新建文件夹 (2)\250933P9_250403_C332001_2M.csv";
            string csv_file_path = $@"D:\THLCR_Data\{HBath}\{HBath}_{Date}_C332001_2M.csv"; //组装1 组装2路径 
            //string csv_file_path = $@"E:\THLCR_Data\{HBath}\{HBath}_{Date}_332009.csv";  //组装3路径
            //15车间缺少路径 D:\DATA SAVE\年\年月\年月日\批次号\数据保存.csv
@@ -189,7 +190,7 @@
            {
                DataTable dt = new DataTable();
                string HTypeName = "无尘";
                //string csv_file_path_Read = @"C:\Users\admin\Desktop\新建文件夹 (2)\20231123_1.csv";
                //string csv_file_path_Read = @"C:\Users\admin\Desktop\新建文件夹 (2)\250933P9_250403_C332001_2M_1.csv";
                string csv_file_path_Read = $@"D:\THLCR_Data\{HBath}\{HBath}_{Date}_C332001_2M_Read.csv"; //组装1 组装2路径 
                //string csv_file_path_Read = $@"E:\THLCR_Data\{HBath}\{HBath}_{Date}_332009_Read.csv";  //组装3路径
@@ -229,7 +230,7 @@
                parser.Close();
                //获取当前时间
                DateTime ActionTime = DateTime.Parse(DateTime.Now.AddMinutes(-2).ToString("yyyy-MM-dd  HH:mm:ss"));
                DateTime ActionTime = DateTime.Parse(DateTime.Now.AddMinutes(-20).ToString("yyyy-MM-dd  HH:mm:ss"));
                DateTime EndTime = DateTime.Parse(DateTime.Now.AddMinutes(1).ToString("yyyy-MM-dd  HH:mm:00"));
                bool flag_1 = false;
                bool flag_2 = false;
@@ -240,7 +241,7 @@
                        DateTime NowTime = DateTime.Parse(item["测试时间"].ToString());
                        string HBadCodeSN = item["序号"].ToString();
                        if (((NowTime >= ActionTime && NowTime < EndTime) || dt.Rows.Count <= 20) && HBadCodeSN != "")
                        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
@@ -257,16 +258,17 @@
                                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 * from Sb_EquipMentCollection_SN where HBarCode='" + HBarCode + "' and HCreateTime='" + HCreateTime + "'", "Sb_EquipMentCollection_SN");
                                if (ds.Tables[0].Rows.Count == 0)
                                if (true)
                                {
                                    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}')";
                                        oCN.RunProc(sql);
                                        ListSelect.Items.Add("条码:" + HBarCode + ",日期:" + HCreateTime + ",结果:" + HResult);
                                        ListSelect.Items.Add("条码:" + HBarCode + ",当前日期:" + DateTime.Now.ToString() + ",日期:" + HCreateTime + ",结果:" + HResult);
                                        list.Add(HBarCode);
                                        for (int i = 0; i < dt.Columns.Count; i++)
                                        {
@@ -372,10 +374,17 @@
            }
        }
        public static string AllProcessExchange = "-1";
        public static string AllProcessExchangeHProcExchBillNo = "";
        public static string AllProcessExchangeHProcExchInterID = "";
        public static string AllSNBarcodeProcCtrl = "";
        public static string AllHProcID = "0";
        public static string AllHProName = "";
        public static double AllHQty = 0;
        //根据条码 判断是否保存
        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)
            {
                flag_2 = false;
@@ -388,23 +397,28 @@
            if (HBarCode.Length == 29)
            {
                string str1 = HBarCode.Substring(18, 8);
                string str2 = HBarCode.Substring(23, 3);
                DataSet ds = oCN.RunProcReturn("select  HInterID,HBillNo from Sc_ProcessExchangeBillMain where HProjectNum like'" + str1 + "-1%' or HProjectNum like'" + str2 + "-1%' order by HMakeDate desc", "Sc_ProcessExchangeBillMain");
                //判断是否能找到对应的流转卡
                if (ds.Tables[0].Rows.Count > 0)
                {
                     HProcExchBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString();
                    HProcExchInterID = ds.Tables[0].Rows[0]["HInterID"].ToString();
                }
                else {
                    if (!flag_1)
                //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 (ds.Tables[0].Rows.Count > 0)
                    {
                        MessageBox.Show(new Form { TopMost = true }, "条码:" + HBarCode + ",流转卡不存在!");
                        AllProcessExchangeHProcExchBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString();
                        AllProcessExchangeHProcExchInterID = ds.Tables[0].Rows[0]["HInterID"].ToString();
                    }
                    DBHelper.CustomWriteLog("条码:" + HBarCode + ",流转卡不存在!", DateTime.Now.ToString("yyyy-MM-dd"));
                    flag_2 = true;
                    return false;
                    else
                    {
                        if (!flag_1 && (DateTime.Now - time).Minutes > hqty)
                        {
                            time = DateTime.Now;
                            MessageBox.Show(new Form { TopMost = true }, "条码:" + HBarCode + ",流转卡不存在!");
                        }
                        DBHelper.CustomWriteLog("条码:" + HBarCode + ",流转卡不存在!", DateTime.Now.ToString("yyyy-MM-dd"));
                        flag_2 = true;
                        return false;
                    }
                    AllProcessExchange = str1;
                }
            }
            //判断长度是否为50位  15车间
@@ -415,11 +429,12 @@
                //判断是否能找到对应的流转卡
                if (ds.Tables[0].Rows.Count > 0)
                {
                    HProcExchBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString();
                    AllProcessExchangeHProcExchBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString();
                }
                else {
                    if (!flag_1)
                    if (!flag_1 && (DateTime.Now - time).Minutes > hqty)
                    {
                        time = DateTime.Now;
                        MessageBox.Show("条码:" + HBarCode + ",流转卡不存在!");
                    }
                    DBHelper.CustomWriteLog("条码:" + HBarCode + ",流转卡不存在!", DateTime.Now.ToString("yyyy-MM-dd"));
@@ -429,24 +444,41 @@
                }
            }
            //赋值
            HProcExchBillNo = AllProcessExchangeHProcExchBillNo;
            HProcExchInterID = AllProcessExchangeHProcExchInterID;
            //过站控制
            DataSet ds1 = oCN.RunProcReturn(@"select   b.HProcNo,b.HProcID,p.HName 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 HProcID = "0";
            if (ds1.Tables[0].Rows.Count > 0)
            DataSet ds1;
            if ((HProcExchBillNo + HProcNumber) != AllSNBarcodeProcCtrl) {
                //查询工序
                ds1 = oCN.RunProcReturn(@"SELECT  HItemID,HName FROM Gy_Process WHERE HNumber='" + HProcNumber + "'", "Gy_Process");
                if (ds1.Tables[0].Rows.Count > 0)
                {
                    AllHProcID = ds1.Tables[0].Rows[0]["HItemID"].ToString();
                    AllHProName = ds1.Tables[0].Rows[0]["HName"].ToString();
                }
                //查询流转卡数量
                ds1 = oCN.RunProcReturn(@"SELECT  HQty FROM Sc_ProcessExchangeBillSub  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());
                }
                AllSNBarcodeProcCtrl = HProcExchBillNo + HProcNumber;
            }
            string HProcID = AllHProcID;
            string HProName = AllHProName;
            if ((HProcExchBillNo + HProcNumber) == AllSNBarcodeProcCtrl)
            {
                HProcID = ds1.Tables[0].Rows[0]["HProcID"].ToString();
                string HProName = ds1.Tables[0].Rows[0]["HName"].ToString();
                ds1 = oCN.RunProcReturn("exec h_p_Sc_SNBarcodeProcCtrl_S '" + HBarCode + "'," + HProcID, "h_v_Gy_QualifiedRecordsList");
                if (ds1.Tables[0].Rows.Count == 0)
                {
                    if (!flag_1)
                    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"));
@@ -456,8 +488,9 @@
                }
                else if (ds1.Tables[0].Rows[0]["HBack"].ToString() == "2")
                {
                    if (!flag_1)
                    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"));
@@ -468,15 +501,22 @@
            }
            //查询出站数量是否超过流转卡数量
            ds1 = 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.HProcID={HProcID}
group by b.HInterID,b.HEntryID,b.HQty", "Sc_ProcessExchangeBill_Out");
            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");
            if (double.Parse(ds1.Tables[0].Rows[0][0].ToString()) < 0)
            double hqtyOut = AllHQty;
            if (ds1.Tables[0].Rows.Count > 0)
            {
                if (!flag_1)
                hqtyOut = double.Parse(ds1.Tables[0].Rows[0][0].ToString());
            }
            if (hqtyOut <= 0)
            {
                if (!flag_1 && (DateTime.Now - time).Minutes > hqty)
                {
                    time = DateTime.Now;
                    MessageBox.Show("流转卡:" + HProcExchBillNo + ",出站数量超过流转卡数量!");
                }
                DBHelper.CustomWriteLog("流转卡:" + HProcExchBillNo + ",出站数量超过流转卡数量!", DateTime.Now.ToString("yyyy-MM-dd"));
@@ -484,28 +524,33 @@
                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++)
            //拍照工序除外
            if (HProcNumber != "013") {
                //增加产线组装追溯单
                DataSet dataSet = oCN.RunProcReturn("exec h_p_Gy_BarCodeBillBomList '" + HProcExchBillNo + "'," + HProcID, "h_p_Gy_BarCodeBillBomList");
                if (dataSet.Tables[0].Rows.Count > 0)
                {
                    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)
                    //判配件数量是否等于0
                    for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
                    {
                        if (!flag_1)
                        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)
                        {
                            MessageBox.Show("流转卡:" + HProcExchBillNo + ",配件条码:" + HMaterBarCode + ",配件代码:" + HMaterNamePJ + ",数量为0!");
                            if (!flag_1 && (DateTime.Now - time).Minutes > hqty)
                            {
                                time = DateTime.Now;
                                MessageBox.Show("流转卡:" + HProcExchBillNo + ",配件条码:" + HMaterBarCode + ",配件代码:" + HMaterNamePJ + ",数量为0!");
                            }
                            DBHelper.CustomWriteLog("流转卡:" + HProcExchBillNo + ",配件条码:" + HMaterBarCode + ",配件代码:" + HMaterNamePJ + ",数量为0!", DateTime.Now.ToString("yyyy-MM-dd"));
                            flag_2 = true;
                            return false;
                        }
                        DBHelper.CustomWriteLog("流转卡:" + HProcExchBillNo + ",配件条码:" + HMaterBarCode + ",配件代码:" + HMaterNamePJ + ",数量为0!", DateTime.Now.ToString("yyyy-MM-dd"));
                        flag_2 = true;
                        return false;
                    }
                }
            }
            flag_2 = false;
            return true;
        }