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/AutoControl/InitAction.cs

298 lines
11 KiB
C#

using DataBlockHelper.DBHelpers;
using DevExpress.DataAccess.Wizard.Presenters;
using DevExpress.XtraEditors.Filtering.Templates;
using Mesnac.Action.Base;
using Mesnac.Action.ChemicalWeighing.AutoControl.DB;
using Mesnac.Action.ChemicalWeighing.AutoControl.Entity;
using Mesnac.Action.ChemicalWeighing.FreeDb;
using Mesnac.Action.ChemicalWeighing.LjMixManager;
using Mesnac.Action.ChemicalWeighing.LjPlanning;
using Mesnac.Controls.Base;
using Mesnac.Controls.Default;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using IAction = Mesnac.Action.Base.IAction;
namespace Mesnac.Action.ChemicalWeighing.AutoControl
{
public class InitAction : ChemicalWeighingAction, IAction
{
private List<Control> McControls;
Color backColor = Color.Transparent;
MCTextBoxEntity TextE = new MCTextBoxEntity();
MCLabelEntity LabelE = new MCLabelEntity();
MCComboBoxEntity ComboE = new MCComboBoxEntity();
MCRadioButtonEntity RadioE = new MCRadioButtonEntity();
public Timer timer;
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须要调用
McControls = GetAllControls();
ControlsHelper.ControlImport<MCTextBox>(TextE, McControls);
// McControls.FirstOrDefault(x => x.Name == name)
//TextE.HALeftOrRight = McControls.FirstOrDefault(x => x.Name == "HALeftOrRight") as MCCombobox;
//TextE.HBLeftOrRight = McControls.FirstOrDefault(x => x.Name == "HBLeftOrRight") as MCCombobox;
//TextE.CALeftOrRight = McControls.FirstOrDefault(x => x.Name == "CALeftOrRight") as MCCombobox;
//TextE.CBLeftOrRight = McControls.FirstOrDefault(x => x.Name == "CBLeftOrRight") as MCCombobox;
ControlsHelper.ControlImport<MCCombobox>(ComboE, McControls);
ControlsHelper.ControlImport<MCLabel>(LabelE, McControls);
ControlsHelper.ControlImport<MCRadioButton>(RadioE, McControls);
ControlInit();
RadioE.Line1.CheckedChanged += Mcradion_CheckedChanged;
RadioE.Line2.CheckedChanged += Mcradion_CheckedChanged;
RadioE.Line3.CheckedChanged += Mcradion_CheckedChanged;
RadioE.Line4.CheckedChanged += Mcradion_CheckedChanged;
RadioE.Line5.CheckedChanged += Mcradion_CheckedChanged;
RadioE.Line6.CheckedChanged += Mcradion_CheckedChanged;
RadioE.Line7.CheckedChanged += Mcradion_CheckedChanged;
RadioE.Line8.CheckedChanged += Mcradion_CheckedChanged;
RadioE.Dry1.CheckedChanged += DMcradion_CheckedChanged;
RadioE.Dry2.CheckedChanged += DMcradion_CheckedChanged;
RadioE.Dry3.CheckedChanged += DMcradion_CheckedChanged;
RadioE.Dry4.CheckedChanged += DMcradion_CheckedChanged;
RadioE.Line1.MCValue = true;
RadioE.Dry1.MCValue = true;
timer = new Timer();
timer.Interval = 1000;
timer.Enabled = true;
timer.Tick += new EventHandler(StateRefresh);//添加事件
}
#region 前端Timer状态刷新
private void StateRefresh(object sender, EventArgs e)
{
if (GetAllDbMCControlsByOption(DbOptionTypes.QueryAndModify).Count == 0)
{
timer.Stop();
timer.Dispose();
}
DB2105Helper dB2105Helper = new DB2105Helper();
var startJob = dB2105Helper.GetStartJob;
LabelE.State1.MCValue = ConvertOnOff(startJob[0].Val);
LabelE.State2.MCValue = ConvertOnOff(startJob[1].Val);
LabelE.State3.MCValue = ConvertOnOff(startJob[2].Val);
LabelE.State4.MCValue = ConvertOnOff(startJob[3].Val);
LabelE.State5.MCValue = ConvertOnOff(startJob[4].Val);
LabelE.State6.MCValue = ConvertOnOff(startJob[5].Val);
LabelE.State7.MCValue = ConvertOnOff(startJob[6].Val);
LabelE.State8.MCValue = ConvertOnOff(startJob[7].Val);
LabelE.State1.BackColor = ConvertColor(startJob[0].Val);
LabelE.State2.BackColor = ConvertColor(startJob[1].Val);
LabelE.State3.BackColor = ConvertColor(startJob[2].Val);
LabelE.State4.BackColor = ConvertColor(startJob[3].Val);
LabelE.State5.BackColor = ConvertColor(startJob[4].Val);
LabelE.State6.BackColor = ConvertColor(startJob[5].Val);
LabelE.State7.BackColor = ConvertColor(startJob[6].Val);
LabelE.State8.BackColor = ConvertColor(startJob[7].Val);
var rd = Db3000Helper.ReadModel();
if (rd[ControlsHelper.SingleSelect(RadioE) - 1])
{
LabelE.RepairState.MCValue = "开";
}
else
{
LabelE.RepairState.MCValue = "关";
}
}
private string ConvertOnOff(bool state)
{
if (state)
{
return "启动";
}
else
{
return "停止";
}
}
private Color ConvertColor(bool state)
{
if (state)
{
return Color.LightGreen;
}
else
{
return Color.Transparent;
}
}
#endregion
#region PLC读数 刷新控件
private void Mcradion_CheckedChanged(object sender, EventArgs e)
{
MCRadioButton mCRadio = sender as MCRadioButton;
RadioE.Line1.BackColor = backColor;
RadioE.Line2.BackColor = backColor;
RadioE.Line3.BackColor = backColor;
RadioE.Line4.BackColor = backColor;
RadioE.Line5.BackColor = backColor;
RadioE.Line6.BackColor = backColor;
RadioE.Line7.BackColor = backColor;
RadioE.Line8.BackColor = backColor;
mCRadio.BackColor = Color.LightSkyBlue;
int select = ControlsHelper.SingleSelect(RadioE);
ControlsHelper.GWInit(select, ComboE, TextE);
switch (select)
{
case 1:
case 2:
RadioE.Dry1.MCValue = true; break;
case 3:
case 4:
RadioE.Dry2.MCValue = true; break;
case 5:
case 6:
RadioE.Dry3.MCValue = true; break;
case 7:
case 8:
RadioE.Dry4.MCValue = true; break;
default: break;
}
}
private void DMcradion_CheckedChanged(object sender, EventArgs e)
{
MCRadioButton mCRadio = sender as MCRadioButton;
RadioE.Dry1.BackColor = backColor;
RadioE.Dry2.BackColor = backColor;
RadioE.Dry3.BackColor = backColor;
RadioE.Dry4.BackColor = backColor;
mCRadio.BackColor = Color.LightSkyBlue;
ControlsHelper.DInit(ControlsHelper.DrySelect(RadioE), ComboE, TextE);
}
/// <summary>
/// 控件从Plc初始化
/// </summary>
public void ControlInit()
{
ComboE.ChooseMaterial1.DataSource = StockMaterrialDbHelp.GetSiloMaterrial();
ComboE.ChooseMaterial2.DataSource = StockMaterrialDbHelp.GetSiloMaterrial();
DB2104Helper waterData = new DB2104Helper();
TextE.ColdValueA.MCValue = waterData.GetAColWater.Set;
TextE.ColdValueB.MCValue = waterData.GetBColWater.Set;
TextE.HotValueA.MCValue = waterData.GetAHotWater.Set;
TextE.HotValueB.MCValue = waterData.GetBHotWater.Set;
TextE.ColdToleranceA.MCValue = waterData.GetAColWater.Tolerance;
TextE.ColdToleranceB.MCValue = waterData.GetBColWater.Tolerance;
TextE.HotToleranceA.MCValue = waterData.GetAHotWater.Tolerance;
TextE.HotToleranceB.MCValue = waterData.GetBHotWater.Tolerance;
ComboE.DryM1.DataSource = StockMaterrialDbHelp.GetDryerMaterrial();
ComboE.DryM2.DataSource = StockMaterrialDbHelp.GetDryerMaterrial();
ComboE.DryM3.DataSource = StockMaterrialDbHelp.GetDryerMaterrial();
ComboE.DryM4.DataSource = StockMaterrialDbHelp.GetDryerMaterrial();
ComboE.DryM5.DataSource = StockMaterrialDbHelp.GetDryerMaterrial();
ComboE.DryM6.DataSource = StockMaterrialDbHelp.GetDryerMaterrial();
ComboE.DryM7.DataSource = StockMaterrialDbHelp.GetDryerMaterrial();
ComboE.DryM8.DataSource = StockMaterrialDbHelp.GetDryerMaterrial();
ComboE.DryM9.DataSource = StockMaterrialDbHelp.GetDryerMaterrial();
ComboE.DryM10.DataSource = StockMaterrialDbHelp.GetDryerMaterrial();
ComboE.DryM11.DataSource = StockMaterrialDbHelp.GetDryerMaterrial();
ComboE.DryM12.DataSource = StockMaterrialDbHelp.GetDryerMaterrial();
string[] s = new string[8];
for (int i = 1; i <= 8; i++)
{
s[i - 1] = "产线" + i;
}
ComboE.PasteChooseWet.DataSource = s;
string[] s1 = new string[4];
for (int i = 1; i <= 4; i++)
{
s1[i - 1] = "产线" + i;
}
ComboE.PasteChooseDry.DataSource = s1;
DB2104Helper dB2104Helper = new DB2104Helper();
var data = GetTable();
ComboE.CALeftOrRight.DataSource = data.Copy();
ComboE.HALeftOrRight.DataSource = data.Copy();
ComboE.CBLeftOrRight.DataSource = data.Copy();
ComboE.HBLeftOrRight.DataSource = data.Copy();
var ha = dB2104Helper.GetAHotWater;
TextE.HADeviation.MCValue = ha.differ;
ComboE.HALeftOrRight.MCValue = ha.stand;
var hb = dB2104Helper.GetBHotWater;
TextE.HBDeviation.MCValue = hb.differ;
ComboE.HBLeftOrRight.MCValue = hb.stand;
var ca = dB2104Helper.GetAColWater;
TextE.CADeviation.MCValue = ca.differ;
ComboE.CALeftOrRight.MCValue = ca.stand;
var cb = dB2104Helper.GetBColWater;
TextE.CBDeviation.MCValue = cb.differ;
ComboE.CBLeftOrRight.MCValue = cb.stand;
}
private DataTable GetTable()
{
DataTable dataTable = new System.Data.DataTable();
dataTable.Columns.Add("CmbValue", typeof(string));
dataTable.Columns.Add("CmbDisplay", typeof(string));
DataRow dr = dataTable.NewRow();
dr[0] = "0";
dr[1] = "无";
dataTable.Rows.Add(dr);
dr = dataTable.NewRow();
dr[0] = "1";
dr[1] = "左";
dataTable.Rows.Add(dr);
dr = dataTable.NewRow();
dr[0] = "2";
dr[1] = "右";
dataTable.Rows.Add(dr);
return dataTable;
}
#endregion
}
}