using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

using System.Data.OleDb;


using DataLinkMesWork;

//using SystemFramework;

namespace bizFacade
{
    /// <summary>
    /// 关键零部件追溯
    /// </summary>
    public partial class BaseDataSystemMES
    {
        /// <summary>
        /// 创建增加数据用表
        /// 获得物料已经验证的记录
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static DataTable GetInsertTableMaterialVerifyOver(DataTable dt)
        {
            DataTable dt1;
            DataRow row;

            dt1 = dt.Clone();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                row = dt1.NewRow();
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    row[j] = dt.Rows[i][j];
                }
                if (Convert.ToInt32(row["验证结果"]) != 0)
                {
                    dt1.Rows.Add(row);
                }

            }

            return dt1;
        }
        /// <summary>
        /// 创建增加数据用表
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static DataTable GetInsertTable(DataTable dt)
        {
            DataTable dt1;
            DataRow row;

            dt1 = dt.Clone();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                row = dt1.NewRow();
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    row[j] = dt.Rows[i][j];
                }
                dt1.Rows.Add(row);

            }

            return dt1;
        }

        /// <summary>
        /// MES_装配数据_零部件追溯_临时状态_增加
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        //public static void VerifyAssemblyPartTempTableInsert(DataTable dt)
        //{
        //    string sql;
        //    sql = "INSERT INTO [MES_装配数据_零部件追溯_临时状态]"
        //        + "([订单号],[SAP物料号],[发动机型号],[发动机型号代码], [发动机机型], "
        //        + "[发动机数量], [厂牌编号起始号], [客户名称],[投料日期],[文件编号],[集团名称],[通知号],"
        //        + "[功率],[指南文件编号],[装机状态],[适用状态],[物料描述],[计划下达日期],[计划完工日期],"
        //        + "[主配厂家],[工位号], [工位名称],[物料号], [零件图号], [零件名称], [零件数量],"
        //        + "[是否扫描],[扫描方式代码], [扫描方式], [厂家代码],[生产厂家],  "
        //        + "[操作指导],[发动机号],[追踪代码],[物料号表索引号],[零件数量验证],"
        //        + "[物料条码], [物料条码物料号], [物料条码批次],[验证结果], [操作者工号], [操作者姓名], [班次代码], "
        //        + "物料来源代码,物料来源,是否禁用代码,是否禁用,被强制验证物料号,更改代码,更改原因)"

        //        + "VALUES(@订单号,@SAP物料号,@发动机型号,@发动机型号代码,@发动机机型,"
        //        + "@发动机数量,@厂牌编号起始号,@客户名称,@投料日期,@文件编号,@集团名称,@通知号,"
        //        + "@功率,@指南文件编号,@装机状态,@适用状态,@物料描述,@计划下达日期,@计划完工日期,"
        //        + "@主配厂家,@工位号,@工位名称,@物料号,@零件图号,@零件名称,@零件数量,"
        //        + " @是否扫描,@扫描方式代码,@扫描方式,@厂家代码,@生产厂家,"
        //        + "@操作指导,@发动机号,@追踪代码,@物料号表索引号,@零件数量验证,"
        //        + "@物料条码,@物料条码物料号,@物料条码批次,@验证结果,@操作者工号,@操作者姓名,@班次代码,"
        //        + "@物料来源代码,@物料来源,@是否禁用代码,@是否禁用,@被强制验证物料号,@更改代码,@更改原因)";


        //    OleDbParameter[] thisParms1 = new OleDbParameter[50];
        //    //    + "([订单号],[SAP物料号],[发动机型号],[发动机型号代码], [发动机机型], "
        //    thisParms1[0] = new OleDbParameter("@订单号", OleDbType.VarChar, 50, "订单号");
        //    thisParms1[1] = new OleDbParameter("@SAP物料号", OleDbType.VarChar, 50, "SAP物料号");
        //    thisParms1[2] = new OleDbParameter("@发动机型号", OleDbType.VarChar, 50, "发动机型号");
        //    thisParms1[3] = new OleDbParameter("@发动机型号代码", OleDbType.Integer, 4, "发动机型号代码");
        //    thisParms1[4] = new OleDbParameter("@发动机机型", OleDbType.VarChar, 50, "发动机机型");

        //    //     + "@发动机数量,@厂牌编号起始号,@客户名称,@投料日期,@文件编号,@集团名称,@通知号,"
        //    thisParms1[5] = new OleDbParameter("@发动机数量", OleDbType.Integer, 4, "发动机数量");
        //    thisParms1[6] = new OleDbParameter("@厂牌编号起始号", OleDbType.Integer, 4, "厂牌编号起始号");
        //    thisParms1[7] = new OleDbParameter("@客户名称", OleDbType.VarChar, 50, "客户名称");
        //    thisParms1[8] = new OleDbParameter("@投料日期", OleDbType.DBDate, 8, "投料日期");
        //    thisParms1[9] = new OleDbParameter("@文件编号", OleDbType.VarChar, 50, "文件编号");
        //    thisParms1[10] = new OleDbParameter("@集团名称", OleDbType.VarChar, 50, "集团名称");
        //    thisParms1[11] = new OleDbParameter("@通知号", OleDbType.VarChar, 50, "通知号");

        //    //    + "@功率,@指南文件编号,@装机状态,@适用状态,@物料描述,@计划下达日期,@计划完工日期,"
        //    thisParms1[12] = new OleDbParameter("@功率", OleDbType.VarChar, 50, "功率");
        //    thisParms1[13] = new OleDbParameter("@指南文件编号", OleDbType.VarChar, 50, "指南文件编号");
        //    thisParms1[14] = new OleDbParameter("@装机状态", OleDbType.VarChar, 50, "装机状态");
        //    thisParms1[15] = new OleDbParameter("@适用状态", OleDbType.DBDate, 8, "适用状态");
        //    thisParms1[16] = new OleDbParameter("@物料描述", OleDbType.VarChar, 255, "物料描述");
        //    thisParms1[17] = new OleDbParameter("@计划下达日期", OleDbType.DBDate, 8, "计划下达日期");
        //    thisParms1[18] = new OleDbParameter("@计划完工日期", OleDbType.DBDate, 8, "计划完工日期");

        //    //    + "@主配厂家,@工位号,@工位名称,@物料号,@零件图号,@零件名称,@零件数量,"

        //    thisParms1[19] = new OleDbParameter("@主配厂家", OleDbType.VarChar, 50, "主配厂家");
        //    thisParms1[20] = new OleDbParameter("@工位号", OleDbType.VarChar, 50, "工位号");
        //    thisParms1[21] = new OleDbParameter("@工位名称", OleDbType.VarChar, 50, "工位名称");
        //    thisParms1[22] = new OleDbParameter("@物料号", OleDbType.VarChar, 50, "物料号");
        //    thisParms1[23] = new OleDbParameter("@零件图号", OleDbType.VarChar, 50, "零件图号");
        //    thisParms1[24] = new OleDbParameter("@零件名称", OleDbType.VarChar, 50, "零件名称");
        //    thisParms1[25] = new OleDbParameter("@零件数量", OleDbType.Integer, 4, "零件数量");

        //    //    +"[是否扫描],扫描方式代码, [扫描方式], [厂家代码],[生产厂家],  "

        //    thisParms1[26] = new OleDbParameter("@是否扫描", OleDbType.Integer, 4, "是否扫描");
        //    thisParms1[27] = new OleDbParameter("@扫描方式代码", OleDbType.Integer, 4, "扫描方式代码");
        //    thisParms1[28] = new OleDbParameter("@扫描方式", OleDbType.VarChar, 50, "扫描方式");
        //    thisParms1[29] = new OleDbParameter("@厂家代码", OleDbType.VarChar, 50, "厂家代码");
        //    thisParms1[30] = new OleDbParameter("@生产厂家", OleDbType.VarChar, 50, "生产厂家");

        //    //+ "@操作指导,@发动机号,@物料号表索引号,@零件数量验证,"

        //    thisParms1[31] = new OleDbParameter("@操作指导", OleDbType.VarChar, 255, "操作指导");
        //    thisParms1[32] = new OleDbParameter("@发动机号", OleDbType.VarChar, 50, "发动机号");
        //    thisParms1[33] = new OleDbParameter("@追踪代码", OleDbType.VarChar, 50, "追踪代码");
        //    thisParms1[34] = new OleDbParameter("@物料号表索引号", OleDbType.Integer, 4, "物料号表索引号");
        //    thisParms1[35] = new OleDbParameter("@零件数量验证", OleDbType.Integer, 4, "零件数量验证");

        //    //     +"[物料条码], [物料条码物料号], [物料条码批次],@验证结果, [操作者工号], [操作者姓名], [班次代码], "
        //    thisParms1[36] = new OleDbParameter("@物料条码", OleDbType.VarChar, 50, "物料条码");
        //    thisParms1[37] = new OleDbParameter("@物料条码物料号", OleDbType.VarChar, 50, "物料条码物料号");
        //    thisParms1[38] = new OleDbParameter("@物料条码批次", OleDbType.VarChar, 50, "物料条码批次");
        //    thisParms1[39] = new OleDbParameter("@验证结果", OleDbType.Integer, 4, "验证结果");
        //    thisParms1[40] = new OleDbParameter("@操作者工号", OleDbType.VarChar, 50, "操作者工号");
        //    thisParms1[41] = new OleDbParameter("@操作者姓名", OleDbType.VarChar, 50, "操作者姓名");
        //    thisParms1[42] = new OleDbParameter("@班次代码", OleDbType.VarChar, 50, "班次代码");

        //    //    +"物料来源代码,物料来源,是否禁用代码,是否禁用,被强制验证物料号,更改代码,更改原因)"

        //    thisParms1[43] = new OleDbParameter("@物料来源代码", OleDbType.Integer, 4, "物料来源代码");
        //    thisParms1[44] = new OleDbParameter("@物料来源", OleDbType.VarChar, 50, "物料来源");
        //    thisParms1[45] = new OleDbParameter("@是否禁用代码", OleDbType.Integer, 4, "是否禁用代码");
        //    thisParms1[46] = new OleDbParameter("@是否禁用", OleDbType.VarChar, 50, "是否禁用");
        //    thisParms1[47] = new OleDbParameter("@被强制验证物料号", OleDbType.VarChar, 50, "被强制验证物料号");
        //    thisParms1[48] = new OleDbParameter("@更改代码", OleDbType.VarChar, 50, "更改代码");
        //    thisParms1[49] = new OleDbParameter("@更改原因", OleDbType.VarChar, 255, "更改原因");

        //    DataAccess.ExecuteDataTable_OleDb_Insert_Access(sql, dt, ref  thisParms1);
        //}
        /// <summary>
        /// MES_装配数据_零部件追溯_临时状态_删除
        /// </summary>
        /// <returns></returns>
        //public static bool VerifyAssemblyPartTempTableDelete()
        //{
        //    string sql;
        //    sql = "DELETE FROM  [MES_装配数据_零部件追溯_临时状态] ";

        //    return DataAccess.ExecuteSQL_OleDb_Access(sql);
        //}        
        /// <summary>
        /// MES_装配数据_零部件追溯_临时状态_删除
        /// </summary>
        /// <param name="engineNumber"></param>
        /// <param name="opName"></param>
        /// <returns></returns>
        //public static bool VerifyAssemblyPartTempTableDelete(string engineNumber, string opName)
        //{
        //    string sql;
        //    sql = "DELETE FROM  [MES_装配数据_零部件追溯_临时状态] "
        //        + " where 发动机号='" + engineNumber + "' "
        //        + " and 工位号='" + opName + "'";

        //    return DataAccess.ExecuteSQL_OleDb_Access(sql);
        //}
        /// <summary>
        /// MES_装配数据_零部件追溯_临时状态
        /// 符合条件的行数
        /// </summary>
        /// <returns></returns>
        //public static int VerifyAssemblyPartTempTableCount()
        //{
        //    int count;
        //    string sql;
        //    sql = "SELECT COUNT(*) FROM  [MES_装配数据_零部件追溯_临时状态] ";

        //    DataAccess.ExecuteOutNum_OleDb_Access(sql, out  count);
        //    return count;

        //}
        /// <summary>
        /// MES_装配数据_零部件追溯_临时状态
        /// 符合条件的行数
        /// </summary>
        /// <param name="engineID"></param>
        /// <returns></returns>
        //public static int VerifyAssemblyPartTempTableCountByEngineID(string engineID)
        //{
        //    int count;
        //    string sql;
        //    sql = "SELECT COUNT(*) FROM  [MES_装配数据_零部件追溯_临时状态] "
        //    +" where 发动机号='" + engineID + "' ";
        //    DataAccess.ExecuteOutNum_OleDb_Access(sql, out  count);
        //    return count;

        //}
        /// <summary>
        /// MES_装配数据_零部件追溯_临时状态
        /// 符合条件的行数
        /// </summary>
        /// <param name="engineTraceCode"></param>
        /// <returns></returns>
        //public static int VerifyAssemblyPartTempTableCountByEngineTraceCode(string engineTraceCode)
        //{
        //    int count;
        //    string sql;
        //    sql = "SELECT COUNT(*) FROM  [MES_装配数据_零部件追溯_临时状态] "
        //    +" where 追踪代码='" + engineTraceCode + "' ";

        //    DataAccess.ExecuteOutNum_OleDb_Access(sql, out  count);
        //    return count;
        //}
        ///// <summary>
        ///// MES_装配数据_零部件追溯_临时状态
        ///// 符合条件的行数
        ///// </summary>
        ///// <param name="EngineNumber"></param>
        ///// <returns></returns>
        //public static int VerifyAssemblyPartTempTableCount(string engineNumber, string opName)
        //{
        //    int count;
        //    string sql;
        //    sql = "SELECT COUNT(*) FROM  [MES_装配数据_零部件追溯_临时状态] "
        //        + " where 发动机号='" + engineNumber + "' "
        //        + " and 工位号='" + opName + "'";

        //    DataAccess.ExecuteOutNum_OleDb_Access(sql, out  count);
        //    return count;

        //}
        /// <summary>
        /// MES_装配数据_零部件追溯_临时状态_选择
        /// </summary>
        /// <returns></returns>
        //public static DataTable VerifyAssemblyPartTempTableSelect()
        //{
        //    string sql;
        //    DataTable dt;
        //    sql = "SELECT * FROM  [MES_装配数据_零部件追溯_临时状态] ";

        //    DataAccess.ExecuteDataTable_OleDb_Access(sql, out  dt);

        //    return dt;
        //}       
        /// <summary>
        /// MES_装配数据_零部件追溯_临时状态_更新
        /// </summary>
        /// <param name="ID">物料号表索引号</param>
        /// <param name="barCode">物料条码</param>
        /// <param name="barCode_Material">物料条码物料号</param>
        /// <param name="barCode_SerailNumber">物料条码批次</param>
        /// <param name="materialVerifyResult">验证结果</param>
        /// <returns></returns>
        //public static bool VerifyAssemblyPartTempTableUpdate(int ID,string barCode, string barCode_Material, 
        //    string barCode_SerailNumber, int materialVerifyResult)
        //{
        //    string sql;
        //    sql = "UPDATE  [MES_装配数据_零部件追溯_临时状态] "
        //        + "SET 物料条码='" + barCode + "'"
        //        + ",物料条码物料号='" + barCode_Material + "'"
        //        + ",物料条码批次='" + barCode_SerailNumber + "'"
        //        + ",验证结果=" + materialVerifyResult.ToString()
        //        + " where ID=" + Convert.ToString(ID);

        //    return DataAccess.ExecuteSQL_OleDb_Access(sql);
        //}

        /// <summary>
        /// MES_装配数据_零部件追溯_临时状态_更新
        /// </summary>
        /// <param name="materialIndex">物料号表索引号</param>
        /// <param name="engineNumber">发动机号</param>
        /// <param name="opName">工位号</param>
        /// <param name="barCode">物料条码</param>
        /// <param name="barCode_Material">物料条码物料号</param>
        /// <param name="barCode_SerailNumber">物料条码批次</param>
        /// <param name="materialVerifyResult">验证结果</param>
        /// <returns></returns>
        //public static bool VerifyAssemblyPartTempTableUpdate(int materialIndex, string engineNumber, string opName,
        //    string barCode, string barCode_Material, string barCode_SerailNumber, int materialVerifyResult)
        //{
        //    string sql;
        //    sql = "UPDATE  [MES_装配数据_零部件追溯_临时状态] "
        //        + "SET 物料条码='" + barCode + "'"
        //        + ",物料条码物料号='" + barCode_Material + "'"
        //        + ",物料条码批次='" + barCode_SerailNumber + "'"
        //        + ",验证结果=" + materialVerifyResult.ToString()
        //        + " where ID=" + materialIndex.ToString();
        //    //sql = "UPDATE  [MES_装配数据_零部件追溯_临时状态] "
        //    //    + "SET 物料条码='" + barCode + "'"
        //    //    + ",物料条码物料号='" + barCode_Material + "'"
        //    //    + ",物料条码批次='" + barCode_SerailNumber + "'"
        //    //    + ",验证结果=" + materialVerifyResult.ToString()
        //    //    + " where 物料号表索引号=" + materialIndex.ToString();

        //    return DataAccess.ExecuteSQL_OleDb_Access(sql);
        //}

        /// <summary>
        /// MES_装配数据_零部件追溯_临时状态_更新
        /// </summary>
        /// <param name="materialIndex">物料号表索引号</param>
        /// <param name="barCode">物料条码</param>
        /// <param name="barCode_Material">物料条码物料号</param>
        /// <param name="barCode_SerailNumber">物料条码批次</param>
        /// <param name="engineID"></param>
        /// <param name="traceCode"></param>
        /// <param name="materialVerifyResult">验证结果</param>
        /// <returns></returns>
        //public static bool VerifyAssemblyPartTempTableUpdate_New(int materialIndex,
        //    string barCode, string barCode_Material, string barCode_SerailNumber,string engineID,string traceCode, int materialVerifyResult)
        //{
        //    string sql;
        //    sql = "UPDATE  [MES_装配数据_零部件追溯_临时状态] "
        //        + "SET 物料条码='" + barCode + "'"
        //        + ",物料条码物料号='" + barCode_Material + "'"
        //        + ",物料条码批次='" + barCode_SerailNumber + "'"
        //        + ",发动机号='" + engineID + "'"
        //        + ",追踪代码='" + traceCode + "'"
        //        + ",验证结果=" + materialVerifyResult.ToString()
        //        + ",操作时间='" + DateTime.Now.ToString("G")+"'"
        //        + " where ID=" + materialIndex.ToString();

        //    return DataAccess.ExecuteSQL_OleDb_Access(sql);
        //}
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        //public static bool VerifyAssemblyPartTempTableSelectByMainMaterialCode(out DataTable dt)
        //{
        //    dt = null;
        //    string sql;
        //    sql = "SELECT * FROM   [MES_装配数据_零部件追溯_临时状态] WHERE 是否主物料 = 1";

        //    return DataAccess.ExecuteDataTable_OleDb_Access(sql, out  dt);
        //}
        /// <summary>
        /// MES_装配数据_零部件追溯_临时状态_更新
        /// 取消验证
        /// </summary>
        /// <param name="ID">ID</param>
        /// <returns></returns>
        //public static bool VerifyAssemblyPartTempTableUpdate(int ID)
        //{
        //    string sql;
        //    sql = "UPDATE  [MES_装配数据_零部件追溯_临时状态] "
        //        + "SET 物料条码=''"
        //        + ",物料条码物料号=''"
        //        + ",物料条码批次=''"
        //        + ",验证结果=0 " 
        //        + " where ID=" + Convert.ToString(ID);

        //    return DataAccess.ExecuteSQL_OleDb_Access(sql);
        //}
    }
}
