using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm.Server; using Core.Mes.Client.Comm.Tool; using CoreFS.CA06; using Infragistics.Win.UltraWinEditors; using Infragistics.Win.UltraWinGrid; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Linq; using System.Windows.Forms; namespace Core.StlMes.Client.Qcm { public partial class FrmProductGrade : FrmBase { List list = new List(); int number = 0; private int _index; //临时索引列 public FrmProductGrade() { InitializeComponent(); ExceptionHelper.RegistException(); } public void PopupLoad(string customInfo, OpeBase ob) { this.CustomInfo = customInfo; this.ob = ob; this.OnLoad(EventArgs.Empty); } private void FrmProductGrade_Load(object sender, EventArgs e) { BindcmbType(); } private void BindcmbType() { #region 下拉列表 DataTable dt1 = new DataTable(); dt1.Columns.Add("xiaid"); DataRow dr1 = dt1.NewRow(); dr1["xiaid"] = ">"; dt1.Rows.Add(dr1); DataRow dr2 = dt1.NewRow(); dr2["xiaid"] = ">="; dt1.Rows.Add(dr2); DataRow dr3 = dt1.NewRow(); dr3["xiaid"] = "="; dt1.Rows.Add(dr3); DataRow dr4 = dt1.NewRow(); dr4["xiaid"] = " "; dt1.Rows.Add(dr4); dt1.Columns["xiaid"].Caption = "符号"; xiaxian.DataSource = dt1; xiaxian.ValueMember = "xiaid"; DataTable dt2 = new DataTable(); dt2.Columns.Add("shangid"); DataRow dr5 = dt2.NewRow(); dr5["shangid"] = "<"; dt2.Rows.Add(dr5); DataRow dr6 = dt2.NewRow(); dr6["shangid"] = "<="; dt2.Rows.Add(dr6); DataRow dr7 = dt2.NewRow(); dr7["shangid"] = " "; dt2.Rows.Add(dr7); dt2.Columns["shangid"].Caption = "符号"; shangxian.DataSource = dt2; shangxian.ValueMember = "shangid"; DataTable dt3 = ServerHelper.GetData("com.steering.pss.qcm.CoreDropList.GetDropFenLei", new Object[] { }, this.ob); int num = dt3.Rows.Count; DataTable dt4 = new DataTable(); dt4.Columns.Add("fenlei"); dt4.Columns.Add("fenname"); DataRow dr; for (int i = 0; i < num; i++) { dr = dt4.NewRow(); dr["fenlei"] = dt3.Rows[i]["BASENAME"]; dr["fenname"] = dt3.Rows[i]["BASECODE"]; dt4.Rows.Add(dr); } dt4.Columns["fenlei"].Caption = "钢种类型"; dt4.Columns["fenname"].Caption = "钢种代码"; fenleinumber.DataSource = dt4; fenleinumber.ValueMember = "fenname"; fenleinumber.DisplayMember = "fenlei"; ClsBaseInfo.SetComboItemHeight(fenleinumber); DataTable dt5 = ServerHelper.GetData("com.steering.pss.qcm.CoreDropList.GetSelect", new Object[] { }, this.ob); int num1 = dt5.Rows.Count; DataTable dt6 = new DataTable(); dt6.Columns.Add("id"); dt6.Columns.Add("name"); for (int i = 0; i < num1; i++) { dr = dt6.NewRow(); dr["id"] = dt5.Rows[i]["CHEM_CODE"]; dr["name"] = dt5.Rows[i]["CHEM_NAME"]; dt6.Rows.Add(dr); } dt6.Columns["id"].Caption = "类型"; dt6.Columns["name"].Caption = "名字"; yuanfenlei.DataSource = dt6; yuanfenlei.ValueMember = "id"; yuanfenlei.DisplayMember = "name"; #endregion } /// /// 初始下拉框 /// /// 数据表 /// 下拉框 /// 方法名 /// 描述 /// 代码 private void InitDropList(ref DataTable dt, UltraComboEditor uce, string methodId, string desc) { dt = ServerHelper.GetData(methodId, null, this.ob); if (dt != null && dt.Rows.Count > 0) { uce.DataSource = dt; uce.Text = desc; uce.DisplayMember = desc; } } public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "doQuery": try { this.Cursor = Cursors.WaitCursor; doQuery(false); } finally { this.Cursor = Cursors.Default; } break; case "doSave": doSave(); break; case "QueryKey": try { this.Cursor = Cursors.WaitCursor; doQuery(true); } finally { this.Cursor = Cursors.Default; } break; case "doDelete": this.doDeleteOrResume(true); break; case "doResume": this.doDeleteOrResume(false); break; case "Refresh": BindcmbType(); break; case "Export": GridHelper.ulGridToExcel(ultraGrid2, "钢种信息"); break; case "doClose": this.Close(); break; } } private void doSave() { number = 0; int count = 0; foreach (UltraGridRow row in ultraGrid2.Rows) { if (row.GetValue("cb") == "True") { count++; } foreach (UltraGridRow row2 in row.ChildBands[0].Rows) { if (row2.GetValue("check2") == "True") { count++; } } } if (count == 0) { MessageBox.Show("您当前没有勾选任何行!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } int chkCnt = ultraGrid2.Rows.AsQueryable().Where("cb = 'True'").Count(); int dstCnt = ultraGrid2.Rows.AsQueryable().Where("cb = 'True'") .Select(a => a.GetValue("GRADENAME")).Distinct().Count(); if (chkCnt != dstCnt) { MessageUtil.ShowWarning("钢种名称不能重复!"); return; } save(); } private bool CheckGrd(UltraGridRow row) { if (row.Cells["COEFFICIENT"].Value.ToString().Length > 5) { MessageBox.Show("钢种系数填写错误,总长度4位 小数2位!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } if (row.Cells["GRADENAME"].Value.ToString() == "") { MessageBox.Show("请输入钢种名称!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } if (row.GetValue("VALIDFLAG") == "") { if (isExistGradeName(row.Cells["GRADENAME"].Value.ToString()) == true) { MessageUtil.ShowWarning("系统已存在钢种名称[" + row.Cells["GRADENAME"].Value.ToString() + "]!"); row.Cells["GRADENAME"].Activate(); return false; } } else { if (row.Cells["GRADENAME"].Value.ToString() != row.Cells["GRADENAME_OLD"].Value.ToString()) { if (isExistGradeName(row.Cells["GRADENAME"].Value.ToString()) == true) { MessageUtil.ShowWarning("系统已存在钢种名称[" + row.Cells["GRADENAME"].Value.ToString() + "]!"); row.Cells["GRADENAME"].Activate(); return false; } } } if (row.Cells["ASSORTMENT_NAME"].Value.ToString() == "") { MessageBox.Show("请输入钢种分类名称!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } if (row.Cells["COEFFICIENT"].Value.ToString() == "") { MessageBox.Show("请输入钢种系数!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } return true; } private bool CheckGrdChm(UltraGridRow row, string gradeCode) { if (row.Cells["CHEM_NAME"].Value.ToString() == "") { MessageBox.Show("请选择化学元素描述!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } if (row.Cells["STDMIN"].Value.ToString().Length > 10) { MessageBox.Show("范围下限值最大只能输入十位数!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } if (row.Cells["STDMAX"].Value.ToString().Length > 10) { MessageBox.Show("范围上限值最大只能输入十位数!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } if (row.Cells["STDMIN_SIGN"].Value.ToString() != "") { try { double.Parse(row.Cells["STDMIN"].Value.ToString()); } catch { MessageBox.Show("范围下限值类型输入错误!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } } if (row.Cells["STDMAX_SIGN"].Value.ToString() != "") { try { double.Parse(row.Cells["STDMAX"].Value.ToString()); } catch { MessageBox.Show("范围上限值类型输入错误!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } } if (row.Cells["STDMIN_SIGN"].Value.ToString() != "" && row.Cells["STDMAX_SIGN"].Value.ToString() != "") { try { if (double.Parse(row.Cells["STDMIN"].Value.ToString()) > double.Parse(row.Cells["STDMAX"].Value.ToString())) { MessageBox.Show("成分的最小值不能比最大值大!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } } catch { MessageBox.Show("输入类型错误!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } } if (row.GetValue("VALIDFLAG") == "") { DataTable dtbs = ServerHelper.GetData("com.steering.pss.qcm.CoreSpecificationsGradeChem.SelectCode", new Object[] { gradeCode, row.Cells["CHEM_CODE"].Value.ToString() }, this.ob); if (Convert.ToInt32(dtbs.Rows[0][0]) > 0) { MessageBox.Show("此条记录已存在,请核实!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } } else { if (row.GetValue("CHEM_CODE") != row.GetValue("CHEM_CODE_OLD")) { DataTable dtbs = ServerHelper.GetData("com.steering.pss.qcm.CoreSpecificationsGradeChem.SelectCode", new Object[] { gradeCode, row.Cells["CHEM_CODE"].Value.ToString() }, this.ob); if (Convert.ToInt32(dtbs.Rows[0][0]) > 0) { MessageBox.Show("此条记录已存在,请核实!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } } } return true; } private void save() { ultraGrid2.UpdateData(); ArrayList listGrds = new ArrayList(); for (int i = 0; i < ultraGrid2.Rows.Count; i++) { ArrayList parm = new ArrayList(); if (Convert.ToBoolean(ultraGrid2.Rows[i].Cells["cb"].Value)) { if (CheckGrd(ultraGrid2.Rows[i]) == false) return; parm.Add(ultraGrid2.Rows[i].Cells["GRADENAME"].Value.ToString()); parm.Add(ultraGrid2.Rows[i].Cells["ASSORTMENT_CODE"].Value.ToString()); parm.Add(ultraGrid2.Rows[i].Cells["ASSORTMENT_NAME"].Text.ToString()); parm.Add(ultraGrid2.Rows[i].Cells["COEFFICIENT"].Value.ToString()); parm.Add(this.UserInfo.GetUserName()); parm.Add(ultraGrid2.Rows[i].Cells["MEMO"].Value.ToString()); parm.Add(ultraGrid2.Rows[i].GetValue("ALLOW_BUY") == "True" ? "1" : "0"); parm.Add(ultraGrid2.Rows[i].Cells["GRADECODE"].Value.ToString()); parm.Add(ultraGrid2.Rows[i].Cells["VALIDFLAG"].Value.ToString()); //主表修改 number++; } if (ultraGrid2.Rows[i].ChildBands[0].Rows.Count > 0) { ArrayList listGrdChms = new ArrayList(); for (int j = 0; j < ultraGrid2.Rows[i].ChildBands[0].Rows.Count; j++) { Infragistics.Win.UltraWinGrid.UltraGridRow minrow = ultraGrid2.Rows[i].ChildBands[0].Rows[j]; if (Convert.ToBoolean(minrow.Cells["check2"].Value)) { if (CheckGrdChm(minrow, ultraGrid2.Rows[i].GetValue("GRADECODE")) == false) { return; } ArrayList minParm = new ArrayList(); minParm.Add(ultraGrid2.Rows[i].Cells["assortment_code"].Value.ToString()); minParm.Add(ultraGrid2.Rows[i].Cells["ASSORTMENT_NAME"].Value.ToString()); minParm.Add(ultraGrid2.Rows[i].Cells["COEFFICIENT"].Value.ToString()); minParm.Add(minrow.Cells["STDMIN_SIGN"].Value.ToString()); minParm.Add(minrow.Cells["STDMIN"].Value.ToString()); minParm.Add(minrow.Cells["STDMAX_SIGN"].Value.ToString()); minParm.Add(minrow.Cells["STDMAX"].Value.ToString()); minParm.Add(this.UserInfo.GetUserName()); minParm.Add(minrow.Cells["memo"].Value.ToString()); minParm.Add(ultraGrid2.Rows[i].Cells["GRADENAME"].Value.ToString()); minParm.Add(minrow.Cells["CHEM_NAME"].Text.ToString()); minParm.Add(ultraGrid2.Rows[i].Cells["GRADECODE"].Value.ToString()); minParm.Add(minrow.Cells["CHEM_CODE"].Text.ToString()); minParm.Add(minrow.Cells["VALIDFLAG"].Text.ToString()); //从表修改 number++; listGrdChms.Add(minParm); } } if (listGrdChms.Count > 0) { parm.Add(listGrdChms); } } if (parm.Count > 0) { listGrds.Add(parm); } } if (MessageUtil.ShowYesNoAndQuestion("是否保存数据?") == DialogResult.No) { return; } string gradeCode = ServerHelper.SetDataReturnObj("com.steering.pss.qcm.CoreSpecificationsGrade.save", new Object[] { listGrds }, this.ob).ToString(); if (number > 0) { doQuery(false); MessageBox.Show("保存成功", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } UltraGridRow[] rows = ultraGrid2.Rows.AsQueryable().Where("GRADECODE = '" + gradeCode + "'").ToArray(); if (rows.Length > 0) { rows[0].Activate(); rows[0].ExpandAll(); } } private bool isExistGradeName(string gradeName) { DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreSpecificationsGrade.isExistGradeName", new object[] { gradeName }, ob); if (dt.Rows[0][0].ToString() == "0") { return false; } return true; } /// /// 删除或恢复 /// /// true删除 false恢复 private void doDeleteOrResume(bool flag) { ultraGrid2.UpdateData(); int numb = 0; if (ultraGrid2.Rows.Count == 0) { MessageBox.Show("您当前没有勾选任何行!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } for (int i = 0; i < ultraGrid2.Rows.Count; i++) { if (Convert.ToBoolean(ultraGrid2.Rows[i].Cells["cb"].Value)) { if (ultraGrid2.Rows[i].ChildBands[0].Rows.Count > 0 && flag) { MessageBox.Show("子表数据必须删除!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string tishi = ""; if (flag) tishi = "删除"; else tishi = "恢复"; if (numb == 0) { if (MessageBox.Show(tishi + "勾选记录,您是否继续?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } } numb++; ArrayList listBase = new ArrayList(); if (flag == true) { listBase.Add(UserInfo.GetUserName()); } listBase.Add(ultraGrid2.Rows[i].Cells["GRADECODE"].Text.Trim().ToString()); //主表删除 int count = ServerHelper.SetData("com.steering.pss.qcm.CoreSpecificationsGrade.deleteLineInfo", new Object[] { listBase, flag }, this.ob); } if (ultraGrid2.Rows[i].ChildBands[0].Rows.Count > 0) { for (int j = 0; j < ultraGrid2.Rows[i].ChildBands[0].Rows.Count; j++) { if (Convert.ToBoolean(ultraGrid2.Rows[i].ChildBands[0].Rows[j].Cells["check2"].Value)) { string tishi = ""; if (flag) tishi = "删除"; else tishi = "恢复"; if (numb == 0) { if (MessageBox.Show(tishi + "勾选记录,您是否继续?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } } numb++; ArrayList listChild = new ArrayList(); if (flag == true) { listChild.Add(UserInfo.GetUserName()); listChild.Add(System.DateTime.Now); } listChild.Add(ultraGrid2.Rows[i].ChildBands[0].Rows[j].Cells["GRADECODE"].Text.Trim().ToString()); listChild.Add(ultraGrid2.Rows[i].ChildBands[0].Rows[j].Cells["CHEM_CODE"].Value.ToString()); //从表删除 int count1 = ServerHelper.SetData("com.steering.pss.qcm.CoreSpecificationsGradeChem.deleteLineInfo", new Object[] { listChild, flag }, this.ob); } } } } if (numb == 0) { MessageBox.Show("请选择需要处理的数据行!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } doQuery(false); } /// /// 查询方法,比较通用的查询方法 /// private void doQuery(bool flag) { bool validFlag = flag; string titleName = ""; string gradeName = labelTextBox1.Checked ? labelTextBox1.Text.Trim() : ""; DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreSpecificationsGrade.getLineList", new Object[] { validFlag, titleName, gradeName }, this.ob); dataTable2.Clear(); GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable1, true); //从表的记录也要查询出来。 DataTable mindt = ServerHelper.GetData("com.steering.pss.qcm.CoreSpecificationsGradeChem.getLineList", new Object[] { validFlag, titleName, gradeName }, this.ob); GridHelper.CopyDataToDatatable(ref mindt, ref this.dataTable2, true); for (int i = 0; i < ultraGrid2.Rows.Count; i++) { for (int j = 0; j < ultraGrid2.Rows[i].Cells.Count; j++) { if (ultraGrid2.Rows[i].Cells[j].Column.Key == "cb") continue; ultraGrid2.Rows[i].Cells[j].Activation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly; } if (ultraGrid2.Rows[i].ChildBands != null && ultraGrid2.Rows[i].ChildBands[0].Rows.Count > 0) { for (int j = 0; j < ultraGrid2.Rows[i].ChildBands[0].Rows.Count; j++) { for (int k = 0; k < ultraGrid2.Rows[i].ChildBands[0].Rows[j].Cells.Count; k++) { if (ultraGrid2.Rows[i].ChildBands[0].Rows[j].Cells[k].Column.Key == "check2") continue; ultraGrid2.Rows[i].ChildBands[0].Rows[j].Cells[k].Activation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly; } } } } UltraGridColumn[] col = new UltraGridColumn[] { this.ultraGrid2.DisplayLayout.Bands[0].Columns["MEMO"] }; //GridHelper.RefreshAndAutoSizeExceptRows(ultraGrid2, col); //不同颜色区分是否有效数据 Infragistics.Win.UltraWinGrid.UltraGridRow row = null; Infragistics.Win.UltraWinGrid.UltraGridRow minrow = null; for (int i = 0; i < ultraGrid2.Rows.Count; i++) { row = ultraGrid2.Rows[i]; if (row.ChildBands != null && row.ChildBands[0].Rows.Count > 0) { for (int j = 0; j < row.ChildBands[0].Rows.Count; j++) { minrow = row.ChildBands[0].Rows[j]; if (!minrow.Cells["VALIDFLAG"].Value.ToString().Equals("1")) { minrow.Appearance.ForeColor = Color.Red; } else { minrow.Appearance.ForeColor = Color.Black; } } } if (!row.Cells["VALIDFLAG"].Value.ToString().Equals("1")) { row.Appearance.ForeColor = Color.Red; } else { row.Appearance.ForeColor = Color.Black; } } } private void ultraGrid2_CellChange(object sender, CellEventArgs e) { this.ultraGrid2.UpdateData(); //勾选 全选 if (e.Cell.Column.Key.Equals("cb")) { if (e.Cell.Row.ChildBands[0] != null) { foreach (UltraGridRow row in e.Cell.Row.ChildBands[0].Rows) { row.Cells["check2"].Value = e.Cell.Value; } } } if (e.Cell.Column.Key.Equals("check2")) {//勾选从表(取消勾选) int flag = 0; //判断从表状态参数 foreach (UltraGridRow row in e.Cell.Row.ParentRow.ChildBands[0].Rows) { if (Convert.ToBoolean(row.Cells["check2"].Value)) { flag += 1; //从表勾选了 状态参数+1 } } if (flag < e.Cell.Row.ParentRow.ChildBands[0].Rows.Count) {//状态参数小于从表的行数,说明未全勾选,主表未半选状态 e.Cell.Row.ParentRow.Cells["cb"].Value = null; } else if (flag == 0) //从表取消全部勾选,主表不勾选 { e.Cell.Row.ParentRow.Cells["cb"].Value = false; } else //否则主表未全选状态 { e.Cell.Row.ParentRow.Cells["cb"].Value = true; } } if (e.Cell.Column.Key.Equals("ASSORTMENT_NAME")) { e.Cell.Row.Cells["ASSORTMENT_CODE"].Value = e.Cell.Row.Cells["ASSORTMENT_NAME"].Value; } if (e.Cell.Column.Key.Equals("CHEM_NAME")) { e.Cell.Row.Cells["CHEM_CODE"].Value = e.Cell.Row.Cells["CHEM_NAME"].Value; } if (e.Cell.Column.Key.Equals("cb")) { Activation activation = Activation.NoEdit; if (Convert.ToBoolean(e.Cell.Value)) { activation = Activation.AllowEdit; } CellsCollection cells = e.Cell.Row.Cells; for (int i = 0; i < cells.Count; i++) { if (!cells[i].Column.Key.Equals("cb")) //i!=9 { e.Cell.Row.Cells[i].Activation = activation; } } } if (e.Cell.Column.Key.Equals("check2")) { Activation activation = Activation.ActivateOnly; if (Convert.ToBoolean(e.Cell.Value)) { activation = Activation.AllowEdit; } CellsCollection cells = e.Cell.Row.Cells; for (int i = 0; i < cells.Count; i++) { if (!cells[i].Column.Key.Equals("check2")) { e.Cell.Row.Cells[i].Activation = activation; } } } } private void ultraGrid2_AfterRowInsert(object sender, RowEventArgs e) { for (int i = 0; i < e.Row.Cells.Count; i++) { if (i == 8) break; e.Row.Cells[i].Activation = Activation.NoEdit; } if (e.Row.HasParent()) { e.Row.Cells["GRADECODE"].Value = e.Row.ParentRow.Cells["GRADECODE"].Value.ToString(); } else { e.Row.Cells["GRADECODE"].Value = ++_index; } } private void labelTextBox1_TextBox_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { this.doQuery(false); } } } }