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.

164 lines
6.5 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Mesnac.Action.Base;
using Mesnac.Action.ChemicalWeighing.Entity;
using Mesnac.Action.ChemicalWeighing.Product.XlPlan;
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 EditMaterialAction : ChemicalWeighingAction, IAction
{
#region 字段定义
private RuntimeParameter _runtime;
private DbMCControl _clientGridControl = null;
private DbMCControl _weighGridControl=null;
#endregion
#region 事件定义
/// <summary>
/// 修改计划数事件定义
/// </summary>
public static event EventHandler OnModifyMaterial;
#endregion
#region 业务入口
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须要调用的
this._runtime = runtime;
ICSharpCode.Core.LoggingService<ModifyAction>.Debug("配方管理-修改配方...");
try
{
#region 变量定义
string selectRecipeName = string.Empty;
string selectRecipeID = string.Empty;
xl_recipe pmt_Recipe = null;
string _recipeName = string.Empty;
string _recipeCode = string.Empty;
int? _mixerLine;
string _groupBags = string.Empty;
string _remark = string.Empty;
#endregion
#region 1 获取界面控件
DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "xl_recipe").FirstOrDefault();
if (clientGridControl == null || !(clientGridControl.BaseControl is DataGridView))
{
ICSharpCode.Core.LoggingService<RefreshAction>.Error("{配方管理—编辑配方物料}缺少配方物料管理控件...");
return;
}
this._clientGridControl = clientGridControl;
this._runtime = runtime;
DataGridView clientGridView = this._clientGridControl.BaseControl as DataGridView;
DbMCControl weighGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "xl_weigh").FirstOrDefault();
if (weighGridControl == null || !(weighGridControl.BaseControl is DataGridView))
{
ICSharpCode.Core.LoggingService<RefreshAction>.Error("{配方管理—编辑配方物料}缺少配方物料管理控件...");
return;
}
#endregion
this._weighGridControl = weighGridControl;
DataGridView weighGridView = this._weighGridControl.BaseControl as DataGridView;
#region 2 判断是否选择了要修改的配方
if (clientGridView.SelectedRows.Count != 1)
{
MessageBox.Show("请选择一条要修改的配方", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
this._runtime.IsReturn = true;
return;
}
#endregion
if (weighGridView.SelectedRows.Count != 1)
{
MessageBox.Show("请选择一条要修改的配方物料", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
this._runtime.IsReturn = true;
return;
}
#region 3 判断该配方是否可进行修改如果配方正在RT_Plan表中查不允许修改
selectRecipeID = clientGridView.SelectedRows[0].Cells["ID"].Value as string;
selectRecipeName = clientGridView.SelectedRows[0].Cells["Recipe_Name"].Value as string;
if (Product.XlPlan.PlanHelper.PlanExistsRecipeName(selectRecipeID))
{
MessageBox.Show("该配方正在计划列表中,不能进行修改!", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
this._runtime.IsReturn = true;
return;
}
#endregion
#region 4 获取配方实体
pmt_Recipe = RecipeHelper.GetRecipeByName(selectRecipeID);
#endregion
#region 5 执行配方修改
if (pmt_Recipe != null)
{
_recipeCode = pmt_Recipe.Recipe_Code;
_recipeName = pmt_Recipe.Recipe_Name;
_mixerLine = 0;
_groupBags = pmt_Recipe.GroupBags.ToString();
_remark = pmt_Recipe.Remark;
//decimal totalError = Convert.ToDecimal(pmt_Recipe.Total_Error);
int selectWeighID =Convert.ToInt32(weighGridView.SelectedRows[0].Cells["ID"].Value);//物料对应ID
string materialName = weighGridView.SelectedRows[0].Cells["Material_Name"].Value as string;//料仓名称
//var material = PlanHelper.GetXl_material(selectRecipeID, selectWeighID);
FrmRecipeMaterial frmUpdateRecipe = new FrmRecipeMaterial(ActionType.Modify, selectRecipeID, selectWeighID.ToString(), materialName);
frmUpdateRecipe.ShowDialog(this._runtime.BaseControl.MCRoot as Control);
if (frmUpdateRecipe.DialogResult == DialogResult.OK)
{
#region 触发事件
if (OnModifyMaterial != null)
{
OnModifyMaterial(this._runtime.BaseControl.MCRoot, System.EventArgs.Empty);
}
#endregion
frmUpdateRecipe.Dispose();
MessageBox.Show("配方信息修改成功!");
}
else
{
frmUpdateRecipe.Dispose();
}
}
#endregion
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<ModifyAction>.Error("修改配方失败:" + ex.Message, ex);
MessageBox.Show(ex.Message, Mesnac.Basic.LanguageHelper.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
#endregion
}
}