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

                MIS_BASE.Write_FixAllow(OpName, false);
                //上线工位清MES传递机型信号
                MIS_BASE.Write_EngineTypeGetOver_MES(OpName, false);
                // 清除报警
                MIS_BASE.WritePLC(34, OpName, false);

                if (tagValue == 1)
                {
                    //int planCount = 0; // 计划上料数量
                    //int haveUplaodCount = 0; // 已上料数量
                    //int remainingQuantity = 0; // 待上料数量

                    //// 分装上线工位没有托盘到位离开，通过申请上线和保存完成代替
                    ////MIS_BASE.Write_TagTypeID(115, OpName, 0);
                    ////MIS_BASE.Write_TagTypeID(95, OpName, 0);
                    ////MIS_BASE.Write_TagTypeID(96, OpName, 0);
                    ////MIS_BASE.Write_TagTypeID(97, OpName, 0);
                    ////MIS_BASE.Write_TagTypeID(98, OpName, "");
                    //BaseDataSystemMES.OpName_MIS_MOBY_Insert(OpName, MobyTagType.WorkStartIn, DateTime.Now.ToString());
                    //BaseDataSystemMES.OpName_MIS_MOBY_Insert(OpName, MobyTagType.WorkStart, tagValue.ToString());

                    //// 读取当前选择的计划中的机型，写入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 planCount, out haveUplaodCount, out remainingQuantity);
                    //if (isCheckOk == 2)
                    //{
                    //    MIS_BASE.WritePLC(95, OpName, planCount);
                    //    MIS_BASE.WritePLC(96, OpName, haveUplaodCount);
                    //    MIS_BASE.WritePLC(97, OpName, remainingQuantity);

                    //    MIS_BASE.WritePLC(34, OpName, true);
                    //    string msg = "【" + OpName + "】" + "分装线无上线订单，请下达新订单！";
                    //    MyLog4Net.MyLogHelper.Error("PartLoad", msg);
                    //    SendMessage.AsyncSendMessage_Notice(OpName, msg);
                    //    return;
                    //}
                    //else
                    //{
                    //    BaseDataSystemMES.OpName_MIS_MOBY_Insert(OpName, MobyTagType.EngineID_MES, EngineID);

                    //    // 写入机型代码 （大机型） 机型 发动机号 订单号
                    //    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);
                        
                    //    MIS_BASE.WritePLC(95, OpName, planCount);
                    //    MIS_BASE.WritePLC(96, OpName, haveUplaodCount);
                    //    MIS_BASE.WritePLC(97, OpName, remainingQuantity);


                    //    // MES传递机型
                    //    MIS_BASE.Write_EngineTypeGetOver_MES(OpName, true);
                    //    // 通知web显示
                    //    SendMessage.ShowMoby(OpName);
                    //}
                }
                else
                {
                    ////上线工位清MES传递机型信号
                    //MIS_BASE.Write_EngineTypeGetOver_MES(OpName, false);
                    //// 清除报警
                    //MIS_BASE.WritePLC(34, OpName, false);
                }
            }
            catch (Exception err)
            {
                // 保存出错日志 1.申请上线 2.传递机型 3.允许保存 4.扫码
                MisDataSaveDate.FuntionMesRead.Alarm_SaveFileLog4Error(System.Reflection.MethodBase.GetCurrentMethod().Name, e, "Fun1053", err);
                ////ApplicationLog.WriteLog(err, "Function08:MesReadOver");
            }
        }
    }
}
