using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace FAS_LIB
{
    public class clsBackorders
    {
        private scLevels _Plant;
        private scLevels _AssemblyLine;
        private clsLogWriter lcLogWriter;

        public clsBackorders(scLevels Plant, scLevels AssemblyLine)
        {
            this._Plant = Plant;
            this._AssemblyLine = AssemblyLine;
            this.lcLogWriter = new clsLogWriter("C:\\LogFiles\\BOUImport.log");
            //this.lcBWT2 = new ecDataInterface();
            //clsDBC clsDbc = new clsDBC();
            //clsDbc.GetServer((object)"SE0085CTEntities1");
            //this._CTConnection = Conversions.ToString(clsDbc.ConnectionString);
        }

        public void InsertBackOrderLines(scOrderImportInfo BackOrders)
        {
            string str1 = "";
            OrderLine ldOrderLine;
            clsEngineMES clsEngineMes = new clsEngineMES(this._Plant, this._AssemblyLine);
            scOrderImportInfo ldBackOrder = new scOrderImportInfo();
            ldBackOrder = BackOrders;

            using (SE0085CTEntities1 se0085CtEntities1 = new SE0085CTEntities1())
            {
                //ParameterExpression parameterExpression1;                
                //IQueryable<AssemblyLine> source1 = (IQueryable<AssemblyLine>)Queryable.Select(Queryable.Where((IQueryable<M0>)Queryable.Join((IQueryable<M0>)se0085CtEntities1.SEPlants, (IEnumerable<M1>)se0085CtEntities1.AssemblyLines, (Expression<Func<M0, M2>>)(p => p.SEPlantId), (Expression<Func<M1, M2>>)(a => a.SEPlant.SEPlantId), (Expression<Func<M0, M1, M3>>)((p, a) => new { p = p, a = a })), (Expression<Func<M0, bool>>)Expression.Lambda<Func<AnonymousType_5<SEPlant, AssemblyLine>, bool>>((Expression)Expression.Equal(It.a.AssemLineId, ldBackOrder.AssemblyLine.LevelId, true, (MethodInfo)null), new ParameterExpression[1]
                //{
                //  parameterExpression1
                //})), (Expression<Func<M0, M1>>)(data => data.a));

                IQueryable<AssemblyLine> source1 = (from sp in se0085CtEntities1.SEPlants
                                                    join al in se0085CtEntities1.AssemblyLines
                                                    on sp.SEPlantId equals al.SEPlantId
                                                   where string.Equals(al.AssemLineId,ldBackOrder.AssemblyLine.LevelId)
                                                   && int.Equals(sp.SEPlantActive, 1)
                                                    select new AssemblyLine
                                                    {
                                                        AssemLineId = al.AssemLineId,
                                                        SEPlantId = sp.SEPlantId,
                                                        AssemLineAbbrv = al.AssemLineAbbrv,
                                                        AssemLineName = al.AssemLineName,
                                                        AssemLineValue = al.AssemLineValue,
                                                        AssemLineActive = al.AssemLineActive
                                                    }).AsQueryable<AssemblyLine>();

                if (source1.Count<AssemblyLine>() == 0)
                {
                  int num1 = (int) Interaction.MsgBox((object) ("Error loading Assembly Line data, aborting MES import for AssemblyLineId; " + Conversions.ToString(ldBackOrder.AssemblyLine.LevelId)), MsgBoxStyle.Information, (object) "ONE QMS MES Import Error - E0001");
                }
                else if (source1.Count<AssemblyLine>() == 1)
                {
                    AssemblyLine assemblyLine = source1.First<AssemblyLine>();                    
                    //IQueryable<SEOrder> source2 = (IQueryable<SEOrder>)Queryable.Select<SEOrder, SEOrder>(Queryable.Where<SEOrder>((IQueryable<M0>)se0085CtEntities1.SEOrders, (Expression<Func<M0, bool>>)(o => Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Operators.CompareString)), o.OrderFO, closure95.ldBackOrder.OrderFO, false) == 0)), (Expression<Func<M0, M1>>)(o => o));
                    IQueryable<SEOrder> source2 = (from s in se0085CtEntities1.SEOrders
                                                   where string.Equals(s.OrderFO, ldBackOrder.OrderFO)
                                                   select new SEOrder
                                                   {
                                                       OrderId = s.OrderId,
                                                       OrderFO = s.OrderFO,
                                                       OrderJobName = s.OrderJobName,
                                                       OrderPurchaser = s.OrderPurchaser
                                                   }).AsQueryable<SEOrder>();
                    SEOrder entity;
                    if (source2.Count<SEOrder>() == 0)
                    {
                        if (DateTime.Compare(ldBackOrder.OrderLineShipDt, Conversions.ToDate("12/31/2039")) == 0)
                            return;
                        entity = new SEOrder();
                        entity.OrderFO = ldBackOrder.OrderFO;
                        entity.OrderJobName = ldBackOrder.OrderJobName;
                        entity.OrderPurchaser = ldBackOrder.OrderPurchaser;
                        se0085CtEntities1.SEOrders.Add(entity);
                        se0085CtEntities1.SaveChanges();
                    }
                    else if (source2.Count<SEOrder>() == 1)
                    {
                        entity = source2.First<SEOrder>();
                        if (!(Operators.CompareString(entity.OrderJobName, ldBackOrder.OrderJobName, false) == 0 & Operators.CompareString(entity.OrderPurchaser, ldBackOrder.OrderPurchaser, false) == 0))
                        {
                            if (!ldBackOrder.OrderJobName.Contains("Part"))
                            {
                                entity.OrderJobName = ldBackOrder.OrderJobName;
                            }
                            entity.OrderPurchaser = ldBackOrder.OrderPurchaser;
                            se0085CtEntities1.SaveChanges();
                        }
                    }
                    else
                    {
                        int num2 = (int)Interaction.MsgBox((object)("Multiple Order numbers found, aborting MES import for Order; " + ldBackOrder.OrderFO), MsgBoxStyle.Information, (object)"ONE QMS MES Import Error - E0001");
                        return;
                    }


                    //IQueryable<OrderLine> source3 = (IQueryable<OrderLine>)Queryable.Select(Queryable.Where((IQueryable<M0>)Queryable.Join((IQueryable<M0>)se0085CtEntities1.SEOrders, (IEnumerable<M1>)se0085CtEntities1.OrderLines, (Expression<Func<M0, M2>>)(o => o.OrderId), (Expression<Func<M1, M2>>)(l => l.SEOrder.OrderId), (Expression<Func<M0, M1, M3>>)((o, l) => new { o = o, l = l })), (Expression<Func<M0, bool>>)(data => Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Operators.CompareString)), data.o.OrderFO, closure95.ldBackOrder.OrderFO, false) == 0 & Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Operators.CompareString)), data.l.OrderLineNum, closure95.ldBackOrder.OrderLineNum, false) == 0 & Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Operators.CompareString)), data.l.OrderLineSL, closure95.ldBackOrder.OrderLineSL, false) == 0 & Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Operators.CompareString)), data.l.OrderLineSS, closure95.ldBackOrder.OrderLineSS, false) == 0)), (Expression<Func<M0, M1>>)(data => data.l));
                    
                    IQueryable<OrderLine> source3 = (from or in se0085CtEntities1.SEOrders
                                                     join ol in se0085CtEntities1.OrderLines
                                                     on or.OrderId equals ol.SEOrder.OrderId
                                                     where string.Equals(or.OrderFO, ldBackOrder.OrderFO)
                                                     && string.Equals(ol.OrderLineNum,ldBackOrder.OrderLineNum)
                                                     && string.Equals(ol.OrderLineSL,ldBackOrder.OrderLineSL)
                                                     && string.Equals(ol.OrderLineSS,ldBackOrder.OrderLineSS)
                                                     select new OrderLine
                                                     {
                                                         OrderLineId = ol.OrderLineId,
                                                         OrderId = or.OrderId,
                                                         AssemLineId = ol.AssemLineId,
                                                         OrderLineNum =ol.OrderLineNum,
                                                         OrderLineQty = ol.OrderLineQty,
                                                         OrderLineSL = ol.OrderLineSL,
                                                         OrderLineSS = ol.OrderLineSS,
                                                         OrderLineTargetDt = ol.OrderLineTargetDt,
                                                         OrderLineShipDt = ol.OrderLineShipDt,
                                                         OrderLineShippedDt = ol.OrderLineShippedDt,
                                                         OrderLineShipped = ol.OrderLineShipped,
                                                         OrderLineSER = ol.OrderLineSER,
                                                         OrderLineAssyStartDt = ol.OrderLineAssyStartDt,
                                                     }).AsQueryable<OrderLine>();
                    DateTime? nullable1;
                    bool? nullable2;
                    bool? nullable3;
                    bool? nullable4;
                    bool? nullable5;
                    bool? nullable6;
                    bool? nullable7;
                    bool? nullable8;
                    bool? nullable9;
                    bool? nullable10;
                    DateTime? nullable11;

                    //BLOCK 2 STARTS
                    if (source3.Count<OrderLine>() == 0)
                      {
                        if (DateTime.Compare(ldBackOrder.OrderLineShipDt, Conversions.ToDate("12/31/2039")) == 0)
                          return;
                        ldOrderLine = new OrderLine();
                        ldOrderLine.OrderLineNum = ldBackOrder.OrderLineNum;
                        ldOrderLine.OrderLineQty = (int?) ldBackOrder.OrderLineQty;
                        ldOrderLine.OrderLineShipDt = (DateTime?) ldBackOrder.OrderLineShipDt;
                        ldOrderLine.OrderLineShipped = (bool?) ldBackOrder.OrderLineShipped;
                        ldOrderLine.OrderLineShippedDt = (DateTime?) ldBackOrder.OrderLineShippedDt;
                        ldOrderLine.OrderLineSL = ldBackOrder.OrderLineSL;
                        ldOrderLine.OrderLineSS = ldBackOrder.OrderLineSS;
                        ldOrderLine.OrderLineTargetDt = (DateTime?) ldBackOrder.OrderLineTargetDt;
                        ldOrderLine.OrderLineAssyStartDt = (DateTime?) ldBackOrder.OrderLineOrgAssyStDt;
                        entity.OrderLines.Add(ldOrderLine);
                        assemblyLine.OrderLines.Add(ldOrderLine);

                        int num2 = 1;
                        int ordSectsCnt = ldBackOrder.OrdSectsCnt;
                        int ldCounter01 = num2;
                        while (ldCounter01 <= ordSectsCnt)
                        {
                          ldOrderLine.OrdSections.Add(new OrdSection()
                          {
                            OrdSectsNum = ldCounter01,
                            OrdSectShipSpt = (int?) 0,
                            OrdSectsRelActDt = (DateTime?) Conversions.ToDate("01/01/1901"),
                            OrdSectsRelSchDt = (DateTime?) Conversions.ToDate("01/01/1901"),
                            OrdSectsFabActDt = (DateTime?) Conversions.ToDate("01/01/1901"),
                            OrdSectsFabSchDt = (DateTime?) Conversions.ToDate("01/01/1901"),
                            OrdSectsRelMfg = (DateTime?) Conversions.ToDate("01/01/1901")
                          });
                          checked { ++ldCounter01; }
                        }
                        se0085CtEntities1.SaveChanges();
                      }
                      else if (source3.Count<OrderLine>() == 1)
                      {
                        ldOrderLine = source3.First<OrderLine>();
                        ldOrderLine.OrderLineQty = (int?) ldBackOrder.OrderLineQty;
                        DateTime orderLineShipDt1 = ldBackOrder.OrderLineShipDt;
                        nullable1 = ldOrderLine.OrderLineShipDt;
                        bool? nullable12;
                        if (!nullable1.HasValue)
                        {
                          nullable12 = new bool?();
                        }
                        else
                        {
                          nullable2 = new bool?(DateTime.Compare(nullable1.GetValueOrDefault(), orderLineShipDt1) == 0);
                          nullable12 = nullable2;
                        }
                        nullable3 = nullable12;
                        DateTime date1 = Conversions.ToDate("01/01/1901");
                        DateTime? orderLineShipDt2 = ldOrderLine.OrderLineShipDt;
                        bool? nullable13;
                        if (!orderLineShipDt2.HasValue)
                        {
                          nullable13 = new bool?();
                        }
                        else
                        {
                          nullable4 = new bool?(DateTime.Compare(orderLineShipDt2.GetValueOrDefault(), date1) == 0);
                          nullable13 = nullable4;
                        }
                        nullable5 = nullable13;
                        bool? nullable14;
                        if (!nullable3.HasValue || !nullable3.GetValueOrDefault())
                        {
                          if (!nullable5.HasValue)
                            nullable14 = new bool?();
                          else if (!nullable5.GetValueOrDefault())
                          {
                            nullable14 = nullable3;
                          }
                          else
                          {
                            nullable6 = new bool?(true);
                            nullable14 = nullable6;
                          }
                        }
                        else
                        {
                          nullable7 = new bool?(true);
                          nullable14 = nullable7;
                        }
                        nullable8 = nullable14;
                        bool? nullable15;
                        if (!nullable8.HasValue)
                        {
                          nullable15 = new bool?();
                        }
                        else
                        {
                          nullable9 = new bool?(!nullable8.GetValueOrDefault());
                          nullable15 = nullable9;
                        }
                        nullable10 = nullable15;
                        if (nullable10.GetValueOrDefault())
                        {
                          clsLogWriter lcLogWriter = this.lcLogWriter;
                          string[] strArray1 = new string[6]
                          {
                            "Order ",
                             ldBackOrder.FOLineSLSS,
                            " Data Changed - Current Ship Date From; ",
                            null,
                            null,
                            null
                          };
                          string[] strArray2 = strArray1;
                          int index = 3;
                          nullable11 = ldOrderLine.OrderLineShipDt;
                          string str2 = nullable11.HasValue ? Conversions.ToString(nullable11.GetValueOrDefault()) : (string) null;
                          strArray2[index] = str2;
                          strArray1[4] = " To: ";
                          strArray1[5] = Conversions.ToString(ldBackOrder.OrderLineShipDt);
                          string logMessage = string.Concat(strArray1);
                          lcLogWriter.logData(logMessage);
                        }
                        ldOrderLine.OrderLineShipDt = (DateTime?) ldBackOrder.OrderLineShipDt;
                        ldOrderLine.OrderLineShipped = (bool?) ldBackOrder.OrderLineShipped;
                        DateTime orderLineShippedDt1 = ldBackOrder.OrderLineShippedDt;
                        nullable11 = ldOrderLine.OrderLineShippedDt;
                        bool? nullable16;
                        if (!nullable11.HasValue)
                        {
                          nullable16 = new bool?();
                        }
                        else
                        {
                          nullable8 = new bool?(DateTime.Compare(nullable11.GetValueOrDefault(), orderLineShippedDt1) == 0);
                          nullable16 = nullable8;
                        }
                        nullable6 = nullable16;
                        DateTime date2 = Conversions.ToDate("01/01/1901");
                        DateTime? orderLineShippedDt2 = ldOrderLine.OrderLineShippedDt;
                        bool? nullable17;
                        if (!orderLineShippedDt2.HasValue)
                        {
                          nullable17 = new bool?();
                        }
                        else
                        {
                          nullable10 = new bool?(DateTime.Compare(orderLineShippedDt2.GetValueOrDefault(), date2) == 0);
                          nullable17 = nullable10;
                        }
                        nullable5 = nullable17;
                        bool? nullable18;
                        if (!nullable6.HasValue || !nullable6.GetValueOrDefault())
                        {
                          if (!nullable5.HasValue)
                            nullable18 = new bool?();
                          else if (!nullable5.GetValueOrDefault())
                          {
                            nullable18 = nullable6;
                          }
                          else
                          {
                            nullable3 = new bool?(true);
                            nullable18 = nullable3;
                          }
                        }
                        else
                        {
                          nullable9 = new bool?(true);
                          nullable18 = nullable9;
                        }
                        nullable2 = nullable18;
                        bool? nullable19;
                        if (!nullable2.HasValue)
                        {
                          nullable19 = new bool?();
                        }
                        else
                        {
                          nullable7 = new bool?(!nullable2.GetValueOrDefault());
                          nullable19 = nullable7;
                        }
                        nullable4 = nullable19;
                        if (nullable4.GetValueOrDefault())
                        {
                          clsLogWriter lcLogWriter = this.lcLogWriter;
                          string[] strArray1 = new string[6]
                          {
                            "Order ",
                            ldBackOrder.FOLineSLSS,
                            " Data Changed - Shipped Date From; ",
                            null,
                            null,
                            null
                          };
                          string[] strArray2 = strArray1;
                          int index = 3;
                          nullable1 = ldOrderLine.OrderLineShippedDt;
                          string str2 = nullable1.HasValue ? Conversions.ToString(nullable1.GetValueOrDefault()) : (string) null;
                          strArray2[index] = str2;
                          strArray1[4] = " To: ";
                          strArray1[5] = Conversions.ToString(ldBackOrder.OrderLineShippedDt);
                          string logMessage = string.Concat(strArray1);
                          lcLogWriter.logData(logMessage);
                        }
                        ldOrderLine.OrderLineShippedDt = (DateTime?) ldBackOrder.OrderLineShippedDt;
                        DateTime orderLineTargetDt1 = ldBackOrder.OrderLineTargetDt;
                        nullable11 = ldOrderLine.OrderLineTargetDt;
                        bool? nullable20;
                        if (!nullable11.HasValue)
                        {
                          nullable20 = new bool?();
                        }
                        else
                        {
                          nullable8 = new bool?(DateTime.Compare(nullable11.GetValueOrDefault(), orderLineTargetDt1) == 0);
                          nullable20 = nullable8;
                        }
                        nullable6 = nullable20;
                        DateTime date3 = Conversions.ToDate("01/01/1901");
                        DateTime? orderLineTargetDt2 = ldOrderLine.OrderLineTargetDt;
                        bool? nullable21;
                        if (!orderLineTargetDt2.HasValue)
                        {
                          nullable21 = new bool?();
                        }
                        else
                        {
                          nullable10 = new bool?(DateTime.Compare(orderLineTargetDt2.GetValueOrDefault(), date3) == 0);
                          nullable21 = nullable10;
                        }
                        nullable5 = nullable21;
                        bool? nullable22;
                        if (!nullable6.HasValue || !nullable6.GetValueOrDefault())
                        {
                          if (!nullable5.HasValue)
                            nullable22 = new bool?();
                          else if (!nullable5.GetValueOrDefault())
                          {
                            nullable22 = nullable6;
                          }
                          else
                          {
                            nullable3 = new bool?(true);
                            nullable22 = nullable3;
                          }
                        }
                        else
                        {
                          nullable9 = new bool?(true);
                          nullable22 = nullable9;
                        }
                        nullable2 = nullable22;
                        bool? nullable23;
                        if (!nullable2.HasValue)
                        {
                          nullable23 = new bool?();
                        }
                        else
                        {
                          nullable7 = new bool?(!nullable2.GetValueOrDefault());
                          nullable23 = nullable7;
                        }
                        nullable4 = nullable23;
                        if (nullable4.GetValueOrDefault())
                        {
                          clsLogWriter lcLogWriter = this.lcLogWriter;
                          string[] strArray1 = new string[6]
                          {
                            "Order ",
                            ldBackOrder.FOLineSLSS,
                            " Data Changed - MES/Org Target Date From; ",
                            null,
                            null,
                            null
                          };
                          string[] strArray2 = strArray1;
                          int index = 3;
                          nullable1 = ldOrderLine.OrderLineTargetDt;
                          string str2 = nullable1.HasValue ? Conversions.ToString(nullable1.GetValueOrDefault()) : (string) null;
                          strArray2[index] = str2;
                          strArray1[4] = " To: ";
                          strArray1[5] = Conversions.ToString(ldBackOrder.OrderLineTargetDt);
                          string logMessage = string.Concat(strArray1);
                          lcLogWriter.logData(logMessage);
                        }
                        ldOrderLine.OrderLineTargetDt = (DateTime?) ldBackOrder.OrderLineTargetDt;
                        DateTime orderLineOrgAssyStDt = ldBackOrder.OrderLineOrgAssyStDt;
                        nullable11 = ldOrderLine.OrderLineAssyStartDt;
                        bool? nullable24;
                        if (!nullable11.HasValue)
                        {
                          nullable24 = new bool?();
                        }
                        else
                        {
                          nullable8 = new bool?(DateTime.Compare(nullable11.GetValueOrDefault(), orderLineOrgAssyStDt) == 0);
                          nullable24 = nullable8;
                        }
                        nullable6 = nullable24;
                        DateTime date4 = Conversions.ToDate("01/01/1901");
                        DateTime? orderLineAssyStartDt = ldOrderLine.OrderLineAssyStartDt;
                        bool? nullable25;
                        if (!orderLineAssyStartDt.HasValue)
                        {
                          nullable25 = new bool?();
                        }
                        else
                        {
                          nullable10 = new bool?(DateTime.Compare(orderLineAssyStartDt.GetValueOrDefault(), date4) == 0);
                          nullable25 = nullable10;
                        }
                        nullable5 = nullable25;
                        bool? nullable26;
                        if (!nullable6.HasValue || !nullable6.GetValueOrDefault())
                        {
                          if (!nullable5.HasValue)
                            nullable26 = new bool?();
                          else if (!nullable5.GetValueOrDefault())
                          {
                            nullable26 = nullable6;
                          }
                          else
                          {
                            nullable3 = new bool?(true);
                            nullable26 = nullable3;
                          }
                        }
                        else
                        {
                          nullable9 = new bool?(true);
                          nullable26 = nullable9;
                        }
                        nullable2 = nullable26;
                        bool? nullable27;
                        if (!nullable2.HasValue)
                        {
                          nullable27 = new bool?();
                        }
                        else
                        {
                          nullable7 = new bool?(!nullable2.GetValueOrDefault());
                          nullable27 = nullable7;
                        }
                        nullable4 = nullable27;
                        if (nullable4.GetValueOrDefault())
                        {
                          clsLogWriter lcLogWriter = this.lcLogWriter;
                          string[] strArray1 = new string[6]
                          {
                            "Order ",
                            ldBackOrder.FOLineSLSS,
                            " Data Changed - Orig Assembly Start Date From; ",
                            null,
                            null,
                            null
                          };
                          string[] strArray2 = strArray1;
                          int index = 3;
                          nullable1 = ldOrderLine.OrderLineAssyStartDt;
                          string str2 = nullable1.HasValue ? Conversions.ToString(nullable1.GetValueOrDefault()) : (string) null;
                          strArray2[index] = str2;
                          strArray1[4] = " To: ";
                          strArray1[5] = Conversions.ToString(ldBackOrder.OrderLineOrgAssyStDt);
                          string logMessage = string.Concat(strArray1);
                          lcLogWriter.logData(logMessage);
                        }
                        ldOrderLine.OrderLineAssyStartDt = (DateTime?) ldBackOrder.OrderLineOrgAssyStDt;
                        se0085CtEntities1.SaveChanges();
                        //Database changes occurs

                        if (ldBackOrder.OrdSectsCnt > 0)
                        {
                          //ParameterExpression parameterExpression2;
                          //if (((IQueryable<OrdSection>) Queryable.Select<OrdSection, OrdSection>(Queryable.Where<OrdSection>((IQueryable<M0>) se0085CtEntities1.OrdSections, (Expression<Func<M0, bool>>) Expression.Lambda<Func<OrdSection, bool>>((Expression) Expression.Equal(s.OrderLine.OrderLineId, closure96.ldOrderLine.OrderLineId, true, (MethodInfo) null), new ParameterExpression[1]
                          //{
                          //  parameterExpression2
                          //})), (Expression<Func<M0, M1>>) (s => s))).Count<OrdSection>() == 0)
                         if((from s in se0085CtEntities1.OrdSections where string.Equals(s.OrderLine.OrderLineId,ldOrderLine.OrderLineId) select s).ToList().Count() == 0)
                          {
                            int num2 = 1;
                            int ordSectsCnt = ldBackOrder.OrdSectsCnt;
                            int ldCounter01 = num2;
                            while (ldCounter01 <= ordSectsCnt)
                            {
                              //ParameterExpression parameterExpression3;
                              //IQueryable<OrdSection> source4 = (IQueryable<OrdSection>) Queryable.Select<OrdSection, OrdSection>(Queryable.Where<OrdSection>((IQueryable<M0>) se0085CtEntities1.OrdSections, (Expression<Func<M0, bool>>) Expression.Lambda<Func<OrdSection, bool>>((Expression) Expression.And((Expression) Expression.Equal(s.OrderLine.OrderLineId, closure96.ldOrderLine.OrderLineId, true, (MethodInfo) null), (Expression) Expression.Equal((Expression) Expression.Property((Expression) parameterExpression3, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (OrdSection.get_OrdSectsNum))), (Expression) Expression.Field((Expression) Expression.Constant((object) closure95, typeof (clsBackorders._Closure\u0024__95)), FieldInfo.GetFieldFromHandle(__fieldref (clsBackorders._Closure\u0024__95.ldCounter01))), true, (MethodInfo) null)), new ParameterExpression[1]
                              //{
                              //  parameterExpression3
                              //})), (Expression<Func<M0, M1>>) (s => s));

                              IQueryable<OrdSection> source4 = (from os in se0085CtEntities1.OrdSections
                                                               where string.Equals(os.OrderLine.OrderLineId,ldOrderLine.OrderLineId)
                                                               select new OrdSection
                                                               {
                                                                   OrdSectsNum=os.OrdSectsNum
                                                               }).AsQueryable<OrdSection>();

                              if (source4 != null && source4.Count<OrdSection>() == 0)
                              {
                                ldOrderLine.OrdSections.Add(new OrdSection()
                                {
                                  OrdSectsNum = ldCounter01
                                });
                                se0085CtEntities1.SaveChanges();
                              }
                              checked { ++ldCounter01; }
                            }
                          }
                        }


                        //ParameterExpression parameterExpression4;
                        //IQueryable<AnonymousType_44<Associate, AssocAssignType>> source5 = Queryable.Select(Queryable.Where((IQueryable<M0>) Queryable.Join((IQueryable<M0>) Queryable.Join((IQueryable<M0>) se0085CtEntities1.AssocLookups, (IEnumerable<M1>) se0085CtEntities1.AssocAssignTypes, (Expression<Func<M0, M2>>) (o => o.AssocAssignType.AssocAssignTypeId), (Expression<Func<M1, M2>>) (t => t.AssocAssignTypeId), (Expression<Func<M0, M1, M3>>) ((o, t) => new{ o = o, t = t })), (IEnumerable<M1>) se0085CtEntities1.Associates, (Expression<Func<M0, M2>>) (data => data.o.Associate.AssocId), (Expression<Func<M1, M2>>) (a => a.AssocId), (Expression<Func<M0, M1, M3>>) ((data, a) => new
                        //{
                        //  o = data.o,
                        //  t = data.t,
                        //  a = a
                        //})), (Expression<Func<M0, bool>>) Expression.Lambda<Func<AnonymousType_43<AssocLookup, AssocAssignType, Associate>, bool>>((Expression) Expression.And(Expression.Call((Expression) null, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (Operators.CompareString)), It.o.AssocLookupField, closure95.ldBackOrder.OrderLineOE.AssocLaborName, false) == 0, (Expression) Expression.Equal(It.t.AssocAssignTypeValue, 1, true, (MethodInfo) null)), new ParameterExpression[1]
                        //{
                        //  parameterExpression4
                        //})), (Expression<Func<M0, M1>>) (data => new{ a = data.a, t = data.t }));

                        IQueryable<Associate> source5 = (from al in se0085CtEntities1.AssocLookups
                                    join at in se0085CtEntities1.AssocAssignTypes
                                    on al.AssocAssignTypeId equals at.AssocAssignTypeId
                                    join ae in se0085CtEntities1.Associates
                                    on al.AssocId equals ae.AssocId
                                    where at.AssocAssignTypeValue == 1
                                    select new Associate
                                    {
                                        AssocId = ae.AssocId,
                                        AssocEmpId = ae.AssocEmpId,
                                        AssocLaborName = ae.AssocLaborName,
                                        AssocFirstName = ae.AssocFirstName,
                                        AssocLastName = ae.AssocLastName,
                                        AssocLogin = ae.AssocLogin,
                                        AssocSESA = ae.AssocSESA,
                                        AssocUserPriv = ae.AssocUserPriv,
                                        AssocEmail = ae.AssocEmail,
                                        AssocQCInsp = ae.AssocQCInsp,
                                        AssocActive = ae.AssocActive,
                                        AssocPhone = ae.AssocPhone,
                                        AssocExt = ae.AssocExt
                                    }).AsQueryable<Associate>();

                          IQueryable<AssocAssignType> src5 = (from al in se0085CtEntities1.AssocLookups
                                    join at in se0085CtEntities1.AssocAssignTypes
                                    on al.AssocAssignTypeId equals at.AssocAssignTypeId
                                    join ae in se0085CtEntities1.Associates
                                    on al.AssocId equals ae.AssocId
                                    where at.AssocAssignTypeValue == 1
                                    select new AssocAssignType
                                    {
                                        AssocAssignTypeId = at.AssocAssignTypeId,
                                        AssocAssignTypeDesc = at.AssocAssignTypeDesc,
                                        AssocAssignTypeCode = at.AssocAssignTypeCode,
                                        AssocAssignTypeActive = at.AssocAssignTypeActive,
                                        AssocAssignTypeValue = at.AssocAssignTypeValue
                                    }).AsQueryable<AssocAssignType>();


                        if (source5 != null && source5.Count() > 0 && src5 != null && src5.Count() > 0)
                        {
                          // ISSUE: object of a compiler-generated type is created
                          // ISSUE: variable of a compiler-generated type
                          //clsBackorders._Closure\u0024__95._Closure\u0024__96._Closure\u0024__97 closure97 = new clsBackorders._Closure\u0024__95._Closure\u0024__96._Closure\u0024__97();
                          // ISSUE: reference to a compiler-generated field
                          Associate ldOEAssoc = new Associate();
                          // ISSUE: reference to a compiler-generated field
                          AssocAssignType ldOEAssignType = new AssocAssignType();
                          // ISSUE: reference to a compiler-generated field
                          //ldOEAssoc = source5.First().a;
                          //ldOEAssignType = source5.First().t;
                          ldOEAssoc = source5.First();
                          ldOEAssignType = src5.First();
                          
                          //ParameterExpression parameterExpression2;
                          //if (((IQueryable<OrdLineAssocAssigned>) Queryable.Select<OrdLineAssocAssigned, OrdLineAssocAssigned>(Queryable.Where<OrdLineAssocAssigned>((IQueryable<M0>) se0085CtEntities1.OrdLineAssocAssigneds, (Expression<Func<M0, bool>>) Expression.Lambda<Func<OrdLineAssocAssigned, bool>>((Expression) Expression.And((Expression) Expression.And((Expression) Expression.Equal(q.Associate.AssocId, closure97.ldOEAssoc.AssocId, true, (MethodInfo) null), (Expression) Expression.Equal((Expression) Expression.Property((Expression) Expression.Property((Expression) parameterExpression2, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (OrdLineAssocAssigned.get_AssocAssignType))), (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (AssocAssignType.get_AssocAssignTypeId))), (Expression) Expression.Property((Expression) Expression.Field((Expression) Expression.Constant((object) closure97, typeof (clsBackorders._Closure\u0024__95._Closure\u0024__96._Closure\u0024__97)), FieldInfo.GetFieldFromHandle(__fieldref (clsBackorders._Closure\u0024__95._Closure\u0024__96._Closure\u0024__97.ldOEAssignType))), (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (AssocAssignType.get_AssocAssignTypeId))), true, (MethodInfo) null)), (Expression) Expression.Equal((Expression) Expression.Property((Expression) Expression.Property((Expression) parameterExpression2, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (OrdLineAssocAssigned.get_OrderLine))), (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (OrderLine.get_OrderLineId))), (Expression) Expression.Property((Expression) Expression.Field((Expression) Expression.Constant((object) closure96, typeof (clsBackorders._Closure\u0024__95._Closure\u0024__96)), FieldInfo.GetFieldFromHandle(__fieldref (clsBackorders._Closure\u0024__95._Closure\u0024__96.ldOrderLine))), (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (OrderLine.get_OrderLineId))), true, (MethodInfo) null)), new ParameterExpression[1]
                          //{
                          //  parameterExpression2
                          //})), (Expression<Func<M0, M1>>) (q => q))).Count<OrdLineAssocAssigned>() == 0)
                        IQueryable<OrdLineAssocAssigned> src51 = (from or in se0085CtEntities1.OrdLineAssocAssigneds
                                                            where string.Equals(or.Associate.AssocId,ldOEAssoc.AssocId)
                                                            select new OrdLineAssocAssigned
                                                            {
                                                                AssocAsgId = or.AssocAsgId,
                                                                AssocId = or.AssocId,
                                                                OrderLineId = or.OrderLineId,
                                                                AssocAssignTypeId = or.AssocAssignTypeId
                                                            }).AsQueryable<OrdLineAssocAssigned>();
                        if(src51 != null && src51.Count() == 0)
                          {
                            se0085CtEntities1.OrdLineAssocAssigneds.Add(new OrdLineAssocAssigned()
                            {
                              Associate = ldOEAssoc,
                              AssocAssignType = ldOEAssignType,
                              OrderLine = ldOrderLine
                            });
                            se0085CtEntities1.SaveChanges();
                          }
                          ldOEAssoc = (Associate) null;
                          ldOEAssignType = (AssocAssignType) null;
                        }


                        //ParameterExpression parameterExpression5;
                        //IQueryable<AnonymousType_44<Associate, AssocAssignType>> source6 = Queryable.Select(Queryable.Where((IQueryable<M0>) Queryable.Join((IQueryable<M0>) Queryable.Join((IQueryable<M0>) se0085CtEntities1.AssocLookups, (IEnumerable<M1>) se0085CtEntities1.AssocAssignTypes, (Expression<Func<M0, M2>>) (o => o.AssocAssignType.AssocAssignTypeId), (Expression<Func<M1, M2>>) (t => t.AssocAssignTypeId), (Expression<Func<M0, M1, M3>>) ((o, t) => new{ o = o, t = t })), (IEnumerable<M1>) se0085CtEntities1.Associates, (Expression<Func<M0, M2>>) (data => data.o.Associate.AssocId), (Expression<Func<M1, M2>>) (a => a.AssocId), (Expression<Func<M0, M1, M3>>) ((data, a) => new
                        //{
                        //  o = data.o,
                        //  t = data.t,
                        //  a = a
                        //})), (Expression<Func<M0, bool>>) Expression.Lambda<Func<AnonymousType_43<AssocLookup, AssocAssignType, Associate>, bool>>((Expression) Expression.And(Expression.Call((Expression) null, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (Operators.CompareString)), It.o.AssocLookupField, closure95.ldBackOrder.OrderLineME.AssocLaborName, false) == 0, (Expression) Expression.Equal(It.t.AssocAssignTypeValue, 2, true, (MethodInfo) null)), new ParameterExpression[1]
                        //{
                        //  parameterExpression5
                        //})), (Expression<Func<M0, M1>>) (data => new{ a = data.a, t = data.t }));

                          IQueryable<Associate> source6 = (from al in se0085CtEntities1.AssocLookups
                                    join at in se0085CtEntities1.AssocAssignTypes
                                    on al.AssocAssignTypeId equals at.AssocAssignTypeId
                                    join ae in se0085CtEntities1.Associates
                                    on al.AssocId equals ae.AssocId
                                    where at.AssocAssignTypeValue == 2
                                    select new Associate
                                    {
                                        AssocId = ae.AssocId,
                                        AssocEmpId = ae.AssocEmpId,
                                        AssocLaborName = ae.AssocLaborName,
                                        AssocFirstName = ae.AssocFirstName,
                                        AssocLastName = ae.AssocLastName,
                                        AssocLogin = ae.AssocLogin,
                                        AssocSESA = ae.AssocSESA,
                                        AssocUserPriv = ae.AssocUserPriv,
                                        AssocEmail = ae.AssocEmail,
                                        AssocQCInsp = ae.AssocQCInsp,
                                        AssocActive = ae.AssocActive,
                                        AssocPhone = ae.AssocPhone,
                                        AssocExt = ae.AssocExt
                                    }).AsQueryable<Associate>();

                          IQueryable<AssocAssignType> src6 = (from al in se0085CtEntities1.AssocLookups
                                    join at in se0085CtEntities1.AssocAssignTypes
                                    on al.AssocAssignTypeId equals at.AssocAssignTypeId
                                    join ae in se0085CtEntities1.Associates
                                    on al.AssocId equals ae.AssocId
                                    where at.AssocAssignTypeValue == 2
                                    select new AssocAssignType
                                    {
                                        AssocAssignTypeId = at.AssocAssignTypeId,
                                        AssocAssignTypeDesc = at.AssocAssignTypeDesc,
                                        AssocAssignTypeCode = at.AssocAssignTypeCode,
                                        AssocAssignTypeActive = at.AssocAssignTypeActive,
                                        AssocAssignTypeValue = at.AssocAssignTypeValue
                                    }).AsQueryable<AssocAssignType>();
                        if (source6 != null && source6.Count() > 0 && src6 != null && src6.Count() > 0)
                        {
                          //clsBackorders closure98 = new clsBackorders();
                          Associate ldMEAssoc = new Associate();
                          AssocAssignType ldMEAssignType = new AssocAssignType();
                          //closure98.ldMEAssoc = source6.First().a;
                          //closure98.ldMEAssignType = source6.First().t;
                          ldMEAssoc = source6.First();
                          ldMEAssignType = src6.First();
                          //ParameterExpression parameterExpression2;
                          //if (((IQueryable<OrdLineAssocAssigned>) Queryable.Select<OrdLineAssocAssigned, OrdLineAssocAssigned>(Queryable.Where<OrdLineAssocAssigned>((IQueryable<M0>) se0085CtEntities1.OrdLineAssocAssigneds, (Expression<Func<M0, bool>>) Expression.Lambda<Func<OrdLineAssocAssigned, bool>>((Expression) Expression.And((Expression) Expression.And((Expression) Expression.Equal(q.Associate.AssocId, closure98.ldMEAssoc.AssocId, true, (MethodInfo) null), (Expression) Expression.Equal((Expression) Expression.Property((Expression) Expression.Property((Expression) parameterExpression2, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (OrdLineAssocAssigned.get_AssocAssignType))), (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (AssocAssignType.get_AssocAssignTypeId))), (Expression) Expression.Property((Expression) Expression.Field((Expression) Expression.Constant((object) closure98, typeof (clsBackorders._Closure\u0024__95._Closure\u0024__96._Closure\u0024__98)), FieldInfo.GetFieldFromHandle(__fieldref (clsBackorders._Closure\u0024__95._Closure\u0024__96._Closure\u0024__98.ldMEAssignType))), (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (AssocAssignType.get_AssocAssignTypeId))), true, (MethodInfo) null)), (Expression) Expression.Equal((Expression) Expression.Property((Expression) Expression.Property((Expression) parameterExpression2, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (OrdLineAssocAssigned.get_OrderLine))), (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (OrderLine.get_OrderLineId))), (Expression) Expression.Property((Expression) Expression.Field((Expression) Expression.Constant((object) closure96, typeof (clsBackorders._Closure\u0024__95._Closure\u0024__96)), FieldInfo.GetFieldFromHandle(__fieldref (clsBackorders._Closure\u0024__95._Closure\u0024__96.ldOrderLine))), (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (OrderLine.get_OrderLineId))), true, (MethodInfo) null)), new ParameterExpression[1]
                          //{
                          //  parameterExpression2
                          //})), (Expression<Func<M0, M1>>) (q => q))).Count<OrdLineAssocAssigned>() == 0)
                            IQueryable<OrdLineAssocAssigned> src61 = (from or in se0085CtEntities1.OrdLineAssocAssigneds
                                                            where string.Equals(or.Associate.AssocId,ldMEAssoc.AssocId)
                                                            select new OrdLineAssocAssigned
                                                            {
                                                                AssocAsgId = or.AssocAsgId,
                                                                AssocId = or.AssocId,
                                                                OrderLineId = or.OrderLineId,
                                                                AssocAssignTypeId = or.AssocAssignTypeId
                                                            }).AsQueryable<OrdLineAssocAssigned>();
                        if(src61 != null && src61.Count() == 0)
                          {
                            se0085CtEntities1.OrdLineAssocAssigneds.Add(new OrdLineAssocAssigned()
                            {
                              Associate = ldMEAssoc,
                              AssocAssignType = ldMEAssignType,
                              OrderLine = ldOrderLine
                            });
                            se0085CtEntities1.SaveChanges();
                          }
                          ldMEAssoc = (Associate) null;
                          ldMEAssignType = (AssocAssignType) null;
                        }


                        //ParameterExpression parameterExpression6;
                        //IQueryable<AnonymousType_44<Associate, AssocAssignType>> source7 = Queryable.Select(Queryable.Where((IQueryable<M0>) Queryable.Join((IQueryable<M0>) Queryable.Join((IQueryable<M0>) se0085CtEntities1.AssocLookups, (IEnumerable<M1>) se0085CtEntities1.AssocAssignTypes, (Expression<Func<M0, M2>>) (o => o.AssocAssignType.AssocAssignTypeId), (Expression<Func<M1, M2>>) (t => t.AssocAssignTypeId), (Expression<Func<M0, M1, M3>>) ((o, t) => new{ o = o, t = t })), (IEnumerable<M1>) se0085CtEntities1.Associates, (Expression<Func<M0, M2>>) (data => data.o.Associate.AssocId), (Expression<Func<M1, M2>>) (a => a.AssocId), (Expression<Func<M0, M1, M3>>) ((data, a) => new
                        //{
                        //  o = data.o,
                        //  t = data.t,
                        //  a = a
                        //})), (Expression<Func<M0, bool>>) Expression.Lambda<Func<AnonymousType_43<AssocLookup, AssocAssignType, Associate>, bool>>((Expression) Expression.And(Expression.Call((Expression) null, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (Operators.CompareString)), It.o.AssocLookupField, closure95.ldBackOrder.OrderLineAE.AssocLaborName, false) == 0, (Expression) Expression.Equal(It.t.AssocAssignTypeValue, 3, true, (MethodInfo) null)), new ParameterExpression[1]
                        //{
                        //  parameterExpression6
                        //})), (Expression<Func<M0, M1>>) (data => new{ a = data.a, t = data.t }));

                        IQueryable<Associate> source7 = (from al in se0085CtEntities1.AssocLookups
                                    join at in se0085CtEntities1.AssocAssignTypes
                                    on al.AssocAssignTypeId equals at.AssocAssignTypeId
                                    join ae in se0085CtEntities1.Associates
                                    on al.AssocId equals ae.AssocId
                                    where at.AssocAssignTypeValue == 3
                                    select new Associate
                                    {
                                        AssocId = ae.AssocId,
                                        AssocEmpId = ae.AssocEmpId,
                                        AssocLaborName = ae.AssocLaborName,
                                        AssocFirstName = ae.AssocFirstName,
                                        AssocLastName = ae.AssocLastName,
                                        AssocLogin = ae.AssocLogin,
                                        AssocSESA = ae.AssocSESA,
                                        AssocUserPriv = ae.AssocUserPriv,
                                        AssocEmail = ae.AssocEmail,
                                        AssocQCInsp = ae.AssocQCInsp,
                                        AssocActive = ae.AssocActive,
                                        AssocPhone = ae.AssocPhone,
                                        AssocExt = ae.AssocExt
                                    }).AsQueryable<Associate>();

                          IQueryable<AssocAssignType> src7 = (from al in se0085CtEntities1.AssocLookups
                                    join at in se0085CtEntities1.AssocAssignTypes
                                    on al.AssocAssignTypeId equals at.AssocAssignTypeId
                                    join ae in se0085CtEntities1.Associates
                                    on al.AssocId equals ae.AssocId
                                    where at.AssocAssignTypeValue == 3
                                    select new AssocAssignType
                                    {
                                        AssocAssignTypeId = at.AssocAssignTypeId,
                                        AssocAssignTypeDesc = at.AssocAssignTypeDesc,
                                        AssocAssignTypeCode = at.AssocAssignTypeCode,
                                        AssocAssignTypeActive = at.AssocAssignTypeActive,
                                        AssocAssignTypeValue = at.AssocAssignTypeValue
                                    }).AsQueryable<AssocAssignType>();
                        if (source7 != null && source7.Count() > 0 && src7 != null && src7.Count() > 0)
                        {
                          Associate ldAEAssoc = new Associate();
                          AssocAssignType ldAEAssignType = new AssocAssignType();
                          ldAEAssoc = source7.First();
                          ldAEAssignType = src7.First();
                          //ParameterExpression parameterExpression2;
                          //if (((IQueryable<OrdLineAssocAssigned>) Queryable.Select<OrdLineAssocAssigned, OrdLineAssocAssigned>(Queryable.Where<OrdLineAssocAssigned>((IQueryable<M0>) se0085CtEntities1.OrdLineAssocAssigneds, (Expression<Func<M0, bool>>) Expression.Lambda<Func<OrdLineAssocAssigned, bool>>((Expression) Expression.And((Expression) Expression.And((Expression) Expression.Equal(q.Associate.AssocId, closure99.ldAEAssoc.AssocId, true, (MethodInfo) null), (Expression) Expression.Equal((Expression) Expression.Property((Expression) Expression.Property((Expression) parameterExpression2, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (OrdLineAssocAssigned.get_AssocAssignType))), (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (AssocAssignType.get_AssocAssignTypeId))), (Expression) Expression.Property((Expression) Expression.Field((Expression) Expression.Constant((object) closure99, typeof (clsBackorders._Closure\u0024__95._Closure\u0024__96._Closure\u0024__99)), FieldInfo.GetFieldFromHandle(__fieldref (clsBackorders._Closure\u0024__95._Closure\u0024__96._Closure\u0024__99.ldAEAssignType))), (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (AssocAssignType.get_AssocAssignTypeId))), true, (MethodInfo) null)), (Expression) Expression.Equal((Expression) Expression.Property((Expression) Expression.Property((Expression) parameterExpression2, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (OrdLineAssocAssigned.get_OrderLine))), (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (OrderLine.get_OrderLineId))), (Expression) Expression.Property((Expression) Expression.Field((Expression) Expression.Constant((object) closure96, typeof (clsBackorders._Closure\u0024__95._Closure\u0024__96)), FieldInfo.GetFieldFromHandle(__fieldref (clsBackorders._Closure\u0024__95._Closure\u0024__96.ldOrderLine))), (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (OrderLine.get_OrderLineId))), true, (MethodInfo) null)), new ParameterExpression[1]
                          //{
                          //  parameterExpression2
                          //})), (Expression<Func<M0, M1>>) (q => q))).Count<OrdLineAssocAssigned>() == 0)
                          IQueryable<OrdLineAssocAssigned> src71 = (from or in se0085CtEntities1.OrdLineAssocAssigneds
                                                                    where string.Equals(or.Associate.AssocId, ldAEAssoc.AssocId)
                                                                    select new OrdLineAssocAssigned
                                                                    {
                                                                        AssocAsgId = or.AssocAsgId,
                                                                        AssocId = or.AssocId,
                                                                        OrderLineId = or.OrderLineId,
                                                                        AssocAssignTypeId = or.AssocAssignTypeId
                                                                    }).AsQueryable<OrdLineAssocAssigned>();
                            if(src71 != null && src71.Count() == 0)
                            {
                                se0085CtEntities1.OrdLineAssocAssigneds.Add(new OrdLineAssocAssigned()
                                {
                                    Associate = ldAEAssoc,
                                    AssocAssignType = ldAEAssignType,
                                    OrderLine = ldOrderLine
                                });
                                se0085CtEntities1.SaveChanges();
                            }
                          ldAEAssoc = (Associate) null;
                          ldAEAssignType = (AssocAssignType) null;
                        }


                        //ParameterExpression parameterExpression7;
                        //IQueryable<AnonymousType_44<Associate, AssocAssignType>> source8 = Queryable.Select(Queryable.Where((IQueryable<M0>) Queryable.Join((IQueryable<M0>) Queryable.Join((IQueryable<M0>) se0085CtEntities1.AssocLookups, (IEnumerable<M1>) se0085CtEntities1.AssocAssignTypes, (Expression<Func<M0, M2>>) (o => o.AssocAssignType.AssocAssignTypeId), (Expression<Func<M1, M2>>) (t => t.AssocAssignTypeId), (Expression<Func<M0, M1, M3>>) ((o, t) => new{ o = o, t = t })), (IEnumerable<M1>) se0085CtEntities1.Associates, (Expression<Func<M0, M2>>) (data => data.o.Associate.AssocId), (Expression<Func<M1, M2>>) (a => a.AssocId), (Expression<Func<M0, M1, M3>>) ((data, a) => new
                        //{
                        //  o = data.o,
                        //  t = data.t,
                        //  a = a
                        //})), (Expression<Func<M0, bool>>) Expression.Lambda<Func<AnonymousType_43<AssocLookup, AssocAssignType, Associate>, bool>>((Expression) Expression.And(Expression.Call((Expression) null, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (Operators.CompareString)), It.o.AssocLookupField, closure95.ldBackOrder.OrderLineDM.AssocLaborName, false) == 0, (Expression) Expression.Equal(It.t.AssocAssignTypeValue, 4, true, (MethodInfo) null)), new ParameterExpression[1]
                        //{
                        //  parameterExpression7
                        //})), (Expression<Func<M0, M1>>) (data => new{ a = data.a, t = data.t }));
                        IQueryable<Associate> source8 = (from al in se0085CtEntities1.AssocLookups
                                                         join at in se0085CtEntities1.AssocAssignTypes
                                                         on al.AssocAssignTypeId equals at.AssocAssignTypeId
                                                         join ae in se0085CtEntities1.Associates
                                                         on al.AssocId equals ae.AssocId
                                                         where at.AssocAssignTypeValue == 4
                                                         select new Associate
                                                         {
                                                             AssocId = ae.AssocId,
                                                             AssocEmpId = ae.AssocEmpId,
                                                             AssocLaborName = ae.AssocLaborName,
                                                             AssocFirstName = ae.AssocFirstName,
                                                             AssocLastName = ae.AssocLastName,
                                                             AssocLogin = ae.AssocLogin,
                                                             AssocSESA = ae.AssocSESA,
                                                             AssocUserPriv = ae.AssocUserPriv,
                                                             AssocEmail = ae.AssocEmail,
                                                             AssocQCInsp = ae.AssocQCInsp,
                                                             AssocActive = ae.AssocActive,
                                                             AssocPhone = ae.AssocPhone,
                                                             AssocExt = ae.AssocExt
                                                         }).AsQueryable<Associate>();

                        IQueryable<AssocAssignType> src8 = (from al in se0085CtEntities1.AssocLookups
                                                            join at in se0085CtEntities1.AssocAssignTypes
                                                            on al.AssocAssignTypeId equals at.AssocAssignTypeId
                                                            join ae in se0085CtEntities1.Associates
                                                            on al.AssocId equals ae.AssocId
                                                            where at.AssocAssignTypeValue == 4
                                                            select new AssocAssignType
                                                            {
                                                                AssocAssignTypeId = at.AssocAssignTypeId,
                                                                AssocAssignTypeDesc = at.AssocAssignTypeDesc,
                                                                AssocAssignTypeCode = at.AssocAssignTypeCode,
                                                                AssocAssignTypeActive = at.AssocAssignTypeActive,
                                                                AssocAssignTypeValue = at.AssocAssignTypeValue
                                                            }).AsQueryable<AssocAssignType>();
                        if (source8 != null && source8.Count() > 0 && src8 != null && src8.Count() > 0)
                        {
                          //clsBackorders closure100 = new clsBackorders();
                          Associate ldDMAssoc = new Associate();
                          AssocAssignType ldDMAssignType = new AssocAssignType();
                          ldDMAssoc = source8.First();
                          ldDMAssignType = src8.First();
                          //ParameterExpression parameterExpression2;
                          //if (((IQueryable<OrdLineAssocAssigned>) Queryable.Select<OrdLineAssocAssigned, OrdLineAssocAssigned>(Queryable.Where<OrdLineAssocAssigned>((IQueryable<M0>) se0085CtEntities1.OrdLineAssocAssigneds, (Expression<Func<M0, bool>>) Expression.Lambda<Func<OrdLineAssocAssigned, bool>>((Expression) Expression.And((Expression) Expression.And((Expression) Expression.Equal(q.Associate.AssocId, closure100.ldDMAssoc.AssocId, true, (MethodInfo) null), (Expression) Expression.Equal((Expression) Expression.Property((Expression) Expression.Property((Expression) parameterExpression2, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (OrdLineAssocAssigned.get_AssocAssignType))), (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (AssocAssignType.get_AssocAssignTypeId))), (Expression) Expression.Property((Expression) Expression.Field((Expression) Expression.Constant((object) closure100, typeof (clsBackorders._Closure\u0024__95._Closure\u0024__96._Closure\u0024__100)), FieldInfo.GetFieldFromHandle(__fieldref (clsBackorders._Closure\u0024__95._Closure\u0024__96._Closure\u0024__100.ldDMAssignType))), (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (AssocAssignType.get_AssocAssignTypeId))), true, (MethodInfo) null)), (Expression) Expression.Equal((Expression) Expression.Property((Expression) Expression.Property((Expression) parameterExpression2, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (OrdLineAssocAssigned.get_OrderLine))), (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (OrderLine.get_OrderLineId))), (Expression) Expression.Property((Expression) Expression.Field((Expression) Expression.Constant((object) closure96, typeof (clsBackorders._Closure\u0024__95._Closure\u0024__96)), FieldInfo.GetFieldFromHandle(__fieldref (clsBackorders._Closure\u0024__95._Closure\u0024__96.ldOrderLine))), (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (OrderLine.get_OrderLineId))), true, (MethodInfo) null)), new ParameterExpression[1]
                          //{
                          //  parameterExpression2
                          //})), (Expression<Func<M0, M1>>) (q => q))).Count<OrdLineAssocAssigned>() == 0)
                            IQueryable<OrdLineAssocAssigned> src81 = (from or in se0085CtEntities1.OrdLineAssocAssigneds
                                                                      where string.Equals(or.Associate.AssocId, ldDMAssoc.AssocId)
                                                                    select new OrdLineAssocAssigned
                                                                    {
                                                                        AssocAsgId = or.AssocAsgId,
                                                                        AssocId = or.AssocId,
                                                                        OrderLineId = or.OrderLineId,
                                                                        AssocAssignTypeId = or.AssocAssignTypeId
                                                                    }).AsQueryable<OrdLineAssocAssigned>();
                          if(src81 != null && src81.Count() == 0)
                          {
                            se0085CtEntities1.OrdLineAssocAssigneds.Add(new OrdLineAssocAssigned()
                            {
                              Associate = ldDMAssoc,
                              AssocAssignType = ldDMAssignType,
                              OrderLine = ldOrderLine
                            });
                            se0085CtEntities1.SaveChanges();
                          }
                          ldDMAssoc = (Associate) null;
                          ldDMAssignType = (AssocAssignType) null;
                        }

                        //ParameterExpression parameterExpression8;
                        //IQueryable<AnonymousType_44<Associate, AssocAssignType>> source9 = Queryable.Select(Queryable.Where((IQueryable<M0>) Queryable.Join((IQueryable<M0>) Queryable.Join((IQueryable<M0>) se0085CtEntities1.AssocLookups, (IEnumerable<M1>) se0085CtEntities1.AssocAssignTypes, (Expression<Func<M0, M2>>) (o => o.AssocAssignType.AssocAssignTypeId), (Expression<Func<M1, M2>>) (t => t.AssocAssignTypeId), (Expression<Func<M0, M1, M3>>) ((o, t) => new{ o = o, t = t })), (IEnumerable<M1>) se0085CtEntities1.Associates, (Expression<Func<M0, M2>>) (data => data.o.Associate.AssocId), (Expression<Func<M1, M2>>) (a => a.AssocId), (Expression<Func<M0, M1, M3>>) ((data, a) => new
                        //{
                        //  o = data.o,
                        //  t = data.t,
                        //  a = a
                        //})), (Expression<Func<M0, bool>>) Expression.Lambda<Func<AnonymousType_43<AssocLookup, AssocAssignType, Associate>, bool>>((Expression) Expression.And(Expression.Call((Expression) null, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (Operators.CompareString)), It.o.AssocLookupField, closure95.ldBackOrder.OrderLineCSR.AssocLaborName, false) == 0, (Expression) Expression.Equal(It.t.AssocAssignTypeValue, 5, true, (MethodInfo) null)), new ParameterExpression[1]
                        //{
                        //  parameterExpression8
                        //})), (Expression<Func<M0, M1>>) (data => new{ a = data.a, t = data.t }));


                        IQueryable<Associate> source9 = (from al in se0085CtEntities1.AssocLookups
                                                         join at in se0085CtEntities1.AssocAssignTypes
                                                         on al.AssocAssignTypeId equals at.AssocAssignTypeId
                                                         join ae in se0085CtEntities1.Associates
                                                         on al.AssocId equals ae.AssocId
                                                         where at.AssocAssignTypeValue == 5
                                                         select new Associate
                                                         {
                                                             AssocId = ae.AssocId,
                                                             AssocEmpId = ae.AssocEmpId,
                                                             AssocLaborName = ae.AssocLaborName,
                                                             AssocFirstName = ae.AssocFirstName,
                                                             AssocLastName = ae.AssocLastName,
                                                             AssocLogin = ae.AssocLogin,
                                                             AssocSESA = ae.AssocSESA,
                                                             AssocUserPriv = ae.AssocUserPriv,
                                                             AssocEmail = ae.AssocEmail,
                                                             AssocQCInsp = ae.AssocQCInsp,
                                                             AssocActive = ae.AssocActive,
                                                             AssocPhone = ae.AssocPhone,
                                                             AssocExt = ae.AssocExt
                                                         }).AsQueryable<Associate>();

                        IQueryable<AssocAssignType> src9 = (from al in se0085CtEntities1.AssocLookups
                                                            join at in se0085CtEntities1.AssocAssignTypes
                                                            on al.AssocAssignTypeId equals at.AssocAssignTypeId
                                                            join ae in se0085CtEntities1.Associates
                                                            on al.AssocId equals ae.AssocId
                                                            where at.AssocAssignTypeValue == 5
                                                            select new AssocAssignType
                                                            {
                                                                AssocAssignTypeId = at.AssocAssignTypeId,
                                                                AssocAssignTypeDesc = at.AssocAssignTypeDesc,
                                                                AssocAssignTypeCode = at.AssocAssignTypeCode,
                                                                AssocAssignTypeActive = at.AssocAssignTypeActive,
                                                                AssocAssignTypeValue = at.AssocAssignTypeValue
                                                            }).AsQueryable<AssocAssignType>();
                        if (source9 != null && source9.Count() > 0 && src9 != null && src9.Count() > 0)
                        {
                          //clsBackorders closure101 = new clsBackorders();
                          Associate ldOSAssoc = new Associate();
                          AssocAssignType ldOSAssignType = new AssocAssignType();
                          ldOSAssoc = source9.First();
                          ldOSAssignType = src9.First();
                          //ParameterExpression parameterExpression2;
                          //if (((IQueryable<OrdLineAssocAssigned>) Queryable.Select<OrdLineAssocAssigned, OrdLineAssocAssigned>(Queryable.Where<OrdLineAssocAssigned>((IQueryable<M0>) se0085CtEntities1.OrdLineAssocAssigneds, (Expression<Func<M0, bool>>) Expression.Lambda<Func<OrdLineAssocAssigned, bool>>((Expression) Expression.And((Expression) Expression.And((Expression) Expression.Equal(q.Associate.AssocId, closure101.ldOSAssoc.AssocId, true, (MethodInfo) null), (Expression) Expression.Equal((Expression) Expression.Property((Expression) Expression.Property((Expression) parameterExpression2, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (OrdLineAssocAssigned.get_AssocAssignType))), (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (AssocAssignType.get_AssocAssignTypeId))), (Expression) Expression.Property((Expression) Expression.Field((Expression) Expression.Constant((object) closure101, typeof (clsBackorders._Closure\u0024__95._Closure\u0024__96._Closure\u0024__101)), FieldInfo.GetFieldFromHandle(__fieldref (clsBackorders._Closure\u0024__95._Closure\u0024__96._Closure\u0024__101.ldOSAssignType))), (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (AssocAssignType.get_AssocAssignTypeId))), true, (MethodInfo) null)), (Expression) Expression.Equal((Expression) Expression.Property((Expression) Expression.Property((Expression) parameterExpression2, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (OrdLineAssocAssigned.get_OrderLine))), (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (OrderLine.get_OrderLineId))), (Expression) Expression.Property((Expression) Expression.Field((Expression) Expression.Constant((object) closure96, typeof (clsBackorders._Closure\u0024__95._Closure\u0024__96)), FieldInfo.GetFieldFromHandle(__fieldref (clsBackorders._Closure\u0024__95._Closure\u0024__96.ldOrderLine))), (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (OrderLine.get_OrderLineId))), true, (MethodInfo) null)), new ParameterExpression[1]
                          //{
                          //  parameterExpression2
                          //})), (Expression<Func<M0, M1>>) (q => q))).Count<OrdLineAssocAssigned>() == 0)
                          IQueryable<OrdLineAssocAssigned> src91 = (from or in se0085CtEntities1.OrdLineAssocAssigneds
                                                                    where string.Equals(or.Associate.AssocId, ldOSAssoc.AssocId)
                                                                    select new OrdLineAssocAssigned
                                                                    {
                                                                        AssocAsgId = or.AssocAsgId,
                                                                        AssocId = or.AssocId,
                                                                        OrderLineId = or.OrderLineId,
                                                                        AssocAssignTypeId = or.AssocAssignTypeId
                                                                    }).AsQueryable<OrdLineAssocAssigned>();
                          if (src91 != null && src91.Count() == 0)
                          {
                            se0085CtEntities1.OrdLineAssocAssigneds.Add(new OrdLineAssocAssigned()
                            {
                              Associate = ldOSAssoc,
                              AssocAssignType = ldOSAssignType,
                              OrderLine = ldOrderLine
                            });
                            se0085CtEntities1.SaveChanges();
                          }
                          ldOSAssoc = (Associate) null;
                          ldOSAssignType = (AssocAssignType) null;
                        }







                      }
                      else
                      {
                        int num2 = (int) Interaction.MsgBox((object) ("Multiple Order numbers found, aborting MES import for Order; " + ldBackOrder.OrderFO), MsgBoxStyle.Information, (object) "ONE QMS MES Import Error - E0001");
                        return;
                      }
                    //BLOCK 2 ENDS

                }
                else
                {
                    int num3 = (int)Interaction.MsgBox((object)("Multiple AssemblyLine Ids found, aborting MES import for AssemblyLineId; " + Conversions.ToString(ldBackOrder.AssemblyLine.LevelId)), MsgBoxStyle.Information, (object)"ONE QMS MES Import Error - E0001");
                }
            }
        }

    }
}
