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/ForceWaterControl.cs

333 lines
13 KiB
C#

using DataBlockHelper.DBHelpers;
using DataBlockHelper.Entity.DB2106Entity;
using HslCommunication.Instrument.DLT;
using Mesnac.Action.Base;
using Mesnac.Action.ChemicalWeighing.FreeDb;
using Mesnac.Action.ChemicalWeighing.MainDetailControl.Entity;
using Mesnac.Basic;
using Mesnac.Controls.ChemicalWeighing;
using Mesnac.Controls.Default;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mesnac.Action.ChemicalWeighing.ManualControl
{
public class ForceWaterControl : ChemicalWeighingAction, IAction
{
FHslSwitchEntity HslSwitchE = new FHslSwitchEntity();
FMCTextBoxEntity MCTextBoxE = new FMCTextBoxEntity();
FMCButtonEntity ButtonE = new FMCButtonEntity();
FMCRadioButtonEntity RadioButtonE = new FMCRadioButtonEntity();
DB2119Helper DB2119 = new DB2119Helper();
private List<Control> Controls;
Timer timer;
private byte GelChooseA;
private byte GelChooseB;
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须要调用
Controls = GetAllControls();
SetAllControls();
BottomSelect(runtime);
HslSwitchE.ForceControlHA.OnSwitchChanged += ForceControl_OnSwitchChanged;
HslSwitchE.ForceControlCA.OnSwitchChanged += ForceControl_OnSwitchChanged;
HslSwitchE.ForceControlHB.OnSwitchChanged += ForceControl_OnSwitchChanged;
HslSwitchE.ForceControlCB.OnSwitchChanged += ForceControl_OnSwitchChanged;
StateRefresh(new object(), new EventArgs());
//timer = new Timer();
//timer.Interval = 1000;
//timer.Enabled = true;
//timer.Tick += new EventHandler(StateRefresh);//添加事件
}
private void ForceControl_OnSwitchChanged(object obj, bool state)
{
if(state)
{
if (MessageBox.Show("是否要打开强制排水模式?", "强制模式启动确认",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
}
HslSwitch hslSwitch = obj as HslSwitch;
string name = hslSwitch.Name;
switch (name)
{
case "ForceControlHA":
Db2119WriteHelper.AddHaAddForceOn(state);
break;
case "ForceControlCA":
Db2119WriteHelper.AddCaAddForceOn(state);
break;
case "ForceControlHB":
Db2119WriteHelper.AddHbAddForceOn(state);
break;
case "ForceControlCB":
Db2119WriteHelper.AddCbAddForceOn(state);
break;
default: break;
}
DefaultSwitch(hslSwitch);
}
private void StateRefresh(object sender, EventArgs e)
{
HslSwitchE.ForceControlHA.SwitchStatus = DB2119.Force_HA.forceOn;
HslSwitchE.ForceControlCA.SwitchStatus = DB2119.Force_CA.forceOn;
HslSwitchE.ForceControlHB.SwitchStatus = DB2119.Force_HB.forceOn;
HslSwitchE.ForceControlCB.SwitchStatus = DB2119.Force_CB.forceOn;
}
private void BottomSelect(RuntimeParameter runtime)
{
SingleSelect();
if (ButtonE.StartMetage1 == runtime.Sender)
{
if (!DB2119.Force_CA.forceOn)
{
MessageBox.Show("冷水称A强制控制按钮未打开");
return;
}
if (MessageBox.Show("确认向冷水称A补充", "强制模式启动确认",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
Db2119WriteHelper.AddCaAddValue(Convert.ToInt16(MCTextBoxE.SetWaterValue1.Text));
Db2119WriteHelper.AddCaAddForceBin(GelChooseA);
Db2119WriteHelper.AddCaAddStartIn(true);
ManualLogControl("冷水称A强制补充", Convert.ToInt16(MCTextBoxE.SetWaterValue1.Text), GelChooseA);
MessageBox.Show("冷水称A强制补充");
}
if (ButtonE.StartMetage2 == runtime.Sender)
{
if (!DB2119.Force_HA.forceOn)
{
MessageBox.Show("热水称A强制控制按钮未打开");
return;
}
if (MessageBox.Show("确认向热水称A补充", "强制模式启动确认",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
Db2119WriteHelper.AddHaAddValue(Convert.ToInt16(MCTextBoxE.SetWaterValue2.Text));
Db2119WriteHelper.AddHaAddForceBin(GelChooseA);
Db2119WriteHelper.AddHaAddStartIn(true);
ManualLogControl("热水称A强制补充", Convert.ToInt16(MCTextBoxE.SetWaterValue2.Text), GelChooseA);
MessageBox.Show("热水称A强制补充");
}
if (ButtonE.StartMetage3 == runtime.Sender)
{
if (!DB2119.Force_CB.forceOn)
{
MessageBox.Show("冷水称B强制控制按钮未打开");
return;
}
if (MessageBox.Show("确认向冷水称B补充", "强制模式启动确认",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
Db2119WriteHelper.AddCbAddValue(Convert.ToInt16(MCTextBoxE.SetWaterValue3.Text));
Db2119WriteHelper.AddCbAddForceBin(GelChooseB);
Db2119WriteHelper.AddCbAddStartIn(true);
ManualLogControl("冷水称B强制补充", Convert.ToInt16(MCTextBoxE.SetWaterValue3.Text), GelChooseB + 4);
MessageBox.Show("冷水称B强制补充");
}
if (ButtonE.StartMetage4 == runtime.Sender)
{
if (!DB2119.Force_HB.forceOn)
{
MessageBox.Show("热水称B强制控制按钮未打开");
return;
}
if (MessageBox.Show("确认向热水称B补充", "强制模式启动确认",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
Db2119WriteHelper.AddHbAddValue(Convert.ToInt16(MCTextBoxE.SetWaterValue4.Text));
Db2119WriteHelper.AddHbAddForceBin(GelChooseB);
Db2119WriteHelper.AddHbAddStartIn(true);
ManualLogControl("热水称B强制补充", Convert.ToInt16(MCTextBoxE.SetWaterValue4.Text), GelChooseB + 4);
MessageBox.Show("热水称B强制补充");
}
if (ButtonE.StartOut1 == runtime.Sender)
{
if (!DB2119.Force_CA.forceOn)
{
MessageBox.Show("冷水称A强制控制按钮未打开");
return;
}
if (MessageBox.Show("确认向" + GelChooseA + "排水?", "强制模式启动确认",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
Db2119WriteHelper.AddCaAddRemainValue(Convert.ToInt16(MCTextBoxE.StayWaterValue1.Text));
Db2119WriteHelper.AddCaAddForceBin(GelChooseA);
Db2119WriteHelper.AddCaAddStartOut(true);
ManualLogControl("冷水称A强制排水", Convert.ToInt16(MCTextBoxE.StayWaterValue1.Text), GelChooseA);
MessageBox.Show("冷水称A强制排水");
}
if (ButtonE.StartOut2 == runtime.Sender)
{
if (!DB2119.Force_HA.forceOn)
{
MessageBox.Show("热水称A强制控制按钮未打开");
return;
}
if (MessageBox.Show("确认向" + GelChooseA + "排水?", "强制模式启动确认",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
Db2119WriteHelper.AddHaAddRemainValue(Convert.ToInt16(MCTextBoxE.StayWaterValue2.Text));
Db2119WriteHelper.AddHaAddForceBin(GelChooseA);
Db2119WriteHelper.AddHaAddStartOut(true);
ManualLogControl("热水称A强制排水", Convert.ToInt16(MCTextBoxE.StayWaterValue2.Text), GelChooseA);
MessageBox.Show("热水称A强制排水");
}
if (ButtonE.StartOut3 == runtime.Sender)
{
if (!DB2119.Force_CB.forceOn)
{
MessageBox.Show("冷水称B强制控制按钮未打开");
return;
}
if (MessageBox.Show("确认向" + GelChooseB + 4 + "排水?", "强制模式启动确认",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
Db2119WriteHelper.AddCbAddRemainValue(Convert.ToInt16(MCTextBoxE.StayWaterValue3.Text));
Db2119WriteHelper.AddCbAddForceBin(GelChooseB);
Db2119WriteHelper.AddCbAddStartOut(true);
ManualLogControl("冷水称B强制排水", Convert.ToInt16(MCTextBoxE.StayWaterValue3.Text), GelChooseB + 4);
MessageBox.Show("冷水称B强制排水");
}
if (ButtonE.StartOut4 == runtime.Sender)
{
if (!DB2119.Force_HB.forceOn)
{
MessageBox.Show("热水称B强制控制按钮未打开");
return;
}
if (MessageBox.Show("确认向" + GelChooseB + 4 + "排水?", "强制模式启动确认",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
Db2119WriteHelper.AddHbAddRemainValue(Convert.ToInt16(MCTextBoxE.StayWaterValue4.Text));
Db2119WriteHelper.AddHbAddForceBin(GelChooseB);
Db2119WriteHelper.AddHbAddStartOut(true);
ManualLogControl("热水称B强制排水", Convert.ToInt16(MCTextBoxE.StayWaterValue4.Text), GelChooseB + 4);
MessageBox.Show("热水称B强制排水");
}
}
private void DefaultSwitch(HslSwitch hslSwitch)
{
string status = hslSwitch.SwitchStatus ? "强制状态开" : "强制状态关";
hslSwitch.Text = status;
}
private void SingleSelect()
{
if (Convert.ToBoolean(RadioButtonE.Gel1.MCValue) == true)
{
GelChooseA = 1;
}
if (Convert.ToBoolean(RadioButtonE.Gel2.MCValue) == true)
{
GelChooseA = 2;
}
if (Convert.ToBoolean(RadioButtonE.Gel3.MCValue) == true)
{
GelChooseA = 3;
}
if (Convert.ToBoolean(RadioButtonE.Gel4.MCValue) == true)
{
GelChooseA = 4;
}
if (Convert.ToBoolean(RadioButtonE.Gel5.MCValue) == true)
{
GelChooseB = 1;
}
if (Convert.ToBoolean(RadioButtonE.Gel6.MCValue) == true)
{
GelChooseB = 2;
}
if (Convert.ToBoolean(RadioButtonE.Gel7.MCValue) == true)
{
GelChooseB = 3;
}
if (Convert.ToBoolean(RadioButtonE.Gel8.MCValue) == true)
{
GelChooseB = 4;
}
}
private void SetAllControls()
{
ControlsHelper.ControlImport<HslSwitch>(HslSwitchE, Controls);
ControlsHelper.ControlImport<MCTextBox>(MCTextBoxE, Controls);
ControlsHelper.ControlImport<MCButton>(ButtonE, Controls);
ControlsHelper.ControlImport<MCRadioButton>(RadioButtonE, Controls);
}
/// <summary>
/// 日志插入
/// </summary>
/// <param name="logName">日志内容</param>
/// <param name="value">值</param>
/// <param name="valuekind">值类型 0无 1水称设定值 2水称称量值 3螺旋设定值 4螺旋称量值</param>
/// <param name="deviceno">设备编号</param>
/// <param name="devicekind">设备类型 0无 1水称 2螺旋</param>
public void ManualLogControl(string logName, int value, int deviceno)
{
var Log = new ManualLogEntity()
{
logtext = logName,
logtime = DateTime.Now,
userid = string.IsNullOrWhiteSpace(UserInfo.Instance.UserName) ? "Edit" : UserInfo.Instance.UserName,
value = value,
deviceno = deviceno,
devicekind = 1,
valuekind = 0,
createdate = DateTime.Now.ToString("yyyyMMdd")
};
FreeSqlUnit.Instance.Insert(Log).ExecuteIdentity();
}
}
}