using DataLinkMesWork;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace bizFacade
{
    public class MesFunctions
    {
        /// <summary>
        /// 工件入站
        /// </summary>
        /// <param name="OpName"></param>
        /// <param name="EngineTypeID"></param>
        /// <param name="EngineType"></param>
        /// <param name="PartPallet_Code"></param>
        /// <param name="EngineID"></param>
        /// <param name="Big_EnginTypeID"></param>
        /// <param name="MES_QualityMask"></param>
        /// <param name="OrderForm"></param>
        /// <returns></returns>
        public static bool EnginePart_Incoming(string OpName, int EngineTypeID, string EngineType, int PartPallet_Code, string EngineID, string Big_EnginTypeID, int MES_QualityMask, string OrderForm)
        {
            var procedureName = "MES_合装控制_工件入站";
            var sqlParameters = new SqlParameter[]
            {
                new SqlParameter("@OP_Name", OpName),
                new SqlParameter("@Engine_TypeID", EngineTypeID),
                new SqlParameter("@Engine_Type", EngineType),
                new SqlParameter("@Pallet_Code", PartPallet_Code),
                new SqlParameter("@Product_Code", EngineID),
                new SqlParameter("@Big_EnginTypeID", int.Parse(Big_EnginTypeID)),
                new SqlParameter("@Product_QualityOK", MES_QualityMask),
                new SqlParameter("@OrderForm", OrderForm)
            };
            return DataAccess.ExecuteStoredProcedure(procedureName, ref sqlParameters);
        }
        /// <summary>
        /// 工件出站
        /// </summary>
        /// <param name="OpName"></param>
        /// <param name="EngineTypeID"></param>
        /// <param name="EngineType"></param>
        /// <param name="PartPallet_Code"></param>
        /// <param name="EngineID"></param>
        /// <param name="Big_EnginTypeID"></param>
        /// <param name="MES_QualityMask"></param>
        /// <param name="OrderForm"></param>
        /// <returns></returns>
        public static bool EnginePart_OutStation(string OpName, string EngineID, int MES_QualityMask)
        {
            var procedureName = "MES_合装控制_工件出站";
            var sqlParameters = new SqlParameter[]
            {
                new SqlParameter("@OP_Name", OpName),
                new SqlParameter("@Product_Code", EngineID),
                new SqlParameter("@Product_QualityOK", MES_QualityMask)
            };
            return DataAccess.ExecuteStoredProcedure(procedureName, ref sqlParameters);
        }
        /// <summary>
        /// Condition_Type：1、判断该工位是否在业务范围内（停用）；2、机型匹配，3、获取OPA90的匹配结果
        /// </summary>
        /// <param name="Condition_Type"></param>
        /// <returns></returns>
        public static int GetCondition_AssemblyControl(int Condition_Type)
        {
            //Condition_Type：1、判断该工位是否在业务范围内；2、根据OPA90第一个入站工件进行机型判断；3、获取报警信息
            string procedureName = "MES_合装控制_控制条件";
            var sqlParameters = new SqlParameter[]
            {
                new SqlParameter("@Condition_Type", Condition_Type),
                new SqlParameter("@OP_Name", "OPA90")
            };
            var result = DataAccess.ExecuteStoredProcedure(procedureName, ref sqlParameters, out DataTable dt);
            return int.Parse(dt.Rows[0][0].ToString());
        }
    }
}
