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 (ToyStoreEntities context = new ToyStoreEntities()) { var query = from userInfo in context.Users where userInfo.UserName == TextBox1.Text select userInfo; if (query.Count() != 0) { Response.Write("<script> alert( '注册失败') </script> "); return; } else { User newUser = new User(); newUser.UserName = TextBox1.Text; newUser.Password = TextBox2.Text; newUser.PhoneNumber = TextBox3.Text; if (Request.QueryString["Admin"] == "1") { newUser.IsAdmin = UserType.Admin; } else { newUser.IsAdmin = UserType.RegUser; } context.AddToUsers(newUser); context.SaveChanges(); Response.Write("<script> alert( '注册成功');window.location.href = 'Default.aspx';</script>"); } } } }
/// <summary> /// Deprecated Method for adding a new object to the Users EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToUsers(User user) { base.AddObject("Users", user); }
/// <summary> /// Create a new User object. /// </summary> /// <param name="userName">Initial value of the UserName property.</param> /// <param name="password">Initial value of the Password property.</param> /// <param name="isAdmin">Initial value of the IsAdmin property.</param> public static User CreateUser(global::System.String userName, global::System.String password, global::System.Int32 isAdmin) { User user = new User(); user.UserName = userName; user.Password = password; user.IsAdmin = isAdmin; return user; }