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, "");
                    //清空MOBY的产品流水号

                    // 北汽福田工位状态监控MOBY_增加
                    // 工位号],[订单号],[产品型号代码],[变速器序列号],[发动机型号],[机型基本代码],[变速器总成号] ,[托盘号]
                    // [产品型号代码_MES],[变速器序列号_MES],[发动机型号_MES]
                    // [机床上电],[循环开始],[机床故障],[上料无件],[下料堵塞],[工件到位]
                    // [传递机型],[申请上件],[允许保存],[保存完成],[合格标志],[前序合格]
                    // [工号],[班次],[是否返修件],[合格放行],[不合格放行],[扫描条码]
                    //[到达时间],[离开时间],[持续时间]

                    //初始化物料临时表
                    //第二步，将零件信息转移到零件_临时表中（本地BOM与订单BOM的选择显示关系）
                    BaseDataSystemMES.MesServer_Process_EngineTypeOver_BQ_FirstOP(OpName);
                    BaseDataSystemMES.OpName_MIS_MOBY_Insert(OpName, MobyTagType.WorkStartIn, DateTime.Now.ToString());
                    BaseDataSystemMES.OpName_MIS_MOBY_Insert(OpName, MobyTagType.WorkStart, tagValue.ToString());

                    //5 显示订单、机型信息 线首工位用
                    SendMessage.ShowMoby_FirstOpName(OpName);
                    //3显示操作指导图片 PicShow_String_FirstOpName
                    SendMessage.PicShow_FirstOpName(OpName);
                    //1（直接在界面通过选择机型确认工序内容）
                    SendMessage.ProcessList_FirstOpName(OpName);
                    //界面显示物料信息
                    SendMessage.MaterialList_FirstOpName(OpName);
                }
                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);
                }
            }
            catch(Exception err)
            {
                ////ApplicationLog.WriteLog(err, "Function08:WorkStart");
            }
        }
    }
}
