using DataBlockHelper.DBHelpers; using DataBlockHelper.Entity.DB2104Entity; using DataBlockHelper.Entity.DB2106Entity; using Mesnac.Action.Base; using Mesnac.Action.ChemicalWeighing.AutoControl.DB; using Mesnac.Action.ChemicalWeighing.AutoControl.Entity; using Mesnac.Action.ChemicalWeighing.LjMixManager; using Mesnac.Controls.Base; using Mesnac.Controls.Default; using Mesnac.Core.Service; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Mesnac.Controls.Default; using Button = System.Windows.Forms.Button; using System.Data; using Mesnac.Action.ChemicalWeighing.LjPlanning; using Steema.TeeChart.Functions; namespace Mesnac.Action.ChemicalWeighing.AutoControl { internal class GelerWeterControl : ChemicalWeighingAction, IAction { private List McControls; RuntimeParameter _runtime; GelerWeterControlsEntity ControlsEntity = new GelerWeterControlsEntity(); public static int choose; public void Run(RuntimeParameter runtime) { base.RunIni(runtime); //必须要调用 this._runtime = runtime; McControls = GetAllControls(); ControlImport(); BottomSelect(runtime); } /// /// 单选选择 /// /// 返回单选的产线号 如果未选择返回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.Line2 = GetBaseControl("Line2"); ControlsEntity.Line3 = GetBaseControl("Line3"); ControlsEntity.Line4 = GetBaseControl("Line4"); ControlsEntity.Line5 = GetBaseControl("Line5"); ControlsEntity.Line6 = GetBaseControl("Line6"); ControlsEntity.Line7 = GetBaseControl("Line7"); ControlsEntity.Line8 = GetBaseControl("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"); ControlsEntity.WetManualControl = GetButtonControl("WetManualControl"); ControlsEntity.Download = GetButtonControl("Download"); ControlsEntity.LineStart = GetButtonControl("LineStart"); ControlsEntity.LineStop = GetButtonControl("LineStop"); } private void BottomSelect(RuntimeParameter runtime) { if(ControlsEntity.WetManualControl == runtime.Sender) { ManualAdd frm = new ManualAdd(); choose = SingleSelect(); DialogResult result = frm.ShowDialog(); this._runtime.BaseControl.MCEnabled = false; if (result == DialogResult.OK) { frm.Dispose(); } this._runtime.BaseControl.MCEnabled = true; } if (ControlsEntity.Download == runtime.Sender) { List recipes = new List(); int bin1 = Convert.ToInt32(ControlsEntity.ChooseMaterial1.MCValue.ToString()); int bin2 = Convert.ToInt32(ControlsEntity.ChooseMaterial2.MCValue.ToString()); if(bin1 == -1) { bin1 = 0; } if(bin2 == -1) { bin2 = 0; } RecipePlcView recipe1 = new RecipePlcView() { Bin = (ushort)bin1, Set = Convert.ToSingle(ControlsEntity.MaterialWeight1.MCValue.ToString()), Tolerance = Convert.ToSingle(ControlsEntity.MaterialTolerance1.MCValue.ToString()), }; RecipePlcView recipe2 = new RecipePlcView() { Bin = (ushort)bin2, Set = Convert.ToSingle(ControlsEntity.MaterialWeight2.MCValue.ToString()), Tolerance = Convert.ToSingle(ControlsEntity.MaterialTolerance2.MCValue.ToString()), }; recipes.Add(recipe1); recipes.Add(recipe2); List steps = new List(); Step step1 = new Step() { MixCode = 1, MixSpeed = Convert.ToSingle(ControlsEntity.GelSpeedSet.MCValue.ToString()) }; Step step2 = new Step() { MixCode = 2, }; Step step3 = new Step() { MixCode = 3, MixTime = Convert.ToUInt16(ControlsEntity.GelPosTimeC.MCValue.ToString()), MixTemp = Convert.ToSingle(ControlsEntity.GelPosTimeA.MCValue.ToString()), MixSpeed = Convert.ToSingle(ControlsEntity.GelNagTimeB.MCValue.ToString()) }; Step step4 = new Step() { MixCode = 4, }; Step step5 = new Step() { MixCode = 5, MixTime = Convert.ToUInt16(ControlsEntity.GelWaterTime.MCValue.ToString()) }; Step step6 = new Step() { MixCode = 6, }; Step step7 = new Step() { MixCode = 5, MixTime = Convert.ToUInt16(ControlsEntity.GelWaitTime.MCValue.ToString()) }; Step step8 = new Step() { MixCode = 7, MixTime = Convert.ToUInt16(ControlsEntity.GelCloseHeatTime.MCValue.ToString()), MixTemp = Convert.ToSingle(ControlsEntity.GelOutDelayTime.MCValue.ToString()) }; steps.Add(step1); steps.Add(step2); steps.Add(step3); steps.Add(step4); steps.Add(step5); steps.Add(step6); steps.Add(step7); steps.Add(step8); List mixSteps = new List(); MixStep mixStep1 = new MixStep() { MixCode = 1, }; MixStep mixStep2 = new MixStep() { MixCode = 2, SetValue = Convert.ToSingle(ControlsEntity.WetDryWeight.MCValue.ToString()) }; MixStep mixStep3 = new MixStep() { MixCode = 3, MixTime = Convert.ToUInt16(ControlsEntity.WetMixTime.MCValue.ToString()) }; MixStep mixStep4 = new MixStep() { MixCode = 4, }; MixStep mixStep5 = new MixStep() { MixCode = 5, MixTime = Convert.ToUInt16(ControlsEntity.WetOutDelayTime.MCValue.ToString()), }; mixSteps.Add(mixStep1); mixSteps.Add(mixStep2); mixSteps.Add(mixStep3); mixSteps.Add(mixStep4); mixSteps.Add(mixStep5); switch (SingleSelect()) { case 1: LjPlanningPlcHelp.DownG1Recipe(recipes, steps); LjPlanningPlcHelp.DownM1Recipe(mixSteps); break; case 2: LjPlanningPlcHelp.DownG2Recipe(recipes, steps); LjPlanningPlcHelp.DownM2Recipe(mixSteps); break; case 3: LjPlanningPlcHelp.DownG3Recipe(recipes, steps); LjPlanningPlcHelp.DownM3Recipe(mixSteps); break; case 4: LjPlanningPlcHelp.DownG4Recipe(recipes, steps); LjPlanningPlcHelp.DownM4Recipe(mixSteps); break; case 5: LjPlanningPlcHelp.DownG5Recipe(recipes, steps); LjPlanningPlcHelp.DownM5Recipe(mixSteps); break; case 6: LjPlanningPlcHelp.DownG6Recipe(recipes, steps); LjPlanningPlcHelp.DownM6Recipe(mixSteps); break; case 7: LjPlanningPlcHelp.DownG7Recipe(recipes, steps); LjPlanningPlcHelp.DownM7Recipe(mixSteps); break; case 8: LjPlanningPlcHelp.DownG8Recipe(recipes, steps); LjPlanningPlcHelp.DownM8Recipe(mixSteps); break; default: MessageBox.Show("请选择一条产线!"); return; } } if (ControlsEntity.LineStart == runtime.Sender) { switch (SingleSelect()) { case 1: DB2105WriteHelper.WriteStartJob1(); break; case 2: DB2105WriteHelper.WriteStartJob2(); break; case 3: DB2105WriteHelper.WriteStartJob3(); break; case 4: DB2105WriteHelper.WriteStartJob4(); break; case 5: DB2105WriteHelper.WriteStartJob5(); break; case 6: DB2105WriteHelper.WriteStartJob6(); break; case 7: DB2105WriteHelper.WriteStartJob7(); break; case 8: DB2105WriteHelper.WriteStartJob8(); break; default: MessageBox.Show("请选择一条产线!"); return; } } if (ControlsEntity.LineStop == runtime.Sender) { switch (SingleSelect()) { case 1: DB2105WriteHelper.WriteStopJob1(); break; case 2: DB2105WriteHelper.WriteStopJob2(); break; case 3: DB2105WriteHelper.WriteStopJob3(); break; case 4: DB2105WriteHelper.WriteStopJob4(); break; case 5: DB2105WriteHelper.WriteStopJob5(); break; case 6: DB2105WriteHelper.WriteStopJob6(); break; case 7: DB2105WriteHelper.WriteStopJob7(); break; case 8: DB2105WriteHelper.WriteStopJob8(); break; default: MessageBox.Show("请选择一条产线!"); return; } } } 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; } private MCCombobox GetComboBoxControl(string name) { return McControls.First(x => x.Name == name) as MCCombobox; } } }