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.

164 lines
6.4 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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
{
/// <summary>
/// 移动计划抽象业务
/// </summary>
public abstract class AbstractMoveAction : ChemicalWeighingAction
{
#region 事件定义
/// <summary>
/// 移动计划事件
/// </summary>
public static event EventHandler OnMovePlan;
#endregion
#region 方法定义
/// <summary>
/// 移动计划
/// </summary>
/// <param name="runtime">运行时参数</param>
/// <param name="msg">移动计划提示信息</param>
/// <param name="moveType">移动类型Up上移,Down下移</param>
public void MovePlan(RuntimeParameter runtime, string msg, MoveType moveType)
{
List<string> errorList = new List<string>();
//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<InsertAction>.Error("{当班计划-移动计划} 缺少日期选择控件...");
// return;
//}
//if (pptShiftControl == null)
//{
// ICSharpCode.Core.LoggingService<InsertAction>.Error("{当班计划-移动计划} 缺少班次组合框控件...");
// return;
//}
if (clientGridControl == null || !(clientGridControl.BaseControl is DataGridView))
{
ICSharpCode.Core.LoggingService<AbstractMoveAction>.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
}
}