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; 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; pmt_Recipe = RecipeHelper.GetRecipeByName(selectRecipeName); pmt_Weighs = Product.PptPlan.PlanHelper.GetPmt_weighList(pmt_Recipe.ID); #endregion DataTable table = DataListShow(); 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() { DataTable dataTable = null; if (pmt_Weighs != null && pmt_Weighs.Count > 0) { 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")); 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 } }