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

📄 addcomment.cs

📁 ASP开发网站的 关于网站的设计和说明 还有SQL的程序 数据库
💻 CS
字号:
namespace ASPNET.StarterKit.Communities {

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


    //*********************************************************************
    //
    // AddComment Class
    //
    // Represents the Add Comment page. Enables users to add comments
    // to resources.
    //
    //*********************************************************************

    public class AddComment : SkinnedCommunityControl{
    
        string _skinFileName = "Comments_AddComment.ascx";

        Panel pnlForm;
        Panel pnlPreview;
        TextBox txtTitle;
        CommentHtmlTextBox txtBody;
        Button btnAdd;
        Button btnPreview;
        Title lblPreviewTitle;
        CommentText lblPreviewBody;
        Button btnContinue;


        //*********************************************************************
        //
        // AddComment Constructor
        //
        // Calls the base SkinnedCommunityControl constructor
        // and assigns the default page skin. Also checks whether
        // current user has permissions to add a comment.
        //
        //*********************************************************************

		public AddComment() : base() {
            // Check security
            if (!objUserInfo.MayComment)
               CommunityGlobals.ForceLogin();

            // Assign a default skin file name
            if (SkinFileName == null)
                SkinFileName = _skinFileName;
        }
        

        //*********************************************************************
        //
        // SkinType Property
        //
        // Specifies the skins directory where this page's skin file is located.
        //
        //*********************************************************************
        
        override protected string SkinType {
            get { return "ContentSkins"; }
        }



        //*********************************************************************
        //
        // ContentPageID Property
        //
        // Represents the Content Page ID of the resource being commented on.
        //
        //*********************************************************************

        public int ContentPageID {
            get {return (int)ViewState["ContentPageID"];}
            set {ViewState["ContentPageID"] = value; }
        
        }


        //*********************************************************************
        //
        // ReturnUrl Property
        //
        // Represents the URL that the user is redirected back to
        // after adding a comment.
        //
        //*********************************************************************

        public string ReturnUrl {
            get {
                if (ViewState["ReturnUrl"] == null)
                    return String.Format("{0}.aspx", ContentPageID);
                else 
                    return (string)ViewState["ReturnUrl"];
            }
            set {ViewState["ReturnUrl"] = value; }
        
        }

        
        
        //*********************************************************************
        //
        // InitializeSkin Method
        //
        // Retrieves all the controls from the page skin.
        //
        //*********************************************************************

        override protected void InitializeSkin(Control skin) {
            // Find the Form Panel
            pnlForm = (Panel)GetControl(skin, "pnlForm");
            pnlForm.Visible = true;
            
            // Find the Preview Panel
            pnlPreview = (Panel)GetControl(skin, "pnlPreview");
        
            // Find the Title TextBox
            txtTitle = (TextBox)GetControl(skin, "txtTitle");

            // Find the Body TextBox
            txtBody = (CommentHtmlTextBox)GetControl(skin, "txtBody");
 
            // Find Add Button
            btnAdd = (Button)GetControl(skin, "btnAdd");
    		btnAdd.Click += new EventHandler(btnAdd_Click);

            // Find Preview Button
            btnPreview = (Button)GetControl(skin, "btnPreview");
    		btnPreview.Click += new EventHandler(btnPreview_Click);

            // Find Preview Title
            lblPreviewTitle = (Title)GetControl(skin, "lblPreviewTitle");
            
            // Find Preview Body
            lblPreviewBody = (CommentText)GetControl(skin, "lblPreviewBody");

            // Find Continue Button
            btnContinue = (Button)GetControl(skin, "btnContinue");
            btnContinue.CausesValidation = false;
    		btnContinue.Click += new EventHandler(btnContinue_Click);
        } 


        //*********************************************************************
        //
        // OnLoad Method
        //
        // Assigns values to the controls from the page skin.
        //
        //*********************************************************************

        protected override void OnLoad(EventArgs e) {
            if (!Page.IsPostBack) {
                // Determine content page
                ContentPageID = Int32.Parse(Context.Request.QueryString["id"]);
                ReturnUrl = Context.Request.QueryString["ReturnUrl"];

                // Hide preview panel
                EnsureChildControls();
                pnlPreview.Visible = false;
            }
        }        
        

        //*********************************************************************
        //
        // btnAdd_Click Method
        //
        // This method is raised by clicking the Add button in the Add 
        // Comment form.
        //
        //*********************************************************************

        void btnAdd_Click(Object s, EventArgs e) {
            ModerationStatus _moderationStatus = ModerationStatus.Approved;
        
            if (Page.IsValid) {
                // Determine moderation status
                if (objSectionInfo.EnableModeration && !objUserInfo.MayModerate)
                    _moderationStatus = ModerationStatus.Pending;
                
                // Add the comment
                int _contentPageID = CommentUtility.AddComment(ContentPageID, _moderationStatus, objUserInfo.Username, txtTitle.Text,txtBody.Text);   

				// Show warning message if moderation enabled
				if (objSectionInfo.EnableModeration && !objUserInfo.MayModerate)
				    Context.Response.Redirect(CommunityGlobals.CalculatePath(String.Format("Messages_Message.aspx?message=moderation&ReturnUrl={0}", HttpUtility.UrlEncode(ReturnUrl))));

                // Otherwise, redirect back and send notifications
                Context.Response.BufferOutput = false;
				Context.Response.Redirect(CommunityGlobals.CalculatePath(ReturnUrl), false);
				NotifyUtility.SendNotifications(objSectionInfo.ID, _contentPageID, txtTitle.Text, objUserInfo.Username);
				Context.Response.End();    

            }
        }       
 
 
        //*********************************************************************
        //
        // btnPreview_Click Method
        //
        // This method is raised by clicking the Preview button in the Add 
        // Comment form.
        //
        //*********************************************************************

        void btnPreview_Click(Object s, EventArgs e) {
            EnsureChildControls();
            
            // Display preview panel
            pnlPreview.Visible = true;
            pnlForm.Visible = false;   
            
            // Display preview content
            lblPreviewTitle.Text = txtTitle.Text;
            lblPreviewBody.Text = txtBody.Text;
        }       
 
 
        //*********************************************************************
        //
        // btnContinue_Click Method
        //
        // This method is raised by clicking the Continue button in the Add 
        // Comment form.
        //
        //*********************************************************************

        void btnContinue_Click(Object s, EventArgs e) {
            EnsureChildControls();
            
            // Hide preview panel
            pnlPreview.Visible = false;
            pnlForm.Visible = true;   
        }       
        


    }
}

⌨️ 快捷键说明

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