using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DataLinkMesWork;
using System.Data.OleDb;

//using SystemFramework;

namespace bizFacade
{
    public partial class BaseDataSystemMES
    {

        /// <summary>
        /// 删除[追踪代码]
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="TraceCode"></param>
        /// <returns></returns>
        //public static bool TraceTableDelete(string opName, string TraceCode)
        //{
        //    string sql;
        //    sql = "DELETE FROM [MES_装配数据_发动机号_追踪代码] "
        //            + " where (追踪代码='" + TraceCode + "'"
        //            + " and 工位号='" + opName + "')";
        //    return DataAccess.ExecuteSQL_OleDb_Access(sql);
        //}
        /// <summary>
        /// MES_装配数据_发动机号_追踪代码
        /// 订单号
        /// Access
        /// </summary>
        /// <param name="traceCode"></param>
        /// <param name="connectionString_Access"></param>
        /// <param name="dt"></param>
        /// <returns></returns>
        //public static bool TraceTable_Select(string traceCode, string connectionString_Access,out DataTable dt)
        //{
        //    string sql;
        //    sql = "SELECT top  1 * FROM MES_装配数据_发动机号_追踪代码 "
        //        + " WHERE 追踪代码 = '" + traceCode + "'";
        //    return DataAccess.ExecuteDataTable_OleDb_Access(sql, connectionString_Access, out dt);
        //}

        /// <summary>
        /// MES_装配数据_发动机号_追踪代码
        /// Access
        /// </summary>
        /// <param name="EngineTraceCode"></param>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static bool TraceTable_Select(string EngineTraceCode, out DataTable dt)
        {
            string sql;
            //sql = "SELECT * FROM MES_装配数据_发动机号_追踪代码 "
            //    + " WHERE 发动机号 = '" + EngineTraceCode + "'";
            sql = "SELECT top 1 * FROM MES_装配数据_发动机号_追踪代码 "
                + " WHERE 追踪代码 = '" + EngineTraceCode + "'"
                +" order by 操作时间 desc ";
            //if (!SQLCommon.SqlServerConnectionStatus)
            //{
            //    return DataAccess.ExecuteDataTable_OleDb_Access(sql, out dt);
            //}
            //else
            {
                return DataAccess.ExecuteDataTable(sql, out dt);

            }
        }
        /// <summary>
        /// [MES_装配数据_零部件追溯_发动机号与缸盖号]
        /// </summary>
        private static string GetSqlString_EngineID_CapNumber()
        {
            string sql = null;
            sql = "INSERT INTO [MES_装配数据_零部件追溯_发动机号与缸盖号] " +
                "(订单号,发动机号,追踪代码,工位号,到达时间,离开时间,操作者工号,班次代码,"
                + "[SAP物料号],[发动机型号],[发动机型号代码], [发动机机型], "
                + "[发动机数量], [厂牌编号起始号], [客户名称],[投料日期],[文件编号],[集团名称],[通知号],"
                + "[功率],[指南文件编号],[装机状态],[适用状态],[物料描述],[计划下达日期],[计划完工日期],[主配厂家],[零件类型])"
                + " VALUES ("
                //订单号,发动机号,追踪代码,工位号,到达时间,离开时间,操作者工号,班次代码
                + "'" + MaterialData.orderForm + "',"
                + "'" + MaterialData.engineNumber + "',"
                + "'" + MaterialData.engineTraceCode + "',"
                + "'" + MaterialData.opName + "',"
                + "'" + MaterialData.arrivedTime.ToString("G") + "',"
                + "'" + MaterialData.leavedTime.ToString("G") + "',"
                + "'" + MaterialData.operatorCode + "',"
                + "'" + MaterialData.operatorShift + "',"
                //+ "[SAP物料号],[发动机型号],[发动机型号代码], [发动机机型], "

                + "'" + MaterialData.sAPMaterialNumber + "',"
                + "'" + MaterialData.engineNumberType + "',"
                + "" + MaterialData.engineNumberCode + ","//int
                + "'" + MaterialData.engineNumberBasicType + "',"
                //+ "[发动机数量], [厂牌编号起始号], [客户名称],[投料日期],[文件编号],[集团名称],[通知号],"

                + "" + MaterialData.engineCount + ","//int
                + "" + MaterialData.engineNumberFirstID + ","//int
                + "'" + MaterialData.customesName + "',"
                + "'" + MaterialData.prepareMaterialDateTime.ToString("G") + "',"
                + "'" + MaterialData.fileCode + "',"
                + "'" + MaterialData.groupName + "',"
                + "'" + MaterialData.notifyCode + "',"
                //+ "[功率],[指南文件编号],[装机状态],[适用状态],[物料描述],[计划下达日期],[计划完工日期],主配厂家,零件类型"
                + "'" + MaterialData.n_Force + "',"
                + "'" + MaterialData.directFileCode + "',"
                + "'" + MaterialData.workEngineStatus + "',"
                + "'" + MaterialData.adaptDateTime.ToString("G") + "',"
                + "'" + MaterialData.materialDescript + "',"
                + "'" + MaterialData.planSendedDateTime.ToString("G") + "',"
                + "'" + MaterialData.planFinishDateTime.ToString("G") + "',"
                + "'" + MaterialData.mainPruduceFatory + "',"
                + "" + MaterialData.partType.ToString() + ") ";
            return sql;
        }
        ///// <summary>
        ///// 获得增加表[MES_装配数据_发动机号_追踪代码]的SQL语句
        ///// </summary>
        //private static string GetSqlStringFirstOpNameTableTrace_F2()
        //{
        //    string sql = null;
        //    sql = "INSERT INTO [MES_装配数据_零部件追溯_发动机号与缸盖号] " +
        //        "(订单号,发动机号,追踪代码,工位号,到达时间,离开时间,操作者工号,班次代码,"
        //        + "[SAP物料号],[发动机型号],[发动机型号代码], [发动机机型], "
        //        + "[发动机数量], [厂牌编号起始号], [客户名称],[投料日期],[文件编号],[集团名称],[通知号],"
        //        + "[功率],[指南文件编号],[装机状态],[适用状态],[物料描述],[计划下达日期],[计划完工日期],[主配厂家],[零件类型])"
        //        + " VALUES ("
        //        //订单号,发动机号,追踪代码,工位号,到达时间,离开时间,操作者工号,班次代码
        //        + "'" + MaterialData.orderForm + "',"
        //        + "'" + MaterialData.engineNumber + "',"
        //        + "'" + MaterialData.engineTraceCode + "',"
        //        + "'" + MaterialData.opName + "',"
        //        + "'" + MaterialData.arrivedTime.ToString("G") + "',"
        //        + "'" + MaterialData.leavedTime.ToString("G") + "',"
        //        + "'" + MaterialData.operatorCode + "',"
        //        + "'" + MaterialData.operatorShift + "',"
        //        //+ "[SAP物料号],[发动机型号],[发动机型号代码], [发动机机型], "

        //        + "'" + MaterialData.sAPMaterialNumber + "',"
        //        + "'" + MaterialData.engineNumberType + "',"
        //        + "" + MaterialData.engineNumberCode + ","//int
        //        + "'" + MaterialData.engineNumberBasicType + "',"
        //        //+ "[发动机数量], [厂牌编号起始号], [客户名称],[投料日期],[文件编号],[集团名称],[通知号],"

        //        + "" + MaterialData.engineCount + ","//int
        //        + "" + MaterialData.engineNumberFirstID + ","//int
        //        + "'" + MaterialData.customesName + "',"
        //        + "'" + MaterialData.prepareMaterialDateTime.ToString("G") + "',"
        //        + "'" + MaterialData.fileCode + "',"
        //        + "'" + MaterialData.groupName + "',"
        //        + "'" + MaterialData.notifyCode + "',"
        //        //+ "[功率],[指南文件编号],[装机状态],[适用状态],[物料描述],[计划下达日期],[计划完工日期],主配厂家,零件类型"
        //        + "'" + MaterialData.n_Force + "',"
        //        + "'" + MaterialData.directFileCode + "',"
        //        + "'" + MaterialData.workEngineStatus + "',"
        //        + "'" + MaterialData.adaptDateTime.ToString("G") + "',"
        //        + "'" + MaterialData.materialDescript + "',"
        //        + "'" + MaterialData.planSendedDateTime.ToString("G") + "',"
        //        + "'" + MaterialData.planFinishDateTime.ToString("G") + "',"
        //        + "'" + MaterialData.mainPruduceFatory + "',"
        //        + "" + MaterialData.partType.ToString() + ") ";
        //    return sql;
        //}
        /// <summary>
        /// 线首，用于物料追踪
        /// 传递到总线上线工位的数据成功，更新isOK=1
        /// MES_装配数据_发动机号_物料追踪
        /// SELECT * FROM [MES_装配数据_发动机号_追踪代码] WHERE IsOK = 0
        /// </summary>
        /// <param name="firstOpNameTraceCode">上线工位追溯代码</param>
        /// <returns></returns>
        //public static bool TableTraceUpdate(int firstOpNameTraceCode)
        //{
        //    string sql = null;
        //    sql = "UPDATE MES_装配数据_发动机号_追踪代码 SET IsOK = 1 WHERE 上线工位追溯代码 = " + firstOpNameTraceCode.ToString();
        //    return DataAccess.ExecuteSQL_OleDb_Access(sql);
        //}
        /// <summary>
        /// 线首，用于物料追踪
        /// 查询没有被传递到总线上线工位的数据
        /// MES_装配数据_发动机号_追踪代码
        /// SELECT * FROM [MES_装配数据_发动机号_追踪代码] WHERE IsOK = 0
        /// </summary>
        /// <returns></returns>
        //public static bool TableTraceSelect(out DataTable dt)
        //{
        //    string sql = null;
        //    sql = "SELECT * FROM MES_装配数据_发动机号_追踪代码 WHERE IsOK = 0";
        //    return DataAccess.ExecuteDataTable_OleDb_Access(sql, out dt);
        //}

        /// <summary>
        /// 总线上线工位，用于物料追踪
        /// 增加数据到Access数据库
        /// MES_装配数据_发动机号_追踪代码
        /// INSERT INTO [MES_装配数据_发动机号_追踪代码]
        /// </summary>
        /// <param name="connectionString_Access_OpNameMainLine">零件类型（1缸体）（2缸盖）（3活塞连杆）</param>
        /// <returns></returns>
        //public static bool TableTraceInsert_MainLine(string connectionString_Access_OpNameMainLine)
        //{
        //    // <summary>
        //    // 上线工位追溯代码
        //    // </summary>
        //    int firstOpNameTraceCode;
        //    string sql = null;
        //    string sql2 = null;
        //    DataTable dt;
        //    DataRow dr;
        //    try
        //    {
        //        // 测试 connectionString_Access_OpNameMainLine 文件是否存在？
        //        if (!File.Exists(connectionString_Access_OpNameMainLine))
        //        {
        //            ////ApplicationLog.WriteLog("file not exists filename=:" + connectionString_Access_OpNameMainLine);
        //            return false;
        //        }
                
        //        // 线首，用于物料追踪
        //        // 查询没有被传递到总线上线工位的数据
        //        // MES_装配数据_发动机号_追踪代码
        //        // SELECT * FROM [MES_装配数据_发动机号_追踪代码] WHERE IsOK = 0
        //        TableTraceSelect(out  dt);
        //        if (dt == null) return false;
        //        for (int i = 0; i < dt.Rows.Count; i++)
        //        {
        //            dr = dt.Rows[i];
        //            sql = GetSqlString_TableTraceInsert_MainLine(dr);
        //            if (sql != null)
        //            {
        //                string engineTraceCode = dr[MaterialData.EngineTraceCodeField].ToString();
        //                sql2 = "DELETE FROM MES_装配数据_发动机号_追踪代码 WHERE 追踪代码='" + engineTraceCode + "'";
        //                DataAccess.ExecuteSQL_OleDb_Access(connectionString_Access_OpNameMainLine, sql2);
        //                if (DataAccess.ExecuteSQL_OleDb_Access(connectionString_Access_OpNameMainLine, sql))
        //                {
        //                    if (!Convert.IsDBNull(dr[MaterialData.FirstOpNameTraceCodeField]))
        //                    {
        //                        firstOpNameTraceCode = Convert.ToInt32(dr[MaterialData.FirstOpNameTraceCodeField]);
        //                        TableTraceUpdate(firstOpNameTraceCode);
        //                    }
        //                }
        //            }
        //        }
        //        return true;
        //    }
        //    catch (Exception err)
        //    {
        //        ////ApplicationLog.WriteLog(err.Message);
        //        return false;
        //    }
        //}
        /// <summary>
        /// 线首，用于物料追踪
        /// 增加数据到Access数据库
        /// MES_装配数据_发动机号_追踪代码
        /// INSERT INTO [MES_装配数据_发动机号_追踪代码]
        /// </summary>
        /// <returns></returns>
        //public static bool TableTraceInsert()
        //{
        //    string sql = null;
        //    sql = GetSqlString_TableTraceInsert();
        //    return DataAccess.ExecuteSQL_OleDb_Access(sql);
        //}
        /// <summary>
        /// 线首，用于物料追踪
        /// 增加数据到SqlServer数据库
        /// MES_装配数据_发动机号_追踪代码
        /// INSERT INTO [MES_装配数据_发动机号_追踪代码]
        /// </summary>
        /// <returns></returns>
        public static bool TableTraceInsert_SqlServer()
        {
            string sql = null;
            sql = GetSqlString_TableTraceInsert();
            return DataAccess.ExecuteSQL(sql);
        }
        /// <summary>
        /// 应用于总线上线工位
        /// 获得增加表[MES_装配数据_发动机号_追踪代码]的SQL语句
        /// </summary>
        private static string GetSqlString_TableTraceInsert_MainLine(DataRow dr)
        {
            // <summary>
            // 上线工位追溯代码
            // </summary>
            int firstOpNameTraceCode;
            // <summary>
            // 订单号
            // </summary>
            string orderForm;
            // <summary>
            // 主配厂家
            // </summary>
            string mainPruduceFatory;
            // <summary>
            // 发动号
            // </summary>
            string engineNumber;
            // <summary>
            // 订单计划发动机号
            // </summary>
            string engineNumber_OrderPlan;
            // <summary>
            // 追踪代码
            // </summary>
            string engineTraceCode;
            // <summary>
            // 主物料号
            // </summary>
            string mainMaterialNumber;
            // <summary>
            // 工位号
            // </summary>
            string opName;
            // <summary>
            // 到达时间
            // </summary>
            DateTime arrivedTime;
            // <summary>
            // 离开时间
            // </summary>
            DateTime leavedTime;
            // <summary>
            // 操作者工号
            // </summary>
            string operatorCode;
            // <summary>
            // 班次代码
            // </summary>
            string operatorShift;
            // <summary>
            // SAP物料号
            // </summary>
            string sAPMaterialNumber;
            // <summary>
            // 发动机型号
            // </summary>
            string engineNumberType;
            // <summary>
            // 发动机型号代码
            // </summary>
            int engineNumberCode;
            // <summary>
            // 发动机机型
            // </summary>
            string engineNumberBasicType;
            // <summary>
            // 发动机数量
            // </summary>
            string engineCount;
            // <summary>
            // 厂牌编号起始号
            // </summary>
            string engineNumberFirstID;
            // <summary>
            // 客户名称
            // </summary>
            string customesName;
            // <summary>
            // 投料日期
            // </summary>
            DateTime prepareMaterialDateTime;
            // <summary>
            // 文件编号
            // </summary>
            string fileCode;
            // <summary>
            // 集团名称
            // </summary>
            string groupName;
            // <summary>
            // 通知号
            // </summary>
            string notifyCode;
            // <summary>
            // 功率
            // </summary>
            string n_Force;
            // <summary>
            // 指南文件编号
            // </summary>
            string directFileCode;
            // <summary>
            // 装机状态
            // </summary>
            string workEngineStatus;
            // <summary>
            // 适用状态
            // </summary>
            DateTime adaptDateTime;
            // <summary>
            // 物料描述
            // </summary>
            string materialDescript;
            // <summary>
            // 计划下达日期
            // </summary>
            DateTime planSendedDateTime;
            // <summary>
            // 计划完工日期
            // </summary>
            DateTime planFinishDateTime;
            // <summary>
            // 零件类型
            // </summary>
            int partType;

            string sql = null;
            try
            {
                if (Convert.IsDBNull(dr[MaterialData.FirstOpNameTraceCodeField]))
                {
                    firstOpNameTraceCode = 0; 
                }
                else
                {
                    firstOpNameTraceCode = Convert.ToInt32(dr[MaterialData.FirstOpNameTraceCodeField]);
                }

                if (Convert.IsDBNull(dr[MaterialData.OrderFormField]))
                {
                   orderForm = ""; 
                }
                else
                {
                    orderForm = dr[MaterialData.OrderFormField].ToString();
                }

                //
                if (Convert.IsDBNull(dr[MaterialData.EngineNumber_OrderPlanField]))
                {
                    engineNumber_OrderPlan = "";
                }
                else
                {
                    engineNumber_OrderPlan = dr[MaterialData.EngineNumber_OrderPlanField].ToString();
                }
                if (Convert.IsDBNull(dr[MaterialData.EngineNumberField]))
                {
                    engineNumber = "";
                }
                else
                {
                    engineNumber = dr[MaterialData.EngineNumberField].ToString();
                }
                if (Convert.IsDBNull(dr[MaterialData.EngineTraceCodeField]))
                {
                    engineTraceCode = "";
                }
                else
                {
                    engineTraceCode = dr[MaterialData.EngineTraceCodeField].ToString();
                }

                if (Convert.IsDBNull(dr[MaterialData.MainMaterialNumberField]))
                {
                    mainMaterialNumber = "";
                }
                else
                {
                    mainMaterialNumber = dr[MaterialData.MainMaterialNumberField].ToString();
                }


                if (Convert.IsDBNull(dr[MaterialData.OpNameField]))
                {
                    opName = "";
                }
                else
                {
                    opName = dr[MaterialData.OpNameField].ToString();
                }


                if (Convert.IsDBNull(dr[MaterialData.ArrivedTimeField]))
                {
                    arrivedTime = DateTime.Now;
                }
                else
                {
                    arrivedTime = Convert.ToDateTime(dr[MaterialData.ArrivedTimeField]);
                }


                if (Convert.IsDBNull(dr[MaterialData.LeavedTimeField]))
                {
                    leavedTime = DateTime.Now;
                }
                else
                {
                    leavedTime = Convert.ToDateTime(dr[MaterialData.LeavedTimeField]);
                }


                if (Convert.IsDBNull(dr[MaterialData.OperatorCodeField]))
                {
                    operatorCode = "";
                }
                else
                {
                    operatorCode = dr[MaterialData.OperatorCodeField].ToString();
                }

                if (Convert.IsDBNull(dr[MaterialData.OperatorShiftField]))
                {
                    operatorShift = "";
                }
                else
                {
                    operatorShift = dr[MaterialData.OperatorShiftField].ToString();
                }

                //+ "[SAP物料号],[发动机型号],[发动机型号代码], [发动机机型], "


                if (Convert.IsDBNull(dr[MaterialData.SAPMaterialNumberField]))
                {
                    sAPMaterialNumber = "";
                }
                else
                {
                    sAPMaterialNumber = dr[MaterialData.SAPMaterialNumberField].ToString();
                }


                if (Convert.IsDBNull(dr[MaterialData.EngineNumberTypeField]))
                {
                    engineNumberType = "";
                }
                else
                {
                    engineNumberType = dr[MaterialData.EngineNumberTypeField].ToString();
                }

                if (Convert.IsDBNull(dr[MaterialData.EngineNumberCodeField]))
                {
                    engineNumberCode = 1;
                }
                else
                {
                    engineNumberCode = Convert.ToInt32(dr[MaterialData.EngineNumberCodeField]);
                }


                if (Convert.IsDBNull(dr[MaterialData.EngineNumberBasicTypeField]))
                {
                    engineNumberBasicType = "";
                }
                else
                {
                    engineNumberBasicType = dr[MaterialData.EngineNumberBasicTypeField].ToString();
                }

                //+ "[发动机数量], [厂牌编号起始号], [客户名称],[投料日期],[文件编号],[集团名称],[通知号],"

                if (Convert.IsDBNull(dr[MaterialData.EngineCountField]))
                {
                    engineCount = "";
                }
                else
                {
                    engineCount = dr[MaterialData.EngineCountField].ToString();
                }

                if (Convert.IsDBNull(dr[MaterialData.EngineNumberFirstIDField]))
                {
                    engineNumberFirstID = "";
                }
                else
                {
                    engineNumberFirstID = dr[MaterialData.EngineNumberFirstIDField].ToString();
                }

                if (Convert.IsDBNull(dr[MaterialData.CustomesNameField]))
                {
                    customesName = "";
                }
                else
                {
                    customesName = dr[MaterialData.CustomesNameField].ToString();
                }


                if (Convert.IsDBNull(dr[MaterialData.PrepareMaterialDateTimeField]))
                {
                    prepareMaterialDateTime = DateTime.Now;
                }
                else
                {
                    prepareMaterialDateTime = Convert.ToDateTime(dr[MaterialData.PrepareMaterialDateTimeField]);
                }


                if (Convert.IsDBNull(dr[MaterialData.EngineCountField]))
                {
                    fileCode = ""; 
                }
                else
                {
                    fileCode = dr[MaterialData.EngineCountField].ToString();
                }


                if (Convert.IsDBNull(dr[MaterialData.GroupNameField]))
                {
                    groupName = "";
                }
                else
                {
                    groupName = dr[MaterialData.GroupNameField].ToString();
                }


                if (Convert.IsDBNull(dr[MaterialData.NotifyCodeField]))
                {
                    notifyCode = "";
                }
                else
                {
                    notifyCode = dr[MaterialData.NotifyCodeField].ToString();
                }

                //+ "[功率],[指南文件编号],[装机状态],[适用状态],[物料描述],[计划下达日期],[计划完工日期],主配厂家,零件类型"

                if (Convert.IsDBNull(dr[MaterialData.N_ForceField]))
                {
                    n_Force = "";
                }
                else
                {
                    n_Force = dr[MaterialData.N_ForceField].ToString();
                }

                if (Convert.IsDBNull(dr[MaterialData.DirectFileCodeField]))
                {
                    directFileCode = "";
                }
                else
                {
                    directFileCode = dr[MaterialData.DirectFileCodeField].ToString();
                }


                if (Convert.IsDBNull(dr[MaterialData.WorkEngineStatusField]))
                {
                    workEngineStatus = "";
                }
                else
                {
                    workEngineStatus = dr[MaterialData.WorkEngineStatusField].ToString();
                }


                if (Convert.IsDBNull(dr[MaterialData.AdaptDateTimeField]))
                {
                    adaptDateTime = DateTime.Now; 
                }
                else
                {
                    adaptDateTime = Convert.ToDateTime(dr[MaterialData.AdaptDateTimeField]);
                }

                if (Convert.IsDBNull(dr[MaterialData.MaterialDescriptField]))
                {
                    materialDescript = "";
                }
                else
                {
                    materialDescript = dr[MaterialData.MaterialDescriptField].ToString();
                }

                if (Convert.IsDBNull(dr[MaterialData.PlanSendedDateTimeField]))
                {
                    planSendedDateTime = DateTime.Now;
                }
                else
                {
                    planSendedDateTime = Convert.ToDateTime(dr[MaterialData.PlanSendedDateTimeField]);
                }


                if (Convert.IsDBNull(dr[MaterialData.PlanFinishDateTimeField]))
                {
                    planFinishDateTime = DateTime.Now;
                }
                else
                {
                    planFinishDateTime = Convert.ToDateTime(dr[MaterialData.PlanFinishDateTimeField]);
                }


                if (Convert.IsDBNull(dr[MaterialData.MainPruduceFatoryField]))
                {
                    mainPruduceFatory = "";
                }
                else
                {
                    mainPruduceFatory = dr[MaterialData.MainPruduceFatoryField].ToString();
                }


                if (Convert.IsDBNull(dr[MaterialData.PartTypeField]))
                {
                    partType = 1; 
                }
                else
                {
                    partType = Convert.ToInt32(dr[MaterialData.PartTypeField]);
                }

                sql = "INSERT INTO [MES_装配数据_发动机号_追踪代码] " +
                    "(订单号,订单计划发动机号,发动机号,追踪代码,工位号,到达时间,离开时间,操作者工号,班次代码,"
                    + "[SAP物料号],[发动机型号],[发动机型号代码], [发动机机型], "
                    + "[发动机数量], [厂牌编号起始号], [客户名称],[投料日期],[文件编号],[集团名称],[通知号],"
                    + "[功率],[指南文件编号],[装机状态],[适用状态],[物料描述],[计划下达日期],[计划完工日期],[主配厂家],[零件类型])"
                    + " VALUES ("
                    //上线工位追溯代码,订单号,发动机号,追踪代码,工位号,到达时间,离开时间,操作者工号,班次代码
                    //+ "" + firstOpNameTraceCode + ","
                    + "'" + orderForm + "',"
                    + "'" + engineNumber_OrderPlan + "',"
                    + "'" + engineNumber + "',"
                    + "'" + engineTraceCode + "',"
                    + "'" + opName + "',"
                    + "'" + arrivedTime.ToString("G") + "',"
                    + "'" + leavedTime.ToString("G") + "',"
                    + "'" + operatorCode + "',"
                    + "'" + operatorShift + "',"
                    //+ "[SAP物料号],[发动机型号],[发动机型号代码], [发动机机型], "

                    + "'" + sAPMaterialNumber + "',"
                    + "'" + engineNumberType + "',"
                    + "" + engineNumberCode + ","//int
                    + "'" + engineNumberBasicType + "',"
                    //+ "[发动机数量], [厂牌编号起始号], [客户名称],[投料日期],[文件编号],[集团名称],[通知号],"

                    + "" + engineCount + ","//int
                    + "'" + engineNumberFirstID + "',"
                    + "'" + customesName + "',"
                    + "'" + prepareMaterialDateTime.ToString("G") + "',"
                    + "'" + fileCode + "',"
                    + "'" + groupName + "',"
                    + "'" + notifyCode + "',"
                    //+ "[功率],[指南文件编号],[装机状态],[适用状态],[物料描述],[计划下达日期],[计划完工日期],主配厂家,零件类型"
                    + "'" + n_Force + "',"
                    + "'" + directFileCode + "',"
                    + "'" + workEngineStatus + "',"
                    + "'" + adaptDateTime.ToString("G") + "',"
                    + "'" + materialDescript + "',"
                    + "'" + planSendedDateTime.ToString("G") + "',"
                    + "'" + planFinishDateTime.ToString("G") + "',"
                    + "'" + mainPruduceFatory + "',"
                    + "" + partType.ToString() + ") ";
                return sql;
            }
            catch { return null; }
        }
        /// <summary>
        /// 应用于分线上线工位
        /// 获得增加表[MES_装配数据_发动机号_追踪代码]的SQL语句
        /// </summary>
        private static string GetSqlString_TableTraceInsert()
        {
            string sql = null;
            sql = "INSERT INTO [MES_装配数据_发动机号_追踪代码] " +
                "(订单号,订单计划发动机号,发动机号,追踪代码,主物料号,工位号,到达时间,离开时间,操作者工号,班次代码,"
                + "[SAP物料号],[发动机型号],[发动机型号代码], [发动机机型], "
                + "[发动机数量], [厂牌编号起始号], [客户名称],[投料日期],[文件编号],[集团名称],[通知号],"
                + "[功率],[指南文件编号],[装机状态],[适用状态],[物料描述],[计划下达日期],[计划完工日期],[主配厂家],[零件类型])"
                + " VALUES ("
                //订单号,发动机号,追踪代码,工位号,到达时间,离开时间,操作者工号,班次代码
                + "'" + MaterialData.orderForm + "',"
                + "'" + MaterialData.engineNumber_OrderPlan + "',"
                + "'" + MaterialData.engineNumber + "',"
                + "'" + MaterialData.engineTraceCode + "',"
                + "'" + MaterialData.mainMaterialNumber + "',"
                + "'" + MaterialData.opName + "',"
                + "'" + MaterialData.arrivedTime.ToString("G") + "',"
                + "'" + MaterialData.leavedTime.ToString("G") + "',"
                + "'" + MaterialData.operatorCode + "',"
                + "'" + MaterialData.operatorShift + "',"
                //+ "[SAP物料号],[发动机型号],[发动机型号代码], [发动机机型], "

                + "'" + MaterialData.sAPMaterialNumber + "',"
                + "'" + MaterialData.engineNumberType + "',"
                + "" + MaterialData.engineNumberCode + ","//int
                + "'" + MaterialData.engineNumberBasicType + "',"
                //+ "[发动机数量], [厂牌编号起始号], [客户名称],[投料日期],[文件编号],[集团名称],[通知号],"

                + "" + MaterialData.engineCount + ","//int
                + "'" + MaterialData.engineNumberFirstID + "',"
                + "'" + MaterialData.customesName + "',"
                + "'" + MaterialData.prepareMaterialDateTime.ToString("G") + "',"
                + "'" + MaterialData.fileCode + "',"
                + "'" + MaterialData.groupName + "',"
                + "'" + MaterialData.notifyCode + "',"
                //+ "[功率],[指南文件编号],[装机状态],[适用状态],[物料描述],[计划下达日期],[计划完工日期],主配厂家,零件类型"
                + "'" + MaterialData.n_Force + "',"
                + "'" + MaterialData.directFileCode + "',"
                + "'" + MaterialData.workEngineStatus + "',"
                + "'" + MaterialData.adaptDateTime.ToString("G") + "',"
                + "'" + MaterialData.materialDescript + "',"
                + "'" + MaterialData.planSendedDateTime.ToString("G") + "',"
                + "'" + MaterialData.planFinishDateTime.ToString("G") + "',"
                + "'" + MaterialData.mainPruduceFatory + "',"
                + "" + MaterialData.partType.ToString() + ") ";
            return sql;
        }


    }
}
