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; using Core.Mes.Client.Comm.Format; using Core.Mes.Client.Comm.Control; namespace Core.StlMes.Client.SalePrice.BaseForm { public partial class FrmPriceDoc : FrmBase { string isValid = "1"; public FrmPriceDoc() { InitializeComponent(); } private void FrmPriceDoc_Load(object sender, EventArgs e) { EntityHelper.ShowGridCaption(gdPriceDoc.DisplayLayout.Bands[0]); // InitForm(); } 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 DeleteOrResume(bool flag) { gdPriceDoc.UpdateData(); UltraGridRow[] row = gdPriceDoc.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) { SlmPriceDocEntity spf = (SlmPriceDocEntity)uRow.ListObject; if (spf.Validflag == "无效") { MessageUtil.ShowWarning("您勾选的数据中存在已删除的数据,不必重复删除!"); return; } spf.Createname = UserInfo.GetUserName(); spf.Updatename = UserInfo.GetUserName(); parm.Add(JSONFormat.Format(spf)); } } else { foreach (var uRow in row) { SlmPriceDocEntity spf = (SlmPriceDocEntity)uRow.ListObject; if (spf.Validflag == "有效") { MessageUtil.ShowWarning("您勾选的数据中存在有效的数据,不必进行恢复!"); return; } spf.Createname = UserInfo.GetUserName(); spf.Updatename = UserInfo.GetUserName(); parm.Add(JSONFormat.Format(spf)); } } if (MessageUtil.ShowYesNoAndQuestion("是否" + (flag ? "删除" : "恢复") + "所选的数据!") == DialogResult.No) return; int i = ServerHelper.SetData("com.steering.pss.sale.price.server.CorePriceBaseDoc.deleteOrResume", new object[] { parm, flag }, this.ob); if (i >= 0) { MessageUtil.ShowTips("数据" + (flag ? "删除" : "恢复") + "成功!"); QueryData(); } else { MessageUtil.ShowTips("数据" + (flag ? "删除" : "恢复") + "失败!"); QueryData(); } } private void SaveFormData() { gdPriceDoc.UpdateData(); UltraGridRow[] row = gdPriceDoc.Rows.AsQueryable().Where(a => a.Cells["CHK"].Value.ToString().ToUpper() == "TRUE").ToArray(); if (row.Length <= 0) { MessageUtil.ShowWarning("请选择需要保存的数据!"); return; } if (row.Length > 0) { ArrayList parm = CheckFormData(row); if (parm == null || parm.Count <= 0) { return; } if (MessageUtil.ShowYesNoAndQuestion("是否确认保存数据!") == DialogResult.No) return; int i = ServerHelper.SetData("com.steering.pss.sale.price.server.CorePriceBaseDoc.save", new object[] { parm }, this.ob); if (i > 0) { MessageUtil.ShowTips("数据保存成功!"); QueryData(); } else { MessageUtil.ShowTips("数据保存失败!"); QueryData(); } } } private ArrayList CheckFormData(UltraGridRow[] row) { ArrayList parm = new ArrayList(); List list = new List(); foreach (var uRow in row) { SlmPriceDocEntity spf = (SlmPriceDocEntity)uRow.ListObject; if (spf.Validflag == "无效" && spf.Updatename != "") { MessageUtil.ShowWarning("【" + spf.PriceVerId + "】的因素已经无效,不能修改!"); return null; } spf.ValiddateBegin = Convert.ToDateTime(spf.ValiddateBegin).ToString("yyyy-MM-dd"); spf.ValiddateEnd = Convert.ToDateTime(spf.ValiddateEnd).ToString("yyyy-MM-dd"); ; spf.Createname= UserInfo.GetUserName(); spf.Updatename = UserInfo.GetUserName(); parm.Add(JSONFormat.Format(spf)); } return parm; } /// /// 查询数据 /// private void QueryData() { string priceVerId = ""; string priceVerDesc = ""; if (labelTextBox1.Checked) priceVerDesc = labelTextBox1.Text.Trim(); if (labelTextBox2.Checked) priceVerId = labelTextBox2.Text.Trim(); List list = EntityHelper.GetData( "com.steering.pss.sale.price.server.CorePriceBaseDoc.query", new object[] { priceVerId, priceVerDesc, isValid }, this.ob); slmPriceDocEntityBindingSource.DataSource = list; UltraGridBand ugb = this.gdPriceDoc.DisplayLayout.Bands[0]; UltraGridColumn[] col = new UltraGridColumn[] { ugb.Columns["priceVerDesc"] }; GridHelper.RefreshAndAutoSizeExceptColumns(gdPriceDoc, col); } private void gdPriceDoc_InitializeRow(object sender, InitializeRowEventArgs e) { if (e.Row != null) { if (e.Row.Cells["VALIDFLAG"].Value.ToString() == "无效") { e.Row.Appearance.ForeColor = Color.Red; } else { e.Row.Appearance.ForeColor = Color.Black; } } } private void gdPriceDoc_AfterRowInsert(object sender, RowEventArgs e) { string maxId = gdPriceDoc.Rows.AsQueryable().Max(a => a.Cells["PriceVerId"].Value.ToString()); if (maxId == "") { e.Row.Cells["PriceVerId"].Value = "D000001"; } else { string str = "D" + (Convert.ToInt32(maxId.Substring(1, 6)) + 1).ToString().PadLeft(6, '0'); e.Row.Cells["PriceVerId"].Value = str; } } private void chkValid_CheckedChanged(object sender, EventArgs e) { if (chkValid.Checked) { isValid = "0"; } else { isValid = "1"; } } } }