Example #1
0
        // Create Button Click
        private void createUserCreateButton_Click(object sender, EventArgs e)
        {
            // Obtain data from textboxes
            username        = createUserUserNameTextBox.Text;
            password        = createUserPasswordTextBox.Text;
            passwordConfirm = createUserConfirmTextBox.Text;
            creator         = createUserCreatorTextBox.Text;

            // Iterate over controls
            foreach (Control control in Controls)
            {
                // Check if control is empty
                if (String.IsNullOrWhiteSpace(control.Text))
                {
                    // If empty, change background color, display message, and cancel save
                    control.BackColor = Color.Salmon;
                    MessageBox.Show("All fields are required. Please try again.");
                    return;
                }
            }

            // If passwords don't match, show message and cancel save
            if (password != passwordConfirm)
            {
                MessageBox.Show("The password do not match. Please try again.");
                return;
            }

            // Pass data from form to create a new user
            DataInterface.createUser(username, password, 1, creator);
            // Display message confirming user was created
            MessageBox.Show("Successfully created user. Please log in to continue.");
            this.Close();
            loginForm.Show();
        }