yi eason il y a 3 ans
Parent
commit
63be8dba93

+ 107 - 2
RailLocalMeter/OptionCls/RfidRailWayNo.cs

@@ -73,7 +73,6 @@ namespace RailLocalMeter
         {
             serialPort1.Write(sendData, 0, sendData.Length);
 
-            DateTime dt = DateTime.Now;
             Thread.Sleep(50);
             byte[] recData = new byte[serialPort1.BytesToRead];
             serialPort1.Read(recData, 0, recData.Length);
@@ -91,6 +90,11 @@ namespace RailLocalMeter
         {
             try
             {
+                bool isFirst = true;
+                string strInfo = "", strTest = "", strOldNo = "";
+                //int iDx = 0;
+                //bool isRight = false;
+                //string[] strS = new string[3] { "T", "G", "Q" };
                 while (blThreadFlag)
                 {
                     lock (obj)
@@ -98,8 +102,95 @@ namespace RailLocalMeter
                         byte[] bt = ReadPort(new byte[] { 0x11 });
                         string strtmp = System.Text.Encoding.UTF8.GetString(bt);
 
+
                         if (!string.IsNullOrEmpty(strtmp))
                         {
+                            if (isFirst)
+                            {
+                                strInfo = strtmp;
+                                isFirst = false;
+                            }
+                            else 
+                            {
+                                strInfo += strtmp;
+                                if (strInfo.Length >= 20) 
+                                {
+                                    strOldNo = strInfo.Substring(0, 20);
+                                    if (CacleCls.rfidCarNo != strOldNo)
+                                    {
+                                        CacleCls.rfidCarNo = strInfo.Substring(0,20);
+                                        strOldNo = CacleCls.rfidCarNo;
+                                        lg.WriteLog(LogType.RfidLoc, $"提供给界面的读卡器数据:{strInfo.Substring(0, 20)}");
+                                        if (strInfo.Length > 20)
+                                            strInfo = strInfo.Substring(20);
+                                        else
+                                            strInfo = "";
+                                    }
+                                }
+                            }
+                          
+                            #region 注释
+                            /*
+                            strInfo += strtmp;
+                            if (strInfo.Length >= 40)
+                            {
+                                
+                                foreach (string s in strS) 
+                                {
+                                    iDx = strInfo.IndexOf(s);
+                                    if (iDx >= 0 && (iDx + 20) < strInfo.Length)
+                                    {
+                                        string st = strInfo.Substring(strInfo.IndexOf(s), 20);
+                                        string ms = strInfo.Substring((iDx + 20));
+                                        if (st.Substring(0, ms.Length) == ms)
+                                        {
+                                            if (CacleCls.rfidCarNo != st)
+                                            {
+                                                CacleCls.rfidCarNo = st;
+                                                lg.WriteLog(LogType.RfidLoc, $"提供给界面的读卡器数据:{st}");
+                                            }
+                                            isRight = true;
+                                            break;
+                                        }
+                                    }
+                                }
+                                if (!isRight)
+                                {
+                                    strInfo = "";
+                                    iDx = 0;
+                                }
+                            }
+                            //*/
+
+                            /*
+                            if (strInfo == "")
+                            {
+                                if (strtmp.IndexOf("T") == 0 || strtmp.IndexOf("Q") == 0 || strtmp.IndexOf("G") == 0)
+                                {
+                                    strInfo = strtmp;
+                                }
+                                else
+                                {
+                                    strInfo = "";
+                                }
+                            }
+                            else if (strInfo.Length < 20)
+                            {
+                                strInfo += strtmp;
+                                if (strInfo.Length > 20) strInfo = strInfo.Substring(0, 20);
+                            }
+                            if (strInfo.Length == 20) 
+                            {
+                                if (CacleCls.rfidCarNo != strInfo)
+                                {
+                                    CacleCls.rfidCarNo = strInfo;
+                                    lg.WriteLog(LogType.RfidLoc, $"提供给界面的读卡器数据:{strInfo}");
+                                }
+                                strInfo = "";
+                            }
+                            //*/
+
+                            /*
                             if ((strtmp.IndexOf("T") == 0 || strtmp.IndexOf("Q") == 0 || strtmp.IndexOf("G") == 0) && strtmp.Length > 14)
                             {
                                 if (CacleCls.rfidCarNo != strtmp && strtmp.Trim() != "")
@@ -108,10 +199,24 @@ namespace RailLocalMeter
                                     lg.WriteLog(LogType.RfidLoc, $"获取并提供给界面的读卡器数据:{strtmp}");
                                 }
                             }
-                            else 
+                            else
                             {
                                 lg.WriteLog(LogType.RfidLoc, $"读卡器读取的数据:{strtmp}");
                             }
+                            //*/
+                            #endregion
+                            
+                            strTest += strtmp;
+                            if (strTest.Length >= 100)
+                            {
+                                lg.WriteLog(LogType.RfidLoc, $"读卡器读取的数据:{strTest}");
+                                strTest = "";
+                            }
+                        }
+                        else 
+                        {
+                            isFirst = true;
+                            strInfo = "";
                         }
                     }
                 }

+ 7 - 0
RailLocalMeter/Program.cs

@@ -14,6 +14,13 @@ namespace RailLocalMeter
         [STAThread]
         static void Main()
         {
+            byte[] bt = new byte[10];
+            bt[0] = 31;
+            bt[1] = 32;
+            bt[2] = 20;
+            string strtmp = System.Text.Encoding.UTF8.GetString(bt)?.Trim();
+
+
             bool createNew;
             using (System.Threading.Mutex m = new System.Threading.Mutex(true, Application.ProductName, out createNew))
             {

+ 9 - 7
RailLocalMeter/frmMain.Designer.cs

@@ -2548,7 +2548,7 @@ namespace RailLocalMeter
             this.tableLayoutPanel7.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 60F));
             this.tableLayoutPanel7.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 150F));
             this.tableLayoutPanel7.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 60F));
-            this.tableLayoutPanel7.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 81F));
+            this.tableLayoutPanel7.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 89F));
             this.tableLayoutPanel7.Controls.Add(this.lbPointName, 1, 0);
             this.tableLayoutPanel7.Controls.Add(this.txtCarNo, 3, 0);
             this.tableLayoutPanel7.Controls.Add(this.lbPntName, 0, 0);
@@ -2574,18 +2574,20 @@ namespace RailLocalMeter
             this.lbPointName.Location = new System.Drawing.Point(86, 1);
             this.lbPointName.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.lbPointName.Name = "lbPointName";
-            this.lbPointName.Size = new System.Drawing.Size(501, 36);
+            this.lbPointName.Size = new System.Drawing.Size(493, 36);
             this.lbPointName.TabIndex = 3;
             this.lbPointName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
             // 
             // txtCarNo
             // 
+            this.txtCarNo.Enabled = false;
             this.txtCarNo.Font = new System.Drawing.Font("宋体", 16F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.txtCarNo.Location = new System.Drawing.Point(656, 3);
+            this.txtCarNo.Location = new System.Drawing.Point(648, 3);
             this.txtCarNo.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.txtCarNo.Name = "txtCarNo";
             this.txtCarNo.Size = new System.Drawing.Size(144, 32);
             this.txtCarNo.TabIndex = 0;
+            this.txtCarNo.TextChanged += new System.EventHandler(this.txtCarNo_TextChanged);
             this.txtCarNo.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtCarNo_KeyDown);
             // 
             // lbPntName
@@ -2610,7 +2612,7 @@ namespace RailLocalMeter
             this.label2.Dock = System.Windows.Forms.DockStyle.Fill;
             this.label2.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.label2.ForeColor = System.Drawing.Color.Blue;
-            this.label2.Location = new System.Drawing.Point(596, 1);
+            this.label2.Location = new System.Drawing.Point(588, 1);
             this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label2.Name = "label2";
             this.label2.Size = new System.Drawing.Size(52, 36);
@@ -2625,7 +2627,7 @@ namespace RailLocalMeter
             this.label1.Dock = System.Windows.Forms.DockStyle.Fill;
             this.label1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.label1.ForeColor = System.Drawing.Color.Blue;
-            this.label1.Location = new System.Drawing.Point(808, 1);
+            this.label1.Location = new System.Drawing.Point(800, 1);
             this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label1.Name = "label1";
             this.label1.Size = new System.Drawing.Size(52, 36);
@@ -2636,7 +2638,7 @@ namespace RailLocalMeter
             // pbLineOn
             // 
             this.pbLineOn.Image = ((System.Drawing.Image)(resources.GetObject("pbLineOn.Image")));
-            this.pbLineOn.Location = new System.Drawing.Point(868, 4);
+            this.pbLineOn.Location = new System.Drawing.Point(860, 4);
             this.pbLineOn.Name = "pbLineOn";
             this.pbLineOn.Size = new System.Drawing.Size(39, 30);
             this.pbLineOn.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
@@ -2850,7 +2852,6 @@ namespace RailLocalMeter
         private System.Windows.Forms.Panel plImgShow;
         private System.Windows.Forms.PictureBox pictureShow;
         private System.Windows.Forms.CheckBox cbSetFirst;
-        private ucWeightT ucWeightT1;
         private Infragistics.Win.UltraWinTabControl.UltraTabControl ultraTabControl1;
         private Infragistics.Win.UltraWinTabControl.UltraTabSharedControlsPage ultraTabSharedControlsPage3;
         private Infragistics.Win.UltraWinTabControl.UltraTabSharedControlsPage ultraTabSharedControlsPage4;
@@ -2911,6 +2912,7 @@ namespace RailLocalMeter
         private System.Data.DataColumn dataColumn114;
         private System.Data.DataColumn dataColumn115;
         private System.Windows.Forms.NumericUpDown txtTare;
+        private ucWeightT ucWeightT1;
     }
 }
 

+ 116 - 45
RailLocalMeter/frmMain.cs

@@ -94,6 +94,24 @@ namespace RailLocalMeter
 
         private void frmMain_Load(object sender, EventArgs e)
         {
+            BindTable<MeterWorkRailwayActFirst>(ultraGridFirst, dataTableFirst, "firstx");
+            BindTable<PreRailwayScale>(ultraGridPre, dataTablePre, "prex");
+
+            CacleCls.Clear(); //清理一次数据
+            btnSave.Enabled = false;
+            txtCarNo.Text = "";
+            txtMATTER_NAME.Text = "";
+            txtFORWARDING_UNIT_NAME.Text = "";
+            txtRECEIVING_UINT_NAME.Text = "";
+            txtMETER_TYPE.Text = "";
+            txtMsgInfo.Text = "";
+            txtGroess.Text = "";
+            txtTare.Text = "";
+            txtNet.Text = "";
+            txtMsgInfo.Focus();
+
+
+
             txtMsgInfo.Focus();
             if (AppConfigCache.openCom == "0")
             {
@@ -248,6 +266,8 @@ namespace RailLocalMeter
         {
             if (!blThreadFlag) return;
             int iError = 0;
+
+            bool bClear = false;
             while (blThreadFlag)
             {
                 try
@@ -257,47 +277,65 @@ namespace RailLocalMeter
                         ucWeightT1.setStable(CacleCls.isWd != 1 ? true : false);
                         ucWeightT1.setExceed(CacleCls.weight > AppConfigCache.maxRange * 1000 ? false : true);
 
-                        if (isMeasureSuccess && Math.Abs(CacleCls.lockWgt - CacleCls.weight) > AppConfigCache.changeWgt)
-                        {
-                            isMeasureSuccess = false;
-                            txtCarNo.Text = "";
-                            CacleCls.rfidCarNo = "";
-                            CacleCls.lockCarNo = "";
-                            CacleCls.carType = "";
-                            txtMsgInfo.Focus();
-
-                            BindTable<MeterWorkRailwayActFirst>(ultraGridFirst, dataTableFirst, "firstx");
-
-                            //查询预报数据
-                            BindTable<PreRailwayScale>(ultraGridPre, dataTablePre, "prex");
-                        }
-                        /*
-                        if (isMeasureSuccess && CacleCls.lockCarNo != CacleCls.rfidCarNo && !string.IsNullOrEmpty(CacleCls.rfidCarNo)) 
+                        if (CacleCls.isWd == 0)
                         {
-                            txtCarNo.Text = "";
+                            bClear = false;
+                            //bCl = false;
+                            if (!string.IsNullOrEmpty(CacleCls.rfidCarNo))
+                            {
+                                if (CacleCls.rfidCarNo.Length > 14)
+                                {
+                                    string strRailNo = CacleCls.rfidCarNo.Substring(7, 7);
+                                    if (strRailNo.Trim().Length == 7)
+                                    {
+                                        if (strFinishCarNo != strRailNo || CacleCls.isJg && !isEditRailwayNo)
+                                        {
+                                            CacleCls.lockCarNo = strRailNo;
+                                            CacleCls.carType = CacleCls.rfidCarNo.Substring(1, 5).Trim().ToUpper();
+                                        }
+                                    }
+                                }
+                            }
                         }
-                        //*/
-                        if (txtCarNo.Text.Trim() != "" && !txtCarNo.Focused)
+                        else if (CacleCls.lockWgt > 1000) //有计量过的重量
                         {
-                            CacleCls.lockCarNo = txtCarNo.Text.Trim();
+                            if (Math.Abs(CacleCls.lockWgt - CacleCls.weight) > AppConfigCache.changeWgt) 
+                            {
+                                isEditRailwayNo = false;
+                                isMeasureSuccess = false;
+                                CacleCls.lockCarNo = ""; //清理下数据
+                                CacleCls.carType = "";
+                                txtCarNo.Text = "";
+                                txtMsgInfo.Focus();
+
+                                BindTable<MeterWorkRailwayActFirst>(ultraGridFirst, dataTableFirst, "firstx");
+
+                                //查询预报数据
+                                BindTable<PreRailwayScale>(ultraGridPre, dataTablePre, "prex");
+                            }
                         }
-                        else if (!string.IsNullOrEmpty(CacleCls.rfidCarNo))
+                        else //从未计量过,假如有车号不需要管
                         {
-                            if (CacleCls.rfidCarNo.Length > 14)
+                            if (!CacleCls.isJg&& !bClear) 
                             {
-                                string strRailNo = CacleCls.rfidCarNo.Substring(7, 7);
-                                if (strRailNo.Trim().Length == 7)
-                                {
-                                    CacleCls.lockCarNo = strRailNo;
-                                    CacleCls.carType = CacleCls.rfidCarNo.Substring(1, 5).Trim().ToUpper();
-                                }
+                                bClear = true;
+                                txtCarNo.Text = "";
+
+                                BindTable<MeterWorkRailwayActFirst>(ultraGridFirst, dataTableFirst, "firstx");
+
+                                //查询预报数据
+                                BindTable<PreRailwayScale>(ultraGridPre, dataTablePre, "prex");
+                                txtMsgInfo.Focus();
                             }
                         }
 
-                        if (!string.IsNullOrEmpty(CacleCls.lockCarNo) && txtCarNo.Text.Trim() == "")
+                        if (!string.IsNullOrEmpty(CacleCls.lockCarNo))
                         {
                             txtCarNo.Text = CacleCls.lockCarNo;
                         }
+
+                        
+
                         if (strOldCarNo != CacleCls.lockCarNo)
                         {
                             txtMsgInfo.Text = "";//车号不同的情况下清理下保存按钮
@@ -335,21 +373,24 @@ namespace RailLocalMeter
                             if (!CacleCls.isLock && !CacleCls.isJg && CacleCls.btnState == "1" && CacleCls.isWd == 0)
                             {
                                 /*
-                                if (string.IsNullOrEmpty(CacleCls.lockCarNo)) 
+                                if (CacleCls.serverFlag) 
                                 {
-                                    txtMsgInfo.Text = "车号未识别";
-                                    vicPlayClass.GetVoicePlay(VoiceEnum.车号未识别, "");
-                                    led_controler?.setStaticLineMsg(AppConfigCache.ledIp, "车号未识别");
-                                    return;
-                                }
+                                    if (string.IsNullOrEmpty(CacleCls.lockCarNo))
+                                    {
+                                        txtMsgInfo.Text = "车号未识别";
+                                        vicPlayClass.GetVoicePlay(VoiceEnum.车号未识别, "");
+                                        led_controler?.setStaticLineMsg(AppConfigCache.ledIp, "车号未识别");
+                                        return;
+                                    }
 
-                                
-                                if (CacleCls.lockCarNo.Length != 7) 
-                                {
-                                    txtMsgInfo.Text = "车号不为7位";
-                                    vicPlayClass.GetVoicePlay(VoiceEnum.车号未识别, "");
-                                    led_controler?.setStaticLineMsg(AppConfigCache.ledIp, "车号不为7位");
-                                    return;
+
+                                    if (CacleCls.lockCarNo.Length != 7)
+                                    {
+                                        txtMsgInfo.Text = "车号不为7位";
+                                        vicPlayClass.GetVoicePlay(VoiceEnum.车号未识别, "");
+                                        led_controler?.setStaticLineMsg(AppConfigCache.ledIp, "车号不为7位");
+                                        return;
+                                    }
                                 }
                                 //*/
 
@@ -416,6 +457,9 @@ namespace RailLocalMeter
 
                             if (!CacleCls.isClear)
                             {
+                                BindTable<MeterWorkRailwayActFirst>(ultraGridFirst, dataTableFirst, "firstx");
+                                BindTable<PreRailwayScale>(ultraGridPre, dataTablePre, "prex");
+                                
                                 iError = 32;
                                 CacleCls.Clear(); //清理一次数据
                                 btnSave.Enabled = false;
@@ -653,6 +697,10 @@ namespace RailLocalMeter
                         firstDb.weightType = "0";
                         firstDb.railwayFactoryWeight = Convert.ToDouble(txtTare.Value * 1000);
                         firstDb.valueFlag = "2";
+                        if (string.IsNullOrEmpty(firstDb.railwayNo)) 
+                        {
+                            firstDb.railwayNo = "车号未识别";
+                        }
 
                         RESTfulResult<ResponseData> rt = firstService.doIdentifyWeight(firstDb, out msgInfo);
                         if (rt.Succeed)
@@ -734,6 +782,11 @@ namespace RailLocalMeter
                                 CacleCls.preTrackScale.format(firstDb);
                             }
 
+                            if (string.IsNullOrEmpty(firstDb.railwayNo))
+                            {
+                                firstDb.railwayNo = "车号未识别";
+                            }
+
                             RESTfulResult<ResponseData> rt = firstService.add(firstDb, out msgInfo);
                             if (rt.Succeed)
                             {
@@ -761,6 +814,11 @@ namespace RailLocalMeter
                                 MeterWorkRailwayActFirst mwraf = new MeterWorkRailwayActFirst();
                                 CreateFirst(ref mwraf);
 
+                                if (string.IsNullOrEmpty(mwraf.railwayNo))
+                                {
+                                    mwraf.railwayNo = "车号未识别";
+                                }
+
                                 if (CacleCls.preTrackScale != null)
                                 {
                                     CacleCls.preTrackScale.format(mwraf);
@@ -885,7 +943,7 @@ namespace RailLocalMeter
                     }
                     #endregion
 
-
+                    txtMsgInfo.Focus();
 
 
                     BindTable<PreRailwayScale>(ultraGridWaitFirst, dataTableWaitFirst, "firstWait");
@@ -1241,9 +1299,18 @@ namespace RailLocalMeter
 
         }
 
+        bool isEditRailwayNo = false;
         private void txtCarNo_KeyDown(object sender, KeyEventArgs e)
         {
-            if (e.KeyCode == Keys.Enter) label3.Focus();
+            if (e.KeyCode == Keys.Enter)
+            {
+                if (txtCarNo.Text.Trim().Length > 0)
+                {
+                    CacleCls.lockCarNo = txtCarNo.Text.Trim();
+                    isEditRailwayNo = true;
+                    txtMsgInfo.Focus();
+                }
+            }
         }
         #endregion
 
@@ -1295,8 +1362,12 @@ namespace RailLocalMeter
                 SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
             }
         }
-        #endregion
 
+        private void txtCarNo_TextChanged(object sender, EventArgs e)
+        {
+
+        }
+        #endregion
 
         #region
         private void CreateFirst(ref MeterWorkRailwayActFirst mwraf)