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 FrmWaterRatioStd : FrmBase { public FrmWaterRatioStd() { InitializeComponent(); ExceptionHelper.RegistException(); } private OpeBase _ob; public OpeBase Ob { get { return _ob; } set { _ob = value; } } //UltraComboEditor stdUce = new UltraComboEditor(); //UltraComboEditor stdUcec = new UltraComboEditor(); UltraCombo stdCombo = new UltraCombo(); UltraCombo stdComboRep = new UltraCombo(); string stdName = ""; private void FrmWaterRatioStd_Load(object sender, EventArgs e) { Init(); DoQuery(false); } private void InitDrop(UltraCombo uce, string methodID, string showName, string value, Boolean isNull, OpeBase ob) { DataTable dt = ServerHelper.GetData(methodID, new Object[] { }, ob); if (dt != null && dt.Rows.Count > 0 && isNull) { DataRow dr = dt.NewRow(); for (int i = 0; i < dt.Columns.Count; i++) { dr[i] = ""; } dt.Rows.InsertAt(dr, 0); } uce.DataSource = dt; uce.DisplayMember = showName; uce.ValueMember = value; } private void Init() { //this.Controls.Add(stdCombo); //this.Controls.Add(stdComboRep); //stdCombo.Visible = false; //stdComboRep.Visible = false; //InitDrop(stdCombo, "com.steering.pss.qcm.WaterRatioRStd.getStd", "STD_NAME", "ID_CODE", true, this._ob); //InitDrop(stdComboRep, "com.steering.pss.qcm.WaterRatioRStd.getStdReplace", "STD_NAME", "IDCODE", true, this._ob); //ultraGrid1.DisplayLayout.Bands[0].Columns["STD_NAME_C"].EditorComponent = stdCombo; //ultraGrid1.DisplayLayout.Bands[0].Columns["STD_NAME_C"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList; //ultraGrid1.DisplayLayout.Bands[0].Columns["STD_NAME"].EditorComponent = stdComboRep; //ultraGrid1.DisplayLayout.Bands[0].Columns["STD_NAME"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList; //stdCombo.DisplayLayout.Bands[0].Columns["ID_CODE"].Hidden = true; //stdCombo.DisplayLayout.Bands[0].Columns["STD_NAME"].Header.Caption = "标准名称"; //stdCombo.DisplayLayout.Bands[0].Columns["STD_STYLE_DESC"].Header.Caption = "标准类别"; //stdComboRep.DisplayLayout.Bands[0].Columns["IDCODE"].Hidden = true; //stdComboRep.DisplayLayout.Bands[0].Columns["STD_NAME"].Header.Caption = "标准名称"; //stdComboRep.DisplayLayout.Bands[0].Columns["STD_STYLE_DESC"].Header.Caption = "标准类别"; //stdCombo.DisplayLayout.Bands[0].Columns["STD_NAME"].Width = 240; //stdComboRep.DisplayLayout.Bands[0].Columns["STD_NAME"].Width = 240; //ultraGrid1.UpdateData(); } private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e) { if (e.Tool.Key == "ButtonTool1") //保存 { DoSave(); } if (e.Tool.Key == "ButtonTool2") //删除 { DeleteOrResume(true); } if (e.Tool.Key == "ButtonTool3") //恢复 { DeleteOrResume(false); } if (e.Tool.Key == "ButtonTool5") //刷新 { DoRefresh(); } if (e.Tool.Key == "ButtonTool6") //查询 { DoQuery(false); } if (e.Tool.Key == "ButtonTool7") //查询 { DoQuery(true); } if (e.Tool.Key == "ButtonTool4") //关闭 { if (MessageBox.Show("是否关闭本窗口?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } this.Close(); } } private void DoSave() { if (GetData() == -1) { return; } if (param.Count <= 0 && paramUpdate.Count <= 0) { MessageUtil.ShowWarning("请选择要保存的记录!"); return; } List list = stdList.Distinct().ToList(); if (list.Count < stdList.Count) { MessageUtil.ShowWarning("有重复的标准名称,请重新选择!"); return; } if (MessageBox.Show("是否保存所选记录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return; // int count = ServerHelper.SetData("com.steering.pss.qcm.WaterRatioRStd.save", new object[] { param, paramUpdate }, this._ob); //一个标准只能引用一个水压标准,一个水压标准可被多个标准引用 CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.pss.qcm.WaterRatioRStd"; ccp.MethodName = "save"; ccp.ServerParams = new object[] { param, paramUpdate }; ccp = this._ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp != null && ccp.ReturnInfo == "FALSE###") //服务端传来的错误信息 { MessageUtil.ShowWarning("您所选标准已存在引用标准\n或者为水压系数维护的基础标准,无法保存!"); return; } if (ccp.ReturnCode == -1) return; MessageUtil.ShowTips("保存成功!"); DoQuery(false); } ArrayList param = new ArrayList(); ArrayList paramUpdate = new ArrayList(); List stdList = new List(); private int GetData() { ultraGrid1.UpdateData(); param = new ArrayList(); paramUpdate = new ArrayList(); stdList.Clear(); foreach (UltraGridRow row in ultraGrid1.Rows) { if (row.Cells["CHK"].Value.ToString().ToUpper() == "TRUE") { if (row.Cells["STD_NAME_C"].Text.Trim() == "") { MessageUtil.ShowWarning("请选择标准名称!"); return -1; } if (row.Cells["STD_NAME"].Text.Trim() == "") { MessageUtil.ShowWarning("请选择引用标准名称!"); return -1; } if (row.Cells["STD_CODE_C"].Value.ToString() == row.Cells["STD_CODE"].Value.ToString()) { MessageUtil.ShowWarning("标准不能引用自身!"); return -1; } if (row.Cells["VALIDFLAG"].Value.ToString() == "") { ArrayList list = new ArrayList(); list.Add(row.Cells["ID_"].Value.ToString()); list.Add(row.Cells["STD_CODE_C"].Value.ToString()); list.Add(row.Cells["STD_NAME_C"].Text.Trim()); list.Add(row.Cells["STD_STYLE_C"].Value.ToString()); list.Add(row.Cells["STD_STYLE_DESC_C"].Value.ToString()); list.Add(row.Cells["STD_CODE"].Value.ToString()); list.Add(row.Cells["STD_NAME"].Text.Trim()); list.Add(row.Cells["STD_STYLE"].Value.ToString()); list.Add(row.Cells["STD_STYLE_DESC"].Value.ToString()); list.Add(this.UserInfo.GetUserName()); list.Add(row.Cells["MEMO"].Value.ToString()); param.Add(list); stdName = row.Cells["STD_NAME_C"].Value.ToString(); } else { ArrayList list = new ArrayList(); list.Add(row.Cells["ID_"].Value.ToString()); list.Add(row.Cells["STD_CODE_C"].Value.ToString()); list.Add(row.Cells["STD_NAME_C"].Text.Trim()); list.Add(row.Cells["STD_STYLE_C"].Value.ToString()); list.Add(row.Cells["STD_STYLE_DESC_C"].Value.ToString()); list.Add(row.Cells["STD_CODE"].Value.ToString()); list.Add(row.Cells["STD_NAME"].Text.Trim()); list.Add(row.Cells["STD_STYLE"].Value.ToString()); list.Add(row.Cells["STD_STYLE_DESC"].Value.ToString()); list.Add(this.UserInfo.GetUserName()); list.Add(row.Cells["MEMO"].Value.ToString()); list.Add(row.Cells["STD_CODE_OLD"].Value.ToString()); paramUpdate.Add(list); stdName = row.Cells["STD_NAME_C"].Value.ToString(); } stdList.Add(row.Cells["STD_NAME_C"].Text.Trim()); } } return 0; } private void DoQuery(bool flag) { DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.WaterRatioRStd.query", new object[] { flag }, this._ob); GridHelper.CopyDataToDatatable(ref dt, ref dataTable1, true); foreach (UltraGridRow row in ultraGrid1.Rows) { if (row.Cells["STD_NAME_C"].Value.ToString() == stdName) { row.Activate(); break; } } stdName = ""; } private void DoRefresh() { Init(); } private void DeleteOrResume(bool flag) { ultraGrid1.UpdateData(); UltraGridRow[] dr = GridHelper.GetRowsWithKey(ultraGrid1, new string[] { "CHK" }, new string[] { "True" }); if (dr.Length <= 0) { MessageUtil.ShowWarning("请选择你要操作的记录!"); return; } ArrayList deleteParm = new ArrayList(); foreach (UltraGridRow row in ultraGrid1.Rows) { if (row.Cells["CHK"].Value.ToString().ToUpper() == "TRUE") { if (flag) //删除 { if (row.Cells["VALIDFLAG"].Value.ToString() == "") { MessageUtil.ShowTips("数据尚未写进数据库!"); return; } deleteParm.Add(row.Cells["ID_"].Value.ToString()); } } } if (MessageBox.Show("是否确认" + (flag ? "删除" : "恢复") + "所选数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } int count = ServerHelper.SetData("com.steering.pss.qcm.WaterRatioRStd.delete", new object[] { deleteParm }, this._ob); if (count > 0) { MessageUtil.ShowTips("数据" + (flag ? "删除" : "恢复") + "成功!"); DoQuery(false); } } private void ultraGrid1_CellChange(object sender, CellEventArgs e) { ultraGrid1.UpdateData(); UltraGridRow ugr = ultraGrid1.DisplayLayout.ActiveRow; if (ugr == null) return; //if (e.Cell.Column.Key.Equals("STD_NAME_C")) //{ // if (e.Cell.Text != "") // { // DataRow[] dr = ((DataTable)stdCombo.DataSource).Select("ID_CODE ='" + e.Cell.Value.ToString() + "'"); // if (dr.Length > 0) // { // ugr.Cells["STD_NAME_C"].Value= e.Cell.Value; // //ugr.Cells["STD_STYLE_C"].Value = dr[0][2]; // string[] str = null; // if (dr[0][0].ToString().Contains("#####")) // { // str = dr[0][0].ToString().Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries); // // _stdCodeC = str[0]; // ugr.Cells["STD_CODE_C"].Value = str[0]; // if (str.Length == 2) // { // ugr.Cells["STD_STYLE_C"].Value = str[1]; // } // } // ugr.Cells["STD_STYLE_DESC_C"].Value = dr[0][2]; // } // // ugr.Cells["ID_"].Value = ugr.Cells["STD_CODE_C"].Value.ToString() + ugr.Cells["STD_STYLE_C"].Value.ToString(); // } // else // { // ugr.Cells["STD_NAME_C"].Value = ""; // ugr.Cells["STD_STYLE_C"].Value = ""; // ugr.Cells["STD_STYLE_DESC_C"].Value = ""; // } //} //else if (e.Cell.Column.Key.Equals("STD_NAME")) //{ // if (e.Cell.Text != "") // { // DataRow[] dr = ((DataTable)stdComboRep.DataSource).Select("IDCODE ='" + e.Cell.Value.ToString() + "'" ); // if (dr.Length > 0) // { // ugr.Cells["STD_NAME"].Value = e.Cell.Value; // //ugr.Cells["STD_STYLE"].Value = dr[0][2]; // string[] str = null; // if (dr[0][0].ToString().Contains("#####")) // { // str=dr[0][0].ToString().Split(new char[]{'#'},StringSplitOptions.RemoveEmptyEntries); // //_stdCode = str[0]; // ugr.Cells["STD_CODE"].Value = str[0]; // if(str.Length==2) // { // ugr.Cells["STD_STYLE"].Value = str[1]; // } // } // ugr.Cells["STD_STYLE_DESC"].Value = dr[0][2]; // } // // ugr.Cells["ID_"].Value = ugr.Cells["STD_CODE_C"].Value.ToString() + ugr.Cells["STD_STYLE_C"].Value.ToString(); // } // else // { // ugr.Cells["STD_NAME"].Value = ""; // ugr.Cells["STD_STYLE"].Value = ""; // ugr.Cells["STD_STYLE_DESC"].Value = ""; // } //} else if (e.Cell.Column.Key.Equals("CHK")) { if (e.Cell.Value.ToString().ToUpper() != "TRUE") { ugr.Cells["STD_NAME_C"].Activation = Activation.ActivateOnly; ugr.Cells["STD_NAME"].Activation = Activation.ActivateOnly; ugr.Cells["MEMO"].Activation = Activation.ActivateOnly; } else { ugr.Cells["STD_NAME_C"].Activation = Activation.AllowEdit; ugr.Cells["STD_NAME"].Activation = Activation.AllowEdit; ugr.Cells["MEMO"].Activation = Activation.AllowEdit; } } } private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e) { if (e.Row.Cells["VALIDFLAG"].Value.ToString() == "无效") { e.Row.Appearance.ForeColor = Color.Red; } } private void ultraGrid1_AfterRowInsert(object sender, RowEventArgs e) { ultraGrid1.UpdateData(); UltraGridRow ugr = ultraGrid1.ActiveRow; if (ugr == null) return; if (ugr.Cells["CHK"].Value.ToString().ToUpper() == "TRUE") { ugr.Cells["STD_NAME_C"].Activation = Activation.AllowEdit; ugr.Cells["STD_NAME"].Activation = Activation.AllowEdit; ugr.Cells["MEMO"].Activation = Activation.AllowEdit; } else { ugr.Cells["STD_NAME_C"].Activation = Activation.ActivateOnly; ugr.Cells["STD_NAME"].Activation = Activation.ActivateOnly; ugr.Cells["MEMO"].Activation = Activation.ActivateOnly; } } private void ultraGrid1_AfterRowActivate(object sender, EventArgs e) { ultraGrid1.UpdateData(); UltraGridRow ugr = ultraGrid1.ActiveRow; if (ugr == null) return; if (ugr.Cells["CHK"].Value.ToString().ToUpper() == "TRUE") { ugr.Cells["STD_NAME_C"].Activation = Activation.AllowEdit; ugr.Cells["STD_NAME"].Activation = Activation.AllowEdit; ugr.Cells["MEMO"].Activation = Activation.AllowEdit; } else { ugr.Cells["STD_NAME_C"].Activation = Activation.ActivateOnly; ugr.Cells["STD_NAME"].Activation = Activation.ActivateOnly; ugr.Cells["MEMO"].Activation = Activation.ActivateOnly; } } private void ultraTextEditor1_EditorButtonClick(object sender, EditorButtonEventArgs e) { BaseInfoPopup popup; string key = ultraGrid1.ActiveCell.Column.Key; if (key == "STD_NAME_C") { this.Cursor = Cursors.WaitCursor; string stdCode = ultraGrid1.ActiveRow.GetValue("STD_CODE_C"); DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.WaterRatioRStd.getStd", new object[] { }, _ob); dt.Columns["STD_NAME"].Caption = "标准名称"; dt.Columns["STD_STYLE_DESC"].Caption = "标准类别"; popup = new BaseInfoPopup(dt, "STD_NAME", "STD_CODE", "STD_STYLE"); popup.Load += ((a, b) => { var row = popup.UltraGrid1.Rows.Where(c => c.GetValue("STD_CODE") == stdCode).FirstOrDefault(); if (row != null) { row.Activate(); } this.Cursor = Cursors.Default; }); if (popup.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ultraGrid1.SetActiveRowValue("STD_NAME_C", popup.ChoicedRow.GetValue("STD_NAME")); ultraGrid1.SetActiveRowValue("STD_CODE_C", popup.ChoicedRow.GetValue("STD_CODE")); ultraGrid1.SetActiveRowValue("STD_STYLE_DESC_C", popup.ChoicedRow.GetValue("STD_STYLE_DESC")); ultraGrid1.SetActiveRowValue("STD_STYLE_C", popup.ChoicedRow.GetValue("STD_STYLE")); ultraGrid1.ActiveRow.Update(); } } else if (key == "STD_NAME") { this.Cursor = Cursors.WaitCursor; string stdCode = ultraGrid1.ActiveRow.GetValue("STD_CODE"); DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.WaterRatioRStd.getStdReplace", new object[] { }, _ob); dt.Columns["STD_NAME"].Caption = "引用标准名称"; dt.Columns["STD_STYLE_DESC"].Caption = "标准类别"; popup = new BaseInfoPopup(dt, "STD_NAME", "STD_CODE", "STD_STYLE"); popup.Load += ((a, b) => { var row = popup.UltraGrid1.Rows.Where(c => c.GetValue("STD_CODE") == stdCode).FirstOrDefault(); if (row != null) { row.Activate(); } this.Cursor = Cursors.Default; }); if (popup.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ultraGrid1.SetActiveRowValue("STD_NAME", popup.ChoicedRow.GetValue("STD_NAME")); ultraGrid1.SetActiveRowValue("STD_CODE", popup.ChoicedRow.GetValue("STD_CODE")); ultraGrid1.SetActiveRowValue("STD_STYLE_DESC", popup.ChoicedRow.GetValue("STD_STYLE_DESC")); ultraGrid1.SetActiveRowValue("STD_STYLE", popup.ChoicedRow.GetValue("STD_STYLE")); ultraGrid1.ActiveRow.Update(); } } } } }