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

📄 submitcommentpanel.ascx.cs

📁 Portal C# Article Live
💻 CS
字号:
namespace Interspire.ArticleLive.Web.Templates.DefaultFixed.Panels
{
	using System;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;
	using Interspire.ArticleLive;
	using Interspire.ArticleLive.Web.Security;

	public abstract class SubmitCommentPanel : BaseUserControl
	{
		protected System.Web.UI.WebControls.Button SubmitCommentButton;
		protected System.Web.UI.WebControls.TextBox FromName;
		protected System.Web.UI.WebControls.TextBox FromEmail;
		protected System.Web.UI.WebControls.TextBox Details;
		protected Interspire.ArticleLive.Web.RatingControl Rating;
		protected System.Web.UI.WebControls.CheckBox SendToAuthor;
		protected System.Web.UI.WebControls.CheckBox PostOnSite;
		protected Interspire.ArticleLive.Web.MessageControl MessageControl1;
		protected CustomRequiredFieldValidator DetailsReqVal;
		protected Interspire.ArticleLive.Web.ValidationAlerter ValidationAlerter1;
		protected System.Web.UI.WebControls.Panel DonePanel;
		protected System.Web.UI.WebControls.Panel FormPanel;
		protected Interspire.ArticleLive.Web.CommentRecipientSelect CommentRecipient;
		protected Interspire.ArticleLive.Web.CustomCheckBoxListRequiredFieldValidator CommentRecipientReqVal;

		protected Article CurrentArticle
		{
			get { return (Article)CurrentComment.Content; }
		}

		protected BlogEntry CurrentBlogEntry
		{
			get { return (BlogEntry)CurrentComment.Content; }
		}

		private CommentEngine commentEngine;
		protected CommentEngine CommentEngine
		{
			get {
				if (commentEngine == null)
					commentEngine = new CommentEngine(Config.Current);
				return commentEngine; }
		}

		protected Comment CurrentComment
		{
			get { return (Comment)ViewState["CurrentComment"]; }
			set { ViewState["CurrentComment"] = value; }
		}

		private void Page_Load(object sender, System.EventArgs e)
		{
			if (!IsPostBack)
			{
				if (Action == "SubmitComment")
				{
					if (!Config.Current.EnableArticleComments || (Request.QueryString["ArticleID"] == null && Request.QueryString["EntryID"] == null))
						Visible = false;
					else
					{
						WindowTitle = ResourceHelper.GetString("SubmitComment");
						CurrentComment = new Comment();

						if (Request.IsAuthenticated)
						{
							FromName.Text = ((Identity)User.Identity).FullName;
							FromEmail.Text = ((Identity)User.Identity).Email;
						}

						if (Request.QueryString["ArticleID"] != null)
						{
							CurrentComment.Type = CommentTypeEnum.Article;
							CurrentComment.ContentID = QueryStringHelper.GetInt32("ArticleID");
							CurrentComment.Content = (new ArticleEngine(Config.Current)).GetArticle(CurrentComment.ContentID);
						}
						else if (Request.QueryString["EntryID"] != null)
						{
							CurrentComment.Type = CommentTypeEnum.Blog;
							CurrentComment.ContentID = QueryStringHelper.GetInt32("EntryID");
							CurrentComment.Content = (new BlogEngine(Config.Current)).GetBlogEntry(CurrentComment.ContentID);
						}

						if (CurrentComment.ContentID > 0)
						{
							Visible = true;
							SetDefaultButton(FormPanel, SubmitCommentButton);
							DataBind();
						}
						else
							Visible = false;
					}
				}
				else
					Visible = false;
			}

			if (!Page.IsClientScriptBlockRegistered("formUtil.js") && this.Visible)
				Page.RegisterClientScriptBlock("formUtil.js", "<script src=\"Javascript/formUtil.js\"></script>");
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();

			this.SubmitCommentButton.Click += new System.EventHandler(this.SubmitCommentButton_Click);
			this.Load += new System.EventHandler(this.Page_Load);

			base.OnInit(e);
		}
		
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{

		}
		#endregion

		private void SubmitCommentButton_Click(object sender, System.EventArgs e)
		{
			if (IsValid)
			{
				FormToComment(CurrentComment);
				if (Config.Current.AutoApproveComments)
					CurrentComment.Status = ContentStatusEnum.Approved;
				else
					CurrentComment.Status = ContentStatusEnum.Pending;

				if (CurrentComment.Type == CommentTypeEnum.Article && Config.Current.EnableArticleRating)
					(new ArticleEngine(Config.Current)).RateArticle(CurrentComment.ContentID, CurrentComment.Rating);

				if (CommentRecipient.SendToAuthorSelected)
				{
					string webSiteLink = "<a href='" + Config.Current.WebSiteUrl + "'>" + Config.Current.WebSiteName + "</a>";
					string contentLink = CurrentComment.Type == CommentTypeEnum.Article ? "<a href='" + LinkHelper.CreateArticleLink((Article)CurrentComment.Content, true) + "'>" + LinkHelper.CreateArticleLink((Article)CurrentComment.Content, true) + "</a>" : "<a href='" + LinkHelper.CreateBlogLink((BlogEntry)CurrentComment.Content, true) + "'>" + LinkHelper.CreateBlogLink((BlogEntry)CurrentComment.Content, true) + "</a>";
					string subject = String.Format(ResourceHelper.GetString("SendCommentSubject"), Config.Current.WebSiteName);
					string body = String.Format(CurrentComment.Type == CommentTypeEnum.Article ? ResourceHelper.GetString("SendArticleCommentBody") : ResourceHelper.GetString("SendBlogCommentBody"), webSiteLink, CurrentComment.Content.Title, contentLink, CurrentComment.Rating, CurrentComment.Details);
					(new UserEngine(Config.Current)).SendUserEmail(CurrentComment.Content.AuthorID, subject, body);
				}
			
				if (CommentRecipient.PostOnSiteSelected)
				{
					CommentEngine.SaveComment(CurrentComment);
				}

				FormPanel.Visible = false;
				DonePanel.Visible = true;
			}
		}

		private void FormToComment(Comment comment)
		{
			comment.FromName = FromName.Text;
			comment.FromEmail = FromEmail.Text;
			comment.Rating = Config.Current.EnableArticleRating ? Convert.ToInt32(Rating.SelectedItem.Value) : 0;
			comment.Details = Details.Text;
		}
	}
}

⌨️ 快捷键说明

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