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
    {
        public static bool OP051_OP050_NeedWork_Search(string EngineID, out int MatchResult)
        {
            DataTable dt = new DataTable();
            MatchResult = 0;
            string produceName = "合力_OP050前停判断_下工位是否需要工作_查询";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@桥壳总成号", EngineID);
            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt))
            {
                if (dt.Rows.Count > 0)
                {
                    MatchResult = Convert.ToInt32(dt.Rows[0]["是否需要工作"]);
                    return true;
                }
            }
            return false;
        }
        public static bool OP50_OPA90_MatchResult(int EngineTypeID_Sub, int EngineTypeID_MainLine, int EngineTypeID, out int MatchResult)
        {
            DataTable dt = new DataTable();
            MatchResult = 0;
            string produceName = "合力_OPA90是否允许工作_判断";
            SqlParameter[] thisParms = new SqlParameter[3];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@轮毂机型", EngineTypeID_Sub);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@桥壳_轮毂机型", EngineTypeID_MainLine);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@桥壳_机型", EngineTypeID);
            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt))
            {
                if (dt.Rows.Count > 0)
                {
                    MatchResult = Convert.ToInt32(dt.Rows[0]["是否允许工作"]);
                    return true;
                }
            }
            return false;
        }
        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);
        }
        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;
        }

        /// <summary>
        /// 合力_转线_删除记录数据 同时保存 轮毂 桥壳 关系
        /// </summary>
        /// <param name="EngineID_QiaoKe"></param>
        public static void OPA92_DeleteLineData(string EngineID_QiaoKe)
        {
            DataTable dt = new DataTable();
            string produceName = "合力_转线_删除记录数据";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@桥壳总成号", EngineID_QiaoKe);
            DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt);
        }

        /// <summary>
        /// 合力_转线_删除记录数据 同时保存 轮毂 桥壳 关系
        /// </summary>
        /// <param name="EngineID_QiaoKe"></param>
        public static void OPA92_DeleteLineData(string EngineID_QiaoKe, string EngineID_LunGu1, string EngineID_LunGu2)
        {
            DataTable dt = new DataTable();
            string produceName = "合力_转线_删除记录数据";
            SqlParameter[] thisParms = new SqlParameter[3];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@桥壳总成号", EngineID_QiaoKe);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@轮毂总成号1", EngineID_LunGu1);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@轮毂总成号2", EngineID_LunGu2);
            DataAccess.ExecuteStoredProcedure(produceName, ref thisParms, out dt);
        }
    }
}
