| | |
| | | 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; |
| | |
| | | { |
| | | 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 = "√"; |
| | |
| | | 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) => |
| | | { |
| | |
| | | if (e.KeyCode == Keys.Enter) |
| | | { |
| | | //如果是水检,还要扫工位 |
| | | if (txt_gx.Text.Trim() == fGxShouJian) |
| | | if (txt_gx.Text.Trim() == fGxShouJian && isWater == "1") |
| | | { |
| | | txt_gongWei.Focus(); |
| | | } |
| | |
| | | //如果是水检,可以提交了 |
| | | 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); |
| | | } |
| | | } |
| | |
| | | }; |
| | | 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(); |
| | |
| | | foreach (dynamic dym in lst) |
| | | { |
| | | if (stringBuilder.Length > 0) |
| | | stringBuilder.Append("|"); |
| | | stringBuilder.Append("&"); |
| | | stringBuilder.Append(dym.dicTxt); |
| | | } |
| | | string _txt = stringBuilder.ToString(); |
| | |
| | | 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> |
| | |
| | | /// <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; |
| | |
| | | _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; |
| | |
| | | //水检 |
| | | if (txt_gx.Text.Trim() == fGxShouJian) |
| | | { |
| | | if (isWater == "0") |
| | | { |
| | | return _obj; |
| | | } |
| | | string strCsl1 = "";//模式1出水量 |
| | | string strSw1 = "";//模式1水温 |
| | | string strCsl2 = ""; |
| | |
| | | /// </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)); |
| | |
| | | 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; |
| | |
| | | string SJJG = "";//水检查结果ok、ng |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | 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 |
| | | |
| | | } |