using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.ComponentModel;
using System.Collections;
using Microsoft.VisualBasic.CompilerServices;

//namespace SE0085.CTdB
namespace FAS_LIB
{
    public class clsFASorders
    {
        private scPlants lmPlants;
        private scLevels lmPlantLevel;
        public event clsFASorders.ueUpdateProgressEventHandler ueUpdateProgress;

        public bool ImportFAS(string ImportFile)
        {
            StreamReader streamReader;
            bool flag1;
            try
            {
                streamReader = File.OpenText(ImportFile);
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                clsFASorders.scUpdProgress scUpdProgress = new clsFASorders.scUpdProgress(clsFASorders.emUpdateProgType.ResultStatus, "Error opening FAS Export file: " + ImportFile + "\r\n");
                clsFASorders.ueUpdateProgressEventHandler updateProgressEvent = this.ueUpdateProgress;
                if (updateProgressEvent != null)
                    updateProgressEvent((object)this, new ProgressChangedEventArgs(10, (object)scUpdProgress));
                flag1 = false;
                ProjectData.ClearProjectError();
                goto label_115;
            }
            clsEngineCTdB clsEngineCtdB = new clsEngineCTdB();
            Hashtable hashmdsq2ccd = new clsT2Q2CdB().getHashmdsq2ccd();
            clsPlant clsPlant = new clsPlant();
            this.lmPlants = clsPlant.rtnPlantByDesin("0085");
            this.lmPlants = clsPlant.rtnPlantById(1);
            this.lmPlantLevel = this.lmPlants.PlantLevel;
            clsAssemblyLine clsAssemblyLine = new clsAssemblyLine(this.lmPlants);
            List<scAssemblyLine> scAssemblyLineList1 = new List<scAssemblyLine>();
            List<scAssemblyLine> scAssemblyLineList2 = clsAssemblyLine.rtnAssemblyLines(true);
            streamReader.ReadLine().Split('\t');
            List<clsFASorders.scOrderFas> scOrderFasList = new List<clsFASorders.scOrderFas>();
            List<string> stringList1 = new List<string>();
            List<string> stringList2 = new List<string>();
            while (!streamReader.EndOfStream)
            {
                string[] strArray = streamReader.ReadLine().Split('\t');
                clsFASorders.scOrderFas scOrderFas = new clsFASorders.scOrderFas();
                if (strArray[14].Contains("MO"))
                {
                    if (strArray[15].Contains("Parent:"))
                        scOrderFas.OrderData.FOLineSLSS = strArray[15].Replace("Parent: ", "").Trim();
                }
                else
                    scOrderFas.OrderData.FactoryOrderOE = strArray[14].Trim();
                scOrderFas.OrderData.OrderJobName = strArray[11].Trim();
                if (scOrderFas.OrderData.FOFormatValid)
                {
                    if (strArray[0].Trim().StartsWith("NW") | strArray[0].Trim().StartsWith("GM") | strArray[0].Trim().StartsWith("394") | strArray[0].Trim().StartsWith("244") | strArray[0].Trim().StartsWith("252") | strArray[0].Trim().StartsWith("311"))
                    {
                        scItemMaster scItemMaster1 = new scItemMaster();
                        scItemMaster scItemMaster2 = clsEngineCtdB.rtnByAssyPartNum(strArray[0].Trim());
                        if (scItemMaster2 != null)
                        {
                            scOrderFas.OrdFASExt.OrdCatlgNbr = scItemMaster2.Description1;
                            scOrderFas.OrdFASExt.OrdMfgPartNbr = strArray[0].Trim();
                        }
                        else
                        {
                            scOrderFas.OrdFASExt.OrdCatlgNbr = strArray[0].Trim();
                            scOrderFas.OrdFASExt.OrdMfgPartNbr = strArray[1].Trim();
                        }
                    }
                    else
                    {
                        scOrderFas.OrdFASExt.OrdCatlgNbr = strArray[0].Trim();
                        scOrderFas.OrdFASExt.OrdMfgPartNbr = strArray[1].Trim();
                    }
                    scOrderFas.OrdFASExt.FASOrdQty = Conversions.ToInteger(strArray[2].Trim());
                    scOrderFas.OrdFASExt.FASUnfilledQty = Conversions.ToInteger(strArray[3].Trim());
                    scOrderFas.OrdFASExt.FASPrgrsPnt = Conversions.ToInteger(strArray[7].Trim());
                    short integer = checked((short)Conversions.ToInteger(strArray[7].Trim()));
                    scOrderFas.OrdFASExt.OrdCdDesc = hashmdsq2ccd[(object)integer].ToString().Trim();
                    scOrderFas.OrdFASExt.FASDueDt = Conversions.ToDate(strArray[12].Trim());
                    scOrderFas.OrdFASExt.FASOrdNbr = strArray[14].Trim();
                    scOrderFas.OrdFASExt.OrdProdLn = strArray[16].Trim();
                    scOrderFas.OrdFASExt.FASCmplQty = Conversions.ToInteger(strArray[17].Trim());
                    scOrderFas.OrdFASExt.FASAsmblLn = strArray[18].Trim();
                    scOrderFas.OrdFASExt.FASWorkCtr = strArray[19].Trim();
                    scOrderFasList.Add(scOrderFas);

                    //EXTRA CODE FOR TESTING
                    //if (Conversions.ToInteger(strArray[7].Trim()) >= 240)
                    //{
                    //    int x = Conversions.ToInteger(strArray[7].Trim());
                    //    DateTime dt = Conversions.ToDate(strArray[4].Trim());
                    //    string s = scOrderFas.OrdFASExt.FASOrdNbr;
                    //    int a = clsEngineCtdB.rtnOrderLineId(scOrderFas.OrderData.FOLineSLSS);
                    //}

                    
                    if (Conversions.ToInteger(strArray[7].Trim()) >= 240 & DateTime.Compare(Conversions.ToDate(strArray[4].Trim()), Conversions.ToDate("12/31/2039")) < 0 & !scOrderFas.OrdFASExt.FASOrdNbr.StartsWith("MO") && clsEngineCtdB.rtnOrderLineId(scOrderFas.OrderData.FOLineSLSS) == 0)
                    {
                        scOrderImportInfo BackOrders = new scOrderImportInfo();
                        BackOrders.SEPlant = this.lmPlants;
                        string str = "";
                        string fasAsmblLn = scOrderFas.OrdFASExt.FASAsmblLn;
                        if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(fasAsmblLn, "221", false) == 0)
                            str = "NW221C";
                        else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(fasAsmblLn, "221B", false) == 0)
                            str = "NW221B";
                        else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(fasAsmblLn, "CUKIT", false) == 0)
                            str = "221KITS";
                        else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(fasAsmblLn, "FAB", false) == 0)
                        {
                            if (scOrderFas.OrdFASExt.FASWorkCtr.Contains("221PKKIT"))
                                str = "221KITS";
                            if (scOrderFas.OrdFASExt.FASWorkCtr.Contains("221ASSEM") | scOrderFas.OrdFASExt.FASWorkCtr.Contains("221PACK"))
                                str = "221CT";
                        }
                        bool flag2 = false;
                        List<scAssemblyLine>.Enumerator enumerator;
                        if (str.Length > 0)
                        {
                           enumerator = scAssemblyLineList2.GetEnumerator();
                            try
                            {
                                while (enumerator.MoveNext())
                                {
                                    scLevels current = (scLevels)enumerator.Current;
                                    if (current.LevelAbbrv.Contains(str))
                                    {
                                        BackOrders.AssemblyLine = current;
                                        flag2 = true;
                                        break;
                                    }
                                }
                            }
                            finally
                            {
                                enumerator.Dispose();
                            }
                        }
                        if (flag2)
                        {
                            BackOrders.OrderFO = scOrderFas.OrderData.OrderFO;
                            BackOrders.OrderLineNum = scOrderFas.OrderData.OrderLineNum;
                            BackOrders.OrderLineSL = scOrderFas.OrderData.OrderLineSL;
                            BackOrders.OrderLineSS = scOrderFas.OrderData.OrderLineSS;
                            BackOrders.OrderLineShipDt = Conversions.ToDate(strArray[4].Trim());
                            BackOrders.OrderLineTargetDt = Conversions.ToDate(strArray[4].Trim());
                            BackOrders.OrderPurchaser = scOrderFas.OrderData.OrderJobName;
                            BackOrders.OrderLineNB4Dt = Conversions.ToDate(strArray[6].Trim());
                            BackOrders.OrderLineOrgShipDt = Conversions.ToDate(strArray[5].Trim());
                            BackOrders.OrderLineQty = Conversions.ToInteger(strArray[2].Trim());
                            new clsBackorders(this.lmPlantLevel, BackOrders.AssemblyLine).InsertBackOrderLines(BackOrders);
                            clsFASorders.scUpdProgress scUpdProgress = new clsFASorders.scUpdProgress(clsFASorders.emUpdateProgType.ResultStatus, scOrderFas.OrderData.FactoryOrderOE + " was created in VMS\r\n");
                            clsFASorders.ueUpdateProgressEventHandler updateProgressEvent = this.ueUpdateProgress;
                            if (updateProgressEvent != null)
                                updateProgressEvent((object)this, new ProgressChangedEventArgs(10, (object)scUpdProgress));
                        }
                    }
                }
            }


            //IEnumerable<clsFASorders.scOrderFas> source1 = (IEnumerable<clsFASorders.scOrderFas>)Enumerable.Select<clsFASorders.scOrderFas, clsFASorders.scOrderFas>(
            //    (IEnumerable<clsFASorders.scOrderFas>) Enumerable.OrderBy<clsFASorders.scOrderFas, string>(Enumerable.Where<clsFASorders.scOrderFas>(
            //    (IEnumerable<M0>) scOrderFasList, (Func<M0, bool>) new Func<clsFASorders.scOrderFas, bool>(
            //        (object) null, __methodptr(_Lambda\u0024__3))), (Func<M0, M1>) new Func<clsFASorders.scOrderFas, string>(
            //            (object) null, __methodptr(_Lambda\u0024__4))), (Func<M0, M1>) new Func<clsFASorders.scOrderFas, clsFASorders.scOrderFas>(
            //                (object) null, __methodptr(_Lambda\u0024__5)));  

            IEnumerable<clsFASorders.scOrderFas> source1 = (from s in scOrderFasList
                                                            select s).AsEnumerable<clsFASorders.scOrderFas>();
            Dictionary<string, clsFASorders.scOrderFas> dictionary = new Dictionary<string, clsFASorders.scOrderFas>();
            using (SE0085CTEntities1 se0085CtEntities1 = new SE0085CTEntities1())
            {
                //se0085CtEntities1.Database.Connection.ConnectionString = this._CTConnection;
                List<clsFASorders.scOrderFas>.Enumerator enumerator1;
                enumerator1 = source1.ToList<clsFASorders.scOrderFas>().GetEnumerator();
                try
                {
                    while (enumerator1.MoveNext())
                    {
                        clsFASorders.scOrderFas current = enumerator1.Current;
                        if (!dictionary.ContainsKey(current.OrdFASExt.FASOrdNbr))
                            dictionary.Add(current.OrdFASExt.FASOrdNbr, current);
                        if (DateTime.Compare(current.OrdFASExt.FASDueDt, Conversions.ToDate("12/31/2039")) < 0)
                        {
                            switch (this.UpdateFASLinesDueDate(current.OrderData, current.OrdFASExt))
                            {
                                case 0:
                                    clsFASorders.scUpdProgress scUpdProgress1 = new clsFASorders.scUpdProgress(clsFASorders.emUpdateProgType.ResultStatus, current.OrderData.FactoryOrder + " was not updated in VMS, reference FAS order " + current.OrdFASExt.FASOrdNbr + "\r\n");
                                    clsFASorders.ueUpdateProgressEventHandler updateProgressEvent1 = this.ueUpdateProgress;
                                    if (updateProgressEvent1 != null)
                                    {
                                        updateProgressEvent1((object)this, new ProgressChangedEventArgs(10, (object)scUpdProgress1));
                                        break;
                                    }
                                    break;
                                case 32763:
                                    if (current.OrdFASExt.FASOrdNbr.StartsWith("MO") & (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current.OrdFASExt.FASAsmblLn, "221", false) == 0 | Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current.OrdFASExt.FASAsmblLn, "221B", false) == 0))
                                        stringList1.Add(current.OrdFASExt.FASOrdNbr);
                                    clsFASorders.scUpdProgress scUpdProgress2 = new clsFASorders.scUpdProgress(clsFASorders.emUpdateProgType.OrderInfo, " Add:" + current.OrderData.FactoryOrderOE + "\r\n");
                                    clsFASorders.ueUpdateProgressEventHandler updateProgressEvent2 = this.ueUpdateProgress;
                                    if (updateProgressEvent2 != null)
                                    {
                                        updateProgressEvent2((object)this, new ProgressChangedEventArgs(10, (object)scUpdProgress2));
                                        break;
                                    }
                                    break;
                                case 32764:
                                    if (current.OrdFASExt.FASOrdNbr.StartsWith("MO") & (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current.OrdFASExt.FASAsmblLn, "221", false) == 0 | Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current.OrdFASExt.FASAsmblLn, "221B", false) == 0))
                                        stringList2.Add(current.OrdFASExt.FASOrdNbr);
                                    clsFASorders.scUpdProgress scUpdProgress3 = new clsFASorders.scUpdProgress(clsFASorders.emUpdateProgType.OrderInfo, " Upd:" + current.OrderData.FactoryOrderOE + "\r\n");
                                    clsFASorders.ueUpdateProgressEventHandler updateProgressEvent3 = this.ueUpdateProgress;
                                    if (updateProgressEvent3 != null)
                                    {
                                        updateProgressEvent3((object)this, new ProgressChangedEventArgs(10, (object)scUpdProgress3));
                                        break;
                                    }
                                    break;
                                case 32765:
                                    if (current.OrdFASExt.FASOrdNbr.StartsWith("MO") & (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current.OrdFASExt.FASAsmblLn, "221", false) == 0 | Microsoft.VisualBasic.CompilerServices.Operators.CompareString(current.OrdFASExt.FASAsmblLn, "221B", false) == 0))
                                    {
                                        stringList2.Add(current.OrdFASExt.FASOrdNbr);
                                        break;
                                    }
                                    break;
                                case 32766:
                                    if (DateTime.Compare(current.OrderData.OrderLineShipDt, Conversions.ToDate("12/31/2039")) != 0)
                                    {
                                        clsFASorders.scUpdProgress scUpdProgress4 = new clsFASorders.scUpdProgress(clsFASorders.emUpdateProgType.ResultStatus, current.OrderData.FactoryOrder + " was not found in VMS\r\n");
                                        clsFASorders.ueUpdateProgressEventHandler updateProgressEvent4 = this.ueUpdateProgress;
                                        if (updateProgressEvent4 != null)
                                        {
                                            updateProgressEvent4((object)this, new ProgressChangedEventArgs(10, (object)scUpdProgress4));
                                            break;
                                        }
                                        break;
                                    }
                                    break;
                                case (int)short.MaxValue:
                                    clsFASorders.scUpdProgress scUpdProgress5 = new clsFASorders.scUpdProgress(clsFASorders.emUpdateProgType.ResultStatus, current.OrderData.FactoryOrder + " has duplicate FAS orders attached in VMS, reference FAS order " + current.OrdFASExt.FASOrdNbr + "\r\n");
                                    clsFASorders.ueUpdateProgressEventHandler updateProgressEvent5 = this.ueUpdateProgress;
                                    if (updateProgressEvent5 != null)
                                    {
                                        updateProgressEvent5((object)this, new ProgressChangedEventArgs(10, (object)scUpdProgress5));
                                        break;
                                    }
                                    break;
                                default:
                                    clsFASorders.scUpdProgress scUpdProgress6 = new clsFASorders.scUpdProgress(clsFASorders.emUpdateProgType.OrderInfo, current.OrderData.FactoryOrderOE + "\r\n");
                                    clsFASorders.ueUpdateProgressEventHandler updateProgressEvent6 = this.ueUpdateProgress;
                                    if (updateProgressEvent6 != null)
                                    {
                                        updateProgressEvent6((object)this, new ProgressChangedEventArgs(10, (object)scUpdProgress6));
                                        break;
                                    }
                                    break;
                            }
                        }
                    }
                }
                finally
                {
                    enumerator1.Dispose();
                }
                //ParameterExpression parameterExpression;                
                //IQueryable<OrdFASExt> source2 = (IQueryable<OrdFASExt>) Queryable.Select<OrdFASExt, OrdFASExt>(Queryable.Where<OrdFASExt>((IQueryable<M0>) se0085CtEntities1.OrdFASExts, (Expression<Func<M0, bool>>) Expression.Lambda<Func<OrdFASExt, bool>>((Expression) Expression.Coalesce((Expression) Expression.GreaterThan(f.FASOrdQty, f.FASCmplQty, true, (MethodInfo) null), (Expression) Expression.Constant((object) false, typeof (bool))), new ParameterExpression[1]{ parameterExpression })), (Expression<Func<M0, M1>>) (f => f));
                IQueryable<OrdFASExt> source2 = (from f in se0085CtEntities1.OrdFASExts
                                                 where f.FASOrdQty > f.FASCmplQty
                                                 select f).AsQueryable<OrdFASExt>();
                if (source2 != null)
                {
                    if (source2.Count<OrdFASExt>() > 0)
                    {
                        IEnumerator<OrdFASExt> enumerator2;
                        enumerator2 = source2.GetEnumerator();
                        try
                        {
                            while (enumerator2.MoveNext())
                            {
                                OrdFASExt current = enumerator2.Current;
                                string fasOrdNbr = current.FASOrdNbr;
                                if (!dictionary.ContainsKey(fasOrdNbr))
                                    current.FASCmplQty = current.FASOrdQty;
                            }
                        }
                        finally
                        {
                            if (enumerator2 != null)
                                enumerator2.Dispose();
                        }
                        clsFASorders.scUpdProgress scUpdProgress1 = new clsFASorders.scUpdProgress(clsFASorders.emUpdateProgType.ResultStatus, "FAS Orders Closed: Update CompQty");
                        if (se0085CtEntities1.SaveChanges() > 0)
                        {
                            clsFASorders.scUpdProgress scUpdProgress2 = scUpdProgress1;
                            scUpdProgress2.UpdateStatus = scUpdProgress2.UpdateStatus + " was successful \r\n";
                            clsFASorders.ueUpdateProgressEventHandler updateProgressEvent = this.ueUpdateProgress;
                            if (updateProgressEvent != null)
                                updateProgressEvent((object)this, new ProgressChangedEventArgs(10, (object)scUpdProgress1));
                        }
                        else
                        {
                            clsFASorders.scUpdProgress scUpdProgress2 = scUpdProgress1;
                            scUpdProgress2.UpdateStatus = scUpdProgress2.UpdateStatus + " FAILED! \r\n";
                            clsFASorders.ueUpdateProgressEventHandler updateProgressEvent = this.ueUpdateProgress;
                            if (updateProgressEvent != null)
                                updateProgressEvent((object)this, new ProgressChangedEventArgs(10, (object)scUpdProgress1));
                        }
                    }
                }
                clsFASorders.scUpdProgress scUpdProgress7 = new clsFASorders.scUpdProgress(clsFASorders.emUpdateProgType.ResultStatus, "FAS data import complete:" + Conversions.ToString(DateTime.Now) + "\r\n");
                clsFASorders.ueUpdateProgressEventHandler updateProgressEvent7 = this.ueUpdateProgress;
                if (updateProgressEvent7 != null)
                    updateProgressEvent7((object)this, new ProgressChangedEventArgs(10, (object)scUpdProgress7));
                List<string>.Enumerator enumerator3;
                enumerator3 = stringList1.GetEnumerator();
                try
                {
                    while (enumerator3.MoveNext())
                    {
                        string current = enumerator3.Current;
                        if (clsEngineCtdB.AddUpdFASDtlByMO(current))
                        {
                            clsFASorders.scUpdProgress scUpdProgress1 = new clsFASorders.scUpdProgress(clsFASorders.emUpdateProgType.ResultStatus, "FAS Order: " + current + " attached to a section(s)\r\n");
                            clsFASorders.ueUpdateProgressEventHandler updateProgressEvent1 = this.ueUpdateProgress;
                            if (updateProgressEvent1 != null)
                                updateProgressEvent1((object)this, new ProgressChangedEventArgs(10, (object)scUpdProgress1));
                        }
                        else
                        {
                            clsFASorders.scUpdProgress scUpdProgress1 = new clsFASorders.scUpdProgress(clsFASorders.emUpdateProgType.ResultStatus, "FAS Order: " + current + " failed to attach to a section(s)\r\n");
                            clsFASorders.ueUpdateProgressEventHandler updateProgressEvent1 = this.ueUpdateProgress;
                            if (updateProgressEvent1 != null)
                                updateProgressEvent1((object)this, new ProgressChangedEventArgs(10, (object)scUpdProgress1));
                        }
                    }
                }
                finally
                {
                    enumerator3.Dispose();
                }
                List<string>.Enumerator enumerator4;
                enumerator4 = stringList2.GetEnumerator();
                try
                {
                    while (enumerator4.MoveNext())
                    {
                        string current = enumerator4.Current;
                        if (clsEngineCtdB.AddUpdFASDtlByMO(current))
                        {
                            clsFASorders.scUpdProgress scUpdProgress1 = new clsFASorders.scUpdProgress(clsFASorders.emUpdateProgType.ResultStatus, "FAS Order: " + current + " updated section(s)\r\n");
                            clsFASorders.ueUpdateProgressEventHandler updateProgressEvent1 = this.ueUpdateProgress;
                            if (updateProgressEvent1 != null)
                                updateProgressEvent1((object)this, new ProgressChangedEventArgs(10, (object)scUpdProgress1));
                        }
                        else
                        {
                            clsFASorders.scUpdProgress scUpdProgress1 = new clsFASorders.scUpdProgress(clsFASorders.emUpdateProgType.ResultStatus, "FAS Order: " + current + " failed to update section(s)\r\n");
                            clsFASorders.ueUpdateProgressEventHandler updateProgressEvent1 = this.ueUpdateProgress;
                            if (updateProgressEvent1 != null)
                                updateProgressEvent1((object)this, new ProgressChangedEventArgs(10, (object)scUpdProgress1));
                        }
                    }
                }
                finally
                {
                    enumerator4.Dispose();
                }
                se0085CtEntities1.Database.Connection.Close();
            }
            streamReader.Close();
            flag1 = true;


            label_115:
            return flag1;
        }

        public int UpdateFASLinesDueDate(scOrderData Q2COrder, scOrdFASExt FASOrder)
        {
            //clsFASorders closure108 = new clsFASorders();
            scOrderData Q2COrders = Q2COrder;
            scOrdFASExt FASOrders = FASOrder;
            int num1 = 0;
            using (SE0085CTEntities1 se0085CtEntities1 = new SE0085CTEntities1())
            {
                //se0085CtEntities1.Database.Connection.ConnectionString = this._CTConnection;
               
               // IQueryable<OrderLine> source1 = (IQueryable<OrderLine>)Queryable.Select(Queryable.Where((IQueryable<M0>)Queryable.Join((IQueryable<M0>)se0085CtEntities1.SEOrders, (IEnumerable<M1>)se0085CtEntities1.OrderLines, (Expression<Func<M0, M2>>)(o => o.OrderId), (Expression<Func<M1, M2>>)(l => l.SEOrder.OrderId), (Expression<Func<M0, M1, M3>>)((o, l) => new { o = o, l = l })), (Expression<Func<M0, bool>>)(data => Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), data.o.OrderFO, closure108.Q2COrders.OrderFO, false) == 0 & Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), data.l.OrderLineNum, closure108.Q2COrders.OrderLineNum, false) == 0 & Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), data.l.OrderLineSL, closure108.Q2COrders.OrderLineSL, false) == 0 & Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), data.l.OrderLineSS, closure108.Q2COrders.OrderLineSS, false) == 0)), (Expression<Func<M0, M1>>)(data => data.l));

                IQueryable<OrderLine> source1 = (from o in se0085CtEntities1.SEOrders
                                                join l in se0085CtEntities1.OrderLines
                                                on o.OrderId equals l.SEOrder.OrderId
                                                where o.OrderFO == Q2COrders.OrderFO
                                                && l.OrderLineNum == Q2COrders.OrderLineNum
                                                && l.OrderLineSL == Q2COrders.OrderLineSL
                                                && l.OrderLineSS == Q2COrders.OrderLineSS
                                                select l).AsQueryable<OrderLine>();
                if (source1.Count<OrderLine>() == 0)
                    num1 = 32766;
                else if (source1.Count<OrderLine>() == 1)
                {
                    OrderLine orderLine = source1.First<OrderLine>();
                    //IQueryable<OrdFASExt> source2 = (IQueryable<OrdFASExt>)Queryable.Select<OrdFASExt, OrdFASExt>(Queryable.Where<OrdFASExt>((IQueryable<M0>)se0085CtEntities1.OrdFASExts, (Expression<Func<M0, bool>>)(f => Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Microsoft.VisualBasic.CompilerServices.Operators.CompareString)), f.FASOrdNbr, (Expression)Expression.Call(closure108.FASOrders.FASOrdNbr, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(string.Trim)), (Expression[])null), false) == 0)), (Expression<Func<M0, M1>>)(f => f));
                    IQueryable<OrdFASExt> source2 = (from f in se0085CtEntities1.OrdFASExts
                                                     where string.Equals(f.FASOrdNbr, FASOrders.FASOrdNbr)
                                                     select f).AsQueryable<OrdFASExt>();
                    if (source2.Count<OrdFASExt>() == 0)
                    {
                        OrdFASExt ordFasExt = new OrdFASExt();
                        
                        ordFasExt.FASOrdNbr = Microsoft.VisualBasic.Strings.Left(FASOrders.FASOrdNbr.Trim(), 25);
                        
                        ordFasExt.FASAsmblLn = Microsoft.VisualBasic.Strings.Left(FASOrders.FASAsmblLn.Trim(), 5);
                        
                        ordFasExt.FASCmplQty = (int?)FASOrders.FASCmplQty;
                        
                        ordFasExt.OrdProdLn = Microsoft.VisualBasic.Strings.Left(FASOrders.OrdProdLn.Trim(), 4);
                        
                        ordFasExt.FASOrdQty = (int?)FASOrders.FASOrdQty;
                        
                        ordFasExt.FASPrgrsPnt = (int?)FASOrders.FASPrgrsPnt;
                        
                        ordFasExt.FASUnfilledQty = (int?)FASOrders.FASUnfilledQty;
                        
                        ordFasExt.FASWorkCtr = Microsoft.VisualBasic.Strings.Left(FASOrders.FASWorkCtr.Trim(), 10);
                        
                        ordFasExt.OrdCatlgNbr = Microsoft.VisualBasic.Strings.Left(FASOrders.OrdCatlgNbr.Trim(), 34);
                        
                        ordFasExt.OrdCdDesc = Microsoft.VisualBasic.Strings.Left(FASOrders.OrdCdDesc.Trim(), 50);
                        
                        ordFasExt.OrdMfgPartNbr = Microsoft.VisualBasic.Strings.Left(FASOrders.OrdMfgPartNbr.Trim(), 15);
                        DateTime dateTime;
                        if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.OrdProdLn.Trim(), "258", false) == 0)
                        {
                            if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.FASAsmblLn.Trim(), "221", false) == 0)
                            {
                                TimeSpan timeSpan = new TimeSpan(2, 0, 0, 0);
                                DateTime? orderLineAssyStartDt = orderLine.OrderLineAssyStartDt;
                                int num2 = orderLineAssyStartDt.HasValue ? 1 : 0;
                                TimeSpan? nullable = (TimeSpan?)timeSpan;
                                int num3 = nullable.HasValue ? 1 : 0;
                                dateTime = (DateTime)((num2 & num3) != 0 ? new DateTime?(orderLineAssyStartDt.GetValueOrDefault() + nullable.GetValueOrDefault()) : new DateTime?());
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.FASAsmblLn.Trim(), "221B", false) == 0)
                            {
                                if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.OrdCatlgNbr.Substring(5, 1), "R", false) == 0)
                                {
                                    TimeSpan timeSpan = new TimeSpan(3, 0, 0, 0);
                                    DateTime? orderLineTargetDt = orderLine.OrderLineTargetDt;
                                    int num2 = orderLineTargetDt.HasValue ? 1 : 0;
                                    TimeSpan? nullable = (TimeSpan?)timeSpan;
                                    int num3 = nullable.HasValue ? 1 : 0;
                                    dateTime = (DateTime)((num2 & num3) != 0 ? new DateTime?(orderLineTargetDt.GetValueOrDefault() - nullable.GetValueOrDefault()) : new DateTime?());
                                }
                                else
                                {
                                    TimeSpan timeSpan = new TimeSpan(2, 0, 0, 0);
                                    DateTime? orderLineAssyStartDt = orderLine.OrderLineAssyStartDt;
                                    int num2 = orderLineAssyStartDt.HasValue ? 1 : 0;
                                    TimeSpan? nullable = (TimeSpan?)timeSpan;
                                    int num3 = nullable.HasValue ? 1 : 0;
                                    dateTime = (DateTime)((num2 & num3) != 0 ? new DateTime?(orderLineAssyStartDt.GetValueOrDefault() + nullable.GetValueOrDefault()) : new DateTime?());
                                }
                            }
                            else
                            {
                                
                                dateTime = FASOrders.FASDueDt;
                            }
                        }
                        else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.OrdProdLn.Trim(), "279", false) == 0)
                        {
                            if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.FASAsmblLn.Trim(), "221", false) == 0)
                            {
                                TimeSpan timeSpan = new TimeSpan(2, 0, 0, 0);
                                DateTime? orderLineAssyStartDt = orderLine.OrderLineAssyStartDt;
                                int num2 = orderLineAssyStartDt.HasValue ? 1 : 0;
                                TimeSpan? nullable = (TimeSpan?)timeSpan;
                                int num3 = nullable.HasValue ? 1 : 0;
                                dateTime = (DateTime)((num2 & num3) != 0 ? new DateTime?(orderLineAssyStartDt.GetValueOrDefault() + nullable.GetValueOrDefault()) : new DateTime?());
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.FASAsmblLn.Trim(), "221B", false) == 0)
                            {
                                if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.OrdCatlgNbr.Substring(5, 1), "R", false) == 0)
                                {
                                    TimeSpan timeSpan = new TimeSpan(3, 0, 0, 0);
                                    DateTime? orderLineTargetDt = orderLine.OrderLineTargetDt;
                                    int num2 = orderLineTargetDt.HasValue ? 1 : 0;
                                    TimeSpan? nullable = (TimeSpan?)timeSpan;
                                    int num3 = nullable.HasValue ? 1 : 0;
                                    dateTime = (DateTime)((num2 & num3) != 0 ? new DateTime?(orderLineTargetDt.GetValueOrDefault() - nullable.GetValueOrDefault()) : new DateTime?());
                                }
                                else
                                {
                                    
                                    dateTime = FASOrders.FASDueDt;
                                }
                            }
                            else
                            {
                                
                                dateTime = FASOrders.FASDueDt;
                            }
                        }
                        else
                        {
                            
                            dateTime = FASOrders.FASDueDt;
                        }
                        ordFasExt.FASDueDt = dateTime.DayOfWeek != DayOfWeek.Saturday ? (dateTime.DayOfWeek != DayOfWeek.Sunday ? (DateTime?)dateTime : (DateTime?)dateTime.AddDays(-2.0)) : (DateTime?)dateTime.AddDays(-1.0);
                        orderLine.OrdFASExts.Add(ordFasExt);
                        num1 = se0085CtEntities1.SaveChanges() <= 0 ? 0 : 32763;
                    }
                    else if (source2.Count<OrdFASExt>() == 1)
                    {
                        bool flag1 = false;
                        OrdFASExt ordFasExt = source2.First<OrdFASExt>();
                        bool flag2 = true;
                        bool? nullable1 = orderLine.OrderLineShipped;
                        bool? nullable2;
                        bool? nullable3;
                        if (!nullable1.HasValue)
                        {
                            nullable3 = new bool?();
                        }
                        else
                        {
                            nullable2 = new bool?(nullable1.GetValueOrDefault() == flag2);
                            nullable3 = nullable2;
                        }
                        bool? nullable4 = nullable3;
                        bool? nullable5;
                        bool? nullable6;
                        
                        
                        if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(Q2COrders.FactoryOrderOE.Trim(), FASOrders.FASOrdNbr.Trim(), false) != 0)
                        {
                            nullable5 = new bool?(false);
                            nullable6 = nullable5;
                        }
                        else
                            nullable6 = nullable4;
                        bool? nullable7 = nullable6;
                        int? nullable8;
                        bool? nullable9;
                        bool? nullable10;
                        bool? nullable11;
                        if (nullable7.GetValueOrDefault())
                        {
                            
                            int fasCmplQty = FASOrders.FASCmplQty;
                            nullable8 = orderLine.OrderLineQty;
                            bool? nullable12;
                            if (!nullable8.HasValue)
                            {
                                nullable12 = new bool?();
                            }
                            else
                            {
                                nullable9 = new bool?(fasCmplQty == nullable8.GetValueOrDefault());
                                nullable12 = nullable9;
                            }
                            nullable10 = nullable12;
                            bool? nullable13;
                            if (!nullable10.HasValue)
                            {
                                nullable13 = new bool?();
                            }
                            else
                            {
                                nullable11 = new bool?(!nullable10.GetValueOrDefault());
                                nullable13 = nullable11;
                            }
                            if (nullable13.GetValueOrDefault())
                            {
                                orderLine.OrderLineShipped = (bool?)false;
                                orderLine.OrderLineShippedDt = (DateTime?)Conversions.ToDate("01/01/1901");
                            }
                        }
                        
                        DateTime fasDueDt1 = FASOrders.FASDueDt;
                        bool flag3 = false;
                        bool? nullable14 = ordFasExt.OrdBuildReq;
                        bool? nullable15;
                        if (!nullable14.HasValue)
                        {
                            nullable15 = new bool?();
                        }
                        else
                        {
                            nullable2 = new bool?(nullable14.GetValueOrDefault() == flag3);
                            nullable15 = nullable2;
                        }
                        nullable11 = nullable15;
                        nullable1 = ordFasExt.OrdBuildReq;
                        bool? nullable16;
                        if (nullable1.HasValue)
                        {
                            nullable16 = nullable11;
                        }
                        else
                        {
                            nullable10 = new bool?(true);
                            nullable16 = nullable10;
                        }
                        nullable9 = nullable16;
                        DateTime? nullable17;
                        DateTime? nullable18;
                        DateTime t2;
                        if (nullable9.GetValueOrDefault())
                        {
                            DateTime dateTime;
                            if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.OrdProdLn.Trim(), "258", false) == 0)
                            {
                                if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.FASAsmblLn.Trim(), "221", false) == 0)
                                {
                                    TimeSpan timeSpan = new TimeSpan(2, 0, 0, 0);
                                    nullable17 = orderLine.OrderLineAssyStartDt;
                                    int num2 = nullable17.HasValue ? 1 : 0;
                                    TimeSpan? nullable12 = (TimeSpan?)timeSpan;
                                    int num3 = nullable12.HasValue ? 1 : 0;
                                    DateTime? nullable13;
                                    if ((num2 & num3) == 0)
                                    {
                                        nullable13 = new DateTime?();
                                    }
                                    else
                                    {
                                        nullable18 = new DateTime?(nullable17.GetValueOrDefault() + nullable12.GetValueOrDefault());
                                        nullable13 = nullable18;
                                    }
                                    dateTime = (DateTime)nullable13;
                                }
                                else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.FASAsmblLn.Trim(), "221B", false) == 0)
                                {
                                    if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.OrdCatlgNbr.Substring(5, 1), "R", false) == 0)
                                    {
                                        TimeSpan timeSpan = new TimeSpan(3, 0, 0, 0);
                                        nullable17 = orderLine.OrderLineTargetDt;
                                        int num2 = nullable17.HasValue ? 1 : 0;
                                        TimeSpan? nullable12 = (TimeSpan?)timeSpan;
                                        int num3 = nullable12.HasValue ? 1 : 0;
                                        DateTime? nullable13;
                                        if ((num2 & num3) == 0)
                                        {
                                            nullable13 = new DateTime?();
                                        }
                                        else
                                        {
                                            nullable18 = new DateTime?(nullable17.GetValueOrDefault() - nullable12.GetValueOrDefault());
                                            nullable13 = nullable18;
                                        }
                                        dateTime = (DateTime)nullable13;
                                    }
                                    else
                                    {
                                        TimeSpan timeSpan = new TimeSpan(2, 0, 0, 0);
                                        DateTime? orderLineAssyStartDt = orderLine.OrderLineAssyStartDt;
                                        int num2 = orderLineAssyStartDt.HasValue ? 1 : 0;
                                        TimeSpan? nullable12 = (TimeSpan?)timeSpan;
                                        int num3 = nullable12.HasValue ? 1 : 0;
                                        DateTime? nullable13;
                                        if ((num2 & num3) == 0)
                                        {
                                            nullable13 = new DateTime?();
                                        }
                                        else
                                        {
                                            nullable18 = new DateTime?(orderLineAssyStartDt.GetValueOrDefault() + nullable12.GetValueOrDefault());
                                            nullable13 = nullable18;
                                        }
                                        dateTime = (DateTime)nullable13;
                                    }
                                }
                                else
                                {
                                    
                                    dateTime = FASOrders.FASDueDt;
                                }
                            }
                            else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.OrdProdLn.Trim(), "279", false) == 0)
                            {
                                if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.FASAsmblLn.Trim(), "221", false) == 0)
                                {
                                    TimeSpan timeSpan = new TimeSpan(2, 0, 0, 0);
                                    nullable17 = orderLine.OrderLineAssyStartDt;
                                    int num2 = nullable17.HasValue ? 1 : 0;
                                    TimeSpan? nullable12 = (TimeSpan?)timeSpan;
                                    int num3 = nullable12.HasValue ? 1 : 0;
                                    DateTime? nullable13;
                                    if ((num2 & num3) == 0)
                                    {
                                        nullable13 = new DateTime?();
                                    }
                                    else
                                    {
                                        nullable18 = new DateTime?(nullable17.GetValueOrDefault() + nullable12.GetValueOrDefault());
                                        nullable13 = nullable18;
                                    }
                                    dateTime = (DateTime)nullable13;
                                }
                                else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.FASAsmblLn.Trim(), "221B", false) == 0)
                                {
                                    if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.OrdCatlgNbr.Substring(5, 1), "R", false) == 0)
                                    {
                                        TimeSpan timeSpan = new TimeSpan(3, 0, 0, 0);
                                        nullable17 = orderLine.OrderLineTargetDt;
                                        int num2 = nullable17.HasValue ? 1 : 0;
                                        TimeSpan? nullable12 = (TimeSpan?)timeSpan;
                                        int num3 = nullable12.HasValue ? 1 : 0;
                                        DateTime? nullable13;
                                        if ((num2 & num3) == 0)
                                        {
                                            nullable13 = new DateTime?();
                                        }
                                        else
                                        {
                                            nullable18 = new DateTime?(nullable17.GetValueOrDefault() - nullable12.GetValueOrDefault());
                                            nullable13 = nullable18;
                                        }
                                        dateTime = (DateTime)nullable13;
                                    }
                                    else
                                    {
                                        
                                        dateTime = FASOrders.FASDueDt;
                                    }
                                }
                                else
                                {
                                    
                                    dateTime = FASOrders.FASDueDt;
                                }
                            }
                            else
                            {
                                
                                dateTime = FASOrders.FASDueDt;
                            }
                            t2 = dateTime.DayOfWeek != DayOfWeek.Saturday ? (dateTime.DayOfWeek != DayOfWeek.Sunday ? dateTime : dateTime.AddDays(-2.0)) : dateTime.AddDays(-1.0);
                        }
                        else
                        {
                            DateTime date = Conversions.ToDate("1901-01-01");
                            DateTime? fasDueDt2 = ordFasExt.FASDueDt;
                            bool? nullable12;
                            if (!fasDueDt2.HasValue)
                            {
                                nullable12 = new bool?();
                            }
                            else
                            {
                                nullable11 = new bool?(DateTime.Compare(fasDueDt2.GetValueOrDefault(), date) <= 0);
                                nullable12 = nullable11;
                            }
                            nullable9 = nullable12;
                            
                            t2 = !nullable9.GetValueOrDefault() ? (DateTime)ordFasExt.FASDueDt : FASOrders.FASDueDt;
                        }
                        
                        int fasCmplQty1 = FASOrders.FASCmplQty;
                        nullable8 = ordFasExt.FASCmplQty;
                        bool? nullable19 = nullable8.HasValue ? new bool?(nullable8.GetValueOrDefault() == fasCmplQty1) : new bool?();
                        
                        
                        bool? nullable20 = Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.FASOrdNbr, FASOrders.FASOrdNbr, false) == 0 & Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.FASAsmblLn, FASOrders.FASAsmblLn, false) == 0 ? nullable19 : new bool?(false);
                        nullable17 = ordFasExt.FASDueDt;
                        bool? nullable21 = nullable17.HasValue ? new bool?(DateTime.Compare(nullable17.GetValueOrDefault(), t2) == 0) : new bool?();
                        bool? nullable22 = !nullable20.HasValue || nullable20.GetValueOrDefault() ? (nullable21.HasValue ? (nullable21.GetValueOrDefault() ? nullable20 : new bool?(false)) : new bool?()) : new bool?(false);
                        
                        int fasOrdQty1 = FASOrders.FASOrdQty;
                        int? fasOrdQty2 = ordFasExt.FASOrdQty;
                        bool? nullable23 = fasOrdQty2.HasValue ? new bool?(fasOrdQty2.GetValueOrDefault() == fasOrdQty1) : new bool?();
                        bool? nullable24 = !nullable22.HasValue || nullable22.GetValueOrDefault() ? (nullable23.HasValue ? (nullable23.GetValueOrDefault() ? nullable22 : new bool?(false)) : new bool?()) : new bool?(false);
                        
                        int fasPrgrsPnt1 = FASOrders.FASPrgrsPnt;
                        int? fasPrgrsPnt2 = ordFasExt.FASPrgrsPnt;
                        bool? nullable25 = fasPrgrsPnt2.HasValue ? new bool?(fasPrgrsPnt2.GetValueOrDefault() == fasPrgrsPnt1) : new bool?();
                        bool? nullable26 = !nullable24.HasValue || nullable24.GetValueOrDefault() ? (nullable25.HasValue ? (nullable25.GetValueOrDefault() ? nullable24 : new bool?(false)) : new bool?()) : new bool?(false);
                        
                        int fasUnfilledQty1 = FASOrders.FASUnfilledQty;
                        int? fasUnfilledQty2 = ordFasExt.FASUnfilledQty;
                        bool? nullable27 = fasUnfilledQty2.HasValue ? new bool?(fasUnfilledQty2.GetValueOrDefault() == fasUnfilledQty1) : new bool?();
                        bool? nullable28 = !nullable26.HasValue || nullable26.GetValueOrDefault() ? (nullable27.HasValue ? (nullable27.GetValueOrDefault() ? nullable26 : new bool?(false)) : new bool?()) : new bool?(false);
                        
                        bool? nullable29 = Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.FASWorkCtr, FASOrders.FASWorkCtr, false) == 0 ? nullable28 : new bool?(false);
                        
                        bool? nullable30 = Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.OrdCatlgNbr, FASOrders.OrdCatlgNbr, false) == 0 ? nullable29 : new bool?(false);
                        bool? nullable31;
                        
                        if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.OrdCdDesc, FASOrders.OrdCdDesc, false) != 0)
                        {
                            nullable7 = new bool?(false);
                            nullable31 = nullable7;
                        }
                        else
                            nullable31 = nullable30;
                        nullable1 = nullable31;
                        bool? nullable32;
                        
                        if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.OrdMfgPartNbr, FASOrders.OrdMfgPartNbr, false) != 0)
                        {
                            nullable5 = new bool?(false);
                            nullable32 = nullable5;
                        }
                        else
                            nullable32 = nullable1;
                        nullable14 = nullable32;
                        bool? nullable33;
                        
                        if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.OrdProdLn, FASOrders.OrdProdLn, false) != 0)
                        {
                            nullable2 = new bool?(false);
                            nullable33 = nullable2;
                        }
                        else
                            nullable33 = nullable14;
                        nullable11 = nullable33;
                        bool? nullable34;
                        if (!nullable11.HasValue)
                        {
                            nullable34 = new bool?();
                        }
                        else
                        {
                            nullable10 = new bool?(!nullable11.GetValueOrDefault());
                            nullable34 = nullable10;
                        }
                        nullable9 = nullable34;
                        if (nullable9.GetValueOrDefault())
                        {
                            nullable18 = ordFasExt.FASDueDt;
                            bool? nullable12 = nullable18.HasValue ? new bool?(DateTime.Compare(nullable18.GetValueOrDefault(), t2) == 0) : new bool?();
                            
                            bool? nullable13 = Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.FASAsmblLn, Microsoft.VisualBasic.Strings.Left(FASOrders.FASAsmblLn.Trim(), 5), false) == 0 ? nullable12 : new bool?(false);
                            
                            int fasUnfilledQty3 = FASOrders.FASUnfilledQty;
                            int? fasUnfilledQty4 = ordFasExt.FASUnfilledQty;
                            bool? nullable35;
                            bool? nullable36;
                            if (!fasUnfilledQty4.HasValue)
                            {
                                nullable36 = new bool?();
                            }
                            else
                            {
                                nullable35 = new bool?(fasUnfilledQty4.GetValueOrDefault() == fasUnfilledQty3);
                                nullable36 = nullable35;
                            }
                            bool? nullable37 = nullable36;
                            bool? nullable38 = !nullable13.HasValue || nullable13.GetValueOrDefault() ? (nullable37.HasValue ? (nullable37.GetValueOrDefault() ? nullable13 : new bool?(false)) : new bool?()) : new bool?(false);
                            
                            bool? nullable39 = Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.OrdProdLn, Microsoft.VisualBasic.Strings.Left(FASOrders.OrdProdLn.Trim(), 4), false) == 0 ? nullable38 : new bool?(false);
                            
                            int fasOrdQty3 = FASOrders.FASOrdQty;
                            int? nullable40 = ordFasExt.FASOrdQty;
                            bool? nullable41;
                            bool? nullable42;
                            if (!nullable40.HasValue)
                            {
                                nullable42 = new bool?();
                            }
                            else
                            {
                                nullable41 = new bool?(nullable40.GetValueOrDefault() == fasOrdQty3);
                                nullable42 = nullable41;
                            }
                            bool? nullable43 = nullable42;
                            bool? nullable44 = !nullable39.HasValue || nullable39.GetValueOrDefault() ? (nullable43.HasValue ? (nullable43.GetValueOrDefault() ? nullable39 : new bool?(false)) : new bool?()) : new bool?(false);
                            
                            bool? nullable45 = Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.FASWorkCtr, Microsoft.VisualBasic.Strings.Left(FASOrders.FASWorkCtr.Trim(), 10), false) == 0 ? nullable44 : new bool?(false);
                            
                            bool? nullable46 = Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.OrdCatlgNbr, Microsoft.VisualBasic.Strings.Left(FASOrders.OrdCatlgNbr.Trim(), 34), false) == 0 ? nullable45 : new bool?(false);
                            
                            bool? nullable47 = Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ordFasExt.OrdMfgPartNbr, Microsoft.VisualBasic.Strings.Left(FASOrders.OrdMfgPartNbr.Trim(), 15), false) == 0 ? nullable46 : new bool?(false);
                            if ((nullable47.HasValue ? new bool?(!nullable47.GetValueOrDefault()) : new bool?()).GetValueOrDefault())
                            {
                                
                                ordFasExt.FASAsmblLn = Microsoft.VisualBasic.Strings.Left(FASOrders.FASAsmblLn.Trim(), 5);
                                ordFasExt.FASDueDt = (DateTime?)t2;
                                
                                ordFasExt.FASUnfilledQty = (int?)FASOrders.FASUnfilledQty;
                                
                                ordFasExt.OrdProdLn = Microsoft.VisualBasic.Strings.Left(FASOrders.OrdProdLn.Trim(), 4);
                                
                                ordFasExt.FASOrdQty = (int?)FASOrders.FASOrdQty;
                                
                                ordFasExt.FASWorkCtr = Microsoft.VisualBasic.Strings.Left(FASOrders.FASWorkCtr.Trim(), 10);
                                
                                ordFasExt.OrdCatlgNbr = Microsoft.VisualBasic.Strings.Left(FASOrders.OrdCatlgNbr.Trim(), 34);
                                
                                ordFasExt.OrdMfgPartNbr = Microsoft.VisualBasic.Strings.Left(FASOrders.OrdMfgPartNbr.Trim(), 15);
                                flag1 = true;
                            }
                            
                            int fasCmplQty2 = FASOrders.FASCmplQty;
                            nullable40 = ordFasExt.FASCmplQty;
                            bool? nullable48;
                            if (!nullable40.HasValue)
                            {
                                nullable48 = new bool?();
                            }
                            else
                            {
                                nullable35 = new bool?(fasCmplQty2 > nullable40.GetValueOrDefault());
                                nullable48 = nullable35;
                            }
                            nullable41 = nullable48;
                            if (nullable41.GetValueOrDefault())
                            {
                                
                                ordFasExt.FASCmplQty = (int?)FASOrders.FASCmplQty;
                                flag1 = true;
                            }
                            
                            int fasPrgrsPnt3 = FASOrders.FASPrgrsPnt;
                            nullable40 = ordFasExt.FASPrgrsPnt;
                            bool? nullable49;
                            if (!nullable40.HasValue)
                            {
                                nullable49 = new bool?();
                            }
                            else
                            {
                                nullable35 = new bool?(nullable40.GetValueOrDefault() < fasPrgrsPnt3);
                                nullable49 = nullable35;
                            }
                            nullable41 = nullable49;
                            if (nullable41.GetValueOrDefault())
                            {
                                
                                ordFasExt.FASPrgrsPnt = (int?)FASOrders.FASPrgrsPnt;
                                
                                ordFasExt.OrdCdDesc = Microsoft.VisualBasic.Strings.Left(FASOrders.OrdCdDesc.Trim(), 50);
                                flag1 = true;
                            }
                            if (ordFasExt.OrdCatlgNbr.Length == 0)
                            {
                                
                                ordFasExt.OrdCatlgNbr = Microsoft.VisualBasic.Strings.Left(FASOrders.OrdCatlgNbr.Trim(), 34);
                                flag1 = true;
                            }
                            num1 = !flag1 ? 32765 : (se0085CtEntities1.SaveChanges() <= 0 ? 0 : 32764);
                        }
                        else
                            num1 = 32765;
                    }
                    else
                        num1 = (int)short.MaxValue;
                }
                se0085CtEntities1.Database.Connection.Close();
            }
            return num1;
        }

        public delegate void ueUpdateProgressEventHandler(object sender, ProgressChangedEventArgs e);       

        public class scOrderFas
        {
            private scOrderData _OrderData;
            private scOrdFASExt _OrdFASExt;
            private scOrdFASExtDtl _OrdFASExtDtl;

            public scOrderData OrderData
            {
                get
                {
                    return this._OrderData;
                }
                set
                {
                    this._OrderData = value;
                }
            }

            public scOrdFASExt OrdFASExt
            {
                get
                {
                    return this._OrdFASExt;
                }
                set
                {
                    this._OrdFASExt = value;
                }
            }

            public scOrdFASExtDtl OrdFASExtDtl
            {
                get
                {
                    return this._OrdFASExtDtl;
                }
                set
                {
                    this._OrdFASExtDtl = value;
                }
            }

            public scOrderFas()
            {
                this._OrderData = new scOrderData();
                this._OrdFASExt = new scOrdFASExt();
                this._OrdFASExtDtl = new scOrdFASExtDtl();
            }
        }

        public class scUpdProgress
        {
            private clsFASorders.emUpdateProgType _UpdateType;
            private string _UpdateStatus;

            public clsFASorders.emUpdateProgType UpdateType
            {
                get
                {
                    return this._UpdateType;
                }
                set
                {
                    this._UpdateType = value;
                }
            }

            public string UpdateStatus
            {
                get
                {
                    return this._UpdateStatus;
                }
                set
                {
                    this._UpdateStatus = value;
                }
            }

            public scUpdProgress()
            {
                this._UpdateType = clsFASorders.emUpdateProgType.OrderInfo;
                this._UpdateStatus = "";
            }

            public scUpdProgress(clsFASorders.emUpdateProgType UpdType, string UpdStatus)
            {
                this._UpdateType = UpdType;
                this._UpdateStatus = UpdStatus;
            }
        }

        public enum emUpdateProgType
        {
            OrderInfo,
            ResultStatus,
        }
    }
    
}
