/* * This is the event handler that removes the selected student from the database. It requires * secondary authentication as an added precaution as it does modify the database. */ private void removeButton_Click(object sender, EventArgs e) { if (studentListBox.SelectedIndex != -1) { using (var myform = new AdminLogin()) { //myform.ShowDialog(); //if (myform.DialogResult == DialogResult.OK && (myform.authok == "Admin" || myform.authok == "Administrator")) //{ string name = studentListBox.SelectedItem.ToString(); string[] fullname = name.Split(','); //tokenizes name for searching the DB string lastname = fullname[0].Trim(); string firstname = fullname[1].Trim(); string password = fullname[2].Trim(); Valid student = new Valid(lastname, firstname, Utility.Encrypt(password, false)); if (student.RemoveStudent(student)) //executes the remove SQL query and returns a boolean if successful { MessageBox.Show("Student removed."); OpenFill(); } else { MessageBox.Show("Error removing student."); } //} /*else * { * MessageBox.Show("Failed to remove student."); * }*/ } } }
/* * Method created to backup and scrub the database. This is intended to be used each semester to allow administrators to import a current * list of enrolled students. */ private void backupAndDeleteDatabaseEntriesToolStripMenuItem_Click(object sender, EventArgs e) { MessageBox.Show("Warning, this will remove all entries from the student database."); try { createDatabaseDumpToolStripMenuItem.PerformClick(); //call the full DB dump function if (backedUp == true) //check against form property set by the DB dump function { Valid student = new Valid("filler", "filler", "%"); //creates a student with a wildcard password for a full delete if (student.RemoveStudent(student)) { MessageBox.Show("Database has been backed up and scrubbed."); } } } catch { MessageBox.Show("An error has occured while performing the delete process."); } }