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); } 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; } } public static void DownSlio(SlioEntity entity) { var d = new Uhd() { A = Convert.ToSingle(entity.TxtA.MCValue.ToString()), B = Convert.ToSingle(entity.TxtB.MCValue.ToString()), C = Convert.ToSingle(entity.TxtC.MCValue.ToString()), D = Convert.ToSingle(entity.TxtD.MCValue.ToString()), E = Convert.ToSingle(entity.TxtE.MCValue.ToString()), F = Convert.ToSingle(entity.TxtF.MCValue.ToString()), G = Convert.ToSingle(entity.TxtG.MCValue.ToString()), H = Convert.ToSingle(entity.TxtH.MCValue.ToString()), I = Convert.ToSingle(entity.TxtI.MCValue.ToString()), J = Convert.ToSingle(entity.TxtJ.MCValue.ToString()), K = Convert.ToSingle(entity.TxtK.MCValue.ToString()), L = Convert.ToSingle(entity.TxtL.MCValue.ToString()), M = Convert.ToSingle(entity.TxtM.MCValue.ToString()), N = Convert.ToSingle(entity.TxtN.MCValue.ToString()), O = Convert.ToSingle(entity.TxtO.MCValue.ToString()), Delay1=Convert.ToUInt16(entity.TxtDelay1.MCValue.ToString()), Delay2 = Convert.ToUInt16(entity.TxtDelay2.MCValue.ToString()), Delay3 = Convert.ToUInt16(entity.TxtDelay3.MCValue.ToString()), }; DB120WriteHelp.AddABCDEF(d); } public static void DownPipe(PipeEntity pipe) { var y = new Pipe() { MainPipieA = Convert.ToSingle(pipe.MainA.MCValue), AuxPipieA = Convert.ToSingle(pipe.AuxA.MCValue), MainPipieB = Convert.ToSingle(pipe.MainB.MCValue), AuxPipieB = Convert.ToSingle(pipe.AuxB.MCValue), MainPipieC = Convert.ToSingle(pipe.MainC.MCValue), AuxPipieC = Convert.ToSingle(pipe.AuxC.MCValue), UpperPressure = Convert.ToSingle(pipe.Upper.MCValue), LowerPressure = Convert.ToSingle(pipe.Lower.MCValue) }; DB92WriterHelp.Add(y) ; } } }