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>
        /// 北汽福田变速器序列号总线上线_获得机型信息
        /// </summary>
        /// <param name="partSn"></param>
        /// <param name="EngineTypeID"></param>
        /// <param name="EngineType"></param>
        /// <param name="EngineID"></param>
        /// <param name="IsRepeatedNumber"> 0 不重号；1 重号；2：失败</param>
        /// <returns></returns>
        public static bool GetEngineType(string partSn, out int EngineTypeID, out string EngineType, out string EngineID,out int  IsRepeatedNumber)
        {
            DataTable dt = new DataTable();
            EngineTypeID = 0;
            EngineType = "";
            EngineID = "";
            IsRepeatedNumber = 2;
            string produceName = "北汽福田变速器序列号总线上线_获得机型信息";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@变速器序列号", partSn);

            thisParms[2].Direction = ParameterDirection.Output;
            if (DataAccess.ExecuteStoredProcedure(produceName, ref thisParms,out dt))
            {
                if(dt.Rows.Count > 0)
                {
                    IsRepeatedNumber = Convert.ToInt32( dt.Rows[0]["IsRepeatedNumber"]);
                    EngineTypeID = Convert.ToInt32(dt.Rows[0]["EngineTypeID"]);
                    EngineType =  dt.Rows[0]["EngineType"].ToString();
                    EngineID =  dt.Rows[0]["EngineID"].ToString();
                    return true;
                }
            }
            return false;
        }
        /// <summary>
        /// 北汽福田变速器序列号总线上线_增加
        /// </summary>
        /// <param name="partSn"></param>
        /// <param name="EngineTypeID"></param>
        /// <param name="EngineType"></param>
        /// <param name="OpName"></param>
        /// <returns></returns>
        public static bool UpLoadOpNameInsert(string partSn,  int EngineTypeID,  string EngineType, string OpName)
        {

            string produceName = "北汽福田变速器序列号总线上线_增加";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@变速器序列号", partSn);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@基本型号代码", EngineTypeID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@基本型号", EngineType);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@工位号", OpName);
            return DataAccess.ExecuteStoredProcedure(produceName, ref thisParms);
        }

        //        ALTER PROCEDURE[dbo].[北汽福田变速器序列号总线上线_增加]
        //        @变速器序列号 nvarchar(50)='1333 050 062 0001*146012023*12345678',--'1333 050 062 0001'
        //@基本型号代码 int=1,
        //@基本型号 nvarchar(50)='1333 050 062 0001',
        //@工位号 nvarchar(50) = 'J05PA010'
    }
}
