Exemplo n.º 1
0
 public ActionResult AddRegistration(AccountEntity account)
 {
     if (ModelState.IsValid)
     {
         AccountModel accountModel = new AccountModel();
         string       passXC       = new XCryptEngine(XCryptEngine.AlgorithmType.MD5).Encrypt(account.AccountPass,
                                                                                              "pl");
         account.AccountPass = passXC;
         bool check = accountModel.AddAccount(account);
         if (check == true)
         {
             return(View("~/Views/LoginAccount/LoginForm.cshtml"));
         }
         else
         {
             ViewBag.error = "Error";
             ListRole();
             return(View("~/Views/LoginAccount/RegistrationForm.cshtml"));
         }
     }
     else
     {
         ListRole();
         ViewBag.error = "Error";
         return(View("~/Views/LoginAccount/RegistrationForm.cshtml"));
     }
 }
Exemplo n.º 2
0
        //thêm nhan viên mới
        public void addAccount()
        {
            //khai bao biên cho textbox
            string Username = txtUserName.Text.Trim();
            string name     = txtName.Text.Trim();
            string password = txtPassWord.Text.Trim();


            if (txtUserName.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải Nhập Tên đăng nhập", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtUserName.Focus();
                return;
            }
            //check name

            if (txtName.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải Nhập Tên Nhân Viên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtName.Focus();
                return;
            }
            //Check Password
            if (txtPassWord.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập mật Khẩu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtName.Focus();
                return;
            }
            //check tai khoan tồn tại
            if (AccountModel.CheckKey(Username))
            {
                MessageBox.Show("Tài Khoản Đấ Có vui lòng chọn tài khoản khác", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtUserName.Focus();
                return;
            }

            accountModel.AddAccount(Username, name, password);
            MessageBox.Show("Thêm nhân viên thành công ", "Thông báo");
            txtUserName.Text = "";
            txtName.Text     = "";
            txtPassWord.Text = "";
            txtUserName.Focus();
        }
        public Account HelloAccount(string client_login, string client_pass)
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(ConfigurationManager.
                                                                    ConnectionStrings["DefaultConnection"].ConnectionString))
                {
                    connection.Open();
                    SqlDataReader reader;
                    SqlCommand    command = new SqlCommand();
                    command.CommandText = "SELECT * FROM Accounts";
                    command.Connection  = connection;
                    reader = command.ExecuteReader();

                    AccountModel am = new AccountModel();


                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            Account acc = new Account();
                            acc.Username = reader.GetValue(1).ToString().Trim();
                            acc.Password = reader.GetValue(2).ToString().Trim();
                            am.AddAccount(acc);
                        }
                    }

                    MyValidator validator = new MyValidator();
                    validator.Validate(am, client_login, client_pass);
                }

                return(new Account(client_login, client_pass));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }