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) { 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.Target = ((salesVsTarget.Sales * rand.Next(-10, 30)) / 100) + salesVsTarget.Sales; salesVsTarget.SalesPercent = (salesVsTarget.Sales / salesVsTarget.Target) * 100; salesVsTargetList.Add(salesVsTarget); } return(salesVsTargetList); }
public object Convert(object value, Type targetType, object parameter, string language) { SalesByCountry originalValue = value as SalesByCountry; ObservableCollection <SalesByCountry> data = new ObservableCollection <SalesByCountry>(); { Random random = new Random(); { SalesByCountry salesByCountry = new SalesByCountry(); salesByCountry.Month = new DateTime(2009, 1, 1); salesByCountry.Country = "US"; salesByCountry.Sales = originalValue.Sales + (random.Next(100, 500)); salesByCountry.Target = originalValue.Target + (random.Next(1, 5000)); data.Add(salesByCountry); salesByCountry = new SalesByCountry(); salesByCountry.Month = new DateTime(2009, 2, 1); salesByCountry.Country = "Japan"; salesByCountry.Sales = (random.Next(100, 300)); salesByCountry.Target = originalValue.Target + (random.Next(1, 5000)); data.Add(salesByCountry); salesByCountry = new SalesByCountry(); salesByCountry.Month = new DateTime(2009, 3, 1); salesByCountry.Country = "Brazil"; salesByCountry.Sales = (random.Next(100, 300)); salesByCountry.Target = originalValue.Target + (random.Next(1, 5000)); data.Add(salesByCountry); salesByCountry = new SalesByCountry(); salesByCountry.Month = new DateTime(2009, 4, 1); salesByCountry.Country = "Benin"; salesByCountry.Sales = (random.Next(100, 300)); salesByCountry.Target = originalValue.Target + (random.Next(1, 5000)); data.Add(salesByCountry); salesByCountry = new SalesByCountry(); salesByCountry.Month = new DateTime(2009, 5, 1); salesByCountry.Country = "Canada"; salesByCountry.Sales = (random.Next(100, 300)); salesByCountry.Target = originalValue.Target + (random.Next(1, 5000)); data.Add(salesByCountry); salesByCountry = new SalesByCountry(); salesByCountry.Month = new DateTime(2009, 6, 1); salesByCountry.Country = "China"; salesByCountry.Sales = originalValue.Sales + (random.Next(100, 500)); salesByCountry.Target = originalValue.Target + (random.Next(1, 5000)); data.Add(salesByCountry); salesByCountry = new SalesByCountry(); salesByCountry.Month = new DateTime(2009, 7, 1); salesByCountry.Country = "Austria"; salesByCountry.Sales = originalValue.Sales + (random.Next(100, 500)); salesByCountry.Target = originalValue.Target + (random.Next(1, 5000)); data.Add(salesByCountry); } } return(data); }