using Mesnac.Action.Base; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ICSharpCode.Core; using Mesnac.Action.ChemicalWeighing.Product.PptPlan.entity; using Mesnac.Action.ChemicalWeighing.Product.PptPlan; using Mesnac.Action.ChemicalWeighing.Technical.PmtRecipe.entity; namespace Mesnac.Action.ChemicalWeighing.Product { public class ReloadPlanInfo : ChemicalWeighingAction, IAction { public static event EventHandler ReloadPlan; private RuntimeParameter _runtime; private DbMCControl _clientGridControl = null; //网格计划控件 private string selectedPlanId = null;//选中计划号 private string selectedPlanState = null; public void Run(RuntimeParameter runtime) { base.RunIni(runtime); //必须要调用的 ICSharpCode.Core.LoggingService.Debug("重传计划信息..."); //获取界面控件 DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Base_PlanInfo").FirstOrDefault(); if (clientGridControl == null) { ICSharpCode.Core.LoggingService.Error("{生产计划-重传计划信息} 缺少计划列表网格控件..."); return; } this._runtime = runtime; this._clientGridControl = clientGridControl; DataGridView clientGridView = this._clientGridControl.BaseControl as DataGridView; if (clientGridView.SelectedRows.Count != 1) { string msg1_1 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Product_PptPlan_ModifyPlanNumAction_msg1_1")); //请选择 MessageBox.Show(msg1_1, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); this._runtime.IsReturn = true; return; } //获取选中的计划号 this.selectedPlanId = clientGridView.SelectedRows[0].Cells["plan_Id"].Value as string; this.selectedPlanState = clientGridView.SelectedRows[0].Cells["plan_state"].Value as string; if (this.selectedPlanState == "执行中") { //获取当前选中计划 Base_PlanInfo planInfo = PlanHelper.getPlanInfoByPlanId(this.selectedPlanId); //调试时注释 if (WriteRecipeInfoToPLC(planInfo)) //if(true) { ICSharpCode.Core.LoggingService.Debug("{生产计划-计划下传} 计划重传成功..."); planInfo.plan_beginTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); Product.PptPlan.PlanHelper.UpdateBasePlanStateInfo(planInfo); } else { MessageBox.Show("计划重传失败!"); } #region 触发事件 if (ReloadPlan != null) { ReloadPlan(runtime.BaseControl.MCRoot, System.EventArgs.Empty); } #endregion } else { MessageBox.Show("仅限重传执行中的计划", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } public static bool WriteRecipeInfoToPLC(Product.PptPlan.entity.Base_PlanInfo base_PlanInfo) { try { Base_RecipeInfo info = Technical.PmtRecipe.RecipeHelper.GetRecipeById(base_PlanInfo.recipe_Id); //配方编号 var plan_Id = Convert.ToInt32(base_PlanInfo.plan_Id); object[] recipeidArray = new object[9]; for (int i = 0; i < 9; i++) { recipeidArray[i] = base_PlanInfo.plan_Id.Substring(i, 1); } return true; } catch (Exception ex) { return true; } } } }