📄 blogfeedbackadmin.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Web;
using System.Web.UI.WebControls;
using CommunityServer.Blogs.Components;
using CommunityServer.Components;
using CommunityServer.Controls;
namespace CommunityServer.Blogs.Controls
{
/// <summary>
/// Displays an interface for managing a blog's comments and traceback.
/// </summary>
public class BlogFeedbackAdmin : WeblogAdminTemplatedWebControl
{
#region Setup
DataGrid FeedbackList;
Button ApproveTop;
Button ModerateTop;
Button DeleteTop;
Button ApproveBottom;
Button ModerateBottom;
Button DeleteBottom;
Pager GridPager;
/// <exclude />
protected override void AttachChildControls()
{
FeedbackList = (DataGrid)FindControl( "FeedbackList" );
if ( FeedbackList != null )
{
// FeedbackList.AllowPaging = true;
// FeedbackList.AllowCustomPaging = true;
FeedbackList.AutoGenerateColumns = false;
// FeedbackList.PageIndexChanged += new DataGridPageChangedEventHandler(FeedbackList_PageIndexChanged);
FeedbackList.ItemDataBound += new DataGridItemEventHandler(FeedbackList_ItemDataBound);
}
GridPager = FindControl("GridPager") as Pager;
ApproveTop = FindControl( "ApproveTop" ) as Button;
if ( ApproveTop != null )
{
ApproveTop.Text = ResourceManager.GetString( "Feedback_Approve" );
ApproveTop.Click += new EventHandler(Approve_Click);
}
ModerateTop = FindControl( "ModerateTop" ) as Button;
if ( ModerateTop != null )
{
ModerateTop.Text = ResourceManager.GetString( "Feedback_Moderate" );
ModerateTop.Click += new EventHandler(Moderate_Click);
}
DeleteTop = FindControl( "DeleteTop" ) as Button;
if ( DeleteTop != null )
{
DeleteTop.Text = ResourceManager.GetString( "Feedback_Delete" );
DeleteTop.Click += new EventHandler(Delete_Click);
DeleteTop.Attributes.Add( "onclick", "if ( !confirm('" + ResourceManager.GetString("Feedback_ConfirmDelete").Replace("'", @"\'") + "') ) {return false; } " );
}
ApproveBottom = FindControl( "ApproveBottom" ) as Button;
if ( ApproveBottom != null )
{
ApproveBottom.Text = ResourceManager.GetString( "Feedback_Approve" );
ApproveBottom.Click += new EventHandler(Approve_Click);
}
ModerateBottom = FindControl( "ModerateBottom" ) as Button;
if ( ModerateBottom != null )
{
ModerateBottom.Text = ResourceManager.GetString( "Feedback_Moderate" );
ModerateBottom.Click += new EventHandler(Moderate_Click);
}
DeleteBottom = FindControl( "DeleteBottom" ) as Button;
if ( DeleteBottom != null )
{
DeleteBottom.Text = ResourceManager.GetString( "Feedback_Delete" );
DeleteBottom.Click += new EventHandler(Delete_Click);
DeleteBottom.Attributes.Add( "onclick", "if ( !confirm('" + ResourceManager.GetString("Feedback_ConfirmDelete").Replace("'", @"\'") + "') ) {return false; } " );
}
}
/// <exclude />
protected override void OnLoad(EventArgs e)
{
if ( !Page.IsPostBack )
{
this.DataBind();
}
base.OnLoad( e );
}
/// <exclude />
public override void DataBind()
{
base.DataBind ();
this.FeedbackList.DataKeyField = "PostID";
Int32 totalRecords;
this.FeedbackList.DataSource = BlogFeedback.GetFeedback( this.CurrentWeblog.SectionID, GridPager.PageIndex, this.GridPager.PageSize, out totalRecords );
//this.FeedbackList.VirtualItemCount = totalRecords;
this.GridPager.TotalRecords = totalRecords;
this.FeedbackList.DataBind();
}
#endregion
#region FeedbackList Event Handlers
private void FeedbackList_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if ( e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem )
{
BlogFeedbackItem item = e.Item.DataItem as BlogFeedbackItem;
Literal Subject = e.Item.FindControl( "Subject" ) as Literal;
if ( Subject != null )
{
Subject.Text = HttpUtility.HtmlEncode( item.Subject );
}
Literal Body = e.Item.FindControl( "Body" ) as Literal;
if ( Body != null )
{
Body.Text = HttpUtility.HtmlEncode( Formatter.RemoveHtml(item.Body,250) );
}
Literal IsModerated = e.Item.FindControl( "IsModerated" ) as Literal;
if ( IsModerated != null )
{
if ( item.IsApproved )
{
IsModerated.Text = ResourceManager.GetString( "Yes" );
}
else
{
IsModerated.Text = ResourceManager.GetString( "No" );
}
}
Literal PostedBy = e.Item.FindControl( "PostedBy" ) as Literal;
if ( PostedBy != null )
{
PostedBy.Text = HttpUtility.HtmlEncode( item.PostAuthor );
}
Literal DatePosted = e.Item.FindControl( "DatePosted" ) as Literal;
if ( DatePosted != null )
{
DatePosted.Text = Formatter.FormatDatePost( item.PostDate );
}
if(item.HasTitleUrl)
{
HyperLink CommentUrl = e.Item.FindControl( "CommentUrl" ) as HyperLink;
if ( CommentUrl != null )
{
if(item.HasTitleUrl)
{
CommentUrl.Text = "Url";
if ( item.TitleUrl.StartsWith( "http://" ) || item.TitleUrl.StartsWith( "https://" ) )
{
CommentUrl.NavigateUrl = item.TitleUrl;
CommentUrl.ToolTip = item.TitleUrl;
}
else
{
CommentUrl.NavigateUrl = "";
}
}
else
CommentUrl.Visible = false;
}
}
}
}
// private void FeedbackList_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
// {
// this.FeedbackList.CurrentPageIndex = e.NewPageIndex;
// this.DataBind();
// }
#endregion
#region Button Click Handlers
private void Approve_Click(object sender, EventArgs e)
{
Int32[] targetItems = this.GetSelectedPostIDs();
this.ApproveItems( targetItems );
ResetData();
}
private void Moderate_Click(object sender, EventArgs e)
{
Int32[] targetItems = this.GetSelectedPostIDs();
this.ModerateItems( targetItems );
ResetData();
}
private void Delete_Click(object sender, EventArgs e)
{
Int32[] targetItems = this.GetSelectedPostIDs();
this.DeleteItems( targetItems );
ResetData();
}
#endregion
#region Command Implementors
protected void ApproveItems( Int32[] targetItems )
{
BlogFeedback.ApproveFeedback( CSContext.Current.User.UserID, this.CurrentWeblog.SectionID, targetItems );
}
protected void ModerateItems( Int32[] targetItems )
{
BlogFeedback.ModerateFeedback( CSContext.Current.User.UserID, this.CurrentWeblog.SectionID, targetItems );
}
protected void DeleteItems( Int32[] targetItems )
{
BlogFeedback.DeleteFeedback( CSContext.Current.User.UserID, CurrentWeblog.SectionID, targetItems );
}
#endregion
/// <summary>
/// Gets the postIDs of the feedback items selected via the Selector checkbox
/// </summary>
protected Int32[] GetSelectedPostIDs()
{
ArrayList selectedItems = new ArrayList();
foreach( DataGridItem item in this.FeedbackList.Items )
{
CheckBox selector = item.FindControl( "Selector" ) as CheckBox;
if ( selector != null && selector.Checked )
{
Int32 postID = Convert.ToInt32( this.FeedbackList.DataKeys[ item.ItemIndex ] );
selectedItems.Add( postID );
}
}
Int32[] IDs = new Int32[ selectedItems.Count ];
selectedItems.CopyTo( IDs );
return IDs;
}
/// <summary>
/// Resets the data visible in the control
/// </summary>
protected void ResetData()
{
Context.Response.Redirect( Context.Request.RawUrl, true );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -