using DataBlockHelper.DBHelpers; using Mesnac.Action.Base; using Mesnac.Action.ChemicalWeighing.AutoControl.Entity; using Mesnac.Controls.Base; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Mesnac.Action.ChemicalWeighing.AutoControl { public class WaterInitAction : ChemicalWeighingAction, IAction { DryerWaterControlsEntity ControlsEntity = new DryerWaterControlsEntity(); private List McControls; public void Run(RuntimeParameter runtime) { base.RunIni(runtime); //必须要调用 McControls = GetAllControls(); ControlImport(); ControlInitFromPLC(); } /// /// 控件从Plc初始化 /// private void ControlInitFromPLC() { DB2104Helper dB2104Helper = new DB2104Helper(); ControlsEntity.ColdValueA.MCValue = dB2104Helper.GetAColWater.Set; ControlsEntity.ColdValueB.MCValue = dB2104Helper.GetBColWater.Set; ControlsEntity.HotValueA.MCValue = dB2104Helper.GetAHotWater.Set; ControlsEntity.HotValueB.MCValue = dB2104Helper.GetBHotWater.Set; ControlsEntity.ColdToleranceA.MCValue = dB2104Helper.GetAColWater.Tolerance; ControlsEntity.ColdToleranceB.MCValue = dB2104Helper.GetBColWater.Tolerance; ControlsEntity.HotToleranceA.MCValue = dB2104Helper.GetAHotWater.Tolerance; ControlsEntity.HotToleranceB.MCValue = dB2104Helper.GetBHotWater.Tolerance; } private void ControlImport() { ControlsEntity.WaterConfrim = GetButtonControl("WaterConfrim"); ControlsEntity.ColdValueA = GetBaseControl("ColdValueA"); ControlsEntity.ColdValueB = GetBaseControl("ColdValueB"); ControlsEntity.HotValueA = GetBaseControl("HotValueA"); ControlsEntity.HotValueB = GetBaseControl("HotValueB"); ControlsEntity.ColdToleranceA = GetBaseControl("ColdToleranceA"); ControlsEntity.ColdToleranceB = GetBaseControl("ColdToleranceB"); ControlsEntity.HotToleranceA = GetBaseControl("HotToleranceA"); ControlsEntity.HotToleranceB = GetBaseControl("HotToleranceB"); } private IBaseControl GetBaseControl(string name) { return McControls.First(x => x.Name == name) as IBaseControl; } private Button GetButtonControl(string name) { return McControls.First(x => x.Name == name) as Button; } } }