Example #1
0
        public IEnumerable <ReportItem <TValue> > Generate <TValue>(ReportInput input)
        {
            if (input == null)
            {
                throw new System.ArgumentNullException(nameof(input));
            }

            switch (input.GroupBy)
            {
            case ReportGroupMetric.Day:
                return(GenerateByDay <TValue>(input.From, input.To));

            case ReportGroupMetric.Month:
                return(GenerateByMonth <TValue>(input.From, input.To));

            case ReportGroupMetric.Year:
                return(GenerateByYear <TValue>(input.From, input.To));

            case ReportGroupMetric.PersianDay:
                return(GenerateByPersianDay <TValue>(input.From, input.To));

            case ReportGroupMetric.PersianMonth:
                return(GenerateByPersianMonth <TValue>(input.From, input.To));

            case ReportGroupMetric.PersianYear:
                return(GenerateByPersianYear <TValue>(input.From, input.To));

            default:
                return(null);
            }
        }
Example #2
0
        public static IEnumerable <ReportItem <TValue> > FillTheGaps <TValue>(
            this IEnumerable <ReportItem <TValue> > report,
            ReportInput input
            ) where TValue : struct
        {
            var range = _rangeGen.Generate <TValue>(input);

            return(report.Union(range).OrderBy(r => r.Key).ToList());
        }
Example #3
0
        public static IQueryable <ReportItem <int> > ToJoinReport <TEntity>(
            this IQueryable <TEntity> source,
            IQueryable <DimDate> dimDate,
            ReportInput reportInput,
            Expression <Func <TEntity, DateTime> > innerKey
            ) where TEntity : class
        {
            var join = source
                       .Join(dimDate, innerKey, d => d.Date, (e, d) => new Joint <TEntity> {
                E = e, D = d
            });

            if (reportInput.From.HasValue)
            {
                join = join.Where(a => a.D.Date >= reportInput.From.Value);
            }

            if (reportInput.To.HasValue)
            {
                join = join.Where(a => a.D.Date < reportInput.To.Value);
            }

            var dates = join.Select(j => j.D);
            IQueryable <ReportItem <int> > select;

            switch (reportInput.GroupBy)
            {
            case ReportGroupMetric.PersianDay:
                select = dates.GroupBy(d => new
                {
                    d.PersianDayOfMonth,
                    d.PersianDayOfWeekName,
                    d.PersianMonth,
                    d.PersianMonthName,
                    d.PersianYear,
                })
                         .Select(g => new ReportItem <int>
                {
                    Key   = g.Key.PersianYear * 10000 + g.Key.PersianMonth * 100 + g.Key.PersianDayOfMonth,
                    Value = g.Count(),

                    Day       = g.Key.PersianDayOfMonth,
                    DayName   = g.Key.PersianDayOfWeekName,
                    Month     = g.Key.PersianMonth,
                    MonthName = g.Key.PersianMonthName,
                    Year      = g.Key.PersianYear,
                });
                break;

            case ReportGroupMetric.PersianMonth:
                select = dates.GroupBy(d => new
                {
                    d.PersianMonth,
                    d.PersianMonthName,
                    d.PersianYear,
                })
                         .Select(g => new ReportItem <int>
                {
                    Key   = g.Key.PersianYear * 100 + g.Key.PersianMonth,
                    Value = g.Count(),

                    Day       = 0,
                    DayName   = null,
                    Month     = g.Key.PersianMonth,
                    MonthName = g.Key.PersianMonthName,
                    Year      = g.Key.PersianYear,
                });
                break;

            case ReportGroupMetric.PersianYear:
                select = dates.GroupBy(d => new
                {
                    d.PersianYear
                })
                         .Select(g => new ReportItem <int>
                {
                    Key   = g.Key.PersianYear,
                    Value = g.Count(),

                    Day       = 0,
                    DayName   = null,
                    Month     = 0,
                    MonthName = null,
                    Year      = g.Key.PersianYear,
                });
                break;

            default:
                throw new InvalidOperationException($"Grouping by {reportInput.GroupBy} not supported.");
            }

            return(select.OrderBy(i => i.Key));
        }