using DataBlockHelper.Entity.DB2106Entity; using HslCommunication.Instrument.DLT; using Mesnac.Action.Base; using Mesnac.Action.ChemicalWeighing.AutoControl.DB; using Mesnac.Action.ChemicalWeighing.AutoControl.Entity; using Mesnac.Action.ChemicalWeighing.FreeDb; using Mesnac.Action.ChemicalWeighing.LjPlanning; using Mesnac.Controls.Base; using Mesnac.Controls.Default; using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Mesnac.Action.ChemicalWeighing.AutoControl { public class RefreshAction : ChemicalWeighingAction, IAction { GelerWeterControlsEntity ControlsEntity = new GelerWeterControlsEntity(); private List McControls; public void Run(RuntimeParameter runtime) { base.RunIni(runtime); //必须要调用 McControls = GetAllControls(); ControlImport(); ControlInitFromPLC(); } #region 控件初始化 /// /// 控件从Plc初始化 /// private void ControlInitFromPLC() { //switch (SingleSelect()) //{ // case 1: // LjPlanningPlcHelp.GetGelatG1. //} ControlsEntity.ChooseMaterial1.DataSource = StockMaterrialDbHelp.GetSiloMaterrial(); ControlsEntity.ChooseMaterial2.DataSource = StockMaterrialDbHelp.GetSiloMaterrial(); var selected = FreeSqlUnit.Instance.Select().Where(x => x.DeviceId == SingleSelect()).ToList(); if (selected.Count != 0) { ControlsEntity.ChooseMaterial1.SelectedValue = selected[0].MaterrialId; ControlsEntity.ChooseMaterial2.SelectedValue = selected[1].MaterrialId; } else { ControlsEntity.ChooseMaterial1.SelectedIndex = 0; ControlsEntity.ChooseMaterial2.SelectedIndex = 0; } var getGelatG1 = LjPlanningPlcHelp.GetGelatG1; var getWeterM1 = LjPlanningPlcHelp.GetWeterM1; var getGelatG2 = LjPlanningPlcHelp.GetGelatG2; var getWeterM2 = LjPlanningPlcHelp.GetWeterM2; var getGelatG3 = LjPlanningPlcHelp.GetGelatG3; var getWeterM3 = LjPlanningPlcHelp.GetWeterM3; var getGelatG4 = LjPlanningPlcHelp.GetGelatG4; var getWeterM4 = LjPlanningPlcHelp.GetWeterM4; var getGelatG5 = LjPlanningPlcHelp.GetGelatG5; var getWeterM5 = LjPlanningPlcHelp.GetWeterM5; var getGelatG6 = LjPlanningPlcHelp.GetGelatG6; var getWeterM6 = LjPlanningPlcHelp.GetWeterM6; var getGelatG7 = LjPlanningPlcHelp.GetGelatG7; var getWeterM7 = LjPlanningPlcHelp.GetWeterM7; var getGelatG8 = LjPlanningPlcHelp.GetGelatG8; var getWeterM8 = LjPlanningPlcHelp.GetWeterM8; switch (SingleSelect()) { case 1: ControlsEntity.MaterialWeight1.MCValue = getGelatG1.RecipePlcViews[0].Set; ControlsEntity.MaterialWeight2.MCValue = getGelatG1.RecipePlcViews[1].Set; ControlsEntity.MaterialTolerance1.MCValue = getGelatG1.RecipePlcViews[0].Tolerance; ControlsEntity.MaterialTolerance2.MCValue = getGelatG1.RecipePlcViews[1].Tolerance; ControlsEntity.GelSpeedSet.MCValue = getGelatG1.RecipeSteps[0].MixSpeed; ControlsEntity.GelPosTimeA.MCValue = getGelatG1.RecipeSteps[2].MixTemp; ControlsEntity.GelNagTimeB.MCValue = getGelatG1.RecipeSteps[2].MixSpeed; ControlsEntity.GelPosTimeC.MCValue = getGelatG1.RecipeSteps[2].MixTime; ControlsEntity.GelWaterTime.MCValue = getGelatG1.RecipeSteps[4].MixTime; ControlsEntity.GelWaitTime.MCValue = getGelatG1.RecipeSteps[6].MixTime; ControlsEntity.GelCloseHeatTime.MCValue = getGelatG1.RecipeSteps[7].MixTime; ControlsEntity.GelOutDelayTime.MCValue = getGelatG1.RecipeSteps[7].MixTemp; ControlsEntity.WetDryWeight.MCValue = getWeterM1[1].SetValue; ControlsEntity.WetMixTime.MCValue = getWeterM1[2].MixTime; ControlsEntity.WetOutDelayTime.MCValue = getWeterM1[4].MixTime; break; case 2: ControlsEntity.MaterialWeight1.MCValue = getGelatG2.RecipePlcViews[0].Set; ControlsEntity.MaterialWeight2.MCValue = getGelatG2.RecipePlcViews[1].Set; ControlsEntity.MaterialTolerance1.MCValue = getGelatG2.RecipePlcViews[0].Tolerance; ControlsEntity.MaterialTolerance2.MCValue = getGelatG2.RecipePlcViews[1].Tolerance; ControlsEntity.GelSpeedSet.MCValue = getGelatG2.RecipeSteps[0].MixSpeed; ControlsEntity.GelPosTimeA.MCValue = getGelatG2.RecipeSteps[2].MixTemp; ControlsEntity.GelNagTimeB.MCValue = getGelatG2.RecipeSteps[2].MixSpeed; ControlsEntity.GelPosTimeC.MCValue = getGelatG2.RecipeSteps[2].MixTime; ControlsEntity.GelWaterTime.MCValue = getGelatG2.RecipeSteps[4].MixTime; ControlsEntity.GelWaitTime.MCValue = getGelatG2.RecipeSteps[6].MixTime; ControlsEntity.GelCloseHeatTime.MCValue = getGelatG2.RecipeSteps[7].MixTime; ControlsEntity.GelOutDelayTime.MCValue = getGelatG2.RecipeSteps[7].MixTemp; ControlsEntity.WetDryWeight.MCValue = getWeterM2[1].SetValue; ControlsEntity.WetMixTime.MCValue = getWeterM2[2].MixTime; ControlsEntity.WetOutDelayTime.MCValue = getWeterM2[4].MixTime; break; case 3: ControlsEntity.MaterialWeight1.MCValue = getGelatG3.RecipePlcViews[0].Set; ControlsEntity.MaterialWeight2.MCValue = getGelatG3.RecipePlcViews[1].Set; ControlsEntity.MaterialTolerance1.MCValue = getGelatG3.RecipePlcViews[0].Tolerance; ControlsEntity.MaterialTolerance2.MCValue = getGelatG3.RecipePlcViews[1].Tolerance; ControlsEntity.GelSpeedSet.MCValue = getGelatG3.RecipeSteps[0].MixSpeed; ControlsEntity.GelPosTimeA.MCValue = getGelatG3.RecipeSteps[2].MixTemp; ControlsEntity.GelNagTimeB.MCValue = getGelatG3.RecipeSteps[2].MixSpeed; ControlsEntity.GelPosTimeC.MCValue = getGelatG3.RecipeSteps[2].MixTime; ControlsEntity.GelWaterTime.MCValue = getGelatG3.RecipeSteps[4].MixTime; ControlsEntity.GelWaitTime.MCValue = getGelatG3.RecipeSteps[6].MixTime; ControlsEntity.GelCloseHeatTime.MCValue = getGelatG3.RecipeSteps[7].MixTime; ControlsEntity.GelOutDelayTime.MCValue = getGelatG3.RecipeSteps[7].MixTemp; ControlsEntity.WetDryWeight.MCValue = getWeterM3[1].SetValue; ControlsEntity.WetMixTime.MCValue = getWeterM3[2].MixTime; ControlsEntity.WetOutDelayTime.MCValue = getWeterM3[4].MixTime; break; case 4: ControlsEntity.MaterialWeight1.MCValue = getGelatG4.RecipePlcViews[0].Set; ControlsEntity.MaterialWeight2.MCValue = getGelatG4.RecipePlcViews[1].Set; ControlsEntity.MaterialTolerance1.MCValue = getGelatG4.RecipePlcViews[0].Tolerance; ControlsEntity.MaterialTolerance2.MCValue = getGelatG4.RecipePlcViews[1].Tolerance; ControlsEntity.GelSpeedSet.MCValue = getGelatG4.RecipeSteps[0].MixSpeed; ControlsEntity.GelPosTimeA.MCValue = getGelatG4.RecipeSteps[2].MixTemp; ControlsEntity.GelNagTimeB.MCValue = getGelatG4.RecipeSteps[2].MixSpeed; ControlsEntity.GelPosTimeC.MCValue = getGelatG4.RecipeSteps[2].MixTime; ControlsEntity.GelWaterTime.MCValue = getGelatG4.RecipeSteps[4].MixTime; ControlsEntity.GelWaitTime.MCValue = getGelatG4.RecipeSteps[6].MixTime; ControlsEntity.GelCloseHeatTime.MCValue = getGelatG4.RecipeSteps[7].MixTime; ControlsEntity.GelOutDelayTime.MCValue = getGelatG4.RecipeSteps[7].MixTemp; ControlsEntity.WetDryWeight.MCValue = getWeterM4[1].SetValue; ControlsEntity.WetMixTime.MCValue = getWeterM4[2].MixTime; ControlsEntity.WetOutDelayTime.MCValue = getWeterM4[4].MixTime; break; case 5: ControlsEntity.MaterialWeight1.MCValue = getGelatG5.RecipePlcViews[0].Set; ControlsEntity.MaterialWeight2.MCValue = getGelatG5.RecipePlcViews[1].Set; ControlsEntity.MaterialTolerance1.MCValue = getGelatG5.RecipePlcViews[0].Tolerance; ControlsEntity.MaterialTolerance2.MCValue = getGelatG5.RecipePlcViews[1].Tolerance; ControlsEntity.GelSpeedSet.MCValue = getGelatG5.RecipeSteps[0].MixSpeed; ControlsEntity.GelPosTimeA.MCValue = getGelatG5.RecipeSteps[2].MixTemp; ControlsEntity.GelNagTimeB.MCValue = getGelatG5.RecipeSteps[2].MixSpeed; ControlsEntity.GelPosTimeC.MCValue = getGelatG5.RecipeSteps[2].MixTime; ControlsEntity.GelWaterTime.MCValue = getGelatG5.RecipeSteps[4].MixTime; ControlsEntity.GelWaitTime.MCValue = getGelatG5.RecipeSteps[6].MixTime; ControlsEntity.GelCloseHeatTime.MCValue = getGelatG5.RecipeSteps[7].MixTime; ControlsEntity.GelOutDelayTime.MCValue = getGelatG5.RecipeSteps[7].MixTemp; ControlsEntity.WetDryWeight.MCValue = getWeterM5[1].SetValue; ControlsEntity.WetMixTime.MCValue = getWeterM5[2].MixTime; ControlsEntity.WetOutDelayTime.MCValue = getWeterM5[4].MixTime; break; case 6: ControlsEntity.MaterialWeight1.MCValue = getGelatG6.RecipePlcViews[0].Set; ControlsEntity.MaterialWeight2.MCValue = getGelatG6.RecipePlcViews[1].Set; ControlsEntity.MaterialTolerance1.MCValue = getGelatG6.RecipePlcViews[0].Tolerance; ControlsEntity.MaterialTolerance2.MCValue = getGelatG6.RecipePlcViews[1].Tolerance; ControlsEntity.GelSpeedSet.MCValue = getGelatG6.RecipeSteps[0].MixSpeed; ControlsEntity.GelPosTimeA.MCValue = getGelatG6.RecipeSteps[2].MixTemp; ControlsEntity.GelNagTimeB.MCValue = getGelatG6.RecipeSteps[2].MixSpeed; ControlsEntity.GelPosTimeC.MCValue = getGelatG6.RecipeSteps[2].MixTime; ControlsEntity.GelWaterTime.MCValue = getGelatG6.RecipeSteps[4].MixTime; ControlsEntity.GelWaitTime.MCValue = getGelatG6.RecipeSteps[6].MixTime; ControlsEntity.GelCloseHeatTime.MCValue = getGelatG6.RecipeSteps[7].MixTime; ControlsEntity.GelOutDelayTime.MCValue = getGelatG6.RecipeSteps[7].MixTemp; ControlsEntity.WetDryWeight.MCValue = getWeterM6[1].SetValue; ControlsEntity.WetMixTime.MCValue = getWeterM6[2].MixTime; ControlsEntity.WetOutDelayTime.MCValue = getWeterM6[4].MixTime; break; case 7: ControlsEntity.MaterialWeight1.MCValue = getGelatG7.RecipePlcViews[0].Set; ControlsEntity.MaterialWeight2.MCValue = getGelatG7.RecipePlcViews[1].Set; ControlsEntity.MaterialTolerance1.MCValue = getGelatG7.RecipePlcViews[0].Tolerance; ControlsEntity.MaterialTolerance2.MCValue = getGelatG7.RecipePlcViews[1].Tolerance; ControlsEntity.GelSpeedSet.MCValue = getGelatG7.RecipeSteps[0].MixSpeed; ControlsEntity.GelPosTimeA.MCValue = getGelatG7.RecipeSteps[2].MixTemp; ControlsEntity.GelNagTimeB.MCValue = getGelatG7.RecipeSteps[2].MixSpeed; ControlsEntity.GelPosTimeC.MCValue = getGelatG7.RecipeSteps[2].MixTime; ControlsEntity.GelWaterTime.MCValue = getGelatG7.RecipeSteps[4].MixTime; ControlsEntity.GelWaitTime.MCValue = getGelatG7.RecipeSteps[6].MixTime; ControlsEntity.GelCloseHeatTime.MCValue = getGelatG7.RecipeSteps[7].MixTime; ControlsEntity.GelOutDelayTime.MCValue = getGelatG7.RecipeSteps[7].MixTemp; ControlsEntity.WetDryWeight.MCValue = getWeterM7[1].SetValue; ControlsEntity.WetMixTime.MCValue = getWeterM7[2].MixTime; ControlsEntity.WetOutDelayTime.MCValue = getWeterM7[4].MixTime; break; case 8: ControlsEntity.MaterialWeight1.MCValue = getGelatG8.RecipePlcViews[0].Set; ControlsEntity.MaterialWeight2.MCValue = getGelatG8.RecipePlcViews[1].Set; ControlsEntity.MaterialTolerance1.MCValue = getGelatG8.RecipePlcViews[0].Tolerance; ControlsEntity.MaterialTolerance2.MCValue = getGelatG8.RecipePlcViews[1].Tolerance; ControlsEntity.GelSpeedSet.MCValue = getGelatG8.RecipeSteps[0].MixSpeed; ControlsEntity.GelPosTimeA.MCValue = getGelatG8.RecipeSteps[2].MixTemp; ControlsEntity.GelNagTimeB.MCValue = getGelatG8.RecipeSteps[2].MixSpeed; ControlsEntity.GelPosTimeC.MCValue = getGelatG8.RecipeSteps[2].MixTime; ControlsEntity.GelWaterTime.MCValue = getGelatG8.RecipeSteps[4].MixTime; ControlsEntity.GelWaitTime.MCValue = getGelatG8.RecipeSteps[6].MixTime; ControlsEntity.GelCloseHeatTime.MCValue = getGelatG8.RecipeSteps[7].MixTime; ControlsEntity.GelOutDelayTime.MCValue = getGelatG8.RecipeSteps[7].MixTemp; ControlsEntity.WetDryWeight.MCValue = getWeterM8[1].SetValue; ControlsEntity.WetMixTime.MCValue = getWeterM8[2].MixTime; ControlsEntity.WetOutDelayTime.MCValue = getWeterM8[4].MixTime; break; default: return; } } #endregion #region 辅助类 /// /// 单选选择 /// /// 返回单选的产线号 如果未选择返回0 private int SingleSelect() { if (Convert.ToBoolean(ControlsEntity.Line1.MCValue) == true) { return 1; } else if (Convert.ToBoolean(ControlsEntity.Line2.MCValue) == true) { return 2; } else if (Convert.ToBoolean(ControlsEntity.Line3.MCValue) == true) { return 3; } else if (Convert.ToBoolean(ControlsEntity.Line4.MCValue) == true) { return 4; } else if (Convert.ToBoolean(ControlsEntity.Line5.MCValue) == true) { return 5; } else if (Convert.ToBoolean(ControlsEntity.Line6.MCValue) == true) { return 6; } else if (Convert.ToBoolean(ControlsEntity.Line7.MCValue) == true) { return 7; } else if (Convert.ToBoolean(ControlsEntity.Line8.MCValue) == true) { return 8; } else { return 0; } } /// /// 控件导入 /// private void ControlImport() { ControlsEntity.Line1 = GetMCRadioButtonControl("Line1"); ControlsEntity.Line2 = GetMCRadioButtonControl("Line2"); ControlsEntity.Line3 = GetMCRadioButtonControl("Line3"); ControlsEntity.Line4 = GetMCRadioButtonControl("Line4"); ControlsEntity.Line5 = GetMCRadioButtonControl("Line5"); ControlsEntity.Line6 = GetMCRadioButtonControl("Line6"); ControlsEntity.Line7 = GetMCRadioButtonControl("Line7"); ControlsEntity.Line8 = GetMCRadioButtonControl("Line8"); ControlsEntity.ChooseMaterial1 = GetComboBoxControl("ChooseMaterial1"); ControlsEntity.ChooseMaterial2 = GetComboBoxControl("ChooseMaterial2"); ControlsEntity.MaterialWeight1 = GetBaseControl("MaterialWeight1"); ControlsEntity.MaterialWeight2 = GetBaseControl("MaterialWeight2"); ControlsEntity.MaterialTolerance1 = GetBaseControl("MaterialTolerance1"); ControlsEntity.MaterialTolerance2 = GetBaseControl("MaterialTolerance2"); ControlsEntity.GelSpeedSet = GetBaseControl("GelSpeedSet"); ControlsEntity.GelPosTimeA = GetBaseControl("GelPosTimeA"); ControlsEntity.GelNagTimeB = GetBaseControl("GelNagTimeB"); ControlsEntity.GelPosTimeC = GetBaseControl("GelPosTimeC"); ControlsEntity.GelWaterTime = GetBaseControl("GelWaterTime"); ControlsEntity.GelWaitTime = GetBaseControl("GelWaitTime"); ControlsEntity.GelCloseHeatTime = GetBaseControl("GelCloseHeatTime"); ControlsEntity.GelOutDelayTime = GetBaseControl("GelOutDelayTime"); ControlsEntity.WetDryWeight = GetBaseControl("WetDryWeight"); ControlsEntity.WetMixTime = GetBaseControl("WetMixTime"); ControlsEntity.WetOutDelayTime = GetBaseControl("WetOutDelayTime"); } private IBaseControl GetBaseControl(string name) { return McControls.First(x => x.Name == name) as IBaseControl; } private MCCombobox GetComboBoxControl(string name) { return McControls.First(x => x.Name == name) as MCCombobox; } private MCRadioButton GetMCRadioButtonControl(string name) { return McControls.First(x => x.Name == name) as MCRadioButton; } #endregion } }