Пример #1
0
    /// <summary>
    /// Recomputes the data from the datasource and refreshes it
    /// </summary>
    public void Refresh()
    {
        // In case Page_Load has not been called, make sure combo boxes are populated.
        SetUpSelectors();
        if (String.IsNullOrEmpty(cmbGrouping.SelectedValue))
        {
            cmbGrouping.SelectedIndex = 0;
        }

        if (HistogramManager == null)
        {
            throw new InvalidOperationException("Null HistogramManager");
        }

        BucketManager bm = BucketManager;

        bm.ScanData(HistogramManager);

        // check for daily with less than a year
        if (bm is DailyBucketManager dbm && dbm.MaxDate.CompareTo(dbm.MinDate) > 0 && dbm.MaxDate.Subtract(dbm.MinDate).TotalDays > 365)
        {
            BucketManager = bm = new WeeklyBucketManager();
            bm.ScanData(HistogramManager);
        }

        if (bm is DateBucketManager datebm)
        {
            gcTrends.XDatePattern = datebm.DateFormat;
            gcTrends.XDataType    = GoogleColumnDataType.date;
        }
        else
        {
            gcTrends.XDatePattern = "{0}";
            gcTrends.XDataType    = GoogleColumnDataType.@string;
        }

        using (DataTable dt = bm.ToDataTable(HistogramManager))
        {
            gvRawData.Columns.Clear();
            if (String.IsNullOrEmpty(bm.BaseHRef))
            {
                gvRawData.Columns.Add(new BoundField()
                {
                    DataField = BucketManager.ColumnNameDisplayName, HeaderText = bm.DisplayName
                });
            }
            else
            {
                gvRawData.Columns.Add(new HyperLinkField()
                {
                    DataTextField = BucketManager.ColumnNameDisplayName, DataNavigateUrlFormatString = "{0}", DataNavigateUrlFields = new string[] { BucketManager.ColumnNameHRef }, HeaderText = bm.DisplayName, Target = "_blank"
                });
            }

            foreach (DataColumn dc in dt.Columns)
            {
                if (dc.ColumnName.CompareCurrentCultureIgnoreCase(BucketManager.ColumnNameHRef) == 0 || dc.ColumnName.CompareOrdinal(BucketManager.ColumnNameDisplayName) == 0)
                {
                    continue;
                }
                gvRawData.Columns.Add(new BoundField()
                {
                    HeaderText = dc.ColumnName, DataField = dc.ColumnName
                });
            }
            gvRawData.DataSource = dt;
            gvRawData.DataBind();
        }

        RefreshChartAndTable(bm.Buckets);

        if (bm is YearMonthBucketManager ybm && ybm.Buckets.Any())
        {
            gvYearly.Visible    = true;
            gvYearly.DataSource = ybm.ToYearlySummary();
            gvYearly.DataBind();

            // Set the column headers so that they're localized
            for (int i = 0; i < 12; i++)
            {
                gvYearly.HeaderRow.Cells[i + 1].Text = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.AbbreviatedMonthNames[i];
            }
        }
Пример #2
0
    /// <summary>
    /// Recomputes the data from the datasource and refreshes it
    /// </summary>
    public void Refresh()
    {
        // In case Page_Load has not been called, make sure combo boxes are populated.
        SetUpSelectors();
        if (String.IsNullOrEmpty(cmbGrouping.SelectedValue))
        {
            cmbGrouping.SelectedIndex = 0;
        }

        if (HistogramManager == null)
        {
            throw new InvalidOperationException("Null HistogramManager");
        }

        BucketManager bm = BucketManager;

        bm.ScanData(HistogramManager);

        // check for daily with less than a year
        if (bm is DailyBucketManager dbm && dbm.MaxDate.CompareTo(dbm.MinDate) > 0 && dbm.MaxDate.Subtract(dbm.MinDate).TotalDays > 365)
        {
            BucketManager = bm = new WeeklyBucketManager();
            bm.ScanData(HistogramManager);
        }

        if (bm is DateBucketManager datebm)
        {
            gcTrends.XDatePattern = (bm is WeeklyBucketManager) ? String.Format(CultureInfo.InvariantCulture, Resources.LocalizedText.ChartFormatWeekOf, datebm.DateFormat) : datebm.DateFormat;
            gcTrends.XDataType    = GoogleColumnDataType.date;
        }
        else
        {
            gcTrends.XDatePattern = "{0}";
            gcTrends.XDataType    = GoogleColumnDataType.@string;
        }

        using (DataTable dt = bm.ToDataTable(HistogramManager))
        {
            gvRawData.Columns.Clear();
            if (String.IsNullOrEmpty(bm.BaseHRef))
            {
                gvRawData.Columns.Add(new BoundField()
                {
                    DataField = BucketManager.ColumnNameDisplayName, HeaderText = bm.DisplayName
                });
            }
            else
            {
                gvRawData.Columns.Add(new HyperLinkField()
                {
                    DataTextField = BucketManager.ColumnNameDisplayName, DataNavigateUrlFormatString = "{0}", DataNavigateUrlFields = new string[] { BucketManager.ColumnNameHRef }, HeaderText = bm.DisplayName, Target = "_blank"
                });
            }

            foreach (DataColumn dc in dt.Columns)
            {
                if (dc.ColumnName.CompareCurrentCultureIgnoreCase(BucketManager.ColumnNameHRef) == 0 || dc.ColumnName.CompareOrdinal(BucketManager.ColumnNameDisplayName) == 0)
                {
                    continue;
                }
                gvRawData.Columns.Add(new BoundField()
                {
                    HeaderText = dc.ColumnName, DataField = dc.ColumnName
                });
            }
            gvRawData.DataSource = dt;
            gvRawData.DataBind();
        }

        RefreshChartAndTable(bm.Buckets);
    }