private void Btn_DeleteAward_Click(object sender, RoutedEventArgs e) { string selectedAward; selectedAward = Convert.ToString(ListBox_AwardDetails.SelectedValue); // Verify the user selected a record to delete if (!string.IsNullOrEmpty(selectedAward)) { MessageBoxResult result; result = MessageBox.Show(Tools.deleteMessage, Tools.deleteTitle, MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { foreach (AwardDBInfo award in awardList) { if (award.Award == selectedAward) { // Remove from the database award.DeleteFromDatabase(); } } awardList = AwardDBInfo.LoadObjectList(CurrentBranch); ListBox_AwardDetails.DataContext = awardList; } } else { MessageBox.Show(Tools.RecordDeleteMessage, Tools.RecordSelectTitle); } }
// Copy Constructor public AwardDBInfo(AwardDBInfo other) { branch = other.branch; award = other.award; oldaward = other.oldaward; hasDataChanged = other.hasDataChanged; isNewRecord = other.isNewRecord; }
private void CmbBox_Service_SelectionChanged(object sender, SelectionChangedEventArgs e) { // Enable buttons if actual branch selected, disable on blank branch item Btn_AddAward.IsEnabled = !string.IsNullOrEmpty(CurrentBranch); Btn_EditAward.IsEnabled = !string.IsNullOrEmpty(CurrentBranch); Btn_DeleteAward.IsEnabled = !string.IsNullOrEmpty(CurrentBranch); awardList = AwardDBInfo.LoadObjectList(CurrentBranch); ListBox_AwardDetails.DataContext = awardList; }
private void Save() { CurrentAward.WriteDataToDatabase(); awardList = AwardDBInfo.LoadObjectList(CurrentBranch); ListBox_AwardDetails.DataContext = awardList; HideControls(); CurrentAward = null; }
private void Btn_EditAward_Click(object sender, RoutedEventArgs e) { string selectedAward; selectedAward = Convert.ToString(ListBox_AwardDetails.SelectedValue); // Verify the user selected a record to edit if (!string.IsNullOrEmpty(selectedAward)) { CurrentAward = new AwardDBInfo(CurrentBranch, selectedAward); ShowControls(); } else { MessageBox.Show(Tools.RecordSelectMessage, Tools.RecordSelectTitle); } }
// Loads the awards for a given branch into a list of objects public static List <AwardDBInfo> LoadObjectList(string Branch) { List <AwardDBInfo> records = new List <AwardDBInfo>(); AwardDBInfo current; try { using (MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString)) { conn.OpenAsync(); using (MySqlCommand command = conn.CreateCommand()) { command.CommandText = "SELECT AwardName FROM AwardsList WHERE BranchName=@BName;"; command.Parameters.Add("@BName", MySqlDbType.VarChar).Value = Branch; using (MySqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { if (!reader.IsDBNull(0)) { current = new AwardDBInfo(Branch, reader.GetString(0)); records.Add(current); } } } } } } catch (InvalidOperationException) { MessageBox.Show(Tools.DBErrorMessage, Tools.DBErrorTitle); } catch (MySqlException e) { Tools.HandleSQLExceptions(e); } return(records); }
private void Btn_AddAward_Click(object sender, RoutedEventArgs e) { CurrentAward = new AwardDBInfo(currentBranch); ShowControls(); }
// Loads data into the ranks observable collection for the dropdown for the selected branch private void CmbBox_Service_SelectionChanged(object sender, SelectionChangedEventArgs e) { AwardList = AwardDBInfo.LoadStringList(AwardInfo.Branch); }