using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

//namespace SE0085.CTdB
namespace FAS_LIB
{
    public class clsAssemblyLine
    {
        private scPlants _Plant;
        private scAssemblyLine _AssemblyLine;
        private List<scAssemblyLine> _AssemblyLinesList;

        public scPlants Plant
        {
            get
            {
                return this._Plant;
            }
            set
            {
                this._Plant = value;
            }
        }

        public scAssemblyLine AssemblyLine
        {
            get
            {
                return this._AssemblyLine;
            }
            set
            {
                this._AssemblyLine = value;
            }
        }
        public clsAssemblyLine(scPlants Plant)
        {
            this._Plant = new scPlants();
            this._AssemblyLinesList = new List<scAssemblyLine>();
            this._Plant = Plant;
            this._AssemblyLine = new scAssemblyLine();
            //this.GetdBConnString();
        }

        public clsAssemblyLine(scLevels Plant)
        {
            this._Plant = new scPlants();
            this._AssemblyLinesList = new List<scAssemblyLine>();
            this._Plant.PlantLevel = Plant;
            this._AssemblyLine = new scAssemblyLine();
            //this.GetdBConnString();
        }

        public List<scAssemblyLine> rtnAssemblyLines(bool ActiveOnly)
        {
      
          List<scAssemblyLine> scAssemblyLineList = new List<scAssemblyLine>();
          using (SE0085CTEntities1 se0085CtEntities1 = new SE0085CTEntities1())
          {
            //se0085CtEntities1.Database.Connection.ConnectionString = this._CTConnection;
            //ParameterExpression parameterExpression1;
            //ParameterExpression parameterExpression2;
        
            //IQueryable<scAssemblyLine> source = (IQueryable<scAssemblyLine>) Queryable.Select<SE0085.dBc.AssemblyLine, scAssemblyLine>(Queryable.Where<SE0085.dBc.AssemblyLine>((IQueryable<M0>) se0085CtEntities1.AssemblyLines, (Expression<Func<M0, bool>>) Expression.Lambda<Func<SE0085.dBc.AssemblyLine, bool>>((Expression) Expression.Coalesce((Expression) Expression.And((Expression) Expression.Convert((Expression) Expression.Equal(al.SEPlant.SEPlantId, this._Plant.PlantId, true, (MethodInfo) null), typeof (bool?)), (Expression) Expression.Or((Expression) Expression.Equal((Expression) Expression.Property((Expression) parameterExpression1, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (SE0085.dBc.AssemblyLine.get_AssemLineActive))), (Expression) Expression.Convert((Expression) Expression.Field((Expression) Expression.Constant((object) closure57, typeof (clsAssemblyLine._Closure\u0024__57)), FieldInfo.GetFieldFromHandle(__fieldref (clsAssemblyLine._Closure\u0024__57.\u0024VB\u0024Local_ldActive1))), typeof (bool?)), true, (MethodInfo) null), (Expression) Expression.Equal((Expression) Expression.Property((Expression) parameterExpression1, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (SE0085.dBc.AssemblyLine.get_AssemLineActive))), (Expression) Expression.Convert((Expression) Expression.Field((Expression) Expression.Constant((object) closure57, typeof (clsAssemblyLine._Closure\u0024__57)), FieldInfo.GetFieldFromHandle(__fieldref (clsAssemblyLine._Closure\u0024__57.\u0024VB\u0024Local_ldActive2))), typeof (bool?)), true, (MethodInfo) null))), (Expression) Expression.Constant((object) false, typeof (bool))), new ParameterExpression[1]
            //{
            //  parameterExpression1
            //})), (Expression<Func<M0, M1>>) Expression.Lambda<Func<SE0085.dBc.AssemblyLine, scAssemblyLine>>((Expression) Expression.MemberInit(Expression.New((ConstructorInfo) MethodBase.GetMethodFromHandle(__methodref (scAssemblyLine.\u002Ector)), (Expression[]) null), (MemberBinding) Expression.Bind((MethodInfo) MethodBase.GetMethodFromHandle(__methodref (scLevels.set_LevelId)), (Expression) Expression.Property((Expression) parameterExpression2, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (SE0085.dBc.AssemblyLine.get_AssemLineId)))), (MemberBinding) Expression.Bind((MethodInfo) MethodBase.GetMethodFromHandle(__methodref (scLevels.set_LevelAbbrv)), (Expression) Expression.Property((Expression) parameterExpression2, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (SE0085.dBc.AssemblyLine.get_AssemLineAbbrv)))), (MemberBinding) Expression.Bind((MethodInfo) MethodBase.GetMethodFromHandle(__methodref (scLevels.set_LevelName)), (Expression) Expression.Property((Expression) parameterExpression2, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (SE0085.dBc.AssemblyLine.get_AssemLineName)))), (MemberBinding) Expression.Bind((MethodInfo) MethodBase.GetMethodFromHandle(__methodref (scLevels.set_LevelValue)), (Expression) Expression.ConvertChecked((Expression) Expression.Property((Expression) parameterExpression2, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (SE0085.dBc.AssemblyLine.get_AssemLineValue))), typeof (byte))), (MemberBinding) Expression.Bind((MethodInfo) MethodBase.GetMethodFromHandle(__methodref (scLevels.set_LevelActiveBool)), (Expression) Expression.Convert((Expression) Expression.Property((Expression) parameterExpression2, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (SE0085.dBc.AssemblyLine.get_AssemLineActive))), typeof (bool))), (MemberBinding) Expression.Bind((MethodInfo) MethodBase.GetMethodFromHandle(__methodref (scLevels.set_LevelParentId)), (Expression) Expression.Property((Expression) Expression.Property((Expression) parameterExpression2, (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (SE0085.dBc.AssemblyLine.get_SEPlant))), (MethodInfo) MethodBase.GetMethodFromHandle(__methodref (SEPlant.get_SEPlantId))))), new ParameterExpression[1]
            //{
            //  parameterExpression2
            //}));

              IQueryable<scAssemblyLine> source = (from s in se0085CtEntities1.AssemblyLines
                                                   where s.SEPlant.SEPlantId == this._Plant.PlantId
                                                   && s.AssemLineActive == ActiveOnly
                                                   select new scAssemblyLine
                                             {
                                                 LevelId = s.AssemLineId,
                                                 LevelParentId = s.SEPlantId,
                                                 LevelName = s.AssemLineName,
                                                 LevelValue = s.AssemLineValue.HasValue ? s.AssemLineValue.Value : (byte)0,
                                                 LevelActiveBool =s.AssemLineActive.HasValue ? s.AssemLineActive.Value : false,
                                                 LevelAbbrv = s.AssemLineAbbrv
                                             }).AsQueryable<scAssemblyLine>();

            if (source != null && source.Count<scAssemblyLine>() > 0)
              scAssemblyLineList = source.ToList<scAssemblyLine>();
            this._AssemblyLinesList = scAssemblyLineList;
            se0085CtEntities1.Database.Connection.Close();
          }
          return scAssemblyLineList;
        }

        public scAssemblyLine rtnAssemblyLineByAbbrv(int PlantId, string AssemblyLineAddrv)
        {
            // ISSUE: object of a compiler-generated type is created
            // ISSUE: variable of a compiler-generated type
            //clsAssemblyLine closure58 = new clsAssemblyLine();
            // ISSUE: reference to a compiler-generated field
            //closure58.AssemblyLineAddrv = AssemblyLineAddrv;
            scAssemblyLine scAssemblyLine = new scAssemblyLine();
            using (SE0085CTEntities1 se0085CtEntities1 = new SE0085CTEntities1())
            {
                //se0085CtEntities1.Database.Connection.ConnectionString = this._CTConnection;
                //ParameterExpression parameterExpression1;
                //ParameterExpression parameterExpression2;
                //IQueryable<scAssemblyLine> source = (IQueryable<scAssemblyLine>)Queryable.Select<SE0085.dBc.AssemblyLine, scAssemblyLine>(Queryable.Where<SE0085.dBc.AssemblyLine>((IQueryable<M0>)se0085CtEntities1.AssemblyLines, (Expression<Func<M0, bool>>)Expression.Lambda<Func<SE0085.dBc.AssemblyLine, bool>>((Expression)Expression.And((Expression)Expression.Equal(al.SEPlant.SEPlantId, this._Plant.PlantId, true, (MethodInfo)null), (Expression)Expression.Equal((Expression)Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Operators.CompareString)), (Expression)Expression.Property((Expression)parameterExpression1, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SE0085.dBc.AssemblyLine.get_AssemLineAbbrv))), (Expression)Expression.Field((Expression)Expression.Constant((object)closure58, typeof(clsAssemblyLine)), FieldInfo.GetFieldFromHandle(__fieldref(clsAssemblyLine.AssemblyLineAddrv))), (Expression)Expression.Constant((object)false, typeof(bool))), (Expression)Expression.Constant((object)0, typeof(int)))), new ParameterExpression[1]
                //{
                //  parameterExpression1
                //})), (Expression<Func<M0, M1>>)Expression.Lambda<Func<SE0085.dBc.AssemblyLine, scAssemblyLine>>((Expression)Expression.MemberInit(Expression.New((ConstructorInfo)MethodBase.GetMethodFromHandle(__methodref(scAssemblyLine.Ector)), (Expression[])null), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scLevels.set_LevelId)), (Expression)Expression.Property((Expression)parameterExpression2, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SE0085.dBc.AssemblyLine.get_AssemLineId)))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scLevels.set_LevelAbbrv)), (Expression)Expression.Property((Expression)parameterExpression2, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SE0085.dBc.AssemblyLine.get_AssemLineAbbrv)))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scLevels.set_LevelName)), (Expression)Expression.Property((Expression)parameterExpression2, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SE0085.dBc.AssemblyLine.get_AssemLineName)))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scLevels.set_LevelValue)), (Expression)Expression.ConvertChecked((Expression)Expression.Property((Expression)parameterExpression2, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SE0085.dBc.AssemblyLine.get_AssemLineValue))), typeof(byte))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scLevels.set_LevelActiveBool)), (Expression)Expression.Convert((Expression)Expression.Property((Expression)parameterExpression2, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SE0085.dBc.AssemblyLine.get_AssemLineActive))), typeof(bool))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scLevels.set_LevelParentId)), (Expression)Expression.Property((Expression)Expression.Property((Expression)parameterExpression2, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SE0085.dBc.AssemblyLine.get_SEPlant))), (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SEPlant.get_SEPlantId))))), new ParameterExpression[1]
                //{
                //  parameterExpression2
                //}));

                IQueryable<scAssemblyLine> source = (from s in se0085CtEntities1.AssemblyLines
                                                     where s.SEPlant.SEPlantId == this._Plant.PlantId
                                                     && s.AssemLineAbbrv == AssemblyLineAddrv
                                                     select new scAssemblyLine
                                                     {
                                                         LevelId = s.AssemLineId,
                                                         LevelParentId = s.SEPlantId,
                                                         LevelName = s.AssemLineName,
                                                         LevelValue = s.AssemLineValue.HasValue ? s.AssemLineValue.Value : (byte)0,
                                                         LevelActiveBool = s.AssemLineActive.HasValue ? s.AssemLineActive.Value : false,
                                                         LevelAbbrv = s.AssemLineAbbrv
                                                     }).AsQueryable<scAssemblyLine>();

                if (source.Count<scAssemblyLine>() != 1)
                    return (scAssemblyLine)null;
                scAssemblyLine = source.First<scAssemblyLine>();
                this._AssemblyLine = scAssemblyLine;
                se0085CtEntities1.Database.Connection.Close();
            }
            return scAssemblyLine;
        }

        public scAssemblyLine rtnAssemblyLineById(int AssemblyLineId)
        {
            // ISSUE: object of a compiler-generated type is created
            // ISSUE: variable of a compiler-generated type
            //clsAssemblyLine closure56 = new clsAssemblyLine();
            // ISSUE: reference to a compiler-generated field
            //closure56.AssemblyLineId = AssemblyLineId;
            scAssemblyLine scAssemblyLine = new scAssemblyLine();
            using (SE0085CTEntities1 se0085CtEntities1 = new SE0085CTEntities1())
            {
                //se0085CtEntities1.Database.Connection.ConnectionString = this._CTConnection;
                //ParameterExpression parameterExpression1;
                //ParameterExpression parameterExpression2;
                // ISSUE: method reference
                // ISSUE: field reference
                //IQueryable<scAssemblyLine> source = (IQueryable<scAssemblyLine>)Queryable.Select<SE0085.dBc.AssemblyLine, scAssemblyLine>(Queryable.Where<SE0085.dBc.AssemblyLine>((IQueryable<M0>)se0085CtEntities1.AssemblyLines, (Expression<Func<M0, bool>>)Expression.Lambda<Func<SE0085.dBc.AssemblyLine, bool>>((Expression)Expression.And((Expression)Expression.Equal(al.SEPlant.SEPlantId, this._Plant.PlantId, true, (MethodInfo)null), (Expression)Expression.Equal((Expression)Expression.Property((Expression)parameterExpression1, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SE0085.dBc.AssemblyLine.get_AssemLineId))), (Expression)Expression.Field((Expression)Expression.Constant((object)closure56, typeof(clsAssemblyLine)), FieldInfo.GetFieldFromHandle(__fieldref(clsAssemblyLine.AssemblyLineId))), true, (MethodInfo)null)), new ParameterExpression[1]
                //{
                //  parameterExpression1
                //})), (Expression<Func<M0, M1>>)Expression.Lambda<Func<SE0085.dBc.AssemblyLine, scAssemblyLine>>((Expression)Expression.MemberInit(Expression.New((ConstructorInfo)MethodBase.GetMethodFromHandle(__methodref(scAssemblyLine.Ector)), (Expression[])null), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scLevels.set_LevelId)), (Expression)Expression.Property((Expression)parameterExpression2, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SE0085.dBc.AssemblyLine.get_AssemLineId)))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scLevels.set_LevelAbbrv)), (Expression)Expression.Property((Expression)parameterExpression2, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SE0085.dBc.AssemblyLine.get_AssemLineAbbrv)))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scLevels.set_LevelName)), (Expression)Expression.Property((Expression)parameterExpression2, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SE0085.dBc.AssemblyLine.get_AssemLineName)))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scLevels.set_LevelValue)), (Expression)Expression.ConvertChecked((Expression)Expression.Property((Expression)parameterExpression2, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SE0085.dBc.AssemblyLine.get_AssemLineValue))), typeof(byte))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scLevels.set_LevelActiveBool)), (Expression)Expression.Convert((Expression)Expression.Property((Expression)parameterExpression2, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SE0085.dBc.AssemblyLine.get_AssemLineActive))), typeof(bool))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scLevels.set_LevelParentId)), (Expression)Expression.Property((Expression)Expression.Property((Expression)parameterExpression2, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SE0085.dBc.AssemblyLine.get_SEPlant))), (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SEPlant.get_SEPlantId))))), new ParameterExpression[1]
                //{
                //  parameterExpression2
                //}));
                IQueryable<scAssemblyLine> source = (from al in se0085CtEntities1.AssemblyLines
                                                     where al.SEPlant.SEPlantId == this._Plant.PlantId
                                                     && al.AssemLineId == AssemblyLineId
                                                     && al.AssemLineActive == true
                                                     select new scAssemblyLine
                                                     {
                                                         LevelId = al.AssemLineId,
                                                         LevelAbbrv = al.AssemLineAbbrv,
                                                         LevelName = al.AssemLineName,
                                                         LevelValue = al.AssemLineValue.HasValue ? al.AssemLineValue.Value : (byte)0,
                                                         LevelActiveBool = al.AssemLineActive.HasValue ? al.AssemLineActive.Value : false,
                                                         LevelParentId = al.SEPlant.SEPlantId
                                                     }).AsQueryable<scAssemblyLine>();

                if (source != null && source.Count<scAssemblyLine>() == 1)
                    scAssemblyLine = source.First<scAssemblyLine>();
                this._AssemblyLine = scAssemblyLine;
                se0085CtEntities1.Database.Connection.Close();
            }
            return scAssemblyLine;
        }
    }
}
