using Core.Mes.Client.Comm.Format; using Core.Mes.Client.Comm.Server; using Core.Mes.Client.Comm.Tool; using Core.StlMes.Client.PnCost.Models; using CoreFS.CA06; using Infragistics.Win.UltraWinGrid; using System; 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.PnCost { public partial class frmBasePrice : FrmBase { #region 定义变量 public frmBasePrice() { InitializeComponent(); } #endregion #region 初始化 private void frmBasePrice_Load(object sender, EventArgs e) { EntityHelper.ShowGridCaption(ultraGrid1.DisplayLayout.Bands[0]); DataTable dt = ServerHelper.GetData("com.steering.pss.pncost.base.ComBasePrice.queryPliao", new object[] { }, ob); for (int i = 2000; i < 2051; i++) { year.Items.Add(i); } for (int i = 2000; i < 2051; i++) { ultraComboYear.Items.Add(i); } ultraComboYear.Value = System.DateTime.Now.Year.ToString2(); Query(); } #endregion #region 方法 public override void ToolBar_Click(object sender, string ToolbarKey) { base.ToolBar_Click(sender, ToolbarKey); switch (ToolbarKey) { case "Query": Query(); break; case "Update": Save(); break; case "Delete": Delete(); break; case "Resume": Resume(); break; case "Close": this.Close(); break; } } /// 查询方法 /// /// 查询方法 /// private void Query() { #region 条件验证 string gang = ultraComboYear.Value.ToString2(); #endregion List data = EntityHelper.GetData( "com.steering.pss.pncost.base.ComBasePrice.query", new object[] { gang }, ob); costBasePriceEntityBindingSource.DataSource = data; if (ultraGrid1.Rows.Count == 0) { return; } for (int i = 0; i < ultraGrid1.Rows.Count; i++) { if (ultraGrid1.Rows[i].Cells["VALIDFLAG"].Value.ToString() == "无效") { ultraGrid1.Rows[i].Appearance.ForeColor = Color.Red; } ultraGrid1.Rows[i].Cells["xuanze"].Value = false; ultraGrid1.Rows[i].Cells["YEAR"].Value = ultraComboYear.Value.ToString2(); GridEdite(ultraGrid1.Rows[i]); } ultraGrid1.UpdateData(); ultraGrid1.ActiveRow = ultraGrid1.Rows[0]; } /// 保存方法 /// /// 保存方法 /// private void Save() { string stringnew = ""; string year = ""; string xuanze = "false"; try { #region 验证信息 ultraGrid1.UpdateData(); for (int i = 0; i < ultraGrid1.Rows.Count; i++) { if (ultraGrid1.Rows[i].Cells["xuanze"].Value.ToString() == "True") { if (ultraGrid1.Rows[i].Cells["ARCCODE"].Value.ToString() == "") { MessageUtil.ShowWarning("分类描述不能为空!请选择分类"); return; } if (ultraGrid1.Rows[i].Cells["ITEMCODE"].Value.ToString() == "") { MessageUtil.ShowWarning("物料名称不能为空!请选择物料"); return; } if (ultraGrid1.Rows[i].Cells["YEAR"].Value.ToString2() == "") { MessageUtil.ShowWarning("年份不能为空!请选择年份"); return; } if (ultraGrid1.Rows[i].Cells["CREATENAME"].Value.ToString() == "")//判断是新增还是修改的保存 { stringnew = ultraGrid1.Rows[i].Cells["ITEMCODE"].Value.ToString(); year = ultraGrid1.Rows[i].Cells["YEAR"].Value.ToString(); DataTable dt = ServerHelper.GetData("com.steering.pss.pncost.base.ComBasePrice.queryNum", new Object[] { stringnew, year }, ob); if (dt.Rows[0][0].ToString() == "1") { MessageUtil.ShowWarning("年份'" + year + "'重复!,请重新输入"); return; } } else //修改 { stringnew = ultraGrid1.Rows[i].Cells["ITEMCODE"].Value.ToString(); year = ultraGrid1.Rows[i].Cells["YEAR"].Value.ToString(); if (ultraGrid1.Rows[i].Cells["YEAR"].Value.ToString2() != ultraGrid1.Rows[i].Cells["YEARNEW"].Value.ToString2()) { DataTable dt = ServerHelper.GetData("com.steering.pss.pncost.base.ComBasePrice.queryNum", new Object[] { stringnew, year }, ob); if (dt.Rows[0][0].ToString() == "1") { MessageUtil.ShowWarning("年份'" + year + "'重复!,请重新输入"); return; } } } xuanze = "true"; } } if (xuanze == "false") { MessageUtil.ShowWarning("请选择你要保存的记录!"); return; } if (MessageUtil.ShowYesNoAndQuestion("是否确认保存?") == System.Windows.Forms.DialogResult.No) { return; } #endregion for (int i = 0; i < ultraGrid1.Rows.Count; i++) { if (ultraGrid1.Rows[i].Cells["xuanze"].Value.ToString() == "True") { CostBasePriceEntity parm = new CostBasePriceEntity(); parm.ItemCode = ultraGrid1.Rows[i].Cells["ITEMCODE"].Value.ToString(); parm.ItemName = ultraGrid1.Rows[i].Cells["ITEMNAME"].Value.ToString(); parm.ArcCode = ultraGrid1.Rows[i].Cells["ARCCODE"].Value.ToString(); parm.ArcItem = ultraGrid1.Rows[i].Cells["ARCITEM"].Value.ToString(); parm.Memo = ultraGrid1.Rows[i].Cells["MEMO"].Value.ToString(); parm.Year = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["YEAR"].Value.ToString()); parm.Month1 = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["MONTH1"].Value.ToString3()); parm.Month2 = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["MONTH2"].Value.ToString3()); parm.Month3 = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["MONTH3"].Value.ToString3()); parm.Month4 = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["MONTH4"].Value.ToString3()); parm.Month5 = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["MONTH5"].Value.ToString3()); parm.Month6 = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["MONTH6"].Value.ToString3()); parm.Month7 = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["MONTH7"].Value.ToString3()); parm.Month8 = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["MONTH8"].Value.ToString3()); parm.Month9 = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["MONTH9"].Value.ToString3()); parm.Month10 = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["MONTH10"].Value.ToString3()); parm.Month11 = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["MONTH11"].Value.ToString3()); parm.Month12 = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["MONTH12"].Value.ToString3()); if (ultraGrid1.Rows[i].Cells["CREATENAME"].Value.ToString() == "")//判断是新增还是修改的保存 { parm.CreateName = this.UserInfo.GetUserName();//新增保存 string JsonStr = JSONFormat.Format(parm); ServerHelper.SetData("com.steering.pss.pncost.base.ComBasePrice.isave", new object[] { JsonStr }, ob); } else { parm.UpdateName = this.UserInfo.GetUserName();//修改保存 string JsonStr = JSONFormat.Format(parm); string yeranew = ""; yeranew = ultraGrid1.Rows[i].Cells["YEARNEW"].Value.ToString(); ServerHelper.SetData("com.steering.pss.pncost.base.ComBasePrice.usave", new object[] { JsonStr, yeranew }, ob); } } } } catch (Exception ex) { MessageUtil.ShowError("保存失败!'" + ex.Message + "'"); return; } MessageUtil.ShowTips("保存成功!"); Query(); for (int i = 0; i < ultraGrid1.Rows.Count; i++) { if (ultraGrid1.Rows[i].Cells["ITEMCODE"].Value.ToString() == stringnew) { if (ultraGrid1.Rows[i].Cells["YEAR"].Value.ToString() == year) { ultraGrid1.Rows[i].Activate(); } } } } /// 删除方法 /// /// 删除方法 /// private void Delete() { string stringnew = ""; string year = ""; string xuanze = "false"; try { #region 验证信息 ultraGrid1.UpdateData(); for (int i = 0; i < ultraGrid1.Rows.Count; i++) { if (ultraGrid1.Rows[i].Cells["xuanze"].Value.ToString() == "True") { if (ultraGrid1.Rows[i].Cells["VALIDFLAG"].Value.ToString() != "有效") { MessageUtil.ShowWarning("选择的数据已经作废!"); return; } xuanze = "true"; } } if (xuanze == "false") { MessageUtil.ShowWarning("请选择你要删除的记录!"); return; } if (MessageUtil.ShowYesNoAndQuestion("是否确认删除?") == System.Windows.Forms.DialogResult.No) { return; } #endregion for (int i = 0; i < ultraGrid1.Rows.Count; i++) { if (ultraGrid1.Rows[i].Cells["xuanze"].Value.ToString() == "True") { stringnew = ultraGrid1.Rows[i].Cells["ITEMCODE"].Value.ToString(); year = ultraGrid1.Rows[i].Cells["YEAR"].Value.ToString(); CostBasePriceEntity parm = new CostBasePriceEntity(); parm.ItemCode = ultraGrid1.Rows[i].Cells["ITEMCODE"].Value.ToString(); parm.Year = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["YEAR"].Value.ToString()); parm.UpdateName = this.UserInfo.GetUserName(); parm.DeleteName = this.UserInfo.GetUserName(); string JsonStr = JSONFormat.Format(parm); ServerHelper.SetData("com.steering.pss.pncost.base.ComBasePrice.delete", new object[] { JsonStr }, ob); } } } catch (Exception ex) { MessageUtil.ShowError("删除失败!'" + ex.Message + "'"); return; } MessageUtil.ShowTips("删除成功!"); Query(); for (int i = 0; i < ultraGrid1.Rows.Count; i++) { if (ultraGrid1.Rows[i].Cells["ITEMCODE"].Value.ToString() == stringnew) { if (ultraGrid1.Rows[i].Cells["YEAR"].Value.ToString() == year) { ultraGrid1.Rows[i].Activate(); } } } } /// 恢复方法 /// /// 恢复方法 /// private void Resume() { string stringnew = ""; string year = ""; string xuanze = "false"; try { #region 验证信息 ultraGrid1.UpdateData(); for (int i = 0; i < ultraGrid1.Rows.Count; i++) { if (ultraGrid1.Rows[i].Cells["xuanze"].Value.ToString() == "True") { if (ultraGrid1.Rows[i].Cells["VALIDFLAG"].Value.ToString() != "无效") { MessageUtil.ShowWarning("选择的数据没有作废!"); return; } xuanze = "true"; } } if (xuanze == "false") { MessageUtil.ShowWarning("请选择你要恢复的记录!"); return; } if (MessageUtil.ShowYesNoAndQuestion("是否确认恢复?") == System.Windows.Forms.DialogResult.No) { return; } #endregion for (int i = 0; i < ultraGrid1.Rows.Count; i++) { if (ultraGrid1.Rows[i].Cells["xuanze"].Value.ToString() == "True") { stringnew = ultraGrid1.Rows[i].Cells["ITEMCODE"].Value.ToString(); year = ultraGrid1.Rows[i].Cells["YEAR"].Value.ToString(); CostBasePriceEntity parm = new CostBasePriceEntity(); parm.ItemCode = ultraGrid1.Rows[i].Cells["ITEMCODE"].Value.ToString(); parm.Year = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["YEAR"].Value.ToString()); parm.UpdateName = this.UserInfo.GetUserName(); string JsonStr = JSONFormat.Format(parm); ServerHelper.SetData("com.steering.pss.pncost.base.ComBasePrice.resume", new object[] { JsonStr }, ob); } } } catch (Exception ex) { MessageUtil.ShowError("恢复失败!'" + ex.Message + "'"); return; } MessageUtil.ShowTips("恢复成功!"); Query(); for (int i = 0; i < ultraGrid1.Rows.Count; i++) { if (ultraGrid1.Rows[i].Cells["ITEMCODE"].Value.ToString() == stringnew) { if (ultraGrid1.Rows[i].Cells["YEAR"].Value.ToString() == year) { ultraGrid1.Rows[i].Activate(); } } } } #endregion #region 事件 /// 选择事件 /// /// 选择事件 /// private void ultraGrid1_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e) { ultraGrid1.UpdateData(); if (e.Cell.Column.Key == "xuanze") { GridEdite(e.Cell.Row); } } /// 选择判断 /// /// 选择判断 /// private void GridEdite(UltraGridRow row) { if (row.GetValue("xuanze") == "True") { row.Cells["YEARNEW"].Value = row.Cells["YEAR"].Value; foreach (UltraGridCell cell in row.Cells) { if (cell.Column.CellActivation == Activation.AllowEdit) { cell.Activation = Activation.AllowEdit; } } } else { foreach (UltraGridCell cell in row.Cells) { if (cell.Column.Key == "xuanze") continue; if (cell.Column.CellActivation == Activation.AllowEdit) { cell.Activation = Activation.ActivateOnly; } } } } #endregion } }