예제 #1
0
        // This is an event listener for submit button.
        // This method will check if username and password are valid and empty fields
        // on the form.
        private void SubmitBtn_Click(object sender, EventArgs e)
        {
            newUsername     = userNameTextbox.Text;
            newPassword     = passwordTextbox.Text;
            reEnterPassword = reEnterPasswordTextbox.Text;
            firstName       = firstNameTextbox.Text;
            lastName        = lastNameTextbox.Text;
            dateOfBirth     = dateOfBirthDatePicker.Text;
            userType        = userTypeCombobox.Text;

            User newUser = new User()
            {
                Username    = newUsername,
                Password    = newPassword,
                FirstName   = firstName,
                SurName     = lastName,
                DateOfBirth = dateOfBirth,
                UserType    = userType
            };

            bool isValid = CheckLoginValid(newPassword, reEnterPassword);

            if (!newUser.CheckEmptyFields())
            {
                MessageBox.Show("All fields must be filled", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (!checkDobValid(dateOfBirth))
            {
                MessageBox.Show("Date of birth is invalid", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (!isValid)
            {
                MessageBox.Show("Username or password is not valid", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                if (CheckSamePassword(newPassword, reEnterPassword))
                {
                    Users users = new Users();
                    users.SaveNewUser(newUser);
                }
                ShowForm.ShowLoginForm(this);
            }
        }
예제 #2
0
        // This is an event listener of login button.
        // This method will load user data and check if username and password are valid.
        private void loginBtn_Click(object sender, EventArgs e)
        {
            User   user     = new User();
            string username = usernameTextbox.Text;
            string password = passwordTextbox.Text;

            Users users = new Users();

            users.LoadData();

            user = users.IsLoginSucceed(username, password);

            if (user != null)
            {
                ShowForm.ShowTextEditorForm(user, this);
            }
            else
            {
                MessageBox.Show("Invalid username or password", "Login Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
예제 #3
0
 // This is an event listener for register button.
 // This method will show registration form.
 private void newUserBtn_Click(object sender, EventArgs e)
 {
     ShowForm.ShowNewUserForm(this);
 }
예제 #4
0
 // This is an event listener of cancel button.
 // This method will hide registration form and go back to login form.
 private void CancelBtn_Click(object sender, EventArgs e)
 {
     ShowForm.ShowLoginForm(this);
 }
예제 #5
0
 // An event listener of logout button to logout from current user
 private void LogoutToolStripMenuItem_Click(object sender, EventArgs e)
 {
     currentUser = null;
     ShowForm.ShowLoginForm(null, this);
 }
예제 #6
0
 // This is an event listener of about button to show an about box
 private void AboutFormEventClick(object sender, EventArgs e)
 {
     ShowForm.ShowAboutBox();
 }