using Core.Mes.Client.Comm.Format; 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 ComBaseStdRTestCtrl : UserControl { private ComBaseStdRTestBLL _comBaseStdRTestBLL; private OpeBase _ob; //查询条件 private string _phyNameMin = ""; private string _validflag = ""; public ComBaseStdRTestCtrl(System.Windows.Forms.Control container, OpeBase ob) { InitializeComponent(); _ob = ob; _comBaseStdRTestBLL = new ComBaseStdRTestBLL(ob); container.Controls.Add(this); this.Dock = DockStyle.Fill; EntityHelper.ShowGridCaption(ultraGrid1.DisplayLayout.Bands[0]); } public void Query(string phyNameMin, string validflag) { _validflag = validflag; _phyNameMin = phyNameMin; comBaseStdRTestEntityBindingSource.DataSource = _comBaseStdRTestBLL.Query(phyNameMin, validflag); foreach (UltraGridRow row in ultraGrid1.Rows) { GridEdite(row); } } public void Relocate(string phyCodeMin) { Query(_phyNameMin, _validflag); var row = ultraGrid1.Rows.AsQueryable().Where(a => a.GetValue("PhyCodeMin") == phyCodeMin).FirstOrDefault(); if (row != null) { row.Activate(); } } public void Save() { var rows = ultraGrid1.Rows.AsQueryable().Where(a => a.GetValue("Chk") == "True"); if (rows.Count() == 0) { MessageUtil.ShowWarning("请选择一条记录!"); return; } List parms = new List(); foreach (var row in rows) { ComBaseStdRTestEntity stdRTestEntity = EntityHelper.CopyEntity(row.ListObject); if (stdRTestEntity.PhyCodeMin == "") { MessageUtil.ShowWarning("请选择试样组!"); row.SetCellActive("PhyNameMin"); return; } if (stdRTestEntity.StdCodeTest == "") { MessageUtil.ShowWarning("请选择试验标准!"); row.SetCellActive("StdNameTest"); return; } if (_comBaseStdRTestBLL.GetRepateCnt(stdRTestEntity.StdCodeTest, stdRTestEntity.PhyCodeMin, stdRTestEntity.Pk) > 0) { MessageUtil.ShowWarning("系统已存在 试样组:" + stdRTestEntity.PhyNameMin + " + 试验标准:" + stdRTestEntity.StdNameTest + "的组合!"); return; } if (stdRTestEntity.LevelTest == null) { stdRTestEntity.LevelTest = 1; } stdRTestEntity.CreateName = CoreUserInfo.UserInfo.GetUserName(); stdRTestEntity.UpdateName = CoreUserInfo.UserInfo.GetUserName(); parms.Add(stdRTestEntity); } if (MessageUtil.ShowYesNoAndQuestion("是否确认保存?") == DialogResult.No) { return; } _comBaseStdRTestBLL.Save(parms); MessageUtil.ShowTips("保存成功!"); Relocate(parms[0].PhyCodeMin); } public List GetSaveParms() { ultraGrid1.UpdateData(); var rows = ultraGrid1.Rows.AsQueryable().Where(a => a.GetValue("Chk") == "True"); List parms = new List(); foreach (var row in rows) { ComBaseStdRTestEntity stdRTestEntity = EntityHelper.CopyEntity(row.ListObject); if (stdRTestEntity.StdNameTest == "") { MessageUtil.ShowWarning("请选择试验标准!"); row.SetCellActive("StdNameTest"); return null; } else if (stdRTestEntity.PhyNameMin == "") { MessageUtil.ShowWarning("请选择试样组!"); row.SetCellActive("PhyNameMin"); return null; } else if (stdRTestEntity.LevelTest == null) { MessageUtil.ShowWarning("请输入优先级!"); row.SetCellActive("LevelTest"); return null; } stdRTestEntity.CreateName = CoreUserInfo.UserInfo.GetUserName(); stdRTestEntity.UpdateName = CoreUserInfo.UserInfo.GetUserName(); parms.Add(JSONFormat.Format(stdRTestEntity)); } return parms; } public void UpdateValidflag(string validflag) { var rows = ultraGrid1.Rows.AsQueryable().Where(a => a.GetValue("Chk") == "True"); if (rows.Count() == 0) { MessageUtil.ShowWarning("请选择记录!"); return; } List parms = new List(); foreach (var row in rows) { ComBaseStdRTestEntity stdRTestEntity = EntityHelper.CopyEntity(row.ListObject); stdRTestEntity.DeleteName = CoreUserInfo.UserInfo.GetUserName(); stdRTestEntity.UpdateName = CoreUserInfo.UserInfo.GetUserName(); parms.Add(stdRTestEntity); } if (MessageUtil.ShowYesNoAndQuestion("是否确认" + (validflag == "0" ? "作废" : "恢复") + "选择的记录?") == DialogResult.No) { return; } _comBaseStdRTestBLL.UpdateValidflag(parms, validflag); MessageUtil.ShowTips((validflag == "0" ? "作废" : "恢复") + "成功!"); Relocate(parms[0].PhyCodeMin); } public List GetUpdateValidflagParms() { ultraGrid1.UpdateData(); var rows = ultraGrid1.Rows.AsQueryable().Where(a => a.GetValue("Chk") == "True"); List parms = new List(); foreach (var row in rows) { ComBaseStdRTestEntity stdRTestEntity = EntityHelper.CopyEntity(row.ListObject); stdRTestEntity.DeleteName = CoreUserInfo.UserInfo.GetUserName(); stdRTestEntity.UpdateName = CoreUserInfo.UserInfo.GetUserName(); parms.Add(JSONFormat.Format(stdRTestEntity)); } return parms; } private void ultraGrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e) { if (e.Row.GetValue("Validflag") == "无效") { e.Row.Appearance.ForeColor = Color.Red; } } private void ultraGrid1_AfterRowInsert(object sender, Infragistics.Win.UltraWinGrid.RowEventArgs e) { ultraGrid1.UpdateData(); } private void ultraTextEditor1_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e) { if (ultraGrid1.ActiveCell.Column.Key == "StdNameTest") { //DataTable dt = _comBaseStdRTestBLL.GetComBaseStdS(); //dt.Columns["STD_NAME"].Caption = "试验标准"; //BaseInfoPopup baseInfoPopup = new BaseInfoPopup(dt, "STD_NAME", "STD_CODE"); //baseInfoPopup.LabelTextBox1.Caption = "试验标准"; //var row = baseInfoPopup.UltraGrid1.Rows.AsQueryable().Where( // a => a.GetValue("STD_CODE") == ultraGrid1.ActiveRow.GetValue("StdCodeTest")).FirstOrDefault(); //if (row != null) //{ // row.Activate(); //} //if (baseInfoPopup.ShowDialog() == DialogResult.OK) //{ // ultraGrid1.ActiveRow.SetValue("StdCodeTest", baseInfoPopup.ChoicedRow.GetValue("STD_CODE")); // ultraGrid1.ActiveRow.SetValue("StdNameTest", baseInfoPopup.ChoicedRow.GetValue("STD_NAME")); //} string stdCodes = ultraGrid1.ActiveRow.GetValue("StdCodeTest"); ComBaseStdChoice baseStdChoice = new ComBaseStdChoice(new string[] { "S" }, stdCodes, _ob); if (baseStdChoice.ShowDialog() == DialogResult.OK) { ultraGrid1.ActiveRow.SetValue("StdCodeTest", baseStdChoice.ChoiceStdCodes); ultraGrid1.ActiveRow.SetValue("StdNameTest", baseStdChoice.ChoiceStdNames); } } else if (ultraGrid1.ActiveCell.Column.Key == "PhyNameMin") { DataTable dt = _comBaseStdRTestBLL.GetComBasePhyC(); dt.Columns["PHY_TYPE"].Caption = "试样组"; BaseInfoPopup baseInfoPopup = new BaseInfoPopup(dt, "PHY_TYPE", "PHY_CODE"); baseInfoPopup.LabelTextBox1.Caption = "试样组"; var row = baseInfoPopup.UltraGrid1.Rows.AsQueryable().Where( a => a.GetValue("PHY_CODE") == ultraGrid1.ActiveRow.GetValue("PhyCodeMin")).FirstOrDefault(); if (row != null) { row.Activate(); } if (baseInfoPopup.ShowDialog() == DialogResult.OK) { ultraGrid1.ActiveRow.SetValue("PhyCodeMin", baseInfoPopup.ChoicedRow.GetValue("PHY_CODE")); ultraGrid1.ActiveRow.SetValue("PhyNameMin", baseInfoPopup.ChoicedRow.GetValue("PHY_TYPE")); } } } 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 ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { } private void ultraGrid1_CellChange(object sender, CellEventArgs e) { e.Cell.Row.Update(); GridEdite(e.Cell.Row); } } }