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

📄 createeditblogpost.cs

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

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

using CommunityServer.Blogs.Components;
using CommunityServer.Components;
using CommunityServer.Controls;

namespace CommunityServer.Blogs.Controls 
{

    /// <summary>
    /// Enables creating and editing WeblogPosts
    /// </summary>
    public class CreateEditBlogPost : WeblogAdminTemplatedWebControl 
    {

        #region Member Variables
        CSContext csContext   = CSContext.Current;
        WeblogPost currentPost = null;

       
        #endregion

        #region CreateEditBlogPost Constructor
        /// <remarks>
        /// Class contructor used to determine the mode of the server control.
        /// </remarks>
        public CreateEditBlogPost() 
        {
			CSEvents.AuthorizePost();

            if(csContext.PostID > 0)
            {
            	currentPost = WeblogPosts.GetPost(csContext.PostID,true,false,false);
            }

            if(currentPost == null)
            {
                PostMode = CreateEditPostMode.NewPost;
                this.BlogPostType = (BlogPostType)Enum.Parse(typeof(BlogPostType),Context.Request.QueryString["BPT"],true);
            }
            else
            {
                PostMode = CreateEditPostMode.EditPost;
                this.BlogPostType = currentPost.BlogPostType;
            }
        }
        #endregion

		protected override void OnInit(EventArgs e)
		{
//			ConfirmationPage cp = Page as ConfirmationPage;
//			if(cp != null)
//				cp.IsInEdit = true;

			base.OnInit (e);
		}



        protected override void AttachChildControls()
        {
            EditorView();
            DisplayPreview();
            
        }

        private string DateToString(DateTime dt)
        {
            return dt.ToShortDateString() + " " + dt.ToShortTimeString();
        }


        #region WireUp the editor
   
        /***********************************************************************
        // EditorView
        //
        /// <remarks>
        /// When a CurrentUser replies to a post, the CurrentUser control that controls the UI
        /// is loaded and passed to this method. Elements of the form are then wired
        /// up to handle events, such as button clicks
        /// </remarks>
        /// <param name="control">Usercontrol used to control UI formatting</param>
        ***********************************************************************/
		private void EditorView() 
		{
            
			Editor editor = null;


			editor =  FindControl("PostBody") as Editor;
			if(editor != null)
				editor.EnableHtmlModeEditing = true; //should this be a permission?

			CheckBoxList categoryList = FindControl("CategoryList") as CheckBoxList;
			if(categoryList != null)
			{
				CategoryType ct = (this.BlogPostType == BlogPostType.Post) ? CategoryType.BlogPost : CategoryType.BlogArticle;
				ArrayList categories = PostCategories.GetCategories(CurrentWeblog.SectionID,ct,true,true);
				foreach(PostCategory c in categories)
				{
					categoryList.Items.Add(new ListItem(c.Name,c.Name));
				}
			}


			RegularExpressionValidator vRegexPostName = FindControl("vRegexPostName") as RegularExpressionValidator;
			vRegexPostName.Text = ResourceManager.GetString("Weblog_CreateEditBlogPost_PostNameRegexValidator");
			vRegexPostName.ValidationExpression = WeblogPosts.PostNamePattern;



			TextBox postDate = FindControl("postdate") as TextBox;
            
			BlogPostConfig pc = currentPost != null ? currentPost.PostConfig : BlogPostConfig.IsAggregated  | BlogPostConfig.IsCommunityAggregated;
                
			CommentModerationDropDownList ModerationDDL = (CommentModerationDropDownList)FindControl("ModerationDDL");
			if(currentPost == null)
			{
				SetYesNo(pc,true,true,CurrentUser.EnableThreadTracking,CurrentWeblog.EnableRatings,CurrentWeblog.EnableTrackbacks);

				ModerationDDL.Items.FindByValue(CurrentWeblog.ModerationType.ToString()).Selected = true;
				if(postDate != null)
				{
					postDate.Text = DateToString(UserTime.CurrentUserTime);
				}
			}
			else
			{
				SetYesNo(pc,currentPost.IsApproved,!currentPost.IsLocked,currentPost.IsTracked,currentPost.EnableRatings,currentPost.EnableTrackBacks);
				TextBox postSubject = FindControl("PostSubject") as TextBox;
				if(postSubject != null)
					postSubject.Text = Globals.HtmlDecode(currentPost.Subject);

				TextBox postName = FindControl("postName") as TextBox;
				if(postName != null)
					postName.Text = currentPost.HasName ? Globals.UrlDecode(currentPost.Name).Replace("_", " ") : string.Empty;

				TextBox postExcerpt = FindControl("postExcerpt") as TextBox;
				if(postExcerpt != null)
					postExcerpt.Text = currentPost.Excerpt;

				ModerationDDL.Items.FindByValue(currentPost.ModerationType.ToString()).Selected = true;

                
				if(postDate != null)
				{
					postDate.Text = DateToString(currentPost.BloggerTime);
				}

				if(editor != null)
					editor.Text = currentPost.Body;

				RadioButtonList postIcon =   FindControl("PostIcon") as RadioButtonList;
				if(postIcon != null)
				{
					ListItem li = postIcon.Items.FindByValue(currentPost.EmoticonID.ToString());
					if(li != null)
						li.Selected = true;
				}

				if(categoryList != null && currentPost.HasCategories)
				{
					foreach(string cat in currentPost.Categories)
					{
						ListItem li = categoryList.Items.FindByValue(cat);
						if(li != null)
							li.Selected = true;
					}
				}
                
			}

			//EnableSticky();

			Button prevButton = (Button) FindControl("PreviewButton");
			prevButton.Text = ResourceManager.GetString("CreateEditPost_PreviewButton");
			prevButton.Click += new System.EventHandler(PreviewButton_Click);
			OverideConfirmation(prevButton);
				
                
			Button postButton = (Button) FindControl("PostButton");
			postButton.Text = ResourceManager.GetString("CreateEditPost_PostButton");
			postButton.Click  += new System.EventHandler(PostButton_Click);
			OverideConfirmation(postButton);

			Button cancelButton = (Button) FindControl("Cancel");
			cancelButton.Text = ResourceManager.GetString("CreateEditPost_Cancel");
			cancelButton.Click += new System.EventHandler(CancelButton_Click);
			OverideConfirmation(cancelButton);

			//We have a second set of buttons in the advanced option section
            
			Button prevButton2 = (Button) FindControl("PreviewButton2");
			prevButton2.Text = ResourceManager.GetString("CreateEditPost_PreviewButton");
			prevButton2.Click += new System.EventHandler(PreviewButton_Click);
			OverideConfirmation(prevButton2);
                
			Button postButton2 = (Button) FindControl("PostButton2");
			postButton2.Text = ResourceManager.GetString("CreateEditPost_PostButton");
			postButton2.Click  += new System.EventHandler(PostButton_Click);
			OverideConfirmation(postButton2);

			Button cancelButton2 = (Button) FindControl("Cancel2");
			cancelButton2.Text = ResourceManager.GetString("CreateEditPost_Cancel");
			cancelButton2.Click += new System.EventHandler(CancelButton_Click);
			OverideConfirmation(cancelButton2);


			
            
                
		}

		private void OverideConfirmation(Button b)
		{
			b.Attributes.Add("OnKeyDown", ConfirmationPage.ByPassFuncationName);
		}

        private void SetYesNo(BlogPostConfig bc, bool isPublished, bool allowReplies, bool emailReplies, bool rate, bool track)
        {
            bool isPost = BlogPostType == BlogPostType.Post;
            EnableYesNo("ynEnableReplies",allowReplies,true);
            EnableYesNo("ynEmailMe",emailReplies,true);
            EnableYesNo("ynPublished",isPublished,true);
            EnableYesNo("ynAggregatePost",WeblogPost.IsPostConfigSelected(bc,BlogPostConfig.IsAggregated),isPost);
            EnableYesNo("ynCommunity",WeblogPost.IsPostConfigSelected(bc,BlogPostConfig.IsCommunityAggregated),isPost);
            EnableYesNo("ynSyndicateExcerpt",WeblogPost.IsPostConfigSelected(bc,BlogPostConfig.SyndicateExcerpt),isPost);
            EnableYesNo("ynPersonalHomePage",WeblogPost.IsPostConfigSelected(bc,BlogPostConfig.DisplayOnHomePage),isPost);
			EnableYesNo("ynEnableRatings",rate,true);
			EnableYesNo("ynEnableTrackBacks",track,true);
			
        }

        private void PopulateFromYesNo(WeblogPost thread)
        {
            bool isPost = BlogPostType == BlogPostType.Post;
            thread.IsTracked = GetYesNo("ynEmailMe");
            thread.IsLocked = !GetYesNo("ynEnableReplies");
            thread.IsApproved = GetYesNo("ynPublished");
			thread.EnableRatings = GetYesNo("ynEnableRatings");
			thread.EnableTrackBacks = GetYesNo("ynEnableTrackBacks");
            if(isPost)
            {
                thread.IsAggregated = GetYesNo("ynAggregatePost");
                thread.IsCommunityAggregated = GetYesNo("ynCommunity");
                thread.SyndicateExcerpt = GetYesNo("ynSyndicateExcerpt");
                thread.DisplayOnHomePage = GetYesNo("ynPersonalHomePage");
            }

        }

        private bool GetYesNo(string ynID)
        {
            return (FindControl(ynID) as YesNoRadioButtonList).SelectedValue;
        }

        private void EnableYesNo(string ynID, bool Selected, bool enable)
        {
            YesNoRadioButtonList yn = FindControl(ynID) as YesNoRadioButtonList;
            if(yn != null)
            {
                yn.SelectedValue = Selected;

                if(!enable)
                    FindControl(ynID + "_row").Visible = false;
            }
        }

        /***********************************************************************
        // DisplayPreview
        //
        /// <remarks>
        /// Displays a preview of a CurrentUser's post to a message.
        /// </remarks>
        /// <param name="control">Usercontrol used to control UI formatting</param>
        ***********************************************************************/
        private void DisplayPreview() 
        {
            Button button;

            // Wire up the back button
            button = (Button) FindControl("BackButton");
            button.Text = ResourceManager.GetString("CreateEditPost_BackButton");
            button.Click += new System.EventHandler(BackButton_Click);
        	OverideConfirmation(button);

            // Wire up the post button
            button = (Button) FindControl("PreviewPostButton");

⌨️ 快捷键说明

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