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

📄 createeditblogpost.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
📖 第 1 页 / 共 2 页
字号:
            button.Text = ResourceManager.GetString("CreateEditPost_PreviewPostButton");
            button.Click += new System.EventHandler(PostButton_Click);
        	OverideConfirmation(button);

        }

        #endregion

        #region Events

        /***********************************************************************
        // BackButton_Click
        //
        /// <remarks>
        /// Event handler for the back button click from Preview mode
        /// </remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ************************************************************************/
        private void BackButton_Click(Object sender, EventArgs e) 
        {
            TogglePreview(true);

        }


        /***********************************************************************
        // PostButton_Click
        //
        /// <remarks>
        /// This event handler fires when the preview button is clicked.  It needs
        /// to show/hide the appropriate panels.
        /// </remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ************************************************************************/
        private void PostButton_Click (Object sender, EventArgs e) 
        {
            WeblogPost postToAdd = (currentPost == null) ? new WeblogPost() : currentPost;

            WeblogPost newPost = null; 
            CheckBoxList categoryList = null;
            //HtmlInputFile attachment = null;

            // Only proceed if the post is valid
            //
			if (!Page.IsValid) 
			{
				ExpanderPanel AdvancedProperties = FindControl("Toggler") as ExpanderPanel;
				AdvancedProperties.Collapsed = false;
				return;
			}
			


            // Get details on the post to be added
            //
            postToAdd.Subject = ((TextBox) FindControl("PostSubject")).Text;
            postToAdd.Name = ((TextBox) FindControl("postName")).Text;
            postToAdd.Excerpt = ((TextBox) FindControl("postExcerpt")).Text;

            categoryList = FindControl("CategoryList") as CheckBoxList;
            if(categoryList != null)
            {
                ArrayList al = new ArrayList();
                foreach(ListItem li in categoryList.Items)
                {
                    if(li.Selected)
                        al.Add(li.Value);
                }
                postToAdd.Categories = (string[])al.ToArray(typeof(string));
            }

            PopulateFromYesNo(postToAdd);

			CommentModerationDropDownList ModerationDDL = (CommentModerationDropDownList)FindControl("ModerationDDL");
			postToAdd.ModerationType = (CommentModerationType)Enum.Parse(typeof(CommentModerationType),ModerationDDL.SelectedValue,false);

            // Set the body of the post
            //
            SetBodyContents( postToAdd);

            TextBox postDate = FindControl("postdate") as TextBox;
            if(postDate.Text.Trim().Length > 0)
            {
                try
                {
                    DateTime dt = DateTime.Parse(postDate.Text.Trim());
                    postToAdd.BloggerTime = dt;
                    postToAdd.PostDate = UserTime.ConvertToServerTime(dt);
                }
                catch(FormatException)
                {
                    Label DateError = FindControl("DateError") as Label;
                    DateError.Visible = true;
                    ExpanderPanel Toggler = FindControl("Toggler") as ExpanderPanel;
                    Toggler.Collapsed = false;
                    return;
                }
            }
            else
            {
                postToAdd.PostDate = DateTime.Now;
				postToAdd.BloggerTime = UserTime.ConvertToUserTime(postToAdd.PostDate);
				
            }

            

					
            BlogPostResults result = BlogPostResults.Success;

            newPost = AddPost(postToAdd, PostMode, out result);

            if(result == BlogPostResults.Success)
                Context.Response.Redirect(BlogUrls.Instance().AdminContentList(CurrentWeblog.ApplicationKey,newPost.BlogPostType));
            else
            {
                ResourceControl Message = FindControl("Message") as ResourceControl;
                Message.ResourceName = result == BlogPostResults.DuplicationName ? "Weblog_Exception_DuplicatePostName" : "Weblog_Exception_DuplicatePostBody";

                FindControl("ErrorPanel").Visible = true;
            }

        }

        #region CancelButton_Click
        /***********************************************************************
        // CancelButton_Click
        //
        /// <remarks>
        /// Event raised when the CurrentUser decides to cancel the post.
        /// </remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ************************************************************************/
        private void CancelButton_Click(Object sender, EventArgs e) 
        {
            
            Context.Response.Redirect(BlogUrls.Instance().AdminContentList(CurrentWeblog.ApplicationKey,this.BlogPostType));
            Page.Response.End();
        }
        #endregion

		private void TogglePreview(bool tog)
		{
			FindControl("Preview").Visible = !tog;

			FindControl("Post").Visible = tog;
			FindControl("Toggler").Visible = tog;
			FindControl("AdvancedProperties").Visible = tog;
			FindControl("ButtonSet").Visible = tog;
		}

        #region PreviewButton_Click
        /***********************************************************************
        // PreviewButton_Click
        //
        /// <remarks>
        /// This event handler fires when the preview button is clicked.  It needs
        /// to show/hide the appropriate panels.
        /// </remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ************************************************************************/
        private void PreviewButton_Click(Object sender, EventArgs e) 
        {
            Literal title = null;
			Literal body = null;
            TextBox textbox;
            Editor editor;
            // only do this stuff if the page is valid
            if (!Page.IsValid) 
                return;
			

            // Find and enable the Preview display

			TogglePreview(false);

            // Set the title text


            // Preview the post subject
            title = FindControl("PreviewSubject") as Literal;
			body = FindControl("PreviewBody") as Literal;


            textbox = (TextBox) FindControl("PostSubject");
			title.Text = Transforms.CensorPost(Globals.HtmlEncode(textbox.Text));

            // Where should the body content come from?
            //
            editor = (Editor) FindControl("PostBody");

			body.Text = Transforms.CensorPost(HtmlScrubber.Clean(editor.Text,true,true));//, CurrentUser.Username);
            
			
        }
        #endregion
        #endregion

        #region Supporting Methods

        void SetBodyContents(Post p) 
        {
			
            Editor postBody = (Editor) FindControl("postBody");
               
            p.PostType = PostType.HTML;
            p.Body = postBody.Text;
			p.FormattedBody = null; //make sure we reset this after formatting!
			
        }

        WeblogPost AddPost(WeblogPost post, CreateEditPostMode mode, out BlogPostResults result) 
        {
           

            switch (mode) 
            {

                case CreateEditPostMode.NewPost:
                    post.Username = CurrentUser.Username;
                    post.SectionID = CurrentWeblog.SectionID;
                    post.ParentID = 0;
                    post.BlogPostType = this.BlogPostType;

                    int pid = -1;
                    

                    result = WeblogPosts.Add(post,CurrentUser, out pid);
                    post.PostID = pid;
                    post.User = CurrentUser;
                    break;

                case CreateEditPostMode.EditPost:
                    result = BlogPostResults.Success;
                    post.PostID = csContext.PostID;
                    result = WeblogPosts.Update(post,CurrentUser.UserID);
                    break;
                default:
                    result = BlogPostResults.UnKnownError;
                    break;

            }

            return post;
        }


        #endregion

        #region Properies

        /// <value>
        /// Indicates whether the post being made is a new post, a reply to an existing post, or an
        /// editing of an existing post.  The allowable values are NewPost, ReplyToPost, and EditPost.
        /// </value>
        /// <remarks>When setting the Mode property to NewPost, you must supply a weblogID property.
        /// When setting the Mode to ReplyToPost or EditPost, you must supply a PostID property.</remarks>
        public CreateEditPostMode PostMode 
        {
            get 
            {
                Object state = ViewState[ "mode" ];
                if ( state != null ) 
                {
                    return (CreateEditPostMode)state;
                }
                return CreateEditPostMode.NewPost;
            }
            set { ViewState["mode"] = value; }
        }

        public BlogPostType BlogPostType 
        {
            get 
            {
                Object state = ViewState[ "BlogPostType" ];
                if ( state != null ) 
                {
                    return (BlogPostType)state;
                }
                return BlogPostType.Post;
            }
            set 
            { 
                if(value != BlogPostType.Post && value != BlogPostType.Article)
                    throw new CSException(CSExceptionType.AccessDenied, "Can only edit posts and articles");

                ViewState["BlogPostType"] = value; }
        }

        #endregion
    }
}

⌨️ 快捷键说明

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