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.

198 lines
7.1 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 Mesnac.Action.Base;
using Mesnac.Codd.Session;
using System.Reflection;
using Mesnac.Controls.Base;
namespace Mesnac.Action.ChemicalWeighing.Product.XlPlan
{
/// <summary>
/// 当班计划窗体初始化业务
/// </summary>
public class InitFormAction : ChemicalWeighingAction,IAction
{
#region 字段定义
public static bool IsFirstRun = true; //是否首次运行
private RuntimeParameter _runtime;
//private DbMCControl _planDateControl = null; //计划日期
//private DbMCControl _pptShiftControl = null; //班次
private DbMCControl _clientGridControl = null; //本地计划控件
#endregion
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime);
#region 首次执行,进行事件订阅
if (IsFirstRun)
{
IsFirstRun = false;
ICSharpCode.Core.LoggingService<InitFormAction>.Debug("当班计划-窗体初始化业务...");
}
#endregion
PlanHelper.IsInit = false; //先设置是否已初始化标记为False
#region 初始化
#region 获取界面控件
string source = string.Empty;
//DbMCControl planDateControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "[xl_plan].[Plan_Date]").FirstOrDefault();
//DbMCControl pptShiftControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Pmt_Shiftime").FirstOrDefault();
DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "xl_plan").FirstOrDefault(); //获取本机台计划网格控件
//if (planDateControl == null)
//{
// ICSharpCode.Core.LoggingService<InitFormAction>.Error("{当班计划-窗体加载} 缺少日期选择控件...");
// return;
//}
//if (pptShiftControl == null)
//{
// ICSharpCode.Core.LoggingService<InitFormAction>.Error("{当班计划-窗体加载} 缺少班次组合框控件...");
// return;
//}
if (clientGridControl == null)
{
ICSharpCode.Core.LoggingService<InitFormAction>.Error("{当班计划-窗体加载} 缺少计划列表网格控件...");
return;
}
this._runtime = runtime;
//this._planDateControl = planDateControl;
//this._pptShiftControl = pptShiftControl;
this._clientGridControl = clientGridControl;
#endregion
#region 初始化操作
DataGridView clientGrid = (clientGridControl.BaseControl as DataGridView);
this.InitGridViewEvent(clientGrid);
this.InitData();
#endregion
#endregion
PlanHelper.IsInit = true; //初始化完毕后再设置是否已初始化标记为True
}
#region 方法定义
#region 网格事件处理方法
/// <summary>
/// 初始化网格样式
/// </summary>
/// <param name="dgv">DataGridView网格控件对象</param>
private void InitGridViewEvent(DataGridView dgv)
{
if (dgv != null)
{
PlanHelper.SetDataGridViewStyle(dgv); //设置网格样式
//双击时取消选择行(取消高亮显示)
//dgv.CellDoubleClick += delegate(object sender, DataGridViewCellEventArgs e)
//{
// if (dgv.Rows != null && dgv.Rows.Count > 0)
// {
// foreach (DataGridViewRow row in dgv.Rows)
// {
// row.Selected = false;
// }
// }
//};
//dgv.VisibleChanged += delegate(object sender, EventArgs e)
//{
// PlanHelper.SetBackColor(dgv);
//};
////PlanHelper.SetBackColor(dgv);
//ContextMenuStrip cms = new ContextMenuStrip();
//cms.Items.Add("称量明细");
//dgv.ContextMenuStrip = cms;
//cms.Click += Cms_Click;
}
}
private void Cms_Click(object sender, EventArgs e)
{
//ShowMsg("11111");
//MessageBox.Show("11111");
}
#endregion
#region 初始化界面控件数据
/// <summary>
/// 初始化界面控件数据
/// </summary>
private void InitData()
{
#region 取消事件绑定
//List<DesignAction> valueChangedList = null;
//List<DesignAction> cacheValueChangedList = new List<DesignAction>();
//PropertyInfo pi1 = this._planDateControl.BaseControl.GetType().GetProperty("ValueChangedList");
//if (pi1 != null)
//{
// valueChangedList = pi1.GetValue(this._planDateControl.BaseControl) as List<DesignAction>;
// cacheValueChangedList.AddRange(valueChangedList);
// valueChangedList.Clear();
//}
//List<DesignAction> selectedChanged = null;
//List<DesignAction> cacheSelectedChanged = new List<DesignAction>();
//PropertyInfo pi2 = this._pptShiftControl.BaseControl.GetType().GetProperty("SelectedChanged");
//if (pi2 != null)
//{
// selectedChanged = pi2.GetValue(this._pptShiftControl.BaseControl) as List<DesignAction>;
// cacheSelectedChanged.AddRange(selectedChanged);
// selectedChanged.Clear();
//}
#endregion
//DataTable shiftTable = ProductHelper.GetShiftData();
//this._pptShiftControl.BaseControl.BindDataSource = shiftTable;
if (PlanHelper.PlanLog != null)
{
//如果记录了上次执行计划的时间和班次,则把日期和班次设置为上次的值
//this._planDateControl.BaseControl.MCValue = PlanHelper.PlanLog.LastDate;
//this._pptShiftControl.BaseControl.MCValue = PlanHelper.PlanLog.LastShiftID;
//this._planDateControl.BaseControl.MCValue = DateTime.Now.Date;
//this._pptShiftControl.BaseControl.MCValue = PlanHelper.PlanLog.LastShiftID;
#region 重新绑定事件
//if (pi1 != null && valueChangedList != null)
//{
// valueChangedList.AddRange(cacheValueChangedList);
//}
//if (pi2 != null && selectedChanged != null)
//{
// selectedChanged.AddRange(cacheSelectedChanged);
//}
#endregion
}
}
#endregion
#endregion
}
}