using System;
using System.Data;
using System.Data.SqlClient;
using DataLinkMesWork;
using System.Collections;
using System.Collections.Specialized;
using SystemFramework;

namespace bizFacade
{
    /// <summary>
    /// 电子看板信息系统
    /// </summary>
    public partial class BaseDataSystemMES
    {    
        ///// <summary>
        ///// 电子看板_发动机号_线首工位_创建线首发动机号_根据输入机型代码_手动方式
        ///// </summary>
        ///// <param name="opName">工位号</param>
        ///// <param name="engineType">发动机型号</param>
        ///// <param name="engineYear">年份</param>
        ///// <param name="engineMoon">月份</param>
        ///// <param name="engineDay">日期</param>
        ///// <param name="engineNumber">流水号</param>
        ///// <param name="isSubLine">@是否分线 bit=0 @是否分线 = 0 总线线首（OP2010）；=1分线线首(OP1010,OP2100)</param>
        ///// <param name="dt"></param>
        //static public void GetEngineID_Manual(string opName, string engineType, string engineYear, string engineMoon, string engineDay, int engineNumber, bool isSubLine, out DataTable dt)
        //{
        //    string procedureName;
        //    procedureName = "电子看板_发动机号_线首工位_创建线首发动机号_根据输入机型代码_手动方式";
        //    SqlParameter[] thisParms = new SqlParameter[7];
        //    thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
        //    thisParms[1] = new System.Data.SqlClient.SqlParameter("@发动机型号", engineType);
        //    thisParms[2] = new System.Data.SqlClient.SqlParameter("@年份", engineYear);
        //    thisParms[3] = new System.Data.SqlClient.SqlParameter("@月份", engineMoon);
        //    thisParms[4] = new System.Data.SqlClient.SqlParameter("@日期", engineDay);
        //    thisParms[5] = new System.Data.SqlClient.SqlParameter("@流水号", engineNumber);
        //    thisParms[6] = new System.Data.SqlClient.SqlParameter("@是否分线", isSubLine);
        //    DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
        //}

        /// <summary>
        /// 电子看板_发动机号_线首工位_创建线首发动机号_根据输入机型代码
        /// 工件机型,机型代码,工件编号,壳体编号型号,工件流水号,QR码,基本流水号
        /// </summary>
        /// <param name="opName">工位号</param>
        /// <param name="engineType">发动机型号</param>
        /// <param name="palletCode">托盘号 = 0 总线线首（OP2010）；=1分线线首(OP1010,OP2100)</param>
        /// <param name="dt">工件机型,机型代码,工件编号,壳体编号型号,工件流水号,QR码,基本流水号</param>
        static public void GetEngineID_Auto(string opName, string engineType, string palletCode, out DataTable dt)
        {
            try
            {
                string procedureName;
                procedureName = "电子看板_发动机号_线首工位_创建线首发动机号_根据输入机型代码";
                SqlParameter[] thisParms = new SqlParameter[3];
                thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
                thisParms[1] = new System.Data.SqlClient.SqlParameter("@发动机型号", engineType);
                thisParms[2] = new System.Data.SqlClient.SqlParameter("@托盘号", palletCode);
                DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
            }
            catch (Exception err)
            {
                dt = null;
            }
        }

        /// <summary>
        /// 分线线首号生成
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="engineType"></param>
        /// <param name="partcode"></param>
        /// <param name="dt"></param>
        static public void GetEngineID_Auto_branch(string opName, string engineType, string partcode, out DataTable dt)
        {
            string procedureName;
            procedureName = "电子看板_发动机号_线首工位_创建线首发动机号_根据输入机型代码_分线";
            SqlParameter[] thisParms = new SqlParameter[3];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@发动机型号", engineType);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@托盘号", partcode);
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
        }
        /// <summary>
        /// 电子看板_发动机号_线首工位_创建线首发动机号_根据输入机型代码_分线_手动方式
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="engineType"></param>
        /// <param name="engineYear"></param>
        /// <param name="engineMoon"></param>
        /// <param name="engineDay"></param>
        /// <param name="engineNumber"></param>
        /// <param name="isSubLine"></param>
        /// <param name="dt"></param>
        static public void GetEngineID_Manual_branch(string opName, string engineType, string engineYear, string engineMoon, string engineDay, int engineNumber, bool isSubLine, out DataTable dt)
        {
            string procedureName;
            procedureName = "电子看板_发动机号_线首工位_创建线首发动机号_根据输入机型代码_分线_手动方式";
            SqlParameter[] thisParms = new SqlParameter[7];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@发动机型号", engineType);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@年份", engineYear);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@月份", engineMoon);
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@日期", engineDay);
            thisParms[5] = new System.Data.SqlClient.SqlParameter("@流水号", engineNumber);
            thisParms[6] = new System.Data.SqlClient.SqlParameter("@是否分线", isSubLine);
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
        }
        
        ///// <summary>
        ///// [电子看板_发动机号_线首工位_手动方式_增加]
        ///// </summary>
        ///// <param name="opName">工位号</param>
        ///// <param name="orderForm">订单号</param>
        ///// <param name="PartPalletCode">托盘号</param>
        ///// <param name="engineType">工件机型</param>
        ///// <param name="dt">工件机型,机型代码,工件编号, 壳体编号型号,工件流水号,QR码,基本流水号</param>
        //static public bool GetEngineID_ManulEngine_Save(string opName, string orderForm, string PartPalletCode, string engineType, string EngineID_DateTime, DataTable dt)
        //{
        //    string engineID;
        //    int engineTypeID;
        //    string partCode_Space;
        //    string partCode;
        //    string shellCode;
        //    string shellCode_Space;
        //    string QR_Code;
        //    int engineCount;
        //    int barCodeType;
        //    string engineTypeBase;
        //    string partCode_Text;
        //    string partCode_BarCode;
        //    string engineType_Text;
        //    string engineType_BarCode;

        //    try
        //    {
        //        GetEngineIDFromFirstOpName(out engineID, out engineTypeID, out partCode_Space,
        //   out partCode, out shellCode, out shellCode_Space, out QR_Code,
        //   out engineCount, out barCodeType, out engineTypeBase,
        //   out partCode_Text, out partCode_BarCode, out engineType_Text, out engineType_BarCode, dt);


        //        string procedureName;
        //        procedureName = "电子看板_发动机号_线首工位_手动方式_增加";
        //        SqlParameter[] thisParms = new SqlParameter[19];
        //        thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
        //        thisParms[1] = new System.Data.SqlClient.SqlParameter("@订单号", orderForm);
        //        thisParms[2] = new System.Data.SqlClient.SqlParameter("@发动机号", engineID);
        //        thisParms[3] = new System.Data.SqlClient.SqlParameter("@发动机型号", engineType);
        //        thisParms[4] = new System.Data.SqlClient.SqlParameter("@基本机型", engineTypeBase);
        //        thisParms[5] = new System.Data.SqlClient.SqlParameter("@机型代码", engineTypeID);
        //        thisParms[6] = new System.Data.SqlClient.SqlParameter("@托盘号", PartPalletCode);
        //        thisParms[7] = new System.Data.SqlClient.SqlParameter("@条码类型", barCodeType);
        //        thisParms[8] = new System.Data.SqlClient.SqlParameter("@零件流水号", partCode);
        //        thisParms[9] = new System.Data.SqlClient.SqlParameter("@零件流水号带空格", partCode_Space);
        //        thisParms[10] = new System.Data.SqlClient.SqlParameter("@壳体编号型号", shellCode);
        //        thisParms[11] = new System.Data.SqlClient.SqlParameter("@壳体编号型号带空格", shellCode_Space);
        //        thisParms[12] = new System.Data.SqlClient.SqlParameter("@QR码", QR_Code);
        //        thisParms[13] = new System.Data.SqlClient.SqlParameter("@基本流水号", engineCount);
        //        thisParms[14] = new System.Data.SqlClient.SqlParameter("@流水号文本", partCode_Text);
        //        thisParms[15] = new System.Data.SqlClient.SqlParameter("@流水号条码", partCode_BarCode);
        //        thisParms[16] = new System.Data.SqlClient.SqlParameter("@型号文本", engineType_Text);
        //        thisParms[17] = new System.Data.SqlClient.SqlParameter("@型号条码", engineType_BarCode);
        //        thisParms[18] = new System.Data.SqlClient.SqlParameter("@工件编号时间", EngineID_DateTime);

        //        return DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms);
        //        //  return DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
        //    }

        //    catch (Exception err)
        //    {
        //        ////ApplicationLog.WriteLog(err, err.Message);
        //        return false;

        //    }
        //}


        ///// <summary>
        ///// 电子看板_发动机号_线首工位_增加
        ///// </summary>
        ///// <param name="opName">工位号</param>
        ///// <param name="orderForm">订单号</param>
        ///// <param name="PartPalletCode">托盘号</param>
        ///// <param name="engineType">工件机型</param>
        ///// <param name="dt">工件机型,机型代码,工件编号, 壳体编号型号,工件流水号,QR码,基本流水号</param>
        //static public bool GetEngineID_Save(string opName, string orderForm, string PartPalletCode, string engineType, DataTable dt)
        //{
        //    string engineID;
        //    int engineTypeID;
        //    string partCode_Space;
        //    string partCode;
        //    string shellCode;
        //    string shellCode_Space;
        //    string QR_Code;
        //    int engineCount;
        //    int barCodeType;
        //    string engineTypeBase;
        //    string partCode_Text;
        //    string partCode_BarCode;
        //    string engineType_Text;
        //    string engineType_BarCode;
        //    string codeCreatetime;
        //    string a_code;
        //    string b_code;
        //    string c_code;
        //    string d_code;

        //    try
        //    {
        //        GetEngineIDFromFirstOpName_Auto(out engineID, out engineTypeID, out partCode_Space,
        //   out partCode, out shellCode, out shellCode_Space, out QR_Code,
        //   out engineCount, out barCodeType, out engineTypeBase,
        //   out partCode_Text, out partCode_BarCode, out engineType_Text, out engineType_BarCode, out codeCreatetime,
        //    out a_code, out b_code, out c_code, out d_code,
        //   dt);


        //        string procedureName;
        //        procedureName = "电子看板_发动机号_线首工位_增加";
        //        SqlParameter[] thisParms = new SqlParameter[23];
        //        thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
        //        thisParms[1] = new System.Data.SqlClient.SqlParameter("@订单号", orderForm);
        //        thisParms[2] = new System.Data.SqlClient.SqlParameter("@发动机号", engineID);
        //        thisParms[3] = new System.Data.SqlClient.SqlParameter("@发动机型号", engineType);
        //        thisParms[4] = new System.Data.SqlClient.SqlParameter("@基本机型", engineTypeBase);
        //        thisParms[5] = new System.Data.SqlClient.SqlParameter("@机型代码", engineTypeID);
        //        thisParms[6] = new System.Data.SqlClient.SqlParameter("@托盘号", PartPalletCode);
        //        thisParms[7] = new System.Data.SqlClient.SqlParameter("@条码类型", barCodeType);
        //        thisParms[8] = new System.Data.SqlClient.SqlParameter("@零件流水号", partCode);
        //        thisParms[9] = new System.Data.SqlClient.SqlParameter("@零件流水号带空格", partCode_Space);
        //        thisParms[10] = new System.Data.SqlClient.SqlParameter("@壳体编号型号", shellCode);
        //        thisParms[11] = new System.Data.SqlClient.SqlParameter("@壳体编号型号带空格", shellCode_Space);
        //        thisParms[12] = new System.Data.SqlClient.SqlParameter("@QR码", QR_Code);
        //        thisParms[13] = new System.Data.SqlClient.SqlParameter("@基本流水号", engineCount);
        //        thisParms[14] = new System.Data.SqlClient.SqlParameter("@流水号文本", partCode_Text);
        //        thisParms[15] = new System.Data.SqlClient.SqlParameter("@流水号条码", partCode_BarCode);
        //        thisParms[16] = new System.Data.SqlClient.SqlParameter("@型号文本", engineType_Text);
        //        thisParms[17] = new System.Data.SqlClient.SqlParameter("@型号条码", engineType_BarCode);
        //        thisParms[18] = new System.Data.SqlClient.SqlParameter("@条码创建时间", codeCreatetime);
        //        thisParms[19] = new System.Data.SqlClient.SqlParameter("@总成代码", a_code);
        //        thisParms[20] = new System.Data.SqlClient.SqlParameter("@零件图号", b_code);
        //        thisParms[21] = new System.Data.SqlClient.SqlParameter("@邓氏码", c_code);
        //        thisParms[22] = new System.Data.SqlClient.SqlParameter("@VPPS码", d_code);


        //        return DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms);
        //        //  return DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
        //    }

        //    catch (Exception err)
        //    {
        //        ////ApplicationLog.WriteLog(err, err.Message);
        //        return false;

        //    }
        //}

        /// <summary>
        /// 电子看板_发动机号_线首工位_增加
        /// </summary>
        /// <param name="opName">工位号</param>
        /// <param name="orderForm">订单号</param>
        /// <param name="PartPalletCode">托盘号</param>
        /// <param name="engineType">工件机型</param>
        /// <param name="dt">工件机型,机型代码,工件编号, 壳体编号型号,工件流水号,QR码,基本流水号</param>
        static public bool GetEngineID_Save_Outline(string opName, string orderForm, string PartPalletCode, string engineType, int engineTypeID, string engineID, string barCodeType)
        {

            try
            {
                string procedureName;
                procedureName = "电子看板_发动机号_线首工位_增加";
                SqlParameter[] thisParms = new SqlParameter[19];
                thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
                thisParms[1] = new System.Data.SqlClient.SqlParameter("@订单号", orderForm);
                thisParms[2] = new System.Data.SqlClient.SqlParameter("@发动机号", engineID);
                thisParms[3] = new System.Data.SqlClient.SqlParameter("@发动机型号", engineType);
                thisParms[4] = new System.Data.SqlClient.SqlParameter("@基本机型", engineType);
                thisParms[5] = new System.Data.SqlClient.SqlParameter("@机型代码", engineTypeID);
                thisParms[6] = new System.Data.SqlClient.SqlParameter("@托盘号", PartPalletCode);
                thisParms[7] = new System.Data.SqlClient.SqlParameter("@条码类型", barCodeType);
                thisParms[8] = new System.Data.SqlClient.SqlParameter("@零件流水号", engineID);
                thisParms[9] = new System.Data.SqlClient.SqlParameter("@零件流水号带空格", engineID);
                thisParms[10] = new System.Data.SqlClient.SqlParameter("@壳体编号型号", engineType);
                thisParms[11] = new System.Data.SqlClient.SqlParameter("@壳体编号型号带空格", engineType);
                thisParms[12] = new System.Data.SqlClient.SqlParameter("@QR码", engineID);
                thisParms[13] = new System.Data.SqlClient.SqlParameter("@基本流水号", 1);
                thisParms[14] = new System.Data.SqlClient.SqlParameter("@流水号文本", engineID);
                thisParms[15] = new System.Data.SqlClient.SqlParameter("@流水号条码", engineID);
                thisParms[16] = new System.Data.SqlClient.SqlParameter("@型号文本", engineType);
                thisParms[17] = new System.Data.SqlClient.SqlParameter("@型号条码", engineType);
                thisParms[18] = new System.Data.SqlClient.SqlParameter("@条码创建时间", DateTime.Now.ToShortDateString());
                return DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms);
            }

            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, err.Message);
                return false;

            }
        }
        /// <summary>
        /// 电子看板_装配零件_盆子类型_查询
        /// </summary>
        static public DataTable WorkPlatePartSelect(string opName, string engineID)
        {
            try
            {
                DataTable dt = new DataTable();
                string procedureName;
                procedureName = "电子看板_装配零件_盆子类型_查询";
                SqlParameter[] thisParms = new SqlParameter[2];
                thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
                thisParms[1] = new System.Data.SqlClient.SqlParameter("@发动机型号", engineID);
                DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
                return dt;
            }
            catch (Exception err)
            {
                ////ApplicationLog.WriteLog(err, err.Message);
                return null;
            }
        }
        /// <summary>
        /// [电子看板_发动机号_线首工位]信息手动用
        /// </summary>
        /// <param name="engineID">发动机号</param>
        /// <param name="engineTypeID">机型代码</param>
        /// <param name="partCode_Space">零件流水号带空格</param>
        /// <param name="partCode">零件流水号</param>
        /// <param name="shellCode">壳体编号型号</param>
        /// <param name="shellCode_Space">壳体编号型号带空格</param>
        /// <param name="QR_Code">QR码</param>
        /// <param name="engineCount">基本流水号</param>
        /// <param name="barCodeType">条码类型</param>
        /// <param name="engineTypeBase">基本机型</param>
        /// <param name="partCode_Text">流水号文本</param>
        /// <param name="partCode_BarCode">流水号条码</param>
        /// <param name="engineType_Text">型号文本</param>
        /// <param name="engineType_BarCode">型号条码</param>
        /// <param name="dt"></param>
        //static public void GetEngineIDFromFirstOpName(out string engineID, out int engineTypeID, out string partCode_Space,
        //    out string partCode, out string shellCode, out string shellCode_Space, out string QR_Code,
        //    out int engineCount, out int barCodeType, out string engineTypeBase,
        //    out string partCode_Text, out string partCode_BarCode,
        //    out string engineType_Text, out string engineType_BarCode,
        //    DataTable dt)
        //{
        //    engineID = "";
        //    engineTypeID = 0;
        //    partCode_Space = "";
        //    partCode = "";
        //    shellCode = "";
        //    shellCode_Space = "";
        //    QR_Code = "";
        //    engineCount = 0;
        //    barCodeType = 0;
        //    engineTypeBase = "";
        //    partCode_Text = "";
        //    partCode_BarCode = "";
        //    engineType_Text = "";
        //    engineType_BarCode = "";

        //    engineID = dt.Rows[0]["发动机号"].ToString();
        //    engineTypeID = Convert.ToInt32(dt.Rows[0]["机型代码"]);
        //    shellCode = dt.Rows[0]["壳体编号型号"].ToString();
        //    shellCode_Space = dt.Rows[0]["壳体编号型号带空格"].ToString();
        //    partCode = dt.Rows[0]["零件流水号"].ToString();
        //    partCode_Space = dt.Rows[0]["零件流水号带空格"].ToString();
        //    QR_Code = dt.Rows[0]["QR码"].ToString();
        //    engineCount = Convert.ToInt32(dt.Rows[0]["基本流水号"]);
        //    engineTypeBase = dt.Rows[0]["基本机型"].ToString();
        //    barCodeType = Convert.ToInt32(dt.Rows[0]["条码类型"]);
        //    partCode_Text = dt.Rows[0]["流水号文本"].ToString();
        //    partCode_BarCode = dt.Rows[0]["流水号条码"].ToString();
        //    engineType_Text = dt.Rows[0]["型号文本"].ToString();
        //    engineType_BarCode = dt.Rows[0]["型号条码"].ToString();

        //}

        /// <summary>
        /// [电子看板_发动机号_线首工位]信息自动用
        /// </summary>
        /// <param name="engineID">发动机号</param>
        /// <param name="engineTypeID">机型代码</param>
        /// <param name="partCode_Space">零件流水号带空格</param>
        /// <param name="partCode">零件流水号</param>
        /// <param name="shellCode">壳体编号型号</param>
        /// <param name="shellCode_Space">壳体编号型号带空格</param>
        /// <param name="QR_Code">QR码</param>
        /// <param name="engineCount">基本流水号</param>
        /// <param name="barCodeType">条码类型</param>
        /// <param name="engineTypeBase">基本机型</param>
        /// <param name="partCode_Text">流水号文本</param>
        /// <param name="partCode_BarCode">流水号条码</param>
        /// <param name="engineType_Text">型号文本</param>
        /// <param name="engineType_BarCode">型号条码</param>
        /// <param name="dt"></param>
        static public void GetEngineIDFromFirstOpName_Auto(out string engineID, out int engineTypeID, out string partCode_Space,
            out string partCode, out string shellCode, out string shellCode_Space, out string QR_Code,
            out int engineCount, out int barCodeType, out string engineTypeBase,
            out string partCode_Text, out string partCode_BarCode,
            out string engineType_Text, out string engineType_BarCode, out string CodeCreatetime,
            out string a_code, out string b_code, out string c_code, out string d_code,
            DataTable dt)
        {
            engineID = "";
            engineTypeID = 0;
            partCode_Space = "";
            partCode = "";
            shellCode = "";
            shellCode_Space = "";
            QR_Code = "";
            engineCount = 0;
            barCodeType = 0;
            engineTypeBase = "";
            partCode_Text = "";
            partCode_BarCode = "";
            engineType_Text = "";
            engineType_BarCode = "";

            engineID = dt.Rows[0]["发动机号"].ToString();
            engineTypeID = Convert.ToInt32(dt.Rows[0]["机型代码"]);
            shellCode = dt.Rows[0]["壳体编号型号"].ToString();
            shellCode_Space = dt.Rows[0]["壳体编号型号带空格"].ToString();
            partCode = dt.Rows[0]["零件流水号"].ToString();
            partCode_Space = dt.Rows[0]["零件流水号带空格"].ToString();
            QR_Code = dt.Rows[0]["QR码"].ToString();
            engineCount = Convert.ToInt32(dt.Rows[0]["基本流水号"]);
            engineTypeBase = dt.Rows[0]["基本机型"].ToString();
            barCodeType = Convert.ToInt32(dt.Rows[0]["条码类型"]);
            partCode_Text = dt.Rows[0]["流水号文本"].ToString();
            partCode_BarCode = dt.Rows[0]["流水号条码"].ToString();
            engineType_Text = dt.Rows[0]["型号文本"].ToString();
            engineType_BarCode = dt.Rows[0]["型号条码"].ToString();
            CodeCreatetime = dt.Rows[0]["条码创建时间"].ToString();
            a_code = dt.Rows[0]["总成代码"].ToString();
            b_code = dt.Rows[0]["零件图号"].ToString();
            c_code = dt.Rows[0]["邓氏码"].ToString();
            d_code = dt.Rows[0]["VPPS码"].ToString();
        }

    }
}
