|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using Mesnac.Action.Base;
|
|
|
|
|
using Mesnac.Communication;
|
|
|
|
|
using Mesnac.Codd.Session;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using Mesnac.Action.Feeding.BasicInfo;
|
|
|
|
|
using Mesnac.Basic;
|
|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
|
|
|
|
|
namespace Mesnac.Action.Feeding.Socket
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Socket接收消息处理
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class StartReciveProcess : FeedingAction, IAction
|
|
|
|
|
{
|
|
|
|
|
#region 事件定义
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 刷新计划事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static event EventHandler OnRefreshPlan;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 刷新计划执行类型:单个、连续 事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static event EventHandler OnRefreshPlanExecuteType;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 换班后,刷新主机手信息事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static event EventHandler OnRefreshWorkerInfo;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 刷新有新新网络计划通知
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static event EventHandler OnRefreshNewNetNote;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 业务入口
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="runtime">参数</param>
|
|
|
|
|
public void Run(RuntimeParameter runtime)
|
|
|
|
|
{
|
|
|
|
|
base.RunIni(runtime);
|
|
|
|
|
TcpService.Instance.ProcessAcceptComplete += new EventHandler<SocketAsyncEventArgs>(Instance_ProcessAcceptComplete); //客户端连接完成事件
|
|
|
|
|
TcpService.Instance.ReceiveMsgHandler += new SocketListener.ReceiveMsgHandler(Instance_ReceiveMsgHandler); //接收到客户端消息的事件
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 业务处理
|
|
|
|
|
|
|
|
|
|
#region 客户端连接时,把当前计划列表发送给客户端
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 客户端连接时,把当前计划列表发送给客户端
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">客户端IP</param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void Instance_ProcessAcceptComplete(object sender, SocketAsyncEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (PlanCommon.PlanLog != null)
|
|
|
|
|
{
|
|
|
|
|
PlanCommon.SendInit(base.CurrEquipCode, PlanCommon.PlanLog.LastSelectDate, PlanCommon.PlanLog.LastSelectShiftID, PlanCommon.PlanLog.LastClassID, base.GetConfigValue("LastUserID", "0"));
|
|
|
|
|
//1、发送计划列表
|
|
|
|
|
//PlanCommon.SendNetPlanMsg(base.CurrEquipCode, PlanCommon.PlanLog.LastSelectDate, PlanCommon.PlanLog.LastSelectShiftID);
|
|
|
|
|
//2、发送当前计划号
|
|
|
|
|
//string netMsg = "{0}:{1}/";
|
|
|
|
|
//netMsg = String.Format(netMsg, Global.ProtocalHeader.ReceivePlanIdIpNumber, PlanCommon.PlanLog.LastPlanID);
|
|
|
|
|
//Mesnac.Communication.TcpService.Instance.NetSendMsg(netMsg);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string sbNetMsg = Global.ProtocalHeader.ReceivePlanIpNumber + ":/";
|
|
|
|
|
Mesnac.Communication.TcpService.Instance.NetSendMsg(sbNetMsg.ToString()); //发送网络消息
|
|
|
|
|
ICSharpCode.Core.LoggingService.Debug("没有计划日志!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 接收消息时的事件处理程序
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 接收消息时的事件处理程序
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="uid">客户端IP</param>
|
|
|
|
|
/// <param name="info">接收到的消息</param>
|
|
|
|
|
private void Instance_ReceiveMsgHandler(string uid, string info)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (!String.IsNullOrEmpty(info) && info.Length > 4)
|
|
|
|
|
{
|
|
|
|
|
string[] infoArrary = info.Split('/');
|
|
|
|
|
for (int i = 0; i < infoArrary.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(infoArrary[i]))
|
|
|
|
|
continue;
|
|
|
|
|
info = infoArrary[i]+"/";
|
|
|
|
|
string protocal = info.Substring(0, 4); //协议头
|
|
|
|
|
//System.Threading.Thread.Sleep(500);
|
|
|
|
|
string msg = info.Substring(4).Replace(":", string.Empty); //消息内容
|
|
|
|
|
switch (protocal)
|
|
|
|
|
{
|
|
|
|
|
case Global.ProtocalHeader.SendPlanIpNumber:
|
|
|
|
|
//客户端添加计划后,通知上辅机进行刷新。
|
|
|
|
|
this.ExecSendPlan(msg);
|
|
|
|
|
break;
|
|
|
|
|
case Global.ProtocalHeader.SelectPlanIpNumber:
|
|
|
|
|
//客户端查询对应日期、班次的本地计划信息
|
|
|
|
|
this.ExecSelectPlan(msg);
|
|
|
|
|
break;
|
|
|
|
|
case Global.ProtocalHeader.SendExcPlanIpNumber:
|
|
|
|
|
//客户端设置配方运行方式
|
|
|
|
|
this.ExecSendExcPlan(msg);
|
|
|
|
|
break;
|
|
|
|
|
case Global.ProtocalHeader.SendStopPlanIpNumber:
|
|
|
|
|
//客户端终止计划
|
|
|
|
|
this.ExecSendStopPlan();
|
|
|
|
|
break;
|
|
|
|
|
case Global.ProtocalHeader.SendResetInNumber:
|
|
|
|
|
//客户端配方重传
|
|
|
|
|
this.ExecSendReset();
|
|
|
|
|
break;
|
|
|
|
|
case Global.ProtocalHeader.SendWorkerBarcode:
|
|
|
|
|
//换班 胶料秤客户端发送的操作主手的员工编号
|
|
|
|
|
PlanCommon.IsShift = true;//交接班标记
|
|
|
|
|
this.ExecSendWorkerBarcode(msg);
|
|
|
|
|
break;
|
|
|
|
|
case Global.ProtocalHeader.SendMaterBarcode:
|
|
|
|
|
//扫描的架子条码
|
|
|
|
|
this.ExecSendMaterBarcode(msg);
|
|
|
|
|
break;
|
|
|
|
|
case Global.ProtocalHeader.SendAddPlanIpNumbar:
|
|
|
|
|
//客户端新增计划
|
|
|
|
|
this.ExecSendAddPlan(msg);
|
|
|
|
|
break;
|
|
|
|
|
case Global.ProtocalHeader.SendNetNewPlan:
|
|
|
|
|
//网络计划下达时,通知中控室机台有新计划下达
|
|
|
|
|
this.ExecSendNetNewPlan();
|
|
|
|
|
break;
|
|
|
|
|
case Global.ProtocalHeader.SendWareInfo:
|
|
|
|
|
//气力输送发送过来的日罐的料位信息
|
|
|
|
|
this.ExecSendWareInfo(msg);
|
|
|
|
|
break;
|
|
|
|
|
case Global.ProtocalHeader.SendBarRight:
|
|
|
|
|
// 胶料秤客户端扫描条码错误时发送,中控室上位机向plc设置报警位 置胶料秤报警灯
|
|
|
|
|
// DownLoadSetRubLamp(1);
|
|
|
|
|
this.ExecSendBarRight();
|
|
|
|
|
break;
|
|
|
|
|
case Global.ProtocalHeader.SendRepair:
|
|
|
|
|
//停机维修,设置维修标志
|
|
|
|
|
this.ExecSendRepair();
|
|
|
|
|
break;
|
|
|
|
|
case Global.ProtocalHeader.SendNewMessage:
|
|
|
|
|
//显示网络下发来的通知
|
|
|
|
|
this.ExecSendNewMessage(msg);
|
|
|
|
|
break;
|
|
|
|
|
case Global.ProtocalHeader.SendModifyPlanNum:
|
|
|
|
|
//客户端修改正在执行的计划车数,并下传到PLC
|
|
|
|
|
this.ExecSendModifyPlanNum(msg);
|
|
|
|
|
break;
|
|
|
|
|
case Global.ProtocalHeader.SendChanYong:
|
|
|
|
|
//把掺用物料添加到配方中,并下传至PLC
|
|
|
|
|
this.ExecSendChanYong(msg);
|
|
|
|
|
break;
|
|
|
|
|
case Global.ProtocalHeader.SendStopChanYong:
|
|
|
|
|
this.ExecSendStopChanYong();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Debug(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 业务处理辅助方法
|
|
|
|
|
|
|
|
|
|
#region 客户端添加计划后,通知上辅机进行刷新
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 客户端添加计划后,通知上辅机进行刷新
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="msg">客户端发送过来的计划列表,格式:date|shift|Name+code+set+finish+planId~Name+code+set+finish+planId........~</param>
|
|
|
|
|
private void ExecSendPlan(string msg)
|
|
|
|
|
{
|
|
|
|
|
this.SynchroPlanList(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 客户端查询对应日期、班次的本地计划信息
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 客户端查询对应日期、班次的本地计划信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="msg">客户端发送的消息,格式:SelectPlanIpNumber + ':' + G_PlanDate + '|' + G_ShiftID + '|' + G_ClassID + '|' + G_OperID + '/'</param>
|
|
|
|
|
private void ExecSelectPlan(string msg)
|
|
|
|
|
{
|
|
|
|
|
if (!String.IsNullOrEmpty(msg))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (msg.Substring(msg.Length - 1) != "/")
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Warn("客户端发送的消息格式不正确,正确格式:SelectPlanIpNumber + ':' + G_PlanDate + '|' + G_ShiftID + '|' + G_ClassID + '|' + G_OperID + '/'");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string[] strs = msg.Replace("/", string.Empty).Split(new char[] { '|' });
|
|
|
|
|
if (strs == null || strs.Length != 2)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Warn("客户端发送的消息式不正确,正确格式:SelectPlanIpNumber + ':' + G_PlanDate + '|' + G_ShiftID +'/'");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
DateTime planDate = Convert.ToDateTime(strs[0]);
|
|
|
|
|
int shiftID = Convert.ToInt32(strs[1]);
|
|
|
|
|
//int classID = Convert.ToInt32(strs[2]);
|
|
|
|
|
//int operID = Convert.ToInt32(strs[3]);
|
|
|
|
|
|
|
|
|
|
//发送计划列表
|
|
|
|
|
PlanCommon.SendNetPlanMsg(base.CurrEquipCode, planDate, shiftID, 0, base.GetConfigValue("LastUserID", "0"));
|
|
|
|
|
//交接班,保存当前班次信息
|
|
|
|
|
if (PlanCommon.IsShift)
|
|
|
|
|
{
|
|
|
|
|
PlanLog log = PlanCommon.PlanLog;
|
|
|
|
|
if (log == null)
|
|
|
|
|
{
|
|
|
|
|
log = new PlanLog();
|
|
|
|
|
}
|
|
|
|
|
log.LastSelectDate = planDate;
|
|
|
|
|
ICSharpCode.Core.LoggingService.Debug("辅值last日期:" + planDate);
|
|
|
|
|
log.LastSelectShiftID = shiftID;
|
|
|
|
|
//log.LastClassID = classID;
|
|
|
|
|
PlanCommon.PlanLog = log;
|
|
|
|
|
//刷新界面上的主机手信息
|
|
|
|
|
if (StartReciveProcess.OnRefreshWorkerInfo != null)
|
|
|
|
|
{
|
|
|
|
|
StartReciveProcess.OnRefreshWorkerInfo(null, System.EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
//刷新界面上的计划列表
|
|
|
|
|
if (StartReciveProcess.OnRefreshPlan != null)
|
|
|
|
|
{
|
|
|
|
|
StartReciveProcess.OnRefreshPlan(null, System.EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
PlanCommon.IsShift = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Error("Socket ExecSelectPlan 错误:" + ex.Message, ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 客户端设置配方运行方式
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 客户端设置配方运行方式
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="msg">格式:协议头:0/ 协议头:1/</param>
|
|
|
|
|
private void ExecSendExcPlan(string msg)
|
|
|
|
|
{
|
|
|
|
|
if (!String.IsNullOrEmpty(msg))
|
|
|
|
|
{
|
|
|
|
|
if (msg.Substring(msg.Length - 1) != "/")
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Warn("客户端发送的消息格式不正确,正确格式:SelectPlanIpNumber + ':' + G_PlanDate + '|' + G_ShiftID + '|' + G_ClassID + '|' + G_OperID + '/'");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int execPlanType = Convert.ToInt32(msg.Replace("/", String.Empty).Replace(":", string.Empty));
|
|
|
|
|
RunSchema.Instance.UpdateNodeValueToRunSchema("PlanExecuteType", execPlanType.ToString());
|
|
|
|
|
|
|
|
|
|
ProducingPlan.ExecutePlan execplan = new ProducingPlan.ExecutePlan();
|
|
|
|
|
execplan.PlanExecute(PlanCommon.ExecClass, PlanCommon.ExecShift, PlanCommon.ExecDate);
|
|
|
|
|
|
|
|
|
|
//刷新界面
|
|
|
|
|
if (StartReciveProcess.OnRefreshPlanExecuteType != null)
|
|
|
|
|
{
|
|
|
|
|
StartReciveProcess.OnRefreshPlanExecuteType(null, System.EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Error("解析客户端设置计划运行方式失败:" + ex.Message, ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 客户端终止计划
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 客户端终止计划
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void ExecSendStopPlan()
|
|
|
|
|
{
|
|
|
|
|
new FeedingPlc.PausePlan().ExecPause();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 客户端配方重传
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 客户端配方重传
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void ExecSendReset()
|
|
|
|
|
{
|
|
|
|
|
string msg = String.Empty;
|
|
|
|
|
PlanLog planLog = PlanCommon.PlanLog;
|
|
|
|
|
if (planLog == null)
|
|
|
|
|
{
|
|
|
|
|
msg = "没有正在生产的计划,不能进行配方重传!";
|
|
|
|
|
ICSharpCode.Core.LoggingService.Info(msg);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
PlanStates planStates = PlanCommon.GetPlanState(planLog.LastPlanID);
|
|
|
|
|
if (planStates != PlanStates.Producting)
|
|
|
|
|
{
|
|
|
|
|
msg = "当前计划未处于生产状态,不能进行配方重传!";
|
|
|
|
|
ICSharpCode.Core.LoggingService.Info(msg);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (new PLCRecipe().RecipeReset() > 0)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Info("配方重传成功!");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Error("配方重传失败!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 换班 胶料秤客户端发送的操作主手的员工编号
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 换班 胶料秤客户端发送的操作主手的员工编号
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="msg">换班的主机手编号</param>
|
|
|
|
|
private void ExecSendWorkerBarcode(string msg)
|
|
|
|
|
{
|
|
|
|
|
if (!String.IsNullOrEmpty(msg))
|
|
|
|
|
{
|
|
|
|
|
if (msg.Substring(msg.Length - 1) != "/")
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Warn("客户端发送的消息格式不正确,正确格式:协议头 + ':' + HRCode + '/'");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string hrCode = msg.Replace("/", String.Empty); //获取主机手编号
|
|
|
|
|
string hrName = String.Empty;
|
|
|
|
|
if (base.NetType == NetTypes.Net)
|
|
|
|
|
{
|
|
|
|
|
//如果是网络版获取主机手名称
|
|
|
|
|
hrName = this.GetUserNameByHRCode(hrCode);
|
|
|
|
|
}
|
|
|
|
|
//更新配置文件(RunSchema.xml)中当前主机手编号和主机手名称
|
|
|
|
|
RunSchema.Instance.UpdateNodeValueToRunSchema("LastUserID", hrCode);
|
|
|
|
|
RunSchema.Instance.UpdateNodeValueToRunSchema("LastUserName", hrName);
|
|
|
|
|
//刷新界面
|
|
|
|
|
//if (StartReciveProcess.OnRefreshWorkerInfo != null)
|
|
|
|
|
//{
|
|
|
|
|
// StartReciveProcess.OnRefreshWorkerInfo(null, System.EventArgs.Empty);
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Error("解析客户端设置计划运行方式失败:" + ex.Message, ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 扫描架子条码
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 扫描架子条码
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="msg"></param>
|
|
|
|
|
private void ExecSendMaterBarcode(string msg)
|
|
|
|
|
{
|
|
|
|
|
PlanCommon.GetScanBarcode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 客户端新增计划
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 客户端新增计划
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="msg"></param>
|
|
|
|
|
private void ExecSendAddPlan(string msg)
|
|
|
|
|
{
|
|
|
|
|
//预留
|
|
|
|
|
ICSharpCode.Core.LoggingService.Debug("预留方法!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 网络计划下达时,通知中控室机台有新计划下达
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 网络计划下达时,通知中控室机台有新计划下达
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void ExecSendNetNewPlan()
|
|
|
|
|
{
|
|
|
|
|
if (StartReciveProcess.OnRefreshNewNetNote != null)
|
|
|
|
|
{
|
|
|
|
|
string msg = String.Format("{0}网络有新计划下达", DateTime.Now);
|
|
|
|
|
StartReciveProcess.OnRefreshNewNetNote(msg, System.EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 气力输送发送过来的日罐的料位信息
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 气力输送发送过来的日罐的料位信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="msg"></param>
|
|
|
|
|
private void ExecSendWareInfo(string msg)
|
|
|
|
|
{
|
|
|
|
|
//预留
|
|
|
|
|
ICSharpCode.Core.LoggingService.Debug("预留方法!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 胶料秤客户端扫描条码错误时发送,中控室上位机向plc设置报警位 置胶料秤报警灯
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 胶料秤客户端扫描条码错误时发送,中控室上位机向plc设置报警位 置胶料秤报警灯
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void ExecSendBarRight()
|
|
|
|
|
{
|
|
|
|
|
//预留
|
|
|
|
|
ICSharpCode.Core.LoggingService.Debug("预留方法!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 维修
|
|
|
|
|
|
|
|
|
|
private void ExecSendRepair()
|
|
|
|
|
{
|
|
|
|
|
//预留
|
|
|
|
|
ICSharpCode.Core.LoggingService.Debug("预留方法!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 显示Socket通知
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 显示Socket通知
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="msg">发送的通知内容</param>
|
|
|
|
|
private void ExecSendNewMessage(string msg)
|
|
|
|
|
{
|
|
|
|
|
if (StartReciveProcess.OnRefreshNewNetNote != null)
|
|
|
|
|
{
|
|
|
|
|
StartReciveProcess.OnRefreshNewNetNote(msg, System.EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 客户端修改生产车数,并下传至PLC
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 客户端修改生产车数,并下传至PLC
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="msg">客户端发送的Socket指令,格式:协议头:PlanID:PlanNum/</param>
|
|
|
|
|
private void ExecSendModifyPlanNum(string msg)
|
|
|
|
|
{
|
|
|
|
|
if (base.NetType == NetTypes.Net)
|
|
|
|
|
{
|
|
|
|
|
if (!String.IsNullOrEmpty(msg))
|
|
|
|
|
{
|
|
|
|
|
if (msg.Substring(msg.Length - 1) != "/")
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Warn("客户端发送的消息格式不正确,正确格式:协议头 + ':' + PlanID + ':' + PlanNum + '/'");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string[] values = msg.Split(new char[] { ':' });
|
|
|
|
|
if (values == null || values.Length != 2)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Warn("客户端发送的消息格式不正确,正确格式:协议头 + ':' + PlanID + ':' + PlanNum + '/'");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string planId = values[0];
|
|
|
|
|
int planNum = Convert.ToInt32(values[1].Replace("/", String.Empty));
|
|
|
|
|
new FeedingPlc.ModifyPlanNum().SimpleModifyPlanNum(planId, planNum);
|
|
|
|
|
//刷新当班计划界面
|
|
|
|
|
if (StartReciveProcess.OnRefreshPlan != null)
|
|
|
|
|
{
|
|
|
|
|
StartReciveProcess.OnRefreshPlan(null, System.EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Warn("客户端修改生产车数失败:" + ex.Message, ex);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 把掺用物料添加到配方中,并下传至PLC
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 把掺用物料添加到配方中,并下传至PLC
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="msg">要掺用的物料编码</param>
|
|
|
|
|
private void ExecSendChanYong(string msg)
|
|
|
|
|
{
|
|
|
|
|
if (base.NetType != NetTypes.Net)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//防止并发执行
|
|
|
|
|
lock (String.Empty)
|
|
|
|
|
{
|
|
|
|
|
string downFlag = this.GetDownFlag();
|
|
|
|
|
if (downFlag.CompareTo("1") > 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.ModifyAndDownLoadPF(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 停止掺用物料
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 停止掺用物料
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void ExecSendStopChanYong()
|
|
|
|
|
{
|
|
|
|
|
string downFlag = String.Empty;
|
|
|
|
|
string strSql = String.Empty;
|
|
|
|
|
PlanLog log = PlanCommon.PlanLog;
|
|
|
|
|
|
|
|
|
|
if (base.NetType != NetTypes.Net)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
lock (String.Empty)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
downFlag = this.GetDownFlag();
|
|
|
|
|
if (downFlag != "3")
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//1、更新下传标志
|
|
|
|
|
DbHelper localHelper = base.NewDbHelper(DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (localHelper == null)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Error("修改下传配方失败:获取本地数据连接失败!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
localHelper.CommandType = CommandType.Text;
|
|
|
|
|
localHelper.ClearParameter();
|
|
|
|
|
strSql = "update pmt_ChanYong set Download_Flag = '4'";
|
|
|
|
|
localHelper.CommandText = strSql;
|
|
|
|
|
localHelper.ExecuteNonQuery();
|
|
|
|
|
|
|
|
|
|
//2、从网络获取最新配方并下传
|
|
|
|
|
if (log == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
List<string> msgList = null;
|
|
|
|
|
int result = new BasicInfo.PLCRecipe().SendPlan(log.LastPlanID, out msgList);
|
|
|
|
|
if (result != 1)
|
|
|
|
|
{
|
|
|
|
|
base.LogError("配方下传失败...");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//3、清空掺用物料
|
|
|
|
|
localHelper.ClearParameter();
|
|
|
|
|
strSql = "truncate table pmt_ChanYong";
|
|
|
|
|
localHelper.CommandText = strSql;
|
|
|
|
|
localHelper.ExecuteNonQuery();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Error(ex.Message, ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 辅助方法
|
|
|
|
|
|
|
|
|
|
#region 解析客户端发送的计划列表
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 解析客户端发送的计划列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="msg">客户端发送过来的计划列表,格式:date|shift|Name+code+set+finish+planId~Name+code+set+finish+planId......../</param>
|
|
|
|
|
/// <returns>返回解析的计划列表</returns>
|
|
|
|
|
public List<SimplePlan> ParsePlanFromMsg(string msg)
|
|
|
|
|
{
|
|
|
|
|
List<SimplePlan> planList = new List<SimplePlan>();
|
|
|
|
|
if (!String.IsNullOrEmpty(msg))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (msg.Substring(msg.Length - 1) != "/")
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Warn("客户端发送的计划列表格式不正确,正确格式:date|shift|Name+code+set+finish+planId~Name+code+set+finish+planId......../_1");
|
|
|
|
|
return planList;
|
|
|
|
|
}
|
|
|
|
|
string[] strs = msg.Replace(":", string.Empty).Split(new char[] { '|' });
|
|
|
|
|
if (strs == null || strs.Length != 3)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Warn("客户端发送的计划列表格式不正确,正确格式:date|shift|Name+code+set+finish+planId~Name+code+set+finish+planId......../_2");
|
|
|
|
|
return planList;
|
|
|
|
|
}
|
|
|
|
|
DateTime planDate = Convert.ToDateTime(strs[0]); //获取计划日期
|
|
|
|
|
PlanCommon.ExecDate = strs[0];
|
|
|
|
|
int shifID = Convert.ToInt32(strs[1]); //获取班次
|
|
|
|
|
PlanCommon.ExecShift = strs[1];
|
|
|
|
|
//int classID = Convert.ToInt32(strs[2]);
|
|
|
|
|
//PlanCommon.ExecClass = strs[2];
|
|
|
|
|
//string userID = strs[3];
|
|
|
|
|
strs[2] = strs[2].Replace("/", String.Empty);
|
|
|
|
|
string[] temps = strs[2].Split(new char[] { '~' });
|
|
|
|
|
if (temps != null && temps.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
SimplePlan plan = null;
|
|
|
|
|
for (int i = 0; i < temps.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
string[] planData = temps[i].Replace("/", String.Empty).Split(new char[] { '+' });
|
|
|
|
|
if (planData == null || planData.Length != 5)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Warn("客户端发送的计划列表格式不正确,正确格式:date|shift|Name+code+set+finish+planId~Name+code+set+finish+planId......../_3");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
plan = new SimplePlan();
|
|
|
|
|
plan.PlanDate = planDate; //计划日期
|
|
|
|
|
plan.ShiftID = shifID; //班次
|
|
|
|
|
//plan.ClassID = classID;
|
|
|
|
|
plan.RecipeMaterialName = planData[0]; //物料名称
|
|
|
|
|
plan.RecipeMaterialCode = planData[1]; //物料代码
|
|
|
|
|
plan.PlanNum = Convert.ToInt32(planData[2]); //计划车数
|
|
|
|
|
string strRealNum = planData[3];
|
|
|
|
|
if (planData[3].IndexOf("[") > 0)
|
|
|
|
|
{
|
|
|
|
|
strRealNum = planData[3].Substring(0, planData[3].IndexOf("["));
|
|
|
|
|
}
|
|
|
|
|
plan.RealNum = Convert.ToInt32(strRealNum); //完成车数
|
|
|
|
|
plan.PlanID = planData[4]; //计划ID
|
|
|
|
|
//plan.UserID = userID;
|
|
|
|
|
|
|
|
|
|
planList.Add(plan);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//如果没有计划,则删除当前所有计划
|
|
|
|
|
if (planList.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
PlanCommon.DelCurrentPlan(base.CurrEquipCode, planDate, shifID);
|
|
|
|
|
//刷新界面上的计划列表
|
|
|
|
|
if (StartReciveProcess.OnRefreshPlan != null)
|
|
|
|
|
{
|
|
|
|
|
StartReciveProcess.OnRefreshPlan(null, System.EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Error("解析客户端发送的计划列表错误:" + ex.Message, ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return planList;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 获取配方ID
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取配方ID
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="equipCode">机台号</param>
|
|
|
|
|
/// <param name="recipeMaterialCode">配方物料编码</param>
|
|
|
|
|
/// <param name="recipeMaterialName">配方物料名称</param>
|
|
|
|
|
/// <returns>返回配方ID,获取失败返回0</returns>
|
|
|
|
|
public int GetRecipeID(string equipCode, string recipeMaterialCode, string recipeMaterialName)
|
|
|
|
|
{
|
|
|
|
|
DbHelper localHelper = base.NewDbHelper(Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (localHelper == null)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Error("获取配方ID失败:获取本地数据连接失败!");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
localHelper.CommandType = System.Data.CommandType.Text;
|
|
|
|
|
localHelper.ClearParameter();
|
|
|
|
|
string strSql = "select ObjID from pmt_recipe where equip_code = @RecipeEquipCode and mater_code = @RecipeMaterialCode and mater_name = @RecipeMaterialName";
|
|
|
|
|
localHelper.CommandText = strSql;
|
|
|
|
|
localHelper.AddParameter("@RecipeEquipCode", equipCode);
|
|
|
|
|
localHelper.AddParameter("@RecipeMaterialCode", recipeMaterialCode);
|
|
|
|
|
localHelper.AddParameter("@RecipeMaterialName", recipeMaterialName);
|
|
|
|
|
object result = localHelper.ToScalar();
|
|
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
|
|
{
|
|
|
|
|
return Convert.ToInt32(result);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 同步客户端发送的计划列表,支持客户端添加、删除、上移、下移
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 同步客户端发送的计划列表,支持客户端添加、删除、上移、下移
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="msg">客户端发送的计划列表</param>
|
|
|
|
|
public void SynchroPlanList(string msg)
|
|
|
|
|
{
|
|
|
|
|
List<string> errorList = new List<string>();
|
|
|
|
|
//1、解析计划列表
|
|
|
|
|
List<SimplePlan> planList = this.ParsePlanFromMsg(msg);
|
|
|
|
|
if (planList == null || planList.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
//如果是NULL全部删除本地当班计划
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
DateTime planDate = planList[0].PlanDate;
|
|
|
|
|
int shiftId = planList[0].ShiftID;
|
|
|
|
|
//2、判断是网络版还是单机版
|
|
|
|
|
if (base.NetType == NetTypes.Net)
|
|
|
|
|
{
|
|
|
|
|
//网络版
|
|
|
|
|
foreach (SimplePlan plan in planList)
|
|
|
|
|
{
|
|
|
|
|
//如果本地表中没有计划则从网络接收计划
|
|
|
|
|
if (!PlanCommon.PlanExists(Basic.DataSourceFactory.MCDbType.Local, base.CurrEquipCode, plan.PlanID))
|
|
|
|
|
{
|
|
|
|
|
PlanCommon.RecivePlan(plan.PlanID, base.CurrEquipCode, plan.PlanDate, plan.ShiftID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//单机版
|
|
|
|
|
foreach (SimplePlan plan in planList)
|
|
|
|
|
{
|
|
|
|
|
//如果本地表中没有计划则添加计划
|
|
|
|
|
if (!PlanCommon.PlanExists(Basic.DataSourceFactory.MCDbType.Local, base.CurrEquipCode, plan.PlanID))
|
|
|
|
|
{
|
|
|
|
|
int recipeObjId = this.GetRecipeID(base.CurrEquipCode.Substring(3, 2), plan.RecipeEquipCode, plan.RecipeMaterialName);
|
|
|
|
|
PlanLog log = PlanCommon.PlanLog;
|
|
|
|
|
if (log != null)
|
|
|
|
|
{
|
|
|
|
|
plan.ClassID = log.LastClassID;
|
|
|
|
|
}
|
|
|
|
|
PlanCommon.AddPlan(Basic.DataSourceFactory.MCDbType.Local, base.CurrEquipCode, plan.PlanDate, plan.ShiftID, plan.ClassID, recipeObjId.ToString(),0, plan.PlanNum, out errorList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//3、获取当班计划列表,如果客户端发送的计划列表中没有,则删除本地库的计划
|
|
|
|
|
DataTable table = PlanCommon.GetPlanData(Basic.DataSourceFactory.MCDbType.Local, base.CurrEquipCode, planDate, shiftId);
|
|
|
|
|
if (table != null && table.Rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (DataRow row in table.Rows)
|
|
|
|
|
{
|
|
|
|
|
string planId = row["PlanID"] as string;
|
|
|
|
|
bool flag = false;
|
|
|
|
|
foreach (SimplePlan plan in planList)
|
|
|
|
|
{
|
|
|
|
|
if (planId.Trim() == plan.PlanID.Trim())
|
|
|
|
|
{
|
|
|
|
|
flag = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//如果客户端发送的计划列表中没有此计划
|
|
|
|
|
if (!flag)
|
|
|
|
|
{
|
|
|
|
|
PlanStates planState = PlanCommon.GetPlanState(planId);
|
|
|
|
|
if (planState != PlanStates.Producting && planState != PlanStates.Completed)
|
|
|
|
|
{
|
|
|
|
|
//在本地库中删除此计划
|
|
|
|
|
PlanCommon.DeleteByPlanID(planId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//4、对更新本地计划列表排序
|
|
|
|
|
for (int i = 0; i < planList.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
PlanCommon.UpdateActionOrder(planList[i].PlanID, i + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//5、刷新界面上的计划列表
|
|
|
|
|
if (StartReciveProcess.OnRefreshPlan != null)
|
|
|
|
|
{
|
|
|
|
|
StartReciveProcess.OnRefreshPlan(null, System.EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 从网络库中获取主机手名
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 从网络库中获取主机手名
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="hrCode">主机手的HRCode</param>
|
|
|
|
|
/// <returns>返回对应主机手的名称</returns>
|
|
|
|
|
public string GetUserNameByHRCode(string hrCode)
|
|
|
|
|
{
|
|
|
|
|
DbHelper serverHelper = base.NewDbHelper(DataSourceFactory.MCDbType.Server);
|
|
|
|
|
if (serverHelper == null)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Error("从网络库中获取主机手名失败:获取网络数据连接失败!");
|
|
|
|
|
return String.Empty;
|
|
|
|
|
}
|
|
|
|
|
serverHelper.CommandType = CommandType.Text;
|
|
|
|
|
serverHelper.ClearParameter();
|
|
|
|
|
//string strSql = "select UserName from BasUser where HRCode = @HRCode";
|
|
|
|
|
string strSql = "select top 1 [USER_NAME] from SYS_USER where Worker_barcode=@HRCode";
|
|
|
|
|
serverHelper.CommandText = strSql;
|
|
|
|
|
serverHelper.AddParameter("@HRCode", hrCode);
|
|
|
|
|
object result = serverHelper.ToScalar();
|
|
|
|
|
if (result == null || result == System.DBNull.Value)
|
|
|
|
|
{
|
|
|
|
|
return String.Empty;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return result.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 从本地库的pmt_ChanYong表中取出掺用标志
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取下传标志
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>成功返回掺用标志,失败返回String.Empty</returns>
|
|
|
|
|
public string GetDownFlag()
|
|
|
|
|
{
|
|
|
|
|
DbHelper localHelper = base.NewDbHelper(DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (localHelper == null)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Error("获取掺用标志失败:获取本地数据连接失败!");
|
|
|
|
|
return String.Empty;
|
|
|
|
|
}
|
|
|
|
|
localHelper.CommandType = CommandType.Text;
|
|
|
|
|
localHelper.ClearParameter();
|
|
|
|
|
string strSql = "select top 1 Download_Flag from pmt_ChanYong";
|
|
|
|
|
localHelper.CommandText = strSql;
|
|
|
|
|
object result = localHelper.ToScalar();
|
|
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
|
|
{
|
|
|
|
|
return result.ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return String.Empty;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 添加掺用物料,修改配方
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 添加掺用物料,修改配方
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="materCode"></param>
|
|
|
|
|
public void ModifyAndDownLoadPF(string materCode)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string cyType = "1"; //定义掺用类型变量
|
|
|
|
|
string cyWeight = "0"; //掺用重量
|
|
|
|
|
string smatercode = String.Empty;
|
|
|
|
|
string edtCode = "1"; //配方版本号
|
|
|
|
|
string weightID = "1"; //称量序号
|
|
|
|
|
string mWeightId = String.Empty; //
|
|
|
|
|
string materName = String.Empty; //物料名称
|
|
|
|
|
|
|
|
|
|
object result = null; //保存临时结果
|
|
|
|
|
PlanLog log = null; //当前计划日志
|
|
|
|
|
materCode = materCode.Replace("/", String.Empty);
|
|
|
|
|
string strSql = String.Empty;
|
|
|
|
|
//1、更新下传标志
|
|
|
|
|
DbHelper localHelper = base.NewDbHelper(DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (localHelper == null)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Error("修改下传配方失败:获取本地数据连接失败!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
localHelper.CommandType = CommandType.Text;
|
|
|
|
|
localHelper.ClearParameter();
|
|
|
|
|
strSql = "update pmt_ChanYong set Download_Flag = '1'";
|
|
|
|
|
localHelper.CommandText = strSql;
|
|
|
|
|
localHelper.ExecuteNonQuery();
|
|
|
|
|
|
|
|
|
|
//获取物料名称
|
|
|
|
|
localHelper.ClearParameter();
|
|
|
|
|
strSql = "select mater_name from pmt_material where mater_code = @mater_code";
|
|
|
|
|
localHelper.CommandText = strSql;
|
|
|
|
|
localHelper.AddParameter("@mater_code", materCode);
|
|
|
|
|
result = localHelper.ToScalar();
|
|
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
|
|
{
|
|
|
|
|
materName = result.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//2、获取掺用类型,掺用类型 1代表不掺用,2计重掺用,3不计重掺用
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
localHelper.ClearParameter();
|
|
|
|
|
strSql = "select * from Pmt_ChanYong where mater_Code= @mater_code";
|
|
|
|
|
localHelper.CommandText = strSql;
|
|
|
|
|
localHelper.AddParameter("@mater_code", materCode);
|
|
|
|
|
DataTable table = localHelper.ToDataTable();
|
|
|
|
|
if (table != null && table.Rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
cyType = Mesnac.Basic.DataProcessor.RowValue(table.Rows[0], "ChanYong_Type", "0");
|
|
|
|
|
cyWeight = Mesnac.Basic.DataProcessor.RowValue(table.Rows[0], "ChangYong_Weight", 0).ToString();
|
|
|
|
|
smatercode = Mesnac.Basic.DataProcessor.RowValue(table.Rows[0], "smater_Code", String.Empty);
|
|
|
|
|
}
|
|
|
|
|
if (cyType.CompareTo("2") < 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//3、获取当前计划的配方版本号
|
|
|
|
|
log = PlanCommon.PlanLog;
|
|
|
|
|
if (log == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
localHelper.ClearParameter();
|
|
|
|
|
strSql = "select edt_code from ppt_plan where plan_id = @PlanID";
|
|
|
|
|
localHelper.CommandText = strSql;
|
|
|
|
|
localHelper.AddParameter("@PlanID", log.LastPlanID);
|
|
|
|
|
result = localHelper.ToScalar();
|
|
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
|
|
{
|
|
|
|
|
edtCode = result.ToString().Trim();
|
|
|
|
|
}
|
|
|
|
|
//4、修改配方
|
|
|
|
|
weightID = "1";
|
|
|
|
|
string recipeMaterialCode = String.Empty; //计划配方对应的物料编码
|
|
|
|
|
DataRow planRow = PlanCommon.GetPlanData(DataSourceFactory.MCDbType.Local, log.LastPlanID);
|
|
|
|
|
if (planRow != null)
|
|
|
|
|
{
|
|
|
|
|
recipeMaterialCode = planRow["RecipeMaterialCode"] as string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
localHelper.ClearParameter();
|
|
|
|
|
strSql = "select max(weight_id) from pmt_weigh where father_code = @father_code and equip_code = @equip_code and edt_code = @edt_code and weigh_type = 2";
|
|
|
|
|
localHelper.CommandText = strSql;
|
|
|
|
|
localHelper.AddParameter("@father_code", recipeMaterialCode);
|
|
|
|
|
localHelper.AddParameter("@equip_code", base.CurrEquipCode.Substring(3, 2));
|
|
|
|
|
localHelper.AddParameter("@edt_code", edtCode);
|
|
|
|
|
result = localHelper.ToScalar();
|
|
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
|
|
{
|
|
|
|
|
weightID = (Convert.ToInt32(result.ToString().Trim()) + 1).ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cyType == "2") //计重掺用,配方内掺用
|
|
|
|
|
{
|
|
|
|
|
localHelper.ClearParameter();
|
|
|
|
|
strSql = "select top 1 Weight_id from pmt_weigh where father_code= @father_code and equip_code= @equip_code and edt_code= @edt_code and weigh_type=2 and child_code>'2' order by Set_weight desc";
|
|
|
|
|
localHelper.CommandText = strSql;
|
|
|
|
|
localHelper.AddParameter("@father_code", recipeMaterialCode);
|
|
|
|
|
localHelper.AddParameter("@equip_code", base.CurrEquipCode.Substring(3, 2));
|
|
|
|
|
localHelper.AddParameter("@edt_code", edtCode);
|
|
|
|
|
result = localHelper.ToScalar();
|
|
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
|
|
{
|
|
|
|
|
mWeightId = result.ToString().Trim();
|
|
|
|
|
if (String.IsNullOrEmpty(mWeightId))
|
|
|
|
|
{
|
|
|
|
|
mWeightId = "1";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
strSql = "update pmt_weigh set set_weight=set_weight-{0} where weight_id={1} and father_code='{2}' and equip_code='{3}' and edt_code='{4}' and weigh_type=2;";
|
|
|
|
|
strSql = String.Format(strSql, cyWeight, mWeightId, recipeMaterialCode, base.CurrEquipCode.Substring(3, 2), edtCode);
|
|
|
|
|
}
|
|
|
|
|
else if (cyType == "3") //不计重掺用,配方外掺用
|
|
|
|
|
{
|
|
|
|
|
strSql = "update pmt_recipe set total_weight = total_weight + {0} where mater_code='{1}' and equip_code='{2}' and edt_code='{3}';";
|
|
|
|
|
strSql = String.Format(strSql, cyWeight, recipeMaterialCode, base.CurrEquipCode.Substring(3, 2), edtCode);
|
|
|
|
|
}
|
|
|
|
|
strSql += "insert into pmt_weigh(RecipeObjID,weight_id,father_code,equip_code,edt_code,weigh_type,act_code,child_code,child_name,set_weight,error_allow,ChanYong_Flag)";
|
|
|
|
|
strSql += " values(@RecipeObjID,@weight_id,@father_code,@equip_code,@edt_code,2,0,@child_code,@child_name,@set_weight,0.5,'1')";
|
|
|
|
|
localHelper.ClearParameter();
|
|
|
|
|
localHelper.CommandText = strSql;
|
|
|
|
|
localHelper.AddParameter("@RecipeObjID", RecipeCache.Instance.RecipeInfo.ObjID);
|
|
|
|
|
localHelper.AddParameter("@weight_id", weightID);
|
|
|
|
|
localHelper.AddParameter("@father_code", recipeMaterialCode);
|
|
|
|
|
localHelper.AddParameter("@equip_code", base.CurrEquipCode.Substring(3, 2));
|
|
|
|
|
localHelper.AddParameter("@edt_code", edtCode);
|
|
|
|
|
localHelper.AddParameter("@child_code", materCode);
|
|
|
|
|
localHelper.AddParameter("@child_name", materName);
|
|
|
|
|
localHelper.AddParameter("@set_weight", cyWeight);
|
|
|
|
|
localHelper.ExecuteNonQuery();
|
|
|
|
|
|
|
|
|
|
//配方重传
|
|
|
|
|
if (new PLCRecipe().RecipeReset() > 0)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Info("掺用配方下传成功!");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Error("掺用配方下传失败!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//更新下传标志
|
|
|
|
|
localHelper.ClearParameter();
|
|
|
|
|
strSql = "update pmt_ChanYong set Download_Flag = '2'";
|
|
|
|
|
localHelper.CommandText = strSql;
|
|
|
|
|
localHelper.ExecuteNonQuery();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Error("修改下传配方失败:" + ex.Message, ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|