Пример #1
0
        /// <summary>
        /// Return all subactivities (level 2) that fullfill search criteria.
        /// If activityCodes are null, all activities will be returned. If activityCodes is empty no activities will be returned.
        /// Notice that this will include one subactivity "Not specified on this level" for each activity, even if the activity do not have any subactivities at all!
        /// </summary>
        public static IEnumerable <ActivityTreeListRow> GetSubActivities(PollutantTransfersSearchFilter filter, List <string> activityCodes)
        {
            if (activityCodes != null && activityCodes.Count() == 0)
            {
                return(new List <ActivityTreeListRow>());
            }

            DataClassesPollutantTransferDataContext      db     = getPollutantTransferDataContext();
            Expression <Func <POLLUTANTTRANSFER, bool> > lambda = getActivityAreaLambda(filter);

            //add activities to expression
            if (activityCodes != null)
            {
                ParameterExpression param       = lambda.Parameters[0];
                Expression          activityExp = LinqExpressionBuilder.GetInExpr(param, "IAActivityCode", activityCodes);

                Expression exp = LinqExpressionBuilder.CombineAnd(lambda.Body, activityExp);
                lambda = Expression.Lambda <Func <POLLUTANTTRANSFER, bool> >(exp, param);
            }

            //find data for sub-activity level, this level never has children.
            IEnumerable <ActivityTreeListRow> subactivities = db.POLLUTANTTRANSFERs.Where(lambda)
                                                              .GroupBy(p => new { SectorCode = p.IASectorCode, ActivityCode = p.IAActivityCode, SubActivityCode = p.IASubActivityCode, PollutantCode = p.PollutantCode })
                                                              .Select(x => new ActivityTreeListRow(
                                                                          x.Key.SectorCode,
                                                                          x.Key.ActivityCode,
                                                                          !x.Key.SubActivityCode.Equals(null) ? x.Key.SubActivityCode : ActivityTreeListRow.CODE_UNSPECIFIED,
                                                                          x.Key.PollutantCode,
                                                                          x.Count(),
                                                                          x.Sum(p => p.Quantity),
                                                                          false));

            return(subactivities);
        }
Пример #2
0
        /// <summary>
        /// return all activities (level 1) that fullfill search criteria within the sectorCodes given.
        /// If sectorCodes are null, all activities will be returned. If sectorCodes is empty no activities will be returned.
        /// </summary>
        public static IEnumerable <ActivityTreeListRow> GetActivities(PollutantTransfersSearchFilter filter, List <string> sectorCodes)
        {
            if (sectorCodes != null && sectorCodes.Count() == 0)
            {
                return(new List <ActivityTreeListRow>());
            }

            DataClassesPollutantTransferDataContext      db     = getPollutantTransferDataContext();
            Expression <Func <POLLUTANTTRANSFER, bool> > lambda = getActivityAreaLambda(filter);

            if (sectorCodes != null)
            {
                ParameterExpression param     = lambda.Parameters[0];
                Expression          sectorExp = LinqExpressionBuilder.GetInExpr(param, "IASectorCode", sectorCodes);

                Expression exp = LinqExpressionBuilder.CombineAnd(lambda.Body, sectorExp);
                lambda = Expression.Lambda <Func <POLLUTANTTRANSFER, bool> >(exp, param);
            }

            //find data for activity level
            IEnumerable <ActivityTreeListRow> activities = db.POLLUTANTTRANSFERs.Where(lambda)
                                                           .GroupBy(p => new { SectorCode = p.IASectorCode, ActivityCode = p.IAActivityCode, PollutantCode = p.PollutantCode })
                                                           .Select(x => new ActivityTreeListRow(
                                                                       x.Key.SectorCode,
                                                                       x.Key.ActivityCode,
                                                                       null,
                                                                       x.Key.PollutantCode,
                                                                       x.Count(),
                                                                       x.Sum(p => p.Quantity),
                                                                       x.First(p => !p.IASubActivityCode.Equals(null)) != null));

            return(activities);
        }
Пример #3
0
        private static Expression <Func <WASTETRANSFER_CONFIDENTIAL, bool> > getLambdaExpressionConfidential(WasteTransferTimeSeriesFilter filter, WasteTypeFilter.Type wasteType)
        {
            Expression <Func <WASTETRANSFER_CONFIDENTIAL, bool> > lambda = getLambdaExpressionConfidential(filter);
            ParameterExpression param = lambda.Parameters[0];

            //Apply waste type
            Expression expType = LinqExpressionBuilder.GetLinqExpressionWasteTransferType(wasteType, param, true);
            Expression exp     = LinqExpressionBuilder.CombineAnd(lambda.Body, expType);

            lambda = Expression.Lambda <Func <WASTETRANSFER_CONFIDENTIAL, bool> >(exp, param);
            return(lambda);
        }
Пример #4
0
        private static Expression <Func <POLLUTANTRELEASE, bool> > getLambdaExpression(PollutantReleasesTimeSeriesFilter filter, MediumFilter.Medium medium)
        {
            // apply filter
            ParameterExpression param = Expression.Parameter(typeof(POLLUTANTRELEASE), "p");
            Expression          exp   = LinqExpressionBuilder.GetLinqExpressionPollutantReleases(filter, param);

            //apply medium condition
            Expression expMedium = LinqExpressionBuilder.GetLinqExpressionMediumRelease(medium, param);

            exp = LinqExpressionBuilder.CombineAnd(exp, expMedium);

            Expression <Func <POLLUTANTRELEASE, bool> > lambda = Expression.Lambda <Func <POLLUTANTRELEASE, bool> >(exp, param);

            return(lambda);
        }
Пример #5
0
        ///<summary>
        ///Return all subareas (level 1) that fullfill search criteria.
        ///If countryCodes are null, all subareas will be returned. If countryCodes is empty no subareas will be returned.
        ///</summary>
        public static IEnumerable <AreaTreeListRow> GetSubAreas(PollutantTransfersSearchFilter filter, List <string> countryCodes)
        {
            if (countryCodes != null && countryCodes.Count() == 0)
            {
                return(new List <AreaTreeListRow>());
            }

            DataClassesPollutantTransferDataContext      db     = getPollutantTransferDataContext();
            Expression <Func <POLLUTANTTRANSFER, bool> > lambda = getActivityAreaLambda(filter);

            //add countries to expression
            if (countryCodes != null)
            {
                ParameterExpression param      = lambda.Parameters[0];
                Expression          countryExp = LinqExpressionBuilder.GetInExpr(param, "CountryCode", countryCodes);

                Expression exp = LinqExpressionBuilder.CombineAnd(lambda.Body, countryExp);
                lambda = Expression.Lambda <Func <POLLUTANTTRANSFER, bool> >(exp, param);
            }

            //find data for sub-activity level, this level never has children.

            AreaFilter.RegionType regionType = filter.AreaFilter.TypeRegion;
            bool isRbd = AreaFilter.RegionType.RiverBasinDistrict.Equals(regionType);

            IEnumerable <AreaTreeListRow> subareas = db.POLLUTANTTRANSFERs.Where(lambda)
                                                     .GroupBy(p => new { CountryCode = p.CountryCode, SubAreaCode = isRbd ? p.RiverBasinDistrictCode : p.NUTSLevel2RegionCode, PollutantCode = p.PollutantCode })
                                                     .Select(x => new AreaTreeListRow(
                                                                 x.Key.CountryCode,
                                                                 !x.Key.SubAreaCode.Equals(null) ? x.Key.SubAreaCode : AreaTreeListRow.CODE_UNKNOWN,
                                                                 regionType,
                                                                 x.Key.PollutantCode,
                                                                 x.Count(),
                                                                 x.Sum(p => p.Quantity),
                                                                 false));

            return(subareas);
        }