using Mesnac.Action.Base; using Mesnac.Controls.Default; using System.Windows.Forms; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using DataBlockHelper.DBHelpers; using Mesnac.Controls.ChemicalWeighing; using DataBlockHelper; namespace Mesnac.Action.ChemicalWeighing.Qu { internal class InitAction : ChemicalWeighingAction, IAction { MCLabel MCLabelA; MCLabel MCLabelB; MCButton BtnA; MCButton BtnB; Timer timer; MCTextBox vibSilo_On; MCTextBox vibSilo_Off; MCTextBox vibDaybin_On; MCTextBox vibDaybin_Off; MCTextBox vibHopper_On; MCTextBox vibHopper_Off; MCTextBox plsSilo_On; MCTextBox plsSilo_Off; MCTextBox plsDaybin_On; MCTextBox plsDaybin_Off; MCTextBox plsHopper_On; MCTextBox plsHopper_Off; MCButton btnUpdate; MCButton MCButton2147483646; HslLanternSimple HslEnable; HslLanternSimple HslPuase; MCButton BtnEnable; MCButton BtnPuase; HslLanternSimple CoolWaterA; HslLanternSimple CoolWaterB; HslLanternSimple HotWaterA; HslLanternSimple HotWaterB; MCButton BtnCoolWaterA; MCButton BtnCoolWaterB; MCButton BtnHotWaterA; MCButton BtnHotWaterB; HslLanternSimple HslDa; HslLanternSimple HslDb; HslLanternSimple HslDc; HslLanternSimple HslDd; MCButton BtnDa; MCButton BtnDb; MCButton BtnDc; MCButton BtnDd; public void Run(RuntimeParameter runtime) { base.RunIni(runtime); //必须调用 var controls = GetAllControls(); HslDa=controls.FirstOrDefault(x => x.Name == "HslDa") as HslLanternSimple; HslDb = controls.FirstOrDefault(x => x.Name == "HslDb") as HslLanternSimple; HslDc = controls.FirstOrDefault(x => x.Name == "HslDc") as HslLanternSimple; HslDd = controls.FirstOrDefault(x => x.Name == "HslDd") as HslLanternSimple; BtnDa=controls.FirstOrDefault(x => x.Name == "BtnDa") as MCButton; BtnDb = controls.FirstOrDefault(x => x.Name == "BtnDb") as MCButton; BtnDc = controls.FirstOrDefault(x => x.Name == "BtnDc") as MCButton; BtnDd = controls.FirstOrDefault(x => x.Name == "BtnDd") as MCButton; BtnDa.Click += BtnDa_Click; BtnDb.Click += BtnDb_Click; BtnDc.Click += BtnDc_Click; BtnDd.Click += BtnDd_Click; BtnCoolWaterA = controls.FirstOrDefault(x => x.Name == "BtnCoolWaterA") as MCButton; BtnCoolWaterA.Click += BtnCoolWaterA_Click; BtnCoolWaterB = controls.FirstOrDefault(x => x.Name == "BtnCoolWaterB") as MCButton; BtnCoolWaterB.Click += BtnCoolWaterB_Click; BtnHotWaterA = controls.FirstOrDefault(x => x.Name == "BtnCoolHotWaterA") as MCButton; BtnHotWaterA.Click += BtnHotWaterA_Click; BtnHotWaterB = controls.FirstOrDefault(x => x.Name == "BtnCoolHotWaterB") as MCButton; BtnHotWaterB.Click += BtnHotWaterB_Click; CoolWaterA = controls.FirstOrDefault(x => x.Name == "CoolWaterA") as HslLanternSimple; CoolWaterB = controls.FirstOrDefault(x => x.Name == "CoolWaterB") as HslLanternSimple; HotWaterA = controls.FirstOrDefault(x => x.Name == "HotWaterA") as HslLanternSimple; HotWaterB = controls.FirstOrDefault(x => x.Name == "HotWaterB") as HslLanternSimple; HslEnable = controls.FirstOrDefault(x => x.Name == "HslEnable") as HslLanternSimple; HslPuase = controls.FirstOrDefault(x => x.Name == "HslPuase") as HslLanternSimple; BtnEnable = controls.FirstOrDefault(x => x.Name == "BtnEnable") as MCButton; BtnEnable.Click += BtnEnable_Click; BtnPuase = controls.FirstOrDefault(x => x.Name == "BtnPuase") as MCButton; BtnPuase.Click += BtnPuase_Click; MCLabelA = controls.FirstOrDefault(x => x.Name == "MCLabelA") as MCLabel; MCLabelA.MCValue = ""; MCLabelB = controls.FirstOrDefault(x => x.Name == "MCLabelB") as MCLabel; MCLabelB.MCValue = ""; BtnA = controls.FirstOrDefault(x => x.Name == "BtnA") as MCButton; BtnB = controls.FirstOrDefault(x => x.Name == "BtnB") as MCButton; vibSilo_On= controls.FirstOrDefault(x => x.Name== "vibSilo_On") as MCTextBox; vibSilo_Off= controls.FirstOrDefault(x => x.Name== "vibSilo_Off") as MCTextBox; vibDaybin_On = controls.FirstOrDefault(x => x.Name == "vibDaybin_On") as MCTextBox; vibDaybin_Off = controls.FirstOrDefault(x => x.Name == "vibDaybin_Off") as MCTextBox; vibHopper_On = controls.FirstOrDefault(x => x.Name == "vibHopper_On") as MCTextBox; vibHopper_Off = controls.FirstOrDefault(x => x.Name == "vibHopper_Off") as MCTextBox; plsSilo_On = controls.FirstOrDefault(x => x.Name == "plsSilo_On") as MCTextBox; plsSilo_Off = controls.FirstOrDefault(x => x.Name == "plsSilo_Off") as MCTextBox; plsDaybin_On = controls.FirstOrDefault(x => x.Name == "plsDaybin_On") as MCTextBox; plsDaybin_Off = controls.FirstOrDefault(x => x.Name == "plsDaybin_Off") as MCTextBox; plsHopper_On = controls.FirstOrDefault(x => x.Name == "plsHopper_On") as MCTextBox; plsHopper_Off = controls.FirstOrDefault(x => x.Name == "plsHopper_Off") as MCTextBox; //BtnUpdate btnUpdate= controls.FirstOrDefault(x => x.Name == "BtnUpdate") as MCButton; MCButton2147483646 = controls.FirstOrDefault(x => x.Name == "MCButton2147483646") as MCButton; MCButton2147483646.Click += MCButton2147483646_Click; MCButton2147483646_Click(new object(),new EventArgs()); BtnA.Click += BtnA_Click; BtnB.Click += BtnB_Click; btnUpdate.Click += BtnBc_Click; timer = new Timer(); timer.Interval = 1000; timer.Enabled = true; timer.Tick += new EventHandler(StateRefresh);//添加事件 } private void BtnDd_Click(object sender, EventArgs e) { if (BtnDd.MCValue.ToString().Contains("开")) { DB2108HelperWriteNew.WriteD(true); } else { DB2108HelperWriteNew.WriteD(false); } } private void BtnDc_Click(object sender, EventArgs e) { if (BtnDc.MCValue.ToString().Contains("开")) { DB2108HelperWriteNew.WriteC(true); } else { DB2108HelperWriteNew.WriteC(false); } } private void BtnDb_Click(object sender, EventArgs e) { if (BtnDb.MCValue.ToString().Contains("开")) { DB2108HelperWriteNew.WriteB(true); } else { DB2108HelperWriteNew.WriteB(false); } } private void BtnDa_Click(object sender, EventArgs e) { if (BtnDd.MCValue.ToString().Contains("开")) { DB2108HelperWriteNew.WriteA(true); } else { DB2108HelperWriteNew.WriteA(false); } } private void BtnHotWaterB_Click(object sender, EventArgs e) { if (BtnHotWaterB.MCValue.ToString().Contains("开")) { PlcConnect.Instance.Write("DB2108.8.0", true); } else { PlcConnect.Instance.Write("DB2108.8.0", false); } } private void BtnHotWaterA_Click(object sender, EventArgs e) { if (BtnHotWaterA.MCValue.ToString().Contains("开")) { PlcConnect.Instance.Write("DB2108.6.0", true); } else { PlcConnect.Instance.Write("DB2108.6.0", false); } } private void BtnCoolWaterB_Click(object sender, EventArgs e) { if (BtnCoolWaterB.MCValue.ToString().Contains("开")) { PlcConnect.Instance.Write("DB2108.4.0", true); } else { PlcConnect.Instance.Write("DB2108.4.0", false); } } private void BtnCoolWaterA_Click(object sender, EventArgs e) { if (BtnCoolWaterA.MCValue.ToString().Contains("开")) { PlcConnect.Instance.Write("DB2108.2.0", true); } else { PlcConnect.Instance.Write("DB2108.2.0", false); } } private void BtnPuase_Click(object sender, EventArgs e) { //BtnPuase if (BtnPuase.MCValue.ToString() == "启动") { PlcConnect.Instance.Write("DB2108.0.1", true); } else { PlcConnect.Instance.Write("DB2108.0.1", false); } } private void BtnEnable_Click(object sender, EventArgs e) { if (BtnEnable.MCValue.ToString()== "启动使能") { PlcConnect.Instance.Write("DB2108.0.0",true); } else { PlcConnect.Instance.Write("DB2108.0.0", false); } } private void MCButton2147483646_Click(object sender, EventArgs e) { DB2108HelperNew dB2108 = new DB2108HelperNew(); Time2108 time = dB2108.Time; if (time != null) { vibSilo_On.MCValue = time.VibSiloOn; vibSilo_Off.MCValue = time.VibSiloOff; vibDaybin_On.MCValue = time.VibDaybinOn; vibDaybin_Off.MCValue = time.VibDaybinOff; vibHopper_On.MCValue = time.VibHopperOn; vibHopper_Off.MCValue = time.VibHopperOff; plsSilo_On.MCValue = time.PlsSiloOn; plsSilo_Off.MCValue = time.PlsSiloOff; plsDaybin_On.MCValue = time.PlsDaybinOn; plsDaybin_Off.MCValue = time.PlsDaybinOff; plsHopper_On.MCValue = time.PlsHopperOn; plsHopper_Off.MCValue = time.PlsHopperOff; } } private void BtnA_Click(object sender, EventArgs e) { DB2110WriteHelper.WriteA(); MessageBox.Show("清理成功"); } private void BtnB_Click(object sender, EventArgs e) { DB2110WriteHelper.WriteB(); MessageBox.Show("清理成功"); } private void BtnBc_Click(object sender, EventArgs e) { var b= Check(vibSilo_On); if (b == false) return; b = Check(vibSilo_Off); if (b == false) return; b = Check(vibDaybin_On); if (b == false) return; b = Check(vibDaybin_Off); if (b == false) return; b = Check(vibHopper_On); if (b == false) return; b = Check(vibHopper_Off); if (b == false) return; b = Check(plsSilo_On); if (b == false) return; b = Check(plsSilo_Off); if (b == false) return; b = Check(plsDaybin_On); if (b == false) return; b = Check(plsDaybin_Off); if (b == false) return; b = Check(plsHopper_On); if (b == false) return; b = Check(plsHopper_Off); if (b == false) return; Time2108 time=new Time2108(); time.VibSiloOn = ushort.Parse(vibSilo_On.MCValue.ToString()); time.VibSiloOff = ushort.Parse(vibSilo_Off.MCValue.ToString()); time.VibDaybinOn = ushort.Parse(vibDaybin_On.MCValue.ToString()); time.VibDaybinOff = ushort.Parse(vibDaybin_Off.MCValue.ToString()); time.VibHopperOn=ushort.Parse(vibHopper_On.MCValue.ToString()); time.VibHopperOff=ushort.Parse(vibHopper_Off.MCValue.ToString()); time.PlsSiloOn=ushort.Parse(plsSilo_On.MCValue.ToString()) ; time.PlsSiloOff=ushort.Parse(plsSilo_Off.MCValue.ToString() ) ; time.PlsDaybinOn=ushort.Parse(plsDaybin_On.MCValue.ToString()) ; time.PlsDaybinOff=ushort.Parse(plsDaybin_Off.MCValue.ToString()) ; time.PlsHopperOn = ushort.Parse(plsHopper_On.MCValue.ToString()); time.PlsHopperOff = ushort.Parse(plsHopper_Off.MCValue.ToString()); DB2108HelperWriteNew.Inser(time); MessageBox.Show("更新成功"); } private bool Check(MCTextBox cTextBox) { try { int mc = Convert.ToInt32(cTextBox.MCValue.ToString()); if(mc <=0 || mc > 60) { MessageBox.Show("范围错误 [1-60]"); return false; } } catch (Exception) { MessageBox.Show("格式错误"); return false; } return true; } private void StateRefresh(object sender, EventArgs e) { if (GetAllControls().Count == 0) { timer.Stop(); timer.Dispose(); timer = null; } Db2110Help db2110 = new Db2110Help(); string a = db2110.GetA(); if (a.Length == 0) { MCLabelA.MCValue = "无"; } else { MCLabelA.MCValue = a; } string b=db2110.GetB(); if (b.Length == 0) { MCLabelB.MCValue = "无"; } else { MCLabelB.MCValue = b; } DB2108HelperNew dB2108 = new DB2108HelperNew(); var main = dB2108.Main; if (main.pause) { BtnPuase.MCValue = "停止"; HslPuase.LanternBackground = System.Drawing.Color.Green; } else { BtnPuase.MCValue = "启动"; HslPuase.LanternBackground = System.Drawing.Color.Gray; } if (main.enable) { HslEnable.LanternBackground = System.Drawing.Color.Green; BtnEnable.MCValue = "禁止使能"; } else { BtnEnable.MCValue = "启动使能"; HslEnable.LanternBackground = System.Drawing.Color.Gray; } var ab= dB2108.CoolWaterA; if (ab.enable) { BtnCoolWaterA.MCValue = "冷水秤A使能关闭"; CoolWaterA.LanternBackground= System.Drawing.Color.Green; } else { BtnCoolWaterA.MCValue = "冷水秤A使能开始"; CoolWaterA.LanternBackground = System.Drawing.Color.Gray; } ab= dB2108.CoolWaterB; if (ab.enable) { BtnCoolWaterB.MCValue = "冷水秤B使能关闭"; CoolWaterB.LanternBackground = System.Drawing.Color.Green; } else { BtnCoolWaterB.MCValue = "冷水秤B使能开始"; CoolWaterB.LanternBackground = System.Drawing.Color.Gray; } ab = dB2108.HotWaterA; if (ab.enable) { BtnHotWaterA.MCValue = "热水秤A使能关闭"; HotWaterA.LanternBackground = System.Drawing.Color.Green; } else { BtnHotWaterA.MCValue = "热水秤A使能开始"; HotWaterA.LanternBackground = System.Drawing.Color.Gray; } ab = dB2108.HotWaterB; if (ab.enable) { BtnHotWaterB.MCValue = "热水秤B使能关闭"; HotWaterB.LanternBackground = System.Drawing.Color.Green; } else { BtnHotWaterB.MCValue = "热水秤B使能开始"; HotWaterB.LanternBackground = System.Drawing.Color.Gray; } //干混机 ab = dB2108.DryA; if (ab.enable) { BtnDa.MCValue = "干混A使能关"; HslDa.LanternBackground = System.Drawing.Color.Green; } else { BtnDa.MCValue = "干混A使能开"; HslDa.LanternBackground = System.Drawing.Color.Gray; } ab = dB2108.DryB; if (ab.enable) { BtnDb.MCValue = "干混B使能关"; HslDb.LanternBackground = System.Drawing.Color.Green; } else { BtnDb.MCValue = "干混B使能开"; HslDb.LanternBackground = System.Drawing.Color.Gray; } ab = dB2108.DryC; if (ab.enable) { BtnDc.MCValue = "干混C使能关"; HslDc.LanternBackground = System.Drawing.Color.Green; } else { BtnDc.MCValue = "干混C使能开"; HslDc.LanternBackground = System.Drawing.Color.Gray; } ab = dB2108.DryD; if (ab.enable) { BtnDd.MCValue = "干混D使能关"; HslDd.LanternBackground = System.Drawing.Color.Green; } else { BtnDd.MCValue = "干混D使能开"; HslDd.LanternBackground = System.Drawing.Color.Gray; } } } }