using MesServerWork;
using MisDataFunDll;
using System;
using System.Data;
using System.Threading;
//using SystemFramework;

namespace MesServerFunctions
{
    partial class FunctionMES
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="OpName"></param>
        /// <param name="tagValue"></param>
        private void GetPackCode1(object  e)
        {
            try
            {
                var msgEvent = (DeviceDriver_BasicData.CustomeEvetnArgs)e;
                string OpName = Convert.ToString(msgEvent.OpName);
                string tagValue = msgEvent.TagValue.ToString();
                if (tagValue == "1")
                {
                    // 1.读取来件1信息，
                    string part;
                    MIS_BASE.Read_TagValueByTagTypeID(10, OpName, out part);

                    MisDataFun.GetPackByXT(OpName, part, out string pack);
                    MisDataFun.LogRecording_OP(OpName, "INFO", "GetPackCode", "获取箱体码1对应的PACK码1：" + pack);
                    if (pack != "")
                    {
                        MIS_BASE.Write_TagValueByTagTypeID(74, OpName, pack);
                        MIS_BASE.Write_TagValueByTagTypeID(31, OpName, true);
                        MisDataFun.LogRecording_OP(OpName, "INFO", "GetPackCode", "PACK码1写入完成！");
                    }
                    else
                    {
                        MIS_BASE.Write_TagValueByTagTypeID(74, OpName, "");
                        MIS_BASE.Write_TagValueByTagTypeID(31, OpName, true);
                        MisDataFun.LogRecording_OP(OpName, "ERROR", "GetPackCode", "获取PACK码1错误！");
                    }
                }
                else
                {
                    MIS_BASE.Write_TagValueByTagTypeID(74, OpName, "");
                    MIS_BASE.Write_TagValueByTagTypeID(31, OpName, false);
                    MisDataFun.LogRecording_OP(OpName, "INFO", "GetPackCode", "PLC取消获取PACK码1！");
                }
            }
            catch (Exception err)
            {
                MisDataFun.LogRecording_OP("Function1057", "ERROR", "GetPackCode", err.Message.ToString());
            }
        }

        private void GetPackCode2(object e)
        {
            try
            {
                var msgEvent = (DeviceDriver_BasicData.CustomeEvetnArgs)e;
                string OpName = Convert.ToString(msgEvent.OpName);
                string tagValue = msgEvent.TagValue.ToString();
                if (tagValue == "1")
                {

                    // 1.读取来件1信息，
                    string part;
                    MIS_BASE.Read_TagValueByTagTypeID(11, OpName, out part);

                    MisDataFun.GetPackByXT(OpName, part, out string pack);
                    MisDataFun.LogRecording_OP(OpName, "INFO", "GetPackCode", "获取箱体码2对应的PACK码2：" + pack);
                    if (pack != "")
                    {
                        MIS_BASE.Write_TagValueByTagTypeID(75, OpName, pack);
                        MIS_BASE.Write_TagValueByTagTypeID(32, OpName, true);
                        MisDataFun.LogRecording_OP(OpName, "INFO", "GetPackCode", "PACK码2写入完成！");
                    }
                    else
                    {
                        MIS_BASE.Write_TagValueByTagTypeID(75, OpName, "");
                        MIS_BASE.Write_TagValueByTagTypeID(32, OpName, true);
                        MisDataFun.LogRecording_OP(OpName, "ERROR", "GetPackCode", "获取PACK码2错误！");
                    }
                }
                else
                {
                    MIS_BASE.Write_TagValueByTagTypeID(75, OpName, "");
                    MIS_BASE.Write_TagValueByTagTypeID(32, OpName, false);
                    MisDataFun.LogRecording_OP(OpName, "INFO", "GetPackCode", "PLC取消获取PACK码2！");
                }
            }
            catch (Exception err)
            {
                MisDataFun.LogRecording_OP("Function1057", "ERROR", "GetPackCode", err.Message.ToString());
            }
        }

    }
}
