private void ButtonExit_Click(object sender, EventArgs e)
        {
            this.Hide();
            StaffMainForm f2 = new StaffMainForm(staffMember);

            f2.ShowDialog();
            this.Close();
        }
Beispiel #2
0
        private void ButtonLogIn_Click(object sender, EventArgs e)
        {
            //True if all the components validate successfully
            if (ValidateForm())
            {
                //Checks whether it is a student or staff member attempting to login
                if (RadioButtonStudent.Checked == true)
                {
                    List <StudentModel> studentLogInDetails = new List <StudentModel>();
                    try
                    {
                        //Attempt to retrieve the record from TblStudent in the database that exactly matches the data
                        //input to TextBoxUsername and TextBoxPassword.
                        SqlConnector db = new SqlConnector();
                        studentLogInDetails = db.GetStudent_ByLogInDetails(TextBoxUsername.Text, TextBoxPassword.Text);
                    }
                    catch
                    {
                        MyMessageBox.ShowMessage("Access to the database failed.");
                        return;
                    }

                    if (studentLogInDetails.Count() == 1)
                    {
                        this.Hide();
                        StudentMainForm studentMainForm = new StudentMainForm(studentLogInDetails[0]);
                        studentMainForm.ShowDialog();
                        this.Close();
                    }
                    else
                    {
                        MyMessageBox.ShowMessage("Check your username and password.");
                    }
                }
                else if (RadioButtonStaff.Checked == true)
                {
                    List <StaffModel> staffLogInDetails = new List <StaffModel>();
                    try
                    {
                        SqlConnector db = new SqlConnector();
                        staffLogInDetails = db.GetStaff_ByLogInDetails(TextBoxUsername.Text, TextBoxPassword.Text);
                    }
                    catch
                    {
                        MyMessageBox.ShowMessage("Access to the database failed.");
                        return;
                    }

                    if (staffLogInDetails.Count() == 1)
                    {
                        this.Hide();
                        StaffMainForm staffMainForm = new StaffMainForm(staffLogInDetails[0]);
                        staffMainForm.ShowDialog();
                        this.Close();
                    }
                    else
                    {
                        MyMessageBox.ShowMessage("Check your username and password.");
                    }
                }
            }
            else
            {
                MyMessageBox.ShowMessage("Not all components validated successfully. Please check the flagged entries and try again.");
            }
        }