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.

170 lines
6.1 KiB
C#

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
{
/// <summary>
/// 生产管理-修改计划数业务
/// </summary>
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_weigh> 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<RefreshAction>.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<RefreshAction>.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<object>()
.WithSql(strSql).OrderBy("Weight_Id DESC")
.ToDataTable("*");
//dataTable = new DataTable();
//DataColumn materialName = new DataColumn("Material_Name", Type.GetType("System.String"));
//DataColumn setWeight = new DataColumn("Set_Weight", Type.GetType("System.String"));
//DataColumn setError = new DataColumn("Set_Error", Type.GetType("System.String"));
//DataColumn setError = new DataColumn("Set_Error", Type.GetType("System.String"));
//dataTable.Columns.Add(materialName);
//dataTable.Columns.Add(setWeight);
//dataTable.Columns.Add(setError);
//for (int i = 0; i < pmt_Weighs.Count; i++)
//{
// DataRow dataRow = dataTable.NewRow();
// Pmt_material pmt_Material = Product.PptPlan.PlanHelper.GetPmt_material(pmt_Weighs[i].Material_ID);
// if (pmt_Material != null&& pmt_Material.Material_name != null)
// {
// dataRow["Material_Name"] = pmt_Material.Material_name;
// }
// else
// {
// continue;
// }
// dataRow["Set_Weight"] = pmt_Weighs[i].Set_Weight.ToString();
// dataRow["Set_Error"] = pmt_Weighs[i].Set_Error.ToString();
// dataTable.Rows.Add(dataRow);
//}
}
return dataTable;
}
#endregion
#endregion
}
}