| | |
| | | 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; |
| | | using static DevExpress.XtraPrinting.Native.ExportOptionsPropertiesNames; |
| | | |
| | | namespace Gs.DevApp.DevFrm.Work |
| | | { |
| | | 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 = "√"; |
| | |
| | | /// </summary> |
| | | /// <param name="_fGx">工序</param> |
| | | /// <param name="_fBc">班次</param> |
| | | public Frm_Work01(string _fGx, string _fBc) |
| | | /// <param name="_strinOther">目前为电检路径</param> |
| | | public Frm_Work01(string _fGx, string _fBc, string _strinOther) |
| | | { |
| | | InitializeComponent(); |
| | | gvMx1.IndicatorWidth = 60; |
| | | gvMx1.CustomDrawRowIndicator += (s, e) => |
| | | { |
| | | if (e.Info.IsRowIndicator && e.RowHandle >= 0) |
| | | e.Info.DisplayText = (e.RowHandle + 1).ToString(); |
| | | }; |
| | | txt_gx.Text = _fGx; |
| | | txt_bc.Text = _fBc; |
| | | this.Text = "工序采集 - " + _fGx + " - " + _fBc; |
| | | if (!getConfig()) |
| | | { |
| | | Gs.DevApp.ToolBox.MsgHelper.ShowError("读取配置文件失败,请联系管理员!"); |
| | | } |
| | | txt_dianJianPath.Text = _strinOther; |
| | | dianJianPath = _strinOther; |
| | | this.Text = "工序采集【" + _fGx + " - " + _fBc + "】"; |
| | | label8.Text = _fGx + "数量"; |
| | | 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) => |
| | | { |
| | |
| | | }; |
| | | btnBad.Click += (s, e) => |
| | | { |
| | | UcDictionarySelect frm = new UcDictionarySelect("缺陷描述", " s_type='工序采集不良项目'"); |
| | | string _barCode = txt_barCode.Text.Trim(); |
| | | if (string.IsNullOrEmpty(_barCode)) |
| | | { |
| | | Toast vm = new Toast(-1, "~请先扫追溯码~"); |
| | | vm.Show(); |
| | | return; |
| | | } |
| | | UcDictionarySelect frm = new UcDictionarySelect("工序不良描述", " a.s_type='工序不良描述' and pid<>'00000000-0000-0000-0000-000000000000'"); |
| | | frm.UpdateParent += (ss, ee) => |
| | | { |
| | | System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); |
| | |
| | | }; |
| | | frm.ShowDialog(); |
| | | }; |
| | | this.ActiveControl = this.txt_barCode; |
| | | txt_barCode.Focus(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 先读取配置 |
| | | /// 根据工序,构造不同类型的实体,读取不同的数据 |
| | | /// </summary> |
| | | /// <param name="_barCode">条码</param> |
| | | /// <param name="_checkResult">结果</param> |
| | | /// <param name="_badDescription">不良描述</param> |
| | | /// <returns></returns> |
| | | private bool getConfig() |
| | | { |
| | | string _where = " and 1=1 and defect_code='7001'"; |
| | | var pgq = new PageQueryModel(1, 999999, "a.defect_code", "asc", "", _where); |
| | | var json = JsonConvert.SerializeObject(pgq); |
| | | try |
| | | { |
| | | var strReturn = UtilityHelper.HttpPost("", "MesDefectCodeManager/GetListPage", json); |
| | | var dd = UtilityHelper.ReturnToTablePage(strReturn); |
| | | var dt = dd.rtnData.list; |
| | | if (dt != null && dt.Rows.Count > 0) |
| | | { |
| | | dianJianPath = dt.Rows[0]["defectName"].ToString(); |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MsgHelper.Warning("提示:" + ex.Message); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读取实体 |
| | | /// </summary> |
| | | /// <param name="_barCode"></param> |
| | | /// <param name="_checkResult"></param> |
| | | /// <param name="_badReson"></param> |
| | | /// <returns></returns> |
| | | private dynamic getObj(string _barCode, string _checkResult, string _badReson = "") |
| | | private dynamic getObj(string _barCode, string _checkResult, string _badDescription = "") |
| | | { |
| | | dynamic _obj = new ExpandoObject(); |
| | | _obj.barCode = _barCode; |
| | | _obj.checkResult = _checkResult;//检测结果 |
| | | _obj.processNo = txt_gx.Text.Trim();//工序 |
| | | _obj.banCi = txt_bc.Text.Trim();//班次 |
| | | _obj.gongWei = txt_gw.Text.Trim();//工位 |
| | | _obj.badReson = _badReson.Trim();//不良原因 |
| | | _obj.gongWei = txt_gongWei.Text.Trim();//工位 |
| | | _obj.badDescription = _badDescription.Trim();//不良描述 |
| | | if (txt_gx.Text.Trim() == fGxTouRu) |
| | | { |
| | | return _obj; |
| | | } |
| | | //电检 |
| | | if (txt_gx.Text.Trim() == fGxDianJian) |
| | | { |
| | | string TM = ""; |
| | |
| | | string myStr = File.ReadAllText(dianJianPath, Encoding.Default); |
| | | if (myStr == "") |
| | | { |
| | | return null; |
| | | return _obj; |
| | | } |
| | | File.WriteAllText(dianJianPath, ""); |
| | | JArray dsTemp = JArray.Parse(myStr); |
| | | foreach (var ss in dsTemp) //查找某个字段与值 |
| | | { |
| | |
| | | JN = (((JObject)ss)["JiaoNai"] == null) ? "" : ((JObject)ss)["JiaoNai"]["state"].ToString(); |
| | | XL = (((JObject)ss)["XieLou"] == null) ? "" : ((JObject)ss)["XieLou"]["state"].ToString(); |
| | | GV = (((JObject)ss)["GongLv"] == null) ? "" : ((JObject)ss)["GongLv"]["state"].ToString(); |
| | | JDV = (((JObject)ss)["JieDi"] == null) ? "" : ((JObject)ss)["JieDi"]["value"].ToString().Replace(" ", ", "); |
| | | JDV = (((JObject)ss)["JieDi"] == null) ? "" : ((JObject)ss)["JieDi"]["value"].ToString().Replace(" ", ","); |
| | | JYV = (((JObject)ss)["JueYuan"] == null) ? "" : ((JObject)ss)["JueYuan"]["value"].ToString().Replace(" ", ", "); |
| | | JNV = (((JObject)ss)["JiaoNai"] == null) ? "" : ((JObject)ss)["JiaoNai"]["value"].ToString().Replace(" ", ", "); |
| | | XLV = (((JObject)ss)["XieLou"] == null) ? "" : ((JObject)ss)["XieLou"]["value"].ToString().Replace(" ", ", "); |
| | |
| | | _obj.t009 = JNV; |
| | | _obj.t010 = XLV; |
| | | _obj.t011 = GVV; |
| | | 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 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 = SJJGZ; |
| | | _obj.t013 = GWZT; |
| | | return _obj; |
| | | } |
| | | //终检 |
| | | if (txt_gx.Text.Trim() == fGxZhongJian) |
| | | { |
| | | return _obj; |
| | | } |
| | | return null; |
| | |
| | | /// <summary> |
| | | /// 上报实体 |
| | | /// </summary> |
| | | /// <param name="_checkResult">判定结果</param> |
| | | /// <param name="_badReson">不良原因,可空</param> |
| | | private void addModel(string _checkResult, string _badReson = "") |
| | | /// <param name="_checkResult">结果:√</param> |
| | | /// <param name="_badDescription">不良描述</param> |
| | | private void addModel(string _checkResult, string _badDescription = "") |
| | | { |
| | | string _barCode = txt_barCode.Text.Trim(); |
| | | if (string.IsNullOrEmpty(_barCode)) |
| | |
| | | vm.Show(); |
| | | return; |
| | | } |
| | | dynamic _obj = getObj(_barCode, _checkResult, _badReson); |
| | | if (_obj == null) |
| | | { |
| | | Toast vm = new Toast(-1, "~读取数据失败,请检查设备~"); |
| | | vm.Show(); |
| | | return; |
| | | } |
| | | dynamic _obj = getObj(_barCode, _checkResult, _badDescription); |
| | | try |
| | | { |
| | | string strJson = UtilityHelper.HttpPost("", _webServiceName + "GetModel", JsonConvert.SerializeObject(_obj)); |
| | |
| | | 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"]) |
| | |
| | | { |
| | | Toast vm = new Toast((goodTag == "√" ? 1 : -1), _msg); |
| | | vm.Show(); |
| | | }; |
| | | } |
| | | } |
| | | else |
| | | { |
| | |
| | | Toast vm = new Toast(-1, ex.Message); |
| | | vm.Show(); |
| | | } |
| | | txt_barCode.Text = ""; |
| | | txt_gongWei.Text = ""; |
| | | this.ActiveControl = this.txt_barCode; |
| | | txt_barCode.Focus(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 增加电检取数的列 |
| | | /// 增加电检,水检的列 |
| | | /// </summary> |
| | | public void addColumn() |
| | | { |
| | | //只有电检才显示 |
| | | if (txt_gx.Text.Trim() == fGxDianJian) |
| | | layDianJian.Visibility = LayoutVisibility.Always; |
| | | else |
| | | layDianJian.Visibility = LayoutVisibility.Never; |
| | | //只有水检才显示 |
| | | if (txt_gx.Text.Trim() == fGxShouJian) |
| | | 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 |
| | | |
| | | } |
| | | } |