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

356 lines
14 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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.Action.ChemicalWeighing.Report.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();
DB2105Helper DB2105 = new DB2105Helper();
private List<Control> Controls;
Timer timer;
private byte GelChooseA;
private byte GelChooseB;
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须要调用
Controls = GetAllControls();
SetAllControls();
StateRefresh();
HslSwitchE.ForceControlHA.OnSwitchChanged += ForceControl_OnSwitchChanged;
HslSwitchE.ForceControlCA.OnSwitchChanged += ForceControl_OnSwitchChanged;
HslSwitchE.ForceControlHB.OnSwitchChanged += ForceControl_OnSwitchChanged;
HslSwitchE.ForceControlCB.OnSwitchChanged += ForceControl_OnSwitchChanged;
BottomSelect(runtime);
//timer = new Timer();
//timer.Interval = 1000;
//timer.Enabled = true;
//timer.Tick += new EventHandler(StateRefresh);//添加事件
}
private void ForceControl_OnSwitchChanged(object obj, bool state)
{
DB2105 = new DB2105Helper();
HslSwitch hslSwitch = obj as HslSwitch;
if (state)
{
if (MessageBox.Show("是否要打开强制排水模式?", "强制模式启动确认",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
HslSwitch hs = obj as HslSwitch;
hs.SwitchStatus = false;
return;
}
}
string name = hslSwitch.Name;
switch (name)
{
case "ForceControlHA":
DB2105WriteHelper.AddHaAddForceOn(state);
break;
case "ForceControlCA":
DB2105WriteHelper.AddCaAddForceOn(state);
break;
case "ForceControlHB":
DB2105WriteHelper.AddHbAddForceOn(state);
break;
case "ForceControlCB":
DB2105WriteHelper.AddCbAddForceOn(state);
break;
default: break;
}
DefaultSwitch(hslSwitch, state);
}
private void StateRefresh()
{
if (HslSwitchE.ForceControlHA.SwitchStatus != DB2105.Force_HA.forceOn)
{
HslSwitchE.ForceControlHA.SwitchStatus = DB2105.Force_HA.forceOn;
}
if (HslSwitchE.ForceControlCA.SwitchStatus != DB2105.Force_CA.forceOn)
{
HslSwitchE.ForceControlCA.SwitchStatus = DB2105.Force_CA.forceOn;
}
if (HslSwitchE.ForceControlHB.SwitchStatus != DB2105.Force_HB.forceOn)
{
HslSwitchE.ForceControlHB.SwitchStatus = DB2105.Force_HB.forceOn;
}
if (HslSwitchE.ForceControlCB.SwitchStatus != DB2105.Force_CB.forceOn)
{
HslSwitchE.ForceControlCB.SwitchStatus = DB2105.Force_CB.forceOn;
}
DefaultSwitch(HslSwitchE.ForceControlHA, DB2105.Force_HA.forceOn);
DefaultSwitch(HslSwitchE.ForceControlCA, DB2105.Force_CA.forceOn);
DefaultSwitch(HslSwitchE.ForceControlHB, DB2105.Force_HB.forceOn);
DefaultSwitch(HslSwitchE.ForceControlCB, DB2105.Force_CB.forceOn);
}
private void BottomSelect(RuntimeParameter runtime)
{
DB2105 = new DB2105Helper();
SingleSelect();
if (ButtonE.StartMetage1 == runtime.Sender)
{
if (!DB2105.Force_CA.forceOn)
{
MessageBox.Show("冷水称A强制控制按钮未打开");
return;
}
if (MessageBox.Show("确认向冷水称A补充", "强制模式启动确认",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
DB2105WriteHelper.AddCaAddValue(Convert.ToInt16(MCTextBoxE.SetWaterValue1.Text));
DB2105WriteHelper.AddCaAddForceBin(GelChooseA);
DB2105WriteHelper.AddCaAddStartIn(true);
ManualLogControl("冷水称A强制补充", Convert.ToInt16(MCTextBoxE.SetWaterValue1.Text), GelChooseA);
MessageBox.Show("冷水称A强制补充");
}
if (ButtonE.StartMetage2 == runtime.Sender)
{
if (!DB2105.Force_HA.forceOn)
{
MessageBox.Show("热水称A强制控制按钮未打开");
return;
}
if (MessageBox.Show("确认向热水称A补充", "强制模式启动确认",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
DB2105WriteHelper.AddHaAddValue(Convert.ToInt16(MCTextBoxE.SetWaterValue2.Text));
DB2105WriteHelper.AddHaAddForceBin(GelChooseA);
DB2105WriteHelper.AddHaAddStartIn(true);
ManualLogControl("热水称A强制补充", Convert.ToInt16(MCTextBoxE.SetWaterValue2.Text), GelChooseA);
MessageBox.Show("热水称A强制补充");
}
if (ButtonE.StartMetage3 == runtime.Sender)
{
if (!DB2105.Force_CB.forceOn)
{
MessageBox.Show("冷水称B强制控制按钮未打开");
return;
}
if (MessageBox.Show("确认向冷水称B补充", "强制模式启动确认",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
DB2105WriteHelper.AddCbAddValue(Convert.ToInt16(MCTextBoxE.SetWaterValue3.Text));
DB2105WriteHelper.AddCbAddForceBin(GelChooseB);
DB2105WriteHelper.AddCbAddStartIn(true);
ManualLogControl("冷水称B强制补充", Convert.ToInt16(MCTextBoxE.SetWaterValue3.Text), GelChooseB + 4);
MessageBox.Show("冷水称B强制补充");
}
if (ButtonE.StartMetage4 == runtime.Sender)
{
if (!DB2105.Force_HB.forceOn)
{
MessageBox.Show("热水称B强制控制按钮未打开");
return;
}
if (MessageBox.Show("确认向热水称B补充", "强制模式启动确认",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
DB2105WriteHelper.AddHbAddValue(Convert.ToInt16(MCTextBoxE.SetWaterValue4.Text));
DB2105WriteHelper.AddHbAddForceBin(GelChooseB);
DB2105WriteHelper.AddHbAddStartIn(true);
ManualLogControl("热水称B强制补充", Convert.ToInt16(MCTextBoxE.SetWaterValue4.Text), GelChooseB + 4);
MessageBox.Show("热水称B强制补充");
}
if (ButtonE.StartOut1 == runtime.Sender)
{
if (!DB2105.Force_CA.forceOn)
{
MessageBox.Show("冷水称A强制控制按钮未打开");
return;
}
if (MessageBox.Show("确认向" + GelChooseA + "排水?", "强制模式启动确认",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
DB2105WriteHelper.AddCaAddRemainValue(Convert.ToInt16(MCTextBoxE.StayWaterValue1.Text));
DB2105WriteHelper.AddCaAddForceBin(GelChooseA);
DB2105WriteHelper.AddCaAddStartOut(true);
ManualLogControl("冷水称A强制排水", Convert.ToInt16(MCTextBoxE.StayWaterValue1.Text), GelChooseA);
MessageBox.Show("冷水称A强制排水");
}
if (ButtonE.StartOut2 == runtime.Sender)
{
if (!DB2105.Force_HA.forceOn)
{
MessageBox.Show("热水称A强制控制按钮未打开");
return;
}
if (MessageBox.Show("确认向" + GelChooseA + "排水?", "强制模式启动确认",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
DB2105WriteHelper.AddHaAddRemainValue(Convert.ToInt16(MCTextBoxE.StayWaterValue2.Text));
DB2105WriteHelper.AddHaAddForceBin(GelChooseA);
DB2105WriteHelper.AddHaAddStartOut(true);
ManualLogControl("热水称A强制排水", Convert.ToInt16(MCTextBoxE.StayWaterValue2.Text), GelChooseA);
MessageBox.Show("热水称A强制排水");
}
if (ButtonE.StartOut3 == runtime.Sender)
{
if (!DB2105.Force_CB.forceOn)
{
MessageBox.Show("冷水称B强制控制按钮未打开");
return;
}
if (MessageBox.Show("确认向" + GelChooseB + 4 + "排水?", "强制模式启动确认",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
DB2105WriteHelper.AddCbAddRemainValue(Convert.ToInt16(MCTextBoxE.StayWaterValue3.Text));
DB2105WriteHelper.AddCbAddForceBin(GelChooseB);
DB2105WriteHelper.AddCbAddStartOut(true);
ManualLogControl("冷水称B强制排水", Convert.ToInt16(MCTextBoxE.StayWaterValue3.Text), GelChooseB + 4);
MessageBox.Show("冷水称B强制排水");
}
if (ButtonE.StartOut4 == runtime.Sender)
{
if (!DB2105.Force_HB.forceOn)
{
MessageBox.Show("热水称B强制控制按钮未打开");
return;
}
if (MessageBox.Show("确认向" + GelChooseB + 4 + "排水?", "强制模式启动确认",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
DB2105WriteHelper.AddHbAddRemainValue(Convert.ToInt16(MCTextBoxE.StayWaterValue4.Text));
DB2105WriteHelper.AddHbAddForceBin(GelChooseB);
DB2105WriteHelper.AddHbAddStartOut(true);
ManualLogControl("热水称B强制排水", Convert.ToInt16(MCTextBoxE.StayWaterValue4.Text), GelChooseB + 4);
MessageBox.Show("热水称B强制排水");
}
}
private void DefaultSwitch(HslSwitch hslSwitch, bool state)
{
string status = state ? "强制状态开" : "强制状态关";
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 LjLogEntity()
{
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();
}
}
}