using System;
using System.Collections.Generic;
using MesServerWork;
using MisDataFunDll;
//using SystemFramework;


namespace MesServerFunctions
{
    partial class FunctionMES
    {
        /// <summary>
        /// 工件到位与离开时，清空MES自身信号
        /// </summary>
        /// <param name="OpName"></param>
        /// <param name="tagValue"></param>
        private void WorkStart(object e)
        {
            try
            {
                DeviceDriver_BasicData.CustomeEvetnArgs msgEvent = (DeviceDriver_BasicData.CustomeEvetnArgs)e;
                string OpName = Convert.ToString(msgEvent.OpName);
                int tagValue = Convert.ToInt32(msgEvent.TagValue);

                //线首显示订单信息

                if (tagValue == 1)
                {
                    MisDataFun.OpName_MIS_MOBY_Insert(OpName, MisDataFun.MobyTagType.WorkStartIn, DateTime.Now.ToString());
                    MisDataFun.OpName_MIS_MOBY_Insert(OpName, MisDataFun.MobyTagType.WorkStart, tagValue.ToString());
                }
                else
                {
                    MisDataFun.OpName_MIS_MOBY_Insert(OpName, MisDataFun.MobyTagType.WorkStartOut, DateTime.Now.ToString());

                    // 清除工位数据
                    MIS_BASE.Write_EngineTypeID_MES(OpName, 0);
                    MIS_BASE.Write_EngineType_MES(OpName, "");
                    MIS_BASE.Write_EngineID_MES(OpName, "");
                    MIS_BASE.Write_OrderForm_MES(OpName, "");

                    MIS_BASE.Write_MesReadOver(OpName, false);
                    MIS_BASE.Write_ConfirmOkGo(OpName, false);
                    MIS_BASE.Write_FixAllow(OpName, false);
                    MIS_BASE.Write_EngineTypeGetOver_MES(OpName, false);
                    //工作完成
                    MIS_BASE.Write_MaterialVerifyOver(OpName, false);

                    MIS_BASE.WritePLC(115, OpName, 0); // 清除小机型

                    // 检查项完成
                    MIS_BASE.Write_TagTypeID(30, OpName,0);
                    string message = "MES|checkWorkOverIsShow|" + OpName + "|" + 0;
                    SendMessage.AsyncSendMessage(message);

                    // 重新申请上线
                    MIS_BASE.WritePLC(35, OpName, 0);
                }
            }
            catch(Exception err)
            {
                ////ApplicationLog.WriteLog(err, "Function08:WorkStart");
            }
        }
    }
}
