using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data; using ICSharpCode.Core; using Mesnac.Controls.Base; using Mesnac.Action.Base; using Mesnac.Codd.Session; using Mesnac.Action.ChemicalWeighing.Entity; using Mesnac.Action.ChemicalWeighing.Technical.PmtRecipe.entity; namespace Mesnac.Action.ChemicalWeighing.Technical.PmtRecipe { /// /// 生产管理-修改计划数业务 /// public class ModifyRecipeAction : ChemicalWeighingAction, IAction { #region 字段定义 private RuntimeParameter _runtime; private DbMCControl _clientGridControl = null; #endregion #region 事件定义 /// /// 修改计划数事件定义 /// public static event EventHandler OnModifyRecipe; #endregion #region 业务入口 public void Run(RuntimeParameter runtime) { base.RunIni(runtime); //必须要调用的 this._runtime = runtime; ICSharpCode.Core.LoggingService.Debug("配方管理-修改配方..."); try { #region 变量定义 string selectRecipeName = null; Base_RecipeInfo pmt_Recipe = null; #endregion #region 1 获取界面控件 List recipeControlList = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Base_RecipeInfo"); DbMCControl clientGridControl = recipeControlList.Where(x => x.BaseControl is TreeView).FirstOrDefault(); if (clientGridControl == null || !(clientGridControl.BaseControl is TreeView)) { ICSharpCode.Core.LoggingService.Error("{配方管理—删除配方}缺少配方管理控件..."); return; } this._clientGridControl = clientGridControl; this._runtime = runtime; TreeView clientGridView = this._clientGridControl.BaseControl as TreeView; #endregion #region 2 判断是否选择了要修改的配方 if (clientGridView.SelectedNode == null) { MessageBox.Show("请选择一条要修改的配方", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); this._runtime.IsReturn = true; return; } #endregion #region 3 判断该配方是否可进行修改(如果配方正在RT_Plan表中,查不允许修改) selectRecipeName = clientGridView.SelectedNode.Name as string; if (Product.PptPlan.PlanHelper.PlanExistsRecipeName(selectRecipeName)) { MessageBox.Show("该配方正在计划列表中,不能进行修改!", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); this._runtime.IsReturn = true; return; } #endregion #region 4 获取配方实体 pmt_Recipe = RecipeHelper.GetRecipeById(selectRecipeName); #endregion #region 5 执行配方修改 if (pmt_Recipe != null) { FrmRecipe frmUpdateRecipe = new FrmRecipe(ActionType.Modify, pmt_Recipe); frmUpdateRecipe.ShowDialog(this._runtime.BaseControl.MCRoot as Control); if (frmUpdateRecipe.DialogResult == DialogResult.OK) { #region 触发事件 if (OnModifyRecipe != null) { OnModifyRecipe(this._runtime.BaseControl.MCRoot, System.EventArgs.Empty); } #endregion frmUpdateRecipe.Dispose(); MessageBox.Show("配方信息修改成功!"); } else { frmUpdateRecipe.Dispose(); } } #endregion } catch (Exception ex) { ICSharpCode.Core.LoggingService.Error("修改配方失败:" + ex.Message, ex); MessageBox.Show(ex.Message, Mesnac.Basic.LanguageHelper.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } #endregion } }