using System;
using System.Collections.Generic;
using System.Data;
using System.Threading;
using bizFacade;
//using SystemFramework;
using MesServerWork;

namespace MesServerFunctions
{
    partial class FunctionMES
    {
        /// <summary>
        /// 申请上线(针对上线工位)
        /// </summary>
        /// <param name="OpName"></param>
        /// <param name="tagValue"></param>
        private void PartLoad(object e)
        {
            try
            {
                DoWhatPlc.CustomeEvetnArgs msgEvent = (DoWhatPlc.CustomeEvetnArgs)e;
                string OpName = Convert.ToString(msgEvent.OpName);
                int tagValue = Convert.ToInt32(msgEvent.TagValue);
                

                if (tagValue == 1)
                {
                    // 读取当前选择的计划中的机型，写入PLC
                    // 获取订单的机型
                    string Program_No = "";
                    Db.GetEngineType_Order(OpName, Program_No, out int EngineTypeID, out string EngineType, out string EngineID, out string OrderForm, out int isCheckOk, out int planCount, out int haveUplaodCount, out int remainingQuantity,out string msg2);
                    if (isCheckOk == 2)
                    {
                        MIS_BASE.WritePLC(34, OpName, true);
                        string msg = "【" + OpName + "】" + msg2;
                        // 判断到线体上有滞留工件 ，让去管理系统进行处理
                        SendMessage.AsyncSendMessage_Notice(OpName, msg);
                        MyLog4Net.MyLogHelper.Error("PartLoad", msg);
                        return;
                    }
                    else
                    {
                        BaseDataSystemMES.OpName_MIS_MOBY_Insert(OpName, MobyTagType.EngineID_MES, EngineID);
                        MIS_BASE.WritePLC(34, OpName, false);
                        // 写入机型代码 （大机型） 机型 发动机号 订单号
                        MIS_BASE.Write_EngineTypeID_MES(OpName, EngineTypeID);
                        MIS_BASE.Write_EngineType_MES(OpName, EngineType);
                        MIS_BASE.Write_EngineID_MES(OpName, EngineID);
                        MIS_BASE.Write_OrderForm_MES(OpName, OrderForm);

                        // MES传递机型
                        MIS_BASE.Write_EngineTypeGetOver_MES(OpName, true);
                    }
                }
                else
                {
                    //上线工位清MES传递机型信号
                    MIS_BASE.Write_EngineTypeGetOver_MES(OpName, false);
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "Function08:MesReadOver");
            }
        }
    }
}
