using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using CoreFS.CA06; using Core.Mes.Client.Comm.Tool; using Core.StlMes.Client.ZGMil.Entity; using Core.Mes.Client.Comm.Server; using System.Windows.Documents; using Infragistics.Win.UltraWinEditors; using Infragistics.Win.UltraWinGrid; using Infragistics.Win; using System.Text.RegularExpressions; using System.Collections; using Core.Mes.Client.Comm.Format; namespace Core.StlMes.Client.ZGMil.Signature { public partial class FrmTubTechnological : FrmBase { public FrmTubTechnological() { InitializeComponent(); } private void FrmTubTechnological_Load(object sender, EventArgs e) { EntityHelper.ShowGridCaption(ultraGrid1.DisplayLayout.Bands[0]); EntityHelper.ShowGridCaption(ultraGrid2.DisplayLayout.Bands[0]); InitBase(); } UltraComboEditor plineCode = new UltraComboEditor(); UltraComboEditor station = new UltraComboEditor(); UltraComboEditor factoryId = new UltraComboEditor(); UltraNumericEditor numEditor = new UltraNumericEditor(); UltraDateTimeEditor dateEditor = new UltraDateTimeEditor(); /// /// 加载基础信息 /// private void InitBase() { string[] arr = null; NativeMethodNew na = new NativeMethodNew(this.ob); arr = na.GetPCodePline(this.ValidDataPurviewIds); InitComboEditor1(plineCode, "com.steering.mes.signature.FrmTubTechnological.doQueryPline", "PLINE_CODE", this.ob, false,arr); BindColumn(plineCode, "PlineName", this.Controls, this.ultraGrid1, 0); InitComboEditor(station, "com.steering.mes.signature.FrmTubTechnological.doQueryStation", "STATION_CODE",this.ob, false); BindColumn(station, "StationDesc", this.Controls, this.ultraGrid1, 0); } /// /// 初始化下拉框 /// /// 下拉框 /// 请求的服务 /// 值成员 /// ob对象 /// 是否有空行 public static void InitComboEditor(UltraComboEditor uce, string methodId, string valueMember, OpeBase ob, bool isEmpty) { DataTable dt = ServerHelper.GetData(methodId, null, ob); if (dt != null && dt.Rows.Count > 0) { if (isEmpty) { Object[] obj = new Object[] { "", "" }; DataRow dr = dt.NewRow(); dr.ItemArray = obj; dt.Rows.InsertAt(dr, 0); } uce.ValueMember = valueMember; uce.DataSource = dt; SetComboItemHeight(uce); } } public static void InitComboEditor2(UltraComboEditor uce, string methodId, string valueMember, OpeBase ob, string value,bool isEmpty) { DataTable dt = ServerHelper.GetData(methodId, new object[] { value }, ob); if (dt != null && dt.Rows.Count > 0) { if (isEmpty) { Object[] obj = new Object[] { "", "" }; DataRow dr = dt.NewRow(); dr.ItemArray = obj; dt.Rows.InsertAt(dr, 0); } uce.ValueMember = valueMember; uce.DataSource = dt; SetComboItemHeight(uce); } } public static void InitComboEditor1(UltraComboEditor uce, string methodId, string valueMember, OpeBase ob, bool isEmpty,string[] arr) { DataTable dt = ServerHelper.GetData(methodId, new object[]{arr}, ob); if (dt != null && dt.Rows.Count > 0) { if (isEmpty) { Object[] obj = new Object[] { "", "" }; DataRow dr = dt.NewRow(); dr.ItemArray = obj; dt.Rows.InsertAt(dr, 0); } uce.ValueMember = valueMember; uce.DataSource = dt; SetComboItemHeight(uce); } } /// /// 将下拉框绑定到GRID列 /// /// 下拉框(已经初始化完成) /// 列名 /// 空间集合(每次只需填入this.Controls) /// GRID /// GRID的第几层结构 public static void BindColumn(UltraComboEditor uce, string ColumnName, System.Windows.Forms.Control.ControlCollection con, UltraGrid ug, int i) { con.Add(uce); uce.Visible = false; ug.DisplayLayout.Bands[i].Columns[ColumnName].EditorComponent = uce; ug.DisplayLayout.Bands[i].Columns[ColumnName].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList; SetComboItemHeight(uce); } /// /// 设置UltraComboEditor中的中文和非中文统一高度。 /// /// public static void SetComboItemHeight(UltraComboEditor cmb) { foreach (ValueListItem item in cmb.Items) { if (Regex.IsMatch(item.DisplayText, @"[\u4e00-\u9fa5]+")) { item.Appearance.FontData.SizeInPoints = 9.0F; } else { item.Appearance.FontData.SizeInPoints = 10.5F; } } } /// /// 重写基类方法 /// /// /// public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "Query": doQueryData(); break; case "Add": doAdd(); break; case"Update": doUpdate(); break; case"Delete": doDelete(); break; case "Close": this.Close(); break; } } /// /// 删除工艺项 /// private void doDelete() { UltraGridRow urg = ultraGrid2.ActiveRow; if (urg == null) { MessageUtil.ShowTips("无数据!"); return; } this.ultraGrid2.UpdateData(); IQueryable checkMagRows = this.ultraGrid2.Rows.AsQueryable().Where(" CHK = 'True'"); if (checkMagRows.Count() == 0) { if (MessageUtil.ShowYesNoAndQuestion("是否作废该项所有工艺项?") == DialogResult.No) { MessageUtil.ShowTips("请选择需要作废的的工艺项!"); return; } else { foreach (UltraGridRow row1 in ultraGrid2.Rows) { row1.Cells["CHK"].Value = true; } } } IQueryable checkMagRows1 = this.ultraGrid2.Rows.AsQueryable().Where(" CHK = 'True'"); ArrayList parm = new ArrayList(); foreach (UltraGridRow row in checkMagRows1) { MilCraftworkSetEntity _milCraftEntity = EntityHelper.CopyEntity(row.ListObject); string _milCraftTity = JSONFormat.Format(_milCraftEntity); parm.Add(_milCraftTity); } if (MessageUtil.ShowYesNoAndQuestion("是否确认作废工艺项?") == DialogResult.No) { return; } CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.mes.signature.FrmTubTechnological"; ccp.MethodName = "doDeleteData"; ccp.ServerParams = new object[] { parm }; ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { if (ccp.ReturnInfo.Equals("作废成功!")) { doQueryData(); MessageUtil.ShowTips(ccp.ReturnInfo); } } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } /// /// 修改工艺项 /// private void doUpdate() { this.ultraGrid2.UpdateData(); IQueryable checkMagRows = this.ultraGrid2.Rows.AsQueryable().Where(" CHK = 'True'"); if (checkMagRows.Count() == 0) { MessageUtil.ShowTips("请选择需要修改的的工艺项!"); return; } ArrayList parm = new ArrayList(); foreach (UltraGridRow row in checkMagRows) { if (row.Cells["FactorName"].Text.ToString() == "" || row.Cells["FactorVal"].Text.ToString() == "") { MessageUtil.ShowTips("工艺项/工艺参数都不能为空!"); return; } MilCraftworkSetEntity _milCraftEntity = EntityHelper.CopyEntity(row.ListObject); _milCraftEntity.FactorId = row.Cells["FactorName"].Value.ToString(); _milCraftEntity.FactorName = row.Cells["FactorName"].Text.Trim(); _milCraftEntity.UpdateName = this.UserInfo.GetUserName(); string _milCraftTity = JSONFormat.Format(_milCraftEntity); parm.Add(_milCraftTity); } if (MessageUtil.ShowYesNoAndQuestion("是否修改工艺项?") == DialogResult.No) { return; } CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.mes.signature.FrmTubTechnological"; ccp.MethodName = "doUpdateData"; ccp.ServerParams = new object[] {parm}; ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { if (ccp.ReturnInfo.Equals("修改成功!")) { doQueryData(); MessageUtil.ShowTips(ccp.ReturnInfo); } } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } /// /// 查询已维护的工艺参数 /// private void doQueryData() { string[] arr = null; NativeMethodNew na = new NativeMethodNew(this.ob); arr = na.GetPCodePline(this.ValidDataPurviewIds); List listSource = EntityHelper.GetData("com.steering.mes.signature.FrmTubTechnological.doQueryData", new object[] { arr }, ob); MilCraftworkSetEntitybindingSource.DataSource = listSource; } /// /// 维护工艺参数 /// private void doAdd() { this.ultraGrid1.UpdateData(); this.ultraGrid2.UpdateData(); UltraGridRow uRow = this.ultraGrid1.ActiveRow; if (!(uRow.Cells["PlineName"].Text.ToString() != "" && uRow.Cells["StationDesc"].Text.ToString() != "" && uRow.Cells["ClassName"].Text.Trim() != "")) { MessageUtil.ShowTips("机组/工序点/版本号都不允许为空!"); return; } List ss = new List(); ArrayList list = new ArrayList(); MilCraftworkSetEntity milCraftEntity = EntityHelper.CopyEntity(uRow.ListObject); if (milCraftEntity.PlineCode.Equals("")) { milCraftEntity.PlineCode = uRow.Cells["PlineName"].Value.ToString(); milCraftEntity.PlineName = uRow.Cells["PlineName"].Text.Trim(); milCraftEntity.StationCode = uRow.Cells["StationDesc"].Value.ToString(); milCraftEntity.StationDesc = uRow.Cells["StationDesc"].Text.Trim(); milCraftEntity.CreateName = this.UserInfo.GetUserName(); } else { milCraftEntity.CreateName = this.UserInfo.GetUserName(); } string milCraftTity = JSONFormat.Format(milCraftEntity); list.Add(milCraftTity); IQueryable checkMagRows = this.ultraGrid2.Rows.AsQueryable().Where(" CHK = 'True'"); if (checkMagRows.Count() == 0) { MessageUtil.ShowTips("请选择需要维护的工艺项!"); return; } ArrayList parm = new ArrayList(); foreach(UltraGridRow row in checkMagRows) { if (row.Cells["FactorName"].Text.ToString() == "" || row.Cells["FactorVal"].Text.ToString() == "") { MessageUtil.ShowTips("工艺项/工艺参数都不能为空!"); return; } MilCraftworkSetEntity _milCraftEntity = EntityHelper.CopyEntity (row.ListObject); _milCraftEntity.FactorId = row.Cells["FactorName"].Value.ToString(); _milCraftEntity.FactorName = row.Cells["FactorName"].Text.Trim(); string _milCraftTity = JSONFormat.Format(_milCraftEntity); parm.Add(_milCraftTity); if (ss.Contains(_milCraftEntity.FactorName.ToString())) { MessageUtil.ShowTips("已选择相同工艺项,不允许重复!"); return; } else { ss.Add(_milCraftEntity.FactorName.ToString()); } } if (!getCraftSet(uRow.Cells["PlineName"].Value.ToString2(), uRow.Cells["StationDesc"].Value.ToString2(), uRow.Cells["ClassName"].Text.Trim())) { MessageUtil.ShowTips("已存在该版本名称,不允许重复!"); return; } if (MessageUtil.ShowYesNoAndQuestion("是否维护工艺参数?") == DialogResult.No) { return; } CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.mes.signature.FrmTubTechnological"; ccp.MethodName = "doAdd"; ccp.ServerParams = new object[] {list,parm }; ccp = ob.ExecuteNonQuery(ccp,CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { if (ccp.ReturnInfo.Equals("维护成功!")) { doQueryData(); MessageUtil.ShowTips(ccp.ReturnInfo); } } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } /// /// 判断是否已有相同产线版本 /// /// private bool getCraftSet(string plineCode,string stationId,string className) { DataTable ds = ServerHelper.GetData("com.steering.mes.signature.FrmTubTechnological.getCraftSet", new object[] { plineCode, stationId, className }, ob); if (ds.Rows.Count > 0) { return false; } else { return true; } } private void doQueryData(string className,string stationCode,string plineCode) { List listSource = EntityHelper.GetData("com.steering.mes.signature.FrmTubTechnological.doQuery", new object[] { className, stationCode, plineCode }, ob); MilCraftworkSetEntity1bindingSource.DataSource = listSource; } private void ultraGrid1_AfterRowActivate(object sender, EventArgs e) { doQueryData(this.ultraGrid1.ActiveRow.Cells["ClassName"].Value.ToString(), this.ultraGrid1.ActiveRow.Cells["stationCode"].Value.ToString(), this.ultraGrid1.ActiveRow.Cells["PlineCode"].Value.ToString()); } private void ultraGrid2_CellChange(object sender, CellEventArgs e) { ultraGrid2.UpdateData(); UltraGridRow ugr = this.ultraGrid2.ActiveRow; string factorId = ""; if (e.Cell.Column.Key.Equals("FactorName")) { factorId = this.ultraGrid2.ActiveRow.Cells["FactorName"].Value.ToString(); DataTable ds = ServerHelper.GetData("com.steering.mes.signature.FrmTubTechnological.doQueryType", new object[] { factorId }, ob); if (ds.Rows.Count > 0) { if (ds.Rows[0]["COLUMN_TYPE"].ToString() == "D") { this.ultraGrid2.ActiveRow.Cells["FactorVal"].Value = ""; ugr.Cells["FactorVal"].EditorComponent = numEditor; numEditor.NumericType = NumericType.Decimal; numEditor.MaskInput = "nnnnn.nnn"; } else if (ds.Rows[0]["COLUMN_TYPE"].ToString() == "T") { this.ultraGrid2.ActiveRow.Cells["FactorVal"].Value = ""; ugr.Cells["FactorVal"].EditorComponent = dateEditor; dateEditor.FormatString = "yyyy-MM-dd HH:mm:ss"; } else { this.ultraGrid2.ActiveRow.Cells["FactorVal"].Value = ""; ugr.Cells["FactorVal"].EditorComponent = null; } } } } private void ultraGrid1_CellChange(object sender, CellEventArgs e) { this.ultraGrid1.UpdateData(); if (e.Cell.Column.Key == "StationDesc") { InitComboEditor2(factoryId, "com.steering.mes.signature.FrmTubTechnological.doQueryFactor", "FACTOR_ID",this.ob, this.ultraGrid1.ActiveRow.Cells["StationDesc"].Value.ToString2(), false); BindColumn(factoryId, "FactorName", this.Controls, this.ultraGrid2, 0); } } } }