using Mesnac.Action.Base;
using Mesnac.Action.ChemicalWeighing.DBHelper;
using Mesnac.Action.ChemicalWeighing.Entity;
using Mesnac.Controls.Base;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;
namespace Mesnac.Action.ChemicalWeighing.Report.BinReport
{
///
///料仓库存警告报表
///
class InitFormAction : ChemicalWeighingAction, IAction
{
private DbMCControl _dg = null;
public static event EventHandler OnRefreshBinEvent;//刷新料仓
private RuntimeParameter _runtime;
bool flag=true;
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须要调用的
this._runtime = runtime;
ICSharpCode.Core.LoggingService.Debug("仓库报警报表-窗体初始化...");
this._dg = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Pmt_Bin").FirstOrDefault();
if (_dg == null)
{
ICSharpCode.Core.LoggingService.Warn("{仓库报警报表} 缺少控件...");
runtime.IsReturn = false;
return;
}
#region 触发事件, 刷新客户端计划
this.InitData();
#endregion
#region 根据状态处理背景色
DataGridView clientGrid = this._dg.BaseControl as DataGridView;
SetBackColor(clientGrid);
#endregion
}
private void InitData()
{
if (flag)
{
flag = false;
//System.Timers.Timer timer = new System.Timers.Timer(5000);
//timer.Elapsed += new ElapsedEventHandler(StartServer);
//timer.AutoReset = true;
//timer.Enabled = true;
//timer.Start();
StartServer();
}
}
private void StartServer()//object sender, ElapsedEventArgs e
{
if (OnRefreshBinEvent != null)
{
OnRefreshBinEvent(this._runtime.BaseControl.MCRoot, System.EventArgs.Empty);
}
}
#region 设置(网格控件)计划状态背景色
///
/// 设置计划状态背景色
///
///
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)
{
decimal limitWeight = Convert.ToDecimal(row.Cells["LimitWeight"].Value.ToString());
decimal binWeight = Convert.ToDecimal(row.Cells["BinWeight"].Value.ToString());
if (limitWeight > binWeight)
{
row.DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(255, 0, 0); //灰色
}
}
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService.Error("设置料仓报警背景色失败:" + ex.Message);
}
}
}
#endregion
}
}