using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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 System.Configuration;
using Mesnac.Action.ChemicalWeighing.Technical.PmtRecipe.entity;
using Mesnac.Action.ChemicalWeighing.Product.PptPlan.entity;
namespace Mesnac.Action.ChemicalWeighing.Product.PptPlan
{
///
/// 添加计划业务
///
public class InsertAction : ChemicalWeighingAction, IAction
{
#region 事件定义
///
/// 添加计划事件定义
///
public static event EventHandler OnInsertPlan;
#endregion
#region 字段定义
private RuntimeParameter _runtime;
//private DbMCControl _planDateControl = null; //计划日期
//private DbMCControl _pptShiftControl = null; //班次
private DbMCControl _clientGridControl = null; //网格计划控件
#endregion
#region IAction接口实现
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime);
this._runtime = runtime;
ICSharpCode.Core.LoggingService.Debug("当班计划—添加计划业务...");
//DbMCControl planDateControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "[RT_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, "Base_PlanInfo").FirstOrDefault(); //获取本机台计划网格控件
//if (planDateControl == null)
//{
// ICSharpCode.Core.LoggingService.Error("{当班计划-添加计划} 缺少日期选择控件...");
// return;
//}
//if (pptShiftControl == null)
//{
// ICSharpCode.Core.LoggingService.Error("{当班计划-添加计划} 缺少班次组合框控件...");
// return;
//}
//this._planDateControl = planDateControl;
//this._pptShiftControl = pptShiftControl;
this._clientGridControl = clientGridControl;
DateTime planDate = DateTime.Now;
//DateTime.TryParse(this._planDateControl.BaseControl.MCValue.ToString(), out planDate);
//int shiftID = Global.PublicVar.Instance.globalShiftID;
int shiftID = Product.ProductHelper.shiftIDAtuoRefresh();
//int.TryParse(this._pptShiftControl.BaseControl.MCValue.ToString(), out shiftID);
if (shiftID == 0)
{
string msg1 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Product_PptPlan_InsertAction_msg1")); //自动刷新班次号未生效!
MessageBox.Show(msg1, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
this._runtime.IsReturn = true;
return;
}
this.DoWork(planDate, shiftID);
}
#endregion
#region 方法定义
///
/// 添加计划
///
protected void DoWork(DateTime planDate, int shiftID)
{
DataGridView dataGridView = this._clientGridControl.BaseControl as DataGridView;
this._runtime.BaseControl.MCEnabled = false;
try
{
FrmPlan frmPlan = new FrmPlan(0);
frmPlan.ShowDialog(this._runtime.BaseControl.MCRoot as Control);
if (frmPlan.DialogResult == DialogResult.OK)
{
Base_PlanInfo recipe = frmPlan.PlanInfo;
recipe.plan_Team = shiftID.ToString();
int orderNumber = 0;
if (dataGridView.RowCount > 0)
{
orderNumber = Convert.ToInt32(dataGridView.Rows[dataGridView.RowCount - 1].Cells["plan_order"].Value);
}
recipe.plan_order = orderNumber + 1;
int planNum = frmPlan.PlanNum;
//在本地数据库中添加计划
string equipCode = string.Empty;
if (String.IsNullOrEmpty(equipCode))
{
equipCode = ConfigurationManager.AppSettings["EquipCode"];
}
string planID = PlanHelper.SaveBasePlanInfo(recipe);
#region 触发事件
if (OnInsertPlan != null)
{
OnInsertPlan(this._runtime.BaseControl.MCRoot, System.EventArgs.Empty);
}
#endregion
#region 将等待计划数写入PLC
//ChemicalWeighingPlc.PlcPlanHelper.WaitPlanNumToPLC();
#endregion
#region 重新下传计划列表
//ChemicalWeighingPlc.PlcPlanHelper.PlanListReDown();
#endregion
#region 记录日志
string logContent = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Product_PptPlan_InsertAction_logContent_10")); //计划编号:{0},添加完毕!
logContent = String.Format(logContent, planID);
//base.DBLog(logContent); cfm20210729暂时注释
#endregion
}
frmPlan.Dispose();
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService.Error("添加计划异常:" + ex.Message, ex);
#region 记录操作日志
base.DBLog(ex.Message);
#endregion
MessageBox.Show(ex.Message, Mesnac.Basic.LanguageHelper.WarnCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
this._runtime.BaseControl.MCEnabled = true;
}
#endregion
}
}