Esempio n. 1
0
        public ActionResult Register(string name, string password)
        {
            if (string.IsNullOrEmpty(name) || name.Length > 16 || name.Length < 3)
            {
                return(Content("账号密码错误!"));
            }
            if (string.IsNullOrEmpty(password) || password.Length > 16 || password.Length < 6)
            {
                return(Content("账号密码错误!"));
            }
            var user = dal.GetModel(name);

            if (user != null)
            {
                ModelState.AddModelError("name", name + "账号已存在");
                return(View());
            }

            var model = new Models.User();

            model.ID         = dal.GetMaxId() + 1;
            model.name       = name;
            model.password   = password;
            model.Modifytime = DateTime.Now;
            model.AddTime    = DateTime.Now;
            model.status     = 1;
            var isSuccess = dal.Add(model);

            if (isSuccess)
            {
                return(Redirect("/"));
            }
            else
            {
                return(Content("注册失败"));
            }
        }
Esempio n. 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            int er = 0;

            ep.Clear();

            if (txtName.Text == "")
            {
                er++;
                ep.SetError(txtName, "Required");
            }
            if (txtAddress.Text == "")
            {
                er++;
                ep.SetError(txtAddress, "Required");
            }
            if (txtPassword.Text == "")
            {
                er++;
                ep.SetError(txtPassword, "Required");
            }
            if (txtNumber.Text == "")
            {
                er++;
                ep.SetError(txtNumber, "Required");
            }
            if (cmbRole.Text == "")
            {
                er++;
                ep.SetError(cmbRole, "Required");
            }

            if (er > 0)
            {
                return;
            }

            DAL.User user = new DAL.User();
            DAL.Info info = new DAL.Info();

            user.Name        = txtName.Text;
            user.Address     = txtAddress.Text;
            user.PhoneNumber = txtNumber.Text;
            user.Image       = MyControls.FileImage.ImageToByte(user_pic.Image);
            user.Insert();

            info.Password = txtPassword.Text;
            info.Role     = cmbRole.Text;
            user.GetMaxId();
            info.UserId = user.Id;

            if (info.Insert())
            {
                MessageBox.Show("Data Saved");

                //Button btn = (Button)(Myparent.Controls.Find("search", false).First());
                //btn.PerformClick();

                RefreshGrid();

                MyControls.Helper.Clear(this);
                user_pic.Image = null;
                txtName.Focus();
            }
            else
            {
                MessageBox.Show(user.Error + info.Error);
            }
        }