示例#1
0
        public static ObservableCollection <ProductVsCountry> GenerateProductVsCountry(ObservableCollection <SalesDetail> salesDetails)//,ObservableCollection<SalesVsTarget> sale)
        {
            Random rand = new Random();
            ObservableCollection <ProductVsCountry> productVscountry = new ObservableCollection <ProductVsCountry>();
            ObservableCollection <Countries>        countryList      = Countries.GetCountries();
            ObservableCollection <SalesVsTarget>    sales            = GenerateTotalSalesVsTargetList(salesDetails);

            string[]  labels                       = { "Tablet", "Desktop", "Hybrid", "Laptop", "Smartphone" };
            var       query                        = from saleD in salesDetails group saleD by saleD.Country into grouping select grouping;
            Countries countries                    = new Countries();
            List <ProductVsCountry> data           = new List <ProductVsCountry>();
            SalesVsTarget           salesVsTargets = new SalesVsTarget();
            Random r            = new Random();
            float  salespercent = 0;

            for (int i = 0; i < labels.Length; i++)
            {
                salespercent = r.Next(10, 95);
            }

            foreach (IGrouping <string, SalesDetail> groupedRecord in query)
            {
                double market = r.NextDouble();
                market = Math.Round(market, 2);
                //SalesByContinet salesVsTarget = new SalesByContinet();
                sales     = SalesDetail.GenerateTotalSalesVsTargetList(salesDetails);
                countries = countryList[rand.Next(0, (countryList.Count) - 1)];
                productVscountry.Add(new ProductVsCountry
                {
                    country            = countries.Country,
                    continent          = countries.Continent,
                    MarketingVsRevenue = market,
                    SalesPercent       = salespercent
                });
            }
            return(productVscountry);
        }
示例#2
0
        public static ObservableCollection <SalesByCountry> GenerateTotalSalesVsTargetListByCountry(ObservableCollection <SalesDetail> salesDetails)
        {
            ObservableCollection <SalesByCountry> salesVsTargetList = new ObservableCollection <SalesByCountry>();
            var    query = from sales in salesDetails group sales by sales.Country into grouping select grouping;
            Random rand  = new Random();

            string[] products = new string[] { "Tablet", "Desktop", "Hybrid", "Laptop", "Smartphone" };
            foreach (IGrouping <string, SalesDetail> groupedRecord in query)
            {
                SalesDetail    sal           = new SalesDetail();
                SalesByCountry salesVsTarget = new SalesByCountry();
                ObservableCollection <SalesByProductInCountry> productsCollection = new ObservableCollection <SalesByProductInCountry>();
                salesVsTarget.Country = groupedRecord.Key;
                salesVsTarget.Sales   = groupedRecord.Sum(s => s.OrderTotal);
                foreach (string product in products)
                {
                    SalesByProductInCountry productSales = new SalesByProductInCountry();
                    productSales.Name = product;
                    foreach (SalesDetail salesDetail in salesDetails)
                    {
                        if (salesDetail.ProductName == product && salesDetail.Country == salesVsTarget.Country)
                        {
                            productSales.Sales += salesDetail.OrderTotal;
                        }
                    }
                    productsCollection.Add(productSales);
                }
                salesVsTarget.Quantity     = sal.Quantity;
                salesVsTarget.product      = sal.ProductName;
                salesVsTarget.Target       = ((salesVsTarget.Sales * rand.Next(-10, 30)) / 100) + salesVsTarget.Sales;
                salesVsTarget.SalesPercent = (float)(salesVsTarget.Sales / salesVsTarget.Target) * 100;
                salesVsTargetList.Add(salesVsTarget);
            }

            return(salesVsTargetList);
        }
示例#3
0
        void Maps_ShapesSelected(object sender, SelectionEventArgs args)
        {
            SalesByContinet salesByContinent = ((args.Items as ObservableCollection <MapShape>)[0].DataContext as SalesByContinet);

            if (salesByContinent != null)
            {
                if (salesByContinent.Continent == "Africa")
                {
                    this.map.BaseMapIndex           = 6;
                    this.DrillDownButton.Visibility = Visibility.Collapsed;
                    this.DrillUpButton.Visibility   = Visibility.Visible;
                }
                else if (salesByContinent.Continent == "Oceania")
                {
                    this.map.BaseMapIndex           = 1;
                    this.DrillDownButton.Visibility = Visibility.Collapsed;
                    this.DrillUpButton.Visibility   = Visibility.Visible;
                }
                else if (salesByContinent.Continent == "South America")
                {
                    this.map.BaseMapIndex           = 2;
                    this.DrillDownButton.Visibility = Visibility.Collapsed;
                    this.DrillUpButton.Visibility   = Visibility.Visible;
                }
                else if (salesByContinent.Continent == "North America")
                {
                    this.map.BaseMapIndex           = 3;
                    this.DrillDownButton.Visibility = Visibility.Collapsed;
                    this.DrillUpButton.Visibility   = Visibility.Visible;
                }
                else if (salesByContinent.Continent == "Europe")
                {
                    this.map.BaseMapIndex           = 4;
                    this.DrillDownButton.Visibility = Visibility.Collapsed;
                    this.DrillUpButton.Visibility   = Visibility.Visible;
                }
                else if (salesByContinent.Continent == "Antarctica")
                {
                    this.map.BaseMapIndex           = 5;
                    this.DrillDownButton.Visibility = Visibility.Collapsed;
                    this.DrillUpButton.Visibility   = Visibility.Visible;
                }
                else if (salesByContinent.Continent == "Asia")
                {
                    this.map.BaseMapIndex           = 7;
                    this.DrillDownButton.Visibility = Visibility.Collapsed;
                    this.DrillUpButton.Visibility   = Visibility.Visible;
                }

                ViewModel VM = (this.DataContext as ViewModel);
                DateTime  SelectedStartDate, SelectedEndDate;
                if ((this.DataContext as ViewModel).Selectedindex == 0)
                {
                    SelectedStartDate = new DateTime(2011, 1, 1);
                    SelectedEndDate   = new DateTime(2011, 6, 30);
                }
                else
                {
                    SelectedStartDate = new DateTime(2011, 1, 7);
                    SelectedEndDate   = new DateTime(2011, 12, 31);
                }
                #region Chart Data
                VM.SalesVsTarget = (object)(SalesDetail.GenerateTotalSalesVsTargetList(SalesDetail.GenerateSalesDetails(SelectedStartDate, SelectedEndDate)));
                #endregion
                #region Maps Data
                VM.Total_Sales = SalesDetail.GenerateSalesDetails(SelectedStartDate, SelectedEndDate);
                VM.Models      = (SalesDetail.GenerateTotalSalesVsTargetListByContinent(VM.Total_Sales));


                VM.SalesByCountry = (SalesDetail.GenerateTotalSalesVsTargetListByCountry(VM.Total_Sales));
                for (int i = 0; i < VM.Models.Count; i++)
                {
                    VM.Models[i].DisplaySalesValue = String.Format("{0:C}", Convert.ToInt32(VM.Models[i].Sales.ToString()));
                }
                #endregion
                #region Gauge Data
                VM.SalesVsTarget = SalesDetail.GenerateTotalSalesVsTargetList(SalesDetail.GenerateSalesDetails(SelectedStartDate, SelectedEndDate));
                double saletotal  = (VM.SalesVsTarget as ObservableCollection <SalesVsTarget>).Sum(s => s.Sales);
                double saletarget = (VM.SalesVsTarget as ObservableCollection <SalesVsTarget>).Sum(s => s.Target);
                VM.SalesTotal      = (Math.Round(saletotal, 0)).ToString();
                VM.SalesTarget     = (Math.Round(saletarget, 0)).ToString();
                VM.SalesPercentage = (saletotal / saletarget) * 100;
                #endregion
            }
        }