コード例 #1
0
        //Generates the total(entire world) sales vs target list for given period and grouped by Month.
        public static ObservableCollection <SalesVsTarget> GenerateTotalSalesVsTargetList(ObservableCollection <SalesDetail> salesDetails)
        {
            ObservableCollection <SalesVsTarget> salesVsTargetList = new ObservableCollection <SalesVsTarget>();
            var    query     = from sales in salesDetails group sales by sales.OrderDate.Month into grouping select grouping;
            Random rand      = new Random();
            double value     = 20;
            double nextvalue = 40;

            foreach (SalesDetail groupedRecord in salesDetails)
            {
                if (rand.NextDouble() > .5)
                {
                    value     += rand.NextDouble();
                    nextvalue += rand.NextDouble();
                }
                else
                {
                    value     -= rand.NextDouble();
                    nextvalue -= rand.NextDouble();
                }
                SalesVsTarget salesVsTarget = new SalesVsTarget();

                salesVsTarget.Month        = groupedRecord.OrderDate.Month;
                salesVsTarget.Date         = groupedRecord.OrderDate;
                salesVsTarget.Sales        = groupedRecord.OrderTotal * nextvalue;
                salesVsTarget.Target       = rand.Next(0, 120);
                salesVsTarget.SalesPercent = (salesVsTarget.Sales / salesVsTarget.Target) * 100;
                salesVsTargetList.Add(salesVsTarget);
            }

            return(salesVsTargetList);
        }
コード例 #2
0
        //Generates the total sales vs target list of given continent for given period and grouped by month.
        public static ObservableCollection <SalesVsTarget> GenerateTotalSalesVsTargetListByContinent(ObservableCollection <SalesDetail> salesDetails, string continent)
        {
            ObservableCollection <SalesVsTarget> salesVsTargetList = new ObservableCollection <SalesVsTarget>();
            var    query = from sales in salesDetails where sales.Continent == continent group sales by sales.OrderDate.Month into grouping select grouping;
            Random rand  = new Random();

            foreach (IGrouping <int, SalesDetail> groupedRecord in query)
            {
                SalesVsTarget salesVsTarget = new SalesVsTarget();

                salesVsTarget.Month        = groupedRecord.Key;
                salesVsTarget.Date         = groupedRecord.ElementAt(groupedRecord.Key).OrderDate;
                salesVsTarget.Sales        = groupedRecord.Sum(s => s.OrderTotal);
                salesVsTarget.Target       = ((salesVsTarget.Sales * rand.Next(-10, 30)) / 100) + salesVsTarget.Sales;
                salesVsTarget.SalesPercent = (salesVsTarget.Sales / salesVsTarget.Target) * 100;
                salesVsTargetList.Add(salesVsTarget);
            }

            return(salesVsTargetList);
        }