using ICSharpCode.Core; using Mesnac.Action.Base; using Mesnac.Action.ChemicalWeighing.Entity; using Mesnac.Action.ChemicalWeighing.Technical.PmtRecipe.entity; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Mesnac.Action.ChemicalWeighing.MaterialManage { class ModifyMaterialAction : ChemicalWeighingAction, IAction { #region 字段定义 private RuntimeParameter _runtime; private DbMCControl _clientGridControl = null; //用户列表控件 #endregion #region 事件定义 /// /// 修改用户信息事件定义 /// public static event EventHandler OnModifyMaterial; #endregion public void Run(RuntimeParameter runtime) { base.RunIni(runtime); //必须要调用 this._runtime = runtime; #region 获取界面控件 DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Base_MaterialInfo").FirstOrDefault(); if (clientGridControl == null) { ICSharpCode.Core.LoggingService.Error("缺少物料信息列表控件..."); return; } this._runtime = runtime; this._clientGridControl = clientGridControl; DataGridView clientGridView = this._clientGridControl.BaseControl as DataGridView; #endregion //验证是否选中某物料 if (clientGridView.SelectedRows.Count != 1) { string msg1 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_MaterialManage_ModifyMaterialAction_msg1")); //请选择一项要修改的物料! MessageBox.Show(msg1, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); this._runtime.IsReturn = true; return; } //封装选中行对应的物料对象 Base_MaterialInfo material = new Base_MaterialInfo { materialId = clientGridView.SelectedRows[0].Cells["Material_id"].Value as string, materialName = clientGridView.SelectedRows[0].Cells["Material_name"].Value as string }; #region 执行修改物料信息 FrmMaterial frmMaterial = new FrmMaterial(ActionType.Modify, material); DialogResult result = frmMaterial.ShowDialog(); if (result == DialogResult.OK) { Base_MaterialInfo newMaterial = frmMaterial.Material; newMaterial.uid = material.materialId; //在此设定物料对象的ID frmMaterial.Dispose(); string msg2 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_MaterialManage_ModifyMaterialAction_msg2")); //确认修改{0}物料信息? msg2 = String.Format(msg2, material.materialName); if (MessageBox.Show(msg2, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { //更新数据库中的物料信息 MaterialHelper.updateMaterial(newMaterial); #region 触发刷新物料列表事件 if (OnModifyMaterial != null) { OnModifyMaterial(this._runtime.BaseControl.MCRoot, System.EventArgs.Empty); } #endregion } } else { frmMaterial.Dispose(); } #endregion } } }