using System;
using System.Collections.Generic;
using System.Net.NetworkInformation;
using System.Text;
using System.Linq;
using System.Data;
using System.Threading;
using Mesnac.Action.Base;
using Mesnac.Controls.Base;
using System.Windows.Forms;
using Mesnac.Codd.Session;
using System.IO;
using Mesnac.Action.Feeding.Qingquan.BasicInfo;
using Mesnac.Action.Feeding.Qingquan.Sys;
namespace Mesnac.Action.Feeding.Qingquan.FeedingPlc
{
///
/// 配方重传
///
public class RecipeReset : FeedingAction, IAction
{
///
/// 完成配方重传
///
public static event EventHandler OnFinishRecipe;
public void Run(RuntimeParameter runtime)
{
base.LogDebug("配方重传...");
if (runtime.Sender is Control)
{
(runtime.Sender as Control).Enabled = false;
}
try
{
string msg = String.Empty;
#region 判断当班计划界面是否打开
//if (PlanCommon.IsInit == false)
//{
// msg = "当班计划还为初始化,请先打开当班计划,再进行此操作!";
// ShowMsg(msg, Language(1), MessageBoxButtons.OK, MessageBoxIcon.Information);
// return;
//}
#endregion
PlanLog planLog = PlanCommon.PlanLog;
if (planLog == null)
{
msg = "没有正在生产的计划,不能进行配方重传!";
ShowMsg(msg, Language(1), MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
PlanStates planStates = PlanCommon.GetPlanState(planLog.LastPlanID);
if (planStates != PlanStates.Producting)
{
msg = "当前计划未处于生产状态,不能进行配方重传!";
ShowMsg(msg, Language(1), MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (RecipeWeighCache.Instance.CacheFlag == true)
{
msg = "下一个计划的称量信息已下传,不允许配方重传...";
ShowMsg(msg, Language(1), MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (new PLCRecipe().RecipeReset() > 0)
{
//更新总重
double totalweight = PlanCommon.GetTotalWeightByPlanID(planLog.LastPlanID);
PlanCommon.UpdateTotalWeight(planLog.LastPlanID, totalweight);
// 把开始称量信号下传至PLC
//if (!new StartWeightToPlc().DownLoadStartWeight())
//{
// msg = "配方重传失败:把开始称量信号下传至PLC失败!";
// ShowMsg(msg, Language(1), MessageBoxButtons.OK, MessageBoxIcon.Information);
// return;
//}
//else
{
msg = "配方重传成功!";
//ShowMsg(msg, Language(1), MessageBoxButtons.OK, MessageBoxIcon.Information);
//记录数据库日志
//获取当前正在执行的计划
PlanLog log = PlanCommon.PlanLog;
string currentPlanId = String.Empty; //当前计划号
currentPlanId = log.LastPlanID;
string recipe_code = PlanCommon.GetRecipeCodeByPlanID(currentPlanId);
base.DBLog("配方管理", "配方重传", recipe_code + "重传成功");
Mesnac.Basic.MessageBoxTimeOut.Show(msg, Language(1), 3000);
//触发存盘完成事件
if (OnFinishRecipe != null)
{
OnFinishRecipe(null, EventArgs.Empty);
}
}
}
else
{
msg = "配方重传失败!";
ShowMsg(msg, Language(1), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
base.LogError(ex.Message);
base.LogError(ex.StackTrace);
string msg = "配方重传失败:" + ex.Message;
ShowMsg(msg, Language(1), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
{
if (runtime.Sender is Control)
{
(runtime.Sender as Control).Enabled = true;
}
}
}
}
}