using DataBlockHelper.DBHelpers; using Mesnac.Action.ChemicalWeighing.LjDeliverPressureSetting.Entity; using System; using System.Collections.Generic; using System.Drawing.Text; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Mesnac.Action.ChemicalWeighing.LjDeliverPressureSetting { public class PlcDownload { public static void PressureSettingDownload(MCTextboxEntity BoxE) { Conveyor conveyorA = new Conveyor(); Conveyor conveyorB = new Conveyor(); Conveyor conveyorC = new Conveyor(); ConveyorTimer conveyorTimerA = new ConveyorTimer(); ConveyorTimer conveyorTimerB = new ConveyorTimer(); ConveyorTimer conveyorTimerC = new ConveyorTimer(); string Alarm = "组数值超出取值范围!(大于0小于50)"; if (!SetValueWithJudge(conveyorA, Convert.ToSingle(BoxE.ASetValue1.MCValue.ToString()), Convert.ToSingle(BoxE.ASetValue2.MCValue.ToString()), Convert.ToSingle(BoxE.ASetValue3.MCValue.ToString()), Convert.ToSingle(BoxE.ASetValue4.MCValue.ToString()), Convert.ToSingle(BoxE.ASetValue5.MCValue.ToString()), Convert.ToSingle(BoxE.ASetValue6.MCValue.ToString()), Convert.ToSingle(BoxE.ASetValue7.MCValue.ToString()), Convert.ToSingle(BoxE.ASetValue8.MCValue.ToString()))) { MessageBox.Show("A" + Alarm); return; } if (!SetValueWithJudge(conveyorB, Convert.ToSingle(BoxE.BSetValue1.MCValue.ToString()), Convert.ToSingle(BoxE.BSetValue2.MCValue.ToString()), Convert.ToSingle(BoxE.BSetValue3.MCValue.ToString()), Convert.ToSingle(BoxE.BSetValue4.MCValue.ToString()), Convert.ToSingle(BoxE.BSetValue5.MCValue.ToString()), Convert.ToSingle(BoxE.BSetValue6.MCValue.ToString()), Convert.ToSingle(BoxE.BSetValue7.MCValue.ToString()), Convert.ToSingle(BoxE.BSetValue8.MCValue.ToString()))) { MessageBox.Show("B" + Alarm); return; } if (!SetValueWithJudge(conveyorC, Convert.ToSingle(BoxE.CSetValue1.MCValue.ToString()), Convert.ToSingle(BoxE.CSetValue2.MCValue.ToString()), Convert.ToSingle(BoxE.CSetValue3.MCValue.ToString()), Convert.ToSingle(BoxE.CSetValue4.MCValue.ToString()), Convert.ToSingle(BoxE.CSetValue5.MCValue.ToString()), Convert.ToSingle(BoxE.CSetValue6.MCValue.ToString()), Convert.ToSingle(BoxE.CSetValue7.MCValue.ToString()), Convert.ToSingle(BoxE.CSetValue8.MCValue.ToString()))) { MessageBox.Show("C" + Alarm); return; } if (!SetValueWithJudge(conveyorTimerA, Convert.ToInt16(BoxE.ATimeSetValue1.MCValue.ToString()), Convert.ToInt16(BoxE.ATimeSetValue2.MCValue.ToString()))) { MessageBox.Show("时间设定A" + Alarm); return; } if (!SetValueWithJudge(conveyorTimerB, Convert.ToInt16(BoxE.BTimeSetValue1.MCValue.ToString()), Convert.ToInt16(BoxE.BTimeSetValue2.MCValue.ToString()))) { MessageBox.Show("时间设定B" + Alarm); return; } if (!SetValueWithJudge(conveyorTimerC, Convert.ToInt16(BoxE.CTimeSetValue1.MCValue.ToString()), Convert.ToInt16(BoxE.CTimeSetValue2.MCValue.ToString()))) { MessageBox.Show("时间设定C" + Alarm); return; } DB112WriterHelper.AddConveyorA(conveyorA); DB112WriterHelper.AddConveyorB(conveyorB); DB112WriterHelper.AddConveyorC(conveyorC); DB112WriterHelper.AddConveyorTimerA(conveyorTimerA); DB112WriterHelper.AddConveyorTimerB(conveyorTimerB); DB112WriterHelper.AddConveyorTimerC(conveyorTimerC); MessageBox.Show("数据下达成功!"); } private static bool SetValueWithJudge(Conveyor conveyor, float v1, float v2, float v3, float v4, float v5, float v6, float v7, float v8) { if (JudgeValue(v1) && JudgeValue(v2) && JudgeValue(v3) && JudgeValue(v4) && JudgeValue(v5) && JudgeValue(v6) && JudgeValue(v7) && JudgeValue(v8)) { conveyor.SetValue1 = v1; conveyor.SetValue2 = v2; conveyor.SetValue3 = v3; conveyor.SetValue4 = v4; conveyor.SetValue5 = v5; conveyor.SetValue6 = v6; conveyor.SetValue7 = v7; conveyor.SetValue8 = v8; return true; } else { return false; } } private static bool SetValueWithJudge(ConveyorTimer conveyor, short v1, short v2) { if (JudgeValue(v1) && JudgeValue(v2)) { conveyor.SetValue1 = v1; conveyor.SetValue2 = v2; return true; } else { return false; } } private static bool JudgeValue(float value) { if (value < 0 || value > 50) { return false; } else { return true; } } } }