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

📄 forumrepeater.cs

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

namespace AspNetForums.Controls {

    [
    ParseChildren(true),
    Designer(typeof(AspNetForums.Controls.Design.ForumRepeaterDesigner))
    ]
    public class ForumRepeater : ForumRepeaterControl {
        bool showAllForums = false;


        // *********************************************************************
        //  HandleDataBindingForForumTitle
        //
        /// <summary>
        /// DataBinding event for the forum title
        /// </summary>
        /// 
        // ********************************************************************/   
        private void HandleDataBindingForForumTitle(Object sender, EventArgs e) {
            HyperLink forumTitle = (HyperLink) sender;
            RepeaterItem container = (RepeaterItem) forumTitle.NamingContainer;

            Forum forum = (Forum) container.DataItem;

            forumTitle.Text = forum.Name;
            forumTitle.NavigateUrl = Globals.UrlShowForum + forum.ForumID;
        }

        // *********************************************************************
        //  HandleDataBindingForForumDescription
        //
        /// <summary>
        /// DataBinding event for the forum description
        /// </summary>
        /// 
        // ********************************************************************/   
        private void HandleDataBindingForForumDescription(Object sender, EventArgs e) {
            Label forumDescription = (Label) sender;
            RepeaterItem container = (RepeaterItem) forumDescription.NamingContainer;

            Forum forum = (Forum) container.DataItem;

            forumDescription.Text = forum.Description;
        }

        // *********************************************************************
        //  HandleDataBindingForTotalThreads
        //
        /// <summary>
        /// DataBinding event for the forum total threads
        /// </summary>
        /// 
        // ********************************************************************/   
        private void HandleDataBindingForTotalThreads(Object sender, EventArgs e) {
            TableCell totalThreads = (TableCell) sender;
            RepeaterItem container = (RepeaterItem) totalThreads.NamingContainer;
            Label label;

            // Create label and set style
            label = new Label();
            label.CssClass = "normalTextSmaller";

            Forum forum = (Forum) container.DataItem;

            if (forum.TotalThreads > 0)
                label.Text = forum.TotalThreads.ToString();
            else
                label.Text = "-";

            totalThreads.Controls.Add(label);

        }

        // *********************************************************************
        //  HandleDataBindingForTotalPosts
        //
        /// <summary>
        /// DataBinding event for the forum total posts
        /// </summary>
        /// 
        // ********************************************************************/   
        private void HandleDataBindingForTotalPosts(Object sender, EventArgs e) {
            TableCell totalPosts = (TableCell) sender;
            RepeaterItem container = (RepeaterItem) totalPosts.NamingContainer;
            Label label;

            Forum forum = (Forum) container.DataItem;

            label = new Label();
            label.CssClass = "normalTextSmaller";

            if (forum.TotalPosts > 0)
                label.Text = forum.TotalPosts.ToString();
            else
                label.Text = "-";

            totalPosts.Controls.Add(label);
        }
        
        // *********************************************************************
        //  HandleDataBindingForMostRecentPost
        //
        /// <summary>
        /// DataBinding event for the forum most recent post
        /// </summary>
        /// 
        // ********************************************************************/   
        private void HandleDataBindingForMostRecentPost(Object sender, EventArgs e) {
            Label postDetails = (Label) sender;
            RepeaterItem container = (RepeaterItem) postDetails.NamingContainer;
            DateTime postDateTime;
            Label postDate = new Label();
            HyperLink newPost = new HyperLink();
            HyperLink author = new HyperLink();
            String dateFormat;

            // Do we have a signed in user?
            if (ForumUser != null)
                dateFormat = ForumUser.DateFormat;
            else
                dateFormat = Globals.DateFormat;

            // Get the forum
            Forum forum = (Forum) container.DataItem;

            // Get the post date
            postDateTime = forum.MostRecentPostDate;

            // Is a user logged in?
            if (ForumUser != null)
                postDateTime = Users.AdjustForTimezone(postDateTime, ForumUser);

            // Did the post occur today?
            if ((postDateTime.DayOfYear == DateTime.Now.DayOfYear) && (postDateTime.Year == DateTime.Now.Year))
                postDate.Text = "<b>Today @ " + postDateTime.ToString(Globals.TimeFormat) + "</b>";
            else if (postDateTime.Year > 0050)
                postDate.Text = postDateTime.ToString(dateFormat + " " + Globals.TimeFormat);
            else
                postDate.Text = "No Posts";

            // Add the post
            postDetails.Controls.Add(postDate);
            
       }

        // *********************************************************************
        //  HandleDataBindingForPostedBy
        //
        /// <summary>
        /// DataBinding event for the forum most recent post by
        /// </summary>
        /// 
        // ********************************************************************/   
        private void HandleDataBindingForPostedBy(Object sender, EventArgs e) {
            HyperLink postedBy = new HyperLink();
            HyperLink newPost = new HyperLink();
            Label label = (Label) sender;
            RepeaterItem container = (RepeaterItem) label.NamingContainer;

            Forum forum = (Forum) container.DataItem;

            // No threads just return
            if (forum.TotalThreads == 0)
                return;

            // Hyper link for author
            postedBy.Text = forum.MostRecentPostAuthor;
            postedBy.NavigateUrl = Globals.UrlUserProfile + forum.MostRecentPostAuthor;

            // Link to new post
            newPost.Text = "<img border=\"0\" src=\"" + Globals.ApplicationVRoot + "/skins/" + Globals.Skin + "/images/icon_mini_topic.gif\">";
            newPost.NavigateUrl = Globals.UrlShowPost + forum.MostRecentThreadId + "#" + forum.MostRecentPostId;

            label.Controls.Add(new LiteralControl("by "));
            label.Controls.Add(postedBy);
            label.Controls.Add(newPost);
            
        }


        // *********************************************************************
        //  HandleDataBindingForStatusImage
        //
        /// <summary>
        /// DataBinding event for the image used to indicate if there are new posts
        /// </summary>
        /// 
        // ********************************************************************/   
        private void HandleDataBindingForStatusImage(Object sender, EventArgs e) {
            Image img = (Image) sender;
            RepeaterItem container = (RepeaterItem) img.NamingContainer;

            Forum forum = (Forum) container.DataItem;

            if (ForumUser == null) {
                img.ImageUrl = Globals.ApplicationVRoot + "/skins/" + SiteStyle + "/images/forum_status.gif";
            } else {
    
                // Is this a private forum?
                if (forum.IsPrivate) {

                    if (forum.LastUserActivity < forum.MostRecentPostDate) {
                        img.ImageUrl = Globals.ApplicationVRoot + "/skins/" + SiteStyle + "/images/forum_private_newposts.gif";
                        img.AlternateText = "Private Forums - New Posts";
                    } else {
                        img.ImageUrl = Globals.ApplicationVRoot + "/skins/" + SiteStyle + "/images/forum_private.gif";
                        img.AlternateText = "Private Forums";
                    }
                         
                } else {
                    if (forum.LastUserActivity < forum.MostRecentPostDate) {
                        img.ImageUrl = Globals.ApplicationVRoot + "/skins/" + SiteStyle + "/images/forum_status_new.gif";
                        img.AlternateText = "New Posts";

⌨️ 快捷键说明

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