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

namespace bizFacade
{
    /// <summary>
    /// 电子看板信息系统
    /// select 重量1,重量2,重量差,允许重量差,合格标志
    /// </summary>
    public partial class BaseDataSystemMES
    {
        /// <summary>
        /// 测量数据合格_查询_称重
        /// </summary>
        /// <param name="engineID"></param>
        /// <param name="dt"></param>
        static public void ShowWeightData_Select(string engineID, out DataTable dt)
        {
            string procedureName;
            procedureName = "测量数据合格_查询_称重";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@发动机号", engineID);
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
        }
        /// <summary>
        ///测量数据合格_合并_视图_查询_照相
        ///        select IsGoodBad as 合格标志, 列位置  
        ///from 测量数据合格_合并_视图
        ///where EngineID=@工件编号 and 工位号=@工位号
        ///order by 列位置        
        /// </summary>
        /// <param name="engineID"></param>
        /// <param name="opName"></param>
        /// <param name="dt"></param>
        static public void ShowPicData_Select(string engineID, string opName, out DataTable dt)
        {
            string procedureName;
            procedureName = "测量数据合格_合并_视图_查询_照相";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@发动机号", engineID);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
        }

        /// <summary>
        /// insert into 电子看板_发动机号_分线组件装配关系
        ///(工位号,发动机号,机型代码,发动机型号,工位号_分线,发动机号_分线,机型代码_分线,发动机型号_分线)
        ///values(@工位号,@发动机号,@机型代码,@发动机型号,@工位号_分线,@发动机号_分线,@机型代码_分线,@发动机型号_分线)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="engineID"></param>
        /// <param name="engineTypeID"></param>
        /// <param name="engineType"></param>
        /// <param name="opName_SubLine"></param>
        /// <param name="engineID_SubLine"></param>
        /// <param name="engineTypeID_SubLine"></param>
        /// <param name="engineType_SubLine"></param>
        static public void MailLineAndSubLineData_Insert(string opName, string engineID, int engineTypeID, string engineType, string opName_SubLine, string engineID_SubLine, int engineTypeID_SubLine, string engineType_SubLine)
        {
            string procedureName;
            procedureName = "电子看板_发动机号_分线组件装配关系_增加";
            SqlParameter[] thisParms = new SqlParameter[8];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@发动机号", engineID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@机型代码", engineTypeID);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@发动机型号", engineType);
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@工位号_分线", opName_SubLine);
            thisParms[5] = new System.Data.SqlClient.SqlParameter("@发动机号_分线", engineID_SubLine);
            thisParms[6] = new System.Data.SqlClient.SqlParameter("@机型代码_分线", engineTypeID_SubLine);
            thisParms[7] = new System.Data.SqlClient.SqlParameter("@发动机型号_分线", engineType_SubLine);
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms);
        }
        /// <summary>
        /// 电子看板_发动机号_线首工位_查询_根据发动机号
        /// select 工位号,订单号,发动机号,基本机型,机型代码,发动机型号,托盘号,
        /// 条码类型,零件流水号,零件流水号带空格,壳体编号型号,壳体编号型号带空格,QR码
        /// from dbo.电子看板_发动机号_线首工位
        /// where 发动机号=@发动机号 and 是否禁用=0
        /// </summary>
        /// <param name="engineID"></param>
        /// <param name="dt"></param>
        static public void GetEngineID_Select(string engineID, out DataTable dt)
        {
            string procedureName;
            procedureName = "电子看板_发动机号_线首工位_查询_根据发动机号";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@发动机号", engineID);
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
        }
        /// <summary>
        /// select 工位号,发动机号,机型代码,发动机型号,返修数据
        /// from   电子看板_发动机号_工件下线
        /// where  零件流水号=@零件流水号 --and 是否禁用=0
        /// </summary>
        /// <param name="partCode">零件流水号</param>
        /// <param name="dt"></param>
        static public void GetRepareData_Select(string partCode, out DataTable dt)
        {
            string procedureName;
            procedureName = "电子看板_发动机号_工件下线_查询";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@零件流水号", partCode);
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
        }

        /// <summary>
        ///select '' as 工位号,发动机号,机型代码,发动机型号,'' as 返修数据
        ///from   电子看板_发动机号_线首工位
        ///where  零件流水号_返修=@零件流水号 and 是否禁用=0
        /// </summary>
        /// <param name="partCode">零件流水号</param>
        /// <param name="dt"></param>
        static public void GetRepareData_OtherLine_Select(string partCode, out DataTable dt)
        {
            string procedureName;
            procedureName = "电子看板_发动机号_工件下线_其它装配线_查询";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@零件流水号", partCode);
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
        }

        //
        /// <summary>
        /// 电子看板_发动机号_工件下线_增加
        /// @工位号 nvarchar(50) = null,
        /// @发动机号 nvarchar(50) = null,
        /// @机型代码 int = 1,
        /// @发动机型号 nvarchar(50) = null,
        /// @返修数据 nvarchar(4000) = null        
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="partCode">零件流水号</param>
        /// <param name="engineID"></param>
        /// <param name="engineTypeID"></param>
        /// <param name="engineType"></param>
        /// <param name="engineData"></param>
        static public void GetRepareData_Insert(string opName,string partCode, 
            string engineID, int engineTypeID, string engineType, string engineData)
        {
            string procedureName;
            procedureName = "电子看板_发动机号_工件下线_增加";
            SqlParameter[] thisParms = new SqlParameter[6];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@零件流水号", partCode);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@发动机号", engineID);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@机型代码", engineTypeID);
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@发动机型号", engineType);
            thisParms[5] = new System.Data.SqlClient.SqlParameter("@返修数据", engineData);
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms);
        }
        /// <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;
            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, 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("@条码创建时间", codeCreatetime);
                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_SY(string opName, string engineID1, 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;
            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, 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("@发动机号", engineID1);
                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);
                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="EngineTypeID"></param>
        /// <param name="EngineID"></param>
        /// <param name="dt"></param>
        static public void GetTime_Arrived(int EngineTypeID, string EngineID, out DataTable dt)
        {
            string procedureName;
            procedureName = "测量数据发动机在线状态_工件到位时间_查询";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@机型代码", EngineTypeID);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@发动机号", EngineID);
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
        }



        //2013-01-06 王可心 手动创建编号时调用
        /// <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>
        /// 电子看板_发动机号_线首工位_查询_QR码返修
        /// </summary>
        /// <param name="QR"></param>
        /// <param name="dt"></param>
        static public void GetRepareDataSelect_QR(string QR, out DataTable dt)
        {
            string procedureName;
            procedureName = "电子看板_发动机号_线首工位_查询_QR码返修";
            SqlParameter[] thisParms = new SqlParameter[1];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@QR码", QR);
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
        }
        /// <summary>
        /// 电子看板_发动机号_线首工位_查询_两行条码返修
        /// </summary>
        /// <param name="QR"></param>
        /// <param name="dt"></param>
        static public void GetRepareDataSelect_EngingeRepair(string barCode_EngineType, string barCode_EngineNum, out DataTable dt)
        {
            string procedureName;
            procedureName = "电子看板_发动机号_线首工位_查询_两行条码返修";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@型号条码", barCode_EngineType);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@流水号条码", barCode_EngineNum);
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
        }

    }
}
