using bizFacade;
using DataLinkMesWork;
using DoWhatPlc;
using MesServerWork;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MisDataSaveDate
{
    public partial class  Funtion
    {
        private static void EngTypeGetOver(string opName,string tagValue)
        {
            if (hashtable_EngineGetOver.Contains(opName))
            {
                hashtable_EngineGetOver.Remove(opName);
            }
            hashtable_EngineGetOver.Add(opName, tagValue);
            if (tagValue == "1")
            {

                int EngineTypeID;
                string EngineType;
                string EngineID;
                int PartPalletCode;
                // 1 读取机型等信息，保存到监控表

                DtWebApi.ReadWritePLC.GetEngineTypeFromPLC(opName, out EngineTypeID, out EngineType, out EngineID, out PartPalletCode);

                if (hashtable_EngineGetOver_EngineTypeID.Contains(opName))
                {
                    hashtable_EngineGetOver_EngineTypeID.Remove(opName);
                }
                hashtable_EngineGetOver_EngineTypeID.Add(opName, EngineTypeID);

                if (hashtable_EngineGetOver_EngineType.Contains(opName))
                {
                    hashtable_EngineGetOver_EngineType.Remove(opName);
                }
                hashtable_EngineGetOver_EngineType.Add(opName, EngineType);


                if (hashtable_EngineGetOver_EngineID.Contains(opName))
                {
                    hashtable_EngineGetOver_EngineID.Remove(opName);
                }
                hashtable_EngineGetOver_EngineID.Add(opName, EngineID);
                if (hashtable_PartPalletCode.Contains(opName))
                {
                    hashtable_PartPalletCode.Remove(opName);
                }
                hashtable_PartPalletCode.Add(opName, PartPalletCode);

                EngTypeGetOverInsert(opName, EngineTypeID, EngineType, EngineID, PartPalletCode);


                // 2 保存工件到位信息

            }
        }

        //
        /// <summary>
        /// @工位号 nvarchar(50)=null,
        ///@产品型号代码 int=1 ,
        ///@发动机型号 nvarchar(50)=null ,
        ///@发动机号 nvarchar(50)=null ,
        ///@托盘号 nvarchar(50)='0'
        /// </summary>
        /// <param name="EngineID"></param>
        /// <param name="tagID"></param>
        /// <param name="EngineType"></param>
        /// <param name="EngineTypeID"></param>
        /// <param name="opName"></param>
        /// <param name="isGoodBad"></param>
        /// <param name="PartPalletCode"></param>
        /// <param name="Id_tagCF"></param>
        /// <returns></returns>
        public static bool EngTypeGetOverInsert(string opName, int EngineTypeID, string EngineType,string EngineID, int PartPalletCode)
        {
            string procedureName;
            procedureName = "测量数据工位_监控系统_增加";
            SqlParameter[] thisParms = new SqlParameter[5];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@产品型号代码", EngineTypeID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@发动机型号", EngineType);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@发动机号", EngineID);
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@托盘编号", PartPalletCode);

            if (DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms))
            {
                return true;
            }
            return false;
        }
    }
}
