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#

1 year ago
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;
1 year ago
using System.Timers;
1 year ago
using Mesnac.Action.ChemicalWeighing.XlPlcHelper;
1 year ago
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;
1 year ago
OnRefreshBin -= Process_Event;
OnRefreshBin += Process_Event;
1 year ago
PlcPlanHelper.OnUpdateRefreshBinEvent -= Process_Event;
PlcPlanHelper.OnUpdateRefreshBinEvent += Process_Event;
1 year ago
IsFirstRun = false;
}
#endregion
1 year ago
DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Pmt_Bin").FirstOrDefault(); //获取本机台计划控件
1 year ago
if (clientGridControl == null || !(clientGridControl.BaseControl is DataGridView))
{
ICSharpCode.Core.LoggingService<RefreshAction>.Error("{料仓报表}缺少本机台计划网格控件...");
return;
}
this._clientGridControl = clientGridControl;
this.DoWork();
}
#endregion
1 year ago
1 year ago
#region 方法定义
/// <summary>
/// 刷新计划
/// </summary>
protected void DoWork()
{
#region 业务实现
IFreeSql fsql = FreeHelper.Instance;
1 year ago
1 year ago
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 (
1 year ago
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
1 year ago
left join (
1 year ago
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";
1 year ago
lock (String.Empty)
{
//本地计划
if (this._clientGridControl != null && this._clientGridControl.BaseControl != null)
{
1 year ago
DataTable table = fsql.Select<object>().WithSql(sql).OrderBy("Bin_Serial").ToDataTable("*");
1 year ago
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 触发事件, 刷新客户端计划
1 year ago
//if (OnRefreshBin != null)
//{
// OnRefreshBin(this._runtime.BaseControl.MCRoot, System.EventArgs.Empty);
//}
1 year ago
#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
}
}