From f4d5aa97370f698c63b0b9f185f06e7bae56975c Mon Sep 17 00:00:00 2001 From: cdk <2441919651@qq.com> Date: 星期二, 19 八月 2025 08:15:50 +0800 Subject: [PATCH] Merge branch 'master' of http://git.gs-mes.com:8080/r/~tjx/GsMesClient --- DevApp/Gs.DevApp/DevFrm/Work/Frm_Work01.cs | 185 +++++++++++++++++++++++++++++++++------------- 1 files changed, 132 insertions(+), 53 deletions(-) diff --git a/DevApp/Gs.DevApp/DevFrm/Work/Frm_Work01.cs b/DevApp/Gs.DevApp/DevFrm/Work/Frm_Work01.cs index 9e8b054..9b74e45 100644 --- a/DevApp/Gs.DevApp/DevFrm/Work/Frm_Work01.cs +++ b/DevApp/Gs.DevApp/DevFrm/Work/Frm_Work01.cs @@ -4,11 +4,13 @@ using DevExpress.XtraLayout.Utils; using Gs.DevApp.Entity; using Gs.DevApp.ToolBox; +using Gs.DevApp.UserControl; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using NModbus; using System; using System.Collections.Generic; +using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Dynamic; @@ -21,10 +23,11 @@ { public partial class Frm_Work01 : DevExpress.XtraEditors.XtraForm { + string isWater = "0"; string hostName = "192.168.60.51"; int hostNamePoint = 502; string strConn = "Data Source=192.168.1.146;Initial Catalog=GS_MES;User ID=mesUser;Password =qixi1qaz@WSXmes"; - bool isCleanDianJian = false; + bool isCleanDianJian = true; string _webServiceName = "WorkCollect/"; string dianJianPath = "";//鐢垫鍙栧�艰矾寰� string goodTag = "鈭�"; @@ -43,6 +46,16 @@ public Frm_Work01(string _fGx, string _fBc, string _strinOther) { InitializeComponent(); + try + { + string _vanishingSeconds = ConfigurationManager.AppSettings["IsWater"]; + if (!string.IsNullOrEmpty(_vanishingSeconds)) + isWater = _vanishingSeconds; + } + catch (Exception) + { + + } gvMx1.IndicatorWidth = 60; gvMx1.CustomDrawRowIndicator += (s, e) => { @@ -61,7 +74,7 @@ if (e.KeyCode == Keys.Enter) { //濡傛灉鏄按妫�锛岃繕瑕佹壂宸ヤ綅 - if (txt_gx.Text.Trim() == fGxShouJian) + if (txt_gx.Text.Trim() == fGxShouJian && isWater == "1") { txt_gongWei.Focus(); } @@ -76,6 +89,14 @@ //濡傛灉鏄按妫�锛屽彲浠ユ彁浜や簡 if (txt_gx.Text.Trim() == fGxShouJian) { + if (txt_gongWei.Text.Trim().Length <= 0) + { + Toast vm = new Toast(-1, "~璇锋壂宸ヤ綅鐮亊"); + vm.Show(); + this.ActiveControl = this.txt_gongWei; + txt_gongWei.Focus(); + return; + } addModel(goodTag); } } @@ -86,14 +107,15 @@ }; btnBad.Click += (s, e) => { - string _barCode = txt_barCode.Text.Trim(); - if (string.IsNullOrEmpty(_barCode)) + string _collectGuid = lbCollectGuid.Text.Trim(); + if (_collectGuid.Length < 30) { - Toast vm = new Toast(-1, "~璇峰厛鎵拷婧爜~"); + Toast vm = new Toast(-1, "~璇峰厛閫夋嫨杩芥函鐮亊"); vm.Show(); return; } - UcDictionarySelect frm = new UcDictionarySelect("宸ュ簭涓嶈壇鎻忚堪", " a.s_type='宸ュ簭涓嶈壇鎻忚堪' and pid<>'00000000-0000-0000-0000-000000000000'"); + string _msg = "浣犲噯澶囧皢銆�" + txt_gdbh.Text + "銆戙��" + txt_currentBarCode.Text.Trim() + "銆戝彉鏇翠负涓嶈壇"; + UcDictionarySelect frm = new UcDictionarySelect("宸ュ簭涓嶈壇鎻忚堪", " a.s_type='宸ュ簭涓嶈壇鎻忚堪' and pid<>'00000000-0000-0000-0000-000000000000'", _msg); frm.UpdateParent += (ss, ee) => { System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); @@ -101,7 +123,7 @@ foreach (dynamic dym in lst) { if (stringBuilder.Length > 0) - stringBuilder.Append("|"); + stringBuilder.Append("&"); stringBuilder.Append(dym.dicTxt); } string _txt = stringBuilder.ToString(); @@ -111,12 +133,22 @@ vm.Show(); } else - addModel(badTag, _txt); + addModel(badTag, _txt, lbCollectGuid.Text.Trim()); }; frm.ShowDialog(); }; this.ActiveControl = this.txt_barCode; txt_barCode.Focus(); + gvMx1.FocusedRowChanged += (s, e) => + { + if (e.FocusedRowHandle >= 0) + { + DataRow row = gvMx1.GetDataRow(e.FocusedRowHandle); + txt_gdbh.Text = row["gdbh"].ToString(); + txt_currentBarCode.Text = row["barCode"].ToString(); + lbCollectGuid.Text = row["guid"].ToString(); + } + }; } /// <summary> @@ -126,7 +158,7 @@ /// <param name="_checkResult">缁撴灉</param> /// <param name="_badDescription">涓嶈壇鎻忚堪</param> /// <returns></returns> - private dynamic getObj(string _barCode, string _checkResult, string _badDescription = "") + private dynamic getObj(string _barCode, string _checkResult, string _badDescription = "", string _collectGuid = "") { dynamic _obj = new ExpandoObject(); _obj.barCode = _barCode; @@ -135,6 +167,11 @@ _obj.banCi = txt_bc.Text.Trim();//鐝 _obj.gongWei = txt_gongWei.Text.Trim();//宸ヤ綅 _obj.badDescription = _badDescription.Trim();//涓嶈壇鎻忚堪 + _obj.collectGuid = _collectGuid; + if (!string.IsNullOrEmpty(_collectGuid)) + { + return _obj; + } if (txt_gx.Text.Trim() == fGxTouRu) { return _obj; @@ -191,6 +228,10 @@ //姘存 if (txt_gx.Text.Trim() == fGxShouJian) { + if (isWater == "0") + { + return _obj; + } string strCsl1 = "";//妯″紡1鍑烘按閲� string strSw1 = "";//妯″紡1姘存俯 string strCsl2 = ""; @@ -232,16 +273,21 @@ /// </summary> /// <param name="_checkResult">缁撴灉锛氣垰</param> /// <param name="_badDescription">涓嶈壇鎻忚堪</param> - private void addModel(string _checkResult, string _badDescription = "") + private void addModel(string _checkResult, string _badDescription = "", string _collectGuid = "") { string _barCode = txt_barCode.Text.Trim(); - if (string.IsNullOrEmpty(_barCode)) + if (string.IsNullOrEmpty(_collectGuid)) { - Toast vm = new Toast(-1, "~璇峰厛鎵拷婧爜~"); - vm.Show(); - return; + if (string.IsNullOrEmpty(_barCode)) + { + Toast vm = new Toast(-1, "~璇峰厛鎵拷婧爜~"); + vm.Show(); + this.ActiveControl = this.txt_barCode; + txt_barCode.Focus(); + return; + } } - dynamic _obj = getObj(_barCode, _checkResult, _badDescription); + dynamic _obj = getObj(_barCode, _checkResult, _badDescription, _collectGuid); try { string strJson = UtilityHelper.HttpPost("", _webServiceName + "GetModel", JsonConvert.SerializeObject(_obj)); @@ -256,8 +302,10 @@ lbSum3.Text = dy.lbSum3; lbSum4.Text = dy.lbSum4; prog1.Position = dy.jd; - //鑹搧鍒楄〃 txt_barCode.ReadOnly = false; + if (txt_gx.Text.Trim() == fGxShouJian) + txt_gongWei.ReadOnly = false; + //鑹搧鍒楄〃 JObject _job = JObject.Parse(strJson); JArray array = new JArray(); foreach (var a in _job["rtnData"]["list"]) @@ -331,7 +379,7 @@ else layDianJian.Visibility = LayoutVisibility.Never; //鍙湁姘存鎵嶆樉绀� - if (txt_gx.Text.Trim() == fGxShouJian) + if (txt_gx.Text.Trim() == fGxShouJian && isWater == "1") layShuiJian.Visibility = LayoutVisibility.Always; else layShuiJian.Visibility = LayoutVisibility.Never; @@ -482,52 +530,57 @@ string SJJG = "";//姘存鏌ョ粨鏋渙k銆乶g string GWZT = "";//宸ヤ綅鐘舵�� string SJJGZ = "";//姘存鏌ョ粨鏋�1 - System.Text.StringBuilder sbSql1 = new StringBuilder(); - sbSql1.Append($"select MIG004,MIG005 from BASMIG(nolock) where MIG001='ShuiJianZhanWei01' and MIG003='{((BaseEdit)this.txt_gongWei).EditValue.ToString()}'"); - DataTable dataTable1 = this.GetDataTable(sbSql1.ToString(), "tmpBASMIG2"); - if (dataTable1 == null || dataTable1.Rows.Count <= 0) + bool blIp = true; + blIp = CheckPort(hostName, hostNamePoint); + if (blIp) { - ((BaseEdit)this.txt_gongWei).EditValue = (object)""; - LogHelper.Debug(this.ToString(), txt_gongWei.Text + "璇ユ按妫�绔欎綅鐮佷笉瀛樺湪锛岃纭锛�"); - //Toast vm = new Toast(-1, "璇ユ按妫�绔欎綅鐮佷笉瀛樺湪锛岃纭锛�"); - //vm.Show(); - } - else - { - ModbusFactory modbusFactory = new ModbusFactory(); - byte num1 = byte.Parse("1"); - ushort num2 = ushort.Parse("1"); - System.Text.StringBuilder sbSql2 = new StringBuilder(); - sbSql2.Append(string.Format($"select case when MIG006='D' then MIG003+{dataTable1.Rows[0][0]} else MIG003+{dataTable1.Rows[0][1]} end MIG003,MIG004 from BASMIG(nolock) where MIG001 = 'ShuiJianAddress01' order by MIG005")); - DataTable dataTable2 = GetDataTable(sbSql2.ToString(), "tmpBASMIG3"); - if (dataTable2 == null || dataTable2.Rows.Count <= 0) + System.Text.StringBuilder sbSql1 = new StringBuilder(); + sbSql1.Append($"select MIG004,MIG005 from BASMIG(nolock) where MIG001='ShuiJianZhanWei01' and MIG003='{((BaseEdit)this.txt_gongWei).EditValue.ToString()}'"); + DataTable dataTable1 = this.GetDataTable(sbSql1.ToString(), "tmpBASMIG2"); + if (dataTable1 == null || dataTable1.Rows.Count <= 0) { ((BaseEdit)this.txt_gongWei).EditValue = (object)""; - LogHelper.Debug(this.ToString(), txt_gongWei.Text + "姘存鍦板潃涓嶅瓨鍦紝璇风‘璁わ紒"); - //Toast vm = new Toast(-1, "姘存鍦板潃涓嶅瓨鍦紝璇风‘璁わ紒"); + LogHelper.Debug(this.ToString(), txt_gongWei.Text + "璇ユ按妫�绔欎綅鐮佷笉瀛樺湪锛岃纭锛�"); + //Toast vm = new Toast(-1, "璇ユ按妫�绔欎綅鐮佷笉瀛樺湪锛岃纭锛�"); //vm.Show(); } else { - try - { - IModbusMaster master = modbusFactory.CreateMaster(new TcpClient(this.hostName, this.hostNamePoint)); - master.Transport.ReadTimeout = 10000; - master.Transport.Retries = 10000; - strCsl1 = master.ReadHoldingRegisters(num1, ushort.Parse(dataTable2.Rows[0]["MIG003"].ToString()), num2)[0].ToString(); - strSw1 = (float.Parse(master.ReadHoldingRegisters(num1, ushort.Parse(dataTable2.Rows[1]["MIG003"].ToString()), num2)[0].ToString()) / 10f).ToString(); - ushort[] numArray = master.ReadHoldingRegisters(num1, ushort.Parse(dataTable2.Rows[2]["MIG003"].ToString()), num2); - SJJGZ = numArray[0].ToString(); - SJJG = numArray[0].ToString(); - SJJG = (SJJG == "1" ? "OK" : (SJJG == "2" ? "NG" : SJJG)); - GWZT = master.ReadCoils(num1, ushort.Parse(dataTable2.Rows[3]["MIG003"].ToString()), num2)[0].ToString(); - } - catch (Exception ex) + ModbusFactory modbusFactory = new ModbusFactory(); + byte num1 = byte.Parse("1"); + ushort num2 = ushort.Parse("1"); + System.Text.StringBuilder sbSql2 = new StringBuilder(); + sbSql2.Append(string.Format($"select case when MIG006='D' then MIG003+{dataTable1.Rows[0][0]} else MIG003+{dataTable1.Rows[0][1]} end MIG003,MIG004 from BASMIG(nolock) where MIG001 = 'ShuiJianAddress01' order by MIG005")); + DataTable dataTable2 = GetDataTable(sbSql2.ToString(), "tmpBASMIG3"); + if (dataTable2 == null || dataTable2.Rows.Count <= 0) { ((BaseEdit)this.txt_gongWei).EditValue = (object)""; - LogHelper.Debug(this.ToString(), txt_gongWei.Text + ex.Message); - //Toast vm = new Toast(-1, ex.Message); + LogHelper.Debug(this.ToString(), txt_gongWei.Text + "姘存鍦板潃涓嶅瓨鍦紝璇风‘璁わ紒"); + //Toast vm = new Toast(-1, "姘存鍦板潃涓嶅瓨鍦紝璇风‘璁わ紒"); //vm.Show(); + } + else + { + try + { + IModbusMaster master = modbusFactory.CreateMaster(new TcpClient(this.hostName, this.hostNamePoint)); + master.Transport.ReadTimeout = 10000; + master.Transport.Retries = 10000; + strCsl1 = master.ReadHoldingRegisters(num1, ushort.Parse(dataTable2.Rows[0]["MIG003"].ToString()), num2)[0].ToString(); + strSw1 = (float.Parse(master.ReadHoldingRegisters(num1, ushort.Parse(dataTable2.Rows[1]["MIG003"].ToString()), num2)[0].ToString()) / 10f).ToString(); + ushort[] numArray = master.ReadHoldingRegisters(num1, ushort.Parse(dataTable2.Rows[2]["MIG003"].ToString()), num2); + SJJGZ = numArray[0].ToString(); + SJJG = numArray[0].ToString(); + SJJG = (SJJG == "1" ? "OK" : (SJJG == "2" ? "NG" : SJJG)); + GWZT = master.ReadCoils(num1, ushort.Parse(dataTable2.Rows[3]["MIG003"].ToString()), num2)[0].ToString(); + } + catch (Exception ex) + { + ((BaseEdit)this.txt_gongWei).EditValue = (object)""; + LogHelper.Debug(this.ToString(), txt_gongWei.Text + ex.Message); + //Toast vm = new Toast(-1, ex.Message); + //vm.Show(); + } } } } @@ -551,6 +604,32 @@ return ds.Tables[0]; } } + + private bool CheckPort(string host, int port) + { + int vanishingSeconds = 3; + string _vanishingSeconds = ConfigurationManager.AppSettings["AsyncSeconds"]; + if (!string.IsNullOrEmpty(_vanishingSeconds)) + vanishingSeconds = int.Parse(_vanishingSeconds); + bool isOpen = false; + try + { + using (var client = new TcpClient()) + { + var result = client.BeginConnect(host, port, null, null); + var success = result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(vanishingSeconds)); // 绛夊緟5绉� + if (success) + { + isOpen = true; + } + } + } + catch (Exception ex) + { + LogHelper.Debug(this.ToString(), "CheckPort:" + ex.Message); + } + return isOpen; + } #endregion } -- Gitblit v1.9.3