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

//namespace SE0085.CTdB
namespace FAS_LIB
{
    public class clsPlant
    {
        private scPlants _Plant;

        public scPlants rtnPlantByDesin(string PlantDesin)
        {
            scPlants scPlants = new scPlants();
            using (SE0085CTEntities1 se0085CtEntities1 = new SE0085CTEntities1())
            {
                //se0085CtEntities1.Database.Connection.ConnectionString = this._CTConnection;
                //ParameterExpression parameterExpression;
                //IQueryable<scPlants> source = (IQueryable<scPlants>)Queryable.Select<SEPlant, scPlants>(Queryable.Where<SEPlant>((IQueryable<M0>)se0085CtEntities1.SEPlants, (Expression<Func<M0, bool>>)(p => Expression.Call((Expression)null, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(Operators.CompareString)), p.SEPlantDesin, closure55.PlantDesin, false) == 0)), (Expression<Func<M0, M1>>)Expression.Lambda<Func<SEPlant, scPlants>>((Expression)Expression.MemberInit(Expression.New((ConstructorInfo)MethodBase.GetMethodFromHandle(__methodref(scPlants.Ector)), (Expression[])null), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scPlants.set_PlantId)), (Expression)Expression.Property((Expression)parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SEPlant.get_SEPlantId)))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scPlants.set_PlantDesin)), (Expression)Expression.Property((Expression)parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SEPlant.get_SEPlantDesin)))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scPlants.set_PlantName)), (Expression)Expression.Property((Expression)parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SEPlant.get_SEPlantName)))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scPlants.set_PlantCity)), (Expression)Expression.Property((Expression)parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SEPlant.get_SEPlantCity)))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scPlants.set_PlantState)), (Expression)Expression.Property((Expression)parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SEPlant.get_SEPlantState)))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scPlants.set_PlantValue)), (Expression)Expression.ConvertChecked((Expression)Expression.Property((Expression)parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SEPlant.get_SEPlantValue))), typeof(byte))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scPlants.set_PlantActiveBool)), (Expression)Expression.Convert((Expression)Expression.Property((Expression)parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SEPlant.get_SEPlantActive))), typeof(bool)))), new ParameterExpression[1] { parameterExpression }));

                IQueryable<scPlants> source = (from s in se0085CtEntities1.SEPlants
                                               where (s.SEPlantDesin == PlantDesin)
                                                select new scPlants
                                                {
                                                   PlantId = s.SEPlantId,
                                                   PlantDesin = s.SEPlantDesin,
                                                   PlantName = s.SEPlantName,
                                                   PlantCity = s.SEPlantCity,
                                                   PlantState = s.SEPlantState,
                                                   PlantValue = s.SEPlantValue.HasValue ? s.SEPlantValue.Value : (byte)0
                                                }).AsQueryable<scPlants>();
                
                if (source.Count<scPlants>() != 1)
                    return (scPlants)null;
                scPlants = source.First<scPlants>();
                this._Plant = scPlants;
                se0085CtEntities1.Database.Connection.Close();
            }
            return scPlants;
        }

        public scPlants rtnPlantById(int PlantId)
        {
            scPlants scPlants = new scPlants();
            using (SE0085CTEntities1 se0085CtEntities1 = new SE0085CTEntities1())
            {
                //se0085CtEntities1.Database.Connection.ConnectionString = this._CTConnection;
                //ParameterExpression parameterExpression1;
                //ParameterExpression parameterExpression2;
                //IQueryable<scPlants> source = (IQueryable<scPlants>)Queryable.Select<SEPlant, scPlants>(Queryable.Where<SEPlant>((IQueryable<M0>)se0085CtEntities1.SEPlants, (Expression<Func<M0, bool>>)Expression.Lambda<Func<SEPlant, bool>>((Expression)Expression.Equal(p.SEPlantId, closure54.PlantId, true, (MethodInfo)null), new ParameterExpression[1]
                //{
                //  parameterExpression1
                //})), (Expression<Func<M0, M1>>)Expression.Lambda<Func<SEPlant, scPlants>>((Expression)Expression.MemberInit(Expression.New((ConstructorInfo)MethodBase.GetMethodFromHandle(__methodref(scPlants.ctor)), (Expression[])null), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scPlants.set_PlantId)), (Expression)Expression.Property((Expression)parameterExpression2, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SEPlant.get_SEPlantId)))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scPlants.set_PlantDesin)), (Expression)Expression.Property((Expression)parameterExpression2, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SEPlant.get_SEPlantDesin)))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scPlants.set_PlantName)), (Expression)Expression.Property((Expression)parameterExpression2, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SEPlant.get_SEPlantName)))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scPlants.set_PlantCity)), (Expression)Expression.Property((Expression)parameterExpression2, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SEPlant.get_SEPlantCity)))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scPlants.set_PlantState)), (Expression)Expression.Property((Expression)parameterExpression2, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SEPlant.get_SEPlantState)))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scPlants.set_PlantValue)), (Expression)Expression.ConvertChecked((Expression)Expression.Property((Expression)parameterExpression2, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SEPlant.get_SEPlantValue))), typeof(byte))), (MemberBinding)Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(__methodref(scPlants.set_PlantActiveBool)), (Expression)Expression.Convert((Expression)Expression.Property((Expression)parameterExpression2, (MethodInfo)MethodBase.GetMethodFromHandle(__methodref(SEPlant.get_SEPlantActive))), typeof(bool)))), new ParameterExpression[1]
                //{
                //  parameterExpression2
                //}));

                IQueryable<scPlants> source = (from s in se0085CtEntities1.SEPlants
                                               where (s.SEPlantId == PlantId)
                                               select new scPlants
                                               {
                                                   PlantId = s.SEPlantId,
                                                   PlantDesin = s.SEPlantDesin,
                                                   PlantName = s.SEPlantName,
                                                   PlantCity = s.SEPlantCity,
                                                   PlantState = s.SEPlantState,
                                                   PlantValue = s.SEPlantValue.HasValue ? s.SEPlantValue.Value : (byte)0
                                                   //PlantActive = s.SEPlantActive.HasValue ? s.SEPlantActive.Value : (byte)0
                                               }).AsQueryable<scPlants>();
                if (source != null && source.Count<scPlants>() == 1)
                    scPlants = source.First<scPlants>();
                this._Plant = scPlants;
                se0085CtEntities1.Database.Connection.Close();
            }
            return scPlants;
        }
    }
}
