예제 #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string userName = txtName.Text.Trim();

            if (string.IsNullOrEmpty(userName))
            {
                AlertBack("请输入用户名");
                return;
            }
            if (userName.Length < 6)
            {
                AlertBack("用户名的长度不能小于6个字符");
                return;
            }
            if (string.IsNullOrEmpty(TxtTrueName.Text.Trim()))
            {
                AlertBack("请输入真实姓名");
                return;
            }
            User user = new User()
            {
                ID            = UserID,
                Account       = userName,
                TrueName      = TxtTrueName.Text.Trim(),
                AccountType   = (UserTypeOptions)Convert.ToInt32(rblType.SelectedValue),
                Status        = (StatusOptions)Convert.ToInt32(rblStatus.SelectedValue),
                BeginTime     = Convert.ToDateTime(beginTime.Text),
                EndTime       = Convert.ToDateTime(endTime.Text),
                IsSpecialUser = ckbspecialuser.Checked,
                Email         = txtemail.Text.Trim(),
                IsWhiteUser   = chbwhiteuser.Checked,
                Department    = txtDept.Text.Trim()
            };

            try
            {
                //添加
                if (UserID == 0)
                {
                    biService.AddUser(user);
                    Response.Redirect(ReturnUrl);
                }
                else  //修改
                {
                    biService.UpdateUser(user);
                    Response.Redirect(ReturnUrl);
                }
            }
            catch (NotRightException)
            {
                AlertBack("您没有权限执行此操作");
            }
            catch (net91com.Core.ToUserException ex)
            {
                AlertBack(ex.Message);
            }
        }