using Core.Mes.Client.Comm.Tool; using Core.StlMes.Client.Qcm.BLL; using Core.StlMes.Client.Qcm.model; using CoreFS.CA06; using CoreFS.SA06; using Infragistics.Win.UltraWinGrid; using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Linq; using System.Windows.Forms; namespace Core.StlMes.Client.Qcm.Control { public partial class ComBaseImpactCtrl : UserControl { private ComBaseImpactBLL _impactBLL; public ComBaseImpactCtrl(System.Windows.Forms.Control container, OpeBase ob) { InitializeComponent(); _impactBLL = new ComBaseImpactBLL(ob); this.Dock = DockStyle.Fill; container.Controls.Add(this); } private string _impact = ""; private string _validflag = ""; public void Query(string impact, string validflag) { this.comBaseImpactEntityBindingSource.DataSource = _impactBLL.Query(impact, validflag); foreach (var row in entityGrid1.Rows) { GridEdite(row); } } public void Save(List subParms, List subTempParms) { if (entityGrid1.ActiveRow == null) { MessageUtil.ShowWarning("请选择一条记录!"); return; } var row = entityGrid1.Rows.Where(a => a.GetValue("Chk") == "True").FirstOrDefault(); if (row == null && subParms.Count == 0 && subTempParms.Count == 0) { MessageUtil.ShowWarning("请选择一条记录!"); return; } ComBaseImpactEntity parm = null; if (row != null) { parm = EntityHelper.CopyEntity(row.ListObject); if (parm.AllowArc == null) { MessageUtil.ShowWarning("请选择是否允许弧形样!"); row.SetCellActive("AllowArc"); return; } if (parm.AllowArc == true) { if (parm.MinSideArc == null) { MessageUtil.ShowWarning("请输入弧形样侧边最短(%)!"); row.SetCellActive("MinSideArc"); return; } if (parm.MinAboveArc == null) { MessageUtil.ShowWarning("弧形样上边最短(mm)!"); row.SetCellActive("MinAboveArc"); return; } } if (parm.ProcessSurplus == null) { MessageUtil.ShowWarning("加工余量(mm)不能为空!"); row.SetCellActive("ProcessSurplus"); return; } parm.CreateName = CoreUserInfo.UserInfo.GetUserName(); parm.UpdateName = CoreUserInfo.UserInfo.GetUserName(); } if (MessageUtil.ShowYesNoAndQuestion("是否确认保存?") == DialogResult.No) { return; } _impactBLL.Save(parm, subParms, subTempParms); MessageUtil.ShowTips("保存成功!"); string id = entityGrid1.ActiveRow.GetValue("Id"); Relocate(id, _validflag); } public void Relocate(string id, string validflag) { Query(_impact, validflag); var row = entityGrid1.Rows.AsQueryable().Where(a => a.GetValue("Id") == id).FirstOrDefault(); if (row != null) { row.Activate(); } } public void UpdateValidflag(string flag) { entityGrid1.UpdateData(); var rows = entityGrid1.Rows.AsQueryable().Where(a => a.GetValue("Chk") == "True") .Select(a => EntityHelper.CopyEntity(a.ListObject)).ToList(); string id = ""; foreach (var row in rows) { row.DeleteName = CoreUserInfo.UserInfo.GetUserName(); row.UpdateName = CoreUserInfo.UserInfo.GetUserName(); id = row.Id; } _impactBLL.UpdateValidflag(rows, flag); } private void entityGrid1_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e) { e.Cell.Row.Update(); GridEdite(e.Cell.Row); if (e.Cell.Column.Key == "Chk") { UltraGridRow chkRow = e.Cell.Row; foreach (UltraGridRow row in entityGrid1.Rows) { if (row.Cells["Chk"].Value.ToString() == "True" && row != chkRow) { row.Cells["Chk"].Value = "False"; row.Update(); } } } } private void GridEdite(UltraGridRow row) { if (row.GetValue("Chk") == "True") { foreach (UltraGridCell cell in row.Cells) { if (cell.Column.CellActivation == Activation.AllowEdit) { cell.Activation = Activation.AllowEdit; } } } else { foreach (UltraGridCell cell in row.Cells) { if (cell.Column.Key == "Chk") continue; if (cell.Column.CellActivation == Activation.AllowEdit) { cell.Activation = Activation.ActivateOnly; } } } } private void entityGrid1_AfterRowActivate(object sender, EventArgs e) { } private void entityGrid1_AfterRowInsert(object sender, RowEventArgs e) { e.Row.Cells["AllowArc"].Value = false; } private void entityGrid1_InitializeRow(object sender, InitializeRowEventArgs e) { if (e.Row.GetValue("Validflag") == "无效") { e.Row.Appearance.ForeColor = Color.Red; } } } }