/// <summary> /// 根据登录账号获取用户信息 /// </summary> /// <param name="account"></param> /// <returns></returns> public Madminuser GetMadminuserModelByAcount(string account) { //// sql语句 string sql = " SELECT adminuserid,account,name,password,sex,isDelete,isEffective,great_time,modify_time " + "FROM adminuser where account=?account limit 1"; List <MySqlParameter> parameterList = new List <MySqlParameter>(); MySqlParameter parameter = new MySqlParameter("?account", MySqlDbType.VarChar, 50); parameter.Value = account; parameterList.Add(parameter); using (MySqlDataReader sqlDataReader = PKMySqlHelper.ExecuteReader(sql, parameterList.ToArray())) { if (sqlDataReader != null && sqlDataReader.Read()) { Madminuser model = new Madminuser(); model.adminuserid = sqlDataReader["adminuserid"] != DBNull.Value ? sqlDataReader["adminuserid"].ToString() : string.Empty; model.account = sqlDataReader["account"] != DBNull.Value ? sqlDataReader["account"].ToString() : string.Empty; model.name = sqlDataReader["name"] != DBNull.Value ? sqlDataReader["name"].ToString() : string.Empty; model.password = sqlDataReader["password"] != DBNull.Value ? sqlDataReader["password"].ToString() : string.Empty; model.sex = sqlDataReader["sex"] != DBNull.Value ? Convert.ToInt32(sqlDataReader["sex"].ToString()) : 0; model.great_time = sqlDataReader["great_time"] != DBNull.Value ? Convert.ToDateTime(sqlDataReader["great_time"].ToString()) : DateTime.MinValue; model.modify_time = sqlDataReader["modify_time"] != DBNull.Value ? Convert.ToDateTime(sqlDataReader["modify_time"].ToString()) : DateTime.MinValue; return(model); } } return(null); }
/// <summary> /// 新增平台用户 /// </summary> /// <param name="madminuser"></param> /// <returns></returns> public string AddUserMeth(Madminuser madminuser) { if (!base.CheckIsLogin()) { return("-1"); } return(new AdminUserBus().AddUserMeth(madminuser)); }
/// <summary> /// 分页获取管理严用户信息 /// </summary> /// <param name="pagIndex">页码(第一页从1 开始)</param> /// <param name="pagCount">每页数据条数</param> /// <returns></returns> public List <Madminuser> GetAdminUserInfoPagList(int pagIndex, int pagCount, string acount, string name) { // 查询条件 StringBuilder sqlWhere = new StringBuilder(" 1=1 "); if (!string.IsNullOrEmpty(acount)) { sqlWhere.Append(" and account like CONCAT('%',?account,'%')"); } if (!string.IsNullOrEmpty(name)) { sqlWhere.Append(" and name like CONCAT('%',?name,'%')"); } string sql = " SELECT adminuserid,account,name,password,sex,isDelete,isEffective,great_time,modify_time " + $" FROM adminuser WHERE {sqlWhere.ToString()} ORDER BY 1 desc limit {((pagIndex - 1) * pagCount)}, {pagCount}; "; List <MySqlParameter> parameterList = new List <MySqlParameter>(); MySqlParameter parameter = new MySqlParameter("?acount", MySqlDbType.VarChar, 50); parameter.Value = "%" + acount + "%"; parameterList.Add(parameter); parameter = new MySqlParameter("?name", MySqlDbType.VarChar, 50); parameter.Value = "%" + name + "%"; parameterList.Add(parameter); List <Madminuser> listModel = null; using (MySqlDataReader sqlDataReader = PKMySqlHelper.ExecuteReader(sql, parameterList.ToArray())) { if (sqlDataReader != null) { listModel = new List <Madminuser>(); while (sqlDataReader.Read()) { Madminuser model = new Madminuser(); model.adminuserid = sqlDataReader["adminuserid"] != DBNull.Value ? sqlDataReader["adminuserid"].ToString() : string.Empty; model.account = sqlDataReader["account"] != DBNull.Value ? sqlDataReader["account"].ToString() : string.Empty; model.name = sqlDataReader["name"] != DBNull.Value ? sqlDataReader["name"].ToString() : string.Empty; //// model.password = sqlDataReader["password"] != DBNull.Value ? sqlDataReader["password"].ToString() : string.Empty; model.sex = sqlDataReader["sex"] != DBNull.Value ? Convert.ToInt32(sqlDataReader["sex"].ToString()) : 0; model.great_time = sqlDataReader["great_time"] != DBNull.Value ? Convert.ToDateTime(sqlDataReader["great_time"].ToString()) : DateTime.MinValue; model.modify_time = sqlDataReader["modify_time"] != DBNull.Value ? Convert.ToDateTime(sqlDataReader["modify_time"].ToString()) : DateTime.MinValue; model.greatTime = model.great_time.ToString("yyyy-MM-dd HH:mm:ss"); listModel.Add(model); } } } return(listModel); }
/// <summary> /// 新增管理员 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool AddAdminUser(Madminuser model) { //// sql语句 string sql = "INSERT INTO adminuser (adminuserid,account,name,password,sex,isDelete,isEffective,great_time,modify_time) " + "VALUES(?adminuserid, ?account, ?name, ?password, ?sex, ?isDelete, ?isEffective, ?great_time, ?modify_time)"; List <MySqlParameter> parameterList = new List <MySqlParameter>(); MySqlParameter parameter = new MySqlParameter("?adminuserid", MySqlDbType.VarChar, 25); parameter.Value = model.adminuserid; parameterList.Add(parameter); parameter = new MySqlParameter("?account", MySqlDbType.VarChar, 50); parameter.Value = model.account; parameterList.Add(parameter); parameter = new MySqlParameter("?name", MySqlDbType.VarChar, 50); parameter.Value = model.name; parameterList.Add(parameter); parameter = new MySqlParameter("?password", MySqlDbType.VarChar, 50); parameter.Value = model.password; parameterList.Add(parameter); parameter = new MySqlParameter("?sex", MySqlDbType.Int16, 1); parameter.Value = model.sex; parameterList.Add(parameter); parameter = new MySqlParameter("?isDelete", MySqlDbType.Int16, 1); parameter.Value = model.isDelete; parameterList.Add(parameter); parameter = new MySqlParameter("?isEffective", MySqlDbType.Int16, 1); parameter.Value = model.isEffective; parameterList.Add(parameter); DateTime dateTime = System.DateTime.Now; parameter = new MySqlParameter("?great_time", MySqlDbType.DateTime); parameter.Value = dateTime; parameterList.Add(parameter); parameter = new MySqlParameter("?modify_time", MySqlDbType.DateTime); parameter.Value = dateTime; parameterList.Add(parameter); //// 执行操作 return(PKMySqlHelper.ExecuteNonQuery(sql, parameterList.ToArray()) > 0); }
/// <summary> /// 新增平台用户 /// </summary> /// <param name="madminuser"></param> /// <returns></returns> public string AddUserMeth(Madminuser madminuser) { MwxResult mwxResult = new MwxResult() { errcode = -1 }; try { //// 数据合法性检查 string checkAdminUser = this.CheckAdminUser(madminuser); if (!string.IsNullOrEmpty(checkAdminUser)) { mwxResult.errmsg = checkAdminUser; } //// 时间相关参数赋值 madminuser.great_time = System.DateTime.Now; madminuser.modify_time = madminuser.great_time; madminuser.adminuserid = PublicTools.GetRandomNumberByTime(); madminuser.isEffective = 1; madminuser.password = PublicTools.MD5CryptoService(madminuser.password); //// 数据落地入库 if (!new AdminuserService().AddAdminUser(madminuser)) { mwxResult.errmsg = "操作失败"; } else { mwxResult.errcode = 0; mwxResult.errmsg = "操作成功"; } } catch (Exception ex) { mwxResult.errmsg = "操作失败:系统异常!"; } return(JsonHelper.GetJson <MwxResult>(mwxResult)); }
/// <summary> /// 修改用户信息 /// </summary> /// <param name="model">model</param> /// <returns></returns> public bool ChangAdminUserInfor(Madminuser model) { //// sql语句 string sql = "update adminuser set name = ?name,sex=?sex where adminuserid = ?adminuserid"; List <MySqlParameter> parameterList = new List <MySqlParameter>(); MySqlParameter parameter = new MySqlParameter("?name", MySqlDbType.VarChar, 50); parameter.Value = model.name; parameterList.Add(parameter); parameter = new MySqlParameter("?sex", MySqlDbType.Int16, 1); parameter.Value = model.sex; parameterList.Add(parameter); parameter = new MySqlParameter("?adminuserid", MySqlDbType.VarChar, 25); parameter.Value = model.adminuserid; parameterList.Add(parameter); //// 执行操作 return(PKMySqlHelper.ExecuteNonQuery(sql, parameterList.ToArray()) > 0); }
/// <summary> /// 检查新增用户的合法性 /// </summary> /// <param name="madminuser"></param> /// <returns></returns> private string CheckAdminUser(Madminuser madminuser) { if (madminuser == null) { return("操作失败:用户信息不能为空!"); } if (string.IsNullOrEmpty(madminuser.account)) { return("操作失败:账号不能为空!"); } if (!PublicTools.CheckIsNumOrLetter(madminuser.account)) { return("操作失败:账号只能由数字和字母组成!"); } if (string.IsNullOrEmpty(madminuser.name)) { return("操作失败:姓名不能为空!"); } return(string.Empty); }
/// <summary> /// 修改用户信息 /// </summary> /// <param name="model">model</param> /// <returns></returns> public bool ChangAdminUserInfor(Madminuser model) { return(opertService.ChangAdminUserInfor(model)); }
/// <summary> /// 新增管理员 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool AddAdminUser(Madminuser model) { return(opertService.AddAdminUser(model)); }