using Microsoft.VisualBasic.CompilerServices;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
//using System.Data.Odbc;
using System.Data.SqlClient;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;

//namespace SE0085.CTdB
namespace FAS_LIB
{
    public class clsEngineMES
    {
        private LogWriter lcLogWriter;
        private scLevels _Plant;
        private scLevels _AssemblyLine;
        private Dictionary<DateTime, scHolidays> _dtHoliday;
        private Dictionary<string, string> _dtLaborContent;

        public clsEngineMES()
        {
            this._dtHoliday = new Dictionary<DateTime, scHolidays>();
            this._dtLaborContent = new Dictionary<string, string>();
            //this.GetdBConnString();
            this.lcLogWriter = new LogWriter("C:\\MESdata\\MesImport.log");
            this.LoadDictHolidays();
            this.LoadDictLabor();
        }

        public clsEngineMES(scLevels Plant, scLevels AssemblyLine)
        {
            this._dtHoliday = new Dictionary<DateTime, scHolidays>();
            this._dtLaborContent = new Dictionary<string, string>();
            //this.GetdBConnString();
            this.lcLogWriter = new LogWriter("C:\\MESdata\\MesImport.log");
            this._Plant = Plant;
            this._AssemblyLine = AssemblyLine;
            this.LoadDictHolidays();
            this.LoadDictLabor();
        }


        public void UpdateIfRouted(string FOLineSLSS)
        {
            // ISSUE: object of a compiler-generated type is created
            // ISSUE: variable of a compiler-generated type
            //clsEngineMES._Closure4__152 closure152 = new clsEngineMES._Closure4__152();
            string str = FOLineSLSS;
            string ldFO = str.Substring(0, 8);
            string ldLine = str.Substring(8, 3);
            string ldSL = str.Substring(11, 2);
            string ldSS = str.Substring(13, 2);
            using (SE0085CTEntities1 se0085CtEntities1 = new SE0085CTEntities1())
            {
                //se0085CtEntities1.Database.Connection.ConnectionString = this._CTConnection;
                // ISSUE: method reference
                //IQueryable<AnonymousType_63<string, int>> source = Queryable.Select(Queryable.Where((IQueryable<M0>)Queryable.Join((IQueryable<M0>)Queryable.Join((IQueryable<M0>)Queryable.Join((IQueryable<M0>)Queryable.Join((IQueryable<M0>)se0085CtEntities1.OrderLines, (IEnumerable<M1>)se0085CtEntities1.SEOrders, (Expression<Func<M0, M2>>)(ol => ol.SEOrder.OrderId), (Expression<Func<M1, M2>>)(fo => fo.OrderId), (Expression<Func<M0, M1, M3>>)((ol, fo) => new { ol = ol, fo = fo })), (IEnumerable<M1>)se0085CtEntities1.AssemblyLines, (Expression<Func<M0, M2>>)(data => data.ol.AssemblyLine.AssemLineId), (Expression<Func<M1, M2>>)(al => al.AssemLineId), (Expression<Func<M0, M1, M3>>)((data, al) => new
                //{
                //    It1 = data,
                //    al = al
                //})), (IEnumerable<M1>)se0085CtEntities1.OrdSections, (Expression<Func<M0, M2>>)(data => data.It1.ol.OrderLineId), (Expression<Func<M1, M2>>)(os => os.OrderLine.OrderLineId), (Expression<Func<M0, M1, M3>>)((data, os) => new
                //{
                //    It1 = data,
                //    os = os
                //})), (IEnumerable<M1>)se0085CtEntities1.SectionsRoutings, (Expression<Func<M0, M2>>)(data => data.os.OrdSectsId), (Expression<Func<M1, M2>>)(rt => rt.OrdSection.OrdSectsId), (Expression<Func<M0, M1, M3>>)((data, rt) => new
                //{
                //    ol = data.It1.It1.ol,
                //    fo = data.It1.It1.fo,
                //    al = data.It1.al,
                //    os = data.os,
                //    rt = rt
                //})), (Expression<Func<M0, bool>>)(data => Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), data.fo.OrderFO, closure152.ldFO, false) == 0 & Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), data.ol.OrderLineNum, closure152.ldLine, false) == 0 & Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), data.ol.OrderLineSL, closure152.ldSL, false) == 0 & Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), data.ol.OrderLineSS, closure152.ldSS, false) == 0)), (Expression<Func<M0, M1>>)(data => new
                //{
                //    AssemLineAbbrv = data.al.AssemLineAbbrv,
                //    RoutingId = data.rt.RoutingId
                //}));

                var source = from ol in se0085CtEntities1.OrderLines
                             join od in se0085CtEntities1.SEOrders
                             on ol.SEOrder.OrderId equals od.OrderId
                             join al in se0085CtEntities1.AssemblyLines
                             on ol.AssemblyLine.AssemLineId equals al.AssemLineId
                             join os in se0085CtEntities1.OrdSections
                             on ol.OrderLineId equals os.OrderLine.OrderLineId
                             join sr in se0085CtEntities1.SectionsRoutings
                             on os.OrdSectsId equals sr.OrdSection.OrdSectsId
                             where string.Equals(od.OrderFO,ldFO)
                             && string.Equals(ol.OrderLineNum,ldLine)
                             && string.Equals(ol.OrderLineSL, ldSL)
                             && string.Equals(ol.OrderLineSS, ldSS)
                             select new
                             {
                                 AssemLineAbbrv = al.AssemLineAbbrv,
                                 RoutingId = sr.RoutingId
                             };


                if (source != null && source.Count() > 0)
                {
                    string assemLineAbbrv = source.First().AssemLineAbbrv;
                    List<scMESUpdateFull> scMesUpdateFullList = new List<scMESUpdateFull>();
                    List<scMESUpdateFull> OrderList = this.LoadMESOrders(assemLineAbbrv, ldFO, ldLine, ldSL, ldSS);
                    if (OrderList != null && OrderList.Count > 0)
                    {
                        this._AssemblyLine = (scLevels)new clsAssemblyLine(this._Plant).rtnAssemblyLineByAbbrv(this._Plant.LevelId, assemLineAbbrv);
                        this.ScheduleOrder(ref OrderList);
                        this.MESLoad(this._Plant, this._AssemblyLine, OrderList, true, false);
                    }
                }
                se0085CtEntities1.Database.Connection.Close();
            }
       }

        //public void ScheduleOrder(ref List<scMESUpdateFull> OrderList)
        //{
        //    //clsEngineMES._Closure$__156 $VB$Closure_ClosureVariable_9C = null;
        //    IEnumerator<scMESUpdateFull> enumerator = null;
        //    IEnumerator<scMESUpdateFull> enumerator1 = null;
        //    IEnumerator<scMESUpdateFull> enumerator2 = null;
        //    IEnumerator<scMESUpdateFull> enumerator3 = null;
        //    List<string>.Enumerator enumerator4 = new List<string>.Enumerator();
        //    List<string>.Enumerator enumerator5 = new List<string>.Enumerator();
        //    bool? nullable;
        //    DateTime[] ldTargetDate = new DateTime[26];
        //    int td = 0;
        //    do
        //    {
        //        ldTargetDate[td] = Conversions.ToDate("01/01/2020");
        //        td++;
        //    }
        //    while (td <= 24);
        //    string ldOrdSER = " ";
        //    string ldElecClpx = "1";
        //    string ldMechClpx = "1";
        //    int ldSectCnt = 1;
        //    string item = "";
        //    List<string> strs = new List<string>()
        //    {
        //        "SHIPPING",
        //        "SHIP"
        //    };
        //    Conversions.ToDate("01/01/1901");
        //    string hdQ2cNbr = OrderList[0].hd_q2c_nbr;
        //    string odLnDsplySeqNbr = OrderList[0].od_ln_dsply_seq_nbr;
        //    string hdSubLnItmId = OrderList[0].hd_sub_ln_itm_id;
        //    string hdOrigShpschdId = OrderList[0].hd_orig_shpschd_id;
        //    using (SE0085CTEntities1 CTdB = new SE0085CTEntities1())
        //    {
				
        //        //1
        //        var qryOrder = from od in CTdB.SEOrders
        //                      join ol in CTdB.OrderLines
        //                      on od.OrderId equals ol.SEOrder.OrderId
        //                      join le in CTdB.OrderLinesExts
        //                      on ol.OrderLineId equals le.OrderLine.OrderLineId
        //                       where string.Equals(od.OrderFO, hdQ2cNbr)
        //                      && string.Equals(ol.OrderLineNum, odLnDsplySeqNbr)
        //                      && string.Equals(ol.OrderLineSL, hdSubLnItmId)
        //                      && string.Equals(ol.OrderLineSS, hdOrigShpschdId)
        //                      select new
        //                      {
        //                          le.OrderLineCurTargetDt,
        //                          ol.OrderLineSER,
        //                          le.OrderLineElecClpx,
        //                          le.OrderLineMechClpx
        //                      };

        //        if (qryOrder != null)
        //        {
        //            if (qryOrder.Count() > 0)
        //            {
        //                int td1 = 0;
        //                do
        //                {
        //                    ldTargetDate[td1] = (DateTime)qryOrder.FirstOrDefault().OrderLineCurTargetDt;
        //                    td1++;
        //                }
        //                while (td1 <= 24);
        //                ldOrdSER = qryOrder.FirstOrDefault().OrderLineSER;
        //                ldElecClpx = qryOrder.FirstOrDefault().OrderLineElecClpx;
        //                ldMechClpx = qryOrder.FirstOrDefault().OrderLineMechClpx;
        //            }
        //        }
        //        Dictionary<string, RoutingSeq> dlWCRtSeq = null;
        //        //DbSet<RoutingSeq> routingSeqs = CTdB.RoutingSeqs;
        //        //ParameterExpression parameterExpression10 = Expression.Parameter(typeof(RoutingSeq), "rs");
        //        //BinaryExpression binaryExpression4 = Expression.Equal(Expression.Property(Expression.Property(parameterExpression10, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(RoutingSeq).GetMethod("get_AssemblyLine").MethodHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(AssemblyLine).GetMethod("get_AssemLineId").MethodHandle)), Expression.Property(Expression.Field(Expression.Constant(this, typeof(clsEngineMES)), (FieldInfo)FieldInfo.GetFieldFromHandle(typeof(clsEngineMES).GetField("_AssemblyLine").FieldHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(scLevels).GetMethod("get_LevelId").MethodHandle)), true, null);
        //        //ParameterExpression[] parameterExpressionArray8 = new ParameterExpression[] { parameterExpression10 };
        //        //IQueryable<RoutingSeq> routingSeqs1 = routingSeqs.Where<RoutingSeq>(Expression.Lambda<Func<RoutingSeq, bool>>(binaryExpression4, parameterExpressionArray8));
        //        //ParameterExpression parameterExpression11 = Expression.Parameter(typeof(RoutingSeq), "rs");
        //        //ParameterExpression[] parameterExpressionArray9 = new ParameterExpression[] { parameterExpression11 };
        //        //IQueryable<RoutingSeq> qryRtSeq = routingSeqs1.Select<RoutingSeq, RoutingSeq>(Expression.Lambda<Func<RoutingSeq, RoutingSeq>>(parameterExpression11, parameterExpressionArray9));
        //        //2
        //        IQueryable<RoutingSeq> qryRtSeq = from rs in CTdB.RoutingSeqs
        //                                         where rs.AssemblyLine.AssemLineId == this._AssemblyLine.LevelId
        //                                         select rs;
        //        if (qryRtSeq != null)
        //        {
        //            if (qryRtSeq.Count<RoutingSeq>() > 0)
        //            {
        //                dlWCRtSeq = qryRtSeq.ToDictionary<RoutingSeq, string>((RoutingSeq r) => r.RtSeqWorkCenter);
        //                while (true)
        //                {
        //                    item = strs[0];
        //                    if (dlWCRtSeq.ContainsKey(item))
        //                    {
        //                        IEnumerable<scMESUpdateFull> qryShipWC = 
        //                            from sq in OrderList
        //                            where Microsoft.VisualBasic.CompilerServices.Operators.CompareString(sq.dt_eto_workctr, strs[0], false) == 0
        //                            orderby sq.hd_sect_id
        //                            select sq;
        //                        if (qryShipWC != null)
        //                        {
        //                            if (qryShipWC.Count<scMESUpdateFull>() > 0)
        //                            {
        //                                ldSectCnt = 0;
        //                                //{
        //                                    enumerator = qryShipWC.GetEnumerator();
        //                                    while (enumerator.MoveNext())
        //                                    {
        //                                        scMESUpdateFull ldSect = enumerator.Current;
        //                                        ldSectCnt++;
        //                                        ldSect.od_trgt_dt = ldTargetDate[ldSect.hd_sect_id];
        //                                        this.ScheduleWC(ref dlWCRtSeq, ref ldSect, ldOrdSER, ldElecClpx, ldMechClpx, ldSectCnt);
        //                                    }
        //                                //}
        //                                this.SyncShipSplt(ref OrderList, item);
        //                            }
        //                        }
        //                        if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(dlWCRtSeq[item].RtSeqSeries, "PRIMARY", false) == 0 | Microsoft.VisualBasic.CompilerServices.Operators.CompareString(dlWCRtSeq[item].RtSeqSeries, "PRIMRY", false) == 0)
        //                        {
        //                            bool flag = true;
        //                            bool? rtSeqSync2WC = dlWCRtSeq[item].RtSeqSync2WC;
        //                            if (rtSeqSync2WC.HasValue)
        //                            {
        //                                nullable = new bool?(rtSeqSync2WC.GetValueOrDefault() == flag);
        //                            }
        //                            else
        //                            {
        //                                nullable = null;
        //                            }
        //                            if (!nullable.GetValueOrDefault())
        //                            {
        //                                try
        //                                {
        //                                    enumerator3 = qryShipWC.GetEnumerator();
        //                                    while (enumerator3.MoveNext())
        //                                    {
        //                                        scMESUpdateFull ldSect = enumerator3.Current;
        //                                        ldTargetDate[ldSect.hd_sect_id] = ldSect.due_st;
        //                                    }
        //                                }
        //                                finally
        //                                {
        //                                    if (enumerator3 != null)
        //                                    {
        //                                        enumerator3.Dispose();
        //                                    }
        //                                }
        //                            }
        //                            else
        //                            {
        //                                DateTime ldFirst_due_st = Conversions.ToDate("12/31/2039");
        //                                //{
        //                                    enumerator1 = qryShipWC.GetEnumerator();
        //                                    while (enumerator1.MoveNext())
        //                                    {
        //                                        scMESUpdateFull ldSect = enumerator1.Current;
        //                                        if (DateTime.Compare(ldSect.due_st, ldFirst_due_st) < 0)
        //                                        {
        //                                            ldFirst_due_st = ldSect.due_st;
        //                                        }
        //                                    }
        //                                //}
        //                                try
        //                                {
        //                                    enumerator2 = qryShipWC.GetEnumerator();
        //                                    while (enumerator2.MoveNext())
        //                                    {
        //                                        ldTargetDate[enumerator2.Current.hd_sect_id] = ldFirst_due_st;
        //                                    }
        //                                }
        //                                finally
        //                                {
        //                                    if (enumerator2 != null)
        //                                    {
        //                                        enumerator2.Dispose();
        //                                    }
        //                                }
        //                            }
        //                        }
        //                    }
        //                    strs.Remove(item);
        //                    //ParameterExpression parameterExpression12 = Expression.Parameter(typeof(RoutingSeq), "rt");
        //                    //MethodInfo methodFromHandle3 = (MethodInfo)MethodBase.GetMethodFromHandle(typeof(Microsoft.VisualBasic.CompilerServices.Operators).GetMethod("CompareString", new Type[] { typeof(string), typeof(string), typeof(bool) }).MethodHandle);
        //                    //Expression[] expressionArray7 = new Expression[] { Expression.Property(parameterExpression12, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(RoutingSeq).GetMethod("get_RtSeqSeries").MethodHandle)), Expression.Constant("PRIMARY", typeof(string)), Expression.Constant(false, typeof(bool)) };
        //                    //BinaryExpression binaryExpression5 = Expression.Equal(Expression.Call(null, methodFromHandle3, expressionArray7), Expression.Constant(0, typeof(int)));
        //                    //MethodInfo methodInfo3 = (MethodInfo)MethodBase.GetMethodFromHandle(typeof(Microsoft.VisualBasic.CompilerServices.Operators).GetMethod("CompareString", new Type[] { typeof(string), typeof(string), typeof(bool) }).MethodHandle);
        //                    //Expression[] expressionArray8 = new Expression[] { Expression.Property(parameterExpression12, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(RoutingSeq).GetMethod("get_RtSeqSeries").MethodHandle)), Expression.Constant("PRIMRY", typeof(string)), Expression.Constant(false, typeof(bool)) };
        //                    //UnaryExpression unaryExpression = Expression.Not(Expression.Or(binaryExpression5, Expression.Equal(Expression.Call(null, methodInfo3, expressionArray8), Expression.Constant(0, typeof(int)))));
        //                    //MethodInfo methodFromHandle4 = (MethodInfo)MethodBase.GetMethodFromHandle(typeof(Microsoft.VisualBasic.CompilerServices.Operators).GetMethod("CompareString", new Type[] { typeof(string), typeof(string), typeof(bool) }).MethodHandle);
        //                    //Expression[] expressionArray9 = new Expression[] { Expression.Property(parameterExpression12, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(RoutingSeq).GetMethod("get_RtSeqNextWorkCtr").MethodHandle)), Expression.Field(Expression.Constant($VB$Closure_ClosureVariable_9C, typeof(clsEngineMES._Closure$__156)), (FieldInfo)FieldInfo.GetFieldFromHandle(typeof(clsEngineMES._Closure$__156).GetField("$VB$Local_ldCurrentWC").FieldHandle)), Expression.Constant(false, typeof(bool)) };
        //                    //BinaryExpression binaryExpression6 = Expression.And(unaryExpression, Expression.Equal(Expression.Call(null, methodFromHandle4, expressionArray9), Expression.Constant(0, typeof(int))));
        //                    //ParameterExpression[] parameterExpressionArray10 = new ParameterExpression[] { parameterExpression12 };
        //                    //IQueryable<RoutingSeq> routingSeqs2 = qryRtSeq.Where<RoutingSeq>(Expression.Lambda<Func<RoutingSeq, bool>>(binaryExpression6, parameterExpressionArray10));
        //                    //ParameterExpression parameterExpression13 = Expression.Parameter(typeof(RoutingSeq), "rt");
        //                    //MemberExpression memberExpression4 = Expression.Property(parameterExpression13, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(RoutingSeq).GetMethod("get_RtSeqWorkCenter").MethodHandle));
        //                    //ParameterExpression[] parameterExpressionArray11 = new ParameterExpression[] { parameterExpression13 };
        //                    //IQueryable<string> qrySubProcWC = routingSeqs2.Select<RoutingSeq, string>(Expression.Lambda<Func<RoutingSeq, string>>(memberExpression4, parameterExpressionArray11));

        //                    IQueryable<string> qrySubProcWC = from rt in qryRtSeq
        //                                                      where Microsoft.VisualBasic.CompilerServices.Operators.CompareString(rt.RtSeqSeries, "PRIMARY", false) == 0
        //                                                      | Microsoft.VisualBasic.CompilerServices.Operators.CompareString(rt.RtSeqSeries, "PRIMRY", false) == 0
        //                                                      & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(rt.RtSeqNextWorkCtr, item, false) == 0
        //                                                      select rt.RtSeqWorkCenter;

        //                    if (qrySubProcWC != null)
        //                    {
        //                        if (qrySubProcWC.Count<string>() > 0)
        //                        {
        //                            try
        //                            {
        //                                enumerator4 = qrySubProcWC.ToList<string>().GetEnumerator();
        //                                while (enumerator4.MoveNext())
        //                                {
        //                                    string ldSubWC = enumerator4.Current;
        //                                    this.ScheduleSubProc(ref OrderList, dlWCRtSeq[ldSubWC].RtSeqSeries, ldSubWC, ldOrdSER, ldElecClpx, ldMechClpx, ldSectCnt, ldTargetDate);
        //                                }
        //                            }
        //                            finally
        //                            {
        //                                ((IDisposable)enumerator4).Dispose();
        //                            }
        //                        }
        //                    }
        //                    //ParameterExpression parameterExpression14 = Expression.Parameter(typeof(RoutingSeq), "rt");
        //                    //MethodInfo methodInfo4 = (MethodInfo)MethodBase.GetMethodFromHandle(typeof(Microsoft.VisualBasic.CompilerServices.Operators).GetMethod("CompareString", new Type[] { typeof(string), typeof(string), typeof(bool) }).MethodHandle);
        //                    //Expression[] expressionArray10 = new Expression[] { Expression.Property(parameterExpression14, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(RoutingSeq).GetMethod("get_RtSeqSeries").MethodHandle)), Expression.Constant("PRIMARY", typeof(string)), Expression.Constant(false, typeof(bool)) };
        //                    //BinaryExpression binaryExpression7 = Expression.Equal(Expression.Call(null, methodInfo4, expressionArray10), Expression.Constant(0, typeof(int)));
        //                    //MethodInfo methodFromHandle5 = (MethodInfo)MethodBase.GetMethodFromHandle(typeof(Microsoft.VisualBasic.CompilerServices.Operators).GetMethod("CompareString", new Type[] { typeof(string), typeof(string), typeof(bool) }).MethodHandle);
        //                    //Expression[] expressionArray11 = new Expression[] { Expression.Property(parameterExpression14, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(RoutingSeq).GetMethod("get_RtSeqSeries").MethodHandle)), Expression.Constant("PRIMRY", typeof(string)), Expression.Constant(false, typeof(bool)) };
        //                    //BinaryExpression binaryExpression8 = Expression.Or(binaryExpression7, Expression.Equal(Expression.Call(null, methodFromHandle5, expressionArray11), Expression.Constant(0, typeof(int))));
        //                    //MethodInfo methodInfo5 = (MethodInfo)MethodBase.GetMethodFromHandle(typeof(Microsoft.VisualBasic.CompilerServices.Operators).GetMethod("CompareString", new Type[] { typeof(string), typeof(string), typeof(bool) }).MethodHandle);
        //                    //Expression[] expressionArray12 = new Expression[] { Expression.Property(parameterExpression14, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(RoutingSeq).GetMethod("get_RtSeqNextWorkCtr").MethodHandle)), Expression.Field(Expression.Constant($VB$Closure_ClosureVariable_9C, typeof(clsEngineMES._Closure$__156)), (FieldInfo)FieldInfo.GetFieldFromHandle(typeof(clsEngineMES._Closure$__156).GetField("$VB$Local_ldCurrentWC").FieldHandle)), Expression.Constant(false, typeof(bool)) };
        //                    //BinaryExpression binaryExpression9 = Expression.And(binaryExpression8, Expression.Equal(Expression.Call(null, methodInfo5, expressionArray12), Expression.Constant(0, typeof(int))));
        //                    //ParameterExpression[] parameterExpressionArray12 = new ParameterExpression[] { parameterExpression14 };
        //                    //IQueryable<RoutingSeq> routingSeqs3 = qryRtSeq.Where<RoutingSeq>(Expression.Lambda<Func<RoutingSeq, bool>>(binaryExpression9, parameterExpressionArray12));
        //                    //ParameterExpression parameterExpression15 = Expression.Parameter(typeof(RoutingSeq), "rt");
        //                    //MemberExpression memberExpression5 = Expression.Property(parameterExpression15, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(RoutingSeq).GetMethod("get_RtSeqWorkCenter").MethodHandle));
        //                    //ParameterExpression[] parameterExpressionArray13 = new ParameterExpression[] { parameterExpression15 };
        //                    //IQueryable<string> qryNextWC = routingSeqs3.Select<RoutingSeq, string>(Expression.Lambda<Func<RoutingSeq, string>>(memberExpression5, parameterExpressionArray13));
        //                    IQueryable<string> qryNextWC = from rt in qryRtSeq
        //                                                   where Microsoft.VisualBasic.CompilerServices.Operators.CompareString(rt.RtSeqSeries, "PRIMARY", false) == 0
        //                                                   | Microsoft.VisualBasic.CompilerServices.Operators.CompareString(rt.RtSeqSeries, "PRIMRY", false) == 0
        //                                                   & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(rt.RtSeqNextWorkCtr, item, false) == 0
        //                                                   select rt.RtSeqWorkCenter;
        //                    if (qryNextWC != null)
        //                    {
        //                        if (qryNextWC.Count<string>() > 0)
        //                        {
        //                            try
        //                            {
        //                                enumerator5 = qryNextWC.ToList<string>().GetEnumerator();
        //                                while (enumerator5.MoveNext())
        //                                {
        //                                    string ldWC = enumerator5.Current;
        //                                    if (!strs.Contains(ldWC))
        //                                    {
        //                                        strs.Add(ldWC);
        //                                    }
        //                                }
        //                            }
        //                            finally
        //                            {
        //                                ((IDisposable)enumerator5).Dispose();
        //                            }
        //                        }
        //                        else if (strs.Count == 0)
        //                        {
        //                            return;
        //                        }
        //                        if (strs.Count == 0)
        //                        {
        //                            break;
        //                        }
        //                    }
        //                }
        //            }
        //        }
        //    }
        //}

        public void ScheduleOrder(ref List<scMESUpdateFull> OrderList)
        {
            // ISSUE: object of a compiler-generated type is created
            // ISSUE: variable of a compiler-generated type
            //clsEngineMES._Closure4__156 closure156 = new clsEngineMES._Closure4__156();
            DateTime[] TargetDate = new DateTime[26];
            int index1 = 0;
            do
            {
                TargetDate[index1] = Conversions.ToDate("01/01/2020");
                checked { ++index1; }
            }
            while (index1 <= 24);
            string OrdSER = " ";
            string ElecClpx = "1";
            string MechClpx = "1";
            int SectCnt = 1;
            string ldCurrentWC = "";

            List<string> ldWCList = new List<string>();
            ldWCList.Add("SHIPPING");
            ldWCList.Add("SHIP");

            Conversions.ToDate("01/01/1901");
            string ldOrderFO = OrderList[0].hd_q2c_nbr;
            string ldOrderLineNum = OrderList[0].od_ln_dsply_seq_nbr;
            string ldOrderLineSL = OrderList[0].hd_sub_ln_itm_id;
            string ldOrderLineSS = OrderList[0].hd_orig_shpschd_id;
            using (SE0085CTEntities1 se0085CtEntities1 = new SE0085CTEntities1())
            {
                //se0085CtEntities1.Database.Connection.ConnectionString = this._CTConnection;
                // ISSUE: method reference
                //IQueryable<AnonymousType_67<DateTime?, string, string, string>> source1 = Queryable.Select(Queryable.Where((IQueryable<M0>)Queryable.Join((IQueryable<M0>)Queryable.Join((IQueryable<M0>)se0085CtEntities1.SEOrders, (IEnumerable<M1>)se0085CtEntities1.OrderLines, (Expression<Func<M0, M2>>)(od => od.OrderId), (Expression<Func<M1, M2>>)(ol => ol.SEOrder.OrderId), (Expression<Func<M0, M1, M3>>)((od, ol) => new { od = od, ol = ol })), (IEnumerable<M1>)se0085CtEntities1.OrderLinesExts, (Expression<Func<M0, M2>>)(data => data.ol.OrderLineId), (Expression<Func<M1, M2>>)(oe => oe.OrderLine.OrderLineId), (Expression<Func<M0, M1, M3>>)((data, oe) => new
                //{
                //    od = data.od,
                //    ol = data.ol,
                //    oe = oe
                //})), (Expression<Func<M0, bool>>)(data => Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), data.od.OrderFO, closure156.ldOrderFO, false) == 0 & Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), data.ol.OrderLineNum, closure156.ldOrderLineNum, false) == 0 & Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), data.ol.OrderLineSL, closure156.ldOrderLineSL, false) == 0 & Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), data.ol.OrderLineSS, closure156.ldOrderLineSS, false) == 0)), (Expression<Func<M0, M1>>)(data => new
                //{
                //    OrderLineCurTargetDt = data.oe.OrderLineCurTargetDt,
                //    OrderLineSER = data.ol.OrderLineSER,
                //    OrderLineElecClpx = data.oe.OrderLineElecClpx,
                //    OrderLineMechClpx = data.oe.OrderLineMechClpx
                //}));
                var source1 = from od in se0085CtEntities1.SEOrders
                              join ol in se0085CtEntities1.OrderLines
                                on od.OrderId equals ol.SEOrder.OrderId
                              join le in se0085CtEntities1.OrderLinesExts
                                on ol.OrderLineId equals le.OrderLine.OrderLineId
                                where string.Equals(od.OrderFO,ldOrderFO)
                               & string.Equals(ol.OrderLineNum, ldOrderLineNum)
                               & string.Equals(ol.OrderLineSL, ldOrderLineSL)
                               & string.Equals(ol.OrderLineSS, ldOrderLineSS)
                                select new
                                {
                                    le.OrderLineCurTargetDt,
                                    ol.OrderLineSER,
                                    le.OrderLineElecClpx,
                                    le.OrderLineMechClpx
                                };

                if (source1 != null && source1.Count() > 0)
                {
                    int index2 = 0;
                    do
                    {
                        TargetDate[index2] = (DateTime)source1.FirstOrDefault().OrderLineCurTargetDt;
                        checked { ++index2; }
                    }
                    while (index2 <= 24);
                    OrdSER = source1.FirstOrDefault().OrderLineSER;
                    ElecClpx = source1.FirstOrDefault().OrderLineElecClpx;
                    MechClpx = source1.FirstOrDefault().OrderLineMechClpx;
                }
                //ParameterExpression parameterExpression;
                //IQueryable<RoutingSeq> source2 = (IQueryable<RoutingSeq>)Queryable.Select<RoutingSeq, RoutingSeq>(Queryable.Where<RoutingSeq>((IQueryable<M0>)se0085CtEntities1.RoutingSeqs, (Expression<Func<M0, bool>>)Expression.Lambda<Func<RoutingSeq, bool>>((Expression)Expression.Equal(rs.AssemblyLine.AssemLineId, this._AssemblyLine.LevelId, true, (MethodInfo)null), new ParameterExpression[1]
                //{
                //  parameterExpression
                //})), (Expression<Func<M0, M1>>)(rs => rs));
                IQueryable<RoutingSeq> source2 = from rs in se0085CtEntities1.RoutingSeqs
                                                   where rs.AssemblyLine.AssemLineId == this._AssemblyLine.LevelId
                                                   select rs;
                if (source2 != null && source2.Count<RoutingSeq>() > 0)
                {
                    //Dictionary<string, RoutingSeq> dictionary = (Dictionary<string, RoutingSeq>)Enumerable.ToDictionary<RoutingSeq, string>((IEnumerable<M0>)source2, (Func<M0, M1>)new Func<RoutingSeq, string>((object)null, __methodptr(_Lambda4__87)));
                    Dictionary<string, RoutingSeq> dictionary = source2.ToDictionary<RoutingSeq, string>((RoutingSeq r) => r.RtSeqWorkCenter);
                    do
                    {
                        IQueryable<string> source3;
                        do
                        {
                            ldCurrentWC = ldWCList[0];
                            if (dictionary.ContainsKey(ldCurrentWC))
                            {
                                List<scMESUpdateFull> scMesUpdateFullList = OrderList;
                                // ISSUE: virtual method pointer
                                //IntPtr num = __vmethodptr(closure156, _Lambda4__88);
                                //Func<scMESUpdateFull, bool> func = new Func<scMESUpdateFull, bool>((object), num);
                                // ISSUE: method pointer
                                // ISSUE: method pointer
                                //IEnumerable<scMESUpdateFull> source4 = (IEnumerable<scMESUpdateFull>)Enumerable.Select<scMESUpdateFull, scMESUpdateFull>((IEnumerable<M0>)Enumerable.OrderBy<scMESUpdateFull, int>(Enumerable.Where<scMESUpdateFull>((IEnumerable<M0>)scMesUpdateFullList, (Func<M0, bool>)func), (Func<M0, M1>)new Func<scMESUpdateFull, int>((object)null, __methodptr(_Lambda4__89))), (Func<M0, M1>)new Func<scMESUpdateFull, scMESUpdateFull>((object)null, __methodptr(_Lambda4__90)));
                                IEnumerable<scMESUpdateFull> source4 =
                                    from sq in OrderList
                                    where Microsoft.VisualBasic.CompilerServices.Operators.CompareString(sq.dt_eto_workctr, ldWCList[0], false) == 0
                                    orderby sq.hd_sect_id
                                    select sq;
                                if (source4 != null && source4.Count<scMESUpdateFull>() > 0)
                                {
                                    SectCnt = 0;
                                    IEnumerator<scMESUpdateFull> enumerator;
                                   enumerator = source4.GetEnumerator();
                                    try
                                    {
                                        while (enumerator.MoveNext())
                                        {
                                            scMESUpdateFull current = enumerator.Current;
                                            checked { ++SectCnt; }
                                            current.od_trgt_dt = TargetDate[current.hd_sect_id];
                                            this.ScheduleWC(ref dictionary, ref current, OrdSER, ElecClpx, MechClpx, SectCnt);
                                        }
                                    }
                                    finally
                                    {
                                        if (enumerator != null)
                                            enumerator.Dispose();
                                    }
                                    this.SyncShipSplt(ref OrderList, ldCurrentWC);
                                }

                                if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(dictionary[ldCurrentWC].RtSeqSeries, "PRIMARY", false) == 0 | Microsoft.VisualBasic.CompilerServices.Operators.CompareString(dictionary[ldCurrentWC].RtSeqSeries, "PRIMRY", false) == 0)
                                {
                                    bool flag = true;
                                    bool? rtSeqSync2Wc = dictionary[ldCurrentWC].RtSeqSync2WC;
                                    IEnumerator<scMESUpdateFull> enumerator1;
                                    if ((rtSeqSync2Wc.HasValue ? new bool?(rtSeqSync2Wc.GetValueOrDefault() == flag) : new bool?()).GetValueOrDefault())
                                    {
                                        DateTime t2 = Conversions.ToDate("12/31/2039");
                                        IEnumerator<scMESUpdateFull> enumerator2;
                                        enumerator2 = source4.GetEnumerator();
                                        try
                                        {
                                            while (enumerator2.MoveNext())
                                            {
                                                scMESUpdateFull current = enumerator2.Current;
                                                if (DateTime.Compare(current.due_st, t2) < 0)
                                                    t2 = current.due_st;
                                            }
                                        }
                                        finally
                                        {
                                            if (enumerator2 != null)
                                                enumerator2.Dispose();
                                        }
                                        IEnumerator<scMESUpdateFull> enumerator3;
                                        enumerator3 = source4.GetEnumerator();
                                        try
                                        {
                                            while (enumerator3.MoveNext())
                                            {
                                                scMESUpdateFull current = enumerator3.Current;
                                                TargetDate[current.hd_sect_id] = t2;
                                            }
                                        }
                                        finally
                                        {
                                            if (enumerator3 != null)
                                                enumerator3.Dispose();
                                        }
                                    }
                                    else
                                    {
                                        enumerator1 = source4.GetEnumerator();
                                        try
                                        {
                                            while (enumerator1.MoveNext())
                                            {
                                                scMESUpdateFull current = enumerator1.Current;
                                                TargetDate[current.hd_sect_id] = current.due_st;
                                            }
                                        }
                                        finally
                                        {
                                            if (enumerator1 != null)
                                                enumerator1.Dispose();
                                        }
                                    }
                                }
                            }

                            ldWCList.Remove(ldCurrentWC);

                           // IQueryable<string> source5 = (IQueryable<string>)Queryable.Select<RoutingSeq, string>(Queryable.Where<RoutingSeq>((IQueryable<M0>)source2, (Expression<Func<M0, bool>>)(rt => !(Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), rt.RtSeqSeries, "PRIMARY", false) == 0 | Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), rt.RtSeqSeries, "PRIMRY", false) == 0) & Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), rt.RtSeqNextWorkCtr, closure156.ldCurrentWC, false) == 0)), (Expression<Func<M0, M1>>)(rt => rt.RtSeqWorkCenter));
                            IQueryable<string> source5 = from rt in source2
                                                         where Microsoft.VisualBasic.CompilerServices.Operators.CompareString(rt.RtSeqSeries, "PRIMARY", false) == 0
                                                         | Microsoft.VisualBasic.CompilerServices.Operators.CompareString(rt.RtSeqSeries, "PRIMRY", false) == 0
                                                         & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(rt.RtSeqNextWorkCtr, ldCurrentWC, false) == 0
                                                         select rt.RtSeqWorkCenter;
                            List<string>.Enumerator enumerator4;
                            if (source5 != null)
                            {
                                if (source5.Count<string>() > 0)
                                {
                                        enumerator4 = source5.ToList<string>().GetEnumerator();
                                    try
                                    {
                                        while (enumerator4.MoveNext())
                                        {
                                            string current = enumerator4.Current;
                                            this.ScheduleSubProc(ref OrderList, dictionary[current].RtSeqSeries, current, OrdSER, ElecClpx, MechClpx, SectCnt, TargetDate);
                                        }
                                    }
                                    finally
                                    {
                                        enumerator4.Dispose();
                                    }
                                }
                            }

                            //source3 = (IQueryable<string>)Queryable.Select<RoutingSeq, string>(Queryable.Where<RoutingSeq>((IQueryable<M0>)source2, (Expression<Func<M0, bool>>)(rt => (Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), rt.RtSeqSeries, "PRIMARY", false) == 0 | Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), rt.RtSeqSeries, "PRIMRY", false) == 0) & Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), rt.RtSeqNextWorkCtr, closure156.ldCurrentWC, false) == 0)), (Expression<Func<M0, M1>>)(rt => rt.RtSeqWorkCenter));
                            source3 = from t in source2
                                      where Microsoft.VisualBasic.CompilerServices.Operators.CompareString(t.RtSeqSeries, "PRIMARY", false) == 0
                                      | Microsoft.VisualBasic.CompilerServices.Operators.CompareString(t.RtSeqSeries, "PRIMRY", false) == 0
                                      & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(t.RtSeqNextWorkCtr, ldCurrentWC, false) == 0
                                      select t.RtSeqWorkCenter;
                        }
                        while (source3 == null);
                        List<string>.Enumerator enumerator5;
                        if (source3.Count<string>() > 0)
                        {
                           enumerator5 = source3.ToList<string>().GetEnumerator();
                            try
                            {
                                while (enumerator5.MoveNext())
                                {
                                    string current = enumerator5.Current;
                                    if (!ldWCList.Contains(current))
                                    {
                                        ldWCList.Add(current);
                                    }
                                }
                            }
                            finally
                            {
                                enumerator5.Dispose();
                            }
                        }
                        else
                        {
                            if (ldWCList.Count == 0)
                                break;
                        }
                    }
                    while (ldWCList.Count != 0);
                }
                se0085CtEntities1.Database.Connection.Close();
            }
        }

        public void MESLoad(scLevels SEPlant, scLevels AssemblyLine, List<scMESUpdateFull> MESOrderData, bool blnIncludeShipped, bool exCloseAfter = false)
        {
            this.lcLogWriter.logData("Plant " + SEPlant.LevelName + " - " + AssemblyLine.LevelAbbrv);
            scMESOrderInfo scMesOrderInfo1 = new scMESOrderInfo();
            ArrayList MESExtractData = new ArrayList();
            bool flag1 = false;
            bool flag2 = false;
            bool flag3 = false;
            int num = 0;
            List<scMESUpdateFull>.Enumerator enumerator1;
            enumerator1 = MESOrderData.GetEnumerator();
            try
            {
                while (enumerator1.MoveNext())
                {
                    scMESUpdateFull current = enumerator1.Current;
                    Thread.CurrentThread.Join(0);
                    checked { ++num; }
                    if (MESOrderData.Count == num)
                        flag3 = true;
                    scMESOrderInfo scMesOrderInfo2 = new scMESOrderInfo();
                    scMesOrderInfo2.AssemblyLineId = current.AssemblyLineId;
                    scMesOrderInfo2.OrderFO = current.hd_q2c_nbr;
                    scMesOrderInfo2.OrderLineNum = current.od_ln_dsply_seq_nbr;
                    scMesOrderInfo2.OrderLineSL = current.hd_sub_ln_itm_id;
                    scMesOrderInfo2.OrderLineSS = current.hd_orig_shpschd_id;
                    scMesOrderInfo2.OrdShipSplt = current.hd_shp_splt;
                    scMesOrderInfo2.OrdSectsNum = current.hd_sect_id;
                    scMesOrderInfo2.OrdSectsProdNum = current.hd_prdn_ord_nbr;
                    scMesOrderInfo2.OrderLineTargetDt = current.od_trgt_dt;
                    scMesOrderInfo2.OrderLineShipDt = current.od_curr_prom_dt;
                    scMesOrderInfo2.RoutingWorkCenter = current.dt_eto_workctr;
                    scMesOrderInfo2.RoutingNextWorkCtr = current.RoutingNextWorkCtr;
                    scMesOrderInfo2.RoutingSchStartDt = current.due_st;
                    scMesOrderInfo2.RoutingSchFinishDt = current.due_fn;
                    scMesOrderInfo2.RoutingActStartDt = current.act_st;
                    scMesOrderInfo2.RoutingActFinishDt = current.act_fn;
                    scMesOrderInfo2.RoutingRunTimeMin = current.run_tm_tot;
                    scMesOrderInfo2.RoutingStatusCD = current.dt_prdn_dtl_status_cd;
                    if (!flag1)
                    {
                        scMesOrderInfo1 = scMesOrderInfo2;
                        flag1 = true;
                    }
                    if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(scMesOrderInfo1.OrderFO, scMesOrderInfo2.OrderFO, false) == 0 & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(scMesOrderInfo1.OrderLineNum, scMesOrderInfo2.OrderLineNum, false) == 0 & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(scMesOrderInfo1.OrderLineSL, scMesOrderInfo2.OrderLineSL, false) == 0 & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(scMesOrderInfo1.OrderLineSS, scMesOrderInfo2.OrderLineSS, false) == 0 & scMesOrderInfo1.OrdSectsNum == scMesOrderInfo2.OrdSectsNum && Microsoft.VisualBasic.CompilerServices.Operators.CompareString(scMesOrderInfo1.OrdSectsProdNum, scMesOrderInfo2.OrdSectsProdNum, false) != 0)
                    {
                        this.lcLogWriter.logData("Quantity " + scMesOrderInfo1.OrdSectsProdNum + " and " + scMesOrderInfo2.OrdSectsProdNum);
                        scMesOrderInfo2.OrderLineQty = checked(scMesOrderInfo1.OrderLineQty + 1);
                        scMesOrderInfo1 = scMesOrderInfo2;
                    }
                    if (!(Microsoft.VisualBasic.CompilerServices.Operators.CompareString(scMesOrderInfo1.OrderFO, scMesOrderInfo2.OrderFO, false) == 0 & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(scMesOrderInfo1.OrderLineNum, scMesOrderInfo2.OrderLineNum, false) == 0 & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(scMesOrderInfo1.OrderLineSL, scMesOrderInfo2.OrderLineSL, false) == 0 & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(scMesOrderInfo1.OrderLineSS, scMesOrderInfo2.OrderLineSS, false) == 0) | flag3)
                    {
                        if (flag3)
                            MESExtractData.Add((object)scMesOrderInfo2);
                        if (scMesOrderInfo1.OrderLineQty > 1)
                        {
                            try
                            {
                                foreach (scMESOrderInfo scMesOrderInfo3 in MESExtractData)
                                    scMesOrderInfo3.OrderLineQty = scMesOrderInfo1.OrderLineQty;
                            }
                            finally
                            {
                                //IEnumerator enumerator2;
                                //if (enumerator2 is IDisposable)
                                //    (enumerator2 as IDisposable).Dispose();
                            }
                        }
                        this.updateMESData(MESExtractData);
                        scMesOrderInfo1 = scMesOrderInfo2;
                        MESExtractData.Clear();
                        MESExtractData.Add((object)scMesOrderInfo2);
                    }
                    else
                        MESExtractData.Add((object)scMesOrderInfo2);
                    if (!flag2)
                        ;
                    if (flag3)
                        break;
                }
            }
            finally
            {
                enumerator1.Dispose();
            }
        }

        //public List<scMESUpdateFull> LoadMESOrders(string AssyLine, string Q2CNbr, string Q2CLine, string Q2CSL, string Q2CSS)
        //{
        //    //Commented out bcz not in use
        //    List<scMESUpdateFull> scMesUpdateFullList = new List<scMESUpdateFull>();
        //    DataSet dataSet = new DataSet();
        //    //OdbcConnection odbcConnection = new OdbcConnection();
        //    //odbcConnection.ConnectionString = "Driver={Sybase ASE ODBC Driver};NA=mcldb01.m087.us.schneider-electric.com,5000;Database=dbmes;Uid=misuser;Pwd=misuser;";
        //    //OdbcCommand selectCommand = new OdbcCommand();
        //    //selectCommand.Connection = odbcConnection;
        //    //odbcConnection.Open();
        //    //OdbcDataAdapter odbcDataAdapter = new OdbcDataAdapter(selectCommand);
        //    //odbcDataAdapter.SelectCommand.CommandTimeout = 2000;
        //    SqlConnection sqlConnection = new SqlConnection();
        //    sqlConnection.ConnectionString = "Data Source=SYSTEM-12;Initial Catalog=SE0085CT;User Id=sa;Password=pinnacle123";
        //    SqlCommand selectCommand = new SqlCommand();
        //    selectCommand.Connection = sqlConnection;
        //    sqlConnection.Open();
        //    SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(selectCommand);
        //    sqlDataAdapter.SelectCommand.CommandTimeout = 2000;
        //    //string str1 = "select distinct  hd.eto_ln  ,hd.q2c_nbr  ,od.ln_dsply_seq_nbr  ,hd.sub_ln_itm_id  ,hd.orig_shpschd_id  ,hd.shp_splt  ,hd.sect_id  ,hd.prdn_ord_nbr  ,dt.eto_workctr  ,dt.prdn_dtl_status_cd  ,SUM(dt.run_tm_mins) as run_tm_tot  ,MIN(dt.due_to_strt_dt) as due_st  ,MAX(dt.due_to_fnsh_dt) as due_fn  ,MIN(dt.act_strt_dt) as act_st  ,MAX(dt.act_fnsh_dt) as act_fn from dbmes.dbo.mespohdr as hd  join dbmes.dbo.mespodtl as dt  on hd.prdn_ord_nbr = dt.prdn_ord_nbr  join dbmes.dbo.messordr as od  on od.q2c_nbr = hd.q2c_nbr and od.ln_nbr = hd.ln_nbr and od.bom_nbr = hd.bom_nbr  group by  hd.eto_ln  ,hd.q2c_nbr  ,od.ln_dsply_seq_nbr  ,hd.sub_ln_itm_id  ,hd.orig_shpschd_id  ,hd.shp_splt  ,hd.sect_id  ,hd.prdn_ord_nbr  ,dt.eto_workctr  ,dt.prdn_dtl_status_cd  having hd.eto_ln = ? AND hd.q2c_nbr = ? AND od.ln_dsply_seq_nbr = ? AND hd.sub_ln_itm_id = ? AND hd.orig_shpschd_id = ?  order by hd.q2c_nbr, od.ln_dsply_seq_nbr, hd.sect_id, due_st ";
        //    string str1 = "select distinct  hd.eto_ln  ,hd.q2c_nbr  ,od.ln_dsply_seq_nbr  ,hd.sub_ln_itm_id  ,hd.orig_shpschd_id  ,hd.shp_splt  ,hd.sect_id  ,hd.prdn_ord_nbr  ,dt.eto_workctr  ,dt.prdn_dtl_status_cd  ,SUM(dt.run_tm_mins) as run_tm_tot  ,MIN(dt.due_to_strt_dt) as due_st  ,MAX(dt.due_to_fnsh_dt) as due_fn  ,MIN(dt.act_strt_dt) as act_st  ,MAX(dt.act_fnsh_dt) as act_fn from dbo.mespohdr as hd  join dbo.mespodtl as dt  on hd.prdn_ord_nbr = dt.prdn_ord_nbr  join dbo.messordr as od  on od.q2c_nbr = hd.q2c_nbr and od.ln_nbr = hd.ln_nbr and od.bom_nbr = hd.bom_nbr  group by  hd.eto_ln  ,hd.q2c_nbr  ,od.ln_dsply_seq_nbr  ,hd.sub_ln_itm_id  ,hd.orig_shpschd_id  ,hd.shp_splt  ,hd.sect_id  ,hd.prdn_ord_nbr  ,dt.eto_workctr  ,dt.prdn_dtl_status_cd  having hd.eto_ln = @eto_ln AND hd.q2c_nbr = @q2c_nbr AND od.ln_dsply_seq_nbr = @ln_dsply_seq_nbr AND hd.sub_ln_itm_id = @sub_ln_itm_id AND hd.orig_shpschd_id = @orig_shpschd_id  order by hd.q2c_nbr, od.ln_dsply_seq_nbr, hd.sect_id, due_st ";
        //    selectCommand.CommandText = str1;
        //    selectCommand.Parameters.Clear();
        //    string str2 = AssyLine;
        //    //selectCommand.Parameters.AddWithValue("eto_ln", (object)str2);
        //    selectCommand.Parameters.AddWithValue("@eto_ln", (object)str2);
        //    string str3 = Q2CNbr;
        //    //selectCommand.Parameters.AddWithValue("q2c_nbr", (object)str3);
        //    selectCommand.Parameters.AddWithValue("@q2c_nbr", (object)str3);
        //    string str4 = Q2CLine;
        //    //selectCommand.Parameters.AddWithValue("ln_dsply_seq_nbr", (object)str4);
        //    selectCommand.Parameters.AddWithValue("@ln_dsply_seq_nbr", (object)str4);
        //    string str5 = Q2CSL;
        //    //selectCommand.Parameters.AddWithValue("sub_ln_itm_id", (object)str5);
        //    selectCommand.Parameters.AddWithValue("@sub_ln_itm_id", (object)str5);
        //    string str6 = Q2CSS;
        //    //selectCommand.Parameters.AddWithValue("orig_shpschd_id", (object)str6);
        //    selectCommand.Parameters.AddWithValue("@orig_shpschd_id", (object)str6);
        //    sqlDataAdapter.SelectCommand = selectCommand;
        //    dataSet.Tables.Clear();
        //    sqlDataAdapter.Fill(dataSet);
        //    List<string> stringList = new List<string>();
        //    try
        //    {
        //        foreach (DataColumn column in (InternalDataCollectionBase)dataSet.Tables[0].Columns)
        //        {
        //            stringList.Add(column.ColumnName);
        //            //short num;
        //            //checked { ++num; }
        //        }
        //    }
        //    finally
        //    {
        //        //IEnumerator enumerator;
        //        //if (enumerator is IDisposable)
        //        //    (enumerator as IDisposable).Dispose();
        //    }
        //    try
        //    {
        //        foreach (DataRow row in dataSet.Tables[0].Rows)
        //        {
        //            short num = 0;
        //            scMESUpdateFull scMesUpdateFull = new scMESUpdateFull();
        //            List<string>.Enumerator enumerator;
        //            enumerator = stringList.GetEnumerator();
        //            try
        //            {
        //                while (enumerator.MoveNext())
        //                {
        //                    string current = enumerator.Current;
        //                    if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current, "eto_ln", false) == 0)
        //                        scMesUpdateFull.hd_eto_ln = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(row[(int)num]));
        //                    else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current, "q2c_nbr", false) == 0)
        //                        scMesUpdateFull.hd_q2c_nbr = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(row[(int)num]));
        //                    else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current, "ln_dsply_seq_nbr", false) == 0)
        //                        scMesUpdateFull.od_ln_dsply_seq_nbr = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(row[(int)num]));
        //                    else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current, "sub_ln_itm_id", false) == 0)
        //                        scMesUpdateFull.hd_sub_ln_itm_id = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(row[(int)num]));
        //                    else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current, "orig_shpschd_id", false) == 0)
        //                        scMesUpdateFull.hd_orig_shpschd_id = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(row[(int)num]));
        //                    else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current, "shp_splt", false) == 0)
        //                        scMesUpdateFull.hd_shp_splt = Conversions.ToInteger(Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(row[(int)num])));
        //                    else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current, "sect_id", false) == 0)
        //                        scMesUpdateFull.hd_sect_id = Conversions.ToInteger(Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(row[(int)num])));
        //                    else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current, "prdn_ord_nbr", false) == 0)
        //                        scMesUpdateFull.hd_prdn_ord_nbr = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(row[(int)num]));
        //                    else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current, "disp_dt", false) == 0)
        //                        scMesUpdateFull.hd_disp_dt = Conversions.ToDate(Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(row[(int)num])));
        //                    else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current, "eto_workctr", false) == 0)
        //                        scMesUpdateFull.dt_eto_workctr = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(row[(int)num]));
        //                    else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current, "run_tm_tot", false) == 0)
        //                        scMesUpdateFull.run_tm_tot = Conversions.ToInteger(row[(int)num]);
        //                    else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current, "due_st", false) == 0)
        //                        scMesUpdateFull.due_st = Conversions.ToDate(row[(int)num]);
        //                    else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current, "due_fn", false) == 0)
        //                        scMesUpdateFull.due_fn = Conversions.ToDate(row[(int)num]);
        //                    else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current, "act_st", false) == 0)
        //                        scMesUpdateFull.act_st = Conversions.ToDate(row[(int)num]);
        //                    else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current, "act_fn", false) == 0)
        //                        scMesUpdateFull.act_fn = Conversions.ToDate(row[(int)num]);
        //                    else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current, "curr_prom_dt", false) == 0)
        //                        scMesUpdateFull.od_curr_prom_dt = Conversions.ToDate(Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(row[(int)num])));
        //                    else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current, "trgt_dt", false) == 0)
        //                        scMesUpdateFull.od_trgt_dt = Conversions.ToDate(Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(row[(int)num])));
        //                    else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current, "prdn_dtl_status_cd", false) == 0)
        //                        scMesUpdateFull.dt_prdn_dtl_status_cd = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(row[(int)num]));
        //                    else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current, "update_dt", false) == 0)
        //                        scMesUpdateFull.dt_update_dt = Conversions.ToDate(Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(row[(int)num])));
        //                    checked { ++num; }
        //                }
        //            }
        //            finally
        //            {
        //                enumerator.Dispose();
        //            }
        //            scMesUpdateFullList.Add(scMesUpdateFull);
        //        }
        //    }
        //    finally
        //    {
        //        sqlConnection.Close();
        //        sqlConnection.Dispose();
        //        //IEnumerator enumerator;
        //        //if (enumerator is IDisposable)
        //        //    (enumerator as IDisposable).Dispose();
        //    }
        //    return scMesUpdateFullList;
        //}

        public List<scMESUpdateFull> LoadMESOrders(string AssyLine, string Q2CNbr, string Q2CLine, string Q2CSL, string Q2CSS)
        {
            short myCounter = 0;
            IEnumerator enumerator = null;
            IEnumerator enumerator1 = null;
            List<string>.Enumerator enumerator2 = new List<string>.Enumerator();
            List<scMESUpdateFull> ldMESIOrdersList = new List<scMESUpdateFull>();
            DataSet ldRtnData = new DataSet();
            //OdbcConnection ldConn = new OdbcConnection()
            //{
            //    ConnectionString = "Driver={Sybase ASE ODBC Driver};NA=mcldb01.m087.us.schneider-electric.com,5000;Database=dbmes;Uid=misuser;Pwd=misuser;"
            //};
            //OdbcCommand lddBCMD01 = new OdbcCommand()
            //{
            //    Connection = ldConn
            //};
            SqlConnection ldConn = new SqlConnection()
            {
                ConnectionString = "Data Source=SYSTEM-12;Initial Catalog=SE0085CT;User Id=sa;Password=pinnacle123;"
            };
            SqlCommand lddBCMD01 = new SqlCommand()
            {
                Connection = ldConn
            };
            ldConn.Open();
            //OdbcDataAdapter adapter = new OdbcDataAdapter(lddBCMD01);
            SqlDataAdapter adapter = new SqlDataAdapter(lddBCMD01);
            adapter.SelectCommand.CommandTimeout = 2000;
            //lddBCMD01.CommandText = "select distinct  hd.eto_ln  ,hd.q2c_nbr  ,od.ln_dsply_seq_nbr  ,hd.sub_ln_itm_id  ,hd.orig_shpschd_id  ,hd.shp_splt  ,hd.sect_id  ,hd.prdn_ord_nbr  ,dt.eto_workctr  ,dt.prdn_dtl_status_cd  ,SUM(dt.run_tm_mins) as run_tm_tot  ,MIN(dt.due_to_strt_dt) as due_st  ,MAX(dt.due_to_fnsh_dt) as due_fn  ,MIN(dt.act_strt_dt) as act_st  ,MAX(dt.act_fnsh_dt) as act_fn from dbmes.dbo.mespohdr as hd  join dbmes.dbo.mespodtl as dt  on hd.prdn_ord_nbr = dt.prdn_ord_nbr  join dbmes.dbo.messordr as od  on od.q2c_nbr = hd.q2c_nbr and od.ln_nbr = hd.ln_nbr and od.bom_nbr = hd.bom_nbr  group by  hd.eto_ln  ,hd.q2c_nbr  ,od.ln_dsply_seq_nbr  ,hd.sub_ln_itm_id  ,hd.orig_shpschd_id  ,hd.shp_splt  ,hd.sect_id  ,hd.prdn_ord_nbr  ,dt.eto_workctr  ,dt.prdn_dtl_status_cd  having hd.eto_ln = ? AND hd.q2c_nbr = ? AND od.ln_dsply_seq_nbr = ? AND hd.sub_ln_itm_id = ? AND hd.orig_shpschd_id = ?  order by hd.q2c_nbr, od.ln_dsply_seq_nbr, hd.sect_id, due_st ";
            //lddBCMD01.Parameters.Clear();
            //lddBCMD01.Parameters.AddWithValue("eto_ln", AssyLine);
            //lddBCMD01.Parameters.AddWithValue("q2c_nbr", Q2CNbr);
            //lddBCMD01.Parameters.AddWithValue("ln_dsply_seq_nbr", Q2CLine);
            //lddBCMD01.Parameters.AddWithValue("sub_ln_itm_id", Q2CSL);
            //lddBCMD01.Parameters.AddWithValue("orig_shpschd_id", Q2CSS);
            lddBCMD01.CommandText = "select distinct  hd.eto_ln  ,hd.q2c_nbr  ,od.ln_dsply_seq_nbr  ,hd.sub_ln_itm_id  ,hd.orig_shpschd_id  ,hd.shp_splt  ,hd.sect_id  ,hd.prdn_ord_nbr  ,dt.eto_workctr  ,dt.prdn_dtl_status_cd  ,SUM(dt.run_tm_mins) as run_tm_tot  ,MIN(dt.due_to_strt_dt) as due_st  ,MAX(dt.due_to_fnsh_dt) as due_fn  ,MIN(dt.act_strt_dt) as act_st  ,MAX(dt.act_fnsh_dt) as act_fn from dbo.mespohdr as hd  join dbo.mespodtl as dt  on hd.prdn_ord_nbr = dt.prdn_ord_nbr  join dbo.messordr as od  on od.q2c_nbr = hd.q2c_nbr and od.ln_nbr = hd.ln_nbr and od.bom_nbr = hd.bom_nbr  group by  hd.eto_ln  ,hd.q2c_nbr  ,od.ln_dsply_seq_nbr  ,hd.sub_ln_itm_id  ,hd.orig_shpschd_id  ,hd.shp_splt  ,hd.sect_id  ,hd.prdn_ord_nbr  ,dt.eto_workctr  ,dt.prdn_dtl_status_cd  having hd.eto_ln = @eto_ln AND hd.q2c_nbr = @q2c_nbr AND od.ln_dsply_seq_nbr = @ln_dsply_seq_nbr AND hd.sub_ln_itm_id = @sub_ln_itm_id AND hd.orig_shpschd_id = @orig_shpschd_id  order by hd.q2c_nbr, od.ln_dsply_seq_nbr, hd.sect_id, due_st ";
            lddBCMD01.Parameters.Clear();
            lddBCMD01.Parameters.AddWithValue("@eto_ln", AssyLine);
            lddBCMD01.Parameters.AddWithValue("@q2c_nbr", Q2CNbr);
            lddBCMD01.Parameters.AddWithValue("@ln_dsply_seq_nbr", Q2CLine);
            lddBCMD01.Parameters.AddWithValue("@sub_ln_itm_id", Q2CSL);
            lddBCMD01.Parameters.AddWithValue("@orig_shpschd_id", Q2CSS);
            adapter.SelectCommand = lddBCMD01;
            ldRtnData.Tables.Clear();
            adapter.Fill(ldRtnData);
            List<string> myColumnList = new List<string>();
            try
            {
                enumerator = ldRtnData.Tables[0].Columns.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    myColumnList.Add(((DataColumn)enumerator.Current).ColumnName);
                    myCounter = checked((short)(checked(myCounter + 1)));
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            try
            {
                enumerator1 = ldRtnData.Tables[0].Rows.GetEnumerator();
                while (enumerator1.MoveNext())
                {
                    DataRow myrow = (DataRow)enumerator1.Current;
                    myCounter = 0;
                    scMESUpdateFull ldMESIOrders = new scMESUpdateFull();
                    try
                    {
                        enumerator2 = myColumnList.GetEnumerator();
                        while (enumerator2.MoveNext())
                        {
                            string ldItem = enumerator2.Current;
                            if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "eto_ln", false) == 0)
                            {
                                ldMESIOrders.hd_eto_ln = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter]));
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "q2c_nbr", false) == 0)
                            {
                                ldMESIOrders.hd_q2c_nbr = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter]));
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "ln_dsply_seq_nbr", false) == 0)
                            {
                                ldMESIOrders.od_ln_dsply_seq_nbr = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter]));
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "sub_ln_itm_id", false) == 0)
                            {
                                ldMESIOrders.hd_sub_ln_itm_id = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter]));
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "orig_shpschd_id", false) == 0)
                            {
                                ldMESIOrders.hd_orig_shpschd_id = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter]));
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "shp_splt", false) == 0)
                            {
                                ldMESIOrders.hd_shp_splt = Conversions.ToInteger(Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter])));
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "sect_id", false) == 0)
                            {
                                ldMESIOrders.hd_sect_id = Conversions.ToInteger(Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter])));
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "prdn_ord_nbr", false) == 0)
                            {
                                ldMESIOrders.hd_prdn_ord_nbr = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter]));
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "disp_dt", false) == 0)
                            {
                                ldMESIOrders.hd_disp_dt = Conversions.ToDate(Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter])));
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "eto_workctr", false) == 0)
                            {
                                ldMESIOrders.dt_eto_workctr = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter]));
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "run_tm_tot", false) == 0)
                            {
                                ldMESIOrders.run_tm_tot = Conversions.ToInteger(myrow[myCounter]);
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "due_st", false) == 0)
                            {
                                ldMESIOrders.due_st = Conversions.ToDate(myrow[myCounter]);
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "due_fn", false) == 0)
                            {
                                ldMESIOrders.due_fn = Conversions.ToDate(myrow[myCounter]);
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "act_st", false) == 0)
                            {
                                ldMESIOrders.act_st = Conversions.ToDate(myrow[myCounter]);
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "act_fn", false) == 0)
                            {
                                ldMESIOrders.act_fn = Conversions.ToDate(myrow[myCounter]);
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "curr_prom_dt", false) == 0)
                            {
                                ldMESIOrders.od_curr_prom_dt = Conversions.ToDate(Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter])));
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "trgt_dt", false) == 0)
                            {
                                ldMESIOrders.od_trgt_dt = Conversions.ToDate(Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter])));
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "prdn_dtl_status_cd", false) == 0)
                            {
                                ldMESIOrders.dt_prdn_dtl_status_cd = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter]));
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "update_dt", false) == 0)
                            {
                                ldMESIOrders.dt_update_dt = Conversions.ToDate(Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter])));
                            }
                            myCounter = checked((short)(checked(myCounter + 1)));
                        }
                    }
                    finally
                    {
                        ((IDisposable)enumerator2).Dispose();
                    }
                    ldMESIOrdersList.Add(ldMESIOrders);
                }
            }
            finally
            {
                if (enumerator1 is IDisposable)
                {
                    (enumerator1 as IDisposable).Dispose();
                }
            }
            return ldMESIOrdersList;
        }

        public void updateMESData(ArrayList MESExtractData)
		{
			IEnumerator enumerator = null;
			IEnumerator enumerator1 = null;
			IEnumerator ordSectsId = null;
			ArrayList MESExtractOrderedData = new ArrayList();
			IEnumerable<scMESOrderInfo> ldOrderedMESQuery = 
				from object oq in MESExtractData
				select (scMESOrderInfo)oq into oq
				orderby oq.OrderFO, oq.OrderLineNum, oq.OrderLineSS, oq.OrderLineSL, oq.OrdSectsNum, oq.OrdSectsProdNum
				select oq;
			if (ldOrderedMESQuery.Count<scMESOrderInfo>() > 0)
			{
				MESExtractOrderedData.AddRange(ldOrderedMESQuery.ToArray<scMESOrderInfo>());
				int ldSectionCounter = 0;
				string ldProdOrderMem = "";
				ArrayList ldSectionArray = new ArrayList();
				try
				{
					enumerator = MESExtractOrderedData.GetEnumerator();
					while (enumerator.MoveNext())
					{
						scMESOrderInfo ldMESSteps = (scMESOrderInfo)enumerator.Current;
						if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldProdOrderMem, ldMESSteps.OrdSectsProdNum, false) != 0)
						{
							ldProdOrderMem = ldMESSteps.OrdSectsProdNum;
							ldSectionArray.Add(ldMESSteps.OrdSection);
							ldSectionCounter++;
						}
					}
				}
				finally
				{
					if (enumerator is IDisposable)
					{
						(enumerator as IDisposable).Dispose();
					}
				}
				bool ldUpdateRequired = false;
				scMESOrderInfo ldMESOrder = new scMESOrderInfo();
				ldMESOrder = (scMESOrderInfo)MESExtractOrderedData[0];
				scMESTableStatus[] ldMESDBData = this.StatusMES_o_l_rLOJ(ldMESOrder.OrderFO, ldMESOrder.OrderLineNum, ldMESOrder.OrderLineSL, ldMESOrder.OrderLineSS);
				if (ldMESDBData == null)
				{
					this.AddMESSections(MESExtractOrderedData, ldSectionArray);
					ldUpdateRequired = false;
				}
				else if (checked((int)ldMESDBData.Length) > ldSectionCounter)
				{
					int ldDelSectionCnt = 0;
					int ldSectionId = 0;
					int num = checked(ldSectionCounter + 1);
					int length = checked((int)ldMESDBData.Length);
					for (ldDelSectionCnt = num; ldDelSectionCnt <= length; ldDelSectionCnt++)
					{
						ldSectionId = ldMESDBData.ElementAt<scMESTableStatus>(checked(ldDelSectionCnt - 1)).OrdSectsId;
						this.dBDeleteDataBySectionId(ldSectionId, true, false, false);
					}
					ldUpdateRequired = true;
				}
				else if (checked((int)ldMESDBData.Length) >= ldSectionCounter)
				{
					ldUpdateRequired = true;
				}
				else
				{
					ArrayList ldSection2AddArray = new ArrayList();
					int ldAddSectionCnt = 0;
					int length1 = checked((int)ldMESDBData.Length);
					int num1 = checked(ldSectionCounter - 1);
					for (ldAddSectionCnt = length1; ldAddSectionCnt <= num1; ldAddSectionCnt++)
					{
						ldSection2AddArray.Add(RuntimeHelpers.GetObjectValue(ldSectionArray[ldAddSectionCnt]));
					}
					this.AddMESSections(MESExtractOrderedData, ldSection2AddArray);
					ldUpdateRequired = true;
				}
				if (ldUpdateRequired)
				{
					ldMESDBData = this.StatusMES_o_l_rLOJ(ldMESOrder.OrderFO, ldMESOrder.OrderLineNum, ldMESOrder.OrderLineSL, ldMESOrder.OrderLineSS);
					if (checked((int)ldMESDBData.Length) != ldSectionCounter)
					{
						LogWriter logWriter = this.lcLogWriter;
						string[] orderFO = new string[] { "Error importing data, aborting MES import for Order; ", ldMESOrder.OrderFO, "-", ldMESOrder.OrderLineNum, "-", ldMESOrder.OrderLineSS, "-", ldMESOrder.OrderLineSL };
						logWriter.logData(string.Concat(orderFO));
					}
					else
					{
						scOrdSectionsInfo _scOrdSectionsInfo = new scOrdSectionsInfo();
						int ldSectionCnt = 0;
						try
						{
							enumerator1 = ldSectionArray.GetEnumerator();
							while (enumerator1.MoveNext())
							{
								_scOrdSectionsInfo = (scOrdSectionsInfo)enumerator1.Current;
								ArrayList MESExtractSectionData = new ArrayList();
								IEnumerable<scMESOrderInfo> ldMESSectionQuery = 
									from object oq in MESExtractOrderedData
									select (scMESOrderInfo)oq into oq
									where Microsoft.VisualBasic.CompilerServices.Operators.CompareString(oq.OrdSectsProdNum, _scOrdSectionsInfo.OrdSectsProdNum, false) == 0
									select oq;
								if (ldMESSectionQuery.Count<scMESOrderInfo>() <= 0)
								{
									break;
								}
								else
								{
									MESExtractSectionData.AddRange(ldMESSectionQuery.ToArray<scMESOrderInfo>());
									try
									{
										ordSectsId = MESExtractSectionData.GetEnumerator();
										while (ordSectsId.MoveNext())
										{
											((scMESOrderInfo)ordSectsId.Current).OrdSectsId = ldMESDBData[ldSectionCnt].OrdSectsId;
										}
									}
									finally
									{
										if (ordSectsId is IDisposable)
										{
											(ordSectsId as IDisposable).Dispose();
										}
									}
									this.UpdateMES_o_l_s_r(MESExtractSectionData);
									ldSectionCnt++;
								}
							}
						}
						finally
						{
							if (enumerator1 is IDisposable)
							{
								(enumerator1 as IDisposable).Dispose();
							}
						}
					}
				}
			}
		}

        public List<scMESBOM> rtnNWLocation(string Q2CNbr, string Q2CLine, string Q2CSL, string Q2CSS, string MFGPartNbr)
        {
            short myCounter = 0;
            IEnumerator enumerator = null;
            IEnumerator enumerator1 = null;
            List<string>.Enumerator enumerator2 = new List<string>.Enumerator();
            DataSet ldRtnData = new DataSet();
            //OdbcConnection ldConn = new OdbcConnection()
            //{
            //    ConnectionString = "Driver={Sybase ASE ODBC Driver};NA=mcldb01.m087.us.schneider-electric.com,5000;Database=dbmes;Uid=misuser;Pwd=misuser;"
            //};
            //OdbcCommand lddBCMD01 = new OdbcCommand()
            //{
            //    Connection = ldConn
            //};
            //ldConn.Open();
            //OdbcDataAdapter adapter = new OdbcDataAdapter(lddBCMD01);
            SqlConnection ldConn = new SqlConnection()
            {
                ConnectionString = "Data Source=SYSTEM-12;Initial Catalog=SE0085CT;User Id=sa;Password=pinnacle123"
            };
            SqlCommand lddBCMD01 = new SqlCommand()
            {
                Connection = ldConn
            };
            ldConn.Open();
            SqlDataAdapter adapter = new SqlDataAdapter(lddBCMD01);
            adapter.SelectCommand.CommandTimeout = 2000;
            //lddBCMD01.CommandText = "SELECT DISTINCT hdr.plnt ,hdr.q2c_nbr ,odr.ln_dsply_seq_nbr ,hdr.sub_ln_itm_id ,hdr.orig_shpschd_id ,hdr.prdn_ord_nbr, dtl.shp_splt ,hdr.sect_id ,dtl.parent_part_nbr ,dtl.comp_part_nbr ,SUM(dtl.ext_qty_per) AS TotSectQty  FROM dbmes.dbo.mespohdr as hdr JOIN dbmes.dbo.messordr as odr ON hdr.bom_nbr = odr.bom_nbr JOIN dbmes.dbo.mesbomdtl as dtl ON hdr.bom_nbr = dtl.bom_nbr WHERE hdr.plnt='0085' AND hdr.q2c_nbr=? AND odr.ln_dsply_seq_nbr=? AND hdr.sub_ln_itm_id=? AND hdr.orig_shpschd_id=? AND dtl.comp_part_nbr=? AND hdr.ln_nbr = dtl.ln_nbr AND hdr.sect_id = dtl.sect_id AND hdr.ln_nbr = odr.ln_nbr GROUP BY hdr.plnt ,hdr.q2c_nbr ,odr.ln_dsply_seq_nbr ,hdr.sub_ln_itm_id ,hdr.orig_shpschd_id ,hdr.prdn_ord_nbr, dtl.shp_splt ,hdr.sect_id ,dtl.parent_part_nbr ,dtl.comp_part_nbr ORDER BY dtl.shp_splt, hdr.sect_id, dtl.parent_part_nbr ASC";
            lddBCMD01.CommandText = "SELECT DISTINCT hdr.plnt ,hdr.q2c_nbr ,odr.ln_dsply_seq_nbr ,hdr.sub_ln_itm_id ,hdr.orig_shpschd_id ,hdr.prdn_ord_nbr, dtl.shp_splt ,hdr.sect_id ,dtl.parent_part_nbr ,dtl.comp_part_nbr ,SUM(dtl.ext_qty_per) AS TotSectQty  FROM dbmes.dbo.mespohdr as hdr JOIN dbmes.dbo.messordr as odr ON hdr.bom_nbr = odr.bom_nbr JOIN dbmes.dbo.mesbomdtl as dtl ON hdr.bom_nbr = dtl.bom_nbr WHERE hdr.plnt='0085' AND hdr.q2c_nbr=@q2c_nbr AND odr.ln_dsply_seq_nbr=@ln_dsply_seq_nbr AND hdr.sub_ln_itm_id=@sub_ln_itm_id AND hdr.orig_shpschd_id=@orig_shpschd_id AND dtl.comp_part_nbr=@comp_part_nbr AND hdr.ln_nbr = dtl.ln_nbr AND hdr.sect_id = dtl.sect_id AND hdr.ln_nbr = odr.ln_nbr GROUP BY hdr.plnt ,hdr.q2c_nbr ,odr.ln_dsply_seq_nbr ,hdr.sub_ln_itm_id ,hdr.orig_shpschd_id ,hdr.prdn_ord_nbr, dtl.shp_splt ,hdr.sect_id ,dtl.parent_part_nbr ,dtl.comp_part_nbr ORDER BY dtl.shp_splt, hdr.sect_id, dtl.parent_part_nbr ASC";
            lddBCMD01.Parameters.Clear();
            //lddBCMD01.Parameters.AddWithValue("q2c_nbr", Q2CNbr);
            //lddBCMD01.Parameters.AddWithValue("ln_dsply_seq_nbr", Q2CLine);
            //lddBCMD01.Parameters.AddWithValue("sub_ln_itm_id", Q2CSL);
            //lddBCMD01.Parameters.AddWithValue("orig_shpschd_id", Q2CSS);
            //lddBCMD01.Parameters.AddWithValue("comp_part_nbr", MFGPartNbr);
            lddBCMD01.Parameters.AddWithValue("@q2c_nbr", Q2CNbr);
            lddBCMD01.Parameters.AddWithValue("@ln_dsply_seq_nbr", Q2CLine);
            lddBCMD01.Parameters.AddWithValue("@sub_ln_itm_id", Q2CSL);
            lddBCMD01.Parameters.AddWithValue("@orig_shpschd_id", Q2CSS);
            lddBCMD01.Parameters.AddWithValue("@comp_part_nbr", MFGPartNbr);
            adapter.SelectCommand = lddBCMD01;
            ldRtnData.Tables.Clear();
            adapter.Fill(ldRtnData);
            List<string> myColumnList = new List<string>();
            try
            {
                enumerator = ldRtnData.Tables[0].Columns.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    myColumnList.Add(((DataColumn)enumerator.Current).ColumnName);
                    myCounter = checked((short)(checked(myCounter + 1)));
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            List<scMESBOM> ldMesBom = new List<scMESBOM>();
            try
            {
                enumerator1 = ldRtnData.Tables[0].Rows.GetEnumerator();
                while (enumerator1.MoveNext())
                {
                    DataRow myrow = (DataRow)enumerator1.Current;
                    myCounter = 0;
                    scMESBOM ldBOMLine = new scMESBOM();
                    try
                    {
                        enumerator2 = myColumnList.GetEnumerator();
                        while (enumerator2.MoveNext())
                        {
                            string ldItem = enumerator2.Current;
                            if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "plnt", false) == 0)
                            {
                                ldBOMLine.plnt = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter]));
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "q2c_nbr", false) == 0)
                            {
                                ldBOMLine.q2c_nbr = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter]));
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "ln_dsply_seq_nbr", false) == 0)
                            {
                                ldBOMLine.ln_dsply_seq_nbr = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter]));
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "sub_ln_itm_id", false) == 0)
                            {
                                ldBOMLine.sub_ln_itm_id = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter]));
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "orig_shpschd_id", false) == 0)
                            {
                                ldBOMLine.orig_shpschd_id = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter]));
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "prdn_ord_nbr", false) == 0)
                            {
                                ldBOMLine.prdn_ord_nbr = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter]));
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "shp_splt", false) == 0)
                            {
                                ldBOMLine.shp_splt = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter]));
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "sect_id", false) == 0)
                            {
                                ldBOMLine.sect_id = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter]));
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "parent_part_nbr", false) == 0)
                            {
                                ldBOMLine.parent_part_nbr = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter]));
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "comp_part_nbr", false) == 0)
                            {
                                ldBOMLine.comp_part_nbr = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter]));
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldItem, "TotSectQty", false) == 0)
                            {
                                ldBOMLine.ext_qty_per = Conversions.ToDecimal(Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(myrow[myCounter])));
                            }
                            myCounter = checked((short)(checked(myCounter + 1)));
                        }
                    }
                    finally
                    {
                        ((IDisposable)enumerator2).Dispose();
                    }
                    ldMesBom.Add(ldBOMLine);
                }
            }
            finally
            {
                if (enumerator1 is IDisposable)
                {
                    (enumerator1 as IDisposable).Dispose();
                }
            }
            lddBCMD01.Dispose();
            adapter.Dispose();
            ldConn.Close();
            ldConn.Dispose();
            return ldMesBom;
        }

        //public void MESLoad(scPlants SEPlant, scLevels AssemblyLine, List<scMESUpdateFull> MESOrderData, bool blnIncludeShipped, bool exCloseAfter = false)
        //{
        //    this.lcLogWriter.logData("Plant " + SEPlant.PlantName + " - " + AssemblyLine.LevelAbbrv);
        //    scMESOrderInfo scMesOrderInfo1 = new scMESOrderInfo();
        //    ArrayList MESExtractData = new ArrayList();
        //    bool flag1 = false;
        //    bool flag2 = false;
        //    bool flag3 = false;
        //    int num = 0;
        //    List<scMESUpdateFull>.Enumerator enumerator1;
        //    enumerator1 = MESOrderData.GetEnumerator();
        //    try
        //    {
        //        while (enumerator1.MoveNext())
        //        {
        //            scMESUpdateFull current = enumerator1.Current;
        //            Thread.CurrentThread.Join(0);
        //            checked { ++num; }
        //            if (MESOrderData.Count == num)
        //                flag3 = true;
        //            scMESOrderInfo scMesOrderInfo2 = new scMESOrderInfo();
        //            scMesOrderInfo2.AssemblyLineId = current.AssemblyLineId;
        //            scMesOrderInfo2.OrderFO = current.hd_q2c_nbr;
        //            scMesOrderInfo2.OrderLineNum = current.od_ln_dsply_seq_nbr;
        //            scMesOrderInfo2.OrderLineSL = current.hd_sub_ln_itm_id;
        //            scMesOrderInfo2.OrderLineSS = current.hd_orig_shpschd_id;
        //            scMesOrderInfo2.OrdShipSplt = current.hd_shp_splt;
        //            scMesOrderInfo2.OrdSectsNum = current.hd_sect_id;
        //            scMesOrderInfo2.OrdSectsProdNum = current.hd_prdn_ord_nbr;
        //            scMesOrderInfo2.OrderLineTargetDt = current.od_trgt_dt;
        //            scMesOrderInfo2.OrderLineShipDt = current.od_curr_prom_dt;
        //            scMesOrderInfo2.RoutingWorkCenter = current.dt_eto_workctr;
        //            scMesOrderInfo2.RoutingNextWorkCtr = current.RoutingNextWorkCtr;
        //            scMesOrderInfo2.RoutingSchStartDt = current.due_st;
        //            scMesOrderInfo2.RoutingSchFinishDt = current.due_fn;
        //            scMesOrderInfo2.RoutingActStartDt = current.act_st;
        //            scMesOrderInfo2.RoutingActFinishDt = current.act_fn;
        //            scMesOrderInfo2.RoutingRunTimeMin = current.run_tm_tot;
        //            scMesOrderInfo2.RoutingStatusCD = current.dt_prdn_dtl_status_cd;
        //            if (!flag1)
        //            {
        //                scMesOrderInfo1 = scMesOrderInfo2;
        //                flag1 = true;
        //            }
        //            if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(scMesOrderInfo1.OrderFO, scMesOrderInfo2.OrderFO, false) == 0 & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(scMesOrderInfo1.OrderLineNum, scMesOrderInfo2.OrderLineNum, false) == 0 & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(scMesOrderInfo1.OrderLineSL, scMesOrderInfo2.OrderLineSL, false) == 0 & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(scMesOrderInfo1.OrderLineSS, scMesOrderInfo2.OrderLineSS, false) == 0 & scMesOrderInfo1.OrdSectsNum == scMesOrderInfo2.OrdSectsNum && Microsoft.VisualBasic.CompilerServices.Operators.CompareString(scMesOrderInfo1.OrdSectsProdNum, scMesOrderInfo2.OrdSectsProdNum, false) != 0)
        //            {
        //                this.lcLogWriter.logData("Quantity " + scMesOrderInfo1.OrdSectsProdNum + " and " + scMesOrderInfo2.OrdSectsProdNum);
        //                scMesOrderInfo2.OrderLineQty = checked(scMesOrderInfo1.OrderLineQty + 1);
        //                scMesOrderInfo1 = scMesOrderInfo2;
        //            }
        //            if (!(Microsoft.VisualBasic.CompilerServices.Operators.CompareString(scMesOrderInfo1.OrderFO, scMesOrderInfo2.OrderFO, false) == 0 & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(scMesOrderInfo1.OrderLineNum, scMesOrderInfo2.OrderLineNum, false) == 0 & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(scMesOrderInfo1.OrderLineSL, scMesOrderInfo2.OrderLineSL, false) == 0 & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(scMesOrderInfo1.OrderLineSS, scMesOrderInfo2.OrderLineSS, false) == 0) | flag3)
        //            {
        //                if (flag3)
        //                    MESExtractData.Add((object)scMesOrderInfo2);
        //                if (scMesOrderInfo1.OrderLineQty > 1)
        //                {
        //                    try
        //                    {
        //                        foreach (scMESOrderInfo scMesOrderInfo3 in MESExtractData)
        //                            scMesOrderInfo3.OrderLineQty = scMesOrderInfo1.OrderLineQty;
        //                    }
        //                    finally
        //                    {
        //                        //IEnumerator enumerator2;
        //                        //if (enumerator2 is IDisposable)
        //                        //    (enumerator2 as IDisposable).Dispose();
        //                    }
        //                }
        //                this.updateMESData(MESExtractData);
        //                scMesOrderInfo1 = scMesOrderInfo2;
        //                MESExtractData.Clear();
        //                MESExtractData.Add((object)scMesOrderInfo2);
        //            }
        //            else
        //                MESExtractData.Add((object)scMesOrderInfo2);
        //            if (!flag2)
        //                ;
        //            if (flag3)
        //                break;
        //        }
        //    }
        //    finally
        //    {
        //        enumerator1.Dispose();
        //    }
        //}

        public void MESLoad(scPlants SEPlant, scLevels AssemblyLine, List<scMESUpdateFull> MESOrderData, bool blnIncludeShipped, bool exCloseAfter = false)
        {
            List<scMESUpdateFull>.Enumerator enumerator = new List<scMESUpdateFull>.Enumerator();
            IEnumerator orderLineQty = null;
            this.lcLogWriter.logData(string.Concat("Plant ", SEPlant.PlantName, " - ", AssemblyLine.LevelAbbrv));
            scMESOrderInfo ldMESExtractDataMemory = new scMESOrderInfo();
            ArrayList ldMESOrderArrayList = new ArrayList();
            bool ldInitOneShot = false;
            bool blnDBOrderComplete = false;
            bool blnDataEnd = false;
            int ldRowCnt = 0;
            try
            {
                enumerator = MESOrderData.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    scMESUpdateFull ldMesRow = enumerator.Current;
                    Thread.CurrentThread.Join(0);
                    ldRowCnt++;
                    if (MESOrderData.Count == ldRowCnt)
                    {
                        blnDataEnd = true;
                    }
                    scMESOrderInfo ldMESExtractData = new scMESOrderInfo()
                    {
                        AssemblyLineId = ldMesRow.AssemblyLineId,
                        OrderFO = ldMesRow.hd_q2c_nbr,
                        OrderLineNum = ldMesRow.od_ln_dsply_seq_nbr,
                        OrderLineSL = ldMesRow.hd_sub_ln_itm_id,
                        OrderLineSS = ldMesRow.hd_orig_shpschd_id,
                        OrdShipSplt = ldMesRow.hd_shp_splt,
                        OrdSectsNum = ldMesRow.hd_sect_id,
                        OrdSectsProdNum = ldMesRow.hd_prdn_ord_nbr,
                        OrderLineTargetDt = ldMesRow.od_trgt_dt,
                        OrderLineShipDt = ldMesRow.od_curr_prom_dt,
                        RoutingWorkCenter = ldMesRow.dt_eto_workctr,
                        RoutingNextWorkCtr = ldMesRow.RoutingNextWorkCtr,
                        RoutingSchStartDt = ldMesRow.due_st,
                        RoutingSchFinishDt = ldMesRow.due_fn,
                        RoutingActStartDt = ldMesRow.act_st,
                        RoutingActFinishDt = ldMesRow.act_fn,
                        RoutingRunTimeMin = ldMesRow.run_tm_tot,
                        RoutingStatusCD = ldMesRow.dt_prdn_dtl_status_cd
                    };
                    if (!ldInitOneShot)
                    {
                        ldMESExtractDataMemory = ldMESExtractData;
                        ldInitOneShot = true;
                    }
                    if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldMESExtractDataMemory.OrderFO, ldMESExtractData.OrderFO, false) == 0 & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldMESExtractDataMemory.OrderLineNum, ldMESExtractData.OrderLineNum, false) == 0 & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldMESExtractDataMemory.OrderLineSL, ldMESExtractData.OrderLineSL, false) == 0 & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldMESExtractDataMemory.OrderLineSS, ldMESExtractData.OrderLineSS, false) == 0 & ldMESExtractDataMemory.OrdSectsNum == ldMESExtractData.OrdSectsNum)
                    {
                        if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldMESExtractDataMemory.OrdSectsProdNum, ldMESExtractData.OrdSectsProdNum, false) != 0)
                        {
                            this.lcLogWriter.logData(string.Concat("Quantity ", ldMESExtractDataMemory.OrdSectsProdNum, " and ", ldMESExtractData.OrdSectsProdNum));
                            ldMESExtractData.OrderLineQty = checked(ldMESExtractDataMemory.OrderLineQty + 1);
                            ldMESExtractDataMemory = ldMESExtractData;
                        }
                    }
                    if (!(!(Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldMESExtractDataMemory.OrderFO, ldMESExtractData.OrderFO, false) == 0 & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldMESExtractDataMemory.OrderLineNum, ldMESExtractData.OrderLineNum, false) == 0 & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldMESExtractDataMemory.OrderLineSL, ldMESExtractData.OrderLineSL, false) == 0 & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldMESExtractDataMemory.OrderLineSS, ldMESExtractData.OrderLineSS, false) == 0) | blnDataEnd))
                    {
                        ldMESOrderArrayList.Add(ldMESExtractData);
                    }
                    else
                    {
                        if (blnDataEnd)
                        {
                            ldMESOrderArrayList.Add(ldMESExtractData);
                        }
                        if (ldMESExtractDataMemory.OrderLineQty > 1)
                        {
                            try
                            {
                                orderLineQty = ldMESOrderArrayList.GetEnumerator();
                                while (orderLineQty.MoveNext())
                                {
                                    ((scMESOrderInfo)orderLineQty.Current).OrderLineQty = ldMESExtractDataMemory.OrderLineQty;
                                }
                            }
                            finally
                            {
                                if (orderLineQty is IDisposable)
                                {
                                    (orderLineQty as IDisposable).Dispose();
                                }
                            }
                        }
                        this.updateMESData(ldMESOrderArrayList);
                        ldMESExtractDataMemory = ldMESExtractData;
                        ldMESOrderArrayList.Clear();
                        ldMESOrderArrayList.Add(ldMESExtractData);
                    }
                    if(!blnDBOrderComplete);
                    if (blnDataEnd)
                    {
                        break;
                    }
                }
            }
            finally
            {
                ((IDisposable)enumerator).Dispose();
            }
        }

        private void SyncShipSplt(ref List<scMESUpdateFull> OrderList, string WorkCenter)
		{
			//clsEngineMES._Closure$__158._Closure$__159 $VB$Closure_ClosureVariable_9F = null;
			IEnumerator<scMESUpdateFull> enumerator = null;
			IEnumerable<scMESUpdateFull> qryShipWC = 
				from sq in OrderList
				where Microsoft.VisualBasic.CompilerServices.Operators.CompareString(sq.dt_eto_workctr, WorkCenter, false) == 0
				orderby sq.hd_sect_id
				select sq;
			if (qryShipWC != null)
			{
				if (qryShipWC.Count<scMESUpdateFull>() > 0)
				{
					IEnumerable<int> qrySSCnt = 
						from sc in qryShipWC
						select sc.hd_shp_splt;
					List<int> ldShipSltCnt = qrySSCnt.Distinct<int>().ToList<int>();
					DateTime[] ldRtStart = new DateTime[checked(ldShipSltCnt.Count + 1)];
					DateTime[] ldRtFinish = new DateTime[checked(ldShipSltCnt.Count + 1)];
					int count = checked(ldShipSltCnt.Count - 1);
					for (int sp = 0; sp <= count; sp++)
					{
                        //$VB$Closure_ClosureVariable_9F = new clsEngineMES._Closure$__158._Closure$__159($VB$Closure_ClosureVariable_9F)
                        //{
						int	ldShipSplt = ldShipSltCnt[sp];
						//};
						var qryShipSplt = (
							from ss in qryShipWC
                            where ss.hd_shp_splt == ldShipSplt
							select ss).GroupBy((scMESUpdateFull ss) => ss.hd_shp_splt, (scMESUpdateFull ss) => ss, (int hd_shp_splt, IEnumerable<scMESUpdateFull> argument0) => new { hd_shp_splt = hd_shp_splt, g = argument0 }).Select((argument1) => new { due_st = argument1.g.Min<scMESUpdateFull, DateTime>((scMESUpdateFull ss) => ss.due_st), due_fn = argument1.g.Max<scMESUpdateFull, DateTime>((scMESUpdateFull ss) => ss.due_fn) });

						ldRtStart[sp] = qryShipSplt.First().due_st;
						ldRtFinish[sp] = qryShipSplt.First().due_fn;
					}
                    //using (enumerator)
                    //{
						enumerator = qryShipWC.GetEnumerator();
						while (enumerator.MoveNext())
						{
							scMESUpdateFull ldSect = enumerator.Current;
							int num = checked(ldShipSltCnt.Count - 1);
							for (int sp = 0; sp <= num; sp++)
							{
								if (ldSect.hd_shp_splt == ldShipSltCnt[sp])
								{
									ldSect.due_st = ldRtStart[sp];
									ldSect.due_fn = ldRtFinish[sp];
								}
							}
						}
					//}
				}
			}
		}

        private bool ScheduleWC(ref Dictionary<string, RoutingSeq> WCDef, ref scMESUpdateFull RtStep, string OrdSER, string ElecClpx, string MechClpx, int SectCnt)
        {
            int num1 = 16;
            int num2 = 0;
            if (WCDef.ContainsKey(WCDef[RtStep.dt_eto_workctr].RtSeqNextWorkCtr))
                num2 = (int)WCDef[WCDef[RtStep.dt_eto_workctr].RtSeqNextWorkCtr].RtSeqQueueTm;
            int num3 = 0;
            int? nullable1 = WCDef[RtStep.dt_eto_workctr].RtSeqLeadTm;
            bool? nullable2;
            bool? nullable3;
            if (!nullable1.HasValue)
            {
                nullable3 = new bool?();
            }
            else
            {
                nullable2 = new bool?(nullable1.GetValueOrDefault() > num3);
                nullable3 = nullable2;
            }
            int? nullable4;
            int? nullable5;
            if (nullable3.GetValueOrDefault())
            {
                nullable4 = WCDef[RtStep.dt_eto_workctr].RtSeqLeadTm;
                int? nullable6;
                if (!nullable4.HasValue)
                {
                    nullable6 = new int?();
                }
                else
                {
                    nullable5 = new int?(checked(num2 + nullable4.GetValueOrDefault()));
                    nullable6 = nullable5;
                }
                num2 = (int)nullable6;
            }
            DateTime dateTime1;
            if (num2 > 0)
            {
                scMESUpdateFull scMesUpdateFull = RtStep;
                dateTime1 = RtStep.od_trgt_dt;
                DateTime dateTime2 = dateTime1.AddMinutes((double)checked(-1 * num2));
                scMesUpdateFull.due_fn = dateTime2;
            }
            else
                RtStep.due_fn = RtStep.od_trgt_dt;
            int num4 = (int)WCDef[RtStep.dt_eto_workctr].RtSeqBaseTm;
            int num5 = 0;
            if (this._dtLaborContent.ContainsKey(RtStep.dt_eto_workctr))
            {
                num5 = this.LoadLabor(RtStep);
                checked { num4 += num5; }
            }
            int num6 = 0;
            nullable5 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm1;
            bool? nullable7 = nullable5.HasValue ? new bool?(nullable5.GetValueOrDefault() > num6) : new bool?();
            int num7 = 0;
            nullable4 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm2;
            bool? nullable8 = nullable4.HasValue ? new bool?(nullable4.GetValueOrDefault() > num7) : new bool?();
            bool? nullable9 = !nullable7.HasValue || !nullable7.GetValueOrDefault() ? (nullable8.HasValue ? (nullable8.GetValueOrDefault() ? new bool?(true) : nullable7) : new bool?()) : new bool?(true);
            int num8 = 0;
            nullable1 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm3;
            bool? nullable10 = nullable1.HasValue ? new bool?(nullable1.GetValueOrDefault() > num8) : new bool?();
            bool? nullable11 = !nullable9.HasValue || !nullable9.GetValueOrDefault() ? (nullable10.HasValue ? (nullable10.GetValueOrDefault() ? new bool?(true) : nullable9) : new bool?()) : new bool?(true);
            int num9 = 0;
            int? nullable12 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm4;
            bool? nullable13;
            bool? nullable14;
            if (!nullable12.HasValue)
            {
                nullable14 = new bool?();
            }
            else
            {
                nullable13 = new bool?(nullable12.GetValueOrDefault() > num9);
                nullable14 = nullable13;
            }
            bool? nullable15 = nullable14;
            bool? nullable16 = !nullable11.HasValue || !nullable11.GetValueOrDefault() ? (nullable15.HasValue ? (nullable15.GetValueOrDefault() ? new bool?(true) : nullable11) : new bool?()) : new bool?(true);
            int num10 = 0;
            int? nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm5;
            bool? nullable18;
            bool? nullable19;
            if (!nullable17.HasValue)
            {
                nullable19 = new bool?();
            }
            else
            {
                nullable18 = new bool?(nullable17.GetValueOrDefault() > num10);
                nullable19 = nullable18;
            }
            bool? nullable20 = nullable19;
            nullable2 = !nullable16.HasValue || !nullable16.GetValueOrDefault() ? (nullable20.HasValue ? (nullable20.GetValueOrDefault() ? new bool?(true) : nullable16) : new bool?()) : new bool?(true);
            if (nullable2.GetValueOrDefault())
            {
                string[] strArray = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureKey.Split(':');
                int num11 = 0;
                nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm1;
                bool? nullable6;
                if (!nullable17.HasValue)
                {
                    nullable6 = new bool?();
                }
                else
                {
                    nullable13 = new bool?(nullable17.GetValueOrDefault() > num11);
                    nullable6 = nullable13;
                }
                nullable18 = nullable6;
                double? nullable21;
                double? nullable22;
                double? nullable23;
                double? nullable24;
                if (nullable18.GetValueOrDefault() && ((IEnumerable<string>)strArray).Count<string>() > 0)
                {
                    string str = strArray[0].Substring(checked(strArray[0].IndexOf(";") + 1));
                    if (OrdSER.Contains(str.Trim()))
                    {
                        if (str.Trim().Contains("PLC"))
                        {
                            if (num5 > 1440)
                            {
                                nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm1;
                                int? nullable25;
                                if (!nullable17.HasValue)
                                {
                                    nullable25 = new int?();
                                }
                                else
                                {
                                    nullable12 = new int?(checked(num4 + nullable17.GetValueOrDefault()));
                                    nullable25 = nullable12;
                                }
                                num4 = (int)nullable25;
                            }
                        }
                        else
                        {
                            nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm1;
                            int? nullable25;
                            if (!nullable17.HasValue)
                            {
                                nullable25 = new int?();
                            }
                            else
                            {
                                nullable12 = new int?(checked(num4 + nullable17.GetValueOrDefault()));
                                nullable25 = nullable12;
                            }
                            num4 = (int)nullable25;
                        }
                    }
                    else if (str.Contains("MechCplx"))
                    {
                        double num12 = (double)num4;
                        double num13 = Math.Pow(Conversions.ToDouble(MechClpx), 2.0);
                        nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm1;
                        double? nullable25;
                        if (!nullable17.HasValue)
                        {
                            nullable25 = new double?();
                        }
                        else
                        {
                            nullable21 = new double?((double)nullable17.GetValueOrDefault());
                            nullable25 = nullable21;
                        }
                        double? nullable26 = nullable25;
                        double? nullable27;
                        if (!nullable26.HasValue)
                        {
                            nullable27 = new double?();
                        }
                        else
                        {
                            nullable22 = new double?(nullable26.GetValueOrDefault() * num13);
                            nullable27 = nullable22;
                        }
                        nullable23 = nullable27;
                        double? nullable28;
                        if (!nullable23.HasValue)
                        {
                            nullable28 = new double?();
                        }
                        else
                        {
                            nullable24 = new double?(num12 + nullable23.GetValueOrDefault());
                            nullable28 = nullable24;
                        }
                        num4 = checked((int)Math.Round((double)nullable28));
                    }
                    else if (str.Contains("ElecCplx"))
                    {
                        double num12 = (double)num4;
                        double num13 = Math.Pow(Conversions.ToDouble(ElecClpx), 2.0);
                        nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm1;
                        double? nullable25;
                        if (!nullable17.HasValue)
                        {
                            nullable25 = new double?();
                        }
                        else
                        {
                            nullable23 = new double?((double)nullable17.GetValueOrDefault());
                            nullable25 = nullable23;
                        }
                        double? nullable26 = nullable25;
                        double? nullable27;
                        if (!nullable26.HasValue)
                        {
                            nullable27 = new double?();
                        }
                        else
                        {
                            nullable24 = new double?(nullable26.GetValueOrDefault() * num13);
                            nullable27 = nullable24;
                        }
                        nullable21 = nullable27;
                        double? nullable28;
                        if (!nullable21.HasValue)
                        {
                            nullable28 = new double?();
                        }
                        else
                        {
                            nullable22 = new double?(num12 + nullable21.GetValueOrDefault());
                            nullable28 = nullable22;
                        }
                        num4 = checked((int)Math.Round((double)nullable28));
                    }
                    else if (str.Contains("SectCnt"))
                    {
                        nullable5 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm1;
                        int? nullable25;
                        if (!nullable5.HasValue)
                        {
                            nullable25 = new int?();
                        }
                        else
                        {
                            nullable4 = new int?(checked(nullable5.GetValueOrDefault() * SectCnt));
                            nullable25 = nullable4;
                        }
                        nullable17 = nullable25;
                        int? nullable26;
                        if (!nullable17.HasValue)
                        {
                            nullable26 = new int?();
                        }
                        else
                        {
                            nullable12 = new int?(checked(num4 + nullable17.GetValueOrDefault()));
                            nullable26 = nullable12;
                        }
                        num4 = (int)nullable26;
                    }
                }
                int num14 = 0;
                nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm2;
                bool? nullable29;
                if (!nullable17.HasValue)
                {
                    nullable29 = new bool?();
                }
                else
                {
                    nullable13 = new bool?(nullable17.GetValueOrDefault() > num14);
                    nullable29 = nullable13;
                }
                nullable18 = nullable29;
                if (nullable18.GetValueOrDefault() && ((IEnumerable<string>)strArray).Count<string>() > 0)
                {
                    string str = strArray[1].Substring(checked(strArray[1].IndexOf(";") + 1));
                    if (OrdSER.Contains(str.Trim()))
                    {
                        if (str.Trim().Contains("PLC"))
                        {
                            if (num5 > 1440)
                            {
                                nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm2;
                                int? nullable25;
                                if (!nullable17.HasValue)
                                {
                                    nullable25 = new int?();
                                }
                                else
                                {
                                    nullable12 = new int?(checked(num4 + nullable17.GetValueOrDefault()));
                                    nullable25 = nullable12;
                                }
                                num4 = (int)nullable25;
                            }
                        }
                        else
                        {
                            nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm2;
                            int? nullable25;
                            if (!nullable17.HasValue)
                            {
                                nullable25 = new int?();
                            }
                            else
                            {
                                nullable12 = new int?(checked(num4 + nullable17.GetValueOrDefault()));
                                nullable25 = nullable12;
                            }
                            num4 = (int)nullable25;
                        }
                    }
                    else if (str.Contains("MechCplx"))
                    {
                        double num12 = (double)num4;
                        double num13 = Math.Pow(Conversions.ToDouble(MechClpx), 2.0);
                        nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm2;
                        double? nullable25;
                        if (!nullable17.HasValue)
                        {
                            nullable25 = new double?();
                        }
                        else
                        {
                            nullable23 = new double?((double)nullable17.GetValueOrDefault());
                            nullable25 = nullable23;
                        }
                        double? nullable26 = nullable25;
                        double? nullable27;
                        if (!nullable26.HasValue)
                        {
                            nullable27 = new double?();
                        }
                        else
                        {
                            nullable24 = new double?(nullable26.GetValueOrDefault() * num13);
                            nullable27 = nullable24;
                        }
                        nullable21 = nullable27;
                        double? nullable28;
                        if (!nullable21.HasValue)
                        {
                            nullable28 = new double?();
                        }
                        else
                        {
                            nullable22 = new double?(num12 + nullable21.GetValueOrDefault());
                            nullable28 = nullable22;
                        }
                        num4 = checked((int)Math.Round((double)nullable28));
                    }
                    else if (str.Contains("ElecCplx"))
                    {
                        double num12 = (double)num4;
                        double num13 = Math.Pow(Conversions.ToDouble(ElecClpx), 2.0);
                        nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm2;
                        double? nullable25;
                        if (!nullable17.HasValue)
                        {
                            nullable25 = new double?();
                        }
                        else
                        {
                            nullable23 = new double?((double)nullable17.GetValueOrDefault());
                            nullable25 = nullable23;
                        }
                        double? nullable26 = nullable25;
                        double? nullable27;
                        if (!nullable26.HasValue)
                        {
                            nullable27 = new double?();
                        }
                        else
                        {
                            nullable24 = new double?(nullable26.GetValueOrDefault() * num13);
                            nullable27 = nullable24;
                        }
                        nullable21 = nullable27;
                        double? nullable28;
                        if (!nullable21.HasValue)
                        {
                            nullable28 = new double?();
                        }
                        else
                        {
                            nullable22 = new double?(num12 + nullable21.GetValueOrDefault());
                            nullable28 = nullable22;
                        }
                        num4 = checked((int)Math.Round((double)nullable28));
                    }
                    else if (str.Contains("SectCnt"))
                    {
                        nullable5 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm2;
                        int? nullable25;
                        if (!nullable5.HasValue)
                        {
                            nullable25 = new int?();
                        }
                        else
                        {
                            nullable4 = new int?(checked(nullable5.GetValueOrDefault() * SectCnt));
                            nullable25 = nullable4;
                        }
                        nullable17 = nullable25;
                        int? nullable26;
                        if (!nullable17.HasValue)
                        {
                            nullable26 = new int?();
                        }
                        else
                        {
                            nullable12 = new int?(checked(num4 + nullable17.GetValueOrDefault()));
                            nullable26 = nullable12;
                        }
                        num4 = (int)nullable26;
                    }
                }
                int num15 = 0;
                nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm3;
                bool? nullable30;
                if (!nullable17.HasValue)
                {
                    nullable30 = new bool?();
                }
                else
                {
                    nullable13 = new bool?(nullable17.GetValueOrDefault() > num15);
                    nullable30 = nullable13;
                }
                nullable18 = nullable30;
                if (nullable18.GetValueOrDefault() && ((IEnumerable<string>)strArray).Count<string>() > 0)
                {
                    string str = strArray[2].Substring(checked(strArray[2].IndexOf(";") + 1));
                    if (OrdSER.Contains(str.Trim()))
                    {
                        if (str.Trim().Contains("PLC"))
                        {
                            if (num5 > 1440)
                            {
                                nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm3;
                                int? nullable25;
                                if (!nullable17.HasValue)
                                {
                                    nullable25 = new int?();
                                }
                                else
                                {
                                    nullable12 = new int?(checked(num4 + nullable17.GetValueOrDefault()));
                                    nullable25 = nullable12;
                                }
                                num4 = (int)nullable25;
                            }
                        }
                        else
                        {
                            nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm3;
                            int? nullable25;
                            if (!nullable17.HasValue)
                            {
                                nullable25 = new int?();
                            }
                            else
                            {
                                nullable12 = new int?(checked(num4 + nullable17.GetValueOrDefault()));
                                nullable25 = nullable12;
                            }
                            num4 = (int)nullable25;
                        }
                    }
                    else if (str.Contains("MechCplx"))
                    {
                        double num12 = (double)num4;
                        double num13 = Math.Pow(Conversions.ToDouble(MechClpx), 2.0);
                        nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm3;
                        double? nullable25;
                        if (!nullable17.HasValue)
                        {
                            nullable25 = new double?();
                        }
                        else
                        {
                            nullable23 = new double?((double)nullable17.GetValueOrDefault());
                            nullable25 = nullable23;
                        }
                        double? nullable26 = nullable25;
                        double? nullable27;
                        if (!nullable26.HasValue)
                        {
                            nullable27 = new double?();
                        }
                        else
                        {
                            nullable24 = new double?(nullable26.GetValueOrDefault() * num13);
                            nullable27 = nullable24;
                        }
                        nullable21 = nullable27;
                        double? nullable28;
                        if (!nullable21.HasValue)
                        {
                            nullable28 = new double?();
                        }
                        else
                        {
                            nullable22 = new double?(num12 + nullable21.GetValueOrDefault());
                            nullable28 = nullable22;
                        }
                        num4 = checked((int)Math.Round((double)nullable28));
                    }
                    else if (str.Contains("ElecCplx"))
                    {
                        double num12 = (double)num4;
                        double num13 = Math.Pow(Conversions.ToDouble(ElecClpx), 2.0);
                        nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm3;
                        double? nullable25;
                        if (!nullable17.HasValue)
                        {
                            nullable25 = new double?();
                        }
                        else
                        {
                            nullable23 = new double?((double)nullable17.GetValueOrDefault());
                            nullable25 = nullable23;
                        }
                        double? nullable26 = nullable25;
                        double? nullable27;
                        if (!nullable26.HasValue)
                        {
                            nullable27 = new double?();
                        }
                        else
                        {
                            nullable24 = new double?(nullable26.GetValueOrDefault() * num13);
                            nullable27 = nullable24;
                        }
                        nullable21 = nullable27;
                        double? nullable28;
                        if (!nullable21.HasValue)
                        {
                            nullable28 = new double?();
                        }
                        else
                        {
                            nullable22 = new double?(num12 + nullable21.GetValueOrDefault());
                            nullable28 = nullable22;
                        }
                        num4 = checked((int)Math.Round((double)nullable28));
                    }
                    else if (str.Contains("SectCnt"))
                    {
                        nullable5 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm3;
                        int? nullable25;
                        if (!nullable5.HasValue)
                        {
                            nullable25 = new int?();
                        }
                        else
                        {
                            nullable4 = new int?(checked(nullable5.GetValueOrDefault() * SectCnt));
                            nullable25 = nullable4;
                        }
                        nullable17 = nullable25;
                        int? nullable26;
                        if (!nullable17.HasValue)
                        {
                            nullable26 = new int?();
                        }
                        else
                        {
                            nullable12 = new int?(checked(num4 + nullable17.GetValueOrDefault()));
                            nullable26 = nullable12;
                        }
                        num4 = (int)nullable26;
                    }
                }
                int num16 = 0;
                nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm4;
                bool? nullable31;
                if (!nullable17.HasValue)
                {
                    nullable31 = new bool?();
                }
                else
                {
                    nullable13 = new bool?(nullable17.GetValueOrDefault() > num16);
                    nullable31 = nullable13;
                }
                nullable18 = nullable31;
                if (nullable18.GetValueOrDefault() && ((IEnumerable<string>)strArray).Count<string>() > 0)
                {
                    string str = strArray[3].Substring(checked(strArray[3].IndexOf(";") + 1));
                    if (OrdSER.Contains(str.Trim()))
                    {
                        if (str.Trim().Contains("PLC"))
                        {
                            if (num5 > 1440)
                            {
                                nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm4;
                                int? nullable25;
                                if (!nullable17.HasValue)
                                {
                                    nullable25 = new int?();
                                }
                                else
                                {
                                    nullable12 = new int?(checked(num4 + nullable17.GetValueOrDefault()));
                                    nullable25 = nullable12;
                                }
                                num4 = (int)nullable25;
                            }
                        }
                        else
                        {
                            nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm4;
                            int? nullable25;
                            if (!nullable17.HasValue)
                            {
                                nullable25 = new int?();
                            }
                            else
                            {
                                nullable12 = new int?(checked(num4 + nullable17.GetValueOrDefault()));
                                nullable25 = nullable12;
                            }
                            num4 = (int)nullable25;
                        }
                    }
                    else if (str.Contains("MechCplx"))
                    {
                        double num12 = (double)num4;
                        double num13 = Math.Pow(Conversions.ToDouble(MechClpx), 2.0);
                        nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm4;
                        double? nullable25;
                        if (!nullable17.HasValue)
                        {
                            nullable25 = new double?();
                        }
                        else
                        {
                            nullable23 = new double?((double)nullable17.GetValueOrDefault());
                            nullable25 = nullable23;
                        }
                        double? nullable26 = nullable25;
                        double? nullable27;
                        if (!nullable26.HasValue)
                        {
                            nullable27 = new double?();
                        }
                        else
                        {
                            nullable24 = new double?(nullable26.GetValueOrDefault() * num13);
                            nullable27 = nullable24;
                        }
                        nullable21 = nullable27;
                        double? nullable28;
                        if (!nullable21.HasValue)
                        {
                            nullable28 = new double?();
                        }
                        else
                        {
                            nullable22 = new double?(num12 + nullable21.GetValueOrDefault());
                            nullable28 = nullable22;
                        }
                        num4 = checked((int)Math.Round((double)nullable28));
                    }
                    else if (str.Contains("ElecCplx"))
                    {
                        double num12 = (double)num4;
                        double num13 = Math.Pow(Conversions.ToDouble(ElecClpx), 2.0);
                        nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm4;
                        double? nullable25;
                        if (!nullable17.HasValue)
                        {
                            nullable25 = new double?();
                        }
                        else
                        {
                            nullable23 = new double?((double)nullable17.GetValueOrDefault());
                            nullable25 = nullable23;
                        }
                        double? nullable26 = nullable25;
                        double? nullable27;
                        if (!nullable26.HasValue)
                        {
                            nullable27 = new double?();
                        }
                        else
                        {
                            nullable24 = new double?(nullable26.GetValueOrDefault() * num13);
                            nullable27 = nullable24;
                        }
                        nullable21 = nullable27;
                        double? nullable28;
                        if (!nullable21.HasValue)
                        {
                            nullable28 = new double?();
                        }
                        else
                        {
                            nullable22 = new double?(num12 + nullable21.GetValueOrDefault());
                            nullable28 = nullable22;
                        }
                        num4 = checked((int)Math.Round((double)nullable28));
                    }
                    else if (str.Contains("SectCnt"))
                    {
                        nullable5 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm4;
                        int? nullable25;
                        if (!nullable5.HasValue)
                        {
                            nullable25 = new int?();
                        }
                        else
                        {
                            nullable4 = new int?(checked(nullable5.GetValueOrDefault() * SectCnt));
                            nullable25 = nullable4;
                        }
                        nullable17 = nullable25;
                        int? nullable26;
                        if (!nullable17.HasValue)
                        {
                            nullable26 = new int?();
                        }
                        else
                        {
                            nullable12 = new int?(checked(num4 + nullable17.GetValueOrDefault()));
                            nullable26 = nullable12;
                        }
                        num4 = (int)nullable26;
                    }
                }
                int num17 = 0;
                nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm5;
                bool? nullable32;
                if (!nullable17.HasValue)
                {
                    nullable32 = new bool?();
                }
                else
                {
                    nullable13 = new bool?(nullable17.GetValueOrDefault() > num17);
                    nullable32 = nullable13;
                }
                nullable18 = nullable32;
                if (nullable18.GetValueOrDefault() && ((IEnumerable<string>)strArray).Count<string>() > 0)
                {
                    string str = strArray[4].Substring(checked(strArray[4].IndexOf(";") + 1));
                    if (OrdSER.Contains(str.Trim()))
                    {
                        if (str.Trim().Contains("PLC"))
                        {
                            if (num5 > 1440)
                            {
                                nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm5;
                                int? nullable25;
                                if (!nullable17.HasValue)
                                {
                                    nullable25 = new int?();
                                }
                                else
                                {
                                    nullable12 = new int?(checked(num4 + nullable17.GetValueOrDefault()));
                                    nullable25 = nullable12;
                                }
                                num4 = (int)nullable25;
                            }
                        }
                        else
                        {
                            nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm5;
                            int? nullable25;
                            if (!nullable17.HasValue)
                            {
                                nullable25 = new int?();
                            }
                            else
                            {
                                nullable12 = new int?(checked(num4 + nullable17.GetValueOrDefault()));
                                nullable25 = nullable12;
                            }
                            num4 = (int)nullable25;
                        }
                    }
                    else if (str.Contains("MechCplx"))
                    {
                        double num12 = (double)num4;
                        double num13 = Math.Pow(Conversions.ToDouble(MechClpx), 2.0);
                        nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm5;
                        double? nullable25;
                        if (!nullable17.HasValue)
                        {
                            nullable25 = new double?();
                        }
                        else
                        {
                            nullable23 = new double?((double)nullable17.GetValueOrDefault());
                            nullable25 = nullable23;
                        }
                        double? nullable26 = nullable25;
                        double? nullable27;
                        if (!nullable26.HasValue)
                        {
                            nullable27 = new double?();
                        }
                        else
                        {
                            nullable24 = new double?(nullable26.GetValueOrDefault() * num13);
                            nullable27 = nullable24;
                        }
                        nullable21 = nullable27;
                        double? nullable28;
                        if (!nullable21.HasValue)
                        {
                            nullable28 = new double?();
                        }
                        else
                        {
                            nullable22 = new double?(num12 + nullable21.GetValueOrDefault());
                            nullable28 = nullable22;
                        }
                        num4 = checked((int)Math.Round((double)nullable28));
                    }
                    else if (str.Contains("ElecCplx"))
                    {
                        double num12 = (double)num4;
                        double num13 = Math.Pow(Conversions.ToDouble(ElecClpx), 2.0);
                        nullable17 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm5;
                        double? nullable25;
                        if (!nullable17.HasValue)
                        {
                            nullable25 = new double?();
                        }
                        else
                        {
                            nullable23 = new double?((double)nullable17.GetValueOrDefault());
                            nullable25 = nullable23;
                        }
                        double? nullable26 = nullable25;
                        double? nullable27;
                        if (!nullable26.HasValue)
                        {
                            nullable27 = new double?();
                        }
                        else
                        {
                            nullable24 = new double?(nullable26.GetValueOrDefault() * num13);
                            nullable27 = nullable24;
                        }
                        nullable21 = nullable27;
                        double? nullable28;
                        if (!nullable21.HasValue)
                        {
                            nullable28 = new double?();
                        }
                        else
                        {
                            nullable22 = new double?(num12 + nullable21.GetValueOrDefault());
                            nullable28 = nullable22;
                        }
                        num4 = checked((int)Math.Round((double)nullable28));
                    }
                    else if (str.Contains("SectCnt"))
                    {
                        nullable5 = WCDef[RtStep.dt_eto_workctr].RtSeqFeatureTm5;
                        int? nullable25;
                        if (!nullable5.HasValue)
                        {
                            nullable25 = new int?();
                        }
                        else
                        {
                            nullable4 = new int?(checked(nullable5.GetValueOrDefault() * SectCnt));
                            nullable25 = nullable4;
                        }
                        nullable17 = nullable25;
                        int? nullable26;
                        if (!nullable17.HasValue)
                        {
                            nullable26 = new int?();
                        }
                        else
                        {
                            nullable12 = new int?(checked(num4 + nullable17.GetValueOrDefault()));
                            nullable26 = nullable12;
                        }
                        num4 = (int)nullable26;
                    }
                }
            }
            string Left = RtStep.hd_eto_ln.Trim();
            if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(Left, "SWBD", false) == 0)
                RtStep.AssemblyLineId = 1;
            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(Left, "LVDO", false) == 0)
                RtStep.AssemblyLineId = 2;
            RtStep.RoutingNextWorkCtr = WCDef[RtStep.dt_eto_workctr].RtSeqNextWorkCtr;
            int num18 = checked((int)Math.Round(unchecked((double)num4 / (double)num1 / 24.0)));
            RtStep.run_tm_tot = num18;
            scMESUpdateFull scMesUpdateFull1 = RtStep;
            dateTime1 = RtStep.due_fn;
            DateTime dateTime3 = dateTime1.AddMinutes((double)checked(-1 * num18));
            scMesUpdateFull1.due_st = dateTime3;
            scDateValidate scDateValidate1 = new scDateValidate();
            scDateValidate scDateValidate2 = this.ProcessWeekEndsHolidays(RtStep.due_fn, RtStep.due_st);
            RtStep.due_fn = scDateValidate2.EndDate;
            RtStep.due_st = scDateValidate2.StartDate;
            return true;
        }

        public void ScheduleSubProc(ref List<scMESUpdateFull> OrderList, string SubSeq, string SubProcTieWC, string OrdSER, string ElecClpx, string MechClpx, int SectCnt, DateTime[] TargetDate)
		{
			//clsEngineMES._Closure$__157 $VB$Closure_ClosureVariable_9D = null;
			IEnumerator<scMESUpdateFull> enumerator = null;
			IEnumerator<scMESUpdateFull> enumerator1 = null;
			List<string>.Enumerator enumerator2 = new List<string>.Enumerator();
			string item = "";
			List<string> strs = new List<string>()
			{
				SubProcTieWC
			};
			Conversions.ToDate("01/01/1901");
			DateTime[] ldSubTarget = new DateTime[26];
			int i = 0;
			do
			{
				ldSubTarget[i] = TargetDate[i];
				i++;
			}
			while (i <= 24);
			Dictionary<string, RoutingSeq> dlWCRtSeq = null;
			using (SE0085CTEntities1 CTdB = new SE0085CTEntities1())
			{
                //CTdB.Database.Connection.ConnectionString = this._CTConnection;
                //DbSet<RoutingSeq> routingSeqs = CTdB.RoutingSeqs;
                //ParameterExpression parameterExpression = Expression.Parameter(typeof(RoutingSeq), "rs");
                //BinaryExpression binaryExpression = Expression.Equal(Expression.Property(Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(RoutingSeq).GetMethod("get_AssemblyLine").MethodHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(AssemblyLine).GetMethod("get_AssemLineId").MethodHandle)), Expression.Property(Expression.Field(Expression.Constant(this, typeof(clsEngineMES)), (FieldInfo)FieldInfo.GetFieldFromHandle(typeof(clsEngineMES).GetField("_AssemblyLine").FieldHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(scLevels).GetMethod("get_LevelId").MethodHandle)), true, null);
                //ParameterExpression[] parameterExpressionArray = new ParameterExpression[] { parameterExpression };
                //IQueryable<RoutingSeq> routingSeqs1 = routingSeqs.Where<RoutingSeq>(Expression.Lambda<Func<RoutingSeq, bool>>(binaryExpression, parameterExpressionArray));
                //ParameterExpression parameterExpression1 = Expression.Parameter(typeof(RoutingSeq), "rs");
                //ParameterExpression[] parameterExpressionArray1 = new ParameterExpression[] { parameterExpression1 };
                //IQueryable<RoutingSeq> qryRtSeq = routingSeqs1.Select<RoutingSeq, RoutingSeq>(Expression.Lambda<Func<RoutingSeq, RoutingSeq>>(parameterExpression1, parameterExpressionArray1));
                IQueryable<RoutingSeq> qryRtSeq = from rs in CTdB.RoutingSeqs
                                               where rs.AssemblyLine.AssemLineId == this._AssemblyLine.LevelId
                                               select rs;
				if (qryRtSeq != null)
				{
					if (qryRtSeq.Count<RoutingSeq>() > 0)
					{
						dlWCRtSeq = qryRtSeq.ToDictionary<RoutingSeq, string>((RoutingSeq r) => r.RtSeqWorkCenter);
						while (true)
						{
							item = strs[0];
							IEnumerable<scMESUpdateFull> qryShipWC = 
								from sq in OrderList
								where Microsoft.VisualBasic.CompilerServices.Operators.CompareString(sq.dt_eto_workctr, strs[0], false) == 0
								orderby sq.hd_sect_id
								select sq;
							if (qryShipWC != null)
							{
								if (qryShipWC.Count<scMESUpdateFull>() > 0)
								{
                                    //using (enumerator)
                                    //{
										enumerator = qryShipWC.GetEnumerator();
										while (enumerator.MoveNext())
										{
											scMESUpdateFull ldSect = enumerator.Current;
											ldSect.od_trgt_dt = ldSubTarget[ldSect.hd_sect_id];
											ldSect.RoutingProcessed = this.ScheduleWC(ref dlWCRtSeq, ref ldSect, OrdSER, ElecClpx, MechClpx, SectCnt);
										}
									//}
									this.SyncShipSplt(ref OrderList, item);
								}
							}
							if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(dlWCRtSeq[item].RtSeqSeries, SubSeq, false) == 0)
							{
								try
								{
									enumerator1 = qryShipWC.GetEnumerator();
									while (enumerator1.MoveNext())
									{
										scMESUpdateFull ldSect = enumerator1.Current;
										ldSubTarget[ldSect.hd_sect_id] = ldSect.due_st;
									}
								}
								finally
								{
									if (enumerator1 != null)
									{
										enumerator1.Dispose();
									}
								}
							}
							strs.Remove(item);

                            //ParameterExpression parameterExpression2 = Expression.Parameter(typeof(RoutingSeq), "rt");
                            //MethodInfo methodFromHandle = (MethodInfo)MethodBase.GetMethodFromHandle(typeof(Microsoft.VisualBasic.CompilerServices.Operators).GetMethod("CompareString", new Type[] { typeof(string), typeof(string), typeof(bool) }).MethodHandle);
                            //Expression[] expressionArray = new Expression[] { Expression.Property(parameterExpression2, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(RoutingSeq).GetMethod("get_RtSeqSeries").MethodHandle)), Expression.Field(Expression.Constant($VB$Closure_ClosureVariable_9D, typeof(clsEngineMES._Closure$__157)), (FieldInfo)FieldInfo.GetFieldFromHandle(typeof(clsEngineMES._Closure$__157).GetField("$VB$Local_SubSeq").FieldHandle)), Expression.Constant(false, typeof(bool)) };
                            //BinaryExpression binaryExpression1 = Expression.Equal(Expression.Call(null, methodFromHandle, expressionArray), Expression.Constant(0, typeof(int)));
                            //MethodInfo methodInfo = (MethodInfo)MethodBase.GetMethodFromHandle(typeof(Microsoft.VisualBasic.CompilerServices.Operators).GetMethod("CompareString", new Type[] { typeof(string), typeof(string), typeof(bool) }).MethodHandle);
                            //Expression[] expressionArray1 = new Expression[] { Expression.Property(parameterExpression2, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(RoutingSeq).GetMethod("get_RtSeqNextWorkCtr").MethodHandle)), Expression.Field(Expression.Constant($VB$Closure_ClosureVariable_9D, typeof(clsEngineMES._Closure$__157)), (FieldInfo)FieldInfo.GetFieldFromHandle(typeof(clsEngineMES._Closure$__157).GetField("$VB$Local_ldCurrentWC").FieldHandle)), Expression.Constant(false, typeof(bool)) };
                            //BinaryExpression binaryExpression2 = Expression.And(binaryExpression1, Expression.Equal(Expression.Call(null, methodInfo, expressionArray1), Expression.Constant(0, typeof(int))));
                            //ParameterExpression[] parameterExpressionArray2 = new ParameterExpression[] { parameterExpression2 };
                            //IQueryable<RoutingSeq> routingSeqs2 = qryRtSeq.Where<RoutingSeq>(Expression.Lambda<Func<RoutingSeq, bool>>(binaryExpression2, parameterExpressionArray2));
                            //ParameterExpression parameterExpression3 = Expression.Parameter(typeof(RoutingSeq), "rt");
                            //MemberExpression memberExpression = Expression.Property(parameterExpression3, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(RoutingSeq).GetMethod("get_RtSeqWorkCenter").MethodHandle));
                            //ParameterExpression[] parameterExpressionArray3 = new ParameterExpression[] { parameterExpression3 };
                            //IQueryable<string> qryNextWC = routingSeqs2.Select<RoutingSeq, string>(Expression.Lambda<Func<RoutingSeq, string>>(memberExpression, parameterExpressionArray3));

                            IQueryable<string> qryNextWC = from rt in qryRtSeq
                                                           where Microsoft.VisualBasic.CompilerServices.Operators.CompareString(rt.RtSeqSeries, SubSeq, false) == 0
                                                           && Microsoft.VisualBasic.CompilerServices.Operators.CompareString(rt.RtSeqNextWorkCtr, item, false) == 0
                                                           select rt.RtSeqWorkCenter;
							if (qryNextWC != null)
							{
								if (qryNextWC.Count<string>() > 0)
								{
									try
									{
										enumerator2 = qryNextWC.ToList<string>().GetEnumerator();
										while (enumerator2.MoveNext())
										{
											string ldWC = enumerator2.Current;
											if (!strs.Contains(ldWC))
											{
												strs.Add(ldWC);
											}
										}
									}
									finally
									{
										((IDisposable)enumerator2).Dispose();
									}
								}
								else if (strs.Count == 0)
								{
									return;
								}
								if (strs.Count == 0)
								{
									break;
								}
							}
						}
					}
				}
			}
		}

        public int LoadLabor(scMESUpdateFull RtStep)
        {
          // ISSUE: object of a compiler-generated type is created
          // ISSUE: variable of a compiler-generated type
          //clsEngineMES._Closure\u0024__138 closure138 = new clsEngineMES._Closure\u0024__138();
          // ISSUE: reference to a compiler-generated field
          //closure138.\u0024VB\u0024Local_RtStep = RtStep;
          int num = 0;
          using (SE0085CTEntities1 se0085CtEntities1 = new SE0085CTEntities1())
          {
            //se0085CtEntities1.Database.Connection.ConnectionString = this._CTConnection;
            //ParameterExpression parameterExpression;
        
            //IQueryable<Decimal?> source = (IQueryable<Decimal?>) Queryable.Select<SectLaborContentVw, Decimal?>(Queryable.Where<SectLaborContentVw>((IQueryable<M0>) se0085CtEntities1.SectLaborContentVws, (Expression<Func<M0, bool>>) Expression.Lambda<Func<SectLaborContentVw, bool>>((Expression) Expression.And((Expression) Expression.And(Expression.Call((Expression) null, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), l.OrderFO, closure138.\u0024VB\u0024Local_RtStep.hd_q2c_nbr, false) == 0 & Expression.Call((Expression) null, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), l.OrderLineNum, closure138.\u0024VB\u0024Local_RtStep.od_ln_dsply_seq_nbr, false) == 0 & Expression.Call((Expression) null, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), l.OrderLineSL, closure138.\u0024VB\u0024Local_RtStep.hd_sub_ln_itm_id, false) == 0 & Expression.Call((Expression) null, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), l.OrderLineSS, closure138.\u0024VB\u0024Local_RtStep.hd_orig_shpschd_id, false) == 0, (Expression) Expression.Equal(l.OrdSectsNum, closure138.\u0024VB\u0024Local_RtStep.hd_sect_id, true, (MethodInfo) null)), (Expression) Expression.Equal((Expression) Expression.Call((Expression) null, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), (Expression) Expression.Property((Expression) parameterExpression, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (SectLaborContentVw.get_GateMESWorkCtr))), (Expression) Expression.Property((Expression) Expression.Field((Expression) Expression.Constant((object) closure138, typeof (clsEngineMES._Closure\u0024__138)), FieldInfo.GetFieldFromHandle(__fieldref (clsEngineMES._Closure\u0024__138.\u0024VB\u0024Local_RtStep))), (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (scMESUpdateFull.get_dt_eto_workctr))), (Expression) Expression.Constant((object) false, typeof (bool))), (Expression) Expression.Constant((object) 0, typeof (int)))), new ParameterExpression[1]
            //{
            //  parameterExpression
            //})), (Expression<Func<M0, M1>>) (l => l.LaborHrs));

              IQueryable<Decimal?> source = from l in se0085CtEntities1.SectLaborContentVws
                                            where Microsoft.VisualBasic.CompilerServices.Operators.CompareString(l.OrderFO, RtStep.hd_q2c_nbr, false) == 0
                                            && Microsoft.VisualBasic.CompilerServices.Operators.CompareString(l.OrderLineNum, RtStep.od_ln_dsply_seq_nbr, false) == 0
                                            && Microsoft.VisualBasic.CompilerServices.Operators.CompareString(l.OrderLineSL, RtStep.hd_sub_ln_itm_id, false) == 0
                                            && Microsoft.VisualBasic.CompilerServices.Operators.CompareString(l.OrderLineSS, RtStep.hd_orig_shpschd_id, false) == 0
                                            && l.OrdSectsNum == RtStep.hd_sect_id
                                            select l.LaborHrs;
            if (source != null && source.Count<Decimal?>() > 0)
            {
              Decimal d2 = new Decimal(60L);
              Decimal? nullable = source.First<Decimal?>();
              num = Convert.ToInt32((Decimal) (nullable.HasValue ? new Decimal?(Decimal.Multiply(nullable.GetValueOrDefault(), d2)) : new Decimal?()));
            }
            se0085CtEntities1.Database.Connection.Close();
          }
          return num;
        }

        public scDateValidate ProcessWeekEndsHolidays(DateTime EndDate, DateTime StartDate)
        {
            scDateValidate scDateValidate = new scDateValidate();
            DateTime dateTime1 = EndDate;
            DateTime t2 = StartDate;
            int num1 = 0;
            DateTime date = dateTime1.AddDays((double)num1).Date;
            if (date.DayOfWeek == DayOfWeek.Saturday)
                checked { num1 += -1; }
            else if (date.DayOfWeek == DayOfWeek.Sunday)
                checked { num1 += -2; }
            DateTime dateTime2 = dateTime1.AddDays((double)num1);
            for (date = dateTime2.Date; this._dtHoliday.ContainsKey(date); date = dateTime2.Date)
            {
                scHolidays scHolidays = new scHolidays();
                scHolidays = this._dtHoliday[date];
                checked { num1 += -1; }
                dateTime2 = dateTime1.AddDays((double)num1);
                date = dateTime2.Date;
                if (date.DayOfWeek == DayOfWeek.Saturday)
                    checked { num1 += -1; }
                else if (date.DayOfWeek == DayOfWeek.Sunday)
                    checked { num1 += -2; }
                dateTime2 = dateTime1.AddDays((double)num1);
            }
            if (date.DayOfWeek == DayOfWeek.Saturday)
                checked { num1 += -1; }
            else if (date.DayOfWeek == DayOfWeek.Sunday)
                checked { num1 += -2; }
            DateTime dateTime3 = dateTime1.AddDays((double)num1);
            t2 = t2.AddDays((double)num1);
            int num2 = 0;
            dateTime2 = dateTime3.AddDays((double)num2);
            date = dateTime2.Date;
            while (DateTime.Compare(date, t2) >= 0)
            {
                dateTime2 = dateTime3.AddDays((double)num2);
                date = dateTime2.Date;
                if (date.DayOfWeek == DayOfWeek.Saturday)
                {
                    t2 = t2.AddDays(-1.0);
                    checked { num2 += -1; }
                }
                else if (date.DayOfWeek == DayOfWeek.Sunday)
                {
                    t2 = t2.AddDays(-2.0);
                    checked { num2 += -2; }
                }
                dateTime2 = dateTime3.AddDays((double)num2);
                for (date = dateTime2.Date; this._dtHoliday.ContainsKey(date); date = dateTime2.Date)
                {
                    scHolidays scHolidays = new scHolidays();
                    scHolidays = this._dtHoliday[date];
                    t2 = t2.AddDays(-1.0);
                    checked { num2 += -1; }
                    dateTime2 = dateTime3.AddDays((double)num2);
                    date = dateTime2.Date;
                    if (date.DayOfWeek == DayOfWeek.Saturday)
                    {
                        t2 = t2.AddDays(-1.0);
                        checked { num2 += -1; }
                    }
                    else if (date.DayOfWeek == DayOfWeek.Sunday)
                    {
                        t2 = t2.AddDays(-2.0);
                        checked { num2 += -2; }
                    }
                    dateTime2 = dateTime3.AddDays((double)num2);
                }
                if (date.DayOfWeek == DayOfWeek.Saturday)
                {
                    t2 = t2.AddDays(-1.0);
                    checked { num2 += -1; }
                }
                else if (date.DayOfWeek == DayOfWeek.Sunday)
                {
                    t2 = t2.AddDays(-2.0);
                    checked { num2 += -2; }
                }
                else
                    checked { num2 += -1; }
            }
            scDateValidate.EndDate = dateTime3;
            scDateValidate.StartDate = t2;
            return scDateValidate;
        }

        public scMESTableStatus[] StatusMES_o_l_rLOJ(string FactoryOrder, string LineItem, string SLNumber, string SSNumber)
        {
            // ISSUE: object of a compiler-generated type is created
            // ISSUE: variable of a compiler-generated type
            //clsEngineMES closure147 = new clsEngineMES();
            // ISSUE: reference to a compiler-generated field
            //closure147.SSNumber = SSNumber;
            // ISSUE: reference to a compiler-generated field
            //closure147.FactoryOrder = FactoryOrder;
            // ISSUE: reference to a compiler-generated field
            //closure147.LineItem = LineItem;
            // ISSUE: reference to a compiler-generated field
            //closure147.SLNumber = SLNumber;
            using (SE0085CTEntities1 se0085CtEntities1 = new SE0085CTEntities1())
            {
                //se0085CtEntities1.Database.Connection.ConnectionString = this._CTConnection;
                //ParameterExpression parameterExpression;
                // ISSUE: method reference
                //IQueryable<scMESTableStatus> source = (IQueryable<scMESTableStatus>)Queryable.Select((IQueryable<M0>)Queryable.ThenBy(Queryable.ThenBy(Queryable.ThenBy(Queryable.ThenBy(Queryable.ThenBy(Queryable.OrderBy(Queryable.Where((IQueryable<M0>)Queryable.GroupJoin((IQueryable<M0>)Queryable.Join((IQueryable<M0>)Queryable.Join((IQueryable<M0>)se0085CtEntities1.SEOrders, (IEnumerable<M1>)se0085CtEntities1.OrderLines, (Expression<Func<M0, M2>>)(o => o.OrderId), (Expression<Func<M1, M2>>)(l => l.SEOrder.OrderId), (Expression<Func<M0, M1, M3>>)((o, l) => new { o = o, l = l })), (IEnumerable<M1>)se0085CtEntities1.OrdSections, (Expression<Func<M0, M2>>)(data => data.l.OrderLineId), (Expression<Func<M1, M2>>)(s => s.OrderLine.OrderLineId), (Expression<Func<M0, M1, M3>>)((data, s) => new
                //{
                //    It1 = data,
                //    s = s
                //})), (IEnumerable<M1>)se0085CtEntities1.SectionsRoutings, (Expression<Func<M0, M2>>)(data => data.s.OrdSectsId), (Expression<Func<M1, M2>>)(r => r.OrdSection.OrdSectsId), (Expression<Func<M0, IEnumerable<M1>, M3>>)((data, sectionsRoutings) => new
                //{
                //    o = data.It1.o,
                //    l = data.It1.l,
                //    s = data.s,
                //    rt = sectionsRoutings
                //})), (Expression<Func<M0, bool>>)(data => Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), data.o.OrderFO, closure147.FactoryOrder, false) == 0 & Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), data.l.OrderLineNum, closure147.LineItem, false) == 0 & Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), data.l.OrderLineSL, closure147.SLNumber, false) == 0 & Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), data.l.OrderLineSS, closure147.SSNumber, false) == 0)), (Expression<Func<M0, M1>>)(data => data.o.OrderFO)), (Expression<Func<M0, M1>>)(data => data.l.OrderLineNum)), (Expression<Func<M0, M1>>)(data => data.l.OrderLineSS)), (Expression<Func<M0, M1>>)(data => data.l.OrderLineSL)), (Expression<Func<M0, M1>>)(data => data.s.OrdSectsNum)), (Expression<Func<M0, M1>>)(data => data.s.OrdSectsProdNum)), (Expression<Func<M0, M1>>)Expression.Lambda<Func<AnonymousType_60<SEOrder, OrderLine, OrdSection, IEnumerable<SectionsRouting>>, scMESTableStatus>>((Expression)Expression.MemberInit(Expression.New((ConstructorInfo)MethodBase.GetMethodFromHandle(__methodref(scMESTableStatus.Ector)), (Expression[])null), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scMESTableStatus.set_OrderId)), (Expression)Expression.Property((Expression)Expression.Property((Expression)parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(AnonymousType_60<SEOrder, OrderLine, OrdSection, IEnumerable<SectionsRouting>>.get_o), __typeref(AnonymousType_60<SEOrder, OrderLine, OrdSection, IEnumerable<SectionsRouting>>))), (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SEOrder.get_OrderId)))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scMESTableStatus.set_OrderLineId)), (Expression)Expression.Property((Expression)Expression.Property((Expression)parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(AnonymousType_60<SEOrder, OrderLine, OrdSection, IEnumerable<SectionsRouting>>.get_l), __typeref(AnonymousType_60<SEOrder, OrderLine, OrdSection, IEnumerable<SectionsRouting>>))), (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(OrderLine.get_OrderLineId)))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scMESTableStatus.set_OrdSectsId)), (Expression)Expression.Property((Expression)Expression.Property((Expression)parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(AnonymousType_60<SEOrder, OrderLine, OrdSection, IEnumerable<SectionsRouting>>.get_s), __typeref(AnonymousType_60<SEOrder, OrderLine, OrdSection, IEnumerable<SectionsRouting>>))), (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(OrdSection.get_OrdSectsId)))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scMESTableStatus.set_OrdSecRoutingCount)), (Expression)Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Enumerable.Count)), new Expression[1]
                //{
                //  (Expression) Expression.Property((Expression) parameterExpression, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (AnonymousType_60<SEOrder, OrderLine, OrdSection, IEnumerable<SectionsRouting>>.get_rt), __typeref (AnonymousType_60<SEOrder, OrderLine, OrdSection, IEnumerable<SectionsRouting>>)))
                //}))), new ParameterExpression[1]
                //{
                //  parameterExpression
                //}));

                //DOUBT QUERY

                //IQueryable<scMESTableStatus> source = (from o in se0085CtEntities1.SEOrders
                //                                       join l in se0085CtEntities1.OrderLines
                //                                       on o.OrderId equals l.SEOrder.OrderId
                //                                       join s in se0085CtEntities1.OrdSections
                //                                       on l.OrderLineId equals s.OrderLine.OrderLineId
                //                                       join r in se0085CtEntities1.SectionsRoutings
                //                                       on s.OrdSectsId equals r.OrdSection.OrdSectsId
                //                                       where o.OrderFO == FactoryOrder
                //                                       & l.OrderLineNum == LineItem
                //                                       & l.OrderLineSL == SLNumber
                //                                       & l.OrderLineSS == SSNumber
                //                                       orderby o.OrderFO, l.OrderLineNum, l.OrderLineSS, l.OrderLineSL, s.OrdSectsNum, s.OrdSectsProdNum
                //                                       select new scMESTableStatus
                //                                       {
                //                                           OrderId = o.OrderId,
                //                                           OrderLineId = l.OrderLineId,
                //                                           OrdSectsId = s.OrdSectsId
                //                                           //OrdSecRoutingCount = Enumerable.Count()
                //                                       }).AsQueryable<scMESTableStatus>();

                IQueryable<scMESTableStatus> source = (from o in se0085CtEntities1.SEOrders
                                                       join l in se0085CtEntities1.OrderLines
                                                       on o.OrderId equals l.SEOrder.OrderId into OrderLinesGroup
                                                       from ol in OrderLinesGroup.DefaultIfEmpty()
                                                       join s in se0085CtEntities1.OrdSections
                                                       on ol.OrderLineId equals s.OrderLine.OrderLineId into OrdSectionGroup
                                                       from os in OrdSectionGroup.DefaultIfEmpty()
                                                       join r in se0085CtEntities1.SectionsRoutings
                                                       on os.OrdSectsId equals r.OrdSection.OrdSectsId into SectionRoutingGroup
                                                       from srg in SectionRoutingGroup.DefaultIfEmpty()
                                                       where o.OrderFO == FactoryOrder
                                                       & ol.OrderLineNum == LineItem
                                                       & ol.OrderLineSL == SLNumber
                                                       & ol.OrderLineSS == SSNumber
                                                       orderby o.OrderFO, ol.OrderLineNum, ol.OrderLineSS, ol.OrderLineSL, os.OrdSectsNum, os.OrdSectsProdNum
                                                       select new scMESTableStatus
                                                       {
                                                           OrderId = o.OrderId,
                                                           OrderLineId = ol.OrderLineId,
                                                           OrdSectsId = os.OrdSectsId == null ? 0 : os.OrdSectsId,
                                                           OrdSecRoutingCount = SectionRoutingGroup.Count()
                                                       }).AsQueryable<scMESTableStatus>();

                if (source.Count<scMESTableStatus>() > 0)
                    return source.ToArray<scMESTableStatus>();
                return (scMESTableStatus[])null;
            }
        }

        
        public void AddMESSections(ArrayList MesExtractData, ArrayList MESSectionList)
        {
            IEnumerator enumerator = null;
            ArrayList ldMESData = new ArrayList();
            try
            {
                enumerator = MESSectionList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    int ordSectsNum = ((scOrdSectionsInfo)enumerator.Current).OrdSectsNum;
                    IEnumerable<scMESOrderInfo> ldSectionQuery =
                        from object m in MesExtractData
                        select (scMESOrderInfo)m into m
                        where m.OrdSectsNum == ordSectsNum
                        select m;
                    if (ldSectionQuery.Count<scMESOrderInfo>() > 0)
                    {
                        ldMESData.Clear();
                        ldMESData.AddRange(ldSectionQuery.ToArray<scMESOrderInfo>());
                        this.InsertMESLines(ldMESData);
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }

        public void InsertMESLines(ArrayList scMesOrders)
        {
            //BELOW 2 LINES ARE COMMENTED OUT DUE TO CONDITION FAIL EVERYTIME
            //if (DateTime.Compare(DateTime.Today, Conversions.ToDate("08/08/2016")) > 0)
            //    return;
            scMESOrderInfo ldMESOrder = new scMESOrderInfo();
            ldMESOrder = (scMESOrderInfo)scMesOrders[0];
            using (SE0085CTEntities1 se0085CtEntities1 = new SE0085CTEntities1())
            {
                // ISSUE: object of a compiler-generated type is created
                // ISSUE: variable of a compiler-generated type
                //clsEngineMES closure150 = new clsEngineMES();
                //se0085CtEntities1.Database.Connection.ConnectionString = this._CTConnection;
                //ParameterExpression parameterExpression;
                // ISSUE: reference to a compiler-generated field
                //IQueryable<AssemblyLine> source1 = (IQueryable<AssemblyLine>)Queryable.Select(Queryable.Where((IQueryable<M0>)Queryable.Join((IQueryable<M0>)se0085CtEntities1.SEPlants, (IEnumerable<M1>)se0085CtEntities1.AssemblyLines, (Expression<Func<M0, M2>>)(p => p.SEPlantId), (Expression<Func<M1, M2>>)(a => a.SEPlant.SEPlantId), (Expression<Func<M0, M1, M3>>)((p, a) => new { p = p, a = a })), (Expression<Func<M0, bool>>)Expression.Lambda<Func<AnonymousType_5<SEPlant, AssemblyLine>, bool>>((Expression)Expression.Equal(It.a.AssemLineId, closure149.ldMESOrder.AssemblyLineId, true, (MethodInfo)null), new ParameterExpression[1]
                //{
                //  parameterExpression
                //})), (Expression<Func<M0, M1>>)(data => data.a));
                IQueryable<AssemblyLine> source1 = (from p in se0085CtEntities1.SEPlants
                                                    join a in se0085CtEntities1.AssemblyLines
                                                    on p.SEPlantId equals a.SEPlant.SEPlantId
                                                    where a.AssemLineId == 1//ldMESOrder.AssemblyLineId
                                                    select a).AsQueryable<AssemblyLine>();

                if (source1.Count<AssemblyLine>() == 0)
                {
                    this.lcLogWriter.logData("Error loading Assembly Line data, aborting MES import for AssemblyLineId; " + Conversions.ToString(ldMESOrder.AssemblyLineId));
                }
                else if (source1.Count<AssemblyLine>() == 1)
                {
                    AssemblyLine assemblyLine;
                    try
                    {
                        assemblyLine = source1.First<AssemblyLine>();
                    }
                    catch (Exception ex)
                    {
                        ProjectData.SetProjectError(ex);
                        this.lcLogWriter.logData("Error loading Assembly Line data, aborting MES import for AssemblyLineId; " + Conversions.ToString(ldMESOrder.AssemblyLineId));
                        ProjectData.ClearProjectError();
                        return;
                    }
                    //IQueryable<SEOrder> source2 = (IQueryable<SEOrder>)Queryable.Select<SEOrder, SEOrder>(Queryable.Where<SEOrder>((IQueryable<M0>)se0085CtEntities1.SEOrders, (Expression<Func<M0, bool>>)(o => Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), o.OrderFO, closure149.ldMESOrder.OrderFO, false) == 0)), (Expression<Func<M0, M1>>)(o => o));
                    IQueryable<SEOrder> source2 = (from o in se0085CtEntities1.SEOrders
                                                  where string.Equals(o.OrderFO, ldMESOrder.OrderFO)
                                                  select o).AsQueryable<SEOrder>();
                    SEOrder entity;
                    if (source2.Count<SEOrder>() == 0)
                    {
                        entity = new SEOrder();
                        entity.OrderFO = ldMESOrder.OrderFO;
                        se0085CtEntities1.SEOrders.Add(entity);
                    }
                    else if (source2.Count<SEOrder>() == 1)
                    {
                        try
                        {
                            entity = source2.First<SEOrder>();
                        }
                        catch (Exception ex)
                        {
                            ProjectData.SetProjectError(ex);
                            this.lcLogWriter.logData("Error loading MES Order data, aborting MES import for Order; " + ldMESOrder.OrderFO);
                            ProjectData.ClearProjectError();
                            return;
                        }
                    }
                    else
                    {
                        this.lcLogWriter.logData("Multiple Order numbers found, aborting MES import for Order; " + ldMESOrder.OrderFO);
                        return;
                    }
                    OrderLine orderLine = (OrderLine)null;
                    //IQueryable<OrderLine> source3 = (IQueryable<OrderLine>)Queryable.Select(Queryable.Where((IQueryable<M0>)Queryable.Join((IQueryable<M0>)se0085CtEntities1.SEOrders, (IEnumerable<M1>)se0085CtEntities1.OrderLines, (Expression<Func<M0, M2>>)(o => o.OrderId), (Expression<Func<M1, M2>>)(l => l.SEOrder.OrderId), (Expression<Func<M0, M1, M3>>)((o, l) => new { o = o, l = l })), (Expression<Func<M0, bool>>)(data => Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), data.o.OrderFO, closure149.ldMESOrder.OrderFO, false) == 0 & Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), data.l.OrderLineNum, closure149.ldMESOrder.OrderLineNum, false) == 0 & Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), data.l.OrderLineSL, closure149.ldMESOrder.OrderLineSL, false) == 0 & Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), data.l.OrderLineSS, closure149.ldMESOrder.OrderLineSS, false) == 0)), (Expression<Func<M0, M1>>)(data => data.l));
                    IQueryable<OrderLine> source3 = (from o in se0085CtEntities1.SEOrders
                                                    join l in se0085CtEntities1.OrderLines
                                                    on o.OrderId equals l.SEOrder.OrderId
                                                    where string.Equals(o.OrderFO, ldMESOrder.OrderFO)
                                                    & string.Equals(l.OrderLineNum, ldMESOrder.OrderLineNum)
                                                    & string.Equals(l.OrderLineSL, ldMESOrder.OrderLineSL)
                                                    & string.Equals(l.OrderLineSS, ldMESOrder.OrderLineSS)
                                                    select l).AsQueryable<OrderLine>();
                    if (source3.Count<OrderLine>() == 0)
                    {
                        orderLine = new OrderLine();
                        orderLine.OrderLineNum = ldMESOrder.OrderLineNum;
                        orderLine.OrderLineQty = (int?)ldMESOrder.OrderLineQty;
                        orderLine.OrderLineShipDt = (DateTime?)ldMESOrder.OrderLineShipDt;
                        orderLine.OrderLineShipped = (bool?)((uint)ldMESOrder.OrderLineShipped > 0U);
                        orderLine.OrderLineShippedDt = (DateTime?)ldMESOrder.OrderLineShippedDt;
                        orderLine.OrderLineSL = ldMESOrder.OrderLineSL;
                        orderLine.OrderLineSS = ldMESOrder.OrderLineSS;
                        orderLine.OrderLineTargetDt = (DateTime?)ldMESOrder.OrderLineTargetDt;
                        entity.OrderLines.Add(orderLine);
                        assemblyLine.OrderLines.Add(orderLine);
                        this.lcLogWriter.logData("Added Line " + orderLine.SEOrder.OrderFO + "-" + orderLine.OrderLineNum + "-" + orderLine.OrderLineSL + "-" + orderLine.OrderLineSS);
                    }
                    else if (source3.Count<OrderLine>() == 1)
                    {
                        try
                        {
                            orderLine = source3.First<OrderLine>();
                        }
                        catch (Exception ex)
                        {
                            ProjectData.SetProjectError(ex);
                            this.lcLogWriter.logData("Error importing data, aborting MES import for Order; " + ldMESOrder.OrderFO);
                            ProjectData.ClearProjectError();
                        }
                    }
                    else
                    {
                        this.lcLogWriter.logData("Multiple Order numbers found, aborting MES import for Order; " + ldMESOrder.OrderFO);
                    }
                    OrdSection ordSection = (OrdSection)null;
                    string ProdOrderMem = ldMESOrder.OrdSectsProdNum;
                    //IQueryable<OrdSection> source4 = (IQueryable<OrdSection>)Queryable.Select<OrdSection, OrdSection>(Queryable.Where<OrdSection>((IQueryable<M0>)se0085CtEntities1.OrdSections, (Expression<Func<M0, bool>>)(s => Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), s.OrdSectsProdNum, closure149.ldMESOrder.OrdSectsProdNum, false) == 0)), (Expression<Func<M0, M1>>)(s => s));
                    IQueryable<OrdSection> source4 = (from s in se0085CtEntities1.OrdSections
                                                     where s.OrdSectsProdNum == ldMESOrder.OrdSectsProdNum
                                                     select s).AsQueryable<OrdSection>();
                    if (source4.Count<OrdSection>() == 0)
                    {
                        ordSection = new OrdSection();
                        ordSection.OrdSectsCryptRt = Microsoft.VisualBasic.Strings.Left(ldMESOrder.OrdSectsCryptRt, 15);
                        ordSection.OrdSectsCurrWorkCtr = ldMESOrder.OrdSectsCurrWorkCtr;
                        ordSection.OrdSectShipSpt = (int?)ldMESOrder.OrdShipSplt;
                        ordSection.OrdSectsNum = ldMESOrder.OrdSectsNum;
                        ordSection.OrdSectsProdNum = ldMESOrder.OrdSectsProdNum;
                        ordSection.OrdSectsRelMfg = (DateTime?)Conversions.ToDate("01/01/1901");
                        ordSection.OrdSectsFabSchDt = (DateTime?)Conversions.ToDate("01/01/1901");
                        ordSection.OrdSectsFabActDt = (DateTime?)Conversions.ToDate("01/01/1901");
                        ordSection.OrdSectsRelSchDt = (DateTime?)Conversions.ToDate("01/01/1901");
                        ordSection.OrdSectsRelActDt = (DateTime?)Conversions.ToDate("01/01/1901");
                        orderLine.OrdSections.Add(ordSection);
                       this.lcLogWriter.logData("Added Section " + ordSection.OrdSectsProdNum);
                    }
                    else if (source4.Count<OrdSection>() == 1)
                    {
                        try
                        {
                            ordSection = source4.First<OrdSection>();
                        }
                        catch (Exception ex)
                        {
                            ProjectData.SetProjectError(ex);
                            this.lcLogWriter.logData("Error importing data, aborting MES import for Production Order; " + ldMESOrder.OrdSectsProdNum);
                            ProjectData.ClearProjectError();
                        }
                    }
                    else
                    {
                        this.lcLogWriter.logData("Multiple Order numbers found, aborting MES import for Production Order; " + ldMESOrder.OrdSectsProdNum);
                    }

                    ProdOrderMem = "Initialize";
                    try
                    {
                        foreach (scMESOrderInfo scMesOrder in scMesOrders)
                        {
                            if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ProdOrderMem, scMesOrder.OrdSectsProdNum, false) != 0)
                            {
                                if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ProdOrderMem, "Initialize", false) == 0)
                                {
                                    ProdOrderMem = scMesOrder.OrdSectsProdNum;
                                }
                                else
                                {
                                    se0085CtEntities1.SaveChanges();
                                    ProdOrderMem = scMesOrder.OrdSectsProdNum;
                                    //IQueryable<OrdSection> source5 = (IQueryable<OrdSection>)Queryable.Select<OrdSection, OrdSection>(Queryable.Where<OrdSection>((IQueryable<M0>)se0085CtEntities1.OrdSections, (Expression<Func<M0, bool>>)(s => Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), s.OrdSectsProdNum, closure150.ProdOrderMem, false) == 0)), (Expression<Func<M0, M1>>)(s => s));
                                    IQueryable<OrdSection> source5 = from s in se0085CtEntities1.OrdSections
                                                                     where s.OrdSectsProdNum == ProdOrderMem
                                                                     select s;
                                    if (source5.Count<OrdSection>() == 0)
                                    {
                                        ordSection = new OrdSection();
                                        ordSection.OrdSectsCryptRt = Microsoft.VisualBasic.Strings.Left(scMesOrder.OrdSectsCryptRt, 15);
                                        ordSection.OrdSectsCurrWorkCtr = scMesOrder.OrdSectsCurrWorkCtr;
                                        ordSection.OrdSectShipSpt = (int?)scMesOrder.OrdShipSplt;
                                        ordSection.OrdSectsNum = scMesOrder.OrdSectsNum;
                                        ordSection.OrdSectsProdNum = scMesOrder.OrdSectsProdNum;
                                        ordSection.OrdSectsRelMfg = (DateTime?)Conversions.ToDate("01/01/1901");
                                        ordSection.OrdSectsFabSchDt = (DateTime?)Conversions.ToDate("01/01/1901");
                                        ordSection.OrdSectsFabActDt = (DateTime?)Conversions.ToDate("01/01/1901");
                                        ordSection.OrdSectsRelSchDt = (DateTime?)Conversions.ToDate("01/01/1901");
                                        ordSection.OrdSectsRelActDt = (DateTime?)Conversions.ToDate("01/01/1901");
                                        orderLine.OrdSections.Add(ordSection);
                                        this.lcLogWriter.logData("Added Section " + ordSection.OrdSectsProdNum);
                                    }
                                    else if (source5.Count<OrdSection>() == 1)
                                    {
                                        try
                                        {
                                            ordSection = source5.First<OrdSection>();
                                        }
                                        catch (Exception ex)
                                        {
                                            ProjectData.SetProjectError(ex);
                                            this.lcLogWriter.logData("Error importing data, aborting MES import for Production Order; " + ldMESOrder.OrdSectsProdNum);
                                            ProjectData.ClearProjectError();
                                        }
                                    }
                                    else
                                    {
                                        this.lcLogWriter.logData("Multiple Order numbers found, aborting MES import for Production Order; " + ldMESOrder.OrdSectsProdNum);
                                    }
                                }
                            }
                            ordSection.SectionsRoutings.Add(new SectionsRouting()
                            {
                                RoutingActFinishDt = (DateTime?)scMesOrder.RoutingActFinishDt,
                                RoutingActStartDt = (DateTime?)scMesOrder.RoutingActStartDt,
                                RoutingNextWorkCtr = scMesOrder.RoutingNextWorkCtr,
                                RoutingRunTimeMin = (int?)scMesOrder.RoutingRunTimeMin,
                                RoutingSchFinishDt = (DateTime?)scMesOrder.RoutingSchFinishDt,
                                RoutingSchStartDt = (DateTime?)scMesOrder.RoutingSchStartDt,
                                RoutingWorkCenter = scMesOrder.RoutingWorkCenter,
                                RoutingStatusCD = scMesOrder.RoutingStatusCD,
                                RoutingQueuedDt = (DateTime?)Conversions.ToDate("01/01/1901")
                            });
                        }
                    }
                    finally
                    {
                        //IEnumerator enumerator;
                        //if (enumerator is IDisposable)
                        //    (enumerator as IDisposable).Dispose();
                    }
                    se0085CtEntities1.SaveChanges();
                    se0085CtEntities1.Database.Connection.Close();
                }
                else
                {
                    this.lcLogWriter.logData("Error loading Assembly Line data, aborting MES import for AssemblyLineId; " + Conversions.ToString(ldMESOrder.AssemblyLineId));
                }
            }
        }

        public bool dBDeleteDataBySectionId(int SectionId, bool delSection = false, bool delRouting = false, bool delVouchers = false)
        {            
            // ISSUE: object of a compiler-generated type is created
            // ISSUE: variable of a compiler-generated type
            //clsEngineMES._Closure4__154 closure154 = new clsEngineMES._Closure4__154();
            // ISSUE: reference to a compiler-generated field
            //closure154.SectionId = SectionId;
            int num = 0;
            bool flag1;
            if (delSection)
            {
                delRouting = true;
                delVouchers = true;
            }
            else if (delRouting)
                delVouchers = true;
            else if (!delVouchers)
            {
                flag1 = false;
                goto label_63;
            }
            if (delSection & !delRouting & !delVouchers)
            {
                this.lcLogWriter.logData("Requested Delete SectionId " + Conversions.ToString(SectionId));
            }
            else if (delSection & delRouting & !delVouchers)
            {
                this.lcLogWriter.logData("Requested Delete SectionId plus routing " + Conversions.ToString(SectionId));
            }
            else if (delSection & delRouting & delVouchers)
            {
                this.lcLogWriter.logData("Requested Delete SectionId plus routing and labor " + Conversions.ToString(SectionId));
            }
            else if (!delSection & !delRouting & !delVouchers)
            {
                this.lcLogWriter.logData("Requested Delete SectionId " + Conversions.ToString(SectionId) + " but type was not specified");
            }
            using (SE0085CTEntities1 se0085CtEntities1 = new SE0085CTEntities1())
            {
                //se0085CtEntities1.Database.Connection.ConnectionString = this._CTConnection;
                //ParameterExpression parameterExpression1;
                // ISSUE: reference to a compiler-generated field
                //IQueryable<AnonymousType_64<OrdSection, SectionsRouting, IEnumerable<LaborVoucher>>> source1 = Queryable.Select(Queryable.Where((IQueryable<M0>)Queryable.GroupJoin((IQueryable<M0>)Queryable.Join((IQueryable<M0>)se0085CtEntities1.OrdSections, (IEnumerable<M1>)se0085CtEntities1.SectionsRoutings, (Expression<Func<M0, M2>>)(s => s.OrdSectsId), (Expression<Func<M1, M2>>)(r => r.OrdSection.OrdSectsId), (Expression<Func<M0, M1, M3>>)((s, r) => new { s = s, r = r })), (IEnumerable<M1>)se0085CtEntities1.LaborVouchers, (Expression<Func<M0, M2>>)(data => data.r.RoutingId), (Expression<Func<M1, M2>>)(v => v.SectionsRouting.RoutingId), (Expression<Func<M0, IEnumerable<M1>, M3>>)((data, laborVouchers) => new
                //{
                //    s = data.s,
                //    r = data.r,
                //    vt = laborVouchers
                //})), (Expression<Func<M0, bool>>)Expression.Lambda<Func<AnonymousType_64<OrdSection, SectionsRouting, IEnumerable<LaborVoucher>>, bool>>((Expression)Expression.Equal(It.s.OrdSectsId, closure154.SectionId, true, (MethodInfo)null), new ParameterExpression[1]
                //{
                //  parameterExpression1
                //})), (Expression<Func<M0, M1>>)(data => new
                //{
                //    s = data.s,
                //    r = data.r,
                //    vt = data.vt
                //}));

                //GROUP JOIN
                IQueryable<scRoutingLabour> source1 = from s in se0085CtEntities1.OrdSections
                                                      join r in se0085CtEntities1.SectionsRoutings
                                                      on s.OrdSectsId equals r.OrdSection.OrdSectsId into RoutingGroup
                                                      from rg in RoutingGroup.DefaultIfEmpty()
                                                      join l in se0085CtEntities1.LaborVouchers
                                                      on rg.RoutingId equals l.SectionsRouting.RoutingId into LabourGroup
                                                      from lg in LabourGroup.DefaultIfEmpty()
                                                      where s.OrdSectsId == SectionId
                                                      select new scRoutingLabour
                                                      {
                                                          ordSection = s,
                                                          sectionRouting = rg,
                                                          labourVoucher = lg
                                                      };

                //IQueryable<scRoutingLabour> source1 = from s in se0085CtEntities1.OrdSections
                //                                      join r in se0085CtEntities1.SectionsRoutings
                //                                      on s.OrdSectsId equals r.OrdSection.OrdSectsId
                //                                      join l in se0085CtEntities1.LaborVouchers
                //                                      on r.RoutingId equals l.SectionsRouting.RoutingId
                //                                      where s.OrdSectsId == SectionId
                //                                      select new scRoutingLabour
                //                                      {
                //                                          ordSection = s,
                //                                          sectionRouting = r,
                //                                          labourVoucher = l
                //                                      };

                bool flag2 = false;
                //IEnumerator<AnonymousType_64<OrdSection, SectionsRouting, IEnumerable<LaborVoucher>>> enumerator1;
                IEnumerator<scRoutingLabour> enumerator1;

                if (source1.Count() == 0)
                {
                    //ParameterExpression parameterExpression2;
                    // ISSUE: reference to a compiler-generated field
                    //IQueryable<OrdSection> source2 = (IQueryable<OrdSection>)Queryable.Select<OrdSection, OrdSection>(Queryable.Where<OrdSection>((IQueryable<M0>)se0085CtEntities1.OrdSections, (Expression<Func<M0, bool>>)Expression.Lambda<Func<OrdSection, bool>>((Expression)Expression.Equal(s.OrdSectsId, closure154.SectionId, true, (MethodInfo)null), new ParameterExpression[1]
                    //{
                    //parameterExpression2
                    //})), (Expression<Func<M0, M1>>)(s => s));
                    IQueryable<OrdSection> source2 = (from s in se0085CtEntities1.OrdSections
                                                      where s.OrdSectsId == SectionId
                                                      select s).AsQueryable<OrdSection>();
                    IEnumerator<OrdSection> enumerator2;
                    if (delSection)
                    {
                        if (source2.Count<OrdSection>() != 0)
                        {
                            enumerator2 = source2.GetEnumerator();
                            try
                            {
                                while (enumerator2.MoveNext())
                                {
                                    OrdSection current = enumerator2.Current;
                                    try
                                    {
                                        se0085CtEntities1.OrdSections.Remove(current);
                                        flag2 = true;
                                    }
                                    catch (Exception ex)
                                    {
                                        ProjectData.SetProjectError(ex);
                                        flag1 = false;
                                        ProjectData.ClearProjectError();
                                        goto label_63;
                                    }
                                }
                            }
                            finally
                            {
                                if (enumerator2 != null)
                                    enumerator2.Dispose();
                            }
                        }
                    }
                }
                else
                {
                    enumerator1 = source1.GetEnumerator();
                    try
                    {
                        while (enumerator1.MoveNext())
                        {
                            var current1 = enumerator1.Current;
                            if (delVouchers)
                            {
                                if (current1.labourVoucher != null)
                                {
                                    try
                                    {
                                        // IEnumerator<LaborVoucher> enumerator2;
                                        LaborVoucher enumerator2;
                                        try
                                        {
                                            enumerator2 = current1.labourVoucher;//.vt.GetEnumerator();
                                            //while (enumerator2.MoveNext())
                                            //{
                                            LaborVoucher current2 = enumerator2;//.Current;
                                            se0085CtEntities1.LaborVouchers.Remove(current2);
                                            flag2 = true;
                                            //}
                                        }
                                        finally
                                        {
                                            //if (enumerator2 != null)
                                            //    enumerator2.Dispose();
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        ProjectData.SetProjectError(ex);
                                        flag1 = false;
                                        ProjectData.ClearProjectError();
                                        goto label_63;
                                    }
                                }
                            }
                            if (delRouting)
                            {
                                if (current1.sectionRouting != null)
                                {
                                    try
                                    {
                                        se0085CtEntities1.SectionsRoutings.Remove(current1.sectionRouting);
                                        flag2 = true;
                                    }
                                    catch (Exception ex)
                                    {
                                        ProjectData.SetProjectError(ex);
                                        flag1 = false;
                                        ProjectData.ClearProjectError();
                                        goto label_63;
                                    }
                                }
                            }
                            if (delSection)
                            {
                                if (current1.ordSection != null)
                                {
                                    try
                                    {
                                        se0085CtEntities1.OrdSections.Remove(current1.ordSection);
                                        flag2 = true;
                                    }
                                    catch (Exception ex)
                                    {
                                        ProjectData.SetProjectError(ex);
                                        flag1 = false;
                                        ProjectData.ClearProjectError();
                                        goto label_63;
                                    }
                                }
                            }
                        }
                    }
                    finally
                    {
                        if (enumerator1 != null)
                            enumerator1.Dispose();
                    }
                }
                if (flag2)
                {
                    try
                    {
                        num = se0085CtEntities1.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        ProjectData.SetProjectError(ex);
                        Exception exception = ex;
                        this.lcLogWriter.logData("Section Delete Failed! " + Conversions.ToString(SectionId) + " Error; " + exception.Message);
                        ProjectData.ClearProjectError();
                    }
                }
                se0085CtEntities1.Database.Connection.Close();
            }
            flag1 = num > 0;
        label_63:
            return flag1;
        }

        public bool UpdateMES_o_l_s_r(ArrayList MESExtractData)
		{
            //clsEngineMES._Closure$__143 $VB$Closure_ClosureVariable_8F = null;
            //clsEngineMES._Closure$__143._Closure$__144 $VB$Closure_ClosureVariable_90 = null;
            //clsEngineMES._Closure$__143._Closure$__144._Closure$__145 $VB$Closure_ClosureVariable_91 = null;
			IEnumerator<OrderLine> enumerator = null;
			IEnumerator enumerator1 = null;
			IEnumerator<OrdSection> enumerator2 = null;
			IEnumerator enumerator3 = null;
			IEnumerator<SectionsRouting> enumerator4 = null;
			IEnumerator<scSectionsRoutingInfo> enumerator5 = null;
			bool? nullable;
			bool? nullable1;
			bool? nullable2;
			bool? nullable3;
			int? orderLineQty;
			int ordShipSplt;
			bool? nullable4;
			bool? nullable5;
			bool? nullable6;
			bool? nullable7;
			bool? nullable8;
			bool? nullable9;
			bool? nullable10;
			bool? nullable11;
			bool? nullable12;
			bool? nullable13;
			bool? nullable14;
			bool? nullable15;
			bool? nullable16;
			bool? nullable17;
			bool? nullable18;
			bool? nullable19;
			bool? nullable20;
			bool? nullable21;
			bool ldLogONS = false;
			bool ldLineDataChg = false;
			bool ldSectionDataChg = false;
			bool mesExtractLineChg = false;
			int mesSectionCounter = 0;
			int ldRowCounter = 0;
            string ldWorkCenter = "";
			scMESOrderInfo item = (scMESOrderInfo)MESExtractData[0];
			using (SE0085CTEntities1 CTdB = new SE0085CTEntities1())
			{
                //CTdB.Database.Connection.ConnectionString = this._CTConnection;
                //DbSet<SEOrder> sEOrders = CTdB.SEOrders;
                //DbSet<OrderLine> orderLines = CTdB.OrderLines;
                //ParameterExpression parameterExpression = Expression.Parameter(typeof(SEOrder), "o");
                //MemberExpression memberExpression = Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(SEOrder).GetMethod("get_OrderId").MethodHandle));
                //ParameterExpression[] parameterExpressionArray = new ParameterExpression[] { parameterExpression };
                //Expression<Func<SEOrder, int>> expression = Expression.Lambda<Func<SEOrder, int>>(memberExpression, parameterExpressionArray);
                //ParameterExpression parameterExpression1 = Expression.Parameter(typeof(OrderLine), "l");
                //MemberExpression memberExpression1 = Expression.Property(Expression.Property(parameterExpression1, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(OrderLine).GetMethod("get_SEOrder").MethodHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(SEOrder).GetMethod("get_OrderId").MethodHandle));
                //ParameterExpression[] parameterExpressionArray1 = new ParameterExpression[] { parameterExpression1 };
                //Expression<Func<OrderLine, int>> expression1 = Expression.Lambda<Func<OrderLine, int>>(memberExpression1, parameterExpressionArray1);
                //ParameterExpression parameterExpression2 = Expression.Parameter(typeof(SEOrder), "o");
                //ParameterExpression parameterExpression3 = Expression.Parameter(typeof(OrderLine), "l");
                //ConstructorInfo methodFromHandle = (ConstructorInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_41<SEOrder, OrderLine>).GetMethod(".ctor", new Type[] { typeof(T0), typeof(T1) }).MethodHandle, typeof(VB$AnonymousType_41<SEOrder, OrderLine>).TypeHandle);
                //Expression[] expressionArray = new Expression[] { parameterExpression2, parameterExpression3 };
                //MethodInfo[] methodInfoArray = new MethodInfo[] { (MethodInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_41<SEOrder, OrderLine>).GetMethod("get_o").MethodHandle, typeof(VB$AnonymousType_41<SEOrder, OrderLine>).TypeHandle), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_41<SEOrder, OrderLine>).GetMethod("get_l").MethodHandle, typeof(VB$AnonymousType_41<SEOrder, OrderLine>).TypeHandle) };
                //NewExpression newExpression = Expression.New(methodFromHandle, expressionArray, methodInfoArray);
                //ParameterExpression[] parameterExpressionArray2 = new ParameterExpression[] { parameterExpression2, parameterExpression3 };
                //var collection = sEOrders.Join(orderLines, expression, expression1, Expression.Lambda(newExpression, parameterExpressionArray2));
                //ParameterExpression parameterExpression4 = Expression.Parameter(typeof(VB$AnonymousType_41<SEOrder, OrderLine>), "$VB$It");
                //MethodInfo methodInfo = (MethodInfo)MethodBase.GetMethodFromHandle(typeof(Microsoft.VisualBasic.CompilerServices.Operators).GetMethod("CompareString", new Type[] { typeof(string), typeof(string), typeof(bool) }).MethodHandle);
                //Expression[] expressionArray1 = new Expression[] { Expression.Property(Expression.Property(parameterExpression4, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_41<SEOrder, OrderLine>).GetMethod("get_o").MethodHandle, typeof(VB$AnonymousType_41<SEOrder, OrderLine>).TypeHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(SEOrder).GetMethod("get_OrderFO").MethodHandle)), Expression.Property(Expression.Field(Expression.Constant($VB$Closure_ClosureVariable_8F, typeof(clsEngineMES._Closure$__143)), (FieldInfo)FieldInfo.GetFieldFromHandle(typeof(clsEngineMES._Closure$__143).GetField("$VB$Local_mesOrderLine").FieldHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(scMESOrderInfo).GetMethod("get_OrderFO").MethodHandle)), Expression.Constant(false, typeof(bool)) };
                //BinaryExpression binaryExpression = Expression.Equal(Expression.Call(null, methodInfo, expressionArray1), Expression.Constant(0, typeof(int)));
                //MethodInfo methodFromHandle1 = (MethodInfo)MethodBase.GetMethodFromHandle(typeof(Microsoft.VisualBasic.CompilerServices.Operators).GetMethod("CompareString", new Type[] { typeof(string), typeof(string), typeof(bool) }).MethodHandle);
                //Expression[] expressionArray2 = new Expression[] { Expression.Property(Expression.Property(parameterExpression4, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_41<SEOrder, OrderLine>).GetMethod("get_l").MethodHandle, typeof(VB$AnonymousType_41<SEOrder, OrderLine>).TypeHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(OrderLine).GetMethod("get_OrderLineNum").MethodHandle)), Expression.Property(Expression.Field(Expression.Constant($VB$Closure_ClosureVariable_8F, typeof(clsEngineMES._Closure$__143)), (FieldInfo)FieldInfo.GetFieldFromHandle(typeof(clsEngineMES._Closure$__143).GetField("$VB$Local_mesOrderLine").FieldHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(scMESOrderInfo).GetMethod("get_OrderLineNum").MethodHandle)), Expression.Constant(false, typeof(bool)) };
                //BinaryExpression binaryExpression1 = Expression.And(binaryExpression, Expression.Equal(Expression.Call(null, methodFromHandle1, expressionArray2), Expression.Constant(0, typeof(int))));
                //MethodInfo methodInfo1 = (MethodInfo)MethodBase.GetMethodFromHandle(typeof(Microsoft.VisualBasic.CompilerServices.Operators).GetMethod("CompareString", new Type[] { typeof(string), typeof(string), typeof(bool) }).MethodHandle);
                //Expression[] expressionArray3 = new Expression[] { Expression.Property(Expression.Property(parameterExpression4, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_41<SEOrder, OrderLine>).GetMethod("get_l").MethodHandle, typeof(VB$AnonymousType_41<SEOrder, OrderLine>).TypeHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(OrderLine).GetMethod("get_OrderLineSL").MethodHandle)), Expression.Property(Expression.Field(Expression.Constant($VB$Closure_ClosureVariable_8F, typeof(clsEngineMES._Closure$__143)), (FieldInfo)FieldInfo.GetFieldFromHandle(typeof(clsEngineMES._Closure$__143).GetField("$VB$Local_mesOrderLine").FieldHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(scMESOrderInfo).GetMethod("get_OrderLineSL").MethodHandle)), Expression.Constant(false, typeof(bool)) };
                //BinaryExpression binaryExpression2 = Expression.And(binaryExpression1, Expression.Equal(Expression.Call(null, methodInfo1, expressionArray3), Expression.Constant(0, typeof(int))));
                //MethodInfo methodFromHandle2 = (MethodInfo)MethodBase.GetMethodFromHandle(typeof(Microsoft.VisualBasic.CompilerServices.Operators).GetMethod("CompareString", new Type[] { typeof(string), typeof(string), typeof(bool) }).MethodHandle);
                //Expression[] expressionArray4 = new Expression[] { Expression.Property(Expression.Property(parameterExpression4, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_41<SEOrder, OrderLine>).GetMethod("get_l").MethodHandle, typeof(VB$AnonymousType_41<SEOrder, OrderLine>).TypeHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(OrderLine).GetMethod("get_OrderLineSS").MethodHandle)), Expression.Property(Expression.Field(Expression.Constant($VB$Closure_ClosureVariable_8F, typeof(clsEngineMES._Closure$__143)), (FieldInfo)FieldInfo.GetFieldFromHandle(typeof(clsEngineMES._Closure$__143).GetField("$VB$Local_mesOrderLine").FieldHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(scMESOrderInfo).GetMethod("get_OrderLineSS").MethodHandle)), Expression.Constant(false, typeof(bool)) };
                //BinaryExpression binaryExpression3 = Expression.And(binaryExpression2, Expression.Equal(Expression.Call(null, methodFromHandle2, expressionArray4), Expression.Constant(0, typeof(int))));
                //ParameterExpression[] parameterExpressionArray3 = new ParameterExpression[] { parameterExpression4 };
                //var collection1 = collection.Where(Expression.Lambda(binaryExpression3, parameterExpressionArray3));
                //ParameterExpression parameterExpression5 = Expression.Parameter(typeof(VB$AnonymousType_41<SEOrder, OrderLine>), "$VB$It");
                //MemberExpression memberExpression2 = Expression.Property(parameterExpression5, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_41<SEOrder, OrderLine>).GetMethod("get_l").MethodHandle, typeof(VB$AnonymousType_41<SEOrder, OrderLine>).TypeHandle));
                //ParameterExpression[] parameterExpressionArray4 = new ParameterExpression[] { parameterExpression5 };
				IQueryable<OrderLine> dBLineDataQuery = (from o in CTdB.SEOrders
                                                  join l in CTdB.OrderLines
                                                  on o.OrderId equals l.SEOrder.OrderId
                                                  where string.Equals(o.OrderFO, item.OrderFO)
                                                  & string.Equals(l.OrderLineNum, item.OrderLineNum)
                                                  & string.Equals(l.OrderLineSL, item.OrderLineSL)
                                                  & string.Equals(l.OrderLineSS, item.OrderLineSS)
                                                  select l).AsQueryable<OrderLine>();
                try
				{
					enumerator = dBLineDataQuery.GetEnumerator();
					while (enumerator.MoveNext())
					{
						OrderLine dbLineRow = enumerator.Current;
						ordShipSplt = item.OrderLineQty;
						orderLineQty = dbLineRow.OrderLineQty;
						if (orderLineQty.HasValue)
						{
							nullable4 = new bool?(orderLineQty.GetValueOrDefault() == ordShipSplt);
							nullable7 = nullable4;
						}
						else
						{
							nullable2 = null;
							nullable7 = nullable2;
						}
						nullable1 = nullable7;
						if (nullable1.HasValue)
						{
							nullable3 = new bool?(!nullable1.GetValueOrDefault());
							nullable8 = nullable3;
						}
						else
						{
							nullable2 = null;
							nullable8 = nullable2;
						}
						nullable = nullable8;
						if (nullable.GetValueOrDefault())
						{
							ldLineDataChg = true;
							dbLineRow.OrderLineQty = item.OrderLineQty;
						}
					}
				}
                catch
                {}
                finally{
                    if (enumerator != null)
                    {
                        enumerator.Dispose();
                    }
                }
				if (ldLineDataChg)
				{
					if (CTdB.SaveChanges() > 0)
					{
						ldLineDataChg = false;
					}
				}

                //DbSet<SEOrder> sEOrders1 = CTdB.SEOrders;
                //DbSet<OrderLine> orderLines1 = CTdB.OrderLines;
                //ParameterExpression parameterExpression6 = Expression.Parameter(typeof(SEOrder), "o");
                //MemberExpression memberExpression3 = Expression.Property(parameterExpression6, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(SEOrder).GetMethod("get_OrderId").MethodHandle));
                //ParameterExpression[] parameterExpressionArray5 = new ParameterExpression[] { parameterExpression6 };
                //Expression<Func<SEOrder, int>> expression2 = Expression.Lambda<Func<SEOrder, int>>(memberExpression3, parameterExpressionArray5);
                //ParameterExpression parameterExpression7 = Expression.Parameter(typeof(OrderLine), "l");
                //MemberExpression memberExpression4 = Expression.Property(Expression.Property(parameterExpression7, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(OrderLine).GetMethod("get_SEOrder").MethodHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(SEOrder).GetMethod("get_OrderId").MethodHandle));
                //ParameterExpression[] parameterExpressionArray6 = new ParameterExpression[] { parameterExpression7 };
                //Expression<Func<OrderLine, int>> expression3 = Expression.Lambda<Func<OrderLine, int>>(memberExpression4, parameterExpressionArray6);
                //ParameterExpression parameterExpression8 = Expression.Parameter(typeof(SEOrder), "o");
                //ParameterExpression parameterExpression9 = Expression.Parameter(typeof(OrderLine), "l");
                //ConstructorInfo constructorInfo = (ConstructorInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_41<SEOrder, OrderLine>).GetMethod(".ctor", new Type[] { typeof(T0), typeof(T1) }).MethodHandle, typeof(VB$AnonymousType_41<SEOrder, OrderLine>).TypeHandle);
                //Expression[] expressionArray5 = new Expression[] { parameterExpression8, parameterExpression9 };
                //MethodInfo[] methodInfoArray1 = new MethodInfo[] { (MethodInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_41<SEOrder, OrderLine>).GetMethod("get_o").MethodHandle, typeof(VB$AnonymousType_41<SEOrder, OrderLine>).TypeHandle), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_41<SEOrder, OrderLine>).GetMethod("get_l").MethodHandle, typeof(VB$AnonymousType_41<SEOrder, OrderLine>).TypeHandle) };
                //NewExpression newExpression1 = Expression.New(constructorInfo, expressionArray5, methodInfoArray1);
                //ParameterExpression[] parameterExpressionArray7 = new ParameterExpression[] { parameterExpression8, parameterExpression9 };
                //var collection2 = sEOrders1.Join(orderLines1, expression2, expression3, Expression.Lambda(newExpression1, parameterExpressionArray7));
                //DbSet<OrdSection> ordSections = CTdB.OrdSections;
                //ParameterExpression parameterExpression10 = Expression.Parameter(typeof(VB$AnonymousType_41<SEOrder, OrderLine>), "$VB$It");
                //MemberExpression memberExpression5 = Expression.Property(Expression.Property(parameterExpression10, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_41<SEOrder, OrderLine>).GetMethod("get_l").MethodHandle, typeof(VB$AnonymousType_41<SEOrder, OrderLine>).TypeHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(OrderLine).GetMethod("get_OrderLineId").MethodHandle));
                //ParameterExpression[] parameterExpressionArray8 = new ParameterExpression[] { parameterExpression10 };
                //var expression4 = Expression.Lambda(memberExpression5, parameterExpressionArray8);
                //ParameterExpression parameterExpression11 = Expression.Parameter(typeof(OrdSection), "s");
                //MemberExpression memberExpression6 = Expression.Property(Expression.Property(parameterExpression11, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(OrdSection).GetMethod("get_OrderLine").MethodHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(OrderLine).GetMethod("get_OrderLineId").MethodHandle));
                //ParameterExpression[] parameterExpressionArray9 = new ParameterExpression[] { parameterExpression11 };
                //Expression<Func<OrdSection, int>> expression5 = Expression.Lambda<Func<OrdSection, int>>(memberExpression6, parameterExpressionArray9);
                //ParameterExpression parameterExpression12 = Expression.Parameter(typeof(VB$AnonymousType_41<SEOrder, OrderLine>), "$VB$It1");
                //ParameterExpression parameterExpression13 = Expression.Parameter(typeof(OrdSection), "s");
                //ConstructorInfo constructorInfo1 = (ConstructorInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_45<SEOrder, OrderLine, OrdSection>).GetMethod(".ctor", new Type[] { typeof(T0), typeof(T1), typeof(T2) }).MethodHandle, typeof(VB$AnonymousType_45<SEOrder, OrderLine, OrdSection>).TypeHandle);
                //Expression[] expressionArray6 = new Expression[] { Expression.Property(parameterExpression12, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_41<SEOrder, OrderLine>).GetMethod("get_o").MethodHandle, typeof(VB$AnonymousType_41<SEOrder, OrderLine>).TypeHandle)), Expression.Property(parameterExpression12, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_41<SEOrder, OrderLine>).GetMethod("get_l").MethodHandle, typeof(VB$AnonymousType_41<SEOrder, OrderLine>).TypeHandle)), parameterExpression13 };
                //MethodInfo[] methodInfoArray2 = new MethodInfo[] { (MethodInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_45<SEOrder, OrderLine, OrdSection>).GetMethod("get_o").MethodHandle, typeof(VB$AnonymousType_45<SEOrder, OrderLine, OrdSection>).TypeHandle), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_45<SEOrder, OrderLine, OrdSection>).GetMethod("get_l").MethodHandle, typeof(VB$AnonymousType_45<SEOrder, OrderLine, OrdSection>).TypeHandle), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_45<SEOrder, OrderLine, OrdSection>).GetMethod("get_s").MethodHandle, typeof(VB$AnonymousType_45<SEOrder, OrderLine, OrdSection>).TypeHandle) };
                //NewExpression newExpression2 = Expression.New(constructorInfo1, expressionArray6, methodInfoArray2);
                //ParameterExpression[] parameterExpressionArray10 = new ParameterExpression[] { parameterExpression12, parameterExpression13 };
                //var collection3 = collection2.Join(ordSections, expression4, expression5, Expression.Lambda(newExpression2, parameterExpressionArray10));
                //ParameterExpression parameterExpression14 = Expression.Parameter(typeof(VB$AnonymousType_45<SEOrder, OrderLine, OrdSection>), "$VB$It");
                //BinaryExpression binaryExpression4 = Expression.Equal(Expression.Property(Expression.Property(parameterExpression14, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_45<SEOrder, OrderLine, OrdSection>).GetMethod("get_s").MethodHandle, typeof(VB$AnonymousType_45<SEOrder, OrderLine, OrdSection>).TypeHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(OrdSection).GetMethod("get_OrdSectsId").MethodHandle)), Expression.Property(Expression.Field(Expression.Constant($VB$Closure_ClosureVariable_8F, typeof(clsEngineMES._Closure$__143)), (FieldInfo)FieldInfo.GetFieldFromHandle(typeof(clsEngineMES._Closure$__143).GetField("$VB$Local_mesOrderLine").FieldHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(scMESOrderInfo).GetMethod("get_OrdSectsId").MethodHandle)), true, null);
                //ParameterExpression[] parameterExpressionArray11 = new ParameterExpression[] { parameterExpression14 };
                //var collection4 = collection3.Where(Expression.Lambda(binaryExpression4, parameterExpressionArray11));
                //ParameterExpression parameterExpression15 = Expression.Parameter(typeof(VB$AnonymousType_45<SEOrder, OrderLine, OrdSection>), "$VB$It");
                //MemberExpression memberExpression7 = Expression.Property(Expression.Property(parameterExpression15, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_45<SEOrder, OrderLine, OrdSection>).GetMethod("get_s").MethodHandle, typeof(VB$AnonymousType_45<SEOrder, OrderLine, OrdSection>).TypeHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(OrdSection).GetMethod("get_OrdSectsProdNum").MethodHandle));
                //ParameterExpression[] parameterExpressionArray12 = new ParameterExpression[] { parameterExpression15 };
                //var collection5 = collection4.OrderBy(Expression.Lambda(memberExpression7, parameterExpressionArray12));
                //ParameterExpression parameterExpression16 = Expression.Parameter(typeof(VB$AnonymousType_45<SEOrder, OrderLine, OrdSection>), "$VB$It");
                //MemberExpression memberExpression8 = Expression.Property(parameterExpression16, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_45<SEOrder, OrderLine, OrdSection>).GetMethod("get_s").MethodHandle, typeof(VB$AnonymousType_45<SEOrder, OrderLine, OrdSection>).TypeHandle));
                //ParameterExpression[] parameterExpressionArray13 = new ParameterExpression[] { parameterExpression16 };
                //IQueryable<OrdSection> dBsectionDataQuery = collection5.Select(Expression.Lambda(memberExpression8, parameterExpressionArray13));

                 IQueryable<OrdSection> dBsectionDataQuery = (from o in CTdB.SEOrders
                                                 join l in CTdB.OrderLines
                                                 on o.OrderId equals l.SEOrder.OrderId
                                                 join s in CTdB.OrdSections
                                                 on l.OrderLineId equals s.OrderLine.OrderLineId
                                                 where s.OrdSectsId == item.OrdSectsId
                                                 orderby s.OrdSectsProdNum
                                                 select s).AsQueryable<OrdSection>();

				string ldProdOrderMem = "";
				ArrayList mesSectionArray = new ArrayList();
				try
				{
					enumerator1 = MESExtractData.GetEnumerator();
					while (enumerator1.MoveNext())
					{
						item = (scMESOrderInfo)enumerator1.Current;
						if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ldProdOrderMem, item.OrdSectsProdNum, false) != 0)
						{
							ldProdOrderMem = item.OrdSectsProdNum;
							mesSectionCounter++;
							if (dBsectionDataQuery.Count<OrdSection>() < 1)
							{
								this.lcLogWriter.logData(string.Concat("Error importing data, aborting MES import for Order; ", item.OrderFO));
							}
							else
							{
                                //using (ldRowCounter = 0)
                                //{
									enumerator2 = dBsectionDataQuery.GetEnumerator();
									while (enumerator2.MoveNext())
									{
										OrdSection dBsectionRow = enumerator2.Current;
										item.OrdSectsId = dBsectionRow.OrdSectsId;
										ldRowCounter++;
										if (mesSectionCounter == ldRowCounter)
										{
											ordShipSplt = item.OrdSection.OrdShipSplt;
											orderLineQty = dBsectionRow.OrdSectShipSpt;
											if (orderLineQty.HasValue)
											{
												nullable6 = new bool?(orderLineQty.GetValueOrDefault() == ordShipSplt);
												nullable9 = nullable6;
											}
											else
											{
												nullable2 = null;
												nullable9 = nullable2;
											}
											nullable = nullable9;
											if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(Microsoft.VisualBasic.Strings.Trim(dBsectionRow.OrdSectsProdNum), item.OrdSection.OrdSectsProdNum, false) == 0 & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(Microsoft.VisualBasic.Strings.Trim(dBsectionRow.OrdSectsCurrWorkCtr), item.OrdSection.OrdSectsCurrWorkCtr, false) == 0 & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(Microsoft.VisualBasic.Strings.Trim(dBsectionRow.OrdSectsCryptRt), item.OrdSection.OrdSectsCryptRt, false) == 0 & dBsectionRow.OrdSectsNum == item.OrdSection.OrdSectsNum)
											{
												nullable10 = nullable;
											}
											else
											{
												nullable5 = new bool?(false);
												nullable10 = nullable5;
											}
											nullable3 = nullable10;
											if (nullable3.HasValue)
											{
												nullable1 = new bool?(!nullable3.GetValueOrDefault());
												nullable11 = nullable1;
											}
											else
											{
												nullable2 = null;
												nullable11 = nullable2;
											}
											nullable4 = nullable11;
											if (nullable4.GetValueOrDefault())
											{
												ldSectionDataChg = true;
												OrdSection ordSectsProdNum = dBsectionRow;
												ordSectsProdNum.OrdSectsProdNum = item.OrdSectsProdNum;
												ordSectsProdNum.OrdSectsCurrWorkCtr = item.OrdSectsCurrWorkCtr;
												ordSectsProdNum.OrdSectsCryptRt = Microsoft.VisualBasic.Strings.Left(item.OrdSectsCryptRt, 15);
												ordSectsProdNum.OrdSectsNum = item.OrdSectsNum;
												ordSectsProdNum.OrdSectShipSpt = item.OrdShipSplt;
												ordSectsProdNum = null;
											}
										}
									}
								//}
								mesSectionArray.Add(item.OrdSection);
								if (ldSectionDataChg)
								{
									if (CTdB.SaveChanges() > 0)
									{
										ldSectionDataChg = false;
									}
								}
							}
						}
					}
				}
				finally
				{
					if (enumerator1 is IDisposable)
					{
						(enumerator1 as IDisposable).Dispose();
					}
				}
				ArrayList ldSectionRoutingComplete = new ArrayList();
				ArrayList ldProcessedRoutings = new ArrayList();
				try
				{
					enumerator3 = mesSectionArray.GetEnumerator();
					while (enumerator3.MoveNext())
					{
						//$VB$Closure_ClosureVariable_91 = new clsEngineMES._Closure$__143._Closure$__144._Closure$__145($VB$Closure_ClosureVariable_91);
						scOrdSectionsInfo mesSection = (scOrdSectionsInfo)enumerator3.Current;
						//$VB$Closure_ClosureVariable_91.$VB$NonLocal_$VB$Closure_ClosureVariable_90 = $VB$Closure_ClosureVariable_90;
						
                        //DOUBT
                        IEnumerable<scSectionsInfoProcess> mesProcessedWorkcenters = 
							from object w in MESExtractData
							where Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectEqual(NewLateBinding.LateGet(w, null, "OrdSectsProdNum", new object[0], null, null, null), item.OrdSectsProdNum, false)
							orderby NewLateBinding.LateGet(w, null, "RoutingWorkCenter", new object[0], null, null, null)
							select new scSectionsInfoProcess()
							{
								OrdSectsId = item.OrdSectsId,
                                OrdShipSplt = item.OrdShipSplt,
                                OrdSectsNum = item.OrdSectsNum,
                                OrdSectsProdNum = item.OrdSectsProdNum,
								//OrdSectsRelMfg = this.ldSectionData.OrdSectsRelMfg,
                                OrdSectsCryptRt = Microsoft.VisualBasic.Strings.Left(item.OrdSectsCryptRt, 15),
                                OrdSectsCurrWorkCtr = item.OrdSectsCurrWorkCtr,
								RoutingActFinishDt = Conversions.ToDate(NewLateBinding.LateGet(w, null, "RoutingActFinishDt", new object[0], null, null, null)),
								RoutingActStartDt = Conversions.ToDate(NewLateBinding.LateGet(w, null, "RoutingActStartDt", new object[0], null, null, null)),
								RoutingNextWorkCtr = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(NewLateBinding.LateGet(w, null, "RoutingNextWorkCtr", new object[0], null, null, null))),
								RoutingRunTimeMin = Conversions.ToInteger(NewLateBinding.LateGet(w, null, "RoutingRunTimeMin", new object[0], null, null, null)),
								RoutingSchFinishDt = Conversions.ToDate(NewLateBinding.LateGet(w, null, "RoutingSchFinishDt", new object[0], null, null, null)),
								RoutingSchStartDt = Conversions.ToDate(NewLateBinding.LateGet(w, null, "RoutingSchStartDt", new object[0], null, null, null)),
								RoutingWorkCenter = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(NewLateBinding.LateGet(w, null, "RoutingWorkCenter", new object[0], null, null, null))),
								RoutingStatusCD = Microsoft.VisualBasic.Strings.Trim(Conversions.ToString(NewLateBinding.LateGet(w, null, "RoutingStatusCD", new object[0], null, null, null))),
								RoutingProcessed = false
							};
						scSectionsInfoProcess[] mesProcessedRt = mesProcessedWorkcenters.ToArray<scSectionsInfoProcess>();

                        //DbSet<OrdSection> ordSections1 = CTdB.OrdSections;
                        //DbSet<SectionsRouting> sectionsRoutings = CTdB.SectionsRoutings;
                        //ParameterExpression parameterExpression17 = Expression.Parameter(typeof(OrdSection), "s");
                        //MemberExpression memberExpression9 = Expression.Property(parameterExpression17, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(OrdSection).GetMethod("get_OrdSectsId").MethodHandle));
                        //ParameterExpression[] parameterExpressionArray14 = new ParameterExpression[] { parameterExpression17 };
                        //Expression<Func<OrdSection, int>> expression6 = Expression.Lambda<Func<OrdSection, int>>(memberExpression9, parameterExpressionArray14);
                        //ParameterExpression parameterExpression18 = Expression.Parameter(typeof(SectionsRouting), "r");
                        //MemberExpression memberExpression10 = Expression.Property(Expression.Property(parameterExpression18, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(SectionsRouting).GetMethod("get_OrdSection").MethodHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(OrdSection).GetMethod("get_OrdSectsId").MethodHandle));
                        //ParameterExpression[] parameterExpressionArray15 = new ParameterExpression[] { parameterExpression18 };
                        //Expression<Func<SectionsRouting, int>> expression7 = Expression.Lambda<Func<SectionsRouting, int>>(memberExpression10, parameterExpressionArray15);
                        //ParameterExpression parameterExpression19 = Expression.Parameter(typeof(OrdSection), "s");
                        //ParameterExpression parameterExpression20 = Expression.Parameter(typeof(SectionsRouting), "r");
                        //ConstructorInfo constructorInfo2 = (ConstructorInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_38<OrdSection, SectionsRouting>).GetMethod(".ctor", new Type[] { typeof(T0), typeof(T1) }).MethodHandle, typeof(VB$AnonymousType_38<OrdSection, SectionsRouting>).TypeHandle);
                        //Expression[] expressionArray7 = new Expression[] { parameterExpression19, parameterExpression20 };
                        //MethodInfo[] methodFromHandle3 = new MethodInfo[] { (MethodInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_38<OrdSection, SectionsRouting>).GetMethod("get_s").MethodHandle, typeof(VB$AnonymousType_38<OrdSection, SectionsRouting>).TypeHandle), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_38<OrdSection, SectionsRouting>).GetMethod("get_r").MethodHandle, typeof(VB$AnonymousType_38<OrdSection, SectionsRouting>).TypeHandle) };
                        //NewExpression newExpression3 = Expression.New(constructorInfo2, expressionArray7, methodFromHandle3);
                        //ParameterExpression[] parameterExpressionArray16 = new ParameterExpression[] { parameterExpression19, parameterExpression20 };
                        //var collection6 = ordSections1.Join(sectionsRoutings, expression6, expression7, Expression.Lambda(newExpression3, parameterExpressionArray16));
                        //ParameterExpression parameterExpression21 = Expression.Parameter(typeof(VB$AnonymousType_38<OrdSection, SectionsRouting>), "$VB$It");
                        //BinaryExpression binaryExpression5 = Expression.Equal(Expression.Property(Expression.Property(parameterExpression21, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_38<OrdSection, SectionsRouting>).GetMethod("get_s").MethodHandle, typeof(VB$AnonymousType_38<OrdSection, SectionsRouting>).TypeHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(OrdSection).GetMethod("get_OrdSectsId").MethodHandle)), Expression.Property(Expression.Field(Expression.Constant($VB$Closure_ClosureVariable_90, typeof(clsEngineMES._Closure$__143._Closure$__144)), (FieldInfo)FieldInfo.GetFieldFromHandle(typeof(clsEngineMES._Closure$__143._Closure$__144).GetField("$VB$Local_ldSectionData").FieldHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(scOrdSectionsInfo).GetMethod("get_OrdSectsId").MethodHandle)), true, null);
                        //ParameterExpression[] parameterExpressionArray17 = new ParameterExpression[] { parameterExpression21 };
                        //var collection7 = collection6.Where(Expression.Lambda(binaryExpression5, parameterExpressionArray17));
                        //ParameterExpression parameterExpression22 = Expression.Parameter(typeof(VB$AnonymousType_38<OrdSection, SectionsRouting>), "$VB$It");
                        //MemberExpression memberExpression11 = Expression.Property(parameterExpression22, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(VB$AnonymousType_38<OrdSection, SectionsRouting>).GetMethod("get_r").MethodHandle, typeof(VB$AnonymousType_38<OrdSection, SectionsRouting>).TypeHandle));
                        //ParameterExpression[] parameterExpressionArray18 = new ParameterExpression[] { parameterExpression22 };
                        //IQueryable<SectionsRouting> sectionsRoutings1 = collection7.Select(Expression.Lambda(memberExpression11, parameterExpressionArray18));
                        //ParameterExpression parameterExpression23 = Expression.Parameter(typeof(SectionsRouting), "r");
                        //MemberExpression memberExpression12 = Expression.Property(parameterExpression23, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(SectionsRouting).GetMethod("get_RoutingWorkCenter").MethodHandle));
                        //ParameterExpression[] parameterExpressionArray19 = new ParameterExpression[] { parameterExpression23 };
                        //IOrderedQueryable<SectionsRouting> dBroutingQuery = sectionsRoutings1.OrderBy<SectionsRouting, string>(Expression.Lambda<Func<SectionsRouting, string>>(memberExpression12, parameterExpressionArray19));

                        //IOrderedQueryable<SectionsRouting> dBroutingQuery
                        IQueryable<SectionsRouting> dBroutingQuery = (from s in CTdB.OrdSections
                                                                               join r in CTdB.SectionsRoutings
                                                                               on s.OrdSectsId equals r.OrdSection.OrdSectsId
                                                                               where s.OrdSectsId == mesSection.OrdSectsId
                                                                               orderby r.RoutingWorkCenter
                                                                               select r).AsQueryable<SectionsRouting>();
                        string ldWorkCenterMem = "";
						mesSectionCounter = 0;
						ldRowCounter = 0;
                        int ldCounter1 = 0;
                        //using (int ldCounter1 = 0)
                        //{
							enumerator4 = dBroutingQuery.GetEnumerator();
							while (enumerator4.MoveNext())
							{
								SectionsRouting dBroutingRow = enumerator4.Current;
								ldWorkCenterMem = dBroutingRow.RoutingWorkCenter;
								ldWorkCenter = Microsoft.VisualBasic.Strings.Trim(dBroutingRow.RoutingWorkCenter);

								IEnumerable<scSectionsRoutingInfo> mesRoutingStep = 
									from object m in MESExtractData
									select (scMESOrderInfo)m into m
									where Microsoft.VisualBasic.CompilerServices.Operators.CompareString(m.OrdSectsProdNum, item.OrdSection.OrdSectsProdNum , false) == 0 & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(m.RoutingWorkCenter, ldWorkCenter, false) == 0
									select new scSectionsRoutingInfo()
									{
										RoutingActFinishDt = m.RoutingActFinishDt,
										RoutingActStartDt = m.RoutingActStartDt,
										RoutingNextWorkCtr = m.RoutingNextWorkCtr,
										RoutingRunTimeMin = m.RoutingRunTimeMin,
										RoutingSchFinishDt = m.RoutingSchFinishDt,
										RoutingSchStartDt = m.RoutingSchStartDt,
										RoutingWorkCenter = m.RoutingWorkCenter,
										RoutingQueuedDt = m.RoutingQueuedDt,
										RoutingStatusCD = m.RoutingStatusCD
									};

								if (mesRoutingStep.Count<scSectionsRoutingInfo>() == 0)
								{
									this.dBDeleteDataByRoutingId(dBroutingRow.RoutingId, true, false);
								}
								else if (mesRoutingStep.Count<scSectionsRoutingInfo>() == 1)
								{
									try
									{
										enumerator5 = mesRoutingStep.GetEnumerator();
										while (enumerator5.MoveNext())
										{
											scSectionsRoutingInfo mesExtractLine = enumerator5.Current;
											mesExtractLine.RoutingId = dBroutingRow.RoutingId;
											string ldProcessingWC = mesExtractLine.RoutingWorkCenter;
											int num = checked(mesProcessedRt.Count<scSectionsInfoProcess>() - 1);
											for (ldCounter1 = 0; ldCounter1 <= num; ldCounter1++)
											{
												if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(Microsoft.VisualBasic.Strings.Trim(mesProcessedRt[ldCounter1].RoutingWorkCenter), Microsoft.VisualBasic.Strings.Trim(ldProcessingWC), false) == 0)
												{
													mesProcessedRt[ldCounter1].RoutingProcessed = true;
												}
											}
											DateTime routingSchFinishDt = mesExtractLine.RoutingSchFinishDt;
											DateTime? routingSchFinishDt1 = dBroutingRow.RoutingSchFinishDt;
											if (routingSchFinishDt1.HasValue)
											{
												bool? nullable22 = new bool?(DateTime.Compare(routingSchFinishDt1.GetValueOrDefault(), routingSchFinishDt) == 0);
												nullable12 = nullable22;
											}
											else
											{
												nullable2 = null;
												nullable12 = nullable2;
											}
											bool? nullable23 = nullable12;
											DateTime routingSchStartDt = mesExtractLine.RoutingSchStartDt;
											DateTime? routingSchStartDt1 = dBroutingRow.RoutingSchStartDt;
											if (routingSchStartDt1.HasValue)
											{
												bool? nullable24 = new bool?(DateTime.Compare(routingSchStartDt1.GetValueOrDefault(), routingSchStartDt) == 0);
												nullable13 = nullable24;
											}
											else
											{
												nullable2 = null;
												nullable13 = nullable2;
											}
											bool? nullable25 = nullable13;
											if (nullable23.HasValue && !nullable23.GetValueOrDefault())
											{
												nullable14 = new bool?(false);
											}
											else if (nullable25.HasValue)
											{
												nullable14 = (nullable25.GetValueOrDefault() ? nullable23 : new bool?(false));
											}
											else
											{
												nullable2 = null;
												nullable14 = nullable2;
											}
											bool? nullable26 = nullable14;
											DateTime routingActFinishDt = mesExtractLine.RoutingActFinishDt;
											DateTime? routingActFinishDt1 = dBroutingRow.RoutingActFinishDt;
											if (routingActFinishDt1.HasValue)
											{
												bool? nullable27 = new bool?(DateTime.Compare(routingActFinishDt1.GetValueOrDefault(), routingActFinishDt) == 0);
												nullable15 = nullable27;
											}
											else
											{
												nullable2 = null;
												nullable15 = nullable2;
											}
											bool? nullable28 = nullable15;
											if (nullable26.HasValue && !nullable26.GetValueOrDefault())
											{
												nullable16 = new bool?(false);
											}
											else if (nullable28.HasValue)
											{
												nullable16 = (nullable28.GetValueOrDefault() ? nullable26 : new bool?(false));
											}
											else
											{
												nullable2 = null;
												nullable16 = nullable2;
											}
											bool? nullable29 = nullable16;
											DateTime routingActStartDt = mesExtractLine.RoutingActStartDt;
											DateTime? routingActStartDt1 = dBroutingRow.RoutingActStartDt;
											if (routingActStartDt1.HasValue)
											{
												bool? nullable30 = new bool?(DateTime.Compare(routingActStartDt1.GetValueOrDefault(), routingActStartDt) == 0);
												nullable17 = nullable30;
											}
											else
											{
												nullable2 = null;
												nullable17 = nullable2;
											}
											bool? nullable31 = nullable17;
											if (nullable29.HasValue && !nullable29.GetValueOrDefault())
											{
												nullable18 = new bool?(false);
											}
											else if (nullable31.HasValue)
											{
												nullable18 = (nullable31.GetValueOrDefault() ? nullable29 : new bool?(false));
											}
											else
											{
												nullable2 = null;
												nullable18 = nullable2;
											}
											bool? nullable32 = nullable18;
											bool? nullable33 = (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(Microsoft.VisualBasic.Strings.Trim(dBroutingRow.RoutingNextWorkCtr), mesExtractLine.RoutingNextWorkCtr, false) == 0 ? nullable32 : new bool?(false));
											bool? nullable34 = (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(Microsoft.VisualBasic.Strings.Trim(dBroutingRow.RoutingWorkCenter), mesExtractLine.RoutingWorkCenter, false) == 0 ? nullable33 : new bool?(false));
											nullable3 = (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(Microsoft.VisualBasic.Strings.Trim(dBroutingRow.RoutingStatusCD), mesExtractLine.RoutingStatusCD, false) == 0 ? nullable34 : new bool?(false));
											ordShipSplt = mesExtractLine.RoutingRunTimeMin;
											orderLineQty = dBroutingRow.RoutingRunTimeMin;
											if (orderLineQty.HasValue)
											{
												nullable19 = new bool?(orderLineQty.GetValueOrDefault() == ordShipSplt);
											}
											else
											{
												nullable2 = null;
												nullable19 = nullable2;
											}
											nullable1 = nullable19;
											if (nullable3.HasValue && !nullable3.GetValueOrDefault())
											{
												nullable20 = new bool?(false);
											}
											else if (!nullable1.HasValue)
											{
												nullable2 = null;
												nullable20 = nullable2;
											}
											else if (nullable1.GetValueOrDefault())
											{
												nullable20 = nullable3;
											}
											else
											{
												nullable = new bool?(false);
												nullable20 = nullable;
											}
											nullable5 = nullable20;
											if (nullable5.HasValue)
											{
												nullable4 = new bool?(!nullable5.GetValueOrDefault());
												nullable21 = nullable4;
											}
											else
											{
												nullable2 = null;
												nullable21 = nullable2;
											}
											nullable6 = nullable21;
											if (nullable6.GetValueOrDefault())
											{
												mesExtractLineChg = true;
												SectionsRouting routingNextWorkCtr = dBroutingRow;
												routingNextWorkCtr.RoutingSchFinishDt = mesExtractLine.RoutingSchFinishDt;
												routingNextWorkCtr.RoutingSchStartDt = mesExtractLine.RoutingSchStartDt;
												routingNextWorkCtr.RoutingActFinishDt = mesExtractLine.RoutingActFinishDt;
												routingNextWorkCtr.RoutingActStartDt = mesExtractLine.RoutingActStartDt;
												routingNextWorkCtr.RoutingNextWorkCtr = mesExtractLine.RoutingNextWorkCtr;
												routingNextWorkCtr.RoutingWorkCenter = mesExtractLine.RoutingWorkCenter;
												routingNextWorkCtr.RoutingStatusCD = mesExtractLine.RoutingStatusCD;
												routingNextWorkCtr.RoutingRunTimeMin = mesExtractLine.RoutingRunTimeMin;
												routingNextWorkCtr = null;
												if (!ldLogONS)
												{
													ldLogONS = true;
													string[] orderFO = new string[] { "Routing Data Updated ", item.OrderFO, "-", item.OrderLineNum, "-", item.OrderLineSL, "-", item.OrderLineSS, ":", Conversions.ToString(item.OrdSectsNum), ", OrderSectId - ", Conversions.ToString(mesSection.OrdSectsId) };
													string ldLogData = string.Concat(orderFO);
													this.lcLogWriter.logData(ldLogData);
												}
											}
										}
									}
									finally
									{
										if (enumerator5 != null)
										{
											enumerator5.Dispose();
										}
									}
								}
							}
						//}
						scSectionsInfoProcess[] scSectionsInfoProcessArray = mesProcessedRt;
						for (int j = 0; j < checked((int)scSectionsInfoProcessArray.Length); j++)
						{
							scSectionsInfoProcess mesWorkcenter = scSectionsInfoProcessArray[j];
							if (!mesWorkcenter.RoutingProcessed)
							{
								this.InsertMESRoutingStep(mesWorkcenter);
							}
						}
						ldLogONS = false;
					}
				}
				finally
				{
					if (enumerator3 is IDisposable)
					{
						(enumerator3 as IDisposable).Dispose();
					}
				}
				if (mesExtractLineChg)
				{
					if (CTdB.SaveChanges() > 0)
					{
						ldSectionDataChg = false;
					}
				}
			}
			return false;
		}
                

        public void InsertMESRoutingStep(scSectionsInfoProcess RoutingStep)
        {
            // ISSUE: object of a compiler-generated type is created
            // ISSUE: variable of a compiler-generated type
            //clsEngineMES._Closure4__151 closure151 = new clsEngineMES._Closure4__151();
            // ISSUE: reference to a compiler-generated field
            //closure151.RoutingStep = RoutingStep;
            using (SE0085CTEntities1 se0085CtEntities1 = new SE0085CTEntities1())
            {
                //se0085CtEntities1.Database.Connection.ConnectionString = this._CTConnection;
                OrdSection ordSection = (OrdSection)null;
                //ParameterExpression parameterExpression;
                // ISSUE: reference to a compiler-generated field
                //IQueryable<OrdSection> source = (IQueryable<OrdSection>)Queryable.Select<OrdSection, OrdSection>(Queryable.Where<OrdSection>((IQueryable<M0>)se0085CtEntities1.OrdSections, (Expression<Func<M0, bool>>)Expression.Lambda<Func<OrdSection, bool>>((Expression)Expression.Equal(s.OrdSectsId, closure151.RoutingStep.OrdSectsId, true, (MethodInfo)null), new ParameterExpression[1]
                //{
                //  parameterExpression
                //})), (Expression<Func<M0, M1>>)(s => s));

                IQueryable<OrdSection> source = (from s in se0085CtEntities1.OrdSections
                                                 where string.Equals(s.OrdSectsId, RoutingStep.OrdSectsId)
                                                 select s).AsQueryable<OrdSection>();

                if (source.Count<OrdSection>() == 0)
                    return;
                if (source.Count<OrdSection>() == 1)
                {
                    try
                    {
                        ordSection = source.First<OrdSection>();
                    }
                    catch (Exception ex)
                    {
                        ProjectData.SetProjectError(ex);
                        this.lcLogWriter.logData("Error importing data, aborting MES import for SectionID; " + Conversions.ToString(RoutingStep.OrdSectsId));
                        ProjectData.ClearProjectError();
                    }
                }
                else
                {
                    this.lcLogWriter.logData("Multiple Order numbers found, aborting MES import for SectionID; " + Conversions.ToString(RoutingStep.OrdSectsId));
                }
                ordSection.SectionsRoutings.Add(new SectionsRouting()
                {
                    RoutingActFinishDt = (DateTime?)RoutingStep.RoutingActFinishDt,
                    RoutingActStartDt = (DateTime?)RoutingStep.RoutingActStartDt,
                    RoutingNextWorkCtr = RoutingStep.RoutingNextWorkCtr,
                    RoutingRunTimeMin = (int?)RoutingStep.RoutingRunTimeMin,
                    RoutingSchFinishDt = (DateTime?)RoutingStep.RoutingSchFinishDt,
                    RoutingSchStartDt = (DateTime?)RoutingStep.RoutingSchStartDt,
                    RoutingWorkCenter = RoutingStep.RoutingWorkCenter,
                    RoutingStatusCD = RoutingStep.RoutingStatusCD,
                    RoutingQueuedDt = (DateTime?)Conversions.ToDate("01/01/1901")
                });
                se0085CtEntities1.SaveChanges();
                se0085CtEntities1.Database.Connection.Close();
            }
        }


        public bool dBDeleteDataByRoutingId(int RoutingId, bool delRouting = false, bool delVouchers = false)
        {
            // ISSUE: object of a compiler-generated type is created
            // ISSUE: variable of a compiler-generated type
            //clsEngineMES._Closure4__155 closure155 = new clsEngineMES._Closure4__155();
            // ISSUE: reference to a compiler-generated field
            //closure155.RoutingId = RoutingId;
            int num = 0;
            bool flag1;
            if (delRouting)
                delVouchers = true;
            else if (!delVouchers)
            {
                flag1 = false;
                goto label_35;
            }
            using (SE0085CTEntities1 se0085CtEntities1 = new SE0085CTEntities1())
            {
                //se0085CtEntities1.Database.Connection.ConnectionString = this._CTConnection;
                //ParameterExpression parameterExpression;
                // ISSUE: reference to a compiler-generated field
                //IQueryable<AnonymousType_65<SectionsRouting, IEnumerable<LaborVoucher>>> source = Queryable.Select(Queryable.Where((IQueryable<M0>)Queryable.GroupJoin((IQueryable<M0>)se0085CtEntities1.SectionsRoutings, (IEnumerable<M1>)se0085CtEntities1.LaborVouchers, (Expression<Func<M0, M2>>)(r => r.RoutingId), (Expression<Func<M1, M2>>)(v => v.SectionsRouting.RoutingId), (Expression<Func<M0, IEnumerable<M1>, M3>>)((r, laborVouchers) => new
                //{
                //    r = r,
                //    vt = laborVouchers
                //})), (Expression<Func<M0, bool>>)Expression.Lambda<Func<AnonymousType_65<SectionsRouting, IEnumerable<LaborVoucher>>, bool>>((Expression)Expression.Equal(It.r.RoutingId, closure155.RoutingId, true, (MethodInfo)null), new ParameterExpression[1]
                //{
                //  parameterExpression
                //})), (Expression<Func<M0, M1>>)(data => new
                //{
                //    r = data.r,
                //    vt = data.vt
                //}));


                IQueryable<scRoutingLabour> source = from r in se0085CtEntities1.SectionsRoutings
                                                     join vt in se0085CtEntities1.LaborVouchers
                                                     on r.RoutingId equals vt.RoutingId
                                                     into LabourGroup
                                                     from s in LabourGroup.DefaultIfEmpty()
                                                     where r.RoutingId == RoutingId
                                                     select new scRoutingLabour
                                                     {
                                                         sectionRouting = r,
                                                         labourVoucher = s
                                                     };

                //IQueryable<scRoutingLabour> source = from r in se0085CtEntities1.SectionsRoutings
                //                                     join vt in se0085CtEntities1.LaborVouchers
                //                                     on r.RoutingId equals vt.RoutingId
                //                                     where r.RoutingId == RoutingId
                //                                     select new scRoutingLabour
                //                                     {
                //                                         sectionRouting=r,
                //                                         labourVoucher=vt
                //                                     };



                bool flag2 = false;
                //IEnumerator<AnonymousType_65<SectionsRouting, IEnumerable<LaborVoucher>>> enumerator1;
                IEnumerator<scRoutingLabour> enumerator1;

                if (source.Count() != 0)
                {
                    enumerator1 = source.GetEnumerator();
                    try
                    {
                        while (enumerator1.MoveNext())
                        {
                            var current1 = enumerator1.Current;
                            if (delVouchers)
                            {
                                if (current1.labourVoucher != null)
                                {
                                    try
                                    {
                                        //IEnumerator<LaborVoucher> enumerator2;
                                        LaborVoucher enumerator2;
                                            enumerator2 = current1.labourVoucher;
                                        try
                                        {
                                            //while (enumerator2.MoveNext())
                                            //{
                                            LaborVoucher current2 = enumerator2;//.Current;
                                                se0085CtEntities1.LaborVouchers.Remove(current2);
                                                flag2 = true;
                                            //}
                                        }
                                        finally
                                        {
                                            //if (enumerator2 != null)
                                            //    enumerator2.Dispose();
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        ProjectData.SetProjectError(ex);
                                        flag1 = false;
                                        ProjectData.ClearProjectError();
                                        goto label_35;
                                    }
                                }
                            }
                            if (delRouting)
                            {
                                if (current1.sectionRouting != null)
                                {
                                    try
                                    {
                                        se0085CtEntities1.SectionsRoutings.Remove(current1.sectionRouting);
                                        flag2 = true;
                                    }
                                    catch (Exception ex)
                                    {
                                        ProjectData.SetProjectError(ex);
                                        flag1 = false;
                                        ProjectData.ClearProjectError();
                                        goto label_35;
                                    }
                                }
                            }
                        }
                    }
                    finally
                    {
                        if (enumerator1 != null)
                            enumerator1.Dispose();
                    }
                }
                if (flag2)
                    num = se0085CtEntities1.SaveChanges();
                se0085CtEntities1.Database.Connection.Close();
            }
            flag1 = num > 0;
        label_35:
            return flag1;
        }

        public void LoadDictHolidays()
        {
            DateTime dateTime = DateTime.Today.AddDays(-90.0);
            this._dtHoliday.Clear();
            using (SE0085CTEntities1 se0085CtEntities1 = new SE0085CTEntities1())
            {
                //se0085CtEntities1.Database.Connection.ConnectionString = this._CTConnection;
                //ParameterExpression parameterExpression;
                // ISSUE: method reference
                // ISSUE: method reference
                //IQueryable<scHolidays> source = (IQueryable<scHolidays>)Queryable.Select<HolidayList, scHolidays>(Queryable.Where<HolidayList>((IQueryable<M0>)se0085CtEntities1.HolidayLists, (Expression<Func<M0, bool>>)(h => h.HolidayDate > dateTime)), (Expression<Func<M0, M1>>)Expression.Lambda<Func<HolidayList, scHolidays>>((Expression)Expression.MemberInit(Expression.New((ConstructorInfo)MethodBase.GetMethodFromHandle(__methodref(scHolidays.Ector)), (Expression[])null), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scHolidays.set_HolidayId)), (Expression)Expression.Property((Expression)parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(HolidayList.get_HolidayId)))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scHolidays.set_HolidayDesc)), (Expression)Expression.Property((Expression)parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(HolidayList.get_HolidayDesc)))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scHolidays.set_HolidayDate)), (Expression)Expression.Property((Expression)parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(HolidayList.get_HolidayDate)))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scHolidays.set_HolidayGroup)), (Expression)Expression.Property((Expression)parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(HolidayList.get_HolidayGroup)))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scHolidays.set_HolidayAdjDays)), (Expression)Expression.Property((Expression)parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(HolidayList.get_HolidayAdjDays))))), new ParameterExpression[1]
                //  {
                //    parameterExpression
                //  }));
                IQueryable<scHolidays> source = (from h in se0085CtEntities1.HolidayLists
                                                 where h.HolidayDate > dateTime
                                                 select new scHolidays
                                                 {
                                                     HolidayId = h.HolidayId,
                                                     HolidayDesc = h.HolidayDesc,
                                                     HolidayDate = h.HolidayDate,
                                                     HolidayAdjDays = h.HolidayAdjDays,
                                                     HolidayGroup = h.HolidayGroup
                                                 }).AsQueryable<scHolidays>();
                IEnumerator<scHolidays> enumerator;
                enumerator = source.GetEnumerator();
                if (source != null)
                {
                    if (source.Count<scHolidays>() > 0)
                    {
                        try
                        {
                            while (enumerator.MoveNext())
                            {
                                scHolidays current = enumerator.Current;
                                this._dtHoliday.Add(current.HolidayDate, current);
                            }
                        }
                        finally
                        {
                            if (enumerator != null)
                                enumerator.Dispose();
                        }
                    }
                }
                se0085CtEntities1.Database.Connection.Close();
            }
        }

        public void LoadDictLabor()
        {
            this._dtLaborContent.Clear();
            using (SE0085CTEntities1 se0085CtEntities1 = new SE0085CTEntities1())
            {
                //se0085CtEntities1.Database.Connection.ConnectionString = this._CTConnection;
                IQueryable<string> source = (IQueryable<string>)Queryable.Select<GatexRef, string>((IQueryable<GatexRef>)se0085CtEntities1.GatexRefs, (Expression<Func<GatexRef, string>>)(g => g.GateMESWorkCtr));
                //IQueryable<string> source = from g in se0085CtEntities1.GatexRefs
                                               // select g.GateMESWorkCtr;
                IEnumerator<string> enumerator;
                if (source != null)
                {
                    if (source.Count<string>() > 0)
                    {
                         enumerator = source.Distinct<string>().GetEnumerator();
                        try
                        {
                            while (enumerator.MoveNext())
                            {
                                string current = enumerator.Current;
                                this._dtLaborContent.Add(current, current);
                            }
                        }
                        finally
                        {
                            if (enumerator != null)
                                enumerator.Dispose();
                        }
                    }
                }
                se0085CtEntities1.Database.Connection.Close();
            }
        }

    }
}
