using System;
using System.Data;
using System.Windows.Forms;
using System.Xml.Linq;
using bizFacade;
//using SystemFramework;
using MesServerWork;

namespace MesServerFunctions
{
    partial class FunctionMES
    {
        /// <summary>
        /// PLC传递机型处理
        /// </summary>
        /// <param name="OpName"></param>
        /// <param name="tagValue"></param>
        private void EngineTypeGetOver_PLC(object e)
        {
            try
            {
                DoWhatPlc.CustomeEvetnArgs msgEvent = (DoWhatPlc.CustomeEvetnArgs)e;
                string OpName = Convert.ToString(msgEvent.OpName);
                //int tagValue = Convert.ToInt32(msgEvent.TagValue);
                if (msgEvent.TagValueUp.ToString() == "6")
                {
                    MIS_BASE.Write_FixAllow(OpName, false);
                    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
                    {
                        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);

                        BaseDataSystemMES.OpName_MIS_MOBY_Insert(OpName, MobyTagType.WorkStartIn, DateTime.Now.ToString());
                        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.OrderForm, OrderForm);
                        BaseDataSystemMES.OpName_MIS_MOBY_Insert(OpName, MobyTagType.EngineTypeID_MES, EngineTypeID.ToString());
                        BaseDataSystemMES.OpName_MIS_MOBY_Insert(OpName, MobyTagType.EngineType_MES, EngineType);
                        BaseDataSystemMES.OpName_MIS_MOBY_Insert(OpName, MobyTagType.EngineID_MES, EngineID);
                        BaseDataSystemMES.OpName_MIS_MOBY_Insert(OpName, MobyTagType.OrderForm_MES, OrderForm);

                        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);

                        EngineTypeGetOver_PLC_Work(OpName, EngineTypeID, EngineType, EngineID, 0, OrderForm);
                    }
                }
            }
            catch (Exception err)
            {
                // 保存出错日志 1.申请上线 2.传递机型 3.允许保存 4.扫码
                MisDataSaveDate.FuntionMesRead.Alarm_SaveFileLog4Error(System.Reflection.MethodBase.GetCurrentMethod().Name, e, "Fun1053", err);
                ////ApplicationLog.WriteLog(err, "Function02:EngineTypeGetOver_PLC");
            }
        }

    }
}
