// When the Login button has been clicked
        private void LoginButton_Click(object sender, EventArgs e)
        {
            UserDatabase userDB = new UserDatabase(); // Create a new instance of a User Database. This allows reading and writing of the database

            // Verification
            if (UsernameETF.Text.Equals("")) // If no username has been entered
            {
                MessageBox.Show("Please enter a Username"); // Show a message box describing the error
                return; // Stop this method
            }
            else if (PasswordETF.Text.Equals("")) // If no password has been entered
            {
                MessageBox.Show("Please enter a Password");
                return;
            }
            else if (!userDB.ContainsUsername(UsernameETF.Text)) // If the database does not contain this username
            {
                MessageBox.Show("Username not recognised"); // Display a message box describing the error
                return; // Stop this method
            }
            else if (!userDB.ContainsPassword(UsernameETF.Text, PasswordETF.Text)) // If the user has not entered the correct password for this username
            {
                MessageBox.Show("Password is incorrect for this Username");
                return;
            }

            // Start the game

            if (UsernameETF.Text.Equals("Teacher"))
            {
                TeacherForm teacherForm = new TeacherForm();
                teacherForm.Visible = true;
                UsernameETF.Text = ""; // Clear the username text box
                PasswordETF.Text = ""; // Clear the password text box
                return;
            }
            GameForm gameForm = new GameForm(this, UsernameETF.Text); // Create a new instance of a GameForm
            gameForm.Visible = true; // Make the GameForm Visible
            this.Visible = false; // Hide the current Form
            UsernameETF.Text = ""; // Clear the username text box
            PasswordETF.Text = ""; // Clear the password text box
        }
Exemple #2
0
 private void LoginButton_Click(object sender, EventArgs e)
 {
     UserDatabase userDB = new UserDatabase();
     if (!userDB.ContainsUsername(UsernameETF.Text))
     {
         MessageBox.Show("Username not recognised");
         return;
     }
     else if(!userDB.ContainsPassword(UsernameETF.Text, PasswordETF.Text))
     {
         MessageBox.Show("Password is incorrect for this Username");
         return;
     }
     Game gameForm = new Game(this, UsernameETF.Text);
     gameForm.Visible = true;
     this.Visible = false;
 }