using Microsoft.VisualBasic.CompilerServices;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.Odbc;
using System.Linq;
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 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;
            try
            {
                enumerator1 = MESOrderData.GetEnumerator();
                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;
            //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 ";
            //selectCommand.CommandText = str1;
            //selectCommand.Parameters.Clear();
            //string str2 = AssyLine;
            //selectCommand.Parameters.AddWithValue("eto_ln", (object)str2);
            //string str3 = Q2CNbr;
            //selectCommand.Parameters.AddWithValue("q2c_nbr", (object)str3);
            //string str4 = Q2CLine;
            //selectCommand.Parameters.AddWithValue("ln_dsply_seq_nbr", (object)str4);
            //string str5 = Q2CSL;
            //selectCommand.Parameters.AddWithValue("sub_ln_itm_id", (object)str5);
            //string str6 = Q2CSS;
            //selectCommand.Parameters.AddWithValue("orig_shpschd_id", (object)str6);
            //odbcDataAdapter.SelectCommand = selectCommand;
            //dataSet.Tables.Clear();
            //odbcDataAdapter.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
            //{
            //    //IEnumerator enumerator;
            //    //if (enumerator is IDisposable)
            //    //    (enumerator as IDisposable).Dispose();
            //}
            return scMesUpdateFullList;
        }

        public void updateMESData(ArrayList MESExtractData)
        {
            //ArrayList arrayList = new ArrayList();
            //IEnumerable<scMESOrderInfo> source1 = (IEnumerable<scMESOrderInfo>)Enumerable.Select<scMESOrderInfo, scMESOrderInfo>((IEnumerable<M0>)Enumerable.ThenBy<scMESOrderInfo, string>(Enumerable.ThenBy<scMESOrderInfo, int>(Enumerable.ThenBy<scMESOrderInfo, string>(Enumerable.ThenBy<scMESOrderInfo, string>(Enumerable.ThenBy<scMESOrderInfo, string>(Enumerable.OrderBy<scMESOrderInfo, string>((IEnumerable<M0>)Enumerable.Select<object, scMESOrderInfo>((IEnumerable<M0>)MESExtractData.Cast<object>(), (Func<M0, M1>)new Func<object, scMESOrderInfo>((object)null, __methodptr(_Lambda4__67))), (Func<M0, M1>)new Func<scMESOrderInfo, string>((object)null, __methodptr(_Lambda4__68))), (Func<M0, M1>)new Func<scMESOrderInfo, string>((object)null, __methodptr(_Lambda4__69))), (Func<M0, M1>)new Func<scMESOrderInfo, string>((object)null, __methodptr(_Lambda4__70))), (Func<M0, M1>)new Func<scMESOrderInfo, string>((object)null, __methodptr(_Lambda4__71))), (Func<M0, M1>)new Func<scMESOrderInfo, int>((object)null, __methodptr(_Lambda4__72))), (Func<M0, M1>)new Func<scMESOrderInfo, string>((object)null, __methodptr(_Lambda4__73))), (Func<M0, M1>)new Func<scMESOrderInfo, scMESOrderInfo>((object)null, __methodptr(_Lambda4__74)));
            //if (source1.Count<scMESOrderInfo>() <= 0)
            //    return;
            //arrayList.AddRange((ICollection)source1.ToArray<scMESOrderInfo>());
            //int num1 = 0;
            //string Left = "";
            //ArrayList MESSectionList1 = new ArrayList();
            //try
            //{
            //    foreach (scMESOrderInfo scMesOrderInfo in arrayList)
            //    {
            //        if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(Left, scMesOrderInfo.OrdSectsProdNum, false) != 0)
            //        {
            //            Left = scMesOrderInfo.OrdSectsProdNum;
            //            MESSectionList1.Add((object)scMesOrderInfo.OrdSection);
            //            checked { ++num1; }
            //        }
            //    }
            //}
            //finally
            //{
            //    IEnumerator enumerator;
            //    if (enumerator is IDisposable)
            //        (enumerator as IDisposable).Dispose();
            //}
            //scMESOrderInfo scMesOrderInfo1 = new scMESOrderInfo();
            //scMESOrderInfo scMesOrderInfo2 = (scMESOrderInfo)arrayList[0];
            //scMESTableStatus[] scMesTableStatusArray1 = this.StatusMES_o_l_rLOJ(scMesOrderInfo2.OrderFO, scMesOrderInfo2.OrderLineNum, scMesOrderInfo2.OrderLineSL, scMesOrderInfo2.OrderLineSS);
            //bool flag;
            //if (scMesTableStatusArray1 == null)
            //{
            //    this.AddMESSections(arrayList, MESSectionList1);
            //    flag = false;
            //}
            //else if (scMesTableStatusArray1.Length > num1)
            //{
            //    int num2 = checked(num1 + 1);
            //    int length = scMesTableStatusArray1.Length;
            //    int num3 = num2;
            //    while (num3 <= length)
            //    {
            //        this.dBDeleteDataBySectionId(((IEnumerable<scMESTableStatus>)scMesTableStatusArray1).ElementAt<scMESTableStatus>(checked(num3 - 1)).OrdSectsId, true, false, false);
            //        checked { ++num3; }
            //    }
            //    flag = true;
            //}
            //else if (scMesTableStatusArray1.Length < num1)
            //{
            //    ArrayList MESSectionList2 = new ArrayList();
            //    int length = scMesTableStatusArray1.Length;
            //    int num2 = checked(num1 - 1);
            //    int index = length;
            //    while (index <= num2)
            //    {
            //        MESSectionList2.Add(RuntimeHelpers.GetObjectValue(MESSectionList1[index]));
            //        checked { ++index; }
            //    }
            //    this.AddMESSections(arrayList, MESSectionList2);
            //    flag = true;
            //}
            //else
            //    flag = true;
            //if (flag)
            //{
            //    scMESTableStatus[] scMesTableStatusArray2 = this.StatusMES_o_l_rLOJ(scMesOrderInfo2.OrderFO, scMesOrderInfo2.OrderLineNum, scMesOrderInfo2.OrderLineSL, scMesOrderInfo2.OrderLineSS);
            //    if (scMesTableStatusArray2.Length == num1)
            //    {
            //        // ISSUE: object of a compiler-generated type is created
            //        // ISSUE: variable of a compiler-generated type
            //        clsEngineMES._Closure4__142 closure142 = new clsEngineMES._Closure4__142();
            //        // ISSUE: reference to a compiler-generated field
            //        closure142.ldProcSection = new scOrdSectionsInfo();
            //        int index = 0;
            //        try
            //        {
            //            foreach (scOrdSectionsInfo scOrdSectionsInfo in MESSectionList1)
            //            {
            //                // ISSUE: reference to a compiler-generated field
            //                closure142.ldProcSection = scOrdSectionsInfo;
            //                ArrayList MESExtractData1 = new ArrayList();
            //                // ISSUE: method pointer
            //                IEnumerable<M1> m1s = Enumerable.Select<object, scMESOrderInfo>((IEnumerable<M0>)arrayList.Cast<object>(), (Func<M0, M1>)new Func<object, scMESOrderInfo>((object)null, __methodptr(_Lambda4__75)));
            //                // ISSUE: virtual method pointer
            //                IntPtr num2 = __vmethodptr(closure142, _Lambda4__76);
            //                Func<scMESOrderInfo, bool> func = new Func<scMESOrderInfo, bool>((object)closure142, num2);
            //                // ISSUE: method pointer
            //                IEnumerable<scMESOrderInfo> source2 = (IEnumerable<scMESOrderInfo>)Enumerable.Select<scMESOrderInfo, scMESOrderInfo>(Enumerable.Where<scMESOrderInfo>((IEnumerable<M0>)m1s, (Func<M0, bool>)func), (Func<M0, M1>)new Func<scMESOrderInfo, scMESOrderInfo>((object)null, __methodptr(_Lambda4__77)));
            //                if (source2.Count<scMESOrderInfo>() > 0)
            //                {
            //                    MESExtractData1.AddRange((ICollection)source2.ToArray<scMESOrderInfo>());
            //                    try
            //                    {
            //                        foreach (scMESOrderInfo scMesOrderInfo3 in MESExtractData1)
            //                            scMesOrderInfo3.OrdSectsId = scMesTableStatusArray2[index].OrdSectsId;
            //                    }
            //                    finally
            //                    {
            //                        IEnumerator enumerator;
            //                        if (enumerator is IDisposable)
            //                            (enumerator as IDisposable).Dispose();
            //                    }
            //                    this.UpdateMES_o_l_s_r(MESExtractData1);
            //                    checked { ++index; }
            //                }
            //                else
            //                    break;
            //            }
            //        }
            //        finally
            //        {
            //            IEnumerator enumerator;
            //            if (enumerator is IDisposable)
            //                (enumerator as IDisposable).Dispose();
            //        }
            //    }
            //    else
            //        this.lcLogWriter.logData("Error importing data, aborting MES import for Order; " + scMesOrderInfo2.OrderFO + "-" + scMesOrderInfo2.OrderLineNum + "-" + scMesOrderInfo2.OrderLineSS + "-" + scMesOrderInfo2.OrderLineSL);
            //}
        }

        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);
            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.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);
            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();
            }
        }

        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;
        }

    }
}
