Esempio n. 1
0
        private void initMonthChart()
        {
            string       cacheKey     = "39C69D16-CD5A-4287-8DD4-E21019A78B8E";
            CacheWrapper cacheWrapper = Cache[cacheKey] as CacheWrapper;

            if (cacheWrapper == null)
            {
                //LOAD VIEWS
                SortableCollection <KeyValuePair <DateTime, decimal> > salesByMonth = ReportDataSource.GetSalesForPastMonths(6, true);
                //BUILD BAR CHART
                SalesByMonthChart.Series["Sales"].Points.Clear();
                for (int i = 0; i < salesByMonth.Count; i++)
                {
                    int       roundedTotal = (int)Math.Round(salesByMonth[i].Value, 0);
                    DataPoint point        = new DataPoint(SalesByMonthChart.Series["Sales"]);
                    point.SetValueXY(salesByMonth[i].Key.ToString("MMM yy"), new object[] { roundedTotal });
                    SalesByMonthChart.Series["Sales"].Points.Add(point);
                }
                SalesByMonthChart.DataBind();

                //CACHE THE DATA
                cacheWrapper = new CacheWrapper(salesByMonth);
                Cache.Remove(cacheKey);
                Cache.Add(cacheKey, cacheWrapper, null, LocaleHelper.LocalNow.AddMinutes(5).AddSeconds(-1), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
            }
            else
            {
                //USE CACHED VALUES
                SortableCollection <KeyValuePair <DateTime, decimal> > salesByMonth = (SortableCollection <KeyValuePair <DateTime, decimal> >)cacheWrapper.CacheValue;
                SalesByMonthChart.Series["Sales"].Points.Clear();
                for (int i = 0; i < salesByMonth.Count; i++)
                {
                    int       roundedTotal = (int)Math.Round(salesByMonth[i].Value, 0);
                    DataPoint point        = new DataPoint(SalesByMonthChart.Series["Sales"]);
                    point.SetValueXY(salesByMonth[i].Key.ToString("MMM yy"), new object[] { roundedTotal });
                    SalesByMonthChart.Series["Sales"].Points.Add(point);
                }
                SalesByMonthChart.DataBind();
            }
        }