public Boolean SaveUser(UserModel user) { StringBuilder strSql = new StringBuilder(); strSql.Append("INSERT INTO users("); strSql.Append("username,password,email,mobile)"); strSql.Append(" VALUES ("); strSql.Append("@in_username,@in_password,@in_email,@in_mobile)"); MySqlParameter[] cmdParms = { new MySqlParameter("@in_username", user.username), new MySqlParameter("@in_password", user.password), new MySqlParameter("@in_email", user.email), new MySqlParameter("@in_mobile", user.tel)}; return MySqlHelper.ExecuteNonQuery(ConstValues.connStr, strSql.ToString(), cmdParms) == 1 ? true : false; }
private string saveUser(HttpContext context) { string username = context.Request.Params.Get("username"); string password = context.Request.Params.Get("password"); string email = context.Request.Params.Get("email"); string tel = context.Request.Params.Get("mobile"); if (StringHelper.IsEmpty(username)) { throw new Exception("用户名不能为空。"); } if (StringHelper.IsEmpty(password)) { throw new Exception("密码不能为空。"); } if (StringHelper.IsEmpty(email)) { throw new Exception("邮箱地址不能为空。"); } if (StringHelper.IsEmpty(tel)) { throw new Exception("手机号不能为空。"); } UserModel user = new UserModel(); user.username = username; user.email = email; user.tel = tel; user.password = password; UserBll userBll = new UserBll(); if (userBll.SaveUser(user)) { return "ok"; } else { throw new Exception("数据库异常,新用户保存失败。"); } }