private void btnRemoveSelected_Click(object sender, EventArgs e) { int[] recordsToDelete = RowsOfCheckboxesSelected(); if (recordsToDelete.Length is 0) { return; } DialogResult confirmation; string name = null; if (recordsToDelete.Length is 1) { name = $"{dataGridView1.Rows[recordsToDelete[0]].Cells[2].Value} {dataGridView1.Rows[recordsToDelete[0]].Cells[3].Value}"; confirmation = MessageBox.Show($"Are you sure you want to delete {name} from the roster?", "Before we take action...", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); } else { confirmation = MessageBox.Show($"Are you sure you want to delete these {recordsToDelete.Length} students from the roster?", "Before we take action...", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); } if (confirmation is DialogResult.Yes) { DataGridViewRow nextRow; uint keyFromNextRow; for (int i = 0; i < recordsToDelete.Length; i++) { nextRow = dataGridView1.Rows[recordsToDelete[i]]; keyFromNextRow = uint.Parse(nextRow.Cells[1].Value.ToString()); studentHashTable.Remove(keyFromNextRow); } if (recordsToDelete.Length is 1) { MessageBox.Show($"{name} has deleted from the roster.", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show($"{recordsToDelete.Length} students have been deleted from the roster.", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information); } dataGridView1.DataSource = studentHashTable.DataForDisplay().OrderBy(pupil => pupil.ID).ToArray(); } }
private void btnSearch_Click(object sender, EventArgs e) { switch (cmbBxKeySelect.SelectedIndex) { case 0: //Search by student ID if (IDValidator()) { uint keyOfSearchedItem = uint.Parse(txtBxID.Text); searchResults = new Student[1] { currentRoster.DataForDisplay().FirstOrDefault(pupil => pupil.ID == keyOfSearchedItem) }; if (searchResults[0] is null) { MessageBox.Show(@"Sorry, there isn't any record with that ID #. Please double check and try again.", "No Match Found", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } dataGridView1.DataSource = searchResults; if (searchResults[0] != null) { txtBxID.Clear(); } } break; case 1: //Search by full name if (FullNameValidator()) { string first = txtBxFirstName.Text.ToLower(), last = txtBxLastName.Text.ToLower(); searchResults = currentRoster.DataForDisplay() .Where(pupil => pupil.FirstName.ToLower() == first && pupil.LastName.ToLower() == last) .ToArray(); if (searchResults.Length is 0) { MessageBox.Show(@"Sorry, there isn't any record with that full name. Please double check and try again.", "No Match Found", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (searchResults.Length > 1) { MessageBox.Show($"The {searchResults.Length} students named {txtBxFirstName.Text.Trim() + " " + txtBxLastName.Text.Trim()} will be displayed in the table.", "Multiple Students Found", MessageBoxButtons.OK, MessageBoxIcon.Information); } dataGridView1.DataSource = searchResults; if (searchResults.Length != 0) { txtBxFirstName.Clear(); txtBxLastName.Clear(); } } break; default: //Nothing was selected return; } }
public RemoveForm(StudentHashTable theRoster) { InitializeComponent(); studentHashTable = theRoster; theDataSource = studentHashTable.DataForDisplay().OrderBy(pupil => pupil.ID).ToArray(); }
private void DisplayForm_Load(object sender, EventArgs e) { dataGridView1.DataSource = currentRoster.DataForDisplay().OrderBy(pupil => pupil.ID).ToArray(); oldColumn = 1; searchResults = new Student[0]; sortAscending = new bool[6]; sortAscending[0] = true; for (int i = 1; i < sortAscending.Length; i++) { sortAscending[i] = false; } }