using System;
using bizFacade;
using MesServerWork;
//using SystemFramework;

namespace MesServerFunctions
{
    partial class Functions_BASE_WebSubmit
    {
 
        /// <summary>
        /// PLC传递机型处理
        /// </summary>
        /// <param name="OpName"></param>
        /// <param name="tagValue"></param>
        private static void EngineTypeGetOver_PLC(object e)
        {
            try
            {
                DoWhatPlc.CustomeEvetnArgs msgEvent = (DoWhatPlc.CustomeEvetnArgs)e;
                string OpName = Convert.ToString(msgEvent.OpName);
                int tagValue = Convert.ToInt32(msgEvent.TagValue);
                //判断PLC机型与MES机型是否一致
                if (tagValue == 1)
                {
                    bool MesRead = false;

                    int EngineTypeID;//机型代码
                    int PartPallet_Code;//托盘编号

                    string EngineType;//机型
                    string EngineID;//工件编号

                    int EngineTypeID_MES;//机型代码
                    string EngineType_MES;//机型
                    string EngineID_MES;//工件编号

                    MIS_BASE.Read_QualityData_Read_CF(OpName, out MesRead);

                    //第一步，判断允许保存和保存完成信号是否全部被清空，若未清空，则通知复位MES&PLC
                    if (MesRead)
                    {
                        //未能清空信号，请求复位
                        SendInfomation("AskReset", "1", OpName);
                        return;
                    }
                    string OrderForm;
                    MIS_BASE.GetEngineTypeFromPLC(OpName, out EngineTypeID, out EngineType, out EngineID, out PartPallet_Code,out OrderForm);
                    MIS_BASE.GetEngineTypeFromPLC_MES(OpName, out EngineTypeID_MES, out EngineType_MES, out EngineID_MES);

                    // 工位号],[订单号],[产品型号代码],[变速器序列号],[发动机型号],[机型基本代码],[变速器总成号] ,[托盘号]
                    // [产品型号代码_MES],[变速器序列号_MES],[发动机型号_MES]
                    // [机床上电],[循环开始],[机床故障],[上料无件],[下料堵塞],[工件到位]
                    // [传递机型],[申请上件],[允许保存],[保存完成],[合格标志],[前序合格]
                    // [工号],[班次],[是否返修件],[合格放行],[不合格放行],[扫描条码]

                    BaseDataSystemMES.OpName_MIS_MOBY_Insert(OpName, MobyTagType.EngineTypeID, EngineTypeID.ToString());
                    BaseDataSystemMES.OpName_MIS_MOBY_Insert(OpName, MobyTagType.EngineType, EngineType);
                    BaseDataSystemMES.OpName_MIS_MOBY_Insert(OpName, MobyTagType.EngineID, EngineID);
                    BaseDataSystemMES.OpName_MIS_MOBY_Insert(OpName, MobyTagType.PartPallet_Code, PartPallet_Code.ToString());

                    //显示当前订单信息
                    SendMessage.ShowMoby(OpName);

                    if (EngineTypeID_MES == EngineTypeID & EngineID_MES == EngineID & EngineType_MES== EngineType)
                    {
                        MIS_BASE.Write_FixAllow(OpName, true);

                        //显示 显示绿脸

                        return;
                    }
                    else
                    {
                        SendMessage.AsyncSendMessage_Notice(OpName, "码块RFID机型与MES机型不匹配！");
                    }

                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "Function08:EngineTypeGetOver_PLC");
            }
        }

    }
}
