private void editCountry_Click(object sender, RoutedEventArgs e) { // Instantiate the dialog box var dlg = new AddCountryDialogBox { countryName = { Text = ((Country)countriesList.SelectedItem).Name }, countryCode = { Text = ((Country)countriesList.SelectedItem).Code }, Title = "Edit Country", }; // Open the dialog box modally dlg.Title = "Edit Country"; dlg.countryName.IsReadOnly = true; dlg.ShowDialog(); dlg.countryName.IsReadOnly = true; if (dlg.DialogResult != false) { if (dlg.countryCode.Text == String.Empty) { MessageBox.Show("Cannot have empty fields"); return; } _clientCon.EditCountry(((Country)countriesList.SelectedItem).ID, dlg.countryCode.Text); } }
private void addCountry_Click(object sender, RoutedEventArgs e) { // Instantiate the dialog box var dlg = new AddCountryDialogBox(); // Open the dialog box modally dlg.ShowDialog(); if (dlg.DialogResult != false) { var name = dlg.countryName.Text; var code = dlg.countryCode.Text; if (name == String.Empty || code == String.Empty) { MessageBox.Show("Cannot have empty fields"); return; } try { _clientCon.AddCountry(code, name); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }