コード例 #1
0
        private void updateSales()
        {
            validateDates(calendarTerm.SelectionStart.Date, calendarTerm.SelectionEnd.Date);

            lbl_Term.Text = $"Term: {calendarTerm.SelectionStart.Date.ToString("dd-MM-yyyy")} - {calendarTerm.SelectionEnd.Date.ToString("dd-MM-yyyy")}";

            List <Order> allOrders = orderService.GetAllInRange(calendarTerm.SelectionStart, calendarTerm.SelectionEnd);
            Dictionary <DateTime, List <Order> > ordersByDate = allOrders
                                                                .GroupBy(order => order.Date.Date)
                                                                .ToDictionary(kv => kv.Key, kv => kv.ToList());

            lv_Sales.Items.Clear();

            foreach (KeyValuePair <DateTime, List <Order> > pair in ordersByDate)
            {
                List <Order> orders    = pair.Value;
                List <int>   customers = new List <int>();
                int          sold      = 0;
                int          total     = 0;

                foreach (Order order in orders)
                {
                    sold  += order.Number;
                    total += order.Drink.Price * order.Number;

                    if (!customers.Contains(order.Student.Id))
                    {
                        customers.Add(order.Student.Id);
                    }
                }

                ListViewItem li = new ListViewItem(pair.Key.ToString("dd-MM-yyyy"));

                li.SubItems.Add(sold.ToString());
                li.SubItems.Add(total.ToString());
                li.SubItems.Add(customers.Count.ToString());

                lv_Sales.Items.Add(li);
            }
        }