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 System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using Button = System.Windows.Forms.Button; using Mesnac.Action.ChemicalWeighing.LjPlanning; namespace Mesnac.Action.ChemicalWeighing.AutoControl { internal class GelerWeterControl : ChemicalWeighingAction, IAction { private List McControls; RuntimeParameter _runtime; GelerWeterControlsEntity ControlsEntity = new GelerWeterControlsEntity(); public void Run(RuntimeParameter runtime) { base.RunIni(runtime); //必须要调用 this._runtime = runtime; McControls = GetAllControls(); ControlImport(); try { BottomSelect(runtime); } catch(Exception e) { MessageBox.Show("请检查输入内容格式是否正确!"); } } private void BottomSelect(RuntimeParameter runtime) { #region 自动参数下传 if (ControlsEntity.Download == runtime.Sender) { if (MessageBox.Show("确认下传数据?", "下传确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } int bin1 = Convert.ToInt32(ControlsEntity.ChooseMaterial1.MCValue.ToString()); int bin2 = Convert.ToInt32(ControlsEntity.ChooseMaterial2.MCValue.ToString()); List recipes = new List(); float t1 = Convert.ToSingle(ControlsEntity.MaterialTolerance1.MCValue.ToString()); float t2 = Convert.ToSingle(ControlsEntity.MaterialTolerance2.MCValue.ToString()); if(bin2 == -1) { if (t1 < 0.1) { MessageBox.Show("公差不能小于0.1!"); return; } } else { if (t1 < 0.1 || t2 < 0.1) { MessageBox.Show("公差不能小于0.1!"); return; } } RecipePlcView recipe1 = new RecipePlcView() { Bin = (short)StockMaterrialDbHelp.GetCodeById(bin1), Set = Convert.ToSingle(ControlsEntity.MaterialWeight1.MCValue.ToString()), Tolerance = t1, }; RecipePlcView recipe2 = new RecipePlcView() { Bin = (short)StockMaterrialDbHelp.GetCodeById(bin2), Set = Convert.ToSingle(ControlsEntity.MaterialWeight2.MCValue.ToString()), Tolerance = t2, }; 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.ToInt16(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.ToInt16(ControlsEntity.GelWaterTime.MCValue.ToString()) }; Step step6 = new Step() { MixCode = 6, }; Step step7 = new Step() { MixCode = 5, MixTime = Convert.ToInt16(ControlsEntity.GelWaitTime.MCValue.ToString()) }; Step step8 = new Step() { MixCode = 7, MixTime = Convert.ToInt16(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.ToInt16(ControlsEntity.WetMixTime.MCValue.ToString()) }; MixStep mixStep4 = new MixStep() { MixCode = 4, }; MixStep mixStep5 = new MixStep() { MixCode = 5, MixTime = Convert.ToInt16(ControlsEntity.WetOutDelayTime.MCValue.ToString()), }; mixSteps.Add(mixStep1); mixSteps.Add(mixStep2); mixSteps.Add(mixStep3); mixSteps.Add(mixStep4); mixSteps.Add(mixStep5); List materials = new List(); DeviceMaterrial deviceMaterial1 = new DeviceMaterrial() { DeviceId = SingleSelect(), MaterrialId = bin1, Type = 2, Code = StockMaterrialDbHelp.GetCodeById(bin1) }; DeviceMaterrial deviceMaterial2 = new DeviceMaterrial() { DeviceId = SingleSelect(), MaterrialId = bin2, Type = 2, Code = StockMaterrialDbHelp.GetCodeById(bin2) }; materials.Add(deviceMaterial1); materials.Add(deviceMaterial2); switch (SingleSelect()) { case 1: LjPlanningPlcHelp.DownG1Recipe(recipes, steps); LjPlanningPlcHelp.DownM1Recipe(mixSteps); DeviceMaterrialService.Save(materials); break; case 2: LjPlanningPlcHelp.DownG2Recipe(recipes, steps); LjPlanningPlcHelp.DownM2Recipe(mixSteps); DeviceMaterrialService.Save(materials); break; case 3: LjPlanningPlcHelp.DownG3Recipe(recipes, steps); LjPlanningPlcHelp.DownM3Recipe(mixSteps); DeviceMaterrialService.Save(materials); break; case 4: LjPlanningPlcHelp.DownG4Recipe(recipes, steps); LjPlanningPlcHelp.DownM4Recipe(mixSteps); DeviceMaterrialService.Save(materials); break; case 5: LjPlanningPlcHelp.DownG5Recipe(recipes, steps); LjPlanningPlcHelp.DownM5Recipe(mixSteps); DeviceMaterrialService.Save(materials); break; case 6: LjPlanningPlcHelp.DownG6Recipe(recipes, steps); LjPlanningPlcHelp.DownM6Recipe(mixSteps); DeviceMaterrialService.Save(materials); break; case 7: LjPlanningPlcHelp.DownG7Recipe(recipes, steps); LjPlanningPlcHelp.DownM7Recipe(mixSteps); DeviceMaterrialService.Save(materials); break; case 8: LjPlanningPlcHelp.DownG8Recipe(recipes, steps); LjPlanningPlcHelp.DownM8Recipe(mixSteps); DeviceMaterrialService.Save(materials); break; default: MessageBox.Show("请选择一条产线!"); return; } MessageBox.Show("数据下传成功!"); } #endregion #region 手动控制 if (ControlsEntity.GelManualPowder == runtime.Sender) { if (MessageBox.Show("确认手动下粉料?", "下粉确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } bool isReady; switch (SingleSelect()) { case 1: isReady = DB2105WriteHelper.WriteG1Pd(); break; case 2: isReady = DB2105WriteHelper.WriteG2Pd(); break; case 3: isReady = DB2105WriteHelper.WriteG3Pd(); break; case 4: isReady = DB2105WriteHelper.WriteG4Pd(); break; case 5: isReady = DB2105WriteHelper.WriteG5Pd(); break; case 6: isReady = DB2105WriteHelper.WriteG6Pd(); break; case 7: isReady = DB2105WriteHelper.WriteG7Pd(); break; case 8: isReady = DB2105WriteHelper.WriteG8Pd(); break; default: isReady = true; MessageBox.Show("当前未选择产线!"); return; } if (!isReady) { MessageBox.Show("信号未准备好!"); } else { MessageBox.Show("信号下达成功!"); } } if (ControlsEntity.GelManualColdWater == runtime.Sender) { if (MessageBox.Show("确认下冷水?", "下水确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } bool isReady; switch (SingleSelect()) { case 1: isReady = DB2105WriteHelper.WriteG1Cw(); break; case 2: isReady = DB2105WriteHelper.WriteG2Cw(); break; case 3: isReady = DB2105WriteHelper.WriteG3Cw(); break; case 4: isReady = DB2105WriteHelper.WriteG4Cw(); break; case 5: isReady = DB2105WriteHelper.WriteG5Cw(); break; case 6: isReady = DB2105WriteHelper.WriteG6Cw(); break; case 7: isReady = DB2105WriteHelper.WriteG7Cw(); break; case 8: isReady = DB2105WriteHelper.WriteG8Cw(); break; default: isReady = true; MessageBox.Show("当前未选择产线!"); return; } if (!isReady) { MessageBox.Show("信号未准备好!"); } else { MessageBox.Show("信号下达成功!"); } } if (ControlsEntity.GelManualHotWater == runtime.Sender) { if (MessageBox.Show("确认下热水?", "下水确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } bool isReady; switch (SingleSelect()) { case 1: isReady = DB2105WriteHelper.WriteG1Hw(); break; case 2: isReady = DB2105WriteHelper.WriteG2Hw(); break; case 3: isReady = DB2105WriteHelper.WriteG3Hw(); break; case 4: isReady = DB2105WriteHelper.WriteG4Hw(); break; case 5: isReady = DB2105WriteHelper.WriteG5Hw(); break; case 6: isReady = DB2105WriteHelper.WriteG6Hw(); break; case 7: isReady = DB2105WriteHelper.WriteG7Hw(); break; case 8: isReady = DB2105WriteHelper.WriteG8Hw(); break; default: isReady = true; MessageBox.Show("当前未选择产线!"); return; } if (!isReady) { MessageBox.Show("信号未准备好!"); } else { MessageBox.Show("信号下达成功!"); } } if (ControlsEntity.WetManualGel == runtime.Sender) { if (MessageBox.Show("确认下糊化料?", "下糊化料确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } bool isReady; switch (SingleSelect()) { case 1: isReady = DB2105WriteHelper.WriteM1(); break; case 2: isReady = DB2105WriteHelper.WriteM2(); break; case 3: isReady = DB2105WriteHelper.WriteM3(); break; case 4: isReady = DB2105WriteHelper.WriteM4(); break; case 5: isReady = DB2105WriteHelper.WriteM5(); break; case 6: isReady = DB2105WriteHelper.WriteM6(); break; case 7: isReady = DB2105WriteHelper.WriteM7(); break; case 8: isReady = DB2105WriteHelper.WriteM8(); break; default: isReady = false; MessageBox.Show("当前未选择产线!"); return; } if (!isReady) { MessageBox.Show("信号未准备好!"); } else { MessageBox.Show("信号下达成功!"); } } if (ControlsEntity.WetManualControl == runtime.Sender) { if (MessageBox.Show("确认下传数据?", "下传确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } float t = Convert.ToSingle(ControlsEntity.ManualTolerance.MCValue.ToString()); if (t < 0.1) { MessageBox.Show("公差不能小于0.1!"); return; } SetValue value = new SetValue() { Value = Convert.ToSingle(ControlsEntity.ManualWeight.MCValue.ToString()), Toterance = t }; switch (SingleSelect()) { case 1: DB2105WriteHelper.WriteManScrewH1(); DB2105WriteHelper.WriteSetValueH1(value); break; case 2: DB2105WriteHelper.WriteManScrewH2(); DB2105WriteHelper.WriteSetValueH1(value); break; case 3: DB2105WriteHelper.WriteManScrewH3(); DB2105WriteHelper.WriteSetValueH2(value); break; case 4: DB2105WriteHelper.WriteManScrewH4(); DB2105WriteHelper.WriteSetValueH2(value); break; case 5: DB2105WriteHelper.WriteManScrewH5(); DB2105WriteHelper.WriteSetValueH3(value); break; case 6: DB2105WriteHelper.WriteManScrewH6(); DB2105WriteHelper.WriteSetValueH3(value); break; case 7: DB2105WriteHelper.WriteManScrewH7(); DB2105WriteHelper.WriteSetValueH4(value); break; case 8: DB2105WriteHelper.WriteManScrewH8(); DB2105WriteHelper.WriteSetValueH4(value); break; default: MessageBox.Show("当前未选择产线!"); return; } MessageBox.Show("数据下传成功!"); } #endregion #region 自动启停 if (ControlsEntity.LineStart == runtime.Sender) { if (MessageBox.Show("确认启动生产?", "启动确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } 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; } MessageBox.Show("产线已启动!"); } 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; } MessageBox.Show("已经停止生产"); } #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"); ControlsEntity.ManualTolerance = GetBaseControl("ManualTolerance"); ControlsEntity.ManualWeight = GetBaseControl("ManualWeight"); ControlsEntity.WetManualControl = GetButtonControl("WetManualControl"); ControlsEntity.Download = GetButtonControl("Download"); ControlsEntity.LineStart = GetButtonControl("LineStart"); ControlsEntity.LineStop = GetButtonControl("LineStop"); ControlsEntity.GelManualPowder = GetButtonControl("GelManualPowder"); ControlsEntity.GelManualColdWater = GetButtonControl("GelManualColdWater"); ControlsEntity.GelManualHotWater = GetButtonControl("GelManualHotWater"); ControlsEntity.WetManualGel = GetButtonControl("WetManualGel"); } 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; } private MCRadioButton GetMCRadioButtonControl(string name) { return McControls.First(x => x.Name == name) as MCRadioButton; } #endregion } }