⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 forums.cs

📁 微软的.NET论坛的源代码(COOL!!!)
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Web;
using AspNetForums.Components;
using System.Web.UI.WebControls;

namespace AspNetForums {

    // *********************************************************************
    //  Forums
    //
    /// <summary>
    /// This class contains methods for working with the Forums.
    /// </summary>
    /// 
    // ********************************************************************/ 
    public class Forums {

        // *********************************************************************
        //  GetAllButOneForum
        //
        /// <summary>
        /// This method returns a list of all of the forums EXCEPT for the forum
        /// the passed in PostID is from.  This is useful when listing the forums
        /// to move a post awaiting moderation to.
        /// </summary>
        /// <param name="PostID">The Post that belongs to the Forum that we DO NOT want to return.</param>
        /// <returns>A ForumCollection with all of the active forums except for the one specified.</returns>
        /// <remarks>This method is called from the Moderation page, where a post can be moved from
        /// one forum to another.  This method populates the listbox of forums to move the post to: in
        /// essence we want to let the user move the post from its current forum to forum BUT the
        /// forum it exists in.</remarks>
        /// 
        // ********************************************************************/ 
        // TODO: REMOVE?
        /*
        public static ForumCollection GetAllButOneForum(int PostID) {
            ForumCollection forums;

            IWebForumsDataProviderBase dp = DataProvider.Instance();

            forums = dp.GetAllButOneForum(PostID);

            forums.Sort();

            return forums;
        }
        */


        // *********************************************************************
        //  MarkAllThreadsRead
        //
        /// <summary>
        /// Marks all threads in the current forum as read
        /// </summary>
        /// <param name="forumID">Forum to mark threads read for</param>
        /// <param name="username">Username to mark threads read for</param>
        /// 
        // ********************************************************************/ 
        public static void MarkAllThreadsRead(int forumID, string username) {
            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();

            dp.MarkAllThreadsRead(forumID, username);
        }

        // *********************************************************************
        //  GetAllForums
        //
        /// <summary>
        /// Returns all of the active forums in the database.
        /// </summary>
        /// 
        // ********************************************************************/ 
        public static ForumCollection GetAllForums() {
            return GetAllForums(false, null);
        }

        // *********************************************************************
        //  PopulateForumList
        //
        /// <summary>
        /// A listing of forums and forum groups.
        /// </summary>
        /// <param name="username">Username making the request</param>
        /// <param name="listStyle">How the list is to be formatted</param>
        /// 
        // ***********************************************************************/
        public ListItemCollection ForumListItemCollection(string username, ForumListStyle listStyle) {
            return ForumListItemCollection(username, listStyle, null);
        }

        // *********************************************************************
        //  PopulateForumList
        //
        /// <summary>
        /// A listing of forums and forum groups.
        /// </summary>
        /// <param name="username">Username making the request</param>
        /// <param name="listStyle">How the list is to be formatted</param>
        /// 
        // ***********************************************************************/
        public ListItemCollection ForumListItemCollection(string username, ForumListStyle listStyle, ListItemCollection listItems) {

            // Only do this once per request
            if (HttpContext.Current.Items["Moderation-ForumList"] == null) {
                if (listItems == null)
                    listItems = new ListItemCollection();

                ForumGroupCollection forumGroups;
                ForumCollection forumCollection;
                Forums forums = new Forums();

                // Get all forum groups
                forumGroups = ForumGroups.GetAllForumGroups(false, true);
                forumGroups.Sort();

                // Walk through forum groups
                foreach (ForumGroup group in forumGroups) {
                    listItems.Add(new ListItem(group.Name, "g-" + group.ForumGroupID));

                    // Now walk though each forum in the current group
                    forumCollection = forums.GetForumsByForumGroupId(group.ForumGroupID, username);

                    forumCollection.Sort();

                    foreach (Forum forum in forumCollection) {
                        listItems.Add(new ListItem("---" + forum.Name, "f-" + forum.ForumID.ToString()));
                    }
                }

                HttpContext.Current.Items["Moderation-ForumList"] = listItems;

                return listItems;
            } else {
                return (ListItemCollection) HttpContext.Current.Items["Moderation-ForumList"];
            }
        }

        // *********************************************************************
        //  GetAllForums
        //
        /// <summary>
        /// Returns all of the forums in the database.
        /// </summary>
        /// <param name="ShowAllForums">If ShowAllForums is true, ALL forums, active and nonactive,
        /// are returned.  If ShowAllForums is false, just the active forums are returned.</param>
        /// <returns>A ForumCollection with all of the active forums, or all of the active and nonactive
        /// forums, depending on the value of the ShowAllForums property.</returns>
        /// 
        // ***********************************************************************/
        public static ForumCollection GetAllForums(bool showAllForums, string username) {
            ForumCollection forums = null;

            // If the user is anonymous we'll take some load off the database
            if (username == null) {
                if (HttpContext.Current.Cache["ForumCollection-AllForums-Anonymous"] != null)
                    return (ForumCollection) HttpContext.Current.Cache["ForumCollection-AllForums-Anonymous"];
            }

            // Optimize this method to ensure we only ask for the forums once per request
            if (HttpContext.Current.Items["ForumCollection" + showAllForums + username] ==  null) {
                // Create Instance of the IWebForumsDataProviderBase
                IWebForumsDataProviderBase dp = DataProvider.Instance();

                forums = dp.GetAllForums(showAllForums, username);

                // If we have a user add the results to the items collection else add to cache
                if (username == null)
                    HttpContext.Current.Cache.Insert("ForumCollection-AllForums-Anonymous", forums, null, DateTime.Now.AddMinutes(1), TimeSpan.Zero);
                else
                    HttpContext.Current.Items.Add("ForumCollection" + showAllForums + username, forums);

                return forums;
            } else {
                forums = (ForumCollection) HttpContext.Current.Items["ForumCollection" + showAllForums + username];
            }

            return forums;
        }

        
        // *********************************************************************
        //  GetForumsByForumGroupId
        //
        /// <summary>
        /// Used to return a narrow collection of forums that belong to a given forum id.
        /// The username is provied for personalization, e.g. if the user has new
        /// posts in the forum
        /// </summary>
        /// <param name="forumGroupId">Forum Group ID to retrieve forums for</param>
        /// <param name="username">Username making the request</param>
        /// <param name="showAll">Show forums marked as inactive?</param>
        /// 
        // ***********************************************************************/
        public ForumCollection GetForumsByForumGroupId(int forumGroupId, string username, bool showAll) {
            ForumCollection allForums;
            ForumCollection forumsBelongingToGroup = new ForumCollection();

            // First get all the forums
            allForums = GetAllForums(showAll, username);

            // Sort the forums
            allForums.Sort();

            // Find all the forums that belong to the requested forumGroupId
            foreach (Forum f in allForums) {

                if (f.ForumGroupId == forumGroupId)
                    forumsBelongingToGroup.Add(f);

            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -