zrg
2025-05-22 cd7a1182c004bfcc705f28b0a306a9855f3af059
WFormSynchronizeData_SMR/WFormReadData_SMR/ReadyDataForm.cs
@@ -23,7 +23,7 @@
        {
            InitializeComponent();
        }
         public static int num = 0;
        public static int num = 0;
        public static int SelectTime = 0;
        public static DateTime time = DateTime.Now.AddMinutes(-5);
        public static decimal hqty = 2;
@@ -56,7 +56,8 @@
        //员工编码回车
        private void HEmpCode_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter) {
            if (e.KeyCode == Keys.Enter)
            {
                SelectHEmpCode(this.HEmpCode.Text);
            }
        }
@@ -66,7 +67,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("查无数据!");
@@ -117,7 +118,8 @@
        public static List<string> listData = new List<string>();
        //文本读取数据
        public void Read_Txt() {
        public void Read_Txt()
        {
            int year = DateTime.Now.Year;
            string month = DateTime.Now.Month.ToString();
@@ -168,7 +170,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("查无数据!");
@@ -188,10 +190,10 @@
            }
        }
        public static string AllBeginWork = "-1";
        public static string AllProcessExchange = "-1";
        public static string AllProcessExchangeHProcExchBillNo = "";
        public static string AllProcessExchangeHProcExchInterID = "";
        public static string AllBeginWork = "-1";  //是否开工
        public static string AllProcessExchange = "-1";   //流转卡项目号
        public static string AllProcessExchangeHProcExchBillNo = "";  //流转卡号
        public static string AllProcessExchangeHProcExchInterID = ""; //流转卡主码
        public void Xt_ReadText(string FileData)
        {
@@ -220,7 +222,7 @@
            {
                string HBarCode = list[i]["HBadCodeSN"].ToString();
                DateTime NowTime = DateTime.Parse(list[i]["HDate"].ToString());
                if (NowTime >= ActionTime && NowTime < EndTime && list[i]["HBadCodeSN"].ToString() != "" && listData.Contains(HBarCode)==false)
                if (NowTime >= ActionTime && NowTime < EndTime && list[i]["HBadCodeSN"].ToString() != "" && listData.Contains(HBarCode) == false)
                {
                    string HSourceCode = list[i]["HSouceNumber"].ToString();
                    string HEmpCode = this.HEmpCode.Text;
@@ -232,20 +234,21 @@
                    string HResult = list[i]["HResult"].ToString();
                    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");
                    if (true)
                    {
                        DataSet dataSet;
                        string HProjectNum = HBarCode.Substring(18, 8);
                        //通过截取项目号 如果第一条数据的项目号跟后面的一样 就不进行判断
                        if (HBarCode.Contains(AllProcessExchange)==false) {
                        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) {
                            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;
@@ -255,9 +258,10 @@
                        if (AllProcessExchange == HProjectNum)
                        {
                            //通过截取项目号 如果第一条数据的项目号跟后面的一样 就不进行判断
                            if (HBarCode.Contains(AllBeginWork) == false) {
                            if (HBarCode.Contains(AllBeginWork) == false)
                            {
                                //判断当前流转卡对应的工序数据是否开工
                                dataSet = oCN.RunProcReturn("select  * from Sc_ICMOBillStatus_Tmp where HSourceBillNo='" + AllProcessExchangeHProcExchBillNo + "' and HICMOStatus<>'0'", "Sc_ICMOBillStatus_Tmp");
                                dataSet = oCN.RunProcReturn("select  HICMOStatus from Sc_ICMOBillStatus_Tmp where HSourceBillNo='" + AllProcessExchangeHProcExchBillNo + "' and HICMOStatus<>'0'", "Sc_ICMOBillStatus_Tmp");
                                if (dataSet.Tables[0].Rows.Count > 0)
                                {
@@ -272,9 +276,9 @@
                                {
                                    //新增条码数据
                                    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);
                                    ListSelect.Items.Add("条码:" + HBarCode + ",当前日期;" + DateTime.Now.ToString() + ",日期:" + HCreateTime + ",结果:" + HResult);
                                    listData.Add(HBarCode);
                                }
                                else
@@ -350,12 +354,12 @@
                    string HProcNumber = list[i]["HProcNumber"].ToString();
                    int HFlag = 0;
                    DataSet ds = oCN.RunProcReturn(@"select * from Sb_EquipMentCollectionTechParam_SN where HBarCode='" + HBarCode + "' and HCreateTime='" + HCreateTime + "'", "Sb_EquipMentCollectionTechParam_SN");
                    DataSet ds = oCN.RunProcReturn(@"select HItemID from Sb_EquipMentCollectionTechParam_SN where HBarCode='" + HBarCode + "' and HCreateTime='" + HCreateTime + "'", "Sb_EquipMentCollectionTechParam_SN");
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        string sql = $@"insert into Sb_EquipMentCollectionTechParam_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);
                    }
@@ -368,13 +372,13 @@
        }
        public static string AllSNBarcodeProcCtrl = "";
        public static string AllHProcID = "0";
        public static string AllHProName = "";
        public static double AllHQty = 0;
        public static string AllSNBarcodeProcCtrl = "";  //流转卡+工序的拼写
        public static string AllHProcID = "0";           //工序id
        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)
        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)
@@ -386,13 +390,13 @@
            //判断长度是否为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");
                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)
                {
@@ -415,10 +419,11 @@
            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();
@@ -426,7 +431,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());
@@ -438,47 +443,48 @@
            ////第一次流转卡+工序和后面的做对比 如果是同一个流转卡就不进行判断
            //if ((HProcExchBillNo + HProcNumber) == AllSNBarcodeProcCtrl)
            //{
                //过站控制
                //判断当前工序对应的条码是否上道工序过站
                ds1 = oCN.RunProcReturn("exec h_p_Sc_SNBarcodeProcCtrl_S '" + HBarCode + "'," + AllHProcID, "h_p_Sc_SNBarcodeProcCtrl_S");
            //过站控制
            //判断当前工序对应的条码是否上道工序过站
            ds1 = oCN.RunProcReturn("exec h_p_Sc_SNBarcodeProcCtrl_S '" + HBarCode + "'," + AllHProcID, "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 + "工序:" + AllHProName + ",工序控制查无数据!");
                    }
                    DBHelper.CustomWriteLog("条码:" + HBarCode + "工序:" + AllHProName + ",工序控制查无数据!", DateTime.Now.ToString("yyyy-MM-dd"));
                    flag_2 = true;
                    return false;
                    time = DateTime.Now;
                    MessageBox.Show("条码:" + HBarCode + "工序:" + AllHProName + ",工序控制查无数据!");
                }
                else if (ds1.Tables[0].Rows[0]["HBack"].ToString() == "2")
                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")
            {
                //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 + "工序:" + 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;
                    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");
            //查询出站数量是否超过流转卡数量
            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) {
            if (ds1.Tables[0].Rows.Count > 0)
            {
                hqtyOut = double.Parse(ds1.Tables[0].Rows[0][0].ToString());
            }
            //流转卡数量-出站单数量大于0 
@@ -531,7 +537,8 @@
        private void ReadyDataForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (num == 1) {
            if (num == 1)
            {
                MessageBox.Show("当前按钮未暂停,不允许关闭!");
                e.Cancel = true;
            }
@@ -556,7 +563,7 @@
                MessageBox.Show("请先点击暂停按钮!");
            }
        }
    }
}