Exemple #1
0
        public static UserState GetUserStateById(int id)
        {
            const string sql = @"SELECT * FROM UserStates WHERE Id = @id";

            try
            {
                SqlDataReader reader = SqlDBHelper.GetReader(sql, new SqlParameter("@Id", id));
                if (reader.Read())
                {
                    UserState userState = new UserState();
                    userState.id   = (int)reader["Id"];
                    userState.name = (string)reader["Name"];
                    reader.Close();
                    return(userState);
                }
                else
                {
                    reader.Close();
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Log.WriteLog(new Error("数据库业务错误", "获取数据失败", ex));
                return(null);
            }
        }
        /// <summary>
        /// 根据ID 查询用户当前的角色
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static UserRole GetUserRoleById(int id)
        {
            const string  sql    = "SELECT * FROM UserRoles WHERE Id = @Id";
            SqlDataReader reader = SqlDBHelper.GetReader(sql, new SqlParameter("@Id", id));

            return(GetUserRole(reader));
        }
        /// <summary>
        /// 根据编号获取用户信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static User GetUserById(int id)
        {
            const string sql = "SELECT * FROM Users WHERE Id = @Id";

            using (SqlDataReader reader = SqlDBHelper.GetReader(sql, new SqlParameter("@Id", id)))
                return(GetReaderUser(reader));
        }
        /// <summary>
        /// 感觉留言板Id获取分类
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static MessageBoardCategories GetMessageBoradCategories(int id)
        {
            const string  sql    = "SELECT * FROM MessageBoardCategories WHERE CategoriesId = @Id";
            SqlDataReader reader = SqlDBHelper.GetReader(sql, new SqlParameter("@Id", id));

            return(MBCFactory(reader));
        }
        /// <summary>
        /// 根据登录账号获取用户信息
        /// </summary>
        /// <param name="loginId"></param>
        /// <returns></returns>
        public static User GetUserByLoginId(string loginId)
        {
            const string sql = "SELECT * FROM Users WHERE LoginId = @LoginId";

            using (SqlDataReader reader = SqlDBHelper.GetReader(sql, new SqlParameter("@LoginId", loginId)))
                return(GetReaderUser(reader));
        }