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>
        /// MES_装配数据_零部件追溯_数据主表_增加_电子看板
        /// @发动机号 nvarchar(50)=null,
        /// @发动机型号 nvarchar(50)=null,
        /// @机型代码 int=null,
        /// @订单号 nvarchar(50)=null,
        /// @工位号 nvarchar(50)=null,
        /// @到达时间 datetime,
        /// @离开时间 datetime,
        /// @操作者工号 nvarchar(50)=null,
        /// @班次代码 nvarchar(50)=null,
        /// @放行方式 int =null,
        /// @工位类型 nvarchar(50)=null,
        /// @追溯代码 int = null output
        /// </summary>
        /// <param name="engineID">发动机号</param>
        /// <param name="engineType">发动机型号</param>
        /// <param name="engineTypeID">机型代码</param>
        /// <param name="orderForm">订单号</param>
        /// <param name="opName">工位号</param>
        /// <param name="arrivedTime">到达时间</param>
        /// <param name="leavTime">离开时间</param>
        /// <param name="opperatorCode">操作者工号</param>
        /// <param name="shiftCode">班次代码</param>
        /// <param name="goOverType">放行方式</param>
        /// <param name="opNameType">工位类型</param>
        /// <param name="traceCode">追溯代码</param>
        static public void MaterialMailTable_Insert(string engineID,string engineType,int engineTypeID,string orderForm,string opName, 
            DateTime arrivedTime,DateTime leavTime,string opperatorCode,string shiftCode,
            int goOverType,string opNameType,out int traceCode)
        {

            string procedureName;
            try
            {
                procedureName = "MES_装配数据_零部件追溯_数据主表_增加_电子看板";
                SqlParameter[] thisParms = new SqlParameter[12];
                thisParms[0] = new System.Data.SqlClient.SqlParameter("@发动机号", engineID);
                thisParms[1] = new System.Data.SqlClient.SqlParameter("@发动机型号", engineType);
                thisParms[2] = new System.Data.SqlClient.SqlParameter("@机型代码", engineTypeID);
                thisParms[3] = new System.Data.SqlClient.SqlParameter("@订单号", orderForm);
                thisParms[4] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
                thisParms[5] = new System.Data.SqlClient.SqlParameter("@到达时间", arrivedTime);
                thisParms[6] = new System.Data.SqlClient.SqlParameter("@离开时间", leavTime);
                thisParms[7] = new System.Data.SqlClient.SqlParameter("@操作者工号", opperatorCode);
                thisParms[8] = new System.Data.SqlClient.SqlParameter("@班次代码", shiftCode);
                thisParms[9] = new System.Data.SqlClient.SqlParameter("@放行方式", goOverType);
                thisParms[10] = new System.Data.SqlClient.SqlParameter("@工位类型", opNameType);
                thisParms[11] = new System.Data.SqlClient.SqlParameter("@追溯代码", 0);
                thisParms[11].Direction = ParameterDirection.Output;
                DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms);

                traceCode = Convert.ToInt32(thisParms[11].Value);
            }
            catch (Exception err)
            {
                traceCode = 0;
                ////ApplicationLog.WriteLog(err, err.Message);
            }

        }


        /// <summary>
        /// MES_装配数据_零部件追溯_增加_电子看板
        ///ALTER      PROCEDURE MES_装配数据_零部件追溯_增加_电子看板
        ///@追溯代码 int = null,
        ///@发动机号 nvarchar(50)=null,
        ///@工位号 nvarchar(50)=null,
        ///@零件图号 nvarchar(50)=null,
        ///@零件名称 nvarchar(50)=null,
        ///@零件数量 int=null,
        ///@生产厂家 nvarchar(50)=null,
        ///@物料条码批次 nvarchar(50)=null,
        ///@操作者工号 nvarchar(50)=null,
        ///@班次代码 nvarchar(50)=null
        /// </summary>
        /// <param name="traceCode"></param>
        /// <param name="engineID"></param>
        /// <param name="opName"></param>
        /// <param name="opperatorCode"></param>
        /// <param name="shiftCode"></param>
        /// <param name="dt"></param>
        static public void MaterialSubTable_Insert(int traceCode,string engineID, string opName,string opperatorCode,string shiftCode,
            DataTable dt)
        {
            string procedureName;
            procedureName = "MES_装配数据_零部件追溯_增加_电子看板";
            SqlParameter[] thisParms = new SqlParameter[10];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@追溯代码", traceCode);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@发动机号", engineID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@工位号", opName);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@操作者工号", opperatorCode);
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@班次代码", shiftCode);
            thisParms[5] = new System.Data.SqlClient.SqlParameter("@零件图号", SqlDbType.NVarChar, 50, "零件图号");
            thisParms[6] = new System.Data.SqlClient.SqlParameter("@零件名称", SqlDbType.NVarChar, 50, "零件名称");
            thisParms[7] = new System.Data.SqlClient.SqlParameter("@零件数量", SqlDbType.Int, 4, "零件数量");
            thisParms[8] = new System.Data.SqlClient.SqlParameter("@生产厂家", SqlDbType.NVarChar, 50, "生产厂家");
            thisParms[9] = new System.Data.SqlClient.SqlParameter("@物料条码批次", SqlDbType.NVarChar, 50, "零件批号");
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms,dt);
        }
        /// <summary>
        /// 保存物料信息
        /// </summary>
        /// <param name="engineID">发动机号</param>
        /// <param name="engineType">发动机型号</param>
        /// <param name="engineTypeID">机型代码</param>
        /// <param name="orderForm">订单号</param>
        /// <param name="opName">工位号</param>
        /// <param name="arrivedTime">到达时间</param>
        /// <param name="leavTime">离开时间</param>
        /// <param name="opperatorCode">操作者工号</param>
        /// <param name="shiftCode">班次代码</param>
        /// <param name="goOverType">放行方式</param>
        /// <param name="opNameType">工位类型</param>
        /// <param name="dt">装配物料列表</param>
        static public void Material_Insert_B5A(string engineID, string engineType, int engineTypeID, string orderForm, string opName,
            DateTime arrivedTime, DateTime leavTime, string opperatorCode, string shiftCode,
            int goOverType, string opNameType, DataTable dt)
        {
            int traceCode;
            //MES_装配数据_零部件追溯_数据主表_增加_电子看板
            MaterialMailTable_Insert( engineID,  engineType, engineTypeID,orderForm,opName,arrivedTime, leavTime, opperatorCode, shiftCode,goOverType, opNameType,out  traceCode);
            //MES_装配数据_零部件追溯_增加_电子看板
            MaterialSubTable_Insert(traceCode, engineID, opName, opperatorCode, shiftCode, dt);
        }

        /// <summary>
        /// 电子看板_工位名称与产品型号工艺卡_查询
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="engineTypeID"></param>
        /// <param name="PdfSrc"></param>
        static public void GetPdfSrc(string opName, string engineTypeID, out string PdfSrc)
        {
            string sql;
            DataTable dt;
            PdfSrc = null;
            sql = "exec 电子看板_工位名称与产品型号工艺卡_查询 '" + opName + "'," + engineTypeID;
            DataAccess.ExecuteDataTable(sql, out dt);
            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    PdfSrc = dt.Rows[0]["工艺卡路径"].ToString();
                }
            }
        }
    }
}
