示例#1
0
        private void UpdateItemsSource(object parm)
        {
            UpdateProductSales dr = null;

            switch (parm.ToString())
            {
            case "Add at Top":
                dr = new UpdateProductSales()
                {
                    Country  = "Canada",
                    State    = "Brunswick",
                    Product  = "Bike",
                    Date     = "FY 2003",
                    Quantity = 1,
                    Amount   = 100d
                };
                break;

            case "Add at Middle":
                dr = new UpdateProductSales()
                {
                    Country  = "Canada",
                    State    = "Brunswick",
                    Product  = "Bike",
                    Date     = "FY 2007",
                    Quantity = 1,
                    Amount   = 200d
                };
                break;

            case "Add at Bottom":
                dr = new UpdateProductSales()
                {
                    Country  = "Canada",
                    State    = "Brunswick",
                    Product  = "Bike",
                    Date     = "FY 2010",
                    Quantity = 1,
                    Amount   = 300d
                };
                break;
            }
            productSalesData.Add(dr);
        }
示例#2
0
        public static ProductSalesCollection GetSalesData()
        {
            if (singleListDataSource != null)
            {
                return(singleListDataSource);
            }

            // Geography
            string[] countries     = { "Australia", "Canada", "France", "Germany", "United Kingdom", "United States" };
            string[] ausStates     = { "New South Wales", "Queensland", "South Australia", "Tasmania", "Victoria" };
            string[] canadaStates  = { "Alberta", "British Columbia", "Brunswick", "Manitoba", "Ontario", "Quebec" };
            string[] franceStates  = { "Charente-Maritime", "Essonne", "Garonne (Haute)", "Gers", };
            string[] germanyStates = { "Bayern", "Brandenburg", "Hamburg", "Hessen", "Nordrhein-Westfalen", "Saarland" };
            string[] ukStates      = { "England" };
            string[] ussStates     = { "New York", "North Carolina", "Alabama", "California", "Colorado", "New Mexico", "South Carolina" };

            // Time
            string[] dates = { "FY 2005", "FY 2006", "FY 2008", "FY 2009" };
            DateTime date0 = new DateTime(2005, 1, 1);

            // Products
            string[] products = { "Bike", "Car", "Truck", "Scooters" };
            products = new[] { "Bike", "Car" };
            Random r = new Random(123345345);

            int numberOfRecords = count;
            ProductSalesCollection listOfProductSales = new ProductSalesCollection();

            for (int i = 0; i < numberOfRecords; i++)
            {
                UpdateProductSales sales = new UpdateProductSales();
                sales.Country  = countries[r.Next(1, countries.GetLength(0))];
                sales.Quantity = r.Next(1, 12);
                // 1 percent discount for 1 quantity
                double discount = (30000 * sales.Quantity) * (double.Parse(sales.Quantity.ToString()) / 100);
                sales.Amount  = (30000 * sales.Quantity) - discount;
                sales.Date    = dates[r.Next(r.Next(dates.GetLength(0) + 1))];
                sales.Product = products[r.Next(r.Next(products.GetLength(0) + 1))];
                sales.Extra   = i % 2;
                sales.Date2   = date0.AddDays(r.Next(1500));
                switch (sales.Country)
                {
                case "Australia":
                {
                    sales.State = ausStates[r.Next(ausStates.GetLength(0))];
                    break;
                }

                case "Canada":
                {
                    sales.State = canadaStates[r.Next(canadaStates.GetLength(0))];
                    break;
                }

                case "France":
                {
                    sales.State = franceStates[r.Next(franceStates.GetLength(0))];
                    break;
                }

                case "Germany":
                {
                    sales.State = germanyStates[r.Next(germanyStates.GetLength(0))];
                    break;
                }

                case "United Kingdom":
                {
                    sales.State = ukStates[r.Next(ukStates.GetLength(0))];
                    break;
                }

                case "United States":
                {
                    sales.State = ussStates[r.Next(ussStates.GetLength(0))];
                    break;
                }
                }
                listOfProductSales.Add(sales);
            }
            singleListDataSource = listOfProductSales;
            return(listOfProductSales);
        }