Example #1
0
        public List <Order> GetOrders()
        {
            List <Order> orders       = new List <Order>();
            Customer     tempCustomer = new Customer();

            using (SqlConnection connection = new SqlConnection(Database.Instance.ConnectionString))
            {
                connection.Open();

                SqlCommand command = new SqlCommand("ShowOrders", connection);
                command.CommandType = CommandType.StoredProcedure;

                SqlDataReader reader = command.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        int      orderID        = int.Parse(reader["OrderID"].ToString());
                        Customer customer       = tempCustomer.GetCustomer(int.Parse(reader["CustomerID"].ToString()));
                        DateTime dateOfPurchase = DateTime.Parse(reader["DateOfPurchase"].ToString());
                        double   totalPrice     = double.Parse(reader["TotalPrice"].ToString());
                        bool     active         = bool.Parse(reader["Active"].ToString());
                        orders.Add(new Order(orderID, customer, dateOfPurchase, totalPrice, active));
                    }
                }
            }

            return(orders);
        }
Example #2
0
        private void ButtonSearchOrdre_Click(object sender, RoutedEventArgs e)
        {
            Order order = new Order();

            Domain.Customer  customer = new Domain.Customer();
            WindowShowDialog wsd      = new WindowShowDialog();

            if (double.TryParse(TextBoxOrderID.Text, out double resultOrderID) || (double.TryParse(TextBoxCustomer.Text, out double resultCustomer) || double.TryParse(TextBoxTotalPrice.Text, out double resultTotalPrice) || DatePickerDateOfPurchase.SelectedDate != null))
            {
                if (double.TryParse(TextBoxOrderID.Text, out resultOrderID) == false)
                {
                    order.OrderID = 0;
                }
                else
                {
                    order.OrderID = int.Parse(TextBoxOrderID.Text);
                }

                if (double.TryParse(TextBoxCustomer.Text, out resultCustomer) == false)
                {
                    order.Customer            = new Domain.Customer();
                    order.Customer.CustomerID = 0;
                }
                else
                {
                    order.Customer = customer.GetCustomer(int.Parse(TextBoxCustomer.Text));
                }

                if (double.TryParse(TextBoxTotalPrice.Text, out resultTotalPrice) == false)
                {
                    order.TotalPrice = 0;
                }
                else
                {
                    order.TotalPrice = double.Parse(TextBoxTotalPrice.Text);
                }

                if (DatePickerDateOfPurchase.SelectedDate == null)
                {
                    order.DateOfPurchase = new DateTime(1973, 1, 1, 12, 0, 0);
                }
                else
                {
                    order.DateOfPurchase = DateTime.Parse(DatePickerDateOfPurchase.Text);
                }

                eventSendList(orderRepository.DisplaySpecificOrders(order));
                this.Close();
            }

            else
            {
                wsd.LabelShowDialog.Content = "Der var en fejl i 'Order nummer', 'Kunde', 'Samlet pris' eller 'Pakke dato'";
                wsd.ShowDialog();
            }
        }