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.

202 lines
7.9 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.Threading.Tasks;
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 Mesnac.Action.ChemicalWeighing.Technical;
using Mesnac.Action.ChemicalWeighing.Entity.PptPlan;
using FastReport.Data;
using Mesnac.Action.ChemicalWeighing.XlPlcHelper;
namespace Mesnac.Action.ChemicalWeighing.Product.XlPlan
{
/// <summary>
/// 重传信息
/// </summary>
public class ReloadAction : ChemicalWeighingAction, IAction
{
#region 事件定义
/// <summary>
/// 手动下发计划
/// </summary>
public static event EventHandler OnRefreshPlan;
#endregion
#region 字段定义
public int MyProperty { get; set; }
private static bool IsFirstRun = true; //是否首次执行
private RuntimeParameter _runtime;
private DbMCControl _clientGridControl = null; //网格计划控件
string selectedPlanId = string.Empty; //选中的计划号
string selectedRecipeID = string.Empty;
bool flag=false;
#endregion
#region IAction接口实现
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须要调用的
this._runtime = runtime;
ICSharpCode.Core.LoggingService<RefreshAction>.Debug("重新下发计划—刷新计划业务...");
#region 重新下发计划
if (true)
{
DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "xl_plan").FirstOrDefault();
if (clientGridControl == null)
{
ICSharpCode.Core.LoggingService<StopAction>.Error("{生产计划-重传} 缺少计划列表网格控件...");
return;
}
this._runtime = runtime;
this._clientGridControl = clientGridControl;
DataGridView clientGridView = this._clientGridControl.BaseControl as DataGridView;
if (clientGridView.SelectedRows.Count != 1)
{
string msg1_1 = StringParser.Parse("请选择一条要重传的计划!"); //请选择一条要重传计划数的计划!
MessageBox.Show(msg1_1, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
this._runtime.IsReturn = true;
return;
}
string planState = clientGridView.SelectedRows[0].Cells["Plan_State"].Value.ToString();
if (planState == "8")
{
MessageBox.Show("该计划已完成,无法重传下发!", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (planState == "7")
{
MessageBox.Show("该计划已终止,无法重传下发!", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (planState == "5")
{
MessageBox.Show("该计划尚未重新开始,无法重传下发!", Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (planState == "3")
{
DialogResult dr = MessageBox.Show("该计划正在运行中,确认要重传吗?", "提示", MessageBoxButtons.OKCancel);
if (dr == DialogResult.OK) flag=true;
else return;
}
if (flag)
{
selectedPlanId = clientGridView.SelectedRows[0].Cells["Plan_Id"].Value as string;
bool IsExec = Product.XlPlan.PlanHelper.GetXlPlanState(selectedPlanId);//检查当前任务是否还处于执行中
if (IsExec)
{
MessageBox.Show("请确定该计划是否在执行中!");
ICSharpCode.Core.LoggingService<StopAction>.Error("{生产计划-重传计划} ");
return;
}
//获取选中计划、获取选中物料、
List<Xl_DowLoadPlan> materialList = XlPlan.PlanHelper.GetXlPlan(selectedPlanId);
//下传计划给PLC
int planNum = Convert.ToInt32(clientGridView.SelectedRows[0].Cells["Plan_Num"].Value as string);
bool IsSucess = PlcPlanHelper.RetransmissionXlPlanToPlc(planNum);
if (IsSucess)
{
MessageBox.Show("计划任务重传成功!");
ICSharpCode.Core.LoggingService<PlcPlanHelper>.Debug(String.Format("[{0}]计划重传完毕...", selectedPlanId));
}
else
{
MessageBox.Show("计划任务重传失败!请检查设备是否正常,设置计划数量是否正确。");
ICSharpCode.Core.LoggingService<PlcPlanHelper>.Debug(String.Format("[{0}]计划重传失败...", selectedPlanId));
}
IsFirstRun = false;
}
}
#endregion
this.DoWork();
}
#endregion
#region 方法定义
/// <summary>
/// 刷新计划
/// </summary>
protected void DoWork()
{
#region 业务实现
//int shiftID = Global.PublicVar.Instance.globalShiftID;
//int.TryParse(this._pptShiftControl.BaseControl.MCValue.ToString(), out shiftID);
string equipCode = base.CurrEquipCode; //当前机台
//DateTime selectedDate = Convert.ToDateTime(this._planDateControl.BaseControl.MCValue);
//DataTable table = PlanHelper.GetPlanData(selectedDate, shiftID);
//DataTable table = PlanHelper.GetPlanData(selectedDate);
DataTable table = PlanHelper.GetPlanData();
lock (String.Empty)
{
//本地计划
if (this._clientGridControl != null && this._clientGridControl.BaseControl != null)
{
this._clientGridControl.BaseControl.BindDataSource = null;
this._clientGridControl.BaseControl.BindDataSource = table;
#region 根据计划状态处理背景色
DataGridView clientGrid = this._clientGridControl.BaseControl as DataGridView;
PlanHelper.SetBackColor(clientGrid);
#endregion
}
else
{
ICSharpCode.Core.LoggingService<RefreshAction>.Warn("重传计划本地计划控件为Null...");
}
}
#endregion
#region 触发事件, 刷新客户端计划
Global.PublicVar.Instance.LocalPlanIsRefresh = true; //更新机台计划刷新标志
if (OnRefreshPlan != null)
{
OnRefreshPlan(this._runtime.BaseControl.MCRoot, System.EventArgs.Empty);
}
#endregion
}
#endregion
#region 事件处理方法
private void Process_Event(object sender, EventArgs e)
{
if (sender is RuntimeParameter)
{
this.Run(sender as RuntimeParameter);
}
else
{
this.Run(this._runtime);
}
}
#endregion
}
}