using com.steering.pss.sale.price.entity; 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.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Core.StlMes.Client.SalePrice.BaseForm { public partial class FrmPriceFactor : FrmBase { public FrmPriceFactor() { InitializeComponent(); } string isValid = "1"; private void FrmPriceFactor_Load(object sender, EventArgs e) { EntityHelper.ShowGridCaption(gdFactor.DisplayLayout.Bands[0]); InitForm(); } /// /// 初始化数据 /// private void InitForm() { UltraComboEditor uce = new UltraComboEditor(); SalePriceClass.InitComboEditor(uce, "com.steering.pss.sale.price.server.CorePriceFactor.queryTableName", "TABLE_NAME", this.ob, false); gdFactor.DisplayLayout.Bands[0].Columns["TABLENAME"].EditorComponent = uce; gdFactor.DisplayLayout.Bands[0].Columns["TABLENAME"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList; this.Controls.Add(uce); uce.Visible = false; UltraComboEditor uce1 = new UltraComboEditor(); SalePriceClass.InitComboEditorWithParm(uce1, "com.steering.pss.sale.price.server.CorePriceFactor.queryBaseInfo", "BASECODE", "BASENAME", this.ob, true, new object[] { "1228" }); gdFactor.DisplayLayout.Bands[0].Columns["VERTYPE"].EditorComponent = uce1; gdFactor.DisplayLayout.Bands[0].Columns["VERTYPE"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList; this.Controls.Add(uce1); uce1.Visible = false; } public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "Query": QueryData(); break; case "Save": SaveFormData(); break; case "Delete": DeleteOrResume(true); break; case "Resume": DeleteOrResume(false); break; case "Close": this.Close(); break; } } /// /// 初始化行事件 /// /// /// private void gdFactor_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e) { if (e.Row != null) { string tabName = e.Row.Cells["TABLENAME"].Value.ToString(); UltraComboEditor uce = new UltraComboEditor(); SalePriceClass.InitComboEditorWithParm(uce, "com.steering.pss.sale.price.server.CorePriceFactor.queryColumnName", "COLUMN_NAME", "COLUMN_NAME", this.ob, false, new object[] { tabName }); gdFactor.DisplayLayout.Bands[0].Columns["COLUMNKEY"].EditorComponent = uce; gdFactor.DisplayLayout.Bands[0].Columns["COLUMNKEY"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList; this.Controls.Add(uce); uce.Visible = false; if (e.Row.Cells["VALIDFLAG"].Value.ToString() == "无效") { e.Row.Appearance.ForeColor = Color.Red; } else { e.Row.Appearance.ForeColor = Color.Black; } } } /// /// CellChange事件 /// /// /// private void gdFactor_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e) { gdFactor.UpdateData(); if (e.Cell.Column.Key.ToUpper().Equals("COLUMNKEY")) { string tabName = e.Cell.Row.Cells["TABLENAME"].Value.ToString(); string colName = e.Cell.Value.ToString(); DataTable dt = ServerHelper.GetData("com.steering.pss.sale.price.server.CorePriceFactor.queryColumnType", new object[] { tabName, colName }, this.ob); if (dt != null && dt.Rows.Count > 0) { string dataType = dt.Rows[0][0].ToString2().ToUpper(); e.Cell.Row.Cells["COLUMNTYPE"].Value = SalePriceClass.GetColumnType(dataType); } else { e.Cell.Row.Cells["COLUMNTYPE"].Value = ""; } } else if (e.Cell.Column.Key.ToUpper().Equals("CHK")) { if (Convert.ToBoolean(e.Cell.Value)) { e.Cell.Row.Cells["FACTORNAME"].Activation = Activation.AllowEdit; e.Cell.Row.Cells["TABLENAME"].Activation = Activation.AllowEdit; e.Cell.Row.Cells["COLUMNKEY"].Activation = Activation.AllowEdit; e.Cell.Row.Cells["VALSQL"].Activation = Activation.AllowEdit; e.Cell.Row.Cells["VERTYPE"].Activation = Activation.AllowEdit; } else { e.Cell.Row.Cells["FACTORNAME"].Activation = Activation.ActivateOnly; e.Cell.Row.Cells["TABLENAME"].Activation = Activation.ActivateOnly; e.Cell.Row.Cells["COLUMNKEY"].Activation = Activation.ActivateOnly; e.Cell.Row.Cells["VALSQL"].Activation = Activation.ActivateOnly; e.Cell.Row.Cells["VERTYPE"].Activation = Activation.ActivateOnly; } } else if (e.Cell.Column.Key.ToUpper().Equals("TABLENAME")) { e.Cell.Row.Cells["COLUMNKEY"].Value = ""; } } /// /// 激活事件 /// /// /// private void gdFactor_AfterRowActivate(object sender, EventArgs e) { UltraGridRow uRow = gdFactor.ActiveRow; if (uRow != null) { gdFactor.UpdateData(); if (Convert.ToBoolean(uRow.Cells["CHK"].Value)) { uRow.Cells["FACTORNAME"].Activation = Activation.AllowEdit; uRow.Cells["TABLENAME"].Activation = Activation.AllowEdit; uRow.Cells["COLUMNKEY"].Activation = Activation.AllowEdit; uRow.Cells["VALSQL"].Activation = Activation.AllowEdit; uRow.Cells["VERTYPE"].Activation = Activation.AllowEdit; } else { uRow.Cells["FACTORNAME"].Activation = Activation.ActivateOnly; uRow.Cells["TABLENAME"].Activation = Activation.ActivateOnly; uRow.Cells["COLUMNKEY"].Activation = Activation.ActivateOnly; uRow.Cells["VALSQL"].Activation = Activation.ActivateOnly; uRow.Cells["VERTYPE"].Activation = Activation.ActivateOnly; } } } /// /// 插入一行时 /// /// /// private void gdFactor_AfterRowInsert(object sender, RowEventArgs e) { string maxId = gdFactor.Rows.AsQueryable().Max(a => a.Cells["FACTORID"].Value.ToString()); if (maxId == "") { e.Row.Cells["FACTORID"].Value = "F000001"; } else { string str = "F" + (Convert.ToInt32(maxId.Substring(1, 6)) + 1).ToString().PadLeft(6, '0'); e.Row.Cells["FACTORID"].Value = str; } } /// /// 保存界面数据 /// private void SaveFormData() { gdFactor.UpdateData(); UltraGridRow[] row = gdFactor.Rows.AsQueryable().Where(a => a.Cells["CHK"].Value.ToString().ToUpper() == "TRUE").ToArray(); if (row.Length <= 0) { MessageUtil.ShowWarning("请选择需要保存的数据!"); return; } ArrayList parm = CheckFormData(row); if (parm == null || parm.Count <= 0) { return; } if (MessageUtil.ShowYesNoAndQuestion("是否确认保存数据!") == DialogResult.No) return; CoreClientParam ccp = new CoreClientParam(); ccp.IfShowErrMsg = false; ccp.ServerName = "com.steering.pss.sale.price.server.CorePriceFactor"; ccp.MethodName = "saveData"; ccp.ServerParams = new object[] { parm, UserInfo.GetUserName() }; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp != null) { if (ccp.ReturnCode == -1) { MessageUtil.ShowWarning(ccp.ReturnInfo); return; } MessageUtil.ShowTips("数据保存成功!"); QueryData(); } } /// /// 验证界面数据 /// /// 界面数据 /// private ArrayList CheckFormData(UltraGridRow[] row) { ArrayList parm = new ArrayList(); List list = new List(); foreach (var uRow in row) { SlmPriceFactorEntity spf = (SlmPriceFactorEntity)uRow.ListObject; if (spf.Validflag == "无效" && spf.CreateName != "") { MessageUtil.ShowWarning("【" + spf.FactorId + "】的因素已经无效,不能修改!"); return null; } if (spf.FactorName == "") { MessageUtil.ShowWarning("请输入【" + spf.FactorId + "】的因素名称!"); return null; } //if (spf.TableName == "") //{ // MessageUtil.ShowWarning("请选择【" + spf.FactorId + "】的表名!"); // return null; //} //if (spf.ColumnKey == "") //{ // MessageUtil.ShowWarning("请选择【" + spf.FactorId + "】的字段KEY!"); // return null; //} if (spf.VerType == "") { MessageUtil.ShowWarning("请选择【" + spf.FactorId + "】的版本类型!"); return null; } //判断因素名称是否重复 if (spf.Validflag == "") //新增 { DataTable dt = ServerHelper.GetData("com.steering.pss.sale.price.server.CorePriceFactor.queryFacNameByName", new object[] { spf.FactorName }, this.ob); if (dt != null && dt.Rows.Count >= 1) { MessageUtil.ShowWarning("【" + spf.FactorId + "】您输入的因素名称【" + spf.FactorName + "】已存在!"); return null; } } else { DataTable dt = ServerHelper.GetData("com.steering.pss.sale.price.server.CorePriceFactor.queryFacNameById", new object[] { spf.FactorId }, this.ob); if (dt != null && dt.Rows.Count > 0) { if (spf.FactorName != dt.Rows[0][0].ToString()) { DataTable dt1 = ServerHelper.GetData("com.steering.pss.sale.price.server.CorePriceFactor.queryFacNameByName", new object[] { spf.FactorName }, this.ob); if (dt1 != null && dt1.Rows.Count >= 1) { MessageUtil.ShowWarning("【" + spf.FactorId + "】您输入的因素名称【" + spf.FactorName + "】已存在!"); return null; } } } } if (list.Contains(spf.FactorName)) { MessageUtil.ShowWarning("输入的因素名称重复!"); return null; } else { list.Add(spf.FactorName); } parm.Add(spf); } return parm; } /// /// 查询 /// private void QueryData() { string facId = ""; string facName = ""; if (labelTextBox1.Checked) facName = labelTextBox1.Text.Trim(); if (labelTextBox2.Checked) facId = labelTextBox2.Text.Trim(); List list = EntityHelper.GetData( "com.steering.pss.sale.price.server.CorePriceFactor.query", new object[] { facId, facName, isValid }, this.ob); slmPriceFactorEntityBindingSource.DataSource = list; } private void chkValid_CheckedChanged(object sender, EventArgs e) { if (chkValid.Checked) { isValid = "0"; } else { isValid = "1"; } } /// /// 删除或恢复 /// /// private void DeleteOrResume(bool flag) { gdFactor.UpdateData(); UltraGridRow[] row = gdFactor.Rows.AsQueryable().Where(a => a.Cells["CHK"].Value.ToString() == "True").ToArray(); if (row.Length <= 0) { MessageUtil.ShowWarning("请选择需要" + (flag ? "删除" : "恢复") + "的数据!"); return; } ArrayList parm = new ArrayList(); if (flag) { foreach (var uRow in row) { SlmPriceFactorEntity spf = (SlmPriceFactorEntity)uRow.ListObject; if (spf.Validflag == "无效") { MessageUtil.ShowWarning("您勾选的数据中存在已删除的数据,不必重复删除!"); return; } parm.Add(spf.FactorId); } } else { foreach (var uRow in row) { SlmPriceFactorEntity spf = (SlmPriceFactorEntity)uRow.ListObject; if (spf.Validflag == "有效") { MessageUtil.ShowWarning("您勾选的数据中存在有效的数据,不必进行恢复!"); return; } //恢复前判断是否存在相同因素名称的数据 DataTable dt = ServerHelper.GetData("com.steering.pss.sale.price.server.CorePriceFactor.canResume", new object[] { spf.FactorId, spf.FactorName }, this.ob); if (dt != null && dt.Rows.Count > 0) { MessageUtil.ShowWarning("系统已存在名称为【" + spf.FactorName + "】并且有效的因素,不能恢复!"); return; } parm.Add(spf.FactorId); } } if (MessageUtil.ShowYesNoAndQuestion("是否" + (flag ? "删除" : "恢复") + "所选的数据!") == DialogResult.No) return; CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.pss.sale.price.server.CorePriceFactor"; ccp.MethodName = "deleteOrResume"; ccp.ServerParams = new object[] { parm, UserInfo.GetUserName(), flag }; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp != null) { if (ccp.ReturnCode != -1) { MessageUtil.ShowTips("数据" + (flag ? "删除" : "恢复") + "成功!"); QueryData(); } } } } }