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.

128 lines
6.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mesnac.Action.Base;
using Mesnac.Codd.Session;
using System.Data;
using System.Windows.Forms;
using System.Reflection;
namespace Mesnac.Action.Feeding.ProducingPlan
{
/// <summary>
/// 胶料秤监控画面上的计划列表数据处理类
/// </summary>
public class InitPlyScreenPlan : FeedingAction, IAction
{
private static bool _isFirstRun = true; //是否首次执行
private RuntimeParameter _runtime = null;
public void Run(RuntimeParameter runtime)
{
this._runtime = runtime;
base.RunIni(runtime);
if (InitPlyScreenPlan._isFirstRun)
{
//首次执行订阅,刷新插件事件
Mesnac.Gui.Workbench.WorkbenchSingleton.Workbench.AfterRefreshPlugIn += delegate(object sender, System.EventArgs e)
{
RefreshClientPlan.OnRefreshPlan -= new EventHandler(RefreshClientPlan_OnRefreshPlan);
InitPlyScreenPlan._isFirstRun = true;
};
//首次执行订阅,客户端刷新计划执行方式事件
RefreshClientPlan.OnRefreshPlan += new EventHandler(RefreshClientPlan_OnRefreshPlan);
InitPlyScreenPlan._isFirstRun = false;
}
base.LogDebug("胶料秤监控画面上的计划列表数据...");
//DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "ppt_plan").FirstOrDefault();
DbMCControl clientGridControl = this.GetDbMCControlByBaseControlKey("WeightMonitor2.PptPlan").FirstOrDefault();
if (clientGridControl == null)
{
ICSharpCode.Core.LoggingService.Warn("胶料秤监控画面:胶料秤监控画面缺少计划列表控件...");
runtime.IsReturn = true;
return;
}
PlanLog planLog = PlanCommon.PlanLog;
if (planLog == null)
{
ICSharpCode.Core.LoggingService.Warn("胶料秤监控画面:还未缓存过计划...");
runtime.IsReturn = true;
return;
}
if (clientGridControl != null && clientGridControl.BaseControl != null)
{
try
{
DbHelper dbHelper = base.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
return;
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
//查询符合条件的本地计划(查询条件:机台、日期、班次)
//string sqlstr = "select RecipeMaterialName,RecipeMaterialCode,PlanNum,CONVERT(VARCHAR(100),RealNum) AS RealNum,PlanID,PlanState from [PptPlan] where RecipeEquipCode=@RecipeEquipCode and CONVERT(varchar,PlanDate,112)=@PlanDate and ShiftID=@ShiftID order by ActionOrder";
string sqlstr = "select recipe_code as RecipeMaterialName,mater_code as RecipeMaterialCode,plan_num as PlanNum,CONVERT(VARCHAR(100),real_num) AS RealNum,plan_id as PlanID,plan_state as PlanState,edt_code as RecipeVersionID from [ppt_plan] where equip_code=@RecipeEquipCode and CONVERT(varchar,down_date,112)=@PlanDate and shift=@ShiftID order by ActionOrder";
dbHelper.AddParameter("@RecipeEquipCode", base.CurrEquipCode);
dbHelper.AddParameter("@PlanDate", String.Format("{0:yyyyMMdd}", planLog.LastSelectDate));
dbHelper.AddParameter("@ShiftID", planLog.LastSelectShiftID);
dbHelper.CommandText = sqlstr;
DataTable table = dbHelper.ToDataTable();
lock (String.Empty)
{
clientGridControl.BaseControl.BindDataSource = null;
clientGridControl.BaseControl.BindDataSource = table;
#region 根据计划状态处理背景色
DataGridView clientGrid = clientGridControl.BaseControl as DataGridView;
if (clientGrid != null)
{
int count = 0;
foreach (DataGridViewColumn col in clientGrid.Columns)
{
if (col.Visible == true)
{
count++;
}
}
if (count == 3)
{
PlanCommon.SetDataGridViewStyle48(clientGrid);
clientGrid.CellDoubleClick += delegate(object sender, DataGridViewCellEventArgs e)
{
clientGrid.ClearSelection();
};
clientGrid.VisibleChanged += delegate(object sender, EventArgs e)
{
DataGridView grv = sender as DataGridView;
if (grv != null && grv.Visible == true)
{
PlanCommon.SetBackColor48(grv);
}
};
PlanCommon.SetBackColor48(clientGrid);
}
}
}
#endregion
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService.Error("胶料秤监控画面:" + ex.Message, ex);
}
}
}
protected void RefreshClientPlan_OnRefreshPlan(object sender, EventArgs e)
{
this.Run(this._runtime);
}
}
}