Selaa lähdekoodia

更换解析电子秤的正则表达式

章政 7 vuotta sitten
vanhempi
commit
d4f7d4dcb6

+ 16 - 7
UAS-MES/FunctionCode/Make/Make_CartonBoxSNWeigh.cs

@@ -36,6 +36,8 @@ namespace UAS_MES.Make
 
         bool LockSn = false;
 
+        Regex re = new Regex("\\d+.\\d+\\w+");
+
         string PR_CHECKCARTONW = "0";
         //创建串口实例
         SerialPort serialPort1 = new SerialPort();
@@ -198,15 +200,22 @@ namespace UAS_MES.Make
                         }
                     }
                     OperateResult.AppendText(">>箱号" + outboxcode + "称重完成\n", Color.Green);
-                    if (LogicHandler.CartonBoxStepPass(ma_code.Text, User.UserSourceCode, outboxcode, User.UserCode, "卡通箱:" + outboxcode + "整箱过站", out ErrorMessage))
-                    {
-                        dh.UpdateByCondition("package", "pa_printcount= nvl(pa_printcount,0)+1,pa_weight='" + ActualWeight + "',pa_status=1,pa_packageqty=pa_currentqty,pa_totalqty=pa_currentqty", "pa_outboxcode='" + outboxcode + "'");
-                        dh.UpdateByCondition("package", "pa_nextstep='" + dh.getFieldDataByCondition("packagedetail left join makeserial on ms_sncode=pd_barcode and ms_makecode=pd_makecode", "max(ms_nextstepcode)", "pd_outboxcode='" + outboxcode + "'").ToString() + "' ,PA_CURRENTSTEP = '' ", "pa_outboxcode='" + outboxcode + "'");
-                    }
-                    else
+                    //if (LogicHandler.CartonBoxStepPass(ma_code.Text, User.UserSourceCode, outboxcode, User.UserCode, "卡通箱:" + outboxcode + "整箱过站", out ErrorMessage))
+                    //{
+                    //    dh.UpdateByCondition("package", "pa_printcount= nvl(pa_printcount,0)+1,pa_weight='" + ActualWeight + "',pa_status=1,pa_packageqty=pa_currentqty,pa_totalqty=pa_currentqty", "pa_outboxcode='" + outboxcode + "'");
+                    //    dh.UpdateByCondition("package", "pa_nextstep='" + dh.getFieldDataByCondition("packagedetail left join makeserial on ms_sncode=pd_barcode and ms_makecode=pd_makecode", "max(ms_nextstepcode)", "pd_outboxcode='" + outboxcode + "'").ToString() + "' ,PA_CURRENTSTEP = '' ", "pa_outboxcode='" + outboxcode + "'");
+                    //}
+                    //else
+                    //{
+                    //    OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
+                    //}
+                    if (!LogicHandler.OutBoxStepPass(outboxcode, ma_code.Text, User.UserSourceCode, User.UserCode, "卡通箱:" + outboxcode + "整箱过站", "卡通箱整箱过站", out ErrorMessage))
                     {
                         OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
+                        return;
                     }
+                    dh.UpdateByCondition("package", "pa_printcount= nvl(pa_printcount,0)+1,pa_weight='" + ActualWeight + "',pa_status=1,pa_packageqty=pa_currentqty,pa_totalqty=pa_currentqty", "pa_outboxcode='" + outboxcode + "'");
+                    dh.UpdateByCondition("package", "pa_nextstep='" + dh.getFieldDataByCondition("packagedetail left join makeserial on ms_sncode=pd_barcode and ms_makecode=pd_makecode", "max(ms_nextstepcode)", "pd_outboxcode='" + outboxcode + "'").ToString() + "' ,PA_CURRENTSTEP = '' ", "pa_outboxcode='" + outboxcode + "'");
                     LoadCheckQTY();
                     sncode.Clear();
                 }
@@ -227,7 +236,7 @@ namespace UAS_MES.Make
                         {
                             try
                             {
-                                weight.Text = serialPort1.ReadLine();
+                                weight.Text = re.Match(serialPort1.ReadLine().Trim()).Groups[0].Value;
                             }
                             catch (Exception)
                             {

+ 11 - 6
UAS-MES/FunctionCode/Make/Make_CartonBoxWeigh.cs

@@ -30,6 +30,8 @@ namespace UAS_MES.Make
 
         Document doc;
 
+        Regex re = new Regex("\\d+.\\d+\\w+");
+
         Thread thread;
 
         string PR_CHECKCARTONW = "0";
@@ -141,13 +143,13 @@ namespace UAS_MES.Make
                         //称量合格或不合格都记录重量
                         if (ActualWeight >= MinWeight && ActualWeight <= MaxWeight && ActualWeight != 0)
                         {
-                            LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "卡通箱"+ outboxcode.Text + "称重", "称量合格:" + weight.Text.Trim(), outboxcode.Text, "");
+                            LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "卡通箱" + outboxcode.Text + "称重", "称量合格:" + weight.Text.Trim(), outboxcode.Text, "");
                             LogicHandler.RecordProdWeight(outboxcode.Text, "CARTON", float.Parse(ActualWeight.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
                             OperateResult.AppendText(">>箱号" + outboxcode.Text + "检测合格\n", Color.Green);
                         }
                         else
                         {
-                            LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "卡通箱"+ outboxcode.Text + "称重", "称量不合格:" + weight.Text.Trim(), outboxcode.Text, "");
+                            LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "卡通箱" + outboxcode.Text + "称重", "称量不合格:" + weight.Text.Trim(), outboxcode.Text, "");
                             LogicHandler.RecordProdWeight(outboxcode.Text, "CARTON", float.Parse(ActualWeight.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
                             OperateResult.AppendText(">>箱号" + outboxcode.Text + "检测未通过\n", Color.Red, outboxcode);
                             return;
@@ -155,7 +157,7 @@ namespace UAS_MES.Make
                     }
                     else
                     {
-                        LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "卡通箱"+ outboxcode.Text + "称重", "称量完成:" + weight.Text.Trim(), outboxcode.Text, "");
+                        LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "卡通箱" + outboxcode.Text + "称重", "称量完成:" + weight.Text.Trim(), outboxcode.Text, "");
                         LogicHandler.RecordProdWeight(outboxcode.Text, "CARTON", float.Parse(ActualWeight.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
                     }
                     if (AutoPrint.Checked)
@@ -184,7 +186,11 @@ namespace UAS_MES.Make
                     //{
                     //    OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
                     //}
-                    LogicHandler.OutBoxStepPass(outboxcode.Text, ma_code.Text, User.UserSourceCode, User.UserCode, "卡通箱:" + outboxcode.Text + "整箱过站", "卡通箱整箱过站", out ErrorMessage);
+                    if (!LogicHandler.OutBoxStepPass(outboxcode.Text, ma_code.Text, User.UserSourceCode, User.UserCode, "卡通箱:" + outboxcode.Text + "整箱过站", "卡通箱整箱过站", out ErrorMessage))
+                    {
+                        OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, outboxcode);
+                        return;
+                    }
                     dh.UpdateByCondition("package", "pa_printcount= nvl(pa_printcount,0)+1,pa_weight='" + ActualWeight + "',pa_status=1,pa_packageqty=pa_currentqty,pa_totalqty=pa_currentqty", "pa_outboxcode='" + outboxcode.Text + "'");
                     dh.UpdateByCondition("package", "pa_nextstep='" + dh.getFieldDataByCondition("packagedetail left join makeserial on ms_sncode=pd_barcode and ms_makecode=pd_makecode", "max(ms_nextstepcode)", "pd_outboxcode='" + outboxcode.Text + "'").ToString() + "' ,PA_CURRENTSTEP = '' ", "pa_outboxcode='" + outboxcode.Text + "'");
                     LoadCheckQTY();
@@ -207,8 +213,7 @@ namespace UAS_MES.Make
                         {
                             try
                             {
-                                weight.Text = serialPort1.ReadLine();
-                                //weight.Text = Regex.Replace(serialPort1.ReadLine(), "\\D+", "");
+                                weight.Text = re.Match(serialPort1.ReadLine().Trim()).Groups[0].Value;
                             }
                             catch (Exception)
                             {

+ 3 - 10
UAS-MES/FunctionCode/Make/Make_ColorBoxWeigh.cs

@@ -38,6 +38,8 @@ namespace UAS_MES.Make
         string LastSncode;
         bool WeightChange = false;
 
+        Regex re = new Regex("\\d+.\\d+\\w+");
+
         string ErrorMessage;
 
         Thread InitPrint;
@@ -208,16 +210,7 @@ namespace UAS_MES.Make
                         {
                             try
                             {
-                                weight.Text = serialPort1.ReadLine();
-                                //if (pr_colorboxunit.Text == "kg")
-                                //{
-                                //    weight.Text = (float.Parse(weight.Text) / 1000).ToString();
-                                //    WeightChange = true;
-                                //}
-                                //else
-                                //{
-                                //    WeightChange = false;
-                                //}
+                                weight.Text = re.Match(serialPort1.ReadLine().Trim()).Groups[0].Value;
                             }
                             catch (Exception)
                             {