public int AddUser(User user) { string cmdText = "INSERT INTO [User](account,passwd,realname,balance,type)VALUES(@account,@passwd,@realname,@balance,@type);SELECT @@identity"; DbParameter[] cmdParameters = { DbHelper.MakeInParam("@account", (DbType)SqlDbType.NChar, 50, user.Account)/**/, DbHelper.MakeInParam("@passwd", (DbType)SqlDbType.NChar, 40, user.Passwd)/**/, DbHelper.MakeInParam("@realname", (DbType)SqlDbType.NChar, 10, user.Realname)/**/, DbHelper.MakeInParam("@balance", (DbType)SqlDbType.Decimal, 0, user.Balance)/**/, DbHelper.MakeInParam("@type", (DbType)SqlDbType.Int, 0, user.Type)/**/ }; string s = DbHelper.ExecuteScalar(CommandType.Text, cmdText, cmdParameters).ToString(); int i = (string.IsNullOrEmpty(s) ? 0 : int.Parse(s)); return i; } public int AddUser(User user, DbTransaction trans) { string cmdText = "INSERT INTO [User](account,passwd,realname,balance,type)VALUES(@account,@passwd,@realname,@balance,@type);SELECT @@identity"; DbParameter[] cmdParameters = { DbHelper.MakeInParam("@account", (DbType)SqlDbType.NChar, 50, user.Account)/**/, DbHelper.MakeInParam("@passwd", (DbType)SqlDbType.NChar, 40, user.Passwd)/**/, DbHelper.MakeInParam("@realname", (DbType)SqlDbType.NChar, 10, user.Realname)/**/, DbHelper.MakeInParam("@balance", (DbType)SqlDbType.Decimal, 0, user.Balance)/**/, DbHelper.MakeInParam("@type", (DbType)SqlDbType.Int, 0, user.Type)/**/ }; string s = DbHelper.ExecuteScalar(trans, CommandType.Text, cmdText, cmdParameters).ToString(); int i = (string.IsNullOrEmpty(s) ? 0 : int.Parse(s)); return i; }
public void handler(IResponder responder) { string isAdmin = SJSRequest.GetString("IsAdmin"); User user = new User(); user.Uid = 0; user.Account = SJSRequest.GetString("Account").Trim(); user.Passwd = SJSRequest.GetString("Passwd"); user.Realname = SJSRequest.GetString("Realname"); user.Balance = 0; user.Type = (isAdmin == "on" ? (int)eAuthority.AdminUser : (int)eAuthority.CommonUser); if (string.IsNullOrEmpty(user.Account)) { responder.WriteErroredMsg("帐号不能为空"); return; } if (string.IsNullOrEmpty(user.Passwd)) { responder.WriteErroredMsg("密码不能为空"); return; } else { user.Passwd = Utils.MD5(user.Passwd); } User confirm = UserManager.GetUser(user.Account); if (confirm != null) { responder.WriteErroredMsg("此用户名已存在!"); return; } user.Uid = UserManager.AddUser(user); if (user.Uid > 0) { responder.WriteSuccessedMsg("新增用户成功!"); } else { responder.WriteErroredMsg("新增用户失败,数据库写入不成功!"); } }
public static int AddUser(User user, DbTransaction trans) { return DatabaseProvider.GetInstance().AddUser(user, trans); }
/// <summary> /// 添加方法 /// </summary> public static int AddUser(User user) { return DatabaseProvider.GetInstance().AddUser(user); }
/// <summary> /// 修改方法 /// </summary> public static int UpdateUser(User user) { return DatabaseProvider.GetInstance().UpdateUser(user); }
public static User GetUser(IDataReader reader) { User model = new User(); model.Uid = (reader["Uid"] is DBNull ? Convert.ToInt32("0") : Convert.ToInt32(reader["Uid"])); model.Account = reader["Account"].ToString(); model.Passwd = reader["Passwd"].ToString(); model.Realname = reader["Realname"].ToString(); model.Balance = (reader["Balance"] is DBNull ? Convert.ToDouble("0") : Convert.ToDouble(reader["Balance"])); model.Enabled = (reader["Enabled"] is DBNull ? Convert.ToBoolean("false") : Convert.ToBoolean(reader["Enabled"])); model.Type = (reader["Type"] is DBNull ? Convert.ToInt32("0") : Convert.ToInt32(reader["Type"])); return model; }
public void handler(IResponder responder) { IList<App> list = AppManager.GetApp(); if (list.Count > 0) { responder.WriteErroredMsg("系统已初始化,请不要重复初始化!"); return; } App app = new App(); app.Isinstall = true; app.Id = AppManager.AddApp(app); if (app.Id <= 0) { responder.WriteErroredMsg("初始化失败,系统写入失败!"); return; } User user = new User(); user.Account = SJSRequest.GetString("Account").Trim(); user.Passwd = SJSRequest.GetString("Passwd"); user.Realname = SJSRequest.GetString("Realname"); user.Balance = 0; user.Type = (int)eAuthority.AdminUser; if (string.IsNullOrEmpty(user.Account)) { responder.WriteErroredMsg("帐号不能为空"); return; } if (string.IsNullOrEmpty(user.Passwd)) { responder.WriteErroredMsg("密码不能为空"); return; } else { user.Passwd = Utils.MD5(user.Passwd); } User confirm = UserManager.GetUser(user.Account); if (confirm != null) { responder.WriteErroredMsg("此用户名已存在!"); return; } user.Uid = UserManager.AddUser(user); if (user.Uid > 0) { LoginAjaxHandler.Logined(user); responder.WriteSuccessedMsg("初始化成功!"); } else { responder.WriteErroredMsg("初始化失败,数据库写入不成功!"); } }