From 878aad490fc15b11d63fb4fa7ab7ada260f66310 Mon Sep 17 00:00:00 2001
From: lu <123456>
Date: 星期六, 09 八月 2025 10:03:59 +0800
Subject: [PATCH] iqc称重

---
 DevApp/Gs.DevApp/DevFrm/Work/Frm_Work09.cs |  155 ++++++++++++++++++++++++++++++++-------------------
 1 files changed, 97 insertions(+), 58 deletions(-)

diff --git a/DevApp/Gs.DevApp/DevFrm/Work/Frm_Work09.cs b/DevApp/Gs.DevApp/DevFrm/Work/Frm_Work09.cs
index 19b3a47..10f7707 100644
--- a/DevApp/Gs.DevApp/DevFrm/Work/Frm_Work09.cs
+++ b/DevApp/Gs.DevApp/DevFrm/Work/Frm_Work09.cs
@@ -1,8 +1,12 @@
 锘縰sing System;
 using System.Collections.Generic;
+using System.Data;
+using System.Drawing;
 using System.IO.Ports;
+using System.Linq;
 using System.Timers;
 using System.Windows.Forms;
+using DevExpress.Utils;
 using Gs.DevApp.Entity;
 using Gs.DevApp.ToolBox;
 using Newtonsoft.Json;
@@ -11,26 +15,21 @@
 {
     public partial class Frm_Work09 : DevExpress.XtraEditors.XtraForm
     {
+        string _strType = "";
         string _webServiceName = "WorkWeight/";
-        string value = string.Empty;
         /// <summary>
         /// 涓插彛绫�
         /// </summary>
         private SerialPort Sp = new SerialPort();
         /// <summary>
-        /// 鏇存柊UI濮旀墭锛屽彧瀹氫箟锛屼笉瀹炵幇
+        /// gridview瀹氭椂鍒锋柊
         /// </summary>
-        /// <param name="text"></param>
-        public delegate void HandleInterfaceUpdataDelegate(string text);
-        /// <summary>
-        /// 鏇存柊UI濮旀墭锛屽疄鐜�
-        /// </summary>
-        private HandleInterfaceUpdataDelegate interfaceUpdataHandle;
-
-        System.Timers.Timer timer = new System.Timers.Timer(10000); // 1000姣闂撮殧
-        public Frm_Work09()
+        System.Timers.Timer timer = new System.Timers.Timer(10000);
+        public Frm_Work09(string strType)
         {
             InitializeComponent();
+            this._strType = strType;
+            this.Text = _strType + ":" + this.Text;
             this.FormClosing += (s, e) =>
             {
                 if (Sp.IsOpen)
@@ -42,8 +41,35 @@
                 }
             };
             GetComList();
-            this.comLine.getSuppler("");
-            Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameterMx(gvMx1);
+            if (this._strType == QcSeason.浜х嚎绉伴噸.ToString())
+            {
+                this.comLine.getSuppler("");
+            }
+            gvMx1.OptionsFind.ShowSearchNavButtons = false;
+            gvMx1.OptionsView.ShowAutoFilterRow = false;
+            gvMx1.OptionsView.ShowGroupPanel = false;
+            gvMx1.RowStyle += (s, e) =>
+            {
+                //榛樿閫変腑琛屼笉鍙樿壊
+                gvMx1.OptionsSelection.EnableAppearanceFocusedRow = false;
+                //榛樿閫変腑鍗曞厓鏍间笉鍙樿壊
+                gvMx1.OptionsSelection.EnableAppearanceFocusedCell = false;
+                if (e.RowHandle >= 0)
+                {
+                    DataRow row = gvMx1.GetDataRow(e.RowHandle);
+                    if (row == null)
+                        return;
+                    string colorString = row["bgColor"].ToString(); // 浣跨敤鍗佸叚杩涘埗琛ㄧず棰滆壊鐨凙RGB鍊�
+                    Color color = ColorTranslator.FromHtml(colorString);
+                    e.Appearance.BackColor = color;
+                }
+            };
+            gvMx1.IndicatorWidth = 60;
+            gvMx1.CustomDrawRowIndicator += (s, e) =>
+            {
+                if (e.Info.IsRowIndicator && e.RowHandle >= 0)
+                    e.Info.DisplayText = (e.RowHandle + 1).ToString();
+            };
         }
 
         /// <summary> 
@@ -65,17 +91,21 @@
         /// <param name="e"></param>
         private void btnStart_Click(object sender, EventArgs e)
         {
-            string _comLine = comLine.GetId();
+            Sp.DataReceived -= new SerialDataReceivedEventHandler(Sp_DataReceived);
             string _cmbSerialPortNum = cmbSerialPortNum.Text.Trim();
             string _cmbBaudRate = cmbBaudRate.Text.Trim();
             string _comSjw = comSjw.Text.Trim();
             string _comStopBits = comStopBits.Text.Trim();
             string _comParity = comParity.Text.Trim();
-            if (string.IsNullOrEmpty(_comLine))
+            if (this._strType == QcSeason.浜х嚎绉伴噸.ToString())
             {
-                Gs.DevApp.ToolBox.MsgHelper.ShowError("璇烽�夋嫨绾夸綋");
-                this.comLine.Focus();
-                return;
+                string _comLine = comLine.GetId();
+                if (string.IsNullOrEmpty(_comLine))
+                {
+                    Gs.DevApp.ToolBox.MsgHelper.ShowError("璇烽�夋嫨绾夸綋");
+                    this.comLine.Focus();
+                    return;
+                }
             }
             if (cmbSerialPortNum.SelectedIndex < 0)
             {
@@ -109,7 +139,6 @@
             }
             try
             {
-                interfaceUpdataHandle = new HandleInterfaceUpdataDelegate(UpdateTextBox);//瀹炰緥鍖栧鎵樺璞� 
                 Sp.ReceivedBytesThreshold = 1;
                 Sp.PortName = _cmbSerialPortNum;
                 Sp.BaudRate = Convert.ToInt32(_cmbBaudRate);//璁剧疆娉㈢壒鐜�
@@ -130,6 +159,8 @@
                     Gs.DevApp.ToolBox.MsgHelper.ShowError("鏃犳硶璇嗗埆鐨勫仠姝綅");
                 }
                 Sp.DataBits = int.Parse(_comSjw); // 璁剧疆鏁版嵁浣�
+                //Sp.ReadTimeout = 500; // 璁剧疆瓒呮椂鏃堕棿锛屼緥濡�500姣
+                //Sp.ReadBufferSize = 4096; // 璁剧疆缂撳啿鍖哄ぇ灏�
                 Sp.DataReceived += new SerialDataReceivedEventHandler(Sp_DataReceived);
                 Sp.ReceivedBytesThreshold = 1;
                 LogHelper.Debug(this.ToString(), "鎵撳紑涓插彛閫氫俊PortName-" + Sp.PortName.ToString() + ",BaudRate-" + Sp.BaudRate.ToString() + ",StopBits-" + Sp.StopBits.ToString() + ",Parity-" + Sp.Parity.ToString());
@@ -143,7 +174,7 @@
             }
             catch (Exception exe)
             {
-                LogHelper.Debug(this.ToString(), "鎵撳紑澶辫触:" + exe.Message);
+                LogHelper.Debug(this.ToString(), "鎵撳紑涓插彛閫氫俊澶辫触:" + exe.Message);
                 Gs.DevApp.ToolBox.MsgHelper.ShowError("鎵撳紑澶辫触" + exe.Message);
             }
         }
@@ -155,15 +186,39 @@
         /// <param name="e"></param>
         public void Sp_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
         {
-            string abc = string.Empty;
+            string _tmpStr = string.Empty;
             try
             {
                 int i = Sp.BytesToRead;
                 if (i > 0)
                 {
-                    abc = Sp.ReadExisting();
-                    LogHelper.Debug(this.ToString(), $"鐩戝惉鍒版暟鎹�:{abc}");
-                    this.Invoke(interfaceUpdataHandle, abc);
+                    _tmpStr = Sp.ReadExisting();
+                    // Thread.Sleep(1000);
+                    LogHelper.Debug(this.ToString(), $"鐩戝惉鍒版暟鎹紝瀛楄妭闀垮害:{i.ToString()}锛寋_tmpStr}");
+                    this.BeginInvoke(new Action(() =>
+                    {
+                        txtMsg.AppendLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff->瀛楄妭鏁板瓧" + i.ToString() + "->") + _tmpStr);
+                        //ST,GS,+  250.2kg
+                        if (_tmpStr.Length <= 0)
+                        {
+                            LogHelper.Debug(this.ToString(), "_tmpStr闀垮害<=0锛岄��鍑轰笂鎶�");
+                            return;
+                        }
+                        if (!_tmpStr.Contains("ST"))
+                        {
+                            LogHelper.Debug(this.ToString(), "_tmpStr閲嶉噺鐘舵�佷笉涓篠T锛岄��鍑轰笂鎶�");
+                            return;
+                        }
+                        if (!_tmpStr.Contains("+"))
+                        {
+                            LogHelper.Debug(this.ToString(), "_tmpStr涓嶅寘鍚噸閲�+锛岄��鍑轰笂鎶�");
+                            return;
+                        }
+                        string[] _ary = _tmpStr.Split('+');
+                        string abc = _ary.Last();//ST,GS,
+                        txtNum.Text = (abc.Trim().Replace("k", "").Replace("g", "").Replace("S", "").Replace("T", "").Replace("G", "").Replace(",", ""));
+                        addModel(txtNum.Text, _tmpStr);
+                    }));
                 }
             }
             catch (Exception ex)
@@ -173,33 +228,7 @@
             }
         }
 
-        /// <summary>
-        /// 鎺ュ彈鍒版暟鎹紝寮�濮嬪鐞嗘暟鎹�
-        /// </summary>
-        /// <param name="text"></param>
-        private void UpdateTextBox(string text)
-        {
-            //ST,GS,+  250.2kg
-            string _tmpStr = text.Trim();
-            if (_tmpStr.Length <= 0)
-            {
-                LogHelper.Debug(this.ToString(), "_tmpStr闀垮害<=0锛岄��鍑轰笂鎶�");
-                return;
-            }
-            if (!_tmpStr.Contains("ST"))
-            {
-                LogHelper.Debug(this.ToString(), "_tmpStr閲嶉噺鐘舵�佷笉涓篠T锛岄��鍑轰笂鎶�");
-                return;
-            }
-            if (!_tmpStr.Contains("+"))
-            {
-                LogHelper.Debug(this.ToString(), "_tmpStr閲嶉噺+锛岄��鍑轰笂鎶�");
-                return;
-            }
-            _tmpStr = _tmpStr.Substring(7);
-            txtNum.Text = _tmpStr;
-            addModel(_tmpStr);
-        }
+
         /// <summary>
         /// 鍚敤鎴栫鐢�
         /// </summary>
@@ -217,13 +246,22 @@
         /// <summary>
         /// 涓婁紶绉伴噸鏁版嵁
         /// </summary>
-        private void addModel(string _realWeight)
+        /// <param name="_realWeight">鎴彇鍚庣殑鏁伴噺</param>
+        /// <param name="_realWeightTxt">鍘熷瓙涓�</param>
+        private void addModel(string _realWeight, string _realWeightTxt)
         {
-            string _lineId = comLine.GetId();
+            string _lineId = "";
+            if (this._strType == QcSeason.浜х嚎绉伴噸.ToString())
+            {
+                _lineId = comLine.GetId();
+            }
+            else
+                _lineId = "0";
             var _obj = new
             {
                 lineId = _lineId,
-                realWeight = _realWeight,
+                realWeight = _realWeight.Trim(),
+                realWeightTxt = _realWeightTxt.Trim(),
             };
             try
             {
@@ -237,7 +275,7 @@
             }
             catch (Exception ex)
             {
-                ToolBox.MsgHelper.Warning("鎻愮ず锛�" + ex.Message);
+                ToolBox.MsgHelper.ShowError("鎻愮ず锛�" + ex.Message);
             }
         }
 
@@ -248,13 +286,14 @@
         /// <param name="e"></param>
         private void OnTimedEvent(Object source, ElapsedEventArgs e)
         {
+            if (this._strType == QcSeason.iqc绉伴噸.ToString())
+                return;
             var _obj = new
             {
                 lineId = comLine.GetId(),
             };
             try
             {
-                var lst = new List<string>();
                 var strReturn = UtilityHelper.HttpPost("", _webServiceName + "GetModelList", JsonConvert.SerializeObject(_obj), false);
                 var dd = UtilityHelper.ReturnToList(strReturn);
                 var dt = dd.rtnData;
@@ -268,9 +307,9 @@
             }
             catch (Exception ex)
             {
-                MessageBox.Show("gvMx1:" + ex.Message);
+                Toast vm = new Toast(-1, "gvMx1:" + ex.Message);
+                vm.Show();
             }
         }
-
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3