using Mesnac.Action.Base;
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 SetCratParam : ChemicalWeighingAction, IAction
{
private RuntimeParameter _runtime;
private DbMCControl _recipeGridControl = null;
private DbMCControl _materialGridControl = null;
private string selectRecipeId = null;
///
/// 设置参数事件定义
///
public static event EventHandler OnSetCratParam;
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须要调用的
this._runtime = runtime;
ICSharpCode.Core.LoggingService.Debug("配方管理-设置工艺参数...");
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._recipeGridControl = clientGridControl;
DbMCControl materialControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Base_RecipeMaterial").FirstOrDefault();
if(materialControl == null || !(materialControl.BaseControl is DataGridView))
{
ICSharpCode.Core.LoggingService.Error("{配方管理—删除配方}缺少配方关联物料信息控件...");
return;
}
this._materialGridControl = materialControl;
//判断是否选择了要修改的配方 及 关联的物料信息
TreeView recipeGridView = this._recipeGridControl.BaseControl as TreeView;
DataGridView materialGridView = this._materialGridControl.BaseControl as DataGridView;
if (recipeGridView.SelectedNode == null || materialGridView.SelectedRows.Count != 1)
{
MessageBox.Show("请选择一条要修改的配方", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
this._runtime.IsReturn = true;
return;
}
//判断该配方是否可进行修改(如果配方正在RT_Plan表中,查不允许修改)
selectRecipeId = recipeGridView.SelectedNode.Name as string;
if (Product.PptPlan.PlanHelper.PlanExistsRecipeName(selectRecipeId))
{
MessageBox.Show("该配方正在计划列表中,不能进行修改!", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
this._runtime.IsReturn = true;
return;
}
//获取物料编号
string materialId = materialGridView.SelectedRows[0].Cells["material_Id"].Value as string;
//执行设置参数
SetCratParamForm setCratParamForm = new SetCratParamForm(selectRecipeId, materialId);
setCratParamForm.ShowDialog(this._runtime.BaseControl.MCRoot as Control);
if (setCratParamForm.DialogResult == DialogResult.OK)
{
#region 触发事件
if (OnSetCratParam != null)
{
OnSetCratParam(this._runtime.BaseControl.MCRoot, System.EventArgs.Empty);
}
#endregion
setCratParamForm.Dispose();
MessageBox.Show("配方参数修改成功!");
}
else
{
setCratParamForm.Dispose();
}
}
}
}