using System;
using System.Collections;
using System.Collections.Generic;
using ICSSoft.Frame.Data.Entity;
using System.Linq;
using System.Data.Linq;
using System.Xml.Linq;
using ICSSoft.Base.Config.AppConfig;
using ICSSoft.Frame.DataCollect;
using ICSSoft.Frame.Helper;
using System.Windows.Forms;
namespace ICSSoft.Frame.DataConnect.Action
{
///
/// 归属工单采集
///
public class ActionTS : IActionWithStatus
{
private FramDataContext _domainDataProvider = null;
// public ActionTS()
// {
// //
// // TODO: 在此处添加构造函数逻辑
// //
// }
public ActionTS(FramDataContext domainDataProvider)
{
this._domainDataProvider = domainDataProvider;
}
public FramDataContext DataProvider
{
get
{
return _domainDataProvider;
}
}
///
/// 不良品采集
///
///
///
///
///
///
///
///
///
///
public Messages Execute(ActionEventArgs actionEventArgs)
{
Messages messages = new Messages();
Messages msgAutoGoMO = new Messages();
try
{
// 自动做Undo
messages.AddMessages((new ActionUndoNG(this.DataProvider)).UndoNG(actionEventArgs));
// Added end
ActionOnLineHelper dataCollect = new ActionOnLineHelper(this.DataProvider);
//填写SIMULATION 检查工单、ID、途程、操作
messages.AddMessages(dataCollect.CheckID(actionEventArgs));
if (messages.IsSuccess())
{
//补充SIMULATION 不良信息
actionEventArgs.ProductInfo.NowSimulation.PRODUCTSTATUS = ProductStatus.NG;
actionEventArgs.ProductInfo.NowSimulation.NGTIMES = actionEventArgs.ProductInfo.NowSimulation.NGTIMES + 1;
messages.AddMessages(dataCollect.Execute(actionEventArgs));
if (messages.IsSuccess())
{
//获取ErrorGroup2ErrorCode
if (actionEventArgs.ActionType == ActionType.DataCollectAction_NG)
{
actionEventArgs.ProductInfo.ECG2ErrCodes = ParseECG2Errs(((TSActionEventArgs)actionEventArgs).ErrorCodes, actionEventArgs.ActionType);
}
else
{
actionEventArgs.ProductInfo.ECG2ErrCodes = ParseECG2Errs(((TSActionEventArgs)actionEventArgs).ErrorInfor, actionEventArgs.ActionType);
}
ReportHelper reportCollect = new ReportHelper(this.DataProvider);
messages.AddMessages(reportCollect.ReportLineQuanMaster(this.DataProvider, actionEventArgs.ActionType, actionEventArgs.ProductInfo));
}
}
}
catch (Exception e)
{
messages.Add(new Message(e));
}
//return messages;
if (msgAutoGoMO.Count() < 1 || (msgAutoGoMO.IsSuccess() == true && messages.IsSuccess() == false))
return messages;
else
{
msgAutoGoMO.IgnoreError();
msgAutoGoMO.AddMessages(messages);
return msgAutoGoMO;
}
}
//获取不良代码组、不良代码
public static string ParseECG2Errs(object[] errorInfo, string actType)
{
string strReturn = String.Empty;
if (errorInfo == null)
{
return strReturn;
}
for (int i = 0; i < errorInfo.Length; i++)
{
if (actType == ActionType.DataCollectAction_NG || actType == ActionType.DataCollectAction_OutLineNG)
{
ICSECG2EC tsLoc = ((ICSECG2EC)errorInfo[i]);
strReturn += tsLoc.ECGCODE + ":" + tsLoc.ECODE + ";";
}
}
return strReturn;
}
///
/// 不良品采集
///
///
///
///
///
///
///
///
///
///
public Messages Execute(ActionEventArgs actionEventArgs, ActionCheckStatus actionCheckStatus)
{
Messages messages = new Messages();
Messages msgAutoGoMO = new Messages();
try
{
ActionOnLineHelper dataCollect = new ActionOnLineHelper(this.DataProvider);
//填写SIMULATION 检查工单、ID、途程、操作
messages.AddMessages(dataCollect.CheckID(actionEventArgs, actionCheckStatus));
if (messages.IsSuccess())
{
//补充SIMULATION 不良信息
actionEventArgs.ProductInfo.NowSimulation.PRODUCTSTATUS = ProductStatus.NG;
actionEventArgs.ProductInfo.NowSimulation.NGTIMES = actionEventArgs.ProductInfo.NowSimulation.NGTIMES + 1;
if (actionCheckStatus.NeedUpdateSimulation)
{
//保存责任部门到ICSONWIP.DUTYDEPARTMENT栏位
if (actionCheckStatus.DutyDepartment.ToString() != string.Empty)
{
actionEventArgs.DutyDepartment = actionCheckStatus.DutyDepartment;
}
if (actionCheckStatus.TroubleStage.ToString() != string.Empty)
{
actionEventArgs.TroubleStage = actionCheckStatus.TroubleStage;
}
//End
messages.AddMessages(dataCollect.Execute(actionEventArgs));
}
else
{
messages.AddMessages(dataCollect.Execute(actionEventArgs, actionCheckStatus));
}
if (messages.IsSuccess())
{
//Laws Lu,2005/12/19,新增 获取ErrorGroup2ErrorCode
if (actionEventArgs.ActionType == ActionType.DataCollectAction_NG)
{
actionEventArgs.ProductInfo.ECG2ErrCodes = ParseECG2Errs(((TSActionEventArgs)actionEventArgs).ErrorCodes, actionEventArgs.ActionType);
}
else
{
actionEventArgs.ProductInfo.ECG2ErrCodes = ParseECG2Errs(((TSActionEventArgs)actionEventArgs).ErrorInfor, actionEventArgs.ActionType);
}
//检查ErrorCode,ErrorGroup是否正确 TODO
//如果CS能确保ErrorCode,ErrorGroup是正确的,此处逻辑可以去掉
messages.AddMessages(dataCollect.CollectErrorInformation(actionEventArgs.ActionType, actionEventArgs.ProductInfo, ((TSActionEventArgs)actionEventArgs).ErrorCodes, ((TSActionEventArgs)actionEventArgs).Memo));
ReportHelper reportCollect = new ReportHelper(this.DataProvider);
messages.AddMessages(reportCollect.ReportLineQuanMaster(this.DataProvider, actionEventArgs.ActionType, actionEventArgs.ProductInfo));
}
else
{
return messages;
}
}
}
catch (Exception e)
{
messages.Add(new Message(e));
}
if (msgAutoGoMO.Count() < 1 || (msgAutoGoMO.IsSuccess() == true && messages.IsSuccess() == false))
return messages;
else
{
msgAutoGoMO.IgnoreError();
msgAutoGoMO.AddMessages(messages);
return msgAutoGoMO;
}
}
}
}