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

295 lines
12 KiB
C#

using DataBlockHelper.DBHelpers;
using DevExpress.DataAccess.Wizard.Presenters;
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.LjPlanning;
using Mesnac.Controls.Base;
using Mesnac.Controls.Default;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
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
{
GelerWeterControlsEntity ControlsEntity = new GelerWeterControlsEntity();
private List<Control> McControls;
Color backColor = Color.Transparent;
public Timer timer;
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须要调用
McControls = GetAllControls();
ControlImport();
ControlsEntity.Line1.MCValue = true;
ControlsEntity.Line1.BackColor = System.Drawing.Color.LightGreen;
ControlsEntity.Line1.CheckedChanged += Mcradion_CheckedChanged;
ControlsEntity.Line2.CheckedChanged += Mcradion_CheckedChanged;
ControlsEntity.Line3.CheckedChanged += Mcradion_CheckedChanged;
ControlsEntity.Line4.CheckedChanged += Mcradion_CheckedChanged;
ControlsEntity.Line5.CheckedChanged += Mcradion_CheckedChanged;
ControlsEntity.Line6.CheckedChanged += Mcradion_CheckedChanged;
ControlsEntity.Line7.CheckedChanged += Mcradion_CheckedChanged;
ControlsEntity.Line8.CheckedChanged += Mcradion_CheckedChanged;
ControlInitFromPLC();
timer = new Timer();
timer.Interval = 1000;
timer.Enabled = true;
timer.Tick += new EventHandler(StateRefresh);//添加事件
}
#region 前端状态
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;
ControlsEntity.State1.MCValue = ConvertOnOff(startJob[0].Val);
ControlsEntity.State2.MCValue = ConvertOnOff(startJob[1].Val);
ControlsEntity.State3.MCValue = ConvertOnOff(startJob[2].Val);
ControlsEntity.State4.MCValue = ConvertOnOff(startJob[3].Val);
ControlsEntity.State5.MCValue = ConvertOnOff(startJob[4].Val);
ControlsEntity.State6.MCValue = ConvertOnOff(startJob[5].Val);
ControlsEntity.State7.MCValue = ConvertOnOff(startJob[6].Val);
ControlsEntity.State8.MCValue = ConvertOnOff(startJob[7].Val);
ControlsEntity.State1.BackColor = ConvertColor(startJob[0].Val);
ControlsEntity.State2.BackColor = ConvertColor(startJob[1].Val);
ControlsEntity.State3.BackColor = ConvertColor(startJob[2].Val);
ControlsEntity.State4.BackColor = ConvertColor(startJob[3].Val);
ControlsEntity.State5.BackColor = ConvertColor(startJob[4].Val);
ControlsEntity.State6.BackColor = ConvertColor(startJob[5].Val);
ControlsEntity.State7.BackColor = ConvertColor(startJob[6].Val);
ControlsEntity.State8.BackColor = ConvertColor(startJob[7].Val);
var rd = Db3000Helper.ReadModel();
if (rd[SingleSelect() - 1])
{
ControlsEntity.RepairState.MCValue = "开";
}
else
{
ControlsEntity.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;
}
}
private void Mcradion_CheckedChanged(object sender, EventArgs e)
{
MCRadioButton mCRadio = sender as MCRadioButton;
ControlsEntity.Line1.BackColor = backColor;
ControlsEntity.Line2.BackColor = backColor;
ControlsEntity.Line3.BackColor = backColor;
ControlsEntity.Line4.BackColor = backColor;
ControlsEntity.Line5.BackColor = backColor;
ControlsEntity.Line6.BackColor = backColor;
ControlsEntity.Line7.BackColor = backColor;
ControlsEntity.Line8.BackColor = backColor;
mCRadio.BackColor = Color.LightSkyBlue;
}
#endregion
/// <summary>
/// 控件从Plc初始化
/// </summary>
private void ControlInitFromPLC()
{
ControlsEntity.ChooseMaterial1.DataSource = StockMaterrialDbHelp.GetSiloMaterrial();
ControlsEntity.ChooseMaterial2.DataSource = StockMaterrialDbHelp.GetSiloMaterrial();
var selected = FreeSqlUnit.Instance.Select<DeviceMaterrial>().
Where(x => x.DeviceId == SingleSelect()).ToList();
if(selected.Count != 0)
{
ControlsEntity.ChooseMaterial1.SelectedValue = selected[0].MaterrialId;
ControlsEntity.ChooseMaterial2.SelectedValue = selected[1].MaterrialId;
}
else
{
ControlsEntity.ChooseMaterial1.SelectedIndex = 0;
ControlsEntity.ChooseMaterial2.SelectedIndex = 0;
}
var getGelatG1 = LjPlanningPlcHelp.GetGelatG1;
var getWeterM1 = LjPlanningPlcHelp.GetWeterM1;
ControlsEntity.MaterialWeight1.MCValue = getGelatG1.RecipePlcViews[0].Set;
ControlsEntity.MaterialWeight2.MCValue = getGelatG1.RecipePlcViews[1].Set;
ControlsEntity.MaterialTolerance1.MCValue = getGelatG1.RecipePlcViews[0].Tolerance;
ControlsEntity.MaterialTolerance2.MCValue = getGelatG1.RecipePlcViews[1].Tolerance;
ControlsEntity.GelSpeedSet.MCValue = getGelatG1.RecipeSteps[0].MixSpeed;
ControlsEntity.GelPosTimeA.MCValue = getGelatG1.RecipeSteps[2].MixTemp;
ControlsEntity.GelNagTimeB.MCValue = getGelatG1.RecipeSteps[2].MixSpeed;
ControlsEntity.GelPosTimeC.MCValue = getGelatG1.RecipeSteps[2].MixTime;
ControlsEntity.GelWaterTime.MCValue = getGelatG1.RecipeSteps[4].MixTime;
ControlsEntity.GelWaitTime.MCValue = getGelatG1.RecipeSteps[6].MixTime;
ControlsEntity.GelCloseHeatTime.MCValue = getGelatG1.RecipeSteps[7].MixTime;
ControlsEntity.GelOutDelayTime.MCValue = getGelatG1.RecipeSteps[7].MixTemp;
ControlsEntity.WetDryWeight.MCValue = getWeterM1[1].SetValue;
ControlsEntity.WetMixTime.MCValue = getWeterM1[2].MixTime;
ControlsEntity.WetOutDelayTime.MCValue = getWeterM1[4].MixTime;
}
#region 帮助类
/// <summary>
/// 单选选择
/// </summary>
/// <returns>返回单选的产线号 如果未选择返回0</returns>
private int SingleSelect()
{
int no = 0;
if (Convert.ToBoolean(ControlsEntity.Line1.MCValue))
{
no= 1;
}
else if (Convert.ToBoolean(ControlsEntity.Line2.MCValue))
{
no= 2;
}
else if (Convert.ToBoolean(ControlsEntity.Line3.MCValue))
{
no= 3;
}
else if (Convert.ToBoolean(ControlsEntity.Line4.MCValue))
{
no= 4;
}
else if (Convert.ToBoolean(ControlsEntity.Line5.MCValue))
{
no= 5;
}
else if (Convert.ToBoolean(ControlsEntity.Line6.MCValue))
{
no= 6;
}
else if (Convert.ToBoolean(ControlsEntity.Line7.MCValue))
{
no= 7;
}
else if (Convert.ToBoolean(ControlsEntity.Line8.MCValue))
{
no= 8;
}
return no;
}
/// <summary>
/// 控件导入
/// </summary>
private void ControlImport()
{
ControlsEntity.Line1 = GetMCRadioButtonControl("Line1");
ControlsEntity.Line2 = GetMCRadioButtonControl("Line2");
ControlsEntity.Line3 = GetMCRadioButtonControl("Line3");
ControlsEntity.Line4 = GetMCRadioButtonControl("Line4");
ControlsEntity.Line5 = GetMCRadioButtonControl("Line5");
ControlsEntity.Line6 = GetMCRadioButtonControl("Line6");
ControlsEntity.Line7 = GetMCRadioButtonControl("Line7");
ControlsEntity.Line8 = GetMCRadioButtonControl("Line8");
ControlsEntity.State1 = GetBaseControl("State1") as MCLabel;
ControlsEntity.State2 = GetBaseControl("State2") as MCLabel;
ControlsEntity.State3 = GetBaseControl("State3") as MCLabel;
ControlsEntity.State4 = GetBaseControl("State4") as MCLabel;
ControlsEntity.State5 = GetBaseControl("State5") as MCLabel;
ControlsEntity.State6 = GetBaseControl("State6") as MCLabel;
ControlsEntity.State7 = GetBaseControl("State7") as MCLabel;
ControlsEntity.State8 = GetBaseControl("State8") as MCLabel;
ControlsEntity.RepairState = GetBaseControl("RepairState") as MCLabel;
ControlsEntity.ChooseMaterial1 = GetBaseControl("ChooseMaterial1") as MCCombobox;
ControlsEntity.ChooseMaterial2 = GetBaseControl("ChooseMaterial2") as MCCombobox;
ControlsEntity.MaterialWeight1 = GetBaseControl("MaterialWeight1");
ControlsEntity.MaterialWeight2 = GetBaseControl("MaterialWeight2");
ControlsEntity.MaterialTolerance1 = GetBaseControl("MaterialTolerance1");
ControlsEntity.MaterialTolerance2 = GetBaseControl("MaterialTolerance2");
ControlsEntity.GelSpeedSet = GetBaseControl("GelSpeedSet");
ControlsEntity.GelPosTimeA = GetBaseControl("GelPosTimeA");
ControlsEntity.GelNagTimeB = GetBaseControl("GelNagTimeB");
ControlsEntity.GelPosTimeC = GetBaseControl("GelPosTimeC");
ControlsEntity.GelWaterTime = GetBaseControl("GelWaterTime");
ControlsEntity.GelWaitTime = GetBaseControl("GelWaitTime");
ControlsEntity.GelCloseHeatTime = GetBaseControl("GelCloseHeatTime");
ControlsEntity.GelOutDelayTime = GetBaseControl("GelOutDelayTime");
ControlsEntity.WetDryWeight = GetBaseControl("WetDryWeight");
ControlsEntity.WetMixTime = GetBaseControl("WetMixTime");
ControlsEntity.WetOutDelayTime = GetBaseControl("WetOutDelayTime");
}
private IBaseControl GetBaseControl(string name)
{
return McControls.First(x => x.Name == name) as IBaseControl;
}
private MCCombobox GetComboBoxControl(string name)
{
return McControls.First(x => x.Name == name) as MCCombobox;
}
private MCRadioButton GetMCRadioButtonControl(string name)
{
return McControls.First(x => x.Name == name) as MCRadioButton;
}
#endregion
}
}