using bizFacade;
using MesServerWork;
using System;
using System.Threading;
//using SystemFramework;

namespace MesServerFunctions
{
    partial class FunctionMES
    {
        /// <summary>
        /// 工件到位与离开时，清空MES自身信号
        /// </summary>
        /// <param name="OpName"></param>
        /// <param name="tagValue"></param>
        private void WorkStart(object  e)
        {
            try
            {
                DoWhatPlc.CustomeEvetnArgs msgEvent = (DoWhatPlc.CustomeEvetnArgs)e;
                string OpName = Convert.ToString(msgEvent.OpName);
                int tagValue = Convert.ToInt32(msgEvent.TagValue);
                if (tagValue > 0)
                {
                    BaseDataSystemMES.OpName_MIS_MOBY_Insert(OpName, MobyTagType.WorkStart, tagValue.ToString());
                    MIS_BASE.WritePLC(27, OpName, false); // 关系绑定完成
                    BaseDataSystemMES.OpName_MIS_MOBY_Insert(OpName, MobyTagType.WorkStartIn, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                }
                else
                {
                    // 从上个工件离开到下个工件离开为节拍数据
                    BaseDataSystemMES.OpName_MIS_MOBY_Insert(OpName, MobyTagType.WorkStartOut, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    MIS_BASE.Write_MesReadOver(OpName, false);
                    MIS_BASE.Write_ConfirmOkGo(OpName, false);
                    MIS_BASE.Write_FixAllow(OpName, false);
                    MIS_BASE.Write_ConfirmOkGo(OpName, false);
                    MIS_BASE.Write_EngineTypeGetOver_MES(OpName, false);
                    //工作完成
                    MIS_BASE.Write_MaterialVerifyOver(OpName, false);

                    MIS_BASE.WritePLC(77, OpName, 0);// 托盘需要工作

                    MIS_BASE.WritePLC(27, OpName, false); // 关系绑定完成
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "Function02:WorkStart");
            }
        }

    }
}
