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

namespace MesServerFunctions
{
    public class Db
    {
        /// <summary>
        /// 合力_OPA90是否允许工作_判断  如果允许工作则将两个轮毂状态设为待匹配
        /// </summary>
        /// <param name="EngineTypeID"></param>
        /// <param name="EngineTypeID_QiaoKe"></param>
        /// <param name="EngineID"></param>
        /// <param name="OrderForm"></param>
        /// <param name="MatchResult"></param>
        /// <param name="MatchResultStr"></param>
        /// <returns></returns>
        public static bool OP50_OPA90_MatchResult(int EngineTypeID, int EngineTypeID_QiaoKe, string EngineID, string OrderForm, out int MatchResult, out string MatchResultStr)
        {
            DataTable dt = new DataTable();
            MatchResult = 3;// 默认是报警 程序出错
            MatchResultStr = "默认是报警 程序出错";// 默认是报警 程序出错
            string produceName = "合力_OPA90是否允许工作_判断";
            SqlParameter[] thisParms = new SqlParameter[4];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@轮毂机型", EngineTypeID);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@轮毂总成号", EngineID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@桥壳_机型", EngineTypeID_QiaoKe);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@订单号", OrderForm);
            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt))
            {
                if (dt.Rows.Count > 0)
                {
                    MatchResult = Convert.ToInt32(dt.Rows[0]["最终结果"]);
                    MatchResultStr = dt.Rows[0]["最终结果说明"].ToString();
                    return true;
                }
            }
            return false;
        }
        /// <summary>
        /// 合力_转线_OPA90_TO_OP050
        /// </summary>
        /// <param name="partSn_Main"></param>
        /// <param name="partSn_Sub"></param>
        /// <returns></returns>
        public static bool OPA90_TO_OP50_WorkFinish(string partSn_Main, string partSn_Sub)
        {

            string produceName = "合力_转线_OPA90_TO_OP050";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@轮毂总成号", partSn_Sub);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@桥壳总成号", partSn_Main);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }

        /// <summary>
        /// 合力_OP050是否允许工作_判断
        /// </summary>
        /// <param name="MainLineAllowWork"></param>
        /// <returns></returns>
        public static bool OPA90_TO_OP50_CheckTwoFinish(out int MainLineAllowWork)
        {
            DataTable dt;
            MainLineAllowWork = 2;
            string produceName = "合力_OP050是否允许工作_判断";
            SqlParameter[] thisParms = new SqlParameter[0];
            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt))
            {
                if (dt.Rows.Count > 0)
                {
                    MainLineAllowWork = Convert.ToInt32(dt.Rows[0]["是否允许工作"]);
                    return true;
                }
            }
            return false;
        }
    }
}
