/* * This form is intended to be the primary form used by students * Upon launching the program the administrator login page opens requiring an * admin or lab assistant to load the program fully * Upon launching this form is locked into fullscreen to prevent student tampering * with the computer * Alt-Tab will be disabled in future versions, Ctrl-Alt-Del and Alt-F4 require interfering * with System processes to disable and as such are being left to later users to determine * if the risk is neccessary */ public StudentLogin() { InitializeComponent(); this.AutoScaleMode = AutoScaleMode.Dpi; this.WindowState = FormWindowState.Normal; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Bounds = Screen.PrimaryScreen.Bounds; if (FirstTimeLoad()) { using (var myform = new FirstLoadPassword()) { do { myform.ShowDialog(); }while (myform.DialogResult != DialogResult.OK); } } using (var myform = new AdminLogin()) //calls the admin login page on program startup { do { myform.ShowDialog(); }while (myform.DialogResult != DialogResult.OK); } OpenFill(); //call the fill method for the student login list box ResetDir(); //resets the current directory to the base directory }
private void Logout_Click(object sender, EventArgs e) //Opens the student logout form for the lab assistants { //to do single user logouts if (currentLogins.Count > 0) { using (var adminform = new AdminLogin()) { adminform.ShowDialog(); if (adminform.DialogResult == DialogResult.OK) { using (var myform = new Logout(currentLogins)) //passes the current login list to the logout form { var result = myform.ShowDialog(); //Declared as var because we expect an update when this closes if (result == DialogResult.OK) { currentLogins = myform.currentStudents; //receives an updated list from the logout form } OpenFill(); //repopulates the student login list } } } } else { MessageBox.Show("No students currently logged in."); } }
/* * Function to remove an account from the dbo.Admins. This function calls the AdminLogin form as * additional authorization. It is also unable to remove the base Administrator account as it should * not be an available option in the listbox. */ private void removeButton_Click(object sender, EventArgs e) { try { if (removeListBox.SelectedIndex != -1) { using (var myform = new AdminLogin()) //calling the AdminLogin form for additional security { myform.ShowDialog(); if (myform.DialogResult == DialogResult.OK && (myform.authok == "Admin" || myform.authok == "Administrator")) { Valid admin = new Valid(); if (admin.RemoveAdmin(removeListBox.SelectedItem.ToString())) { MessageBox.Show("Selected admin removed."); ListFill(true); ListFill(false); } } } } } catch { } }
private void exitToolStripMenuItem_Click(object sender, EventArgs e) //Exits the program with Admin approval { using (Form myform = new AdminLogin()) { var result = myform.ShowDialog(); if (result == DialogResult.OK) { clearLoginsToolStripMenuItem.PerformClick(); this.Close(); } } }
/* * The following region is composed of entries for the menu buttons to open other forms * Generally, all of these menu strip options first open the AdminLogin form to validate * the user * Some of the options specifically require a higher admin level than the Lab Assistant * these options are denoted by a decision statement that checks the authok value returned * by the AdminLogin form, this value denotes the admin type each login is assigned in the Admin DB * */ #region MenuStripItems private void AddStudent_Click(object sender, EventArgs e) //Opens the add student form { using (Form myform = new AdminLogin()) //Opens the admin login form to control adding to DB { var result = myform.ShowDialog(); if (result == DialogResult.OK) //This generic dialog check looks for a successful { //admin login of any type Form userform = new CreateUser(); userform.ShowDialog(); OpenFill(); //repopulates the list after a student is added } } }
/* * Function for creating new admin accounts. Validates that all required fields have been filled on * button press and calls the appropriate Valid class function to insert */ private void createButton_Click(object sender, EventArgs e) { if (createNameBox.Text != string.Empty) { if (createPassBox.Text != string.Empty && createConfirmBox.Text == createPassBox.Text) { string type; if (labRadioButton.Checked) //if statement to determine the account type being created { type = "LabAssist"; } else { type = "Admin"; } using (var myform = new AdminLogin()) //calls the AdminLogin form as an additional authorization { myform.ShowDialog(); if (myform.DialogResult == DialogResult.OK && (myform.authok == "Admin" || myform.authok == "Administrator")) { Valid Admin = new Valid(); if (Admin.InsertAdmin(createNameBox.Text, createPassBox.Text, type)) { MessageBox.Show("New user created."); } ListFill(true); ListFill(false); } } } else { MessageBox.Show("Password confirmation invalid."); ClearThings(); createNameBox.Focus(); } } else { MessageBox.Show("Please enter a name for this user."); ClearThings(); createNameBox.Focus(); } }
private void AdminTasks_Click(object sender, EventArgs e) //Opens Administrator form { using (var myform = new AdminLogin()) { var result = myform.ShowDialog(); //The following check uses the above mentioned method for determining if an admin //or a lab assistant is attempting to open the admin form as only admins should //be allowed access //The form is declared as a form instead of a var because we expect no return values if (result == DialogResult.OK && (myform.authok == "Admin" || myform.authok == "Administrator")) { Form adminform = new AdminTasks(); adminform.ShowDialog(); OpenFill(); //repopulates the student list as admins can remove students } else { MessageBox.Show("Incorrect username/password."); } } }
private void clearLoginsToolStripMenuItem_Click(object sender, EventArgs e) //allows labassist/admins to log everyone out at end of day { if (currentLogins.Count != 0) { using (Form myform = new AdminLogin()) { myform.ShowDialog(); if (myform.DialogResult == DialogResult.OK) { for (int i = 0; i < currentLogins.Count; i++) { string logDir = Path.Combine(Environment.CurrentDirectory, "Logs"); DateTime dt = DateTime.Now; string date = dt.ToShortDateString(); string time = dt.ToShortTimeString(); string[] newdate = (dt.Date.ToString()).Split(); string[] dateparts = newdate[0].Split('/'); date = dateparts[0] + "-" + dateparts[1] + "-" + dateparts[2]; if (!Directory.Exists(logDir)) { Directory.CreateDirectory(logDir); } string logpath = date + ".txt"; using (StreamWriter outputfile = new StreamWriter("Logs\\" + logpath, true)) { string[] name = currentLogins[i].Split(','); outputfile.WriteLine(Utility.Encrypt(name[1].Trim() + "," + name[0].Trim() + ",," + date + ",Force out: ," + time, false)); outputfile.Close(); } } currentLogins.Clear(); MessageBox.Show("All users logged out."); OpenFill(); } } } }