📄 commentform.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using CommunityServer.Blogs.Components;
using CommunityServer.Components;
namespace CommunityServer.Blogs.Controls
{
/// <summary>
/// Summary description for CommentForum.
/// </summary>
public class CommentForm : WeblogThemedControl
{
private TextBox tbTitle;
private TextBox tbName;
private TextBox tbComment;
private TextBox tbUrl;
private CheckBox chkRemember;
private Button btnSubmit;
private Label Message;
public CommentForm()
{
//
// TODO: Add constructor logic here
//
}
protected override void AttachChildControls()
{
tbTitle = FindControl( "tbTitle" ) as TextBox;
tbName = FindControl( "tbName" ) as TextBox;
tbComment = FindControl( "tbComment" ) as TextBox;
tbUrl = FindControl( "tbUrl" ) as TextBox;
if(Context.Request.IsAuthenticated)
{
tbName.Text = CurrentUser.DisplayName;
(FindControl("NameTitle") as HtmlGenericControl).Visible = false;
(FindControl("NameDesc") as HtmlGenericControl).Visible = false;
tbUrl.Text = CurrentUser.Profile.WebLog;
}
chkRemember = FindControl( "chkRemember" ) as CheckBox;
btnSubmit = FindControl( "btnSubmit" ) as Button;
Message = FindControl( "Message" ) as Label;
btnSubmit.Click +=new EventHandler(btnSubmit_Click);
CheckCookie();
btnSubmit.Text = ResourceManager.GetString( "Submit" );
chkRemember.Text = ResourceManager.GetString( "Weblog_CommentForm_RememberMe" );
}
private WeblogPost _dataSource;
/// <summary>
/// Property DataSource (WeblogEntry)
/// </summary>
public WeblogPost DataSource
{
get
{ return this._dataSource; }
set
{ this._dataSource = value; }
}
public override void DataBind()
{
this.EnsureChildControls();
tbTitle.Text = "re: " + DataSource.Subject;
}
protected override void Authorize(Weblog w)
{
base.Authorize (w);
Permissions.AccessCheck(w,Permission.Reply,CurrentUser);
}
private void CheckCookie()
{
if(!Page.IsPostBack)
{
HttpCookie user = Context.Request.Cookies["CommentUser"];
if(user != null)
{
tbName.Text = user.Values["Name"];
tbUrl.Text = user.Values["Url"];
}
}
}
private void btnSubmit_Click(object sender, EventArgs e)
{
if(!Page.IsValid || !CurrentWeblog.EnableNewComments(DataSource, CurrentUser))
return;
WeblogPost entry = new WeblogPost();
entry.TitleUrl = tbUrl.Text;
entry.Subject = tbTitle.Text;
entry.Body = tbComment.Text;
entry.Excerpt = string.Empty;
entry.IsApproved = !CurrentWeblog.IsPostModerated(DataSource,CurrentUser);
entry.ParentID = DataSource.PostID;
entry.PostType = PostType.HTML;
entry.BlogPostType = BlogPostType.Comment;
entry.SectionID = DataSource.SectionID;
entry.BloggerTime = entry.PostDate = DateTime.Now;
entry.SubmittedUserName = tbName.Text;
// Make sure the URL starts with http://
if(!entry.TitleUrl.StartsWith("http"))
entry.TitleUrl = "http://" + entry.TitleUrl;
// If it is empty, set it to nothing
if(entry.TitleUrl == "http://")
entry.TitleUrl = string.Empty;
if(chkRemember.Checked)
{
HttpCookie userCookie = new HttpCookie( "CommentUser" );
userCookie.Values.Add("Name", tbName.Text);
userCookie.Values.Add("Url", tbUrl.Text);
Context.Response.SetCookie(userCookie);
}
int postID = -1;
BlogPostResults result = WeblogPosts.Add(entry, CurrentUser, out postID);
if(result == BlogPostResults.Success && postID > 0)
Context.Response.Redirect(BlogUrls.Instance().CommentPosted(DataSource,CurrentWeblog));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -