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.DBHelper;
namespace Mesnac.Action.ChemicalWeighing.Technical.PmtRecipe
{
///
/// 生产管理-修改计划数业务
///
public class SelectRecipe : ChemicalWeighingAction, IAction
{
#region 字段定义
private RuntimeParameter _runtime;
private DbMCControl _recipeGridControl = null;
private DbMCControl _weighGridControl = null;
private Pmt_recipe pmt_Recipe = null;
private List pmt_Weighs = null;
#endregion
#region 业务入口
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须要调用的
this._runtime = runtime;
#region 获取界面recipe控件
DbMCControl recipeGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Pmt_recipe").FirstOrDefault();
if (recipeGridControl == null || !(recipeGridControl.BaseControl is DataGridView))
{
ICSharpCode.Core.LoggingService.Error("{配方管理—删除配方}缺少配方管理控件...");
return;
}
this._recipeGridControl = recipeGridControl;
#endregion
this.DoWork();
}
#endregion
#region 方法定义
protected void DoWork()
{
#region 1 判断是否选择了一条配方并显示物料信息
DataGridView recipeGridView = this._recipeGridControl.BaseControl as DataGridView;
if (recipeGridView.SelectedRows.Count == 1)
{
#region 变量定义
string selectRecipeName = null;
#endregion
#region 2.1 获取界面weigh控件
DbMCControl weighGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Pmt_weigh").FirstOrDefault();
if (weighGridControl == null || !(weighGridControl.BaseControl is DataGridView))
{
ICSharpCode.Core.LoggingService.Error("{配方管理—选择配方}缺少配方物料显示控件...");
return;
}
this._weighGridControl = weighGridControl;
DataGridView weighGridView = this._weighGridControl.BaseControl as DataGridView;
#endregion
#region 获取配方的物料信息List
selectRecipeName = recipeGridView.SelectedRows[0].Cells["Recipe_Name"].Value as string;
string selectId = recipeGridView.SelectedRows[0].Cells["ID"].Value as string;
pmt_Recipe = RecipeHelper.GetRecipeByName(selectRecipeName);
pmt_Weighs = Product.PptPlan.PlanHelper.GetPmt_weighList(selectId);
#endregion
DataTable table = DataListShow(selectId);
lock (String.Empty)
{
//本地计划
if (this._weighGridControl != null && table != null)
{
this._weighGridControl.BaseControl.BindDataSource = null;
this._weighGridControl.BaseControl.BindDataSource = table;
}
}
}
else
{
return;
}
#endregion
}
#region DataTable数据整理显示
private DataTable DataListShow(string RecipeID)
{
DataTable dataTable = null;
if (pmt_Weighs != null && pmt_Weighs.Count > 0)
{
IFreeSql fsql = FreeHelper.Instance;
string strSql = $@"SELECT w.Weight_Id,m.Material_name,Set_Weight,Set_Error,TheoryRate,
CASE
WHEN IsRate=1 THEN '是'
WHEN IsRate=0 THEN '否'
END as IsRate
FROM Pmt_weigh w inner join Pmt_material m on w.Material_ID=m.ID
where Recipe_ID = '{RecipeID}'";
dataTable = fsql.Select