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;
namespace Mesnac.Action.ChemicalWeighing.Product.XlPlan
{
///
/// 移动计划抽象业务
///
public abstract class AbstractMoveAction : ChemicalWeighingAction
{
#region 事件定义
///
/// 移动计划事件
///
public static event EventHandler OnMovePlan;
#endregion
#region 方法定义
///
/// 移动计划
///
/// 运行时参数
/// 移动计划提示信息
/// 移动类型,Up上移,Down下移
public void MovePlan(RuntimeParameter runtime, string msg, MoveType moveType)
{
List errorList = new List();
//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.Error("{当班计划-移动计划} 缺少日期选择控件...");
// return;
//}
//if (pptShiftControl == null)
//{
// ICSharpCode.Core.LoggingService.Error("{当班计划-移动计划} 缺少班次组合框控件...");
// return;
//}
if (clientGridControl == null || !(clientGridControl.BaseControl is DataGridView))
{
ICSharpCode.Core.LoggingService.Error("{当班计划——移动计划}缺少本机台计划网格控件...");
return;
}
string planIds = String.Empty;
DataGridView clientGridView = clientGridControl.BaseControl as DataGridView;
if (clientGridView.SelectedRows.Count == 1)
{
DateTime ctlPlanDate = DateTime.Now;
int ctlShift = Global.PublicVar.Instance.globalShiftID;
//DateTime.TryParse(planDateControl.BaseControl.MCValue.ToString(), out ctlPlanDate);
//int.TryParse(pptShiftControl.BaseControl.MCValue.ToString(), out ctlShift);
string planId = clientGridView.SelectedRows[0].Cells["Plan_Id"].Value.ToString();
string plandate = clientGridView.SelectedRows[0].Cells["Plan_Date"].Value.ToString();
if (!plandate.Equals(ctlPlanDate.ToShortDateString()))
{
string msg1 = "不可移动非当前日期的计划!!";
MessageBox.Show(msg1, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
#region 验证(PLC中读取过来的planid对应的数据库中的计划必须是存在的)
xl_plan currentRT_Plan = Product.XlPlan.PlanHelper.GetPlanDataEntity(planId);
if (currentRT_Plan == null)
{
MessageBox.Show("删除异常,要删除的计划在数据库中丢失");
return;
}
#endregion
if (moveType == MoveType.Up)
{
#region 获取交换位置对象并判断是否可以上移(条件:在该条计划前,是否有一条未运行中的计划)并执行上移
int swagPlanSerial = (int)currentRT_Plan.Plan_Serial;
xl_plan swagRtPLan = Product.XlPlan.PlanHelper.GetPlanBySerialUp(swagPlanSerial);
if (swagRtPLan == null)
{
MessageBox.Show("不能上移");
return;
}
else
{
currentRT_Plan.Plan_Serial = swagRtPLan.Plan_Serial;
swagRtPLan.Plan_Serial = swagPlanSerial;
Product.XlPlan.PlanHelper.UpdatePlanSerial(currentRT_Plan);
Product.XlPlan.PlanHelper.UpdatePlanSerial(swagRtPLan);
#region 重新下传计划列表
//ChemicalWeighingPlc.PlcPlanHelper.PlanListReDown();
#endregion
}
#endregion
}
else if (moveType == MoveType.Down)
{
#region 获取交换位置对象并判断是否可以下移(条件:在该条计划后,是否有一条未运行中的计划)并执行下移
int swagPlanSerial = (int)currentRT_Plan.Plan_Serial;
xl_plan swagRtPLan = Product.XlPlan.PlanHelper.GetPlanBySerialDown(swagPlanSerial);
if (swagRtPLan == null)
{
MessageBox.Show("不能下移");
return;
}
else
{
currentRT_Plan.Plan_Serial = swagRtPLan.Plan_Serial;
swagRtPLan.Plan_Serial = swagPlanSerial;
Product.XlPlan.PlanHelper.UpdatePlanSerial(currentRT_Plan);
Product.XlPlan.PlanHelper.UpdatePlanSerial(swagRtPLan);
#region 重新下传计划列表
//ChemicalWeighingPlc.PlcPlanHelper.PlanListReDown();
#endregion
}
#endregion
}
#region 触发移动计划事件,在本机台网格控件中显示本机台计划
if (OnMovePlan != null)
{
OnMovePlan(runtime, System.EventArgs.Empty);
}
#endregion
}
}
#endregion
}
}