using Core.Mes.Client.Comm.Control; 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 frmBaseGradePrice : FrmBase { #region 定义变量 public frmBaseGradePrice() { InitializeComponent(); } #endregion #region 初始化 private void frmBaseGradePrice_Load(object sender, EventArgs e) { EntityHelper.ShowGridCaption(ultraGrid1.DisplayLayout.Bands[0]); for (int i = 2000; i < 2051; i++) { yeardrop.Items.Add(i); } string str1 = ""; for (int i = 1; i < 10; i++) { str1 = "0" + i.ToString2(); monthdrop.Items.Add(str1); } monthdrop.Items.Add(10); monthdrop.Items.Add(11); monthdrop.Items.Add(12); yeardrop.Value = System.DateTime.Now.Year.ToString2(); monthdrop.Value = System.DateTime.Now.Month.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 nianyue = yeardrop.Value.ToString2() + monthdrop.Value.ToString2(); string nian_yue = yeardrop.Value.ToString2() + "-" + monthdrop.Value.ToString2(); #endregion DataTable data = ServerHelper.GetData("com.steering.pss.pncost.base.ComBaseGradePrice.query2", new object[] { nianyue }, ob); GridHelper.CopyDataToDatatable(data, dataTable1, true); //GridHelper.RefreshAndAutoSize(ultraGrid1); //管子:PLN_REQINF_GP表IFBUYPLAN ='1' 年月暂时没加;坯子:PLN_ORDER_ZG_S表 PRO_MONTH管控年月 PLINE_CODE必须是C065,C065 //List datanew = EntityHelper.GetData( // "com.steering.pss.pncost.base.ComBaseGradePrice.query2", new object[] { nianyue, nian_yue }, ob); //costBaseGradePriceEntityBindingSource.DataSource = datanew; 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["CHK"].Value = false; GridEdite(ultraGrid1.Rows[i]); } ultraGrid1.UpdateData(); ultraGrid1.ActiveRow = ultraGrid1.Rows[0]; } /// 保存方法 /// /// 保存方法 /// private void Save() { string wuliao = ""; string xuanze = "false"; try { #region 验证信息 ultraGrid1.UpdateData(); for (int i = 0; i < ultraGrid1.Rows.Count; i++) { if (ultraGrid1.Rows[i].Cells["CHK"].Value.ToString() == "True") { if (ultraGrid1.Rows[i].Cells["COST_PRICE"].Value.ToString2() == "") { 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["CHK"].Value.ToString() == "True") { wuliao = ultraGrid1.Rows[i].Cells["WLBM"].Value.ToString2(); CostBaseGradePriceEntity parm = new CostBaseGradePriceEntity(); parm.WlId = ultraGrid1.Rows[i].Cells["WLBM"].Value.ToString2(); parm.WlDesc = ultraGrid1.Rows[i].Cells["WLMS"].Value.ToString2(); parm.BalYearMonth = ultraGrid1.Rows[i].Cells["YEAR_MONTH"].Value.ToString2(); parm.CostPrice = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["COST_PRICE"].Value.ToString3()); parm.Memo = ultraGrid1.Rows[i].Cells["MEMO"].Value.ToString(); if (ultraGrid1.Rows[i].Cells["create_name"].Value.ToString() == "")//判断是新增还是修改的保存 { parm.CreateName = this.UserInfo.GetUserName();//新增保存 string JsonStr = JSONFormat.Format(parm); ServerHelper.SetData("com.steering.pss.pncost.base.ComBaseGradePrice.isave", new object[] { JsonStr }, ob); } else { parm.UpdateName = this.UserInfo.GetUserName();//修改保存 string JsonStr = JSONFormat.Format(parm); ServerHelper.SetData("com.steering.pss.pncost.base.ComBaseGradePrice.usave", 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["WLBM"].Value.ToString() == wuliao) { ultraGrid1.Rows[i].Activate(); } } } /// 删除方法 /// /// 删除方法 /// private void Delete() { string wuliao = ""; string xuanze = "false"; try { #region 验证信息 ultraGrid1.UpdateData(); for (int i = 0; i < ultraGrid1.Rows.Count; i++) { if (ultraGrid1.Rows[i].Cells["CHK"].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["CHK"].Value.ToString() == "True") { wuliao = ultraGrid1.Rows[i].Cells["WLBM"].Value.ToString2(); CostBaseGradePriceEntity parm = new CostBaseGradePriceEntity(); parm.WlId = ultraGrid1.Rows[i].Cells["WLBM"].Value.ToString2(); parm.BalYearMonth = ultraGrid1.Rows[i].Cells["YEAR_MONTH"].Value.ToString2(); parm.UpdateName = this.UserInfo.GetUserName(); parm.DeleteName = this.UserInfo.GetUserName(); string JsonStr = JSONFormat.Format(parm); ServerHelper.SetData("com.steering.pss.pncost.base.ComBaseGradePrice.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["WLBM"].Value.ToString() == wuliao) { ultraGrid1.Rows[i].Activate(); } } } /// 恢复方法 /// /// 恢复方法 /// private void Resume() { string wuliao = ""; string xuanze = "false"; try { #region 验证信息 ultraGrid1.UpdateData(); for (int i = 0; i < ultraGrid1.Rows.Count; i++) { if (ultraGrid1.Rows[i].Cells["CHK"].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["CHK"].Value.ToString() == "True") { wuliao = ultraGrid1.Rows[i].Cells["WLBM"].Value.ToString2(); CostBaseGradePriceEntity parm = new CostBaseGradePriceEntity(); parm.WlId = ultraGrid1.Rows[i].Cells["WLBM"].Value.ToString2(); parm.BalYearMonth = ultraGrid1.Rows[i].Cells["YEAR_MONTH"].Value.ToString2(); parm.UpdateName = this.UserInfo.GetUserName(); string JsonStr = JSONFormat.Format(parm); ServerHelper.SetData("com.steering.pss.pncost.base.ComBaseGradePrice.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["WLBM"].Value.ToString() == wuliao) { ultraGrid1.Rows[i].Activate(); } } } #endregion #region 事件 /// 选择事件 /// /// 选择事件 /// private void ultraGrid1_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e) { ultraGrid1.UpdateData(); if (e.Cell.Column.Key == "CHK") { GridEdite(e.Cell.Row); } } /// 选择判断 /// /// 选择判断 /// private void GridEdite(UltraGridRow row) { if (row.GetValue("CHK") == "True") { 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 == "CHK") continue; if (cell.Column.CellActivation == Activation.AllowEdit) { cell.Activation = Activation.ActivateOnly; } } } } #endregion } }