Example #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string role     = txtrole.Text;
            string name     = txtname.Text;
            string email    = txtEmail.Text;
            string password = txtPassword.Text;
            string dob      = txtdob.Text;
            string address  = txtAddress.Text;


            if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(address) &&
                !string.IsNullOrEmpty(dob) && !string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(role) &&
                !string.IsNullOrEmpty(password))
            {
                if (password != "")
                {
                    MemberModel user = new MemberModel();
                    user.Email = email;
                    MemberController userController = new MemberController();
                    Boolean          usernameFound  = userController.CheckUsername(user);
                    if (!usernameFound)
                    {
                        user.Email = email;
                        Boolean emailFound = userController.CheckEmail(user);
                        if (!emailFound)
                        {
                            user.MemberName = name;
                            user.Address    = address;
                            user.Email      = email;
                            user.Role       = role;
                            user.Password   = password;
                            user.Dob        = dob;
                            Boolean userAdded = userController.AddUser(user);
                            if (userAdded)
                            {
                                MessageBox.Show("Member successfully added!");
                                makeFieldsBlank();
                                this.Close();
                            }
                            else
                            {
                                MessageBox.Show("Unable to add member!");
                            }
                        }
                        else
                        {
                            MessageBox.Show("This email already exists!");
                            txtEmail.Focus();
                        }
                    }
                    else
                    {
                        MessageBox.Show("This username is already taken! Enter a different username!");
                        txtEmail.Focus();
                    }
                }
                else
                {
                    MessageBox.Show("Password must be 6 digit!");
                    txtPassword.Focus();
                }
            }
            else
            {
                MessageBox.Show("Please input all the fields!");
            }
        }