using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm.Server; using CoreFS.CA06; using Infragistics.Win.UltraWinGrid; using System; using System.Collections; using System.Data; using System.Drawing; using System.Windows.Forms; namespace Core.StlMes.Client.Qcm { public partial class FrmTubeRolling : FrmBase { public FrmTubeRolling() { InitializeComponent(); } private void FrmTubeRolling_Load(object sender, EventArgs e) { BindCmbProLineInfo(); BindCmbKType(); BindCmbGGType(); cmbProLineInfo.SelectedIndex = 0; cmbKType.SelectedIndex = 0; cmbGGType.SelectedIndex = 0; } /// /// 获取管坯规格描述 /// private void BindCmbGGType() { DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreTubeRolling.GetGGType", null, this.ob); cmbGGType.DataSource = dt; cmbGGType.DisplayMember = "SPEC_NAME"; cmbGGType.ValueMember = "SPEC_CODE"; } /// /// 绑定孔型描述 /// private void BindCmbKType() { DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreTubeRolling.GetKType", null, this.ob); cmbKType.DataSource = dt; cmbKType.DisplayMember = "BASENAME"; cmbKType.ValueMember = "BASECODE"; } /// /// 绑定产线描述 /// private void BindCmbProLineInfo() { DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreTubeRolling.GetProLineInfo", null, this.ob); cmbProLineInfo.DataSource = dt; cmbProLineInfo.DisplayMember = "PLINE_NAME"; cmbProLineInfo.ValueMember = "PLINE_CODE"; } /// /// 重写基类代码 /// /// /// public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "doQuery": doQuery(); break; case "doAdd": doAdd(); break; case "doModify": doModify(); break; case "doDelete": this.doDeleteOrResume(true); break; case "doResume": this.doDeleteOrResume(false); break; case "Close": this.Close(); break; } } /// /// 非空项验证 /// /// private bool ValidInput() { //if (string.IsNullOrEmpty(cmbProLineInfo.Text.Trim())) //{ // MessageBox.Show("请输入产线描述!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return false; //} return true; } /// /// 新增 /// private void doAdd() { if (ValidInput()) { try { //判断产线、孔型、管坯规格是否唯一PLINE_CODE,PASS_CODE,SPEC_CODE string plineCode = cmbProLineInfo.Value.ToString(); string passCode = cmbKType.Value.ToString(); string specCode = cmbGGType.Value.ToString(); string plineText = cmbProLineInfo.Text.Trim(); string passText = cmbKType.Text.Trim(); string specText = cmbGGType.Text.Trim(); if (isOnly(plineCode, passCode, specCode)) { MessageBox.Show("产线描述\"" + plineText + "\"、孔型描述\"" + passText + "\"、管坯规格描述\"" + specText + "\"已存在,请重新选择!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } ArrayList parm = new ArrayList(); //string modelCode = GridHelper.AutoCode(this.dataTable1); parm.Add(plineCode); parm.Add(plineText); parm.Add(passCode); parm.Add(passText); parm.Add(specCode); parm.Add(specText); parm.Add(this.UserInfo.GetUserName()); parm.Add(txtMemo.Text); CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.pss.qcm.CoreTubeRolling"; ccp.MethodName = "doAdd"; ccp.ServerParams = new object[] { parm }; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode == -1) return; doQuery(); //高亮显示新增的数据 Infragistics.Win.UltraWinGrid.UltraGridRow row = null; for (int i = 0; i < ultraGrid2.Rows.Count; i++) { row = ultraGrid2.Rows[i]; if (row.Cells["PLINE_CODE"].Value.ToString().Equals(plineCode) && row.Cells["PASS_CODE"].Value.ToString().Equals(passCode) && row.Cells["SPEC_CODE"].Value.ToString().Equals(specCode)) { row.Activate(); break; } } } catch (Exception ex) { MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } /// /// 修改 /// private void doModify() { if (ultraGrid2.ActiveRow == null) { MessageBox.Show("请选择需要修改的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string validflagStr = ultraGrid2.ActiveRow.Cells["VALIDFLAG"].Value.ToString(); //无效数据不允许修改 if ("0".Equals(validflagStr)) { MessageBox.Show("无效数据不支持修改操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (ValidInput()) { ArrayList parm = new ArrayList(); //string modelCode = ultraGrid2.ActiveRow.Cells["PLINE_CODE"].Value.ToString(); //判断产线、孔型、管坯规格是否唯一 string plineCode = cmbProLineInfo.Value.ToString(); string passCode = cmbKType.Value.ToString(); string specCode = cmbGGType.Value.ToString(); //获取名称,用于提示信息。 string plineText = cmbProLineInfo.Text.Trim(); string passText = cmbKType.Text.Trim(); string specText = cmbGGType.Text.Trim(); //依据修改之前的数据作为条件 string proLineInfoTitle = ultraGrid2.ActiveRow.Cells["PLINE_CODE"].Value.ToString(); string kTypeTitle = ultraGrid2.ActiveRow.Cells["PASS_CODE"].Value.ToString(); string ggTypeTitle = ultraGrid2.ActiveRow.Cells["SPEC_CODE"].Value.ToString(); //判断是否只修改了备注。 if (!plineCode.Equals(proLineInfoTitle) || !passCode.Equals(kTypeTitle) || !specCode.Equals(ggTypeTitle)) { if (isOnly(plineCode, passCode, specCode)) { MessageBox.Show("产线描述\"" + plineText + "\"、孔型描述\"" + passText + "\"、管坯规格描述\"" + specText + "\"已存在,请重新选择!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } //确认修改吗? if (MessageBox.Show("是否确认修改选中的数据!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } parm.Add(plineCode); parm.Add(plineText); parm.Add(passCode); parm.Add(passText); parm.Add(specCode); parm.Add(specText); parm.Add(this.UserInfo.GetUserName()); parm.Add(txtMemo.Text.Trim()); //添加条件 parm.Add(proLineInfoTitle); parm.Add(kTypeTitle); parm.Add(ggTypeTitle); CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.pss.qcm.CoreTubeRolling"; ccp.MethodName = "doModify"; ccp.ServerParams = new object[] { parm }; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode == -1) return; doQuery(); //高亮显示新增的数据 Infragistics.Win.UltraWinGrid.UltraGridRow row = null; for (int i = 0; i < ultraGrid2.Rows.Count; i++) { row = ultraGrid2.Rows[i]; if (row.Cells["PLINE_CODE"].Value.ToString().Equals(plineCode) && row.Cells["PASS_CODE"].Value.ToString().Equals(passCode) && row.Cells["SPEC_CODE"].Value.ToString().Equals(specCode)) { row.Activate(); break; } } } } /// /// 验证产线、孔型、管坯规格是否唯一 /// /// /// /// /// private bool isOnly(string proLineInfo, string kType, string ggType) { DataTable dt = new DataTable(); dt = ServerHelper.GetData("com.steering.pss.qcm.CoreTubeRolling.isOnly", new Object[] { proLineInfo, kType, ggType }, this.ob); if (dt.Rows.Count > 0) { return true; } else { return false; } } /// /// 判断产品规格代码是否已存在 /// /// private bool isGGType(string ggType) { DataTable dt = new DataTable(); dt = ServerHelper.GetData("com.steering.pss.qcm.CoreTubeRolling.isGGType", new Object[] { ggType }, this.ob); if (dt.Rows.Count > 0) { return true; } else { return false; } } /// /// 判断孔型代码是否已存在 /// /// private bool isKType(string kType) { DataTable dt = new DataTable(); dt = ServerHelper.GetData("com.steering.pss.qcm.CoreTubeRolling.isKType", new Object[] { kType }, this.ob); if (dt.Rows.Count > 0) { return true; } else { return false; } } /// /// 判断产线代码是否已存在 /// /// private bool isProLineInfo(string proLineInfo) { DataTable dt = new DataTable(); dt = ServerHelper.GetData("com.steering.pss.qcm.CoreTubeRolling.isProLineInfo", new Object[] { proLineInfo }, this.ob); if (dt.Rows.Count > 0) { return true; } else { return false; } } /// /// 查询 /// private void doQuery() { bool validFlag = chkValid.Checked; string titleName = txtTitleName.Text.Trim(); DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreTubeRolling.getLineList", new Object[] { validFlag, titleName }, this.ob); GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable1, true); //不同颜色区分是否有效数据 Infragistics.Win.UltraWinGrid.UltraGridRow row = null; for (int i = 0; i < ultraGrid2.Rows.Count; i++) { row = ultraGrid2.Rows[i]; if (!row.Cells["VALIDFLAG"].Value.ToString().Equals("1")) { row.Appearance.ForeColor = Color.Red; } else { row.Appearance.ForeColor = Color.Black; } } //列自适应 GridHelper.RefreshAndAutoSizeExceptRows(ultraGrid2, new UltraGridColumn[] { ultraGrid2.DisplayLayout.Bands[0].Columns["MEMO"] }); } /// /// GRID ROW激活时信息带至编辑区 /// /// /// private void ultraGrid2_AfterRowActivate(object sender, EventArgs e) { Infragistics.Win.UltraWinGrid.UltraGridRow row = ultraGrid2.ActiveRow; if (row != null) { //PLINE_CODE,PLINE_NAME,PASS_CODE,PASS_NAME,SPEC_CODE,SPEC_NAME cmbProLineInfo.Value = row.Cells["PLINE_CODE"].Value.ToString(); cmbKType.Value = row.Cells["PASS_CODE"].Value.ToString(); cmbGGType.Value = row.Cells["SPEC_CODE"].Value.ToString(); txtMemo.Text = row.Cells["MEMO"].Value.ToString(); } } /// /// 作废或恢复 /// /// true作废 false恢复 private void doDeleteOrResume(bool isDelete) { if (ultraGrid2.ActiveRow == null) { MessageBox.Show("请选择需要" + (isDelete ? "作废" : "恢复") + "的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string validflagStr = ultraGrid2.ActiveRow.Cells["VALIDFLAG"].Value.ToString(); //无效数据不允许作废 if ("0".Equals(validflagStr)) { if (isDelete) { MessageBox.Show("无效数据不支持作废操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } else { //有效数据不允许恢复 if (!isDelete) { MessageBox.Show("有效数据不支持恢复操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } ArrayList param = new ArrayList(); string plineCode = ultraGrid2.ActiveRow.Cells["PLINE_CODE"].Value.ToString(); string passCode = ultraGrid2.ActiveRow.Cells["PASS_CODE"].Value.ToString(); string specCode = ultraGrid2.ActiveRow.Cells["SPEC_CODE"].Value.ToString(); //作废必须结合产线代码、孔型代码、轧管规格代码 param.Add(plineCode); param.Add(passCode); param.Add(specCode); if (param.Count > 0 && MessageBox.Show("是否确认" + (isDelete ? "作废" : "恢复") + "选中的数据!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { int count = ServerHelper.SetData("com.steering.pss.qcm.CoreTubeRolling.deleteLineInfo", new Object[] { param, UserInfo.GetUserName(), isDelete }, this.ob); if (count > 0) { doQuery(); Infragistics.Win.UltraWinGrid.UltraGridRow rowD = null; for (int i = 0; i < ultraGrid2.Rows.Count; i++) { rowD = ultraGrid2.Rows[i]; if (plineCode.Equals(rowD.Cells["PLINE_CODE"].Value.ToString()) && passCode.Equals(rowD.Cells["PASS_CODE"].Value.ToString()) && specCode.Equals(rowD.Cells["SPEC_CODE"].Value.ToString())) { rowD.Activate(); break; } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } } }