private void buttonBack_Click(object sender, EventArgs e)
        {
            //Hides the login page
            this.Hide();

            InstructorMainView back = new InstructorMainView(username);

            //show the register page
            back.ShowDialog();
            //close the login page
            this.Close();
        }
Пример #2
0
        private void buttonLoginInstructor_Click(object sender, EventArgs e)
        {
            //Variables to be used: 1x bool, 4x string
            // bool loggedIn = false;
            bool   found = false;
            string username = "", password = "";

            //check if boxes are empty, the Trim removes white space in text from either side
            if ("".Equals(textBoxUsername.Text.Trim()) || "".Equals(textBoxPassword.Text.Trim()))
            {
                MessageBox.Show("Please make sure you enter a Username and Password");
                return;
            }

            //(1) GET the username and password from the text boxes, is good to put them in a try catch
            try
            {
                username = textBoxUsername.Text.Trim();
                password = textBoxPassword.Text.Trim();
            }
            catch
            {
                //Error message, more useful when you are storing numbers etc. into the database.
                MessageBox.Show("Username or Password given is in an incorrect format.");
                return;
            }
            string userType = "instructor";

            int usernamePos = 0;
            int passwordPos = 5;

            found = SearchUser(userType, usernamePos, passwordPos, username, password);

            if (!found)
            {
                //message stating we couldn't log in
                MessageBox.Show("Login attempt unsuccessful! Please check details");
                initialiseTextBoxes();
                textBoxUsername.Focus();
            }
            else
            {
                //Hides the login page
                this.Hide();

                InstructorMainView instructor = new InstructorMainView(username);
                //show the register page
                instructor.ShowDialog();
                //close the login page
                this.Close();
            }
        }