Esempio n. 1
0
        private void initDayChart()
        {
            string       cacheKey     = "E38012C3-C1A0-45a2-A0FF-F32D8DDE043F";
            CacheWrapper cacheWrapper = Cache[cacheKey] as CacheWrapper;

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

                //CACHE THE DATA
                cacheWrapper = new CacheWrapper(salesByDay);
                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> > salesByDay = (SortableCollection <KeyValuePair <DateTime, decimal> >)cacheWrapper.CacheValue;

                SalesByDayChart.Series["Sales"].Points.Clear();
                for (int i = 0; i < salesByDay.Count; i++)
                {
                    int       roundedTotal = (int)Math.Round(salesByDay[i].Value, 0);
                    DataPoint point        = new DataPoint(SalesByDayChart.Series["Sales"]);
                    point.SetValueXY(salesByDay[i].Key.ToString("MMM d"), new object[] { roundedTotal });
                    SalesByDayChart.Series["Sales"].Points.Add(point);
                }
                SalesByDayChart.DataBind();
            }

            //using (StringWriter writer = new StringWriter())
            //{
            //    SalesByDayChart.Serializer.Content = SerializationContents.Default;
            //    SalesByDayChart.Serializer.Save(writer);
            //    //Dump the contents to a string
            //    string serializedChartContent = writer.ToString();

            //    // GET THE PATH
            //    string theme = Page.Theme;
            //    if (string.IsNullOrEmpty(theme)) theme = Page.StyleSheetTheme;
            //    if (string.IsNullOrEmpty(theme)) theme = "AbleCommerceAdmin";
            //    string path = Server.MapPath("~/App_Themes/" + theme + "/chartstyles.xml");
            //    File.WriteAllText(path, serializedChartContent);
            //}
        }