Ejemplo n.º 1
0
    protected void Bind()
    {
        UserTotals ut = new UserTotals(Username, m_fq, true);

        ut.DataBind();

        IEnumerable <TotalsItemCollection> tic = TotalsItemCollection.AsGroups(ut.Totals);

        rptGroups.DataSource = tic;
        rptGroups.DataBind();
        lblNoTotals.Visible = !tic.Any();
        gvTotals.DataSource = ut.Totals;
        gvTotals.DataBind();
    }
Ejemplo n.º 2
0
        public void BindTotalsForUser(string szUser, bool fLast7Days, bool fMonthToDate, bool fPreviousMonth, bool fPreviousYear, bool fYearToDate, bool fTrailing12, FlightQuery fqSupplied = null)
        {
            if (String.IsNullOrEmpty(szUser))
            {
                throw new ArgumentNullException(nameof(szUser));
            }

            Profile pf = Profile.GetUser(szUser);

            UseHHMM = pf.UsesHHMM;

            // Get All time totals.  This will also give us the entire space of totals items
            FlightQuery fq = (fqSupplied == null) ? new FlightQuery(szUser) : new FlightQuery(fqSupplied);
            UserTotals  ut = new UserTotals(szUser, new FlightQuery(fq), false);

            // if the supplied query has a date range, then don't do any of the subsequent queries; the date range overrides.
            bool fSuppliedQueryHasDates = fq.DateRange != FlightQuery.DateRanges.AllTime;

            if (fSuppliedQueryHasDates)
            {
                fLast7Days = fMonthToDate = fPreviousMonth = fPreviousYear = fYearToDate = fTrailing12 = false;
            }

            Dictionary <string, TotalsItem> dMonthToDate = new Dictionary <string, TotalsItem>();
            Dictionary <string, TotalsItem> dPrevMonth   = new Dictionary <string, TotalsItem>();
            Dictionary <string, TotalsItem> dYTD         = new Dictionary <string, TotalsItem>();
            Dictionary <string, TotalsItem> dTrailing12  = new Dictionary <string, TotalsItem>();
            Dictionary <string, TotalsItem> dPrevYear    = new Dictionary <string, TotalsItem>();
            Dictionary <string, TotalsItem> dLast7       = new Dictionary <string, TotalsItem>();

            // Get all of the results asynchronously, but block until they're all done.
            Task.WaitAll(
                Task.Run(() => { ut.DataBind(); }),
                Task.Run(() => { TotalsForQuery(new FlightQuery(fq)
                {
                    DateRange = FlightQuery.DateRanges.ThisMonth
                }, fMonthToDate, dMonthToDate); }),
                Task.Run(() => { TotalsForQuery(new FlightQuery(fq)
                {
                    DateRange = FlightQuery.DateRanges.PrevMonth
                }, fPreviousMonth, dPrevMonth); }),
                Task.Run(() => { TotalsForQuery(new FlightQuery(fq)
                {
                    DateRange = FlightQuery.DateRanges.YTD
                }, fYearToDate, dYTD); }),
                Task.Run(() => { TotalsForQuery(new FlightQuery(fq)
                {
                    DateRange = FlightQuery.DateRanges.Trailing12Months
                }, fTrailing12, dTrailing12); }),
                Task.Run(() => { TotalsForQuery(new FlightQuery(fq)
                {
                    DateRange = FlightQuery.DateRanges.PrevYear
                }, fPreviousYear, dPrevYear); }),
                Task.Run(() => { TotalsForQuery(new FlightQuery(fq)
                {
                    DateRange = FlightQuery.DateRanges.Custom, DateMin = DateTime.Now.Date.AddDays(-7), DateMax = DateTime.Now.Date.AddDays(1)
                }, fLast7Days, dLast7); })
                );

            IEnumerable <TotalsItemCollection> allTotals = TotalsItemCollection.AsGroups(ut.Totals);

            tblTotals.Controls.Clear();

            // Determine which columns we'll show
            ColumnCount = 2;   // All time is always shown, as are its labels (in adjacent table column)
            if (fLast7Days &= dLast7.Any())
            {
                ColumnCount++;
            }
            if (fMonthToDate &= dMonthToDate.Any())
            {
                ColumnCount++;
            }
            if (fPreviousMonth &= dPrevMonth.Any())
            {
                ColumnCount++;
            }
            if (fTrailing12 &= dTrailing12.Any())
            {
                ColumnCount++;
            }
            if (fPreviousYear &= dPrevYear.Any())
            {
                ColumnCount++;
            }
            if (fYearToDate &= dYTD.Any())
            {
                ColumnCount++;
            }

            mvTotals.SetActiveView(allTotals.Any() ? vwTotals : vwNoTotals);

            string szPreviousMonth = DateTime.Now.AddCalendarMonths(-1).ToString("MMM yyyy", CultureInfo.CurrentCulture);
            string szPreviousYear  = (DateTime.Now.Year - 1).ToString(CultureInfo.CurrentCulture);

            foreach (TotalsItemCollection tic in allTotals)
            {
                TableRow trGroup = new TableRow()
                {
                    CssClass = "totalsGroupHeaderRow"
                };
                tblTotals.Rows.Add(trGroup);
                TableCell tcGroup = new TableCell()
                {
                    ColumnSpan = ColumnCount, Text = tic.GroupName
                };
                trGroup.Cells.Add(tcGroup);

                TableRow trHeader = new TableRow();
                tblTotals.Rows.Add(trHeader);
                const string cssDateRange = "totalsDateRange";
                AddTextCellToRow(trHeader, string.Empty, true); // no header above the total description itself.
                AddTextCellToRow(trHeader, fSuppliedQueryHasDates ? string.Empty : Resources.FlightQuery.DatesAll, true, cssDateRange);
                AddTextCellToRow(trHeader, Resources.Profile.EmailWeeklyTotalsLabel, fLast7Days, cssDateRange);
                AddTextCellToRow(trHeader, Resources.FlightQuery.DatesThisMonth, fMonthToDate, cssDateRange);
                AddTextCellToRow(trHeader, szPreviousMonth, fPreviousMonth, cssDateRange);
                AddTextCellToRow(trHeader, Resources.FlightQuery.DatesYearToDate, fYearToDate, cssDateRange);
                AddTextCellToRow(trHeader, Resources.FlightQuery.DatesPrev12Month, fTrailing12, cssDateRange);
                AddTextCellToRow(trHeader, szPreviousYear, fPreviousYear, cssDateRange);

                foreach (TotalsItem ti in tic.Items)
                {
                    TableRow tr = new TableRow()
                    {
                        CssClass = "totalsGroupRow"
                    };
                    tblTotals.Rows.Add(tr);

                    // Add the description
                    tr.Cells.Add(new TableCell()
                    {
                        Text = ti.Description
                    });

                    decimal rowTotal = AddCellForTotalsItem(tr, ti, true) +
                                       AddCellForTotalsItem(tr, dLast7.ContainsKey(ti.Description) ? dLast7[ti.Description] : null, fLast7Days) +
                                       AddCellForTotalsItem(tr, dMonthToDate.ContainsKey(ti.Description) ? dMonthToDate[ti.Description] : null, fMonthToDate) +
                                       AddCellForTotalsItem(tr, dPrevMonth.ContainsKey(ti.Description) ? dPrevMonth[ti.Description] : null, fPreviousMonth) +
                                       AddCellForTotalsItem(tr, dYTD.ContainsKey(ti.Description) ? dYTD[ti.Description] : null, fYearToDate) +
                                       AddCellForTotalsItem(tr, dTrailing12.ContainsKey(ti.Description) ? dTrailing12[ti.Description] : null, fTrailing12) +
                                       AddCellForTotalsItem(tr, dPrevYear.ContainsKey(ti.Description) ? dPrevYear[ti.Description] : null, fPreviousYear);

                    // Remove rows of empty data
                    if (rowTotal == 0)
                    {
                        tblTotals.Rows.Remove(tr);
                    }
                }
            }
        }