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.

314 lines
11 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 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;
using Mesnac.Action.ChemicalWeighing.Alarm;
using Mesnac.Action.ChemicalWeighing.Entity.PptPlan;
using Mesnac.Action.ChemicalWeighing.Show;
using System.Timers;
using Mesnac.Action.ChemicalWeighing.Product.XlPlan;
namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SCADAHelper
{
public class AlarmRefreshAction : ChemicalWeighingAction,IAction
{
#region 事件定义
/// <summary>
/// 刷新计划事件
/// </summary>
public static event EventHandler OnAlarmRefresh;
#endregion
#region 字段定义
bool flag = true;
private RuntimeParameter _runtime;
private IBaseControl _clientGridControl = null; //报警信息列表控件
private IBaseControl _clientAlarmInfoControl = 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;
//报警刷新保存事件绑定
SaveHelper.AlarmSaveHelper.sender = runtime;
SaveHelper.AlarmSaveHelper.OnAlarmSave -= Process_Event;
SaveHelper.AlarmSaveHelper.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)
{
this._clientGridControl.BindDataSource = null;
this._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
ServerStart();
#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 = AlarmHelper.QueryAlarmLogDataTable();
//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
private void ServerStart()
{
try
{
if (flag)
{
flag = false;
var lblRecipeName = base.GetControlById("lblRecipeName") as System.Windows.Forms.Label;//配方名称
var lblStandardWeight = base.GetControlById("lblStandardWeight") as System.Windows.Forms.Label;//标重
if (lblRecipeName == null) { return; }
List<Xl_DowLoadPlan> materialList = PlanHelper.GetExecPlan();//正在执行的任务
if (materialList == null) { return; }
int i = 0;
foreach (var item in materialList)
{
if (i == 0)
{
lblRecipeName.Text = item.Recipe_Name;
lblRecipeName.Text = item.Recipe_Name;
lblStandardWeight.Text = item.Total_Weight.ToString();
break;
}
}
DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "xl_weigh").FirstOrDefault(); //获取本机台计划控件
if (clientGridControl == null || !(clientGridControl.BaseControl is DataGridView))
{
ICSharpCode.Core.LoggingService<XlInitAction>.Error("{首页展示}缺少本机台计划网格控件...");
return;
}
lock (String.Empty)
{
//本地计划
if (clientGridControl != null && clientGridControl.BaseControl != null)
{
var data = PlanHelper.GetExecPlanDataTable();
clientGridControl.BaseControl.BindDataSource = null;
clientGridControl.BaseControl.BindDataSource = data;
#region 根据计划状态处理背景色
DataGridView clientGrid = clientGridControl.BaseControl as DataGridView;
SetBackColor(clientGrid);
#endregion
}
else
{
ICSharpCode.Core.LoggingService<XlInitAction>.Warn("接在首页展示物料失败本地计划控件为Null...");
}
}
}
}
catch (Exception)
{
throw;
}
finally
{
flag = true;
}
}
#region 设置(网格控件)计划状态背景色
/// <summary>
/// 设置计划状态背景色
/// </summary>
/// <param name="grid"></param>
public static void SetBackColor(DataGridView grid)
{
lock (String.Empty)
{
try
{
if (grid == null || grid.Visible == false)
{
ICSharpCode.Core.LoggingService.Warn("设置背景色失败网格控件为null或不可见");
return;
}
grid.ClearSelection(); //清空选中行
grid.ColumnHeadersHeight = 25;
grid.ColumnHeadersDefaultCellStyle.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
grid.RowHeadersVisible = false;
grid.RowTemplate.Height = 28;
grid.RowsDefaultCellStyle.Font = new System.Drawing.Font("宋体", 12, System.Drawing.FontStyle.Bold);
foreach (DataGridViewRow row in grid.Rows)
{
row.DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(220, 220, 220); //灰色
}
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<XlInitAction>.Error("设置背景色失败:" + ex.Message);
}
}
}
#endregion
}
}