Exemplo n.º 1
0
        private void skipButton_Click(object sender, EventArgs e)
        // This is to allow users to skip the login screen if they don't wish to login at the current time
        // but still want to use the appliction
        {
            username1.Text = username1.Text.Insert(0, "skip");
            password1.Text = password1.Text.Insert(0, "skip");
            //this inserts into the textboxes a 'skip' value, this will allow users to login to an account where statistics are not tracked.
            connection.Open();                         // Opens the connection to the database.
            OleDbCommand command = new OleDbCommand(); // Establishes that a command is going to be used, usually a SQL statement.

            command.Connection  = connection;          // States the command should be associated with the current connection.
            command.CommandText = "select * from userAccount where Username='******'and Password='******'";
            // SQL statement is stated here
            // username1 and password1 refer to the text boxes used in the login form.

            OleDbDataReader reader = command.ExecuteReader(); // Goes through each record and tries to find appropriate matches with that above SQL.
            int             count  = 0;                       // Stores a local variable to this method to allow the use of a loop.

            while (reader.Read())
            {
                count++;    // Implements variable count by 1 when a match is found.
            }
            if (count == 1) // When a match is found,
            {
                MetroMessageBox.Show(this, "Skipping login...", "Skip Successful", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
                connection.Close();              // Closes the connection to the database
                connection.Dispose();            // stops using any resources  related to the database.
                this.Hide();                     // Hides the current form
                Main_menu frm = new Main_menu(); // creates a new instance of the main menu form/
                frm.login1 = this;               // this passes the data that was typed into username1 to the next form, allowing the username to be accessed from other forms.
                frm.Show();                      // Shows the Main_menu form
            }
        }
Exemplo n.º 2
0
        private void signIn_Click(object sender, EventArgs e)
        // Sign in button, signs users into the software when they click login.
        {
            if (password1.Text.Length > 3)
            // Condition that checks if the password will be valid
            {
                connection.Open();                         // Opens the connection to the database.
                OleDbCommand command = new OleDbCommand(); // Establishes that a command is going to be used, usually a SQL statement.
                command.Connection  = connection;          // States the command should be associated with the current connection.
                command.CommandText = "select * from userAccount where Username='******'and Password='******'";
                // SQL statement is stated here, Selects all of the data where the username is the same as the username typed in, and the password.
                // username1 and password1 refer to the text boxes used in the login form.

                OleDbDataReader reader = command.ExecuteReader(); // Goes through each record and tries to find appropriate matches with that above SQL.
                int             count  = 0;                       // Stores a local variable to this method to allow the use of a loop.
                while (reader.Read())
                {
                    count++;    // Implements variable count by 1 when a match is found.
                }
                if (count == 1) // When a match is found,
                {
                    MetroMessageBox.Show(this, "Logging in...", "Login Successful", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
                    connection.Close();              // Closes the connection to the database
                    connection.Dispose();            // stops using any resources  related to the database.
                    this.Hide();                     // Hides the current form
                    Main_menu frm = new Main_menu(); // creates a new instance of the main menu form/
                    frm.login1 = this;               // this passes the data that was typed into username1 to the next form, allowing the username to be accessed from other forms.
                    frm.Show();                      // Shows the Main_menu form
                }
                else
                {
                    MetroMessageBox.Show(this, "Incorrect details", "Login unsuccessful", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                    //Tells users when they do not have the correct details
                }
                connection.Close();
                //Closes connection to the database or else there could be issues with corruption when closing as the connection won't be closed.
            }
            else
            {
                MessageBox.Show("Password not long enough to be valid.");
            }
            // If password is invalid, this message is shown. (Less than 3 characters.)
        }