Exemple #1
0
        private void btnCreateAccount_Click(object sender, EventArgs e)
        {
            try
            {
                string userName        = txtUsername.Text;
                string password        = txtPassword.Text;
                string fullName        = txtName.Text;
                bool   checkedUsername = accountData.checkedAvailable1(userName);
                bool   checkedPassword = accountData.checkedAvailable1(password);
                bool   checkedFullName = accountData.checkedAvailable2(fullName);

                if (!userName.Equals("") && !password.Equals("") && !fullName.Equals(""))
                {
                    if (checkedUsername == true && checkedPassword == true && checkedFullName == true)
                    {
                        Account addNew = new Account(userName, password, fullName);

                        if (accountData.AddNewAccount(addNew))
                        {
                            getAllAccounts();
                            MessageBox.Show("Added successfully");
                        }
                        else
                        {
                            MessageBox.Show("Add fail");
                        }
                        txtName.Enabled          = false;
                        txtPassword.Enabled      = false;
                        txtUsername.Enabled      = false;
                        btnCreateAccount.Enabled = false;
                    }
                    else
                    {
                        MessageBox.Show("Username is about chars and number, and Password is about chars and number, and Full name is only chars!!");
                    }
                }
                else
                {
                    MessageBox.Show("Username or Password or Full name is blank");
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("UNIQUE KEY"))
                {
                    MessageBox.Show("This account is existed");
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Exemple #2
0
        public RedirectToRouteResult AddNewAccount(FormCollection frmcol)
        {
            string fullname = frmcol["first_name"] + " " + frmcol["last_name"];
            string username = frmcol["username"];
            string password = frmcol["password"];
            string phone    = frmcol["phone"];
            string email    = frmcol["email"];

            if (ac.AddNewAccount(username, password, fullname, phone, email))
            {
                ViewBag.Message = "User " + username + " create account successfully";
                ViewBag.Title   = "Homeeeee";
            }
            else
            {
                ViewBag.Message  = "User " + username + " create account fail";
                ViewBag.UserName = username;
                ViewBag.Title    = "Homeeeee";
            }

            return(RedirectToAction("Index", "Login"));
        }