public IEnumerable <CitiesGraphDto> GetCitiesSalesByCompany(int companyId, DateTime startDate, DateTime endDate)
        {
            var sales  = Repository.GetSalesByRange(startDate, endDate).Where(s => s.company.id == companyId);
            var result = new Dictionary <string, SalesCity>();

            foreach (var sale in sales)
            {
                SalesCity city = new SalesCity {
                    name = sale.city.name, latitude = sale.city.latitude, longtitude = sale.city.longtitude, sales = 0m, country = sale.city.country, state = sale.city.state
                };
                var value = sale.TotalCost;
                if (!result.ContainsKey(city.name))
                {
                    result.Add(city.name, city);
                }
                result[city.name].sales += value;
            }
            return(from item in result
                   orderby item.Value.sales descending
                   select new CitiesGraphDto {
                City = item.Value.name,
                Coordinates = new double[2] {
                    item.Value.latitude, item.Value.longtitude
                },
                Sales = item.Value.sales,
                Country = item.Value.country,
                State = item.Value.state
            });
        }
Esempio n. 2
0
        /// <summary>
        /// This method calls a function to get values from a database and create a new chart using this values
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void refresh_Click(object sender, EventArgs e)
        {
            //create connection
            DataBaseConnection dbc = new DataBaseConnection();

            //get values from GUI
            string city    = SalesCity.GetItemText(SalesCity.SelectedItem);
            string product = Product.GetItemText(Product.SelectedItem);

            //monthes for chart
            string[] monthes = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };

            //give a random value for city if required
            if (city == "Any one")
            {
                int    numOfItems = City_List.Count();
                Random rnd        = new Random();
                int    rand       = rnd.Next(0, numOfItems);
                city = City_List[rand];
            }

            //give a random value for product if required
            if (product == "Any one")
            {
                int    numOfItems = Product_List.Count();
                Random rnd        = new Random();
                int    rand       = rnd.Next(0, numOfItems);
                product = Product_List[rand];
            }

            //get valus for each month to dispay
            double[] mothSales = dbc.getValuesFromDB(city, product);

            //give a fancy and nice color to chart
            this.FopdMartChart.Palette = ChartColorPalette.Berry;

            //remove all data from chart
            foreach (var series in FopdMartChart.Series)
            {
                series.Points.Clear();
            }
            // Add series.
            for (int i = 0; i < monthes.Length; i++)
            {
                this.FopdMartChart.Series["Month"].Points.AddXY(monthes[i], mothSales[i]);
            }
        }