You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lj_plc/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Dan/InitAction.cs

513 lines
16 KiB
C#

6 months ago
using DataBlockHelper.DBHelpers;
using DataBlockHelper.Entity;
using Mesnac.Action.Base;
using Mesnac.Controls.ChemicalWeighing;
using Mesnac.Controls.Default;
using System;
using System.Collections.Generic;
6 months ago
using System.Drawing;
6 months ago
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mesnac.Action.ChemicalWeighing.Dan
{
public class InitAction : ChemicalWeighingAction, IAction
{
MCCheckBox cbkA;
MCTextBox txtBoxA;
HslLanternSimple HslA;
MCCheckBox cbkB;
MCTextBox txtBoxB;
HslLanternSimple HslB;
MCCheckBox cbkC;
MCTextBox txtBoxC;
HslLanternSimple HslC;
MCCheckBox cbkD;
MCTextBox txtBoxD;
HslLanternSimple HslD;
MCCheckBox cbkE;
MCTextBox txtBoxE;
HslLanternSimple HslE;
MCCheckBox cbkF;
MCTextBox txtBoxF;
HslLanternSimple HslF;
MCCheckBox cbkG;
MCTextBox txtBoxG;
HslLanternSimple HslG;
MCCheckBox cbkH;
MCTextBox txtBoxH;
HslLanternSimple HslH;
MCCheckBox cbkI;
MCTextBox txtBoxI;
HslLanternSimple HslI;
MCCheckBox cbkJ;
MCTextBox txtBoxJ;
HslLanternSimple HslJ;
MCCheckBox cbkK;
MCTextBox txtBoxK;
HslLanternSimple HslK;
MCCheckBox cbkL;
MCTextBox txtBoxL;
HslLanternSimple HslL;
MCCheckBox cbkM;
MCTextBox txtBoxM;
HslLanternSimple HslM;
MCCheckBox cbkN;
MCTextBox txtBoxN;
HslLanternSimple HslN;
MCCheckBox cbkO;
MCTextBox txtBoxO;
HslLanternSimple HslO;
MCButton MCButton1;
6 months ago
MCButton MCButton2;
6 months ago
List<Control> controll;
Timer timer;
6 months ago
Color backColor;
6 months ago
public void Run(RuntimeParameter runtime)
{
RunIni(runtime);
controll = GetAllControls();
timer = new Timer();
timer.Interval = 1000;
timer.Enabled = true;
timer.Tick += GetPlcValue;//添加事件
MCButton1 = controll.FirstOrDefault(x => x.Name == "MCButton1") as MCButton;
6 months ago
MCButton2 = controll.FirstOrDefault(x => x.Name == "MCButton2") as MCButton;
6 months ago
MCButton1.Click += MCButton1_Click;
6 months ago
MCButton2.Click += MCButton2_Click;
6 months ago
cbkA = controll.FirstOrDefault(x => x.Name == "cbkA") as MCCheckBox;
cbkB = controll.FirstOrDefault(x => x.Name == "cbkB") as MCCheckBox;
cbkC = controll.FirstOrDefault(x => x.Name == "cbkC") as MCCheckBox;
cbkD = controll.FirstOrDefault(x => x.Name == "cbkD") as MCCheckBox;
cbkE = controll.FirstOrDefault(x => x.Name == "cbkE") as MCCheckBox;
cbkF = controll.FirstOrDefault(x => x.Name == "cbkF") as MCCheckBox;
cbkG = controll.FirstOrDefault(x => x.Name == "cbkG") as MCCheckBox;
cbkH = controll.FirstOrDefault(x => x.Name == "cbkH") as MCCheckBox;
cbkI = controll.FirstOrDefault(x => x.Name == "cbkI") as MCCheckBox;
cbkJ = controll.FirstOrDefault(x => x.Name == "cbkJ") as MCCheckBox;
cbkK = controll.FirstOrDefault(x => x.Name == "cbkK") as MCCheckBox;
cbkL = controll.FirstOrDefault(x => x.Name == "cbkL") as MCCheckBox;
cbkM = controll.FirstOrDefault(x => x.Name == "cbkM") as MCCheckBox;
cbkN = controll.FirstOrDefault(x => x.Name == "cbkN") as MCCheckBox;
cbkO = controll.FirstOrDefault(x => x.Name == "cbkO") as MCCheckBox;
txtBoxA = controll.FirstOrDefault(x => x.Name == "txtBoxA") as MCTextBox;
txtBoxB = controll.FirstOrDefault(x => x.Name == "txtBoxB") as MCTextBox;
txtBoxC = controll.FirstOrDefault(x => x.Name == "txtBoxC") as MCTextBox;
txtBoxD = controll.FirstOrDefault(x => x.Name == "txtBoxD") as MCTextBox;
txtBoxE = controll.FirstOrDefault(x => x.Name == "txtBoxE") as MCTextBox;
txtBoxF = controll.FirstOrDefault(x => x.Name == "txtBoxF") as MCTextBox;
txtBoxG = controll.FirstOrDefault(x => x.Name == "txtBoxG") as MCTextBox;
txtBoxH = controll.FirstOrDefault(x => x.Name == "txtBoxH") as MCTextBox;
txtBoxI = controll.FirstOrDefault(x => x.Name == "txtBoxI") as MCTextBox;
txtBoxJ = controll.FirstOrDefault(x => x.Name == "txtBoxJ") as MCTextBox;
txtBoxK = controll.FirstOrDefault(x => x.Name == "txtBoxK") as MCTextBox;
txtBoxL = controll.FirstOrDefault(x => x.Name == "txtBoxL") as MCTextBox;
txtBoxM = controll.FirstOrDefault(x => x.Name == "txtBoxM") as MCTextBox;
txtBoxN = controll.FirstOrDefault(x => x.Name == "txtBoxN") as MCTextBox;
txtBoxO = controll.FirstOrDefault(x => x.Name == "txtBoxO") as MCTextBox;
HslA = controll.FirstOrDefault(x => x.Name == "HslA") as HslLanternSimple;
HslB = controll.FirstOrDefault(x => x.Name == "HslB") as HslLanternSimple;
HslC = controll.FirstOrDefault(x => x.Name == "HslC") as HslLanternSimple;
HslD = controll.FirstOrDefault(x => x.Name == "HslD") as HslLanternSimple;
HslE = controll.FirstOrDefault(x => x.Name == "HslE") as HslLanternSimple;
HslF = controll.FirstOrDefault(x => x.Name == "HslF") as HslLanternSimple;
HslG = controll.FirstOrDefault(x => x.Name == "HslG") as HslLanternSimple;
HslH = controll.FirstOrDefault(x => x.Name == "HslH") as HslLanternSimple;
HslI = controll.FirstOrDefault(x => x.Name == "HslI") as HslLanternSimple;
HslJ = controll.FirstOrDefault(x => x.Name == "HslJ") as HslLanternSimple;
HslK = controll.FirstOrDefault(x => x.Name == "HslK") as HslLanternSimple;
HslL = controll.FirstOrDefault(x => x.Name == "HslL") as HslLanternSimple;
HslM = controll.FirstOrDefault(x => x.Name == "HslM") as HslLanternSimple;
HslN = controll.FirstOrDefault(x => x.Name == "HslN") as HslLanternSimple;
HslO = controll.FirstOrDefault(x => x.Name == "HslO") as HslLanternSimple;
6 months ago
MCButton2_Click(new object(), new EventArgs());
backColor=txtBoxA.BackColor;
cbkA.CheckedChanged += CbkA_CheckedChanged;
}
private void CbkA_CheckedChanged(object sender, EventArgs e)
{
//if (sender == cbkA)
//{
// if (cbkA.Checked)
// {
// txtBoxA.BackColor = Color.Green;
// }
// else
// {
// txtBoxA.BackColor = backColor;
// }
//}
}
6 months ago
6 months ago
private void MCButton2_Click(object sender, EventArgs e)
{
Db2101Helper db = new Db2101Helper();
Ch(cbkA, txtBoxA, HslA, db.SiloA, true);
Ch(cbkB, txtBoxB, HslB, db.SiloB, true);
Ch(cbkC, txtBoxC, HslC, db.SiloC, true);
Ch(cbkD, txtBoxD, HslD, db.SiloD, true);
Ch(cbkE, txtBoxE, HslE, db.SiloE, true);
Ch(cbkF, txtBoxF, HslF, db.SiloF, true);
Ch(cbkG, txtBoxG, HslG, db.SiloG, true);
Ch(cbkH, txtBoxH, HslH, db.SiloH, true);
Ch(cbkI, txtBoxI, HslI, db.SiloI, true);
Ch(cbkJ, txtBoxJ, HslJ, db.SiloJ, true);
Ch(cbkK, txtBoxK, HslK, db.SiloK, true);
Ch(cbkL, txtBoxL, HslL, db.SiloL, true);
Ch(cbkM, txtBoxM, HslM, db.SiloM, true);
Ch(cbkN, txtBoxN, HslN, db.SiloN, true);
Ch(cbkO, txtBoxO, HslO, db.Siloo, true);
6 months ago
}
private void MCButton1_Click(object sender, EventArgs e)
{
Db2101WriteHelp db2101WriteHelp = new Db2101WriteHelp();
short val = 0;
Db2101Entity entityA = new Db2101Entity();
if (cbkA.Checked)
{
val = short.Parse(txtBoxA.MCValue.ToString());
if (val <= 0 || val > 100)
{
MessageBox.Show("冲氮气时间范围[1-100]");
return;
}
entityA.time = val;
}
entityA.enable = cbkA.Checked;
Db2101Entity entityB = new Db2101Entity();
if (cbkB.Checked)
{
val = short.Parse(txtBoxB.MCValue.ToString());
if (val <= 0 || val > 100)
{
MessageBox.Show("冲氮气时间范围[1-100]");
return;
}
entityB.time = val;
}
entityB.enable = cbkB.Checked;
Db2101Entity entityC = new Db2101Entity();
if (cbkC.Checked)
{
val = short.Parse(txtBoxC.MCValue.ToString());
if (val <= 0 || val > 100)
{
MessageBox.Show("冲氮气时间范围[1-100]");
return;
}
entityC.time = val;
}
entityC.enable = cbkC.Checked;
Db2101Entity entityD = new Db2101Entity();
if (cbkD.Checked)
{
val = short.Parse(txtBoxD.MCValue.ToString());
if (val <= 0 || val > 100)
{
MessageBox.Show("冲氮气时间范围[1-100]");
return;
}
entityD.time = val;
}
entityD.enable = cbkD.Checked;
Db2101Entity entityE = new Db2101Entity();
if (cbkE.Checked)
{
val = short.Parse(txtBoxE.MCValue.ToString());
if (val <= 0 || val > 100)
{
MessageBox.Show("冲氮气时间范围[1-100]");
return;
}
entityE.time = val;
}
entityE.enable = cbkE.Checked;
Db2101Entity entityF = new Db2101Entity();
if (cbkF.Checked)
{
val = short.Parse(txtBoxF.MCValue.ToString());
if (val <= 0 || val > 100)
{
MessageBox.Show("冲氮气时间范围[1-100]");
return;
}
entityF.time = val;
}
entityF.enable = cbkF.Checked;
Db2101Entity entityG = new Db2101Entity();
if (cbkG.Checked)
{
val = short.Parse(txtBoxG.MCValue.ToString());
if (val <= 0 || val > 100)
{
MessageBox.Show("冲氮气时间范围[1-100]");
return;
}
entityG.time = val;
}
entityG.enable = cbkG.Checked;
Db2101Entity entityH = new Db2101Entity();
if (cbkH.Checked)
{
val = short.Parse(txtBoxH.MCValue.ToString());
if (val <= 0 || val > 100)
{
MessageBox.Show("冲氮气时间范围[1-100]");
return;
}
entityH.time = val;
}
entityH.enable = cbkH.Checked;
Db2101Entity entityI = new Db2101Entity();
if (cbkI.Checked)
{
val = short.Parse(txtBoxI.MCValue.ToString());
if (val <= 0 || val > 100)
{
MessageBox.Show("冲氮气时间范围[1-100]");
return;
}
entityI.time = val;
}
entityI.enable = cbkI.Checked;
Db2101Entity entityJ = new Db2101Entity();
if (cbkJ.Checked)
{
val = short.Parse(txtBoxJ.MCValue.ToString());
if (val <= 0 || val > 100)
{
MessageBox.Show("冲氮气时间范围[1-100]");
return;
}
entityJ.time = val;
}
entityJ.enable = cbkJ.Checked;
Db2101Entity entityK = new Db2101Entity();
if (cbkK.Checked)
{
val = short.Parse(txtBoxK.MCValue.ToString());
if (val <= 0 || val > 100)
{
MessageBox.Show("冲氮气时间范围[1-100]");
return;
}
entityK.time = val;
}
entityK.enable = cbkK.Checked;
Db2101Entity entityL = new Db2101Entity();
if (cbkL.Checked)
{
val = short.Parse(txtBoxL.MCValue.ToString());
if (val <= 0 || val > 100)
{
MessageBox.Show("冲氮气时间范围[1-100]");
return;
}
entityL.time = val;
}
entityL.enable = cbkL.Checked;
Db2101Entity entityM = new Db2101Entity();
if (cbkM.Checked)
{
val = short.Parse(txtBoxM.MCValue.ToString());
if (val <= 0 || val > 100)
{
MessageBox.Show("冲氮气时间范围[1-100]");
return;
}
entityM.time = val;
}
entityM.enable = cbkM.Checked;
Db2101Entity entityN = new Db2101Entity();
if (cbkN.Checked)
{
val = short.Parse(txtBoxN.MCValue.ToString());
if (val <= 0 || val > 100)
{
MessageBox.Show("冲氮气时间范围[1-100]");
return;
}
entityN.time = val;
}
entityN.enable = cbkN.Checked;
Db2101Entity entityO = new Db2101Entity();
if (cbkO.Checked)
{
val = short.Parse(txtBoxO.MCValue.ToString());
if (val <= 0 || val > 100)
{
MessageBox.Show("冲氮气时间范围[1-100]");
return;
}
entityO.time = val;
}
entityO.enable = cbkO.Checked;
db2101WriteHelp.WriteA(entityA);
db2101WriteHelp.WriteB(entityB);
db2101WriteHelp.WriteC(entityC);
db2101WriteHelp.WriteD(entityD);
db2101WriteHelp.WriteE(entityE);
db2101WriteHelp.WriteF(entityF);
db2101WriteHelp.WriteG(entityG);
db2101WriteHelp.WriteH(entityH);
db2101WriteHelp.WriteI(entityI);
db2101WriteHelp.WriteJ(entityJ);
db2101WriteHelp.WriteK(entityK);
db2101WriteHelp.WriteL(entityL);
db2101WriteHelp.WriteM(entityM);
db2101WriteHelp.WriteN(entityN);
db2101WriteHelp.WriteO(entityO);
db2101WriteHelp.WriteStart();
MessageBox.Show("开始充氮气");
}
private void GetPlcValue(object sender, EventArgs e)
{
if (GetAllControls().Count == 0)
{
timer.Stop();
timer.Dispose();
timer = null;
}
Db2101Helper db=new Db2101Helper();
6 months ago
Ch(cbkA, txtBoxA, HslA, db.SiloA,false);
Ch(cbkB, txtBoxB, HslB, db.SiloB, false);
Ch(cbkC, txtBoxC, HslC, db.SiloC, false);
Ch(cbkD, txtBoxD, HslD, db.SiloD, false);
Ch(cbkE, txtBoxE, HslE, db.SiloE, false);
Ch(cbkF, txtBoxF, HslF, db.SiloF, false);
Ch(cbkG, txtBoxG, HslG, db.SiloG, false);
Ch(cbkH, txtBoxH, HslH, db.SiloH, false);
Ch(cbkI, txtBoxI, HslI, db.SiloI, false);
Ch(cbkJ, txtBoxJ, HslJ, db.SiloJ, false);
Ch(cbkK, txtBoxK, HslK, db.SiloK, false);
Ch(cbkL, txtBoxL, HslL, db.SiloL, false);
Ch(cbkM, txtBoxM, HslM, db.SiloM, false);
Ch(cbkN, txtBoxN, HslN, db.SiloN, false);
Ch(cbkO, txtBoxO, HslO, db.Siloo, false);
6 months ago
}
6 months ago
private void Ch(MCCheckBox cb,MCTextBox cTextBox,HslLanternSimple simple,Db2101Entity entity,bool b)
6 months ago
{
6 months ago
if (b)
{
cb.Checked = entity.enable;
cTextBox.MCValue = entity.time;
}
6 months ago
if (entity.finished) {
simple.LanternBackground = System.Drawing.Color.Green;
}
else
{
simple.LanternBackground = System.Drawing.Color.Gray;
}
}
}
}