using System;
using bizFacade;
using MesServerWork;
//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 == 1)
                {
                    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, "");
                    MIS_BASE.WritePLC(123, OpName, 0);
                    //清空MOBY的产品流水号
                    BaseDataSystemMES.OpName_MIS_MOBY_Insert(OpName, MobyTagType.WorkStartIn, DateTime.Now.ToString());
                    BaseDataSystemMES.OpName_MIS_MOBY_Insert(OpName, MobyTagType.WorkStart, tagValue.ToString());
                }
                else
                {
                    BaseDataSystemMES.OpName_MIS_MOBY_Insert(OpName, MobyTagType.WorkStartOut, DateTime.Now.ToString());
                    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.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.WritePLC(115, OpName, "0");
                    //空挡开关检测
                    MIS_BASE.WritePLC(95, OpName, "0");
                    //倒挡开关检测
                    MIS_BASE.WritePLC(96, OpName, "0");
                    //里程表检测
                    MIS_BASE.WritePLC(97, OpName, "0");
                    //大机型扩展
                    MIS_BASE.WritePLC(98, OpName, "");
                    //TCU
                    MIS_BASE.WritePLC(122, OpName, "0");
                    //注油量
                    MIS_BASE.WritePLC(123, OpName, "0");
                    // 法兰编号
                    if (OpName == "J07ET010") MIS_BASE.WritePLC(124, OpName, "0");

                    BaseDataSystemMES.Check_BarCodeNGTemp(OpName, 2);

                    // 是否返修点
                    MIS_BASE.WritePLC(33, OpName, false);
                    MIS_BASE.WritePLC(34, OpName, false);

                    // 工件离开清除 左右置
                    MIS_BASE.WritePLC(114, OpName, 0);
                }
            }
            catch(Exception err)
            {
                ////ApplicationLog.WriteLog(err, "Function08:WorkStart");
            }
        }
    }
}
