using DataBlockHelper.DBHelpers; 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 System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Reflection; 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 { private List McControls; Color backColor = Color.Transparent; MCTextBoxEntity TextE = new MCTextBoxEntity(); ButtonEntity ButtonE = new ButtonEntity(); MCLabelEntity LabelE = new MCLabelEntity(); MCComboBoxEntity ComboE = new MCComboBoxEntity(); MCRadioButtonEntity RadioE = new MCRadioButtonEntity(); public Timer timer; public void Run(RuntimeParameter runtime) { base.RunIni(runtime); //必须要调用 McControls = GetAllControls(); ControlsHelper.ControlImport(TextE, ButtonE, ComboE, LabelE, RadioE, McControls); RadioE.Line1.MCValue = true; RadioE.Dry1.MCValue = true; RadioE.Line1.BackColor = System.Drawing.Color.LightSkyBlue; RadioE.Line1.CheckedChanged += Mcradion_CheckedChanged; RadioE.Line2.CheckedChanged += Mcradion_CheckedChanged; RadioE.Line3.CheckedChanged += Mcradion_CheckedChanged; RadioE.Line4.CheckedChanged += Mcradion_CheckedChanged; RadioE.Line5.CheckedChanged += Mcradion_CheckedChanged; RadioE.Line6.CheckedChanged += Mcradion_CheckedChanged; RadioE.Line7.CheckedChanged += Mcradion_CheckedChanged; RadioE.Line8.CheckedChanged += Mcradion_CheckedChanged; ControlInitFromPLC(); timer = new Timer(); timer.Interval = 1000; timer.Enabled = true; timer.Tick += new EventHandler(StateRefresh);//添加事件 } #region 前端状态 private void StateRefresh(object sender, EventArgs e) { if (GetAllDbMCControlsByOption(DbOptionTypes.QueryAndModify).Count == 0) { timer.Stop(); timer.Dispose(); } DB2105Helper dB2105Helper = new DB2105Helper(); var startJob = dB2105Helper.GetStartJob; LabelE.State1.MCValue = ConvertOnOff(startJob[0].Val); LabelE.State2.MCValue = ConvertOnOff(startJob[1].Val); LabelE.State3.MCValue = ConvertOnOff(startJob[2].Val); LabelE.State4.MCValue = ConvertOnOff(startJob[3].Val); LabelE.State5.MCValue = ConvertOnOff(startJob[4].Val); LabelE.State6.MCValue = ConvertOnOff(startJob[5].Val); LabelE.State7.MCValue = ConvertOnOff(startJob[6].Val); LabelE.State8.MCValue = ConvertOnOff(startJob[7].Val); LabelE.State1.BackColor = ConvertColor(startJob[0].Val); LabelE.State2.BackColor = ConvertColor(startJob[1].Val); LabelE.State3.BackColor = ConvertColor(startJob[2].Val); LabelE.State4.BackColor = ConvertColor(startJob[3].Val); LabelE.State5.BackColor = ConvertColor(startJob[4].Val); LabelE.State6.BackColor = ConvertColor(startJob[5].Val); LabelE.State7.BackColor = ConvertColor(startJob[6].Val); LabelE.State8.BackColor = ConvertColor(startJob[7].Val); var rd = Db3000Helper.ReadModel(); if (rd[SingleSelect() - 1]) { LabelE.RepairState.MCValue = "开"; } else { LabelE.RepairState.MCValue = "关"; } } private string ConvertOnOff(bool state) { if (state) { return "启动"; } else { return "停止"; } } private Color ConvertColor(bool state) { if (state) { return Color.LightGreen; } else { return Color.Transparent; } } private void Mcradion_CheckedChanged(object sender, EventArgs e) { MCRadioButton mCRadio = sender as MCRadioButton; RadioE.Line1.BackColor = backColor; RadioE.Line2.BackColor = backColor; RadioE.Line3.BackColor = backColor; RadioE.Line4.BackColor = backColor; RadioE.Line5.BackColor = backColor; RadioE.Line6.BackColor = backColor; RadioE.Line7.BackColor = backColor; RadioE.Line8.BackColor = backColor; mCRadio.BackColor = Color.LightSkyBlue; } #endregion /// /// 控件从Plc初始化 /// private void ControlInitFromPLC() { ComboE.ChooseMaterial1.DataSource = StockMaterrialDbHelp.GetSiloMaterrial(); ComboE.ChooseMaterial2.DataSource = StockMaterrialDbHelp.GetSiloMaterrial(); var selected = FreeSqlUnit.Instance.Select(). Where(x => x.DeviceId == SingleSelect() && x.Type == 2).ToList(); if(selected.Count != 0) { ComboE.ChooseMaterial1.SelectedValue = selected[0].MaterrialId; ComboE.ChooseMaterial2.SelectedValue = selected[1].MaterrialId; } else { ComboE.ChooseMaterial1.SelectedIndex = 0; ComboE.ChooseMaterial2.SelectedIndex = 0; } var getGelatG1 = LjPlanningPlcHelp.GetGelatG1; var getWeterM1 = LjPlanningPlcHelp.GetWeterM1; TextE.MaterialWeight1.MCValue = getGelatG1.RecipePlcViews[0].Set; TextE.MaterialWeight2.MCValue = getGelatG1.RecipePlcViews[1].Set; //TextE.MaterialTolerance1.MCValue = getGelatG1.RecipePlcViews[0].Tolerance; //TextE.MaterialTolerance2.MCValue = getGelatG1.RecipePlcViews[1].Tolerance; TextE.GelSpeedSet.MCValue = getGelatG1.RecipeSteps[0].MixSpeed; TextE.GelPosTimeA.MCValue = getGelatG1.RecipeSteps[2].MixTemp; TextE.GelNagTimeB.MCValue = getGelatG1.RecipeSteps[2].MixSpeed; TextE.GelPosTimeC.MCValue = getGelatG1.RecipeSteps[2].MixTime; TextE.GelWaterTime.MCValue = getGelatG1.RecipeSteps[4].MixTime; TextE.GelWaitTime.MCValue = getGelatG1.RecipeSteps[6].MixTime; TextE.GelCloseHeatTime.MCValue = getGelatG1.RecipeSteps[7].MixTime; TextE.GelOutDelayTime.MCValue = getGelatG1.RecipeSteps[7].MixTemp; TextE.WetDryWeight.MCValue = getWeterM1[1].SetValue; TextE.WetMixTime.MCValue = getWeterM1[2].MixTime; TextE.WetOutDelayTime.MCValue = getWeterM1[4].MixTime; DB2104Helper dB2104Helper = new DB2104Helper(); TextE.ColdValueA.MCValue = dB2104Helper.GetAColWater.Set; TextE.ColdValueB.MCValue = dB2104Helper.GetBColWater.Set; TextE.HotValueA.MCValue = dB2104Helper.GetAHotWater.Set; TextE.HotValueB.MCValue = dB2104Helper.GetBHotWater.Set; TextE.ColdToleranceA.MCValue = dB2104Helper.GetAColWater.Tolerance; TextE.ColdToleranceB.MCValue = dB2104Helper.GetBColWater.Tolerance; TextE.HotToleranceA.MCValue = dB2104Helper.GetAHotWater.Tolerance; TextE.HotToleranceB.MCValue = dB2104Helper.GetBHotWater.Tolerance; ComboE.DryM1.DataSource = StockMaterrialDbHelp.GetDryerMaterrial(); ComboE.DryM2.DataSource = StockMaterrialDbHelp.GetDryerMaterrial(); ComboE.DryM3.DataSource = StockMaterrialDbHelp.GetDryerMaterrial(); ComboE.DryM4.DataSource = StockMaterrialDbHelp.GetDryerMaterrial(); ComboE.DryM5.DataSource = StockMaterrialDbHelp.GetDryerMaterrial(); ComboE.DryM6.DataSource = StockMaterrialDbHelp.GetDryerMaterrial(); ComboE.DryM7.DataSource = StockMaterrialDbHelp.GetDryerMaterrial(); ComboE.DryM8.DataSource = StockMaterrialDbHelp.GetDryerMaterrial(); ComboE.DryM9.DataSource = StockMaterrialDbHelp.GetDryerMaterrial(); ComboE.DryM10.DataSource = StockMaterrialDbHelp.GetDryerMaterrial(); ComboE.DryM11.DataSource = StockMaterrialDbHelp.GetDryerMaterrial(); ComboE.DryM12.DataSource = StockMaterrialDbHelp.GetDryerMaterrial(); var drtSelected = FreeSqlUnit.Instance.Select(). Where(x => x.DeviceId == DrySelect() && x.Type == 1).ToList(); if (drtSelected.Count != 0) { ComboE.DryM1.SelectedValue = drtSelected[0].MaterrialId; ComboE.DryM2.SelectedValue = drtSelected[1].MaterrialId; ComboE.DryM3.SelectedValue = drtSelected[2].MaterrialId; ComboE.DryM4.SelectedValue = drtSelected[3].MaterrialId; ComboE.DryM5.SelectedValue = drtSelected[4].MaterrialId; ComboE.DryM6.SelectedValue = drtSelected[5].MaterrialId; ComboE.DryM7.SelectedValue = drtSelected[6].MaterrialId; ComboE.DryM8.SelectedValue = drtSelected[7].MaterrialId; ComboE.DryM9.SelectedValue = drtSelected[8].MaterrialId; ComboE.DryM10.SelectedValue = drtSelected[9].MaterrialId; ComboE.DryM11.SelectedValue = drtSelected[10].MaterrialId; ComboE.DryM12.SelectedValue = drtSelected[11].MaterrialId; } else { ComboE.DryM1.SelectedIndex = 0; ComboE.DryM2.SelectedIndex = 0; ComboE.DryM3.SelectedIndex = 0; ComboE.DryM4.SelectedIndex = 0; ComboE.DryM5.SelectedIndex = 0; ComboE.DryM6.SelectedIndex = 0; ComboE.DryM7.SelectedIndex = 0; ComboE.DryM8.SelectedIndex = 0; ComboE.DryM9.SelectedIndex = 0; ComboE.DryM10.SelectedIndex = 0; ComboE.DryM11.SelectedIndex = 0; ComboE.DryM12.SelectedIndex = 0; } var getDryerD1 = LjPlanningPlcHelp.GetDryerD1; TextE.DryW1.MCValue = getDryerD1.RecipePlcViews[0].Set; TextE.DryW2.MCValue = getDryerD1.RecipePlcViews[1].Set; TextE.DryW3.MCValue = getDryerD1.RecipePlcViews[2].Set; TextE.DryW4.MCValue = getDryerD1.RecipePlcViews[3].Set; TextE.DryW5.MCValue = getDryerD1.RecipePlcViews[4].Set; TextE.DryW6.MCValue = getDryerD1.RecipePlcViews[5].Set; TextE.DryW7.MCValue = getDryerD1.RecipePlcViews[6].Set; TextE.DryW8.MCValue = getDryerD1.RecipePlcViews[7].Set; TextE.DryW9.MCValue = getDryerD1.RecipePlcViews[8].Set; TextE.DryW10.MCValue = getDryerD1.RecipePlcViews[9].Set; TextE.DryW11.MCValue = getDryerD1.RecipePlcViews[10].Set; TextE.DryW12.MCValue = getDryerD1.RecipePlcViews[11].Set; TextE.DryT1.MCValue = getDryerD1.RecipePlcViews[0].Tolerance; TextE.DryT2.MCValue = getDryerD1.RecipePlcViews[1].Tolerance; TextE.DryT3.MCValue = getDryerD1.RecipePlcViews[2].Tolerance; TextE.DryT4.MCValue = getDryerD1.RecipePlcViews[3].Tolerance; TextE.DryT5.MCValue = getDryerD1.RecipePlcViews[4].Tolerance; TextE.DryT6.MCValue = getDryerD1.RecipePlcViews[5].Tolerance; TextE.DryT7.MCValue = getDryerD1.RecipePlcViews[6].Tolerance; TextE.DryT8.MCValue = getDryerD1.RecipePlcViews[7].Tolerance; TextE.DryT9.MCValue = getDryerD1.RecipePlcViews[8].Tolerance; TextE.DryT10.MCValue = getDryerD1.RecipePlcViews[9].Tolerance; TextE.DryT11.MCValue = getDryerD1.RecipePlcViews[10].Tolerance; TextE.DryT12.MCValue = getDryerD1.RecipePlcViews[11].Tolerance; } #region 帮助类 /// /// 单选选择 /// /// 返回单选的产线号 如果未选择返回0 private int SingleSelect() { int no = 0; if (Convert.ToBoolean(RadioE.Line1.MCValue)) { no= 1; } else if (Convert.ToBoolean(RadioE.Line2.MCValue)) { no= 2; } else if (Convert.ToBoolean(RadioE.Line3.MCValue)) { no= 3; } else if (Convert.ToBoolean(RadioE.Line4.MCValue)) { no= 4; } else if (Convert.ToBoolean(RadioE.Line5.MCValue)) { no= 5; } else if (Convert.ToBoolean(RadioE.Line6.MCValue)) { no= 6; } else if (Convert.ToBoolean(RadioE.Line7.MCValue)) { no= 7; } else if (Convert.ToBoolean(RadioE.Line8.MCValue)) { no= 8; } return no; } /// /// 单混机单选选择 /// /// private int DrySelect() { if (Convert.ToBoolean(RadioE.Dry1.MCValue) == true) { return 1; } else if (Convert.ToBoolean(RadioE.Dry2.MCValue) == true) { return 2; } else if (Convert.ToBoolean(RadioE.Dry3.MCValue) == true) { return 3; } else if (Convert.ToBoolean(RadioE.Dry4.MCValue) == true) { return 4; } else { return 0; } } #endregion } }