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/ManualControl/ManualControlAction.cs

517 lines
12 KiB
C#

using Mesnac.Action.Base;
using Mesnac.Controls.Base;
using Mesnac.Controls.Default;
using Mesnac.Core.Service;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mesnac.Action.ChemicalWeighing.ManualControl
{
class ManualControlAction : ChemicalWeighingAction, IAction
{
private List<DbMCControl> McControllist;
private byte GelChooseA;
private byte GelChooseB;
private byte WetChoose1;
private byte WetChoose2;
private byte WetChoose3;
private byte WetChoose4;
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须要调用
#region 控件导入
McControllist = GetAllDbMCControlsByOption(DbOptionTypes.Query);//获取所有待初始化控件
IBaseControl StartMetage1 = GetBaseControl("StartMetage1");
IBaseControl StopMetage1 = GetBaseControl("StopMetage1");
IBaseControl StartMetage2 = GetBaseControl("StartMetage2");
IBaseControl StopMetage2 = GetBaseControl("StopMetage2");
IBaseControl StartMetage3 = GetBaseControl("StartMetage3");
IBaseControl StopMetage3 = GetBaseControl("StopMetage3");
IBaseControl StartMetage4 = GetBaseControl("StartMetage4");
IBaseControl StopMetage4 = GetBaseControl("StopMetage4");
IBaseControl WaterOut1 = GetBaseControl("WaterOut1");
IBaseControl WaterOut2 = GetBaseControl("WaterOut2");
IBaseControl WaterOut3 = GetBaseControl("WaterOut3");
IBaseControl WaterOut4 = GetBaseControl("WaterOut4");
IBaseControl SpiralOn1 = GetBaseControl("SpiralOn1");
IBaseControl SpiralOn2 = GetBaseControl("SpiralOn2");
IBaseControl SpiralOn3 = GetBaseControl("SpiralOn3");
IBaseControl SpiralOn4 = GetBaseControl("SpiralOn4");
IBaseControl Gel1 = GetBaseControl("Gel1");
IBaseControl Gel2 = GetBaseControl("Gel2");
IBaseControl Gel3 = GetBaseControl("Gel3");
IBaseControl Gel4 = GetBaseControl("Gel4");
IBaseControl Gel5 = GetBaseControl("Gel5");
IBaseControl Gel6 = GetBaseControl("Gel6");
IBaseControl Gel7 = GetBaseControl("Gel7");
IBaseControl Gel8 = GetBaseControl("Gel8");
IBaseControl Wet1 = GetBaseControl("Wet1");
IBaseControl Wet2 = GetBaseControl("Wet2");
IBaseControl Wet3 = GetBaseControl("Wet3");
IBaseControl Wet4 = GetBaseControl("Wet4");
IBaseControl Wet5 = GetBaseControl("Wet5");
IBaseControl Wet6 = GetBaseControl("Wet6");
IBaseControl Wet7 = GetBaseControl("Wet7");
IBaseControl Wet8 = GetBaseControl("Wet8");
IBaseControl SetWaterValue1 = GetBaseControl("SetWaterValue1");
IBaseControl SetWaterValue2 = GetBaseControl("SetWaterValue2");
IBaseControl SetWaterValue3 = GetBaseControl("SetWaterValue3");
IBaseControl SetWaterValue4 = GetBaseControl("SetWaterValue4");
IBaseControl SetSpiralValue1 = GetBaseControl("SetSpiralValue1");
IBaseControl SetSpiralValue2 = GetBaseControl("SetSpiralValue2");
IBaseControl SetSpiralValue3 = GetBaseControl("SetSpiralValue3");
IBaseControl SetSpiralValue4 = GetBaseControl("SetSpiralValue4");
#endregion
#region 单选判断
if (Convert.ToBoolean(Gel1.MCValue) == true)
{
GelChooseA = 1;
}
if (Convert.ToBoolean(Gel2.MCValue) == true)
{
GelChooseA = 2;
}
if (Convert.ToBoolean(Gel3.MCValue) == true)
{
GelChooseA = 3;
}
if (Convert.ToBoolean(Gel4.MCValue) == true)
{
GelChooseA = 4;
}
if (Convert.ToBoolean(Gel5.MCValue) == true)
{
GelChooseB = 5;
}
if (Convert.ToBoolean(Gel6.MCValue) == true)
{
GelChooseB = 6;
}
if (Convert.ToBoolean(Gel7.MCValue) == true)
{
GelChooseB = 7;
}
if (Convert.ToBoolean(Gel8.MCValue) == true)
{
GelChooseB = 8;
}
if (Convert.ToBoolean(Wet1.MCValue) == true)
{
WetChoose1 = 1;
}
if (Convert.ToBoolean(Wet2.MCValue) == true)
{
WetChoose1 = 2;
}
if (Convert.ToBoolean(Wet3.MCValue) == true)
{
WetChoose2 = 3;
}
if (Convert.ToBoolean(Wet4.MCValue) == true)
{
WetChoose2 = 4;
}
if (Convert.ToBoolean(Wet5.MCValue) == true)
{
WetChoose3 = 5;
}
if (Convert.ToBoolean(Wet6.MCValue) == true)
{
WetChoose3 = 6;
}
if (Convert.ToBoolean(Wet7.MCValue) == true)
{
WetChoose4 = 7;
}
if (Convert.ToBoolean(Wet8.MCValue) == true)
{
WetChoose4 = 8;
}
#endregion
#region 按钮选择
if (StartMetage1 == runtime.Sender)
{
float value;
if (float.TryParse(Convert.ToString(SetWaterValue1.MCValue), out value))
{
if (MessageBox.Show("冷水称A确认开始称量", "称量确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
MesnacServiceManager.Instance.LoggingService.Info("冷水称A开始称量");
}
else
{
MesnacServiceManager.Instance.LoggingService.Info("冷水称A输入数值的格式有误");
MessageBox.Show("输入数值的格式有误!");
return;
}
}
if (StopMetage1 == runtime.Sender)
{
MesnacServiceManager.Instance.LoggingService.Info("冷水称A称量已手动停止");
MessageBox.Show("称量已停止!");
}
if (StartMetage2 == runtime.Sender)
{
float value;
if (float.TryParse(Convert.ToString(SetWaterValue2.MCValue), out value))
{
if (MessageBox.Show("热水称A确认开始称量", "称量确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
MesnacServiceManager.Instance.LoggingService.Info("热水称A开始称量");
}
else
{
MesnacServiceManager.Instance.LoggingService.Info("热水称A输入数值的格式有误");
MessageBox.Show("输入数值的格式有误!");
return;
}
}
if (StopMetage2 == runtime.Sender)
{
MesnacServiceManager.Instance.LoggingService.Info("热水称A称量已手动停止");
MessageBox.Show("称量已停止!");
}
if (StartMetage3 == runtime.Sender)
{
float value;
if (float.TryParse(Convert.ToString(SetWaterValue3.MCValue), out value))
{
if (MessageBox.Show("冷水称B确认开始称量", "称量确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
MesnacServiceManager.Instance.LoggingService.Info("冷水称B开始称量");
}
else
{
MesnacServiceManager.Instance.LoggingService.Info("冷水称B输入数值的格式有误");
MessageBox.Show("输入数值的格式有误!");
return;
}
}
if (StopMetage3 == runtime.Sender)
{
MesnacServiceManager.Instance.LoggingService.Info("冷水称B称量已手动停止");
MessageBox.Show("称量已停止!");
}
if (StartMetage4 == runtime.Sender)
{
float value;
if (float.TryParse(Convert.ToString(SetWaterValue4.MCValue), out value))
{
if (MessageBox.Show("热水称B确认开始称量", "称量确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
MesnacServiceManager.Instance.LoggingService.Info("热水称B开始称量");
}
else
{
MesnacServiceManager.Instance.LoggingService.Info("热水称B输入数值的格式有误");
MessageBox.Show("输入数值的格式有误!");
return;
}
}
if (StopMetage4 == runtime.Sender)
{
MesnacServiceManager.Instance.LoggingService.Info("热水称B称量已手动停止");
MessageBox.Show("称量已停止!");
}
if (WaterOut1 == runtime.Sender)
{
if (MessageBox.Show("冷水称A确认开始排水", "排水确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
MesnacServiceManager.Instance.LoggingService.Info("冷水称A开始排水");
switch (GelChooseA)
{
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
default: break;
}
}
if (WaterOut2 == runtime.Sender)
{
if (MessageBox.Show("热水称A确认开始排水", "排水确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
MesnacServiceManager.Instance.LoggingService.Info("热水称A开始排水");
switch (GelChooseA)
{
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
default: break;
}
}
if (WaterOut3 == runtime.Sender)
{
if (MessageBox.Show("冷水称B确认开始排水", "排水确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
MesnacServiceManager.Instance.LoggingService.Info("冷水称B开始排水");
switch (GelChooseB)
{
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
default: break;
}
}
if (WaterOut4 == runtime.Sender)
{
if (MessageBox.Show("热水称B确认开始排水", "排水确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
MesnacServiceManager.Instance.LoggingService.Info("热水称B开始排水");
switch (GelChooseB)
{
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
default: break;
}
}
if (SpiralOn1 == runtime.Sender)
{
float value;
if (float.TryParse(Convert.ToString(SetSpiralValue1.MCValue), out value))
{
if (MessageBox.Show("螺旋1确认启动", "螺旋启动确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
MesnacServiceManager.Instance.LoggingService.Info("螺旋1启动");
}
else
{
MesnacServiceManager.Instance.LoggingService.Info("螺旋1输入数值的格式有误");
MessageBox.Show("输入数值的格式有误!");
return;
}
switch (WetChoose1)
{
case 1:
break;
case 2:
break;
default: break;
}
}
if (SpiralOn2 == runtime.Sender)
{
float value;
if (float.TryParse(Convert.ToString(SetSpiralValue2.MCValue), out value))
{
if (MessageBox.Show("螺旋2确认启动", "螺旋启动确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
MesnacServiceManager.Instance.LoggingService.Info("螺旋2启动");
}
else
{
MesnacServiceManager.Instance.LoggingService.Info("螺旋2输入数值的格式有误");
MessageBox.Show("输入数值的格式有误!");
return;
}
switch (WetChoose2)
{
case 3:
break;
case 4:
break;
default: break;
}
}
if (SpiralOn3 == runtime.Sender)
{
float value;
if (float.TryParse(Convert.ToString(SetSpiralValue3.MCValue), out value))
{
if (MessageBox.Show("螺旋3确认启动", "螺旋启动确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
MesnacServiceManager.Instance.LoggingService.Info("螺旋3启动");
}
else
{
MesnacServiceManager.Instance.LoggingService.Info("螺旋3输入数值的格式有误");
MessageBox.Show("输入数值的格式有误!");
return;
}
switch (WetChoose3)
{
case 5:
break;
case 6:
break;
default: break;
}
}
if (SpiralOn4 == runtime.Sender)
{
float value;
if (float.TryParse(Convert.ToString(SetSpiralValue4.MCValue), out value))
{
if (MessageBox.Show("螺旋4确认启动", "螺旋启动确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
MesnacServiceManager.Instance.LoggingService.Info("螺旋4启动");
}
else
{
MesnacServiceManager.Instance.LoggingService.Info("螺旋4输入数值的格式有误");
MessageBox.Show("输入数值的格式有误!");
return;
}
switch (WetChoose4)
{
case 7:
break;
case 8:
break;
default: break;
}
}
#endregion
}
private IBaseControl GetBaseControl(string name)
{
return McControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey == name).FirstOrDefault().BaseControl;
}
}
}