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

📄 postflatview.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
📖 第 1 页 / 共 2 页
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

using CommunityServer.Components;
using CommunityServer.Controls;
using CommunityServer.Discussions.Components;

namespace CommunityServer.Discussions.Controls 
{

    // *********************************************************************
    //  PostFlatView
    //
    /// <summary>
    /// This server control is used to display top level threads. Note, a thread
    /// is a post with more information. The Thread class inherits from the Post
    /// class.
    /// </summary>
    /// 
    // ********************************************************************/
    public class PostFlatView : TemplatedWebControl 
    {

        CSContext csContext;
        ForumPost post;
        Forum forum;
        ForumPermission permission;
		Forum reportForum;
        User user;
        bool siteEnableUserPostingAsAnonymous = false;
        bool forumEnableUserPostingAsAnonymous = false;

        protected override void OnInit(EventArgs e) {

			if (SkinName == null)                
				ExternalSkinFileName = "View-PostFlatView.ascx";
			else 
				ExternalSkinFileName = SkinName;


            this.csContext = CSContext.Current;
            this.user = csContext.User;
            this.post = Posts.GetPost( csContext.PostID, user.UserID, true );

            // Are we looking up the forum by forum id or post id
            //
            if (csContext.ForumID > 0) 
            {
                forum = Forums.GetForum(csContext.ForumID, true, true, CSContext.Current.User.UserID);
            } 
            else if (csContext.PostID > 0) 
            {
                forum = Forums.GetForumByPostID(csContext.PostID, CSContext.Current.User.UserID, true );
            }

            if (forum == null) 
            {
                PermissionBase.RedirectOrExcpetion(CSExceptionType.SectionNotFound, csContext.ForumID.ToString());
            }
        
			//Get the report forum
			reportForum = Forums.GetReportedForum();

            // Get site and forum settings if users may post as anonymous.
            //
            siteEnableUserPostingAsAnonymous = CSContext.Current.SiteSettings.EnableUserPostingAsAnonymous;
            forumEnableUserPostingAsAnonymous = forum.EnableAnonymousPostingForUsers;

            permission = forum.ResolvePermission( user ) as ForumPermission;

            if( !permission.Read )
                throw new CSException( CSExceptionType.AccessDenied );

            base.OnInit(e);
        }

        protected override void OnLoad(EventArgs e) 
        {
            if ( !Page.IsPostBack || !EnableViewState ) 
            {
                DataBind();
            }
            base.OnLoad(e);
        }


        #region Child Controls

        Repeater postRepeater;
        Pager pager;
        RatePost ratePost;
        CurrentPage currentPage;
        RequiredFieldValidator postBodyValidator;
        ForumImageButton prevThread;
        ForumImageButton nextThread;
        Label forumName;
        Label postSubject;
        ForumImageButton newPostButtonUp;
        ForumImageButton newPostButtonDown;
        Label threadStats;
        PlaceHolder pagingArea;
		DropDownList sortOrder;
        //StatusDropDownList threadStatus;

        #endregion

        #region Skin

        protected override void AttachChildControls() 
        {

            postRepeater = (Repeater)FindControl( "PostRepeater" );
            pager = (Pager)FindControl( "Pager" );
            ratePost = (RatePost)FindControl( "RatePost" );
            currentPage = (CurrentPage)FindControl( "CurrentPage" );
            postBodyValidator = (RequiredFieldValidator)FindControl( "PostBodyValidator" );
            prevThread = (ForumImageButton)FindControl( "PrevThread" );
            nextThread = (ForumImageButton)FindControl( "NextThread" );
            forumName = (Label)FindControl( "ForumName" );
            postSubject = (Label)FindControl( "PostSubject" );
            newPostButtonUp = (ForumImageButton)FindControl("NewPostButtonUp");
            newPostButtonDown = (ForumImageButton)FindControl("NewPostButtonDown");
            threadStats = (Label)FindControl("ThreadStats");
            pagingArea = (PlaceHolder)FindControl( "PagingArea" );
			sortOrder = (DropDownList)FindControl( "SortOrder" );
            //threadStatus = (StatusDropDownList) FindControl( "ThreadStatus" );

            InitializeChildControls();
        }

        private void InitializeChildControls() 
        {
            sortOrder.Items.FindByValue( ((int)this.user.PostSortOrder).ToString() ).Selected = true;

            postRepeater.ItemDataBound += new RepeaterItemEventHandler(postRepeater_ItemDataBound);
        }


        #endregion

        #region Event Handlers

		private void ModerationMenu_PostModerateRefresh (object sender, EventArgs e)
		{
			Posts.ClearPosts(csContext.PostID, pager.PageIndex, pager.PageSize, 0, 0);
			HttpContext.Current.Response.Redirect(HttpContext.Current.Request.Url.ToString(), true);
		}

        public void ThreadStatus_Changed (object sender, ThreadStatusEventArgs e) {
            if (e.ThreadID <= 0)
                return;

            Threads.UpdateThreadStatus( e.ThreadID, e.Status );
        }

        #endregion

        #region DataBinding
        public override void DataBind() 
        {
            base.DataBind();

            #region prev/next thread navigation
			
            if ( this.prevThread != null) 
            {
                if (post.ThreadIDPrev > 0) 
                {
                    prevThread.NavigateUrl = Globals.GetSiteUrls().Post(post.ThreadIDPrev);
                } 
                else 
                {
                    prevThread.Visible = false;
                }
            }

            if ( this.nextThread != null) 
            {
                if (post.ThreadIDNext > 0) 
                {
                    nextThread.NavigateUrl = Globals.GetSiteUrls().Post(post.ThreadIDNext);
                } 
                else 
                {
                    nextThread.Visible = false;
                }
            }

            #endregion

            if (ratePost != null) 
            {
                ratePost.Post = this.post;
            }

			if (forumName != null)
				forumName.Text = forum.Name;

			if (postSubject != null)
				postSubject.Text = post.Subject;

            // Get a populated thread set
            //
            PostSet postSet = Posts.GetPosts(csContext.PostID, pager.PageIndex, pager.PageSize, 0, Int32.Parse(sortOrder.SelectedValue));

            postRepeater.DataSource = postSet.Posts;
            postRepeater.DataBind();

            pager.TotalRecords = currentPage.TotalRecords = postSet.TotalRecords;
			pager.UrlPattern = SiteUrls.Instance().PostPagedFormat(csContext.PostID);
            currentPage.TotalPages = pager.CalculateTotalPages();
            currentPage.PageIndex = pager.PageIndex;

			if (pagingArea != null)
				pagingArea.Visible = ( currentPage.TotalPages > 1 );


            #region Post/Reply Permissions
				
            if (newPostButtonUp != null) 
            {
                newPostButtonUp.Visible = UserCanPost();
            }

            if (newPostButtonDown != null) 
            {
                newPostButtonDown.Visible = UserCanPost();
            }

            #endregion

⌨️ 快捷键说明

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