コード例 #1
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            if (!CheckBox1.Checked)
            {
                Response.Write("<script>alert('服务条款未勾选!')</script>");
                return;
            }
            if (!UserNameIselgal || !PwdIselgal || !EmailIselgal)
            {
                return;
            }

            registerUser.UserName = rUserNameText.Text;
            registerUser.Pwd      = rPwdText.Text;
            registerUser.Email    = rEmailText.Text;
            registerUser.Nick     = rNickText.Text == "" || rNickText.Text == "昵称" ? rUserNameText.Text : rNickText.Text;

            //检查是否重名
            try
            {
                if (userBll.ExistsUserName(registerUser.UserName))
                {
                    Response.Write("<script>alert('用户名已存在!')</script>");
                }
                else
                {
                    CanRegister = true;
                }
            }
            catch
            {
                Response.Write("检测重名异常");
            }

            finally
            {
            }
            //注册
            if (CanRegister)
            {
                try
                {
                    if (userBll.Add(registerUser) > 0)
                    {
                        Session["CurrentUser"] = registerUser;
                        Response.Redirect("Home.aspx");
                    }
                }
                catch
                {
                    Response.Write("注册异常");
                }
                finally
                {
                }
            }
        }