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.

117 lines
4.3 KiB
C#

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.BasicInfo;
using Mesnac.Action.Feeding.Sys;
namespace Mesnac.Action.Feeding.FeedingPlc
{
/// <summary>
/// 配方重传
/// </summary>
public class RecipeReset : FeedingAction, IAction
{
/// <summary>
/// 完成配方重传
/// </summary>
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);
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;
}
}
}
}
}