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

namespace MesServerFunctions
{
    partial class FunctionMES
    {
        /// <summary>
        /// 物料扫码完成
        /// </summary>
        /// <param name="OpName"></param>
        /// <param name="tagValue"></param>
        private void MaterialsScanOver(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)
                {
                    MIS_BASE.GetEngineTypeFromPLC(OpName, out int EngineTypeID, out string EngineType, out string EngineID, out int PartPallet_Code, out string OrderForm);
                    string materialsCode = MIS_BASE.ReadPLC(40, OpName).ToString();
                    var dt = MisDataFun.Get_MaterialsScanOverRes(OpName, OrderForm, EngineID, materialsCode);
                    int result = Convert.ToInt32(dt.Rows[0]["result"]);
                    if (result == 1)
                    {
                        MIS_BASE.WritePLC(95, OpName, 1);
                    }
                    else if (result == 2)
                    {
                        MIS_BASE.WritePLC(95, OpName, 2);
                    }
                }
                else
                {
                    MIS_BASE.WritePLC(96, OpName, 0); // 提前上料位置
                    MIS_BASE.WritePLC(33, OpName, false); // 允许提前上料
                    MIS_BASE.Write_EngineID_MES(OpName, "");
                }
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, "Function08:MesReadOver");
            }
        }
    }
}
