using ICSharpCode.Core; using Mesnac.Action.Base; using Mesnac.Action.ChemicalWeighing.Entity; using Mesnac.Action.ChemicalWeighing.Technical.PmtRecipe; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Mesnac.Action.ChemicalWeighing.Technical.XlRecipe { public class AddMaterialAction : ChemicalWeighingAction, IAction { #region 事件定义 /// /// 添加配方事件定义 /// public static event EventHandler OnAddMaterial; #endregion #region 字段定义 private RuntimeParameter _runtime; private DbMCControl _clientGridControl = null; string selectRecipeID = string.Empty; #endregion #region IAction接口实现 public void Run(RuntimeParameter runtime) { base.RunIni(runtime); this._runtime = runtime; ICSharpCode.Core.LoggingService.Debug("配方管理—添加配方物料业务..."); DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "xl_weigh").FirstOrDefault(); if (clientGridControl == null || !(clientGridControl.BaseControl is DataGridView)) { ICSharpCode.Core.LoggingService.Error("{配方管理—添加配方物料}缺少配方管理控件..."); return; } this._clientGridControl = clientGridControl; DataGridView clientGridView = this._clientGridControl.BaseControl as DataGridView; DbMCControl recipGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "xl_recipe").FirstOrDefault(); if (recipGridControl == null || !(recipGridControl.BaseControl is DataGridView)) { ICSharpCode.Core.LoggingService.Error("{配方管理—添加配方物料}缺少配方管理控件..."); return; } DataGridView recipGridView = recipGridControl.BaseControl as DataGridView; if (recipGridView.SelectedRows.Count != 1) { MessageBox.Show("请选择一条要新增的配方", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); this._runtime.IsReturn = true; return; } selectRecipeID = recipGridView.SelectedRows[0].Cells["ID"].Value as string; this.DoWork(); } #endregion #region 方法定义 /// /// 添加配方 /// protected void DoWork() { this._runtime.BaseControl.MCEnabled = false; try { FrmRecipeMaterial frmNewRecipe = new FrmRecipeMaterial(ActionType.Add, selectRecipeID); frmNewRecipe.ShowDialog(this._runtime.BaseControl.MCRoot as Control); if (frmNewRecipe.DialogResult == DialogResult.OK) { #region 触发事件 if (OnAddMaterial != null) { OnAddMaterial(this._runtime.BaseControl.MCRoot, System.EventArgs.Empty); } #endregion frmNewRecipe.Dispose(); MessageBox.Show("新配方添加成功!"); } else { frmNewRecipe.Dispose(); } } catch (Exception ex) { ICSharpCode.Core.LoggingService.Error("添加新配方异常:" + ex.Message, ex); #region 记录操作日志 base.DBLog(ex.Message); #endregion MessageBox.Show(ex.Message, Mesnac.Basic.LanguageHelper.WarnCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); } this._runtime.BaseControl.MCEnabled = true; } #endregion } }