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/FinishBatch/SCADAHelper/AlarmRefreshAction.cs

202 lines
6.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data;
using ICSharpCode.Core;
using Mesnac.Controls.Base;
using Mesnac.Action.Base;
using Mesnac.Codd.Session;
using Mesnac.Action.ChemicalWeighing.Entity;
using Mesnac.Action.ChemicalWeighing.Technical;
namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SCADAHelper
{
public class AlarmRefreshAction : ChemicalWeighingAction,IAction
{
#region 事件定义
/// <summary>
/// 刷新计划事件
/// </summary>
public static event EventHandler OnAlarmRefresh;
#endregion
#region 字段定义
private RuntimeParameter _runtime;
private IBaseControl _clientGridControl = null; //报警信息列表控件
private IBaseControl _clientAlarmInfoControl = null; //报警控件容器
Mesnac.Controls.Default.MultiColHeaderDgv clientGrid = null;
#endregion
#region IAction接口实现
public void Run(RuntimeParameter runtime)
{
Global.PublicVar.Instance.isFlashFlag = false;
base.RunIni(runtime); //必须要调用的
this._runtime = runtime;
#region 事件订阅
if (true)
{
Mesnac.Basic.InvokeHelper.OnAlarmRefresh -= Process_Event;
Mesnac.Basic.InvokeHelper.OnAlarmRefresh += Process_Event;
//报警刷新保存事件绑定
1 year ago
SaveHelper.AlarmSaveHelper.Instance.sender = runtime;
SaveHelper.AlarmSaveHelper.Instance.OnAlarmSave -= Process_Event;
SaveHelper.AlarmSaveHelper.Instance.OnAlarmSave += Process_Event;
}
#endregion
IBaseControl baseControl = null;
IBaseControl infoControl = null;
bool gridFlag = false;
bool infoFlag = false;
foreach(IBaseControl ib in GetAllMCControls())
{
if(ib.MCKey == null)
{
continue;
}
else
{
if(ib.MCKey == "alarmDG")
{
baseControl = ib;
gridFlag = true;
}
if(ib.MCKey == "alarmInfoList")
{
infoControl = ib;
infoFlag = true;
}
}
if(gridFlag && infoFlag)
{
break;
}
}
if (baseControl == null || !(baseControl is DataGridView))
{
ICSharpCode.Core.LoggingService<AlarmRefreshAction>.Error("{当班计划—刷新计划}缺少本机台计划网格控件...");
//return;
}
this._clientGridControl = baseControl;
this._clientAlarmInfoControl = infoControl;
this.DoWork();
}
#endregion
#region 方法定义
/// <summary>
/// 刷新计划
/// </summary>
protected void DoWork()
{
#region 业务实现
DataTable table = DataListShow();
lock (String.Empty)
{
//本地计划
if (this._clientGridControl != null && this._clientAlarmInfoControl != null)
{
if (table != null)
{
_clientGridControl.BindDataSource = null;
_clientGridControl.BindDataSource = table;
if (Global.PublicVar.Instance.AlarmStrList != null && Global.PublicVar.Instance.AlarmStrList.Count != 0)
{
this._clientAlarmInfoControl.MCVisible = true;
}
else
{
this._clientAlarmInfoControl.MCVisible = false;
}
}
else
{
this._clientAlarmInfoControl.MCVisible = false;
}
}
else
{
ICSharpCode.Core.LoggingService<AlarmRefreshAction>.Warn("刷新本地计划失败本地计划控件为Null...");
}
}
#endregion
#region 触发事件
if (OnAlarmRefresh != null)
{
OnAlarmRefresh(this._runtime.BaseControl.MCRoot, System.EventArgs.Empty);
}
#endregion
}
#endregion
#region 事件处理方法
private void Process_Event(object sender, EventArgs e)
{
if (sender is RuntimeParameter)
{
this.Run(sender as RuntimeParameter);
}
else
{
this.Run(this._runtime);
}
}
#endregion
#region DataTable数据整理显示
private DataTable DataListShow()
{
DataTable dataTable = null;
if(Global.PublicVar.Instance.AlarmStrList != null && Global.PublicVar.Instance.AlarmStrList.Count > 0)
{
dataTable = new DataTable();
DataColumn SerialNumColumnText = new DataColumn("SerialNum", Type.GetType("System.String"));
DataColumn ShowTextColumnText = new DataColumn("ShowText", Type.GetType("System.String"));
dataTable.Columns.Add(SerialNumColumnText);
dataTable.Columns.Add(ShowTextColumnText);
for (int i = 0;i< Global.PublicVar.Instance.AlarmStrList.Count;i++)
{
DataRow dataRow = dataTable.NewRow();
dataRow["SerialNum"] = (i + 1).ToString();
dataRow["ShowText"] = Global.PublicVar.Instance.AlarmStrList[i];
dataTable.Rows.Add(dataRow);
}
}
return dataTable;
}
#endregion
}
}