private void Btn_EditConflict_Click(object sender, RoutedEventArgs e) { int selectedIndex; VetConflictDBInfo selectedItem = null; // Get the index from the UI selectedIndex = ListBox_ConflictDetails.SelectedIndex; if (selectedIndex >= 0 && selectedIndex < Veteran.ConflictDetails.Count) { selectedItem = Veteran.ConflictDetails[selectedIndex]; ConflictDetails conflictWin = new ConflictDetails(selectedItem); conflictWin.ShowDialog(); Veteran.ConflictDetails[selectedIndex] = conflictWin.ConflictInfo; ListBox_ConflictDetails.Items.Refresh(); } else { MessageBox.Show(Tools.RecordSelectMessage, Tools.RecordSelectTitle); } }
private void Btn_DeleteConflict_Click(object sender, RoutedEventArgs e) { int selectedIndex; VetConflictDBInfo removeItem = null; // Get the index from the UI selectedIndex = ListBox_ConflictDetails.SelectedIndex; if (selectedIndex >= 0 && selectedIndex < Veteran.ConflictDetails.Count) { MessageBoxResult result; result = MessageBox.Show(Tools.deleteMessage, Tools.deleteTitle, MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { removeItem = Veteran.ConflictDetails[selectedIndex]; // Remove from the database removeItem.DeleteFromDatabase(); // Remove from the list Veteran.ConflictDetails.Remove(removeItem); ListBox_ConflictDetails.Items.Refresh(); } } else { MessageBox.Show(Tools.RecordDeleteMessage, Tools.RecordSelectTitle); } }
// Copy Constructor public VetConflictDBInfo(VetConflictDBInfo other) { hasDataChanged = other.hasDataChanged; id = other.id; cNum = other.cNum; conflict = other.conflict; }
// Default Constructor public ConflictDetails() { InitializeComponent(); ConflictInfo = new VetConflictDBInfo(); IsOk = false; dataPreviouslyChanged = Tools.hasDataChanged; DataContext = this; LoadData(); }
// Loads the conflict details into a list private List <VetConflictDBInfo> LoadConflictDetails() { List <VetConflictDBInfo> records = new List <VetConflictDBInfo>(); int conflictIdNum; try { using (MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString)) { conn.OpenAsync(); using (MySqlCommand command = conn.CreateCommand()) { command.CommandText = "SELECT CNum FROM Conflicts WHERE ID=@idNum;"; command.Parameters.Add("@idNum", MySqlDbType.Int32).Value = id; using (MySqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { if (!reader.IsDBNull(0)) { conflictIdNum = reader.GetInt32(0); VetConflictDBInfo record = new VetConflictDBInfo(conflictIdNum); records.Add(record); } } } } } } catch (InvalidOperationException) { MessageBox.Show(Tools.DBErrorMessage, Tools.DBErrorTitle); } catch (MySqlException e) { Tools.HandleSQLExceptions(e); } return(records); }
private void Btn_EditConflict_Click(object sender, RoutedEventArgs e) { int selectedId; VetConflictDBInfo selectedItem = null; bool found = false; // Get the sNum from the UI selectedId = Convert.ToInt32(ListBox_ConflictDetails.SelectedValue); foreach (VetConflictDBInfo conflict in Veteran.ConflictDetails) { if (conflict.CNum == selectedId) { selectedItem = conflict; found = true; } } // Should always be found, but if for some reason the record is not there, do nothing if (found) { ConflictDetails conflictWin = new ConflictDetails(selectedItem); conflictWin.ShowDialog(); if (conflictWin.IsOk) { // Remove the old listing of the item Veteran.ConflictDetails.Remove(selectedItem); // Insert the updated listing Veteran.ConflictDetails.Add(conflictWin.ConflictInfo); } ListBox_ConflictDetails.Items.Refresh(); } }
private void Btn_DeleteConflict_Click(object sender, RoutedEventArgs e) { int selectedId; VetConflictDBInfo removeItem = null; bool found = false; selectedId = Convert.ToInt32(ListBox_ConflictDetails.SelectedValue); MessageBoxResult result; result = MessageBox.Show(Tools.deleteMessage, Tools.deleteTitle, MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { foreach (VetConflictDBInfo conflict in Veteran.ConflictDetails) { if (conflict.CNum == selectedId) { // Remove from the database conflict.DeleteFromDatabase(); // Flag item for removal from list found = true; removeItem = conflict; } } if (found) { // Remove from the list Veteran.ConflictDetails.Remove(removeItem); } ListBox_ConflictDetails.Items.Refresh(); } }