protected void btnRegister_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid)
        {
            return;
        }

        string strUserName = txtUserName.Text.Trim();
        string strPassword = txtPassword.Text.Trim();
        string strEmail = txtEmail.Text.Trim();
        string strPhoneNumber = txtPhoneNumber.Text.Trim();

        XContactModel.User user = new XContactModel.User();
        user.UserName = strUserName;
        user.Password = strPassword;
        user.Email = strEmail;
        user.PhoneNumber = strPhoneNumber;

        if (isUserNameAlreadyExsit(strUserName))
        {
            Jinhaoxia.Util.AlterMessage.ShowMessage(this.Page, "用户名已存在!");
            return;
        }

        db.AddToUsers(user);

        if (db.SaveChanges() > 0)
        {
            Jinhaoxia.Util.AlterMessage.ShowMessageAndGoLocation(this.Page, "注册成功!", "Login.aspx");
        }
        else
        {
            Jinhaoxia.Util.AlterMessage.ShowMessage(this.Page, "注册失败");
        }
    }
 /// <summary>
 /// 创建新的 User 对象。
 /// </summary>
 /// <param name="userID">UserID 属性的初始值。</param>
 /// <param name="userName">UserName 属性的初始值。</param>
 /// <param name="password">Password 属性的初始值。</param>
 public static User CreateUser(global::System.Int32 userID, global::System.String userName, global::System.String password)
 {
     User user = new User();
     user.UserID = userID;
     user.UserName = userName;
     user.Password = password;
     return user;
 }
 /// <summary>
 /// 用于向 Users EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddToUsers(User user)
 {
     base.AddObject("Users", user);
 }