yangle
2025-04-07 0d59b3fd8050b0f0766be47ed5527d96bd4bf2f7
WFormSynchronizeData_SMR/WFormReadData_SMR/ReadyDataForm.cs
@@ -24,7 +24,9 @@
            InitializeComponent();
        }
         public static int num = 0;
        public static int SelectTime = 0;
        public static DateTime time = DateTime.Now.AddMinutes(-5);
        public static decimal hqty = 2;
        //读取数据
        private void btnReadData_Click(object sender, EventArgs e)
        {
@@ -40,6 +42,7 @@
                    this.btnReadData.Text = "暂停";
                    this.timer1.Enabled = true;
                    num = 1;
                    SelectTime = -4;
                }
                else if (num == 1)
                {
@@ -111,6 +114,7 @@
            }
        }
        public static List<string> listData = new List<string>();
        //文本读取数据
        public void Read_Txt() {
@@ -122,12 +126,12 @@
            string dataTime = DateTime.Now.ToString("yyyyMMdd");
            ////判断是否有这个文件
            bool flag = File.Exists($@"D:\{year}\{month}\{day}\{dataTime}.txt");
            //bool flag = File.Exists($@"C:\Users\admin\Desktop\新建文件夹 (2)\20231123.txt");
            //bool flag = File.Exists($@"C:\Users\admin\Desktop\新建文件夹 (2)\20250403T拍照.txt");
            if (flag)
            {
                StreamReader stream = new StreamReader($@"D:\{year}\{month}\{day}\{dataTime}.txt", Encoding.GetEncoding("gb2312"));
                //StreamReader stream = new StreamReader($@"C:\Users\admin\Desktop\新建文件夹 (2)\20231123.txt", Encoding.GetEncoding("gb2312"));
                //StreamReader stream = new StreamReader($@"C:\Users\admin\Desktop\新建文件夹 (2)\20250403T拍照.txt", Encoding.GetEncoding("gb2312"));
                string FileData = stream.ReadToEnd();
                stream.Close();
@@ -184,6 +188,11 @@
            }
        }
        public static string AllBeginWork = "-1";
        public static string AllProcessExchange = "-1";
        public static string AllProcessExchangeHProcExchBillNo = "";
        public static string AllProcessExchangeHProcExchInterID = "";
        public void Xt_ReadText(string FileData)
        {
            FileData = FileData.Substring(0, FileData.Length - 1);
@@ -201,20 +210,21 @@
                list.Add(dic);
            }
            //获取当前时间
            DateTime ActionTime = DateTime.Parse(DateTime.Now.AddMinutes(-1).ToString("yyyy-MM-dd  HH:mm:ss"));
            DateTime ActionTime = DateTime.Parse(DateTime.Now.AddMinutes(SelectTime).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;
            //循环集合
            for (int i = 0; i < list.Count; i++)
            {
                string HBarCode = list[i]["HBadCodeSN"].ToString();
                DateTime NowTime = DateTime.Parse(list[i]["HDate"].ToString());
                if (NowTime >= ActionTime && NowTime < EndTime && list[i]["HBadCodeSN"].ToString() != "")
                if (NowTime >= ActionTime && NowTime < EndTime && list[i]["HBadCodeSN"].ToString() != "" && listData.Contains(HBarCode)==false)
                {
                    string HSourceCode = list[i]["HSouceNumber"].ToString();
                    string HEmpCode = this.HEmpCode.Text;
                    //string HEmpCode = "";
                    string HType = list[i]["HBadReason"].ToString();
                    string HBarCode = list[i]["HBadCodeSN"].ToString();
                    int HCount = 1;
                    string HCreateTime = list[i]["HDate"].ToString();
                    string HDate = DateTime.Parse(list[i]["HDate"].ToString()).ToString("yyyy-MM-dd");
@@ -222,14 +232,70 @@
                    string HProcNumber = list[i]["HProcNumber"].ToString();
                    int HFlag = 0;
                    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)
                    {
                        string sql = $@"insert into Sb_EquipMentCollection_SN(HSourceCode,HEmpCode,HType,HBarCode,HCount,HCreateTime,HDate,HResult,HProcNumber,HFlag)
                        DataSet dataSet;
                        string HProjectNum = HBarCode.Substring(18, 8);
                        if (HBarCode.Contains(AllProcessExchange)==false) {
                            dataSet = oCN.RunProcReturn("select HInterID,HBillNo from Sc_ProcessExchangeBillMain where HProjectNum='" + HProjectNum + "-1'", "Sc_ProcessExchangeBillMain");
                            if (dataSet.Tables[0].Rows.Count > 0) {
                                AllProcessExchangeHProcExchBillNo = dataSet.Tables[0].Rows[0]["HBillNo"].ToString();
                                AllProcessExchangeHProcExchInterID = dataSet.Tables[0].Rows[0]["HInterID"].ToString();
                                AllProcessExchange = HProjectNum;
                            }
                        }
                        if (AllProcessExchange == HProjectNum)
                        {
                            if (HBarCode.Contains(AllBeginWork) == false) {
                                dataSet = oCN.RunProcReturn("select  * from Sc_ICMOBillStatus_Tmp where HSourceBillNo='" + AllProcessExchangeHProcExchBillNo + "' and HICMOStatus<>'0'", "Sc_ICMOBillStatus_Tmp");
                                if (dataSet.Tables[0].Rows.Count > 0)
                                {
                                    AllBeginWork = HProjectNum;
                                }
                            }
                            if (AllBeginWork == HProjectNum)
                            {
                                if (Get_AllowLoadData(HBarCode, HProcNumber, flag_1, AllProcessExchangeHProcExchBillNo, AllProcessExchangeHProcExchInterID, 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);
                                    oCN.RunProc(sql);
                                    ListSelect.Items.Add("条码:" + HBarCode + ",当前日期;"+DateTime.Now.ToString()+",日期:" + HCreateTime + ",结果:" + HResult);
                                    listData.Add(HBarCode);
                                }
                                else
                                {
                                    flag_1 = flag_2;
                                }
                            }
                            else
                            {
                                if (!flag_1 && (DateTime.Now - time).Minutes > hqty)
                                {
                                    time = DateTime.Now;
                                    MessageBox.Show(new Form { TopMost = true }, "条码:" + HBarCode + ",对应的流转卡:" + AllProcessExchangeHProcExchBillNo + ",流转卡未开工!");
                                }
                                DBHelper.CustomWriteLog("条码:" + HBarCode + ",对应的流转卡:" + AllProcessExchangeHProcExchBillNo + ",流转卡未开工!", DateTime.Now.ToString("yyyy-MM-dd"));
                                flag_1 = true;
                            }
                        }
                        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_1 = true;
                        }
                    }
                }
                else
@@ -294,6 +360,185 @@
            }
        }
        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,string HProcExchBillNo,string HProcExchInterID, out bool flag_2)
        {
            if (HBarCode.Length != 29 && HBarCode.Length != 50)
            {
                flag_2 = false;
                return false;
            }
            //判断长度是否为29位 无尘车间
            if (HBarCode.Length == 29)
            {
            }
            //判断长度是否为50位  15车间
            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");
                //判断是否能找到对应的流转卡
                if (ds.Tables[0].Rows.Count > 0)
                {
                    HProcExchBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString();
                }
                else
                {
                    if (!flag_1 && (DateTime.Now - time).Minutes > hqty)
                    {
                        time = DateTime.Now;
                        MessageBox.Show("条码:" + HBarCode + ",流转卡不存在!");
                    }
                    DBHelper.CustomWriteLog("条码:" + HBarCode + ",流转卡不存在!", DateTime.Now.ToString("yyyy-MM-dd"));
                    flag_2 = true;
                    return false;
                }
            }
            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;
            }
            if ((HProcExchBillNo + HProcNumber) == AllSNBarcodeProcCtrl)
            {
                //过站控制
                ds1 = oCN.RunProcReturn("exec h_p_Sc_SNBarcodeProcCtrl_S '" + HBarCode + "'," + AllHProcID, "h_p_Sc_SNBarcodeProcCtrl_S");
                if (ds1.Tables[0].Rows.Count == 0)
                {
                    if (!flag_1 && (DateTime.Now - time).Minutes > hqty)
                    {
                        time = DateTime.Now;
                        MessageBox.Show("条码:" + HBarCode + "工序:" + AllHProName + ",工序控制查无数据!");
                    }
                    DBHelper.CustomWriteLog("条码:" + HBarCode + "工序:" + AllHProName + ",工序控制查无数据!", DateTime.Now.ToString("yyyy-MM-dd"));
                    flag_2 = true;
                    return false;
                }
                else if (ds1.Tables[0].Rows[0]["HBack"].ToString() == "2")
                {
                    if (!flag_1 && (DateTime.Now - time).Minutes > hqty)
                    {
                        time = DateTime.Now;
                        MessageBox.Show("条码:" + HBarCode + "工序:" + AllHProcID + "," + ds1.Tables[0].Rows[0]["HBackRemark"].ToString() + "!");
                    }
                    DBHelper.CustomWriteLog("条码:" + HBarCode + "工序:" + AllHProcID + "," + 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");
            double hqtyOut = AllHQty;
            if (ds1.Tables[0].Rows.Count > 0) {
                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"));
                flag_2 = true;
                return false;
            }
            //拍照工序除外
            if (HProcNumber != "013")
            {
                //增加产线组装追溯单
                DataSet dataSet = oCN.RunProcReturn("exec h_p_Gy_BarCodeBillBomList '" + HProcExchBillNo + "'," + AllHProcID, "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]["配件代码"].ToString();
                        string HMaterBarCode = dataSet.Tables[0].Rows[i]["HBarCode"].ToString();
                        if (SYHQty == 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;
                        }
                    }
                }
            }
            flag_2 = false;
            return true;
        }
        private void ReadyDataForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (num == 1) {
                MessageBox.Show("当前按钮未暂停,不允许关闭!");
                e.Cancel = true;
            }
            else if (MessageBox.Show("确定要关闭吗?", "确认", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                e.Cancel = true;
            }
        }
        private void btnSelectAll_Click(object sender, EventArgs e)
        {
            if (num == 0)
            {
                if (MessageBox.Show("是否启用检索补漏?", "确认", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    SelectTime = -90;
                    Read_Txt();
                }
            }
            else if (num == 1)
            {
                MessageBox.Show("请先点击暂停按钮!");
            }
        }
    }
}