예제 #1
0
 public BaseDataAccess(Dictionary <DictionaryParameter, string> parameters = null)
 {
     DataContext = new FaoDataContext
     {
         Log            = new DebugTextWriter(),
         CommandTimeout = 180
     };
     Parameters = parameters;
 }
예제 #2
0
        public static List <ListItem> GetCommercialCarSegments(FaoDataContext dataContext, bool allSelected = false)
        {
            var listItems = from ccs in dataContext.CommercialCarSegments
                            select new ListItem(ccs.Name, ccs.CommercialCarSegmentId.ToString(CultureInfo.InvariantCulture));
            var returned = listItems.ToList();

            if (allSelected)
            {
                returned.ForEach(d => d.Selected = true);
            }
            return(returned);
        }
예제 #3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         using (var dataAccess = new FaoDataContext())
         {
             var segments = ListItemAccess.GetCommercialCarSegments(dataAccess, true);
             lbCommercialCarSegment.Items.AddRange(segments.ToArray());
             var daysOfWeek = ListItemAccess.GetDayOfWeeks(true);
             lbDayOfWeek.Items.AddRange(daysOfWeek.ToArray());
         }
         FillMonthSelector();
     }
 }
        public static IQueryable <MaxFleetFactor> GetCommercialCarSemgents(FaoDataContext dataContext
                                                                           , Dictionary <DictionaryParameter, string> parameters)
        {
            var maxFleetFactors = from mff in dataContext.MaxFleetFactors
                                  select mff;

            if (parameters.ContainsKey(DictionaryParameter.DayOfWeek) &&
                parameters[DictionaryParameter.DayOfWeek] != string.Empty)
            {
                var dayOfWeek = int.Parse(parameters[DictionaryParameter.DayOfWeek]);
                maxFleetFactors = maxFleetFactors.Where(d => d.DayOfWeekId == dayOfWeek);
            }


            return(maxFleetFactors);
        }
예제 #5
0
        public static IQueryable <CommercialCarSegment> GetCommercialCarSemgents(FaoDataContext dataContext
                                                                                 , Dictionary <DictionaryParameter, string> parameters)
        {
            var commCarSeg = from ccs in dataContext.CommercialCarSegments
                             select ccs;

            if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.CommercialCarSegment))
            {
                var segementsRequested = parameters[DictionaryParameter.CommercialCarSegment];
                var splitSegments      = segementsRequested.Split(VehicleFieldRestrictions.Separator.ToCharArray()).Select(int.Parse);


                commCarSeg = commCarSeg.Where(d => splitSegments.Contains(d.CommercialCarSegmentId));
            }

            return(commCarSeg);
        }
예제 #6
0
        public static IQueryable <CAR_SEGMENT> GetCarSegments(FaoDataContext dataContext
                                                              , Dictionary <DictionaryParameter, string> parameters)
        {
            var carSegments = from cs in dataContext.CAR_SEGMENTs
                              select cs;

            if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.CarSegment))
            {
                var carSegmentId = int.Parse(parameters[DictionaryParameter.CarSegment]);
                carSegments = carSegments.Where(d => d.car_segment_id == carSegmentId);
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.OwningCountry))
            {
                var owningCountry = parameters[DictionaryParameter.OwningCountry];
                carSegments = carSegments.Where(d => d.country == owningCountry);
            }

            return(carSegments);
        }
예제 #7
0
        public static IQueryable <LOCATION> GetLocations(FaoDataContext dataContext
                                                         , Dictionary <DictionaryParameter, string> parameters)
        {
            var locations = from l in dataContext.LOCATIONs
                            select l;

            if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.Location))
            {
                var locationString = parameters[DictionaryParameter.Location];

                if (!locationString.Contains(Separator))
                {
                    var locationId = int.Parse(locationString);
                    locations = locations.Where(d => d.dim_Location_id == locationId);
                }
                else
                {
                    var splitLocationIds = locationString.Split(Separator.ToCharArray()).Select(int.Parse);
                    locations = from l in locations
                                where splitLocationIds.Contains(l.dim_Location_id)
                                select l;
                }
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.LocationGroup))
            {
                var locationGroupString = parameters[DictionaryParameter.LocationGroup];
                if (!locationGroupString.Contains(Separator))
                {
                    var locationGroupId = int.Parse(locationGroupString);
                    locations = locations.Where(d => d.cms_location_group_id == locationGroupId);
                }
                else
                {
                    var splitLocationGroupIds = locationGroupString.Split(Separator.ToCharArray()).Select(int.Parse);
                    locations = from l in locations
                                where l.cms_location_group_id != null && splitLocationGroupIds.Contains(l.cms_location_group_id.Value)
                                select l;
                }
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.Pool))
            {
                var poolsString = parameters[DictionaryParameter.Pool];
                if (!poolsString.Contains(Separator))
                {
                    var poolId = int.Parse(poolsString);
                    locations = locations.Where(d => d.CMS_LOCATION_GROUP.cms_pool_id == poolId);
                }
                else
                {
                    var splitPoolIds = poolsString.Split(Separator.ToCharArray()).Select(int.Parse);
                    locations = from l in locations
                                where l.cms_location_group_id != null && splitPoolIds.Contains(l.CMS_LOCATION_GROUP.cms_pool_id)
                                select l;
                }
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.LocationCountry))
            {
                var locationCountryString = parameters[DictionaryParameter.LocationCountry];
                if (!locationCountryString.Contains(Separator))
                {
                    var locationCountryId = locationCountryString;
                    locations = locations.Where(d => d.CMS_LOCATION_GROUP.CMS_POOL.country == locationCountryId);
                }
                else
                {
                    var splitLocationCountryIds = locationCountryString.Split(Separator.ToCharArray());
                    locations = from l in locations
                                where l.cms_location_group_id != null && splitLocationCountryIds.Contains(l.CMS_LOCATION_GROUP.CMS_POOL.country)
                                select l;
                }
            }
            return(locations);
        }
예제 #8
0
        /// <summary>
        /// Returns Revenue and Holding Cost Averaged in Range
        /// </summary>
        /// <param name="dataContext"></param>
        /// <param name="minDate"></param>
        /// <returns></returns>
        public static IQueryable <ContributionEntity> GetContribution(FaoDataContext dataContext, DateTime minDate)
        {
            var revenueData = from rev in dataContext.RevenueByCommercialCarSegments
                              where rev.MonthDate >= minDate
                              group rev by new { rev.CarGroupId, rev.LocationId, rev.MonthDate }
            into groupedData
            //Sum Commercial Car Segment away
                select new
            {
                groupedData.Key.CarGroupId,
                groupedData.Key.LocationId,
                groupedData.Key.MonthDate,
                Revenue = groupedData.Sum(d => d.GrossRevenue)
            }
            into groupedByDate
            //Sum Three months to one
            group groupedByDate by new { groupedByDate.CarGroupId, groupedByDate.LocationId }
            into fullyGrouped
                select
            new
            {
                fullyGrouped.Key.CarGroupId,
                fullyGrouped.Key.LocationId,
                Revenue = fullyGrouped.Average(d => d.Revenue)
            };

            //
            var lifeCycleData = from ld in dataContext.LifecycleHoldingCosts
                                where ld.MonthDate >= minDate
                                group ld by ld.CarGroupId
                                into fullyGrouped
                                select new
            {
                CarGroupId  = fullyGrouped.Key,
                HoldingCost = fullyGrouped.Average(d => d.Cost)
            };


            var fullRevData = from rd in revenueData
                              join ld in lifeCycleData on rd.CarGroupId equals ld.CarGroupId
                              into jLd
                              from joinedLd in jLd.DefaultIfEmpty()
                              select new ContributionEntity
            {
                LocationId  = rd.LocationId,
                CarGroupId  = rd.CarGroupId,
                Revenue     = rd.Revenue,
                HoldingCost = joinedLd == null ? 0 : joinedLd.HoldingCost,
            };

            ////

            //var distinctRevCarGroups = revenueData.Select(d => d.CarGroupId);
            //var distinctHcCarGroups = lifeCycleData.Select(d => d.CarGroupId);
            //var distinctLocations = revenueData.Select(d => d.LocationId);

            //var fullCarGroupList = distinctRevCarGroups.Union(distinctHcCarGroups).Distinct();

            //var fullList = from fcg in fullCarGroupList
            //    join rd in revenueData on fcg equals rd.CarGroupId
            //    into jRd
            //    from joinedRd in jRd.DefaultIfEmpty()
            //    join hc in lifeCycleData on fcg equals hc.CarGroupId
            //    //into jHc
            //    //from joinedHc in jHc.DefaultIfEmpty()
            //    select new ContributionEntity
            //           {
            //               CarGroupId = fcg,
            //               //LocationId = joinedRd == null
            //           };

            //var leftJoin = from rd in revenueData
            //                  join ld in lifeCycleData on rd.CarGroupId equals ld.CarGroupId
            //                  into jLd
            //                  from joinedLd in jLd.DefaultIfEmpty()
            //                  select new ContributionEntity
            //                  {
            //                      LocationId = rd.LocationId,
            //                      CarGroupId = rd.CarGroupId,
            //                      Revenue = rd.Revenue,
            //                      HoldingCost = joinedLd == null ? 0 : joinedLd.HoldingCost,
            //                  };



            //var rightJoin = from ld in lifeCycleData
            //               where !(from rd in revenueData
            //                      select rd.CarGroupId).Contains(ld.CarGroupId)

            //               select new ContributionEntity
            //               {
            //                   LocationId = rd.LocationId,
            //                   CarGroupId = rd.CarGroupId,
            //                   Revenue = rd.Revenue,
            //                   HoldingCost = joinedLd == null ? 0 : joinedLd.HoldingCost,
            //               };


            var returned = fullRevData;

            return(returned);
        }
        public static IQueryable <FleetHistory> GetAvailabilityHistory(FaoDataContext dataContext, Dictionary <DictionaryParameter, string> parameters)
        {
            var availability = dataContext.FleetHistories.Select(d => d);
            var startDate    = parameters.GetDateFromDictionary(DictionaryParameter.StartDate);
            var endDate      = parameters.GetDateFromDictionary(DictionaryParameter.EndDate);


            availability = availability.Where(d => d.Timestamp.Date >= startDate);
            if (endDate != DateTime.MinValue)
            {
                availability = availability.Where(d => d.Timestamp.Date <= endDate);
            }

            if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.FleetTypes))
            {
                var selectedFleetTypes = parameters[DictionaryParameter.FleetTypes].Split(',').Select(byte.Parse);
                availability = availability.Where(d => selectedFleetTypes.Contains(d.FleetTypeId));
            }

            if (parameters.ContainsKey(DictionaryParameter.DayOfWeek) &&
                parameters[DictionaryParameter.DayOfWeek] != string.Empty)
            {
                DayOfWeek dowEntered;
                var       success = Enum.TryParse(parameters[DictionaryParameter.DayOfWeek], out dowEntered);
                if (!success)
                {
                    throw new InvalidCastException("Unable to case Day of Week");
                }
                availability = availability.Where(d => d.Timestamp.DayOfWeek == dowEntered);
            }

            if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.CarGroup))
            {
                var carGroupString = parameters[DictionaryParameter.CarGroup];

                if (!carGroupString.Contains(LocationQueryable.Separator))
                {
                    var carGroupId = int.Parse(carGroupString);
                    availability = availability.Where(d => d.CarGroupId == carGroupId);
                }
                else
                {
                    var splitCarGroupIds = carGroupString.Split(LocationQueryable.Separator.ToCharArray()).Select(int.Parse);
                    availability = from a in availability
                                   where splitCarGroupIds.Contains(a.CarGroupId)
                                   select a;
                }
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.CarClass))
            {
                var carClassString = parameters[DictionaryParameter.CarClass];

                if (!carClassString.Contains(LocationQueryable.Separator))
                {
                    var carClassId = int.Parse(carClassString);
                    availability = availability.Where(d => d.CAR_GROUP.car_class_id == carClassId);
                }
                else
                {
                    var splitCarClassIds = carClassString.Split(LocationQueryable.Separator.ToCharArray()).Select(int.Parse);
                    availability = from a in availability
                                   where splitCarClassIds.Contains(a.CAR_GROUP.car_class_id)
                                   select a;
                }
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.CarSegment))
            {
                var carSegmentString = parameters[DictionaryParameter.CarSegment];

                if (!carSegmentString.Contains(LocationQueryable.Separator))
                {
                    var carSegmentId = int.Parse(carSegmentString);
                    availability = availability.Where(d => d.CAR_GROUP.CAR_CLASS.car_segment_id == carSegmentId);
                }
                else
                {
                    var splitCarSegmentIds = carSegmentString.Split(LocationQueryable.Separator.ToCharArray()).Select(int.Parse);
                    availability = from a in availability
                                   where splitCarSegmentIds.Contains(a.CAR_GROUP.CAR_CLASS.car_segment_id)
                                   select a;
                }
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.OwningCountry))
            {
                var owningCountryString = parameters[DictionaryParameter.OwningCountry];

                if (!owningCountryString.Contains(LocationQueryable.Separator))
                {
                    var carOwningCountryId = owningCountryString;
                    availability = availability.Where(d => d.CAR_GROUP.CAR_CLASS.CAR_SEGMENT.country == carOwningCountryId);
                }
                else
                {
                    var splitOwningCountryIds = owningCountryString.Split(LocationQueryable.Separator.ToCharArray());
                    availability = from a in availability
                                   where splitOwningCountryIds.Contains(a.CAR_GROUP.CAR_CLASS.CAR_SEGMENT.country)
                                   select a;
                }
            }


            if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.Location))
            {
                var locationString = parameters[DictionaryParameter.Location];

                if (!locationString.Contains(LocationQueryable.Separator))
                {
                    var locationId = int.Parse(locationString);
                    availability = availability.Where(d => d.LocationId == locationId);
                }
                else
                {
                    var splitLocationIds = locationString.Split(LocationQueryable.Separator.ToCharArray()).Select(int.Parse);
                    availability = from a in availability
                                   where splitLocationIds.Contains(a.LocationId)
                                   select a;
                }
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.LocationGroup))
            {
                var locationGroupString = parameters[DictionaryParameter.LocationGroup];
                if (!locationGroupString.Contains(LocationQueryable.Separator))
                {
                    var locationGroupId = int.Parse(locationGroupString);
                    availability = availability.Where(d => d.LOCATION.cms_location_group_id == locationGroupId);
                }
                else
                {
                    var splitLocationGroupIds = locationGroupString.Split(LocationQueryable.Separator.ToCharArray()).Select(int.Parse);
                    availability = from a in availability
                                   where splitLocationGroupIds.Contains(a.LOCATION.cms_location_group_id.Value)
                                   select a;
                }
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.Pool))
            {
                var poolsString = parameters[DictionaryParameter.Pool];
                if (!poolsString.Contains(LocationQueryable.Separator))
                {
                    var poolId = int.Parse(poolsString);
                    availability = availability.Where(d => d.LOCATION.CMS_LOCATION_GROUP.cms_pool_id == poolId);
                }
                else
                {
                    var splitPoolIds = poolsString.Split(LocationQueryable.Separator.ToCharArray()).Select(int.Parse);
                    availability = from a in availability
                                   where splitPoolIds.Contains(a.LOCATION.CMS_LOCATION_GROUP.cms_pool_id)
                                   select a;
                }
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.LocationCountry))
            {
                var locationCountryString = parameters[DictionaryParameter.LocationCountry];
                if (!locationCountryString.Contains(LocationQueryable.Separator))
                {
                    var locationCountryId = locationCountryString;
                    availability = availability.Where(d => d.LOCATION.CMS_LOCATION_GROUP.CMS_POOL.country == locationCountryId);
                }
                else
                {
                    var splitLocationCountryIds = locationCountryString.Split(LocationQueryable.Separator.ToCharArray());
                    availability = from a in availability
                                   where splitLocationCountryIds.Contains(a.LOCATION.CMS_LOCATION_GROUP.CMS_POOL.country)
                                   select a;
                }
            }

            return(availability);
        }
예제 #10
0
        public static IQueryable <CAR_GROUP> GetCarGroups(FaoDataContext dataContext
                                                          , Dictionary <DictionaryParameter, string> parameters)
        {
            var carGroups = from cg in dataContext.CAR_GROUPs
                            select cg;

            if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.CarGroup))
            {
                var carGroupString = parameters[DictionaryParameter.CarGroup];

                if (!carGroupString.Contains(LocationQueryable.Separator))
                {
                    var carGroupId = int.Parse(carGroupString);
                    carGroups = carGroups.Where(d => d.car_group_id == carGroupId);
                }
                else
                {
                    var splitCarGroupIds = carGroupString.Split(LocationQueryable.Separator.ToCharArray()).Select(int.Parse);
                    carGroups = from cg in carGroups
                                where splitCarGroupIds.Contains(cg.car_group_id)
                                select cg;
                }
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.CarClass))
            {
                var carClassString = parameters[DictionaryParameter.CarClass];

                if (!carClassString.Contains(LocationQueryable.Separator))
                {
                    var carClassId = int.Parse(carClassString);
                    carGroups = carGroups.Where(d => d.car_class_id == carClassId);
                }
                else
                {
                    var splitCarClassIds = carClassString.Split(LocationQueryable.Separator.ToCharArray()).Select(int.Parse);
                    carGroups = from cg in carGroups
                                where splitCarClassIds.Contains(cg.car_class_id)
                                select cg;
                }
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.CarSegment))
            {
                var carSegmentString = parameters[DictionaryParameter.CarSegment];

                if (!carSegmentString.Contains(LocationQueryable.Separator))
                {
                    var carSegmentId = int.Parse(carSegmentString);
                    carGroups = carGroups.Where(d => d.CAR_CLASS.car_segment_id == carSegmentId);
                }
                else
                {
                    var splitCarSegmentIds = carSegmentString.Split(LocationQueryable.Separator.ToCharArray()).Select(int.Parse);
                    carGroups = from cg in carGroups
                                where splitCarSegmentIds.Contains(cg.CAR_CLASS.car_segment_id)
                                select cg;
                }
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.OwningCountry))
            {
                var owningCountryString = parameters[DictionaryParameter.OwningCountry];

                if (!owningCountryString.Contains(LocationQueryable.Separator))
                {
                    var carOwningCountryId = owningCountryString;
                    carGroups = carGroups.Where(d => d.CAR_CLASS.CAR_SEGMENT.country == carOwningCountryId);
                }
                else
                {
                    var splitOwningCountryIds = owningCountryString.Split(LocationQueryable.Separator.ToCharArray());
                    carGroups = from cg in carGroups
                                where splitOwningCountryIds.Contains(cg.CAR_CLASS.CAR_SEGMENT.country)
                                select cg;
                }
            }

            return(carGroups);
        }
        public static IQueryable <ResDeletion> GetDeletions(FaoDataContext dataContext, Dictionary <DictionaryParameter, string> parameters)
        {
            var deletions = from ra in dataContext.ResDeletions
                            select ra;

            if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.ForecastStartDate))
            {
                var forecastStartDate = DateTime.Parse(parameters[DictionaryParameter.ForecastStartDate]);
                deletions = deletions.Where(d => d.RepDate >= forecastStartDate);
            }

            if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.ForecastEndDate))
            {
                var forecastEndDate = DateTime.Parse(parameters[DictionaryParameter.ForecastEndDate]);
                deletions = deletions.Where(d => d.RepDate >= forecastEndDate);
            }

            if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.CarGroup))
            {
                var carGroupString = parameters[DictionaryParameter.CarGroup];

                var carGroupId = int.Parse(carGroupString);
                deletions = deletions.Where(d => d.CarGrpId == carGroupId);
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.CarClass))
            {
                var carClassString = parameters[DictionaryParameter.CarClass];


                var carClassId = int.Parse(carClassString);
                deletions = deletions.Where(d => d.CAR_GROUP.car_class_id == carClassId);
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.CarSegment))
            {
                var carSegmentString = parameters[DictionaryParameter.CarSegment];
                var carSegmentId     = int.Parse(carSegmentString);
                deletions = deletions.Where(d => d.CAR_GROUP.CAR_CLASS.car_segment_id == carSegmentId);
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.OwningCountry))
            {
                var owningCountryString = parameters[DictionaryParameter.OwningCountry];
                var carOwningCountryId  = owningCountryString;
                deletions = deletions.Where(d => d.CAR_GROUP.CAR_CLASS.CAR_SEGMENT.country == carOwningCountryId);
            }

            //
            if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.Location))
            {
                var locationString = parameters[DictionaryParameter.Location];
                var locationId     = int.Parse(locationString);
                deletions = deletions.Where(d => d.LocId == locationId);
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.LocationGroup))
            {
                var locationGroupString = parameters[DictionaryParameter.LocationGroup];
                var locationGroupId     = int.Parse(locationGroupString);
                deletions = deletions.Where(d => d.LOCATION.cms_location_group_id == locationGroupId);
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.Pool))
            {
                var poolsString = parameters[DictionaryParameter.Pool];

                var poolId = int.Parse(poolsString);
                deletions = deletions.Where(d => d.LOCATION.CMS_LOCATION_GROUP.cms_pool_id == poolId);
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.LocationCountry))
            {
                var locationCountryString = parameters[DictionaryParameter.LocationCountry];

                var locationCountryId = locationCountryString;
                deletions = deletions.Where(d => d.LOCATION.CMS_LOCATION_GROUP.CMS_POOL.country == locationCountryId);
            }

            return(deletions);
        }
예제 #12
0
        public static IQueryable <AdditionPlanEntry> GetAdditionPlanEntries(FaoDataContext dc,
                                                                            Dictionary <DictionaryParameter, string> parameters)
        {
            var additionPlanEntities = from ape in dc.AdditionPlanEntries
                                       select ape;

            if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.CarGroup))
            {
                var carGroupId = int.Parse(parameters[DictionaryParameter.CarGroup]);
                additionPlanEntities = additionPlanEntities.Where(d => d.CarGroupId == carGroupId);
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.CarClass))
            {
                var carClassId = int.Parse(parameters[DictionaryParameter.CarClass]);
                additionPlanEntities = additionPlanEntities.Where(d => d.CAR_GROUP.car_class_id == carClassId);
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.CarSegment))
            {
                var carSegmentId = int.Parse(parameters[DictionaryParameter.CarSegment]);
                additionPlanEntities = additionPlanEntities.Where(d => d.CAR_GROUP.CAR_CLASS.car_segment_id == carSegmentId);
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.OwningCountry))
            {
                var owningCountry = parameters[DictionaryParameter.OwningCountry];
                additionPlanEntities = additionPlanEntities.Where(d => d.CAR_GROUP.CAR_CLASS.CAR_SEGMENT.country == owningCountry);
            }


            if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.Location))
            {
                var location = int.Parse(parameters[DictionaryParameter.Location]);
                additionPlanEntities = additionPlanEntities.Where(d => d.LOCATION.dim_Location_id == location);
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.LocationGroup) ||
                     parameters.ContainsValueAndIsntEmpty(DictionaryParameter.Area))
            {
                if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.LocationGroup))
                {
                    var locationGroupId = int.Parse(parameters[DictionaryParameter.LocationGroup]);
                    additionPlanEntities = from av in additionPlanEntities
                                           where av.LOCATION.cms_location_group_id == locationGroupId
                                           select av;
                }
                else
                {
                    var areaId = int.Parse(parameters[DictionaryParameter.Area]);
                    additionPlanEntities = from av in additionPlanEntities
                                           where av.LOCATION.ops_area_id == areaId
                                           select av;
                }
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.Pool) ||
                     parameters.ContainsValueAndIsntEmpty(DictionaryParameter.Region))
            {
                if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.Pool))
                {
                    var poolId = int.Parse(parameters[DictionaryParameter.Pool]);
                    additionPlanEntities = from av in additionPlanEntities
                                           where av.LOCATION.CMS_LOCATION_GROUP.cms_pool_id == poolId
                                           select av;
                }
                else
                {
                    var regionId = int.Parse(parameters[DictionaryParameter.Region]);
                    additionPlanEntities = from av in additionPlanEntities
                                           where av.LOCATION.OPS_AREA.ops_region_id == regionId
                                           select av;
                }
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.LocationCountry))
            {
                var locationCountry = parameters[DictionaryParameter.LocationCountry];
                additionPlanEntities = from av in additionPlanEntities
                                       where av.LOCATION.CMS_LOCATION_GROUP.CMS_POOL.country == locationCountry
                                       select av;
            }
            return(additionPlanEntities);
        }
예제 #13
0
 public MinFleetDataAccess(Dictionary <DictionaryParameter, string> parameters, FaoDataContext dc)
     : base(parameters, dc)
 {
 }
예제 #14
0
        public static IQueryable <FleetSizeFutureTrend> GetFutureTrend(FaoDataContext dataContext
                                                                       , Dictionary <DictionaryParameter, string> parameters)
        {
            var forecast = from fc in dataContext.FleetSizeFutureTrends
                           select fc;

            var startDate = parameters.GetDateFromDictionary(DictionaryParameter.ForecastStartDate);
            var endDate   = parameters.GetDateFromDictionary(DictionaryParameter.ForecastEndDate);

            forecast = forecast.Where(d => d.TargetDate >= startDate);

            forecast = forecast.Where(d => d.TargetDate <= endDate);

            if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.CarGroup))
            {
                var carGroupString = parameters[DictionaryParameter.CarGroup];

                if (!carGroupString.Contains(LocationQueryable.Separator))
                {
                    var carGroupId = int.Parse(carGroupString);
                    forecast = forecast.Where(d => d.CarGrpId == carGroupId);
                }
                else
                {
                    var splitCarGroupIds = carGroupString.Split(LocationQueryable.Separator.ToCharArray()).Select(int.Parse);
                    forecast = from a in forecast
                               where splitCarGroupIds.Contains(a.CarGrpId)
                               select a;
                }
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.CarClass))
            {
                var carClassString = parameters[DictionaryParameter.CarClass];

                if (!carClassString.Contains(LocationQueryable.Separator))
                {
                    var carClassId = int.Parse(carClassString);
                    forecast = forecast.Where(d => d.CAR_GROUP.car_class_id == carClassId);
                }
                else
                {
                    var splitCarClassIds = carClassString.Split(LocationQueryable.Separator.ToCharArray()).Select(int.Parse);
                    forecast = from a in forecast
                               where splitCarClassIds.Contains(a.CAR_GROUP.car_class_id)
                               select a;
                }
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.CarSegment))
            {
                var carSegmentString = parameters[DictionaryParameter.CarSegment];

                if (!carSegmentString.Contains(LocationQueryable.Separator))
                {
                    var carSegmentId = int.Parse(carSegmentString);
                    forecast = forecast.Where(d => d.CAR_GROUP.CAR_CLASS.car_segment_id == carSegmentId);
                }
                else
                {
                    var splitCarSegmentIds = carSegmentString.Split(LocationQueryable.Separator.ToCharArray()).Select(int.Parse);
                    forecast = from a in forecast
                               where splitCarSegmentIds.Contains(a.CAR_GROUP.CAR_CLASS.car_segment_id)
                               select a;
                }
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.OwningCountry))
            {
                var owningCountryString = parameters[DictionaryParameter.OwningCountry];

                if (!owningCountryString.Contains(LocationQueryable.Separator))
                {
                    var carOwningCountryId = owningCountryString;
                    forecast = forecast.Where(d => d.CAR_GROUP.CAR_CLASS.CAR_SEGMENT.country == carOwningCountryId);
                }
                else
                {
                    var splitOwningCountryIds = owningCountryString.Split(LocationQueryable.Separator.ToCharArray());
                    forecast = from a in forecast
                               where splitOwningCountryIds.Contains(a.CAR_GROUP.CAR_CLASS.CAR_SEGMENT.country)
                               select a;
                }
            }

            if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.LocationGroup))
            {
                var locationGroupString = parameters[DictionaryParameter.LocationGroup];
                if (!locationGroupString.Contains(LocationQueryable.Separator))
                {
                    var locationGroupId = int.Parse(locationGroupString);
                    forecast = forecast.Where(d => d.LocGrpId == locationGroupId);
                }
                else
                {
                    var splitLocationGroupIds = locationGroupString.Split(LocationQueryable.Separator.ToCharArray()).Select(int.Parse);
                    forecast = from a in forecast
                               where splitLocationGroupIds.Contains(a.LocGrpId)
                               select a;
                }
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.Pool))
            {
                var poolsString = parameters[DictionaryParameter.Pool];
                if (!poolsString.Contains(LocationQueryable.Separator))
                {
                    var poolId = int.Parse(poolsString);
                    forecast = forecast.Where(d => d.CMS_LOCATION_GROUP.cms_pool_id == poolId);
                }
                else
                {
                    var splitPoolIds = poolsString.Split(LocationQueryable.Separator.ToCharArray()).Select(int.Parse);
                    forecast = from a in forecast
                               where splitPoolIds.Contains(a.CMS_LOCATION_GROUP.cms_pool_id)
                               select a;
                }
            }
            else if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.LocationCountry))
            {
                var locationCountryString = parameters[DictionaryParameter.LocationCountry];
                if (!locationCountryString.Contains(LocationQueryable.Separator))
                {
                    var locationCountryId = locationCountryString;
                    forecast = forecast.Where(d => d.CMS_LOCATION_GROUP.CMS_POOL.country == locationCountryId);
                }
                else
                {
                    var splitLocationCountryIds = locationCountryString.Split(LocationQueryable.Separator.ToCharArray());
                    forecast = from a in forecast
                               where splitLocationCountryIds.Contains(a.CMS_LOCATION_GROUP.CMS_POOL.country)
                               select a;
                }
            }

            return(forecast);
        }