using System;
using System.Data;
using System.Collections;

using System.Windows.Forms;
//using bizFacade;
using System.Collections.Specialized;
//using MesWork;
//using SystemFramework;
using bizFacade;

namespace MesServerWork
{
    public partial class MIS_BASE
    {
        static object lockerMaterial_Insert = new object();

        static public void Material_Insert(string OpName)
        {
            lock (lockerMaterial_Insert)
            {
                try
                {
                    //int tagValue = Convert.ToInt32(msgEvent.TagValue);
                    int IsAllowWork;
                    //第四步，获取是否允许工作
                    BaseDataSystemMES.MesServer_Judge_IsCanWork(OpName, out IsAllowWork);
                    bool EngineGetOver_PLC_NextWorkStep;
                    //传递机型是否到位
                    MIS_BASE.Read_EngineGetOver_PLC(OpName, out EngineGetOver_PLC_NextWorkStep);

                    //暂时先定义为扫描完成才能进行压装工作，因为考虑到工作完成后，操作工未必会去扫描物料的情况
                    if (EngineGetOver_PLC_NextWorkStep&&IsAllowWork == 1)
                    {
                        BaseDataSystemMES.Material_Insert(OpName, 1);

                        //更新订单完工数量及物料
                        Sendmessage("24", "11", OpName);

                        //工作完成
                        MIS_BASE.Write_MaterialVerifyOver(OpName, true);
                        //通知PLC允许工作,允许工作在保存完成时清空
                        MIS_BASE.Write_FixAllow(OpName, true);
                    }
                    else
                    {
                        AsyncSendMessage_Notice(OpName, "请扫描物料！");
                    }

                }
                catch (Exception err)
                {
                    ////ApplicationLog.WriteLog(err, "Function02:ConfirmOkGo");
                }
            }
 
        }
    }
}
