public NanniesWindow() { InitializeComponent(); nannyToAdd = new Nanny { DateOfBirth = DateTime.Now.AddYears(-18) // The youngest age allowed }; nannyToRemove = new Nanny(); nannyToUpdate = new Nanny(); this.addNannyPage.DataContext = nannyToAdd; // The data context of the add nanny page // Initialises the items in the combo boxes this.typeOfPaymentComboBox.ItemsSource = Enum.GetValues(typeof(Payment)); this.vacationDaysComboBox.ItemsSource = Enum.GetValues(typeof(VacationDaysBy)); this.typeOfPaymentComboBox_U.ItemsSource = Enum.GetValues(typeof(Payment)); this.vacationDaysComboBox_U.ItemsSource = Enum.GetValues(typeof(VacationDaysBy)); this.removeNannyComboBox.ItemsSource = BlFactorySingleton.Instance.GetNannies(); this.removeNannyComboBox.DisplayMemberPath = "IdAndName"; this.updateNannyComboBox.ItemsSource = BlFactorySingleton.Instance.GetNannies(); this.updateNannyComboBox.DisplayMemberPath = "IdAndName"; }
private void UpdateButton_Click(object sender, RoutedEventArgs e) { if (errorsMessagesForUpdate.Any()) // If there is some exception { string message = "You have errors in entering the data:"; foreach (var item in errorsMessagesForUpdate) { message += "\n" + item; } MessageBox.Show(message, "Error message", MessageBoxButton.OK, MessageBoxImage.Error); return; } // Warning the user MessageBoxResult boxResult = MessageBox.Show("Are you sure you want to change the details of this nanny?", "Warning message", MessageBoxButton.YesNo, MessageBoxImage.Question); if (boxResult == MessageBoxResult.No) { return; } // Update the nanny try { nannyToAdd.Address = addressTextBox_U.Text; // Inserts the address BlFactorySingleton.Instance.UpdateNanny(nannyToUpdate); MessageBox.Show("The nanny was successfully updated", "Successfull message", MessageBoxButton.OK, MessageBoxImage.Information); nannyToUpdate = new Nanny(); this.updateNannyPage.DataContext = nannyToUpdate; this.removeNannyComboBox.ItemsSource = BlFactorySingleton.Instance.GetNannies(); // Refreshes the remove combo box this.updateNannyComboBox.ItemsSource = BlFactorySingleton.Instance.GetNannies(); // Refreshes the update combo box addressTextBox_U.Text = ""; // Refreshes the "nannies Grouping Page" this.minAge.IsChecked = false; this.maxAge.IsChecked = false; this.nanniesGroupingPage.DataContext = null; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error message", MessageBoxButton.OK, MessageBoxImage.Error); } }