public frmLogin() { InitializeComponent(); connection = conn.oraConn(); User = null; UserFirstName = null; isAdmin = false; isConvenor = false; isSupervisor = false; frmStuDashboard = null; frmEmpDashboard = null; }
private void btnLogin_Click(object sender, EventArgs e) { //validate user based on db User = txtUsername.Text; //record the user char UserLetter = Convert.ToChar(User.Substring(0, 1)); //allows easy access to user accounts without having to remember passwords //which for the main users are set to " " as they cannot be null if (txtPassword.Text.Length == 0) { txtPassword.Text = " "; } //check if a student if (Char.ToLower(UserLetter) == 's' && User.ToLower() != "supervisor") //since student ids would start with an 's' like s748932 { if (User.ToLower() == "student") //for ease of access at the moment... { frmStuDashboard = new frmStuDashboard(User, "Student"); frmStuDashboard.FormClosing += frmStuDashboardClosing; frmStuDashboard.Show(); return; } else { //load in all student rows getStudents(); //search dataset by stuID (username), returning a row if it exists int srowcnt = students.Tables[0].Rows.Count; for (int i = 0; i <= srowcnt - 1; i++) { //search for username if (User.ToLower() == students.Tables[0].Rows[i][0].ToString().ToLower()) { //check if password matches before confirming login if (txtPassword.Text == students.Tables[0].Rows[i][5].ToString()) { UserFirstName = students.Tables[0].Rows[i][1].ToString(); frmStuDashboard = new frmStuDashboard(User, UserFirstName); frmStuDashboard.FormClosing += frmStuDashboardClosing; frmStuDashboard.Show(); return; } else { MessageBox.Show("Incorrect password, please try again", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtPassword.Focus(); return; } } } MessageBox.Show("Student ID not recognised, please try again", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtUsername.Focus(); return; } } //otherwise check if an employee else { //load in all employee rows getEmployees(); //search dataset by empID (username), returning a row if it exists int erowcnt = employees.Tables[0].Rows.Count; for (int i = 0; i < erowcnt; i++) { //search for username //for testing: MessageBox.Show("User: "******", EmpID row: " + employees.Tables[0].Rows[i][0].ToString()); if (User.ToLower() == employees.Tables[0].Rows[i][0].ToString().ToLower()) { //check if password matches before confirming login if (txtPassword.Text == employees.Tables[0].Rows[i][5].ToString()) { ValidateEmployeeStatus(User); UserFirstName = employees.Tables[0].Rows[i][1].ToString(); frmEmpDashboard = new frmEmpDashboard(User, UserFirstName, isAdmin, isConvenor, isSupervisor); frmEmpDashboard.FormClosing += frmEmpDashboardClosing; frmEmpDashboard.Show(); return; } else { MessageBox.Show("Incorrect password, please try again", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtPassword.Focus(); return; } } } MessageBox.Show("Employee ID not recognised, please try again", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtUsername.Focus(); return; /*//(for ease of access, we can use admin convenor or supervisor to access these) * if (User.ToLower() == "admin" || User.ToLower() == "convenor" || User.ToLower() == "supervisor") * { * frmEmpDashboard = new frmEmpDashboard(User, true, true, true); * frmEmpDashboard.FormClosing += frmEmpDashboardClosing; * frmEmpDashboard.Show(); * } * else * { * MessageBox.Show("Please enter a valid username and password", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Warning); * txtPassword.Focus(); * return; * }*/ } }
private void frmStuDashboardClosing(object sender, FormClosingEventArgs e) { frmStuDashboard = null; }