/// <summary> /// Callback for when the DBA panel is made visible after clicking the "DBA" menu button. This method repopulates the DBA List /// and adds the data to the DBA listbox. The listbox contains all of the DBAs in the system, except for the DBA user. This is done /// to prevent the case where a DBA can delete from themselves from the system (and potentially have 0 DBAs for the system) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void panel_dba_VisibleChanged(object sender, EventArgs e) { dbas = Dba.Generate(); for (int i = 0; i < dbas.Count; i++) { if (dbas.ElementAt(i).username.Equals(dba.username)) { dbas.RemoveAt(i); break; } } listBox_dba.DataSource = dbas; listBox_dba.DisplayMember = "fullName"; }
/// <summary> /// Callback for when the "Delete" button is clicked in the DBA panel. This method is used to trigger the deletion of the DBA in the system. /// If no item is selected, nothing happens. An error message displays if the operation was uncessful. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button_dba_delete_Click(object sender, EventArgs e) { if (listBox_dba.SelectedIndex > -1) { dbas.ElementAt(listBox_dba.SelectedIndex).Delete(); listBox_dba.SelectedIndex = -1; dbas = Dba.Generate(); for (int i = 0; i < dbas.Count; i++) { if (dbas.ElementAt(i).username.Equals(dba.username)) { dbas.RemoveAt(i); break; } } listBox_dba.DataSource = dbas; listBox_dba.DisplayMember = "fullName"; } }
/// <summary> /// Callback for when the "Save" or "Add" button is clicked in the DBA panel. The button has the text "Save" when updating an already existing DBA /// and the text "Add" when creating a new DBA to the system. This is determined by checking to see if an element is selected before proceding with /// the operation. If any of the fields are left empty an error message is displayed for the user. The password must also meet the specified requirements. /// If the operation was uncessful, another error message is displayed. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button_dba_save_Click(object sender, EventArgs e) { if (textBox_dba_fName.Text.Equals("") || textBox_dba_lName.Text.Equals("") || textBox_dba_username.Text.Equals("") || textBox_dba_password.Text.Equals("")) { MessageBox.Show("Please fill in all fields."); } else { if (!PasswordMeetsRequirements(textBox_dba_password.Text)) { MessageBox.Show("Entered passwords do not meet minimum requirements\n1 upper case letter, 1 lower case letter, 1 digit, and legth of at least 8."); } else { if (listBox_dba.SelectedIndex < 0) { Dba d = new Dba(textBox_dba_username.Text, textBox_dba_password.Text, textBox_dba_fName.Text, textBox_dba_lName.Text); if (!d.Add()) { MessageBox.Show("Database administrator could not be added."); } else { dbas = Dba.Generate(); for (int i = 0; i < dbas.Count; i++) { if (dbas.ElementAt(i).username.Equals(dba.username)) { dbas.RemoveAt(i); break; } } listBox_dba.DataSource = dbas; listBox_dba.DisplayMember = "fullName"; } } else { Dba d = dbas.ElementAt(listBox_dba.SelectedIndex); if (!d.Update(textBox_dba_password.Text, textBox_dba_fName.Text, textBox_dba_lName.Text)) { MessageBox.Show("Database administrator could not be updated."); } else { dbas = Dba.Generate(); for (int i = 0; i < dbas.Count; i++) { if (dbas.ElementAt(i).username.Equals(dba.username)) { dbas.RemoveAt(i); break; } } listBox_dba.DataSource = dbas; listBox_dba.DisplayMember = "fullName"; } } } } }