Exemplo n.º 1
0
        private void OrderDatesButton_Click(object sender, EventArgs e)
        {
            OrdersResultTextBox.Text                     = "";
            SqlOperations.DisplayFormattedSql            = true;
            SqlOperations.OnShowFormattedStatementEvent += SqlOperations_OnShowFormattedStatementEvent;
            var sb = new StringBuilder();

            sb.AppendLine("Results");
            sb.AppendLine("");

            var orderDates = new List <string>()
            {
                "10-17-2014", "06/11/2015", "10/30/2015"
            };


            var orders            = SqlOperations.ExampleOrderDates(orderDates);
            var groupedOrderItems = orders
                                    .GroupBy(ord => ord.OrderDate)
                                    .Select(ord => new OrderItem
            {
                OrderDateTime = ord.Key,
                OrderList     = ord.ToList()
            })
                                    .ToList();

            foreach (var groupedOrderItem in groupedOrderItems)
            {
                sb.AppendLine($"{groupedOrderItem.OrderDateTime.Value:d} - {groupedOrderItem.OrderList.Count}");
            }

            MessageBox.Show(sb.ToString());
            SqlOperations.OnShowFormattedStatementEvent -= SqlOperations_OnShowFormattedStatementEvent;
            SqlOperations.DisplayFormattedSql            = false;
        }