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 事件定义
///
/// 刷新料仓
///
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.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.Error("{料仓报表}缺少本机台计划网格控件...");
return;
}
this._clientGridControl = clientGridControl;
this.DoWork();
}
#endregion
#region 方法定义
///
/// 刷新计划
///
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