Exemple #1
0
        /**
         * Search for customer with an id.
         * If found show the data on the customer in CustomerGrid.
         * If not found set ErrorLabels text and show error message.
         */
        private void FindCustomerButton_Click(object sender, RoutedEventArgs e)
        {
            // Hide labels with errors and other info for the user.
            HideInteractionLabels();

            // Hide edit customer elements if need be.
            if (EditButton.Content.ToString() == "Gem Ændringer")
            {
                HideEditCustomerElements();

                // Set InfoLabels text to inform the user.
                SetLabelGreenText(InfoLabel, "Der blev ikke gemt nogen ændringer.");
            }

            // Get text from search textbox.
            string result = TxtBoxCustomerId.Text;

            // Parse string text to int value.
            if (int.TryParse(result, out int id))
            {
                // Search for customer in database.
                Customer customer = _context.GetCustomer(id);

                // If customer was found.
                if (customer != null)
                {
                    // Show customer info in customerGrid.
                    CustomerGrid.DataContext = customer;

                    // Sort and show customer bookings in listbox.
                    _context.SortBookings(customer.Bookings);
                    BookingListBox.ItemsSource = customer.Bookings;

                    EditButton.Visibility = Visibility.Visible;
                    ResetSearchTxtBox();
                    SetLabelGreenText(SearchErrorLabel, "Succes! Kunden blev fundet.");
                }
                else
                {
                    SetLabelRedText(SearchErrorLabel, "Beklager, en kunde med det angivne id blev ikke fundet.");
                    ResetSearchTxtBox();
                }
            }
            else
            {
                SetLabelRedText(SearchErrorLabel, "Indtast venligst et id bestående af tal.");
                ResetSearchTxtBox();
            }
        }
Exemple #2
0
        //------------------------------ EVENTHANDLERS --------------------------------------------------------

        /**
         * This method has two functions, either it shows the elements needed to
         * change the status or it changes and saves the status of the booking.
         */
        private void EditStatusButton_Click(object sender, RoutedEventArgs e)
        {
            // Hide InfoLabel.
            InfoLabel.Visibility = Visibility.Collapsed;

            // Get EditButtons text to see, if it is the edit or
            // the save functionality that should be executed.
            string text = EditButton.Content.ToString();

            // The edit functionality executes.
            if (text == "Rediger Status")
            {
                ShowEditStatusElements();
            }

            // The save functionality executes.
            if (text == "Gem Status")
            {
                // Get current status.
                string current = Status.Content.ToString();

                // Get selected item from ComboBox. Probably not the prettiest solution, but it works.
                string selectedStatus = Combo.SelectedItem.ToString(); // System.Windows.Controls.ComboBoxItem: Udleveret
                string status         = selectedStatus.Split()[1];     // Udleveret

                // Only change and save if there are any changes to make.
                if (status != current)
                {
                    // If a user tries to change a status from "Udleveret"
                    // to "Reserveret", an error is returned.
                    if (current == "Udleveret" && status == "Reserveret")
                    {
                        // Set and show InfoLabel as Error.
                        SetLabelRedText(InfoLabel, "Udlejningen er udleveret og kan derfor ikke reserveres.");
                    }
                    // If status is not the same as current and current
                    // is not "Udleveret", the status can be set.
                    else if (status == "Reserveret" || status == "Udleveret" || status == "Tilbageleveret")
                    {
                        // Save changes to database.
                        _booking.Status = status;
                        _context.SaveChanges();

                        // Update this datacontext.
                        DataContext = null;
                        DataContext = _booking;

                        // Update BookingsListBox in MainWindow.
                        List <Booking> bookings = new List <Booking>(_booking.Customer.Bookings);
                        _context.SortBookings(bookings);
                        _bookingListBox.ItemsSource = null;
                        _bookingListBox.ItemsSource = bookings;

                        SetLabelGreenText(InfoLabel, "Ændringen blev gemt.");
                    }
                }
                else
                {
                    SetLabelRedText(InfoLabel, "Der blev ikke gemt nogen ændringer.");
                }

                HideEditStatusElements();
            }
        }