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

📄 createeditpost.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
📖 第 1 页 / 共 4 页
字号:
        /// <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) {
            Control form;
            Literal label;
            TextBox textbox;

            // only do this stuff if the page is valid
            if (!Page.IsValid) 
                return;
			
            // The event was raised by a button in the user control
            // the is the UI for the form -- get the Parent, e.g. the User Control
            form = ((Control)sender).Parent;

			form.FindControl("EditButton").Visible = true;
			form.FindControl("PreviewButton").Visible = false;

            // Find and enable the Preview display
            form.FindControl("Preview").Visible = true;

            // Find and hide the ReplyTo display and Post
            form.FindControl("Post").Visible = false;

            // Set the title text
            if (form.FindControl("PostTitle") != null) 
            {
                if (form.FindControl("PostTitle").GetType().UnderlyingSystemType.ToString() == typeof(Label).ToString() )
                    ((Label) form.FindControl("PostTitle")).Text = "Preview Message";
                else
                    ((Literal) form.FindControl("PostTitle")).Text = "Preview Message";
            }

            // Preview the post subject
            label = (Literal) form.FindControl("PreviewSubject");
            textbox = (TextBox) form.FindControl("PostSubject");
            label.Text = Globals.HtmlEncode(textbox.Text);

            // Preview the post body
            label = (Literal) form.FindControl("PreviewBody");

            // Where should the body content come from?
            //

            postBody = (Editor)form.FindControl("postBody");
            postBody.Text = Formatter.FormatIrcCommands(postBody.Text, user.Username);
            postBody.EnableHtmlModeEditing = user.IsForumAdministrator;

			string signature;
			if (PostMode == CreateEditPostMode.EditPost)
				signature = Globals.FormatSignature(postReplyingTo.User.Profile.SignatureFormatted);
			else
				signature = Globals.FormatSignature(user.Profile.SignatureFormatted);


            label.Text = Transforms.FormatPostText(postBody.Text) + signature;
        }
        #endregion
        
        #region DeleteAttachment_CheckedChanged
		private void DeleteAttachment_CheckedChanged (object sender, EventArgs e) {
			fileToUpload.Visible = deleteAttachment.Checked;
			newAttachment.Visible = deleteAttachment.Checked;
		}
        #endregion

        #endregion

        #region Supporting Methods

        #region SetEditNotes
        void SetEditNotes (Control skin, ForumPost p) {
            string[] editItems = new string[4];
            editItems[0] = user.Username;
            editItems[1] = DateTime.Now.ToString(CSContext.Current.SiteSettings.TimeFormat);
			editItems[2] = CSContext.Current.SiteSettings.TimezoneOffset.ToString();
			editItems[3] = DateTime.Now.ToString(CSContext.Current.SiteSettings.DateFormat);

            TextBox edit = (TextBox) skin.FindControl("EditNotesBody");
            TextBox notes = (TextBox) skin.FindControl("CurrentEditNotesBody");

            // TDD 3/18/2004
            // this was changed to go ahead and save the note in safe HTML format and not to do it on every
            // viewing of the post.
            p.EditNotes = Formatter.EditNotes( String.Format( csContext.Context.Server.HtmlDecode(ResourceManager.GetString("CreateEditPost_EditNotesRecord")), editItems));
        }
        #endregion

        #region SetBodyContents
        void SetBodyContents (Control skin, ForumPost p) {
            postBody = (Editor)skin.FindControl("postBody");

            if (postBody.IsRichTextCapable) 
            {
                p.PostType = PostType.HTML;
                p.Body = postBody.Text;
            } 
            else 
            {
                p.PostType = PostType.BBCode;
                p.Body = postBody.Text;
            }
        }
        #endregion
        
        #region SetSticky
        void SetSticky (Control skin, Thread p) {

            // Are we pinning the post?
            //
            if ((pinnedPost != null) && (Convert.ToInt32(pinnedPost.SelectedItem.Value) > 0)) 
            {
                
                p.IsSticky = true;

                switch (Convert.ToInt32(pinnedPost.SelectedItem.Value)) 
                {

                    case 1:
                        p.StickyDate = DateTime.Now.Date.AddDays(1);
                        break;

                    case 3:
                        p.StickyDate = DateTime.Now.Date.AddDays(3);
                        break;

                    case 7:
                        p.StickyDate = DateTime.Now.Date.AddDays(7);
                        break;

                    case 14:
                        p.StickyDate = DateTime.Now.Date.AddDays(14);
                        break;

                    case 30:
                        p.StickyDate = DateTime.Now.Date.AddMonths(1);
                        break;

                    case 90:
                        p.StickyDate = DateTime.Now.Date.AddMonths(3);
                        break;

                    case 180:
                        p.StickyDate = DateTime.Now.Date.AddMonths(6);
                        break;

                    case 366:
                        p.StickyDate = DateTime.Now.Date.AddYears(1);
                        break;

                    case 999:
                        p.StickyDate = DateTime.Now.Date.AddYears(25);
                        break;
                }
            }
            else
            {
				if (p.IsSticky)
				{
					p.IsSticky = false;
					p.StickyDate = DateTime.Now.AddDays(-1);
				}
            }
        }
        #endregion
        
        #region AddPost
        ForumPost AddPost (ForumPost post, CreateEditPostMode mode, HtmlInputFile attachment) {
            ForumPost newPost = null;

            switch (mode) 
            {

                case CreateEditPostMode.NewPost:
                    post.SectionID = csContext.ForumID;	
                    newPost = Posts.AddPost(post, user);
                    break;

				case CreateEditPostMode.ReplyPrivateMessage:
                case CreateEditPostMode.ReplyToPost:
                    post.ParentID = csContext.PostID;
                    newPost = Posts.AddPost(post, user);
                    break;

                case CreateEditPostMode.EditPost:
					post.PostID = csContext.PostID;
                    Posts.UpdatePost(post, user.UserID);
                    newPost = Posts.GetPost(post.PostID, user.UserID);
                    break;

                case CreateEditPostMode.ReportingPost:
                    post.SectionID = csContext.ForumID;
                    newPost = Posts.AddPost(post, user);
                    break;

            }

            // Attempt to process an attachment
            //
            AddPostAttachment (newPost, attachment);

            return newPost;
        }
        #endregion
        
        #region AddPostAttachment
        void AddPostAttachment (ForumPost p, HtmlInputFile attachment) {

            // these first three check to see if we have a file to attach,
            // no error reply is needed.
            //
            if ((attachment != null) && (p != null)) 
            {
                if (attachment.PostedFile != null) 
                {
                    if (attachment.PostedFile.ContentLength > 0) 
                    {

                        // EAD: We only allow normal filename.ext type files.
                        // Multiple extensions, such as filename.ext.ext could pose a security
                        // risk for admins that allow items such as .exe 
                        // (TryMe.GIF.exe) <- virus masked as a simple pic, hidden when .exe is may be allowed.
                        // Therefore I am coding this not to allow more then one extension.  The user uploading
                        // can rename the file if need be.
                        //
                        // TDD: I'm changing this to look at the last extension not the first because this also
                        // breaks if the file path has a period in it's path.
                        string[] Extensions = attachment.PostedFile.FileName.Split('.');
                        string FileExtension;
						
                        try 
                        {
                            // little error capturing if the file does not have an extension
                            //
                            FileExtension = Extensions[Extensions.Length - 1].ToString();
                        }
                        catch 
                        {
                            throw new CSException(CSExceptionType.PostInvalidAttachmentType);
                        }

						
                        // now some site settings checks
                        //
						if (!CSContext.Current.SiteSettings.EnableAttachments)
							throw new CSException( CSExceptionType.PostAttachmentsNotAllowed );

						else if ((Convert.ToInt32(attachment.PostedFile.ContentLength) > (CSContext.Current.SiteSettings.MaxAttachmentSize * 1000)) && CSContext.Current.SiteSettings.MaxAttachmentSize > 0)
							throw new CSException( CSExceptionType.PostAttachmentTooLarge, CSContext.Current.SiteSettings.MaxAttachmentSize.ToString() );

						else if (!ValidateAttachmentType(FileExtension))
							throw new CSException( CSExceptionType.PostInvalidAttachmentType, FileExtension );

						else
						{
							// 修改,如果版主/管理员修改了附件
							//Posts.AddAttachment(p, new CommunityServer.Components.PostAttachment(attachment.PostedFile));
							CommunityServer.Components.PostAttachment postAttachment = new CommunityServer.Components.PostAttachment(attachment.PostedFile, p.User.UserID);
							Posts.AddAttachment(p, postAttachment);
						}
                    }
                }
            }
        }
        #endregion
        
        #region ValidateAttachmentType
        bool ValidateAttachmentType (string rawExtension) {
            // Todo, possibly, is to convert this system to use the ContentType instead
            // of the file extensions.  But file extensions are easier to maintain by 
            // novice administrators.  Instead of having to list all of the content-types to check.
            //
            // .ContentType == "video/mpeg"		
            // attachment.PostedFile.ContentType;	
            //
            //string[] Types = {"zip", "cab", "jpg", "gif", "png", "mpg", "mpeg", "avi", "wmv", "wma", "mp3", "ra", "rm", "sql", "txt"};
            string[] Types = CSContext.Current.SiteSettings.AllowedAttachmentTypes.Split(';');
			
            // validates against the allowed file extensions entered
            // in the site configuration.
            //
            foreach(string type in Types) 
            {
                if(type.Trim().ToLower() == rawExtension.ToLower()) 
                {
                    return true;
                }
            }
            return false;
        }
        #endregion
        
        #region AllowAttachments
        bool AllowAttachments {
            get {
                User user = CSContext.Current.User;

                if (!user.IsAnonymous) {
                    ForumPermission fp = forum.ResolvePermission( CSContext.Current.User)  as ForumPermission;
					
                    // Do we allow the user to make pinned posts?
                    //
                    if ( (
                        user.IsForumAdministrator || 
                        fp.Attachment || 
                        CommunityServer.Discussions.Moderate.IsForumModerator(user, forum.GroupID, forum.SectionID) 
                        ) && CSContext.Current.SiteSettings.EnableAttachments )
                        return true;
                    else
                        return false;
                }
                else 
                    return false;
            }
        }
        #endregion

        #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 ForumID 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; }
        }
		#endregion
	}
}

⌨️ 快捷键说明

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