You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
3.5 KiB
C#

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.Technical.PmtRecipe
{
public class SaveRecipe : ChemicalWeighingAction, IAction
{
public static event EventHandler SaveAsRecipe;
private RuntimeParameter _runtime;
private DbMCControl _clientGridControl = null;
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须要调用的
this._runtime = runtime;
ICSharpCode.Core.LoggingService<ModifyRecipeAction>.Debug("配方管理-另存配方...");
string selectRecipeName = null;
Base_RecipeInfo pmt_Recipe = null;
try
{
List<DbMCControl> 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<RefreshAction>.Error("{配方管理—另存配方}缺少配方管理控件...");
return;
}
this._clientGridControl = clientGridControl;
this._runtime = runtime;
TreeView clientGridView = this._clientGridControl.BaseControl as TreeView;
selectRecipeName = clientGridView.SelectedNode.Name as string;
//判断是否选择了已有配方
if (clientGridView.SelectedNode.Name == null || selectRecipeName == "全部")
{
MessageBox.Show("请选择一条要另存为的配方", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
this._runtime.IsReturn = true;
return;
}
//获取配方实体
pmt_Recipe = RecipeHelper.GetRecipeById(selectRecipeName);
if (pmt_Recipe != null)
{
FrmRecipe frmUpdateRecipe = new FrmRecipe(ActionType.SaveAs, pmt_Recipe);
frmUpdateRecipe.ShowDialog(this._runtime.BaseControl.MCRoot as Control);
if (frmUpdateRecipe.DialogResult == DialogResult.OK)
{
#region 触发事件
if (SaveAsRecipe != null)
{
SaveAsRecipe(this._runtime.BaseControl.MCRoot, System.EventArgs.Empty);
}
#endregion
frmUpdateRecipe.Dispose();
MessageBox.Show("配方信息另存成功!");
}
else
{
frmUpdateRecipe.Dispose();
}
}
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<ModifyRecipeAction>.Error("配方另存失败:" + ex.Message, ex);
MessageBox.Show(ex.Message, Mesnac.Basic.LanguageHelper.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
}