Пример #1
0
        public ActionResult Chart(ChartReportVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            List <ReportData> list     = new List <ReportData>(4);
            string            siteName = model.SiteID == 0 ? "All web sites" : SitesManager.GetSite(model.SiteID).Name;

            #region
            var data = new ReportData();

            data.Colors = new List <string>();
            data.Colors.Add("#00FF00");
            data.Colors.Add("#FF0000");
            data.Colors.Add("#0000FF");

            data.Type               = "column";
            data.YAxisTitle         = "Values (USD)";
            data.TooltipValueSuffix = "USD";
            data.Text               = "The last four " + CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(DateTime.Now.AddDays(-1).DayOfWeek).ToLower() + " (" + siteName + ")";

            var reportDay = SitesManager.GetSiteReportTheLastFourDay(model.SiteID);

            data.Categories = new List <string>();
            foreach (var item in reportDay)
            {
                data.Categories.Add(item.Key.ToString("MM-dd-yyyy"));
            }

            data.Series = new List <Data>();

            Data revenueDay = new Data()
            {
                name = "Revenue", data = new List <double>()
            };
            foreach (var item in reportDay)
            {
                revenueDay.data.Add(item.Value[0]);
            }
            Data costDay = new Data()
            {
                name = "Cost", data = new List <double>()
            };
            foreach (var item in reportDay)
            {
                costDay.data.Add(item.Value[1]);
            }
            Data profitDay = new Data()
            {
                name = "Profit", data = new List <double>()
            };
            foreach (var item in reportDay)
            {
                profitDay.data.Add(item.Value[0] - item.Value[1]);
            }

            data.Series.Add(revenueDay);
            data.Series.Add(costDay);
            data.Series.Add(profitDay);
            data.Id = Guid.NewGuid().ToString();

            #region Table

            data.Table      = new ChartTable();
            data.Table.Cols = new List <string>();
            data.Table.Rows = new List <string>();
            data.Table.Data = new string[reportDay.Count][];

            data.Table.Rows.Add("Revenue");
            data.Table.Rows.Add("Cost");
            data.Table.Rows.Add("Profit");

            int index = 0;
            foreach (var item in reportDay)
            {
                data.Table.Cols.Add(item.Key.ToString("MM/dd/yyyy"));

                data.Table.Data[index]    = new string[3];
                data.Table.Data[index][0] = item.Value[0].ToString();
                data.Table.Data[index][1] = item.Value[1].ToString();
                data.Table.Data[index][2] = (item.Value[0] - item.Value[1]).ToString();

                index = index + 1;
            }

            #endregion

            list.Add(data);
            #endregion

            #region
            var data2 = new ReportData();

            data2.Colors = new List <string>();
            data2.Colors.Add("#00FF00");
            data2.Colors.Add("#FF0000");
            data2.Colors.Add("#0000FF");

            data2.Text               = "The last four months" + " (" + siteName + ")";
            data2.Type               = "column";
            data2.YAxisTitle         = "Values (USD)";
            data2.TooltipValueSuffix = "USD";
            var reportMonth = SitesManager.GetSiteReportTheLastFourMonth(model.SiteID);

            data2.Categories = new List <string>();
            foreach (var item in reportMonth)
            {
                data2.Categories.Add(CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(item.Key.Month) + " " + item.Key.Year);
            }

            data2.Series = new List <Data>();

            Data revenueMonth = new Data()
            {
                name = "Revenue", data = new List <double>()
            };
            foreach (var item in reportMonth)
            {
                revenueMonth.data.Add(item.Value[0]);
            }
            Data costMonth = new Data()
            {
                name = "Cost", data = new List <double>()
            };
            foreach (var item in reportMonth)
            {
                costMonth.data.Add(item.Value[1]);
            }
            Data profitMonth = new Data()
            {
                name = "Profit", data = new List <double>()
            };
            foreach (var item in reportMonth)
            {
                profitMonth.data.Add(item.Value[0] - item.Value[1]);
            }

            data2.Series.Add(revenueMonth);
            data2.Series.Add(costMonth);
            data2.Series.Add(profitMonth);
            data2.Id = Guid.NewGuid().ToString();

            #region Table

            data2.Table      = new ChartTable();
            data2.Table.Cols = new List <string>();
            data2.Table.Rows = new List <string>();
            data2.Table.Data = new string[reportMonth.Count][];

            data2.Table.Rows.Add("Revenue");
            data2.Table.Rows.Add("Cost");
            data2.Table.Rows.Add("Profit");

            index = 0;
            foreach (var item in reportMonth)
            {
                data2.Table.Cols.Add(CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(item.Key.Month) + " " + item.Key.Year);

                data2.Table.Data[index]    = new string[3];
                data2.Table.Data[index][0] = item.Value[0].ToString();
                data2.Table.Data[index][1] = item.Value[1].ToString();
                data2.Table.Data[index][2] = (item.Value[0] - item.Value[1]).ToString();

                index = index + 1;
            }

            #endregion

            list.Add(data2);
            #endregion

            #region
            var data3 = new ReportData();

            data3.Colors = new List <string>();
            data3.Colors.Add("#00FF00");
            data3.Colors.Add("#FF0000");
            data3.Colors.Add("#0000FF");

            data3.Text               = "The last fifteen days" + " (" + siteName + ")";
            data3.Type               = "column";
            data3.YAxisTitle         = "Values (USD)";
            data3.TooltipValueSuffix = "USD";
            var reportFifteenDays = SitesManager.GetSiteReportTheLastFifteenDays(model.SiteID);

            data3.Categories = new List <string>();
            foreach (var item in reportFifteenDays)
            {
                data3.Categories.Add(item.Key.ToString("MM-dd-yyyy"));
            }

            data3.Series = new List <Data>();

            Data revenueFifteenDays = new Data()
            {
                name = "Revenue", data = new List <double>()
            };
            foreach (var item in reportFifteenDays)
            {
                revenueFifteenDays.data.Add(item.Value[0]);
            }
            Data costFifteenDays = new Data()
            {
                name = "Cost", data = new List <double>()
            };
            foreach (var item in reportFifteenDays)
            {
                costFifteenDays.data.Add(item.Value[1]);
            }
            Data profitFifteenDays = new Data()
            {
                name = "Profit", data = new List <double>()
            };
            foreach (var item in reportFifteenDays)
            {
                profitFifteenDays.data.Add(item.Value[0] - item.Value[1]);
            }

            data3.Series.Add(revenueFifteenDays);
            data3.Series.Add(costFifteenDays);
            data3.Series.Add(profitFifteenDays);
            data3.Id = Guid.NewGuid().ToString();

            #region Table

            data3.Table      = new ChartTable();
            data3.Table.Cols = new List <string>();
            data3.Table.Rows = new List <string>();
            data3.Table.Data = new string[reportFifteenDays.Count][];

            data3.Table.Rows.Add("Revenue");
            data3.Table.Rows.Add("Cost");
            data3.Table.Rows.Add("Profit");

            index = 0;
            foreach (var item in reportFifteenDays)
            {
                data3.Table.Cols.Add(item.Key.ToString("MM-dd-yyyy"));

                data3.Table.Data[index]    = new string[3];
                data3.Table.Data[index][0] = item.Value[0].ToString();
                data3.Table.Data[index][1] = item.Value[1].ToString();
                data3.Table.Data[index][2] = (item.Value[0] - item.Value[1]).ToString();

                index = index + 1;
            }

            #endregion

            list.Add(data3);
            #endregion


            #region
            var data4 = new ReportData();

            data4.Colors = new List <string>();
            data4.Colors.Add("#00FF00");
            data4.Colors.Add("#FF0000");
            data4.Colors.Add("#0000FF");

            data4.Text               = "The last sixty days" + " (" + siteName + ")";
            data4.Type               = "line";
            data4.YAxisTitle         = "Values";
            data4.TooltipValueSuffix = "";
            var reportSixtyDays = SitesManager.GetSiteReportTheLastSixtyDays(model.SiteID);

            data4.Categories = new List <string>();
            foreach (var item in reportSixtyDays)
            {
                data4.Categories.Add(item.Key.ToString("MM-dd-yyyy"));
            }

            data4.Series = new List <Data>();

            Data signupsSixtyDays = new Data()
            {
                name = "Sign Up", data = new List <double>()
            };
            foreach (var item in reportSixtyDays)
            {
                signupsSixtyDays.data.Add(item.Value[0]);
            }
            Data visitsSixtyDays = new Data()
            {
                name = "Billeds", data = new List <double>()
            };
            foreach (var item in reportSixtyDays)
            {
                visitsSixtyDays.data.Add(item.Value[1]);
            }
            Data cancellationsSixtyDays = new Data()
            {
                name = "Cancellations", data = new List <double>()
            };
            foreach (var item in reportSixtyDays)
            {
                cancellationsSixtyDays.data.Add(item.Value[2]);
            }

            data4.Series.Add(signupsSixtyDays);
            data4.Series.Add(visitsSixtyDays);
            data4.Series.Add(cancellationsSixtyDays);
            data4.Id = Guid.NewGuid().ToString();

            #region Table

            data4.Table = new ChartTable();
            /**/
            data4.Table.Cols = new List <string>();
            data4.Table.Rows = new List <string>();

            /**
             * data4.Table.Data = new string[reportSixtyDays.Count][];
             *
             *
             * data4.Table.Rows.Add("Sign Ups");
             * data4.Table.Rows.Add("Billeds");
             * data4.Table.Rows.Add("Cancellations");
             *
             * index = 0;
             * foreach (var item in reportSixtyDays)
             * {
             * data4.Table.Cols.Add(item.Key.ToString("MM-dd-yyyy"));
             *
             * data4.Table.Data[index] = new string[3];
             * data4.Table.Data[index][0] = item.Value[0].ToString();
             * data4.Table.Data[index][1] = item.Value[1].ToString();
             * data4.Table.Data[index][2] = item.Value[2].ToString();
             *
             * index = index + 1;
             * }
             **/
            data4.Table.Data = new string[3][];
            data4.Table.Cols.Add("Sign Ups");
            data4.Table.Cols.Add("Billeds");
            data4.Table.Cols.Add("Cancellations");

            data4.Table.Data[0] = new string[reportSixtyDays.Count];
            data4.Table.Data[1] = new string[reportSixtyDays.Count];
            data4.Table.Data[2] = new string[reportSixtyDays.Count];
            index = 0;
            foreach (var item in reportSixtyDays)
            {
                data4.Table.Rows.Add(item.Key.ToString("MM-dd-yyyy"));

                //data4.Table.Data[index] = new string[3];
                data4.Table.Data[0][index] = item.Value[0].ToString();
                data4.Table.Data[1][index] = item.Value[1].ToString();
                data4.Table.Data[2][index] = item.Value[2].ToString();

                index = index + 1;
            }

            #endregion

            list.Add(data4);
            #endregion


            return(Json(list));
        }