Ejemplo n.º 1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text.Length == 0
                || TextBox2.Text.Length == 0
                || TextBox3.Text.Length == 0
                || TextBox4.Text.Length == 0
                || TextBox2.Text != TextBox3.Text)
            {
                Response.Write("<script> alert( '注册失败') </script> ");
                return;
            }
            else
            {
                //检查用户名是否存在
                using (LiBoClothesShopEntities context = new LiBoClothesShopEntities())
                {
                    var query = from userInfo in context.UserInfoes
                                where userInfo.UserName == TextBox1.Text
                                select userInfo;
                    if (query.Count() != 0)
                    {
                        Response.Write("<script> alert( '注册失败') </script> ");
                        return;
                    }
                    else
                    {
                        UserInfo newUser = new UserInfo();
                        newUser.UserName = TextBox1.Text;
                        newUser.Password = TextBox2.Text;
                        newUser.Phone = TextBox3.Text;
                        if (Convert.ToInt32(Request.QueryString["Type"]) == 2)
                        {
                            newUser.IsAdmin = true;
                        }
                        else
                        {
                            newUser.IsAdmin = false;
                        }

                        context.AddToUserInfoes(newUser);
                        context.SaveChanges();
                        Response.Write("<script> alert( '注册成功');window.location.href = 'Default.aspx';</script>");
                    }
                }
            }
        }