using DevExpress.DataAccess.Wizard.Presenters; 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 Microsoft.Office.Interop.Excel; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using IAction = Mesnac.Action.Base.IAction; namespace Mesnac.Action.ChemicalWeighing.AutoControl { public class InitAction : ChemicalWeighingAction, IAction { GelerWeterControlsEntity ControlsEntity = new GelerWeterControlsEntity(); private List McControls; public void Run(RuntimeParameter runtime) { base.RunIni(runtime); //必须要调用 McControls = GetAllControls(); ControlImport(); ControlsEntity.Line1.MCValue = true; ControlInitFromPLC(); } /// /// 控件从Plc初始化 /// private void ControlInitFromPLC() { 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 = -1; ControlsEntity.ChooseMaterial2.SelectedIndex = -1; } var dryerView = LjPlanningPlcHelp.GetGelatG1; ControlsEntity.MaterialWeight1.MCValue = dryerView.RecipePlcViews[0].Set; ControlsEntity.MaterialWeight2.MCValue = dryerView.RecipePlcViews[1].Set; ControlsEntity.MaterialTolerance1.MCValue = dryerView.RecipePlcViews[0].Tolerance; ControlsEntity.MaterialTolerance2.MCValue = dryerView.RecipePlcViews[1].Tolerance; ControlsEntity.GelSpeedSet.MCValue = dryerView.RecipeSteps[0].MixSpeed; ControlsEntity.GelPosTimeA.MCValue = dryerView.RecipeSteps[2].MixTemp; ControlsEntity.GelNagTimeB.MCValue = dryerView.RecipeSteps[2].MixSpeed; ControlsEntity.GelPosTimeC.MCValue = dryerView.RecipeSteps[2].MixTime; ControlsEntity.GelWaterTime.MCValue = dryerView.RecipeSteps[4].MixTime; ControlsEntity.GelWaitTime.MCValue = dryerView.RecipeSteps[6].MixTime; ControlsEntity.GelCloseHeatTime.MCValue = dryerView.RecipeSteps[7].MixTime; ControlsEntity.GelOutDelayTime.MCValue = dryerView.RecipeSteps[7].MixTemp; ControlsEntity.WetDryWeight.MCValue = LjPlanningPlcHelp.GetWeterM1[1].SetValue; ControlsEntity.WetMixTime.MCValue = LjPlanningPlcHelp.GetWeterM1[2].MixTime; ControlsEntity.WetOutDelayTime.MCValue = LjPlanningPlcHelp.GetWeterM1[4].MixTime; } /// /// 单选选择 /// /// 返回单选的产线号 如果未选择返回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 = GetBaseControl("Line1"); 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; } } }