| | |
| | | using DevExpress.XtraGrid.Columns; |
| | | using DevExpress.Office.Utils; |
| | | using DevExpress.XtraEditors; |
| | | using DevExpress.XtraGrid.Columns; |
| | | using DevExpress.XtraLayout.Utils; |
| | | using Gs.DevApp.Entity; |
| | | using Gs.DevApp.ToolBox; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Linq; |
| | | using NModbus; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | | using System.Data.SqlClient; |
| | | using System.Dynamic; |
| | | using System.IO; |
| | | using System.Net.Sockets; |
| | | using System.Text; |
| | | using System.Windows.Forms; |
| | | |
| | |
| | | { |
| | | public partial class Frm_Work01 : DevExpress.XtraEditors.XtraForm |
| | | { |
| | | 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; |
| | | string _webServiceName = "WorkCollect/"; |
| | | string dianJianPath = "";//电检取值路径 |
| | | string goodTag = "√"; |
| | |
| | | addColumn(); |
| | | txt_barCode.KeyDown += (s, e) => |
| | | { |
| | | if (e.KeyCode == Keys.Enter) { addModel(goodTag); } |
| | | ; |
| | | if (e.KeyCode == Keys.Enter) |
| | | { |
| | | //如果是水检,还要扫工位 |
| | | if (txt_gx.Text.Trim() == fGxShouJian) |
| | | { |
| | | txt_gongWei.Focus(); |
| | | } |
| | | else |
| | | addModel(goodTag); |
| | | } |
| | | }; |
| | | txt_gongWei.KeyDown += (s, e) => |
| | | { |
| | | if (e.KeyCode == Keys.Enter) |
| | | { |
| | | //如果是水检,可以提交了 |
| | | if (txt_gx.Text.Trim() == fGxShouJian) |
| | | { |
| | | addModel(goodTag); |
| | | } |
| | | } |
| | | }; |
| | | btnGood.Click += (s, e) => |
| | | { |
| | |
| | | }; |
| | | frm.ShowDialog(); |
| | | }; |
| | | |
| | | this.ActiveControl = this.txt_barCode; |
| | | txt_barCode.Focus(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据工序,构造不同类型的实体 |
| | | /// 根据工序,构造不同类型的实体,读取不同的数据 |
| | | /// </summary> |
| | | /// <param name="_barCode">条码</param> |
| | | /// <param name="_checkResult">结果</param> |
| | |
| | | _obj.checkResult = _checkResult;//检测结果 |
| | | _obj.processNo = txt_gx.Text.Trim();//工序 |
| | | _obj.banCi = txt_bc.Text.Trim();//班次 |
| | | _obj.gongWei = txt_gw.Text.Trim();//工位 |
| | | _obj.gongWei = txt_gongWei.Text.Trim();//工位 |
| | | _obj.badDescription = _badDescription.Trim();//不良描述 |
| | | if (txt_gx.Text.Trim() == fGxTouRu) |
| | | { |
| | |
| | | _obj.t009 = JNV; |
| | | _obj.t010 = XLV; |
| | | _obj.t011 = GVV; |
| | | //正式上线要清空文本数据 |
| | | //File.WriteAllText(dianJianPath, ""); |
| | | if (isCleanDianJian == true) |
| | | File.WriteAllText(dianJianPath, ""); |
| | | return _obj; |
| | | } |
| | | //水检 |
| | | if (txt_gx.Text.Trim() == fGxShouJian) |
| | | { |
| | | string strCsl1 = "strCsl1"; |
| | | string strSw1 = "strSw1"; |
| | | string strCsl2 = "strCsl2"; |
| | | string strSw2 = "strSw2"; |
| | | string strCsl3 = "strCsl3"; |
| | | string strSw3 = "strSw3"; |
| | | string strCsl4 = "strCsl4"; |
| | | string strSw4 = "strSw4"; |
| | | string strCsl5 = "strCsl5"; |
| | | string strSw5 = "strSw5"; |
| | | string SJJG = ""; |
| | | string strCsl1 = "";//模式1出水量 |
| | | string strSw1 = "";//模式1水温 |
| | | string strCsl2 = ""; |
| | | string strSw2 = ""; |
| | | string strCsl3 = ""; |
| | | string strSw3 = ""; |
| | | string strCsl4 = ""; |
| | | string strSw4 = ""; |
| | | string strCsl5 = ""; |
| | | string strSw5 = ""; |
| | | string SJJG = "";//水检查结果ok、ng |
| | | string GWZT = "";//工位状态 |
| | | string SJJGZ = "";//水检查结果1 |
| | | (strCsl1, strSw1, SJJG, GWZT, SJJGZ) = getShuiJian(); |
| | | _obj.t002 = strCsl1; |
| | | _obj.t003 = strSw1; |
| | | _obj.t004 = strCsl2; |
| | |
| | | _obj.t009 = strSw4; |
| | | _obj.t010 = strCsl5; |
| | | _obj.t011 = strSw5; |
| | | // _obj.t012 = SJJG;这个待确定 |
| | | _obj.t012 = SJJGZ; |
| | | _obj.t013 = GWZT; |
| | | return _obj; |
| | | } |
| | | //终检 |
| | | if (txt_gx.Text.Trim() == fGxZhongJian) |
| | | { |
| | | return _obj; |
| | |
| | | Toast vm = new Toast((goodTag == "√" ? 1 : -1), _msg); |
| | | vm.Show(); |
| | | } |
| | | ; |
| | | } |
| | | else |
| | | { |
| | |
| | | vm.Show(); |
| | | } |
| | | txt_barCode.Text = ""; |
| | | txt_gongWei.Text = ""; |
| | | this.ActiveControl = this.txt_barCode; |
| | | txt_barCode.Focus(); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | layShuiJian.Visibility = LayoutVisibility.Always; |
| | | else |
| | | layShuiJian.Visibility = LayoutVisibility.Never; |
| | | |
| | | List<dynamic> _lst = new List<dynamic>(); |
| | | if (txt_gx.Text.Trim() == fGxDianJian) |
| | | { |
| | |
| | | { |
| | | ziduan = "t007", |
| | | wenben = "接地结果", |
| | | kejian = true, |
| | | visibleIndex = 1, |
| | | visibleIndex = -1, |
| | | }); |
| | | _lst.Add(new |
| | | { |
| | | ziduan = "t009", |
| | | wenben = "交耐结果", |
| | | kejian = true, |
| | | visibleIndex = 1, |
| | | visibleIndex = -1, |
| | | }); |
| | | _lst.Add(new |
| | | { |
| | | ziduan = "t010", |
| | | wenben = "泄漏结果", |
| | | kejian = true, |
| | | visibleIndex = 1, |
| | | visibleIndex = -1, |
| | | }); |
| | | _lst.Add(new |
| | | { |
| | | ziduan = "t011", |
| | | wenben = "功率结果", |
| | | kejian = true, |
| | | visibleIndex = 1, |
| | | visibleIndex = -1, |
| | | }); |
| | | } |
| | | if (txt_gx.Text.Trim() == fGxShouJian) |
| | |
| | | { |
| | | ziduan = "t004", |
| | | wenben = "出水量2", |
| | | kejian = true, |
| | | visibleIndex = 1, |
| | | visibleIndex = -1, |
| | | }); |
| | | _lst.Add(new |
| | | { |
| | | ziduan = "t005", |
| | | wenben = "水温2", |
| | | kejian = true, |
| | | visibleIndex = 1, |
| | | visibleIndex = -1, |
| | | }); |
| | | _lst.Add(new |
| | | { |
| | | ziduan = "t006", |
| | | wenben = "出水量3", |
| | | kejian = true, |
| | | visibleIndex = 1, |
| | | visibleIndex = -1, |
| | | }); |
| | | _lst.Add(new |
| | | { |
| | | ziduan = "t007", |
| | | wenben = "水温3", |
| | | kejian = true, |
| | | visibleIndex = 1, |
| | | visibleIndex = -1, |
| | | }); |
| | | _lst.Add(new |
| | | { |
| | | ziduan = "t008", |
| | | wenben = "出水量4", |
| | | kejian = true, |
| | | visibleIndex = 1, |
| | | visibleIndex = -1, |
| | | }); |
| | | _lst.Add(new |
| | | { |
| | | ziduan = "t009", |
| | | wenben = "水温4", |
| | | kejian = true, |
| | | visibleIndex = 1, |
| | | visibleIndex = -1, |
| | | }); |
| | | _lst.Add(new |
| | | { |
| | | ziduan = "t010", |
| | | wenben = "出水量5", |
| | | kejian = true, |
| | | visibleIndex = 1, |
| | | visibleIndex = -1, |
| | | }); |
| | | _lst.Add(new |
| | | { |
| | | ziduan = "t011", |
| | | wenben = "水温5", |
| | | visibleIndex = -1, |
| | | }); |
| | | _lst.Add(new |
| | | { |
| | | ziduan = "t012", |
| | | wenben = "数据结果", |
| | | kejian = true, |
| | | visibleIndex = 1, |
| | | }); |
| | |
| | | GridColumn newColumn = new GridColumn(); |
| | | newColumn.FieldName = item.ziduan; // 设置与数据源对应的字段名 |
| | | newColumn.Caption = item.wenben; // 设置列的标题 |
| | | //newColumn.Visible = item.visibleIndex; // 设置列是否可见 |
| | | newColumn.VisibleIndex = item.visibleIndex; // 设置列的显示顺序 |
| | | gvMx1.Columns.Add(newColumn); |
| | | } |
| | | } |
| | | |
| | | |
| | | #region 读取水检数据 |
| | | private (string, string, string, string, string) getShuiJian() |
| | | { |
| | | string strCsl1 = ""; //模式1出水量 |
| | | string strSw1 = "";//模式1水温 |
| | | 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) |
| | | { |
| | | ((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) |
| | | { |
| | | ((BaseEdit)this.txt_gongWei).EditValue = (object)""; |
| | | 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 (strCsl1, strSw1, SJJG, GWZT, SJJGZ); |
| | | } |
| | | private DataTable GetDataTable(string SQLString, string tmpBASMIG2) |
| | | { |
| | | using (var connection = new SqlConnection(strConn)) |
| | | { |
| | | var ds = new DataSet(); |
| | | try |
| | | { |
| | | connection.Open(); |
| | | var command = new SqlDataAdapter(SQLString, connection); |
| | | command.Fill(ds, tmpBASMIG2); |
| | | } |
| | | catch (SqlException ex) |
| | | { |
| | | LogHelper.Debug(this.ToString(), ex.Message); |
| | | } |
| | | return ds.Tables[0]; |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | } |
| | | } |