private void btnConfirmOrder_Click(object sender, RoutedEventArgs e) { _addOrder = true; if (_addOrder == true) { if (orderCalender.SelectedDate.HasValue || (Customer)dgCustomerList.SelectedItem == null) { DateTime?dateOrNull = orderCalender.SelectedDate; if (dateOrNull != null) { Customer customer = (Customer)dgCustomerList.SelectedItem; DateTime newSelectedDate = dateOrNull.Value; DateTime timespan = DateTime.Parse(txtBoxTime.Text); TimeSpan enteredDate = timespan.TimeOfDay; DateTime formattedUserDate = newSelectedDate + enteredDate; var newOrder = new Order() { OrderDate = formattedUserDate, Active = true }; try { int newOrderID = _orderManager.AddNewOrder(newOrder); _orderManager.AddNewCustomerOrder(customer.CustomerID, newOrderID); this.DialogResult = true; } catch (Exception ex) { MessageBox.Show(ex.Message + "\n\n" + ex.InnerException.Message); } } } else { MessageBox.Show("Please select a date and a customer."); } } }