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

877 lines
29 KiB
C#

using DataBlockHelper;
using DataBlockHelper.DBHelpers;
using DataBlockHelper.Entity.DB2106Entity;
using DevExpress.Data.Extensions;
using HslCommunication;
using HslCommunication.Instrument.DLT;
using log4net;
using log4net.Config;
using Mesnac.Action.Base;
using Mesnac.Action.ChemicalWeighing.FreeDb;
1 year ago
using Mesnac.Action.ChemicalWeighing.InterfaceDocking;
using Mesnac.Action.ChemicalWeighing.InterfaceDocking.DockingEntity;
using Mesnac.Action.ChemicalWeighing.LjMaterial;
using Mesnac.Action.ChemicalWeighing.LjReport.OpenDoor;
using Mesnac.Action.ChemicalWeighing.MainDetailControl.Entity;
using Mesnac.Basic;
using Mesnac.Controls.Base;
using Mesnac.Controls.ChemicalWeighing;
using Mesnac.Controls.Default;
using Mesnac.Core.Service;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using Timer = System.Windows.Forms.Timer;
namespace Mesnac.Action.ChemicalWeighing.ManualControl
{
public class InitAction : ChemicalWeighingAction, IAction
{
DB2107Helper DB2107;
DB2119Helper DB2119;
DB2103Helper DB2103;
List<DbMCControl> McControllist; // InitData控件
List<DbMCControl> _McControllist; // Modify控件
List<Control> allControl;
1 year ago
HslSwitchEntity hslSwitchEntity;
DbMCControl materialGridControl;
Timer timer;
1 year ago
int no = 0;
Color backColor;
#region 控件变量
IBaseControl WaterActualValue1;
IBaseControl WaterActualValue2;
IBaseControl WaterActualValue3;
IBaseControl WaterActualValue4;
IBaseControl WaterMetValue1;
IBaseControl WaterMetValue2;
IBaseControl WaterMetValue3;
IBaseControl WaterMetValue4;
IBaseControl SpiralActValue1;
IBaseControl SpiralActValue2;
IBaseControl SpiralActValue3;
IBaseControl SpiralActValue4;
IBaseControl SpiralMetValue1;
IBaseControl SpiralMetValue2;
IBaseControl SpiralMetValue3;
IBaseControl SpiralMetValue4;
IBaseControl MetageState1;
IBaseControl MetageState2;
IBaseControl MetageState3;
IBaseControl MetageState4;
IBaseControl WaterOutState1;
IBaseControl WaterOutState2;
IBaseControl WaterOutState3;
IBaseControl WaterOutState4;
IBaseControl SpiralState1;
IBaseControl SpiralState2;
IBaseControl SpiralState3;
IBaseControl SpiralState4;
1 year ago
IBaseControl SetWaterValue1;
IBaseControl SetWaterValue2;
IBaseControl SetWaterValue3;
IBaseControl SetWaterValue4;
IBaseControl SetSpiralValue1;
IBaseControl SetSpiralValue2;
IBaseControl SetSpiralValue3;
IBaseControl SetSpiralValue4;
MCRadioButton Gel1;
MCRadioButton Gel2;
MCRadioButton Gel3;
MCRadioButton Gel4;
MCRadioButton Gel5;
MCRadioButton Gel6;
MCRadioButton Gel7;
MCRadioButton Gel8;
MCRadioButton Wet1;
MCRadioButton Wet2;
MCRadioButton Wet3;
MCRadioButton Wet4;
MCRadioButton Wet5;
MCRadioButton Wet6;
MCRadioButton Wet7;
MCRadioButton Wet8;
#endregion
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须要调用的
1 year ago
#region 控件获取
McControllist = GetAllDbMCControlsByOption(DbOptionTypes.InitData);
_McControllist = GetAllDbMCControlsByOption(DbOptionTypes.Modify);
allControl = GetAllControls();
FillHslSwitch();
WaterActualValue1 = GetBaseControl("WaterActualValue1");
WaterActualValue2 = GetBaseControl("WaterActualValue2");
WaterActualValue3 = GetBaseControl("WaterActualValue3");
WaterActualValue4 = GetBaseControl("WaterActualValue4");
WaterMetValue1 = GetBaseControl("WaterMetValue1");
WaterMetValue2 = GetBaseControl("WaterMetValue2");
WaterMetValue3 = GetBaseControl("WaterMetValue3");
WaterMetValue4 = GetBaseControl("WaterMetValue4");
SpiralActValue1 = GetBaseControl("SpiralActValue1");
SpiralActValue2 = GetBaseControl("SpiralActValue2");
SpiralActValue3 = GetBaseControl("SpiralActValue3");
SpiralActValue4 = GetBaseControl("SpiralActValue4");
SpiralMetValue1 = GetBaseControl("SpiralMetValue1");
SpiralMetValue2 = GetBaseControl("SpiralMetValue2");
SpiralMetValue3 = GetBaseControl("SpiralMetValue3");
SpiralMetValue4 = GetBaseControl("SpiralMetValue4");
MetageState1 = GetBaseControl("MetageState1");
MetageState2 = GetBaseControl("MetageState2");
MetageState3 = GetBaseControl("MetageState3");
MetageState4 = GetBaseControl("MetageState4");
WaterOutState1 = GetBaseControl("WaterOutState1");
WaterOutState2 = GetBaseControl("WaterOutState2");
WaterOutState3 = GetBaseControl("WaterOutState3");
WaterOutState4 = GetBaseControl("WaterOutState4");
SpiralState1 = GetBaseControl("SpiralState1");
SpiralState2 = GetBaseControl("SpiralState2");
SpiralState3 = GetBaseControl("SpiralState3");
SpiralState4 = GetBaseControl("SpiralState4");
SetWaterValue1 = _GetBaseControl("SetWaterValue1");
SetWaterValue2 = _GetBaseControl("SetWaterValue2");
SetWaterValue3 = _GetBaseControl("SetWaterValue3");
SetWaterValue4 = _GetBaseControl("SetWaterValue4");
SetSpiralValue1 = _GetBaseControl("SetSpiralValue1");
SetSpiralValue2 = _GetBaseControl("SetSpiralValue2");
SetSpiralValue3 = _GetBaseControl("SetSpiralValue3");
SetSpiralValue4 = _GetBaseControl("SetSpiralValue4");
materialGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "ManualLogGridView").FirstOrDefault();
#endregion
LogInsertToDatabase("");
1 year ago
#region 配置文件加载
var table = FreeSqlUnit.Instance.Select<ManualControlSetting>().Where("1 = 1").ToList();
SetWaterValue1.MCValue = table.Where(x => x.SettingName == "WaterValue1").LastOrDefault().Value;
SetWaterValue2.MCValue = table.Where(x => x.SettingName == "WaterValue2").LastOrDefault().Value;
SetWaterValue3.MCValue = table.Where(x => x.SettingName == "WaterValue3").LastOrDefault().Value;
SetWaterValue4.MCValue = table.Where(x => x.SettingName == "WaterValue4").LastOrDefault().Value;
SetSpiralValue1.MCValue = table.Where(x => x.SettingName == "SpiralValue1").LastOrDefault().Value;
SetSpiralValue2.MCValue = table.Where(x => x.SettingName == "SpiralValue2").LastOrDefault().Value;
SetSpiralValue3.MCValue = table.Where(x => x.SettingName == "SpiralValue3").LastOrDefault().Value;
SetSpiralValue4.MCValue = table.Where(x => x.SettingName == "SpiralValue4").LastOrDefault().Value;
MesnacServiceManager.Instance.LoggingService.Info("配置已加载");
ManualLogControl("配置已加载 ");
#endregion
#region 变色控制
Gel1 = GetMCRadioButton("Gel1");
backColor = Gel1.BackColor;
Gel1.CheckedChanged += McradionA_CheckedChanged;
Gel2 = GetMCRadioButton("Gel2");
Gel2.CheckedChanged += McradionA_CheckedChanged;
Gel3 = GetMCRadioButton("Gel3");
Gel3.CheckedChanged += McradionA_CheckedChanged;
Gel4 = GetMCRadioButton("Gel4");
Gel4.CheckedChanged += McradionA_CheckedChanged;
Gel5 = GetMCRadioButton("Gel5");
Gel5.CheckedChanged += McradionB_CheckedChanged;
Gel6 = GetMCRadioButton("Gel6");
Gel6.CheckedChanged += McradionB_CheckedChanged;
Gel7 = GetMCRadioButton("Gel7");
Gel7.CheckedChanged += McradionB_CheckedChanged;
Gel8 = GetMCRadioButton("Gel8");
Gel8.CheckedChanged += McradionB_CheckedChanged;
Wet1 = GetMCRadioButton("Wet1");
Wet1.CheckedChanged += Wet1_CheckedChanged;
Wet2 = GetMCRadioButton("Wet2");
Wet2.CheckedChanged += Wet1_CheckedChanged;
Wet3 = GetMCRadioButton("Wet3");
Wet3.CheckedChanged += Wet3_CheckedChanged;
Wet4 = GetMCRadioButton("Wet4");
Wet4.CheckedChanged += Wet3_CheckedChanged;
Wet5 = GetMCRadioButton("Wet5");
Wet5.CheckedChanged += Wet5_CheckedChanged;
Wet6 = GetMCRadioButton("Wet6");
Wet6.CheckedChanged += Wet5_CheckedChanged;
Wet7 = GetMCRadioButton("Wet7");
Wet7.CheckedChanged += Wet7_CheckedChanged;
Wet8 = GetMCRadioButton("Wet8");
Wet8.CheckedChanged += Wet7_CheckedChanged;
#endregion
timer = new Timer();
timer.Interval = 1000;
timer.Enabled = true;
timer.Tick += new EventHandler(ReadFromPlc);//添加事件
1 year ago
}
#region 单选变色控制
private void Wet1_CheckedChanged(object sender, EventArgs e)
{
MCRadioButton mCRadio = sender as MCRadioButton;
Wet1.BackColor = backColor;
Wet2.BackColor=backColor;
mCRadio.BackColor = Color.GreenYellow;
}
private void Wet3_CheckedChanged(object sender, EventArgs e)
{
MCRadioButton mCRadio = sender as MCRadioButton;
Wet3.BackColor = backColor;
Wet4.BackColor = backColor;
mCRadio.BackColor = Color.GreenYellow;
}
private void Wet5_CheckedChanged(object sender, EventArgs e)
{
MCRadioButton mCRadio = sender as MCRadioButton;
Wet5.BackColor = backColor;
Wet6.BackColor = backColor;
mCRadio.BackColor = Color.GreenYellow;
}
private void Wet7_CheckedChanged(object sender, EventArgs e)
{
MCRadioButton mCRadio = sender as MCRadioButton;
Wet7.BackColor = backColor;
Wet8.BackColor = backColor;
mCRadio.BackColor = Color.GreenYellow;
}
private MCRadioButton GetMCRadioButton(string name)
{
var mcradion = allControl.Where(t => t.Name == name).FirstOrDefault() as MCRadioButton;
return mcradion;
}
private void McradionA_CheckedChanged(object sender, EventArgs e)
{
MCRadioButton mCRadio = sender as MCRadioButton;
Gel1.BackColor = backColor;
Gel2.BackColor = backColor;
Gel3.BackColor = backColor;
Gel4.BackColor = backColor;
mCRadio.BackColor = Color.GreenYellow;
}
private void McradionB_CheckedChanged(object sender, EventArgs e)
{
MCRadioButton mCRadio = sender as MCRadioButton;
Gel5.BackColor = backColor;
Gel6.BackColor = backColor;
Gel7.BackColor = backColor;
Gel8.BackColor = backColor;
mCRadio.BackColor = Color.GreenYellow;
}
#endregion
#region 返回数据读取
1 year ago
private void Timer1_Tick()
{
1 year ago
bool mixok1 = PlcConnect.Instance.ReadBool("DB3000.0.0").Content;
Time(1, mixok1 ? 1 : 0);
1 year ago
bool mixok2 = PlcConnect.Instance.ReadBool("DB3000.0.1").Content;
Time(2, mixok2 ? 1 : 0);
bool mixok3 = PlcConnect.Instance.ReadBool("DB3000.0.2").Content;
Time(3, mixok3 ? 1 : 0);
bool mixok4 = PlcConnect.Instance.ReadBool("DB3000.0.3").Content;
Time(4, mixok4 ? 1 : 0);
bool mixok5 = PlcConnect.Instance.ReadBool("DB3000.0.4").Content;
Time(5, mixok5 ? 1 : 0);
bool mixok6 = PlcConnect.Instance.ReadBool("DB3000.0.5").Content;
Time(6, mixok6 ? 1 : 0);
1 year ago
1 year ago
bool mixok7 = PlcConnect.Instance.ReadBool("DB3000.0.6").Content;
Time(7, mixok7 ? 1 : 0);
bool mixok8 = PlcConnect.Instance.ReadBool("DB3000.0.7").Content;
Time(8, mixok8 ? 1 : 0);
1 year ago
}
1 year ago
1 year ago
private void Time(int deviceNo,int statu)
1 year ago
{
OpenDoorService.Insert(new OpenDoorEntity()
{
DeviceId = deviceNo,
OpenTime = DateTime.Now,
CreateTime = DateTime.Now,
Status = statu
});
1 year ago
TankIsDischargedSyncEntity tankIsDischargedSyncEntity = new TankIsDischargedSyncEntity()
{
reqCode = System.Guid.NewGuid().ToString(),
reqTime = DateTime.Now,
deviceNo = deviceNo.ToString(),
state = statu.ToString(),
};
//即使网络不同 也不会影响上位机的使用
ThreadPool.QueueUserWorkItem(delegate
{
HttpResponse httpResponse = new HttpResponse();
// MesnacServiceManager.Instance.LoggingService.Info($"湿混机{deviceNo}下发请求");
string returnTest = httpResponse.PostResponse(tankIsDischargedSyncEntity);
// ManualLogControl($"湿混机{deviceNo}返回数据 " + returnTest);
MesnacServiceManager.Instance.LoggingService.Info($"湿混机{deviceNo}返回数据" + returnTest);
});
1 year ago
}
#endregion
#region Timer刷新方法 Plc读取
1 year ago
private void ReadFromPlc(object sender, EventArgs e)
1 year ago
{
1 year ago
DB2107 = new DB2107Helper();
DB2119 = new DB2119Helper();
1 year ago
DB2103 = new DB2103Helper();
1 year ago
1 year ago
no += 1;
if(no > 5)
{
no = 0;
Timer1_Tick();
}
if (GetAllDbMCControlsByOption(DbOptionTypes.InitData).Count == 0)
{
timer.Stop();
timer.Dispose();
}
#region 称量结束日志
if (DB2119.Coolwater_A.Dos_End)
{
if(PlcControl("DB2119.28.3", false))
{
ManualLogControl("冷水称A称量结束", DB2119.Coolwater_A.Value_Initial, 2, 3, 1);
}
}
if (DB2119.Hotwater_A.Dos_End)
{
if(PlcControl("DB2119.08.3", false))
{
ManualLogControl("热水称A称量结束", DB2119.Hotwater_A.Value_Initial, 2, 1, 1);
}
}
if (DB2119.Coolwater_B.Dos_End)
{
if (PlcControl("DB2119.38.3", false))
{
ManualLogControl("冷水称B称量结束", DB2119.Coolwater_B.Value_Initial, 2, 4, 1);
}
}
if (DB2119.Hotwater_B.Dos_End)
{
if(PlcControl("DB2119.18.3", false))
{
ManualLogControl("热水称B称量结束", DB2119.Hotwater_B.Value_Initial, 2, 2, 1);
}
}
if (DB2119.Spiral_A.Dos_End)
{
if(PlcControl("DB2119.60.3", false))
{
if (DB2119.Spiral_A.Weter_Bin == 1)
{
ManualLogControl("湿混机1称量结束", DB2119.Spiral_A.Value_Weight, 4, 1, 2);
}
else if (DB2119.Spiral_A.Weter_Bin == 2)
{
ManualLogControl("湿混机2称量结束", DB2119.Spiral_A.Value_Weight, 4, 2, 2);
}
else
{
ManualLogControl("螺旋1称量结束", DB2119.Spiral_A.Value_Weight, 4, 12, 2);
}
}
}
if (DB2119.Spiral_B.Dos_End)
{
if(PlcControl("DB2119.82.3", false))
{
if (DB2119.Spiral_B.Weter_Bin == 1)
{
ManualLogControl("湿混机3称量结束", DB2119.Spiral_B.Value_Weight, 4, 3, 2);
}
else if (DB2119.Spiral_B.Weter_Bin == 2)
{
ManualLogControl("湿混机4称量结束", DB2119.Spiral_B.Value_Weight, 4, 4, 2);
}
else
{
ManualLogControl("螺旋2称量结束", DB2119.Spiral_B.Value_Weight, 4, 34, 2);
}
}
}
if (DB2119.Spiral_C.Dos_End)
{
if(PlcControl("DB2119.104.3", false))
{
if (DB2119.Spiral_C.Weter_Bin == 1)
{
ManualLogControl("湿混机5称量结束", DB2119.Spiral_C.Value_Weight, 4, 5, 2);
}
else if (DB2119.Spiral_C.Weter_Bin == 2)
{
ManualLogControl("湿混机6称量结束", DB2119.Spiral_C.Value_Weight, 4, 6, 2);
}
else
{
ManualLogControl("螺旋1称量结束", DB2119.Spiral_C.Value_Weight, 4, 56, 2);
}
}
}
#endregion
#region 实际值 称量值指示
WaterActualValue1.MCValue = DB2107.Weight.WScale_3.ActWeight;
WaterActualValue2.MCValue = DB2107.Weight.WScale_1.ActWeight;
WaterActualValue3.MCValue = DB2107.Weight.WScale_4.ActWeight;
1 year ago
WaterActualValue4.MCValue = DB2107.Weight.WScale_2.ActWeight;
1 year ago
WaterMetValue1.MCValue = DB2119.Coolwater_A.Value_Initial;
1 year ago
WaterMetValue2.MCValue = DB2119.Hotwater_A.Value_Initial;
1 year ago
WaterMetValue3.MCValue = DB2119.Coolwater_B.Value_Initial;
1 year ago
WaterMetValue4.MCValue = DB2119.Hotwater_B.Value_Initial;
SpiralActValue1.MCValue = DB2103.DM2ASF01.ACT_Speed;
SpiralActValue2.MCValue = DB2103.DM2BSF01.ACT_Speed;
SpiralActValue3.MCValue = DB2103.DM2CSF01.ACT_Speed;
SpiralActValue4.MCValue = DB2103.DM2DSF01.ACT_Speed;
1 year ago
SpiralMetValue1.MCValue = DB2119.Spiral_A.Value_Weight;
1 year ago
SpiralMetValue2.MCValue = DB2119.Spiral_B.Value_Weight;
1 year ago
SpiralMetValue3.MCValue = DB2119.Spiral_C.Value_Weight;
1 year ago
#endregion
1 year ago
#region 水称状态指示
1 year ago
if (DB2119.Coolwater_A.Dos_Status)
1 year ago
{
MetageState1.MCValue = "正在称量";
}
else
{
MetageState1.MCValue = "停止称量";
}
if (DB2119.Coolwater_A.Dis_Status)
1 year ago
{
WaterOutState1.MCValue = "正在排水";
}
else
{
WaterOutState1.MCValue = "停止排水";
}
if (DB2119.Hotwater_A.Dos_Status)
1 year ago
{
MetageState2.MCValue = "正在称量";
}
else
{
MetageState2.MCValue = "停止称量";
}
if (DB2119.Hotwater_A.Dis_Status)
1 year ago
{
WaterOutState2.MCValue = "正在排水";
}
else
{
WaterOutState2.MCValue = "停止排水";
}
if (DB2119.Coolwater_B.Dos_Status)
1 year ago
{
MetageState3.MCValue = "正在称量";
}
else
{
MetageState3.MCValue = "停止称量";
}
if (DB2119.Coolwater_B.Dis_Status)
1 year ago
{
WaterOutState3.MCValue = "正在排水";
}
else
{
WaterOutState3.MCValue = "停止排水";
}
if (DB2119.Hotwater_B.Dos_Status)
1 year ago
{
MetageState4.MCValue = "正在称量";
}
else
{
MetageState4.MCValue = "停止称量";
}
if (DB2119.Hotwater_B.Dis_Status)
1 year ago
{
WaterOutState4.MCValue = "正在排水";
}
else
{
WaterOutState4.MCValue = "停止排水";
}
#endregion
1 year ago
#region 螺旋状态指示
1 year ago
if (DB2119.Spiral_A.Dos_Status)
1 year ago
{
SpiralState1.MCValue = "正在螺旋";
}
else
{
SpiralState1.MCValue = "停止螺旋";
}
if (DB2119.Spiral_B.Dos_Status)
1 year ago
{
SpiralState2.MCValue = "正在螺旋";
}
else
{
SpiralState2.MCValue = "停止螺旋";
}
if (DB2119.Spiral_C.Dos_Status)
1 year ago
{
SpiralState3.MCValue = "正在螺旋";
}
else
{
SpiralState3.MCValue = "停止螺旋";
}
//Read = PlcConnect.Instance.Read("DB2119..0", 1);
//content = Read.Content;
//Byt = content[0];
//State1 = Byt.GetBit(2);
//if (State1)
//{
// MetageState4.MCValue = "正在螺旋";
//}
//else
//{
// MetageState4.MCValue = "停止螺旋";
//}
#endregion
ReadHslSwithch();
}
1 year ago
#endregion
#region 控件获取帮助
/// <summary>
/// InitData控件获取
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
private IBaseControl GetBaseControl(string name)
{
return McControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey == name).FirstOrDefault().BaseControl;
}
1 year ago
/// <summary>
/// Modify控件获取
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
private IBaseControl _GetBaseControl(string name)
{
return _McControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey == name).FirstOrDefault().BaseControl;
}
#endregion
#region 日志控制
/// <summary>
/// 日志查询
/// </summary>
/// <param name="txt">查询关键字</param>
private void LogInsertToDatabase(string txt)
{
string sql = "select top 500 id, logtext, logtime, value from Manual_Log ";
if (!string.IsNullOrEmpty(txt))
{
sql += $" where logtext like '%{txt}%'";
}
sql += " order by id desc";
DataTable table = DBHelp.GetTable(sql);
if (this.materialGridControl != null && this.materialGridControl.BaseControl != null)
{
this.materialGridControl.BaseControl.BindDataSource = null;
this.materialGridControl.BaseControl.BindDataSource = table;
}
else
{
ICSharpCode.Core.LoggingService<InitAction>.Warn("ManualContrlolAction 手动操作日志信息控件为Null...");
}
}
/// <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>
private void ManualLogControl(string logName, int value, int valuekind, int deviceno, int devicekind)
{
var Log = new ManualLogEntity()
{
logtext = logName,
logtime = DateTime.Now,
userid = string.IsNullOrWhiteSpace(UserInfo.Instance.UserName) ? "Edit" : UserInfo.Instance.UserName,
value = value,
deviceno = deviceno,
devicekind = devicekind,
valuekind = valuekind,
createdate = DateTime.Now.ToString("yyyyMMdd")
};
FreeSqlUnit.Instance.Insert(Log).ExecuteIdentity();
LogInsertToDatabase("");
}
private void ManualLogControl(string logName, int deviceno, int devicekind)
{
var Log = new ManualLogEntity()
{
logtext = logName,
logtime = DateTime.Now,
userid = string.IsNullOrWhiteSpace(UserInfo.Instance.UserName) ? "Edit" : UserInfo.Instance.UserName,
value = 0,
deviceno = deviceno,
devicekind = devicekind,
valuekind = 0,
createdate = DateTime.Now.ToString("yyyyMMdd")
};
FreeSqlUnit.Instance.Insert(Log).ExecuteIdentity();
LogInsertToDatabase("");
}
private void ManualLogControl(string logName)
{
var Log = new ManualLogEntity()
{
logtext = logName,
logtime = DateTime.Now,
userid = string.IsNullOrWhiteSpace(UserInfo.Instance.UserName) ? "Edit" : UserInfo.Instance.UserName,
value = 0,
deviceno = 0,
devicekind = 0,
valuekind = 0,
createdate = DateTime.Now.ToString("yyyyMMdd")
};
FreeSqlUnit.Instance.Insert(Log).ExecuteIdentity();
LogInsertToDatabase("");
}
#endregion
private bool PlcControl(string address, bool state)
{
return PlcConnect.Instance.Write(address, state).IsSuccess;
}
private void FillHslSwitch()
{
//hslSwitchEntity
hslSwitchEntity = new HslSwitchEntity();
var sourceType = hslSwitchEntity.GetType();
PropertyInfo[] sourcePropertyInfoList = sourceType.GetProperties();
foreach (PropertyInfo sourceProperty in sourcePropertyInfoList)
{
string name = sourceProperty.Name;
var pro = allControl.FirstOrDefault(x => x.Name == name) as HslSwitch;
DefaultSwitch(pro);
pro.OnSwitchChanged += Pro_OnSwitchChanged;
sourceProperty.SetValue(hslSwitchEntity, pro);
}
ReadHslSwithch();
//DefaultSwitch
}
private void ReadHslSwithch()
{
var rd = Db3000Helper.ReadModel();
hslSwitchEntity.HslSwitch1.SwitchStatus = rd[0];
hslSwitchEntity.HslSwitch2.SwitchStatus = rd[1];
hslSwitchEntity.HslSwitch3.SwitchStatus = rd[2];
hslSwitchEntity.HslSwitch4.SwitchStatus = rd[3];
hslSwitchEntity.HslSwitch5.SwitchStatus = rd[4];
hslSwitchEntity.HslSwitch6.SwitchStatus = rd[5];
hslSwitchEntity.HslSwitch7.SwitchStatus = rd[6];
hslSwitchEntity.HslSwitch8.SwitchStatus = rd[7];
}
private void Pro_OnSwitchChanged(object arg1, bool arg2)
{
HslSwitch hslSwitch = arg1 as HslSwitch;
string name = hslSwitch.Name;
int no = Convert.ToInt32(name.Replace("HslSwitch", ""));
Db3000Helper.WriteModel(no, arg2);
DefaultSwitch(hslSwitch);
}
private void DefaultSwitch(HslSwitch hslSwitch)
{
string name = hslSwitch.Name;
string status = hslSwitch.SwitchStatus ? "开" : "关";
string message = "";
if (name == "HslSwitch1")
{
message = "湿混机1:" + status;
}
if (name == "HslSwitch2")
{
message = "湿混机2:" + status;
}
if (name == "HslSwitch3")
{
message = "湿混机3:" + status;
}
if (name == "HslSwitch4")
{
message = "湿混机4:" + status;
}
if (name == "HslSwitch5")
{
message = "湿混机5:" + status;
}
if (name == "HslSwitch6")
{
message = "湿混机6:" + status;
}
if (name == "HslSwitch7")
{
message = "湿混机7:" + status;
}
if (name == "HslSwitch8")
{
message = "湿混机8:" + status;
}
hslSwitch.Text = message;
}
}
}