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.

202 lines
7.6 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.DBHelper;
using System.Timers;
using Mesnac.Action.ChemicalWeighing.XlPlcHelper;
namespace Mesnac.Action.ChemicalWeighing.Report.BinReport
{
public class RefreshAction : ChemicalWeighingAction, IAction
{
#region 事件定义
/// <summary>
/// 刷新料仓
/// </summary>
public static event EventHandler OnRefreshBin;
#endregion
#region 字段定义
private static bool IsFirstRun = true; //是否首次执行
private RuntimeParameter _runtime;
private DbMCControl _clientGridControl = null; //网格计划控件
#endregion
#region IAction接口实现
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须要调用的
this._runtime = runtime;
ICSharpCode.Core.LoggingService<RefreshAction>.Debug("料仓报表—刷新报表业务...");
#region 事件订阅
if (true)
{
//通用调用刷新计划事件订阅
InitFormAction.OnRefreshBinEvent -= Process_Event;
InitFormAction.OnRefreshBinEvent += Process_Event;
OnRefreshBin -= Process_Event;
OnRefreshBin += Process_Event;
PlcPlanHelper.OnUpdateRefreshBinEvent -= Process_Event;
PlcPlanHelper.OnUpdateRefreshBinEvent += Process_Event;
IsFirstRun = false;
}
#endregion
DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Pmt_Bin").FirstOrDefault(); //获取本机台计划控件
if (clientGridControl == null || !(clientGridControl.BaseControl is DataGridView))
{
ICSharpCode.Core.LoggingService<RefreshAction>.Error("{料仓报表}缺少本机台计划网格控件...");
return;
}
this._clientGridControl = clientGridControl;
this.DoWork();
}
#endregion
#region 方法定义
/// <summary>
/// 刷新计划
/// </summary>
protected void DoWork()
{
#region 业务实现
IFreeSql fsql = FreeHelper.Instance;
string sql = @"select Bin_Serial,Bin_Name,Material_ID,x.Material_name,LimitWeight,BinWeight,ISNULL(e.OutWeight,0.00) OutWeight,ISNULL(o.EnterWeight,0.00) EnterWeight from Pmt_Bin b left join xl_material x on b.Material_ID=x.ID
left join (
select distinct BinId,BinName,MaterialCode,MaterialName,ISNULL(SUM(Weights),0.00) as OutWeight,TypeName from ( select b.* from Pmt_Bin b inner join xl_material m on b.Material_ID=m.ID ) b
left join Hw_BinAlarm a on b.Material_ID=a.MaterialCode and b.Bin_Serial=a.BinId where TypeName='出库' and MaterialCode is not null group by BinId,BinName,MaterialCode,MaterialName,TypeName ) e on b.Bin_Serial=e.BinId and b.Material_ID=e.MaterialCode
left join (
select distinct BinId,BinName,MaterialCode,MaterialName,ISNULL(SUM(Weights),0.00) as EnterWeight,TypeName from ( select b.* from Pmt_Bin b inner join xl_material m on b.Material_ID=m.ID ) b
left join Hw_BinAlarm a on b.Material_ID=a.MaterialCode and b.Bin_Serial=a.BinId where TypeName='入库' and MaterialCode is not null group by BinId,BinName,MaterialCode,MaterialName,TypeName) o on b.Bin_Serial=o.BinId and b.Material_ID=e.MaterialCode";
lock (String.Empty)
{
//本地计划
if (this._clientGridControl != null && this._clientGridControl.BaseControl != null)
{
DataTable table = fsql.Select<object>().WithSql(sql).OrderBy("Bin_Serial").ToDataTable("*");
if (table.Rows.Count > 0)
{
_clientGridControl.BaseControl.BindDataSource = null;
_clientGridControl.BaseControl.BindDataSource = table;
}
else
{
_clientGridControl.BaseControl.BindDataSource = null;
}
#region 根据计划状态处理背景色
DataGridView clientGrid = this._clientGridControl.BaseControl as DataGridView;
SetBackColor(clientGrid);
#endregion
}
else
{
ICSharpCode.Core.LoggingService<RefreshAction>.Warn("刷新本地计划失败本地计划控件为Null...");
}
}
#endregion
#region 触发事件, 刷新客户端计划
//if (OnRefreshBin != null)
//{
// OnRefreshBin(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 设置(网格控件)计划状态背景色
/// <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)
{
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<InitFormAction>.Error("设置料仓报警背景色失败:" + ex.Message);
}
}
}
#endregion
}
}