📄 entrylistcontainer.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using CommunityServer.Blogs.Components;
using CommunityServer.Components;
using CommunityServer.Controls;
namespace CommunityServer.Blogs.Controls
{
/// <summary>
/// Summary description for EntryListContainer.
/// </summary>
public class EntryListContainer : WeblogThemedControl
{
#region ChildControls
private EntryList entryItems = null;
private Literal listTitle = null;
//private Pager listPager = null;
private HtmlGenericControl titleWrapper = null;
#endregion
public EntryListContainer()
{
}
#region Public Properties
/// <summary>
/// Gets or sets the type of thread to display
/// </summary>
[
System.ComponentModel.DefaultValue( BlogThreadType.Recent ),
]
public virtual BlogThreadType BlogThreadType
{
get
{
Object state = ViewState["BlogThreadType"];
if ( state != null )
{
return (BlogThreadType)state;
}
return BlogThreadType.Recent;
}
set
{
ViewState["BlogThreadType"] = value;
}
}
/// <summary>
/// Gets or sets the sort order of the displayed posts.
/// </summary>
[
System.ComponentModel.DefaultValue( BlogThreadSortBy.MostRecent ),
]
public virtual BlogThreadSortBy BlogThreadSortBy
{
get
{
Object state = ViewState["BlogThreadSortBy"];
if ( state != null )
{
return (BlogThreadSortBy)state;
}
return BlogThreadSortBy.MostRecent;
}
set
{
ViewState["BlogThreadSortBy"] = value;
}
}
/// <summary>
/// Gets or sets the type of posts to display.
/// </summary>
[
System.ComponentModel.DefaultValue( BlogPostType.Post ),
]
public virtual BlogPostType BlogPostType
{
get
{
Object state = ViewState["BlogPostType"];
if ( state != null )
{
return (BlogPostType)state;
}
return BlogPostType.Post;
}
set
{
ViewState["BlogPostType"] = value;
}
}
/// <summary>
/// Gets or sets if the results are paged.
/// </summary>
[
System.ComponentModel.DefaultValue( false ),
]
public virtual Boolean EnablePaging
{
get
{
Object state = ViewState["EnablePaging"];
if ( state != null )
{
return (Boolean)state;
}
return false;
}
set
{
ViewState["EnablePaging"] = value;
}
}
/// <summary>
/// Gets or sets the size of a page when paging is enabled.
/// </summary>
[
System.ComponentModel.DefaultValue( 15 ),
]
public virtual Int32 PageSize
{
get
{
Object state = ViewState[ "PageSize" ];
if ( state != null )
{
return (Int32)state;
}
return 15;
}
set
{
ViewState[ "PageSize" ] = value;
}
}
/// <summary>
/// Gets or sets the direction of the sort.
/// </summary>
[
System.ComponentModel.DefaultValue( SortOrder.Descending ),
]
public virtual SortOrder SortOrder
{
get
{
Object state = ViewState["SortOrder"];
if ( state != null )
{
return (SortOrder)state;
}
return SortOrder.Descending;
}
set
{
ViewState["SortOrder"] = value;
}
}
private bool _DisplayExcerpts;
public bool DisplayExcerpts
{
get{return _DisplayExcerpts;}
set{_DisplayExcerpts = value;}
}
#endregion
#region Wire up Skin
protected override void AttachChildControls()
{
entryItems = FindControl( "postlist" ) as EntryList;
entryItems.DisplayExcerpts = this.DisplayExcerpts;
listTitle = FindControl( "listTitle" ) as Literal;
titleWrapper = FindControl( "titleWrapper" ) as HtmlGenericControl;
}
#endregion
#region Data
public override void DataBind()
{
base.DataBind();
BlogThreadQuery query = Query();
ThreadSet ts = WeblogPosts.GetBlogThreads(query,true);
entryItems.DataSource = ts.Threads;
entryItems.DataBind();
entryItems.TotalRecords = ts.TotalRecords;
entryItems.PageSize = PageSize;
//this.listPager.Visible = this.EnablePaging && this.PageSize != 0;
switch(query.BlogThreadType)
{
case BlogThreadType.Day:
listTitle.Text = query.DateFilter.ToLongDateString() + " - " + ResourceManager.GetString("Weblog_EntryList_Posts");
break;
case BlogThreadType.Month:
listTitle.Text = query.DateFilter.ToString("MMMM yyyy") + " - " + ResourceManager.GetString("Weblog_EntryList_Posts");
break;
default:
titleWrapper.Visible = false;
break;
}
if(!Globals.IsNullorEmpty(listTitle.Text))
{
this.SetPageTitle(listTitle.Text);
}
else
{
this.SetPageTitle(string.Empty);
}
}
protected BlogThreadQuery Query()
{
BlogThreadQuery query = new BlogThreadQuery();
query.BlogID = CurrentWeblog.SectionID;
query.BlogPostType = this.BlogPostType;
query.BlogThreadType = this.BlogThreadType;
query.IsPublished = true;
query.SortOrder = SortOrder;
//eventually should be able to view by date and category!
switch(query.BlogThreadType)
{
case BlogThreadType.Category:
query.CategoryID = CSContext.Current.CategoryID;
query.PageSize = 0;
break;
case BlogThreadType.Day:
case BlogThreadType.Month:
case BlogThreadType.Year:
query.DateFilter = GetDate();
query.PageSize = 0;
break;
default:
query.PostConfig = BlogPostConfig.IsAggregated;
query.IgnorePaging = true;
query.PageSize = PageSize;
break;
}
// if ( this.EnablePaging && this.PageSize != 0 )
// {
// query.PageIndex = entryItems.PageIndex;
// query.PageSize = PageSize;
// }
return query;
}
#endregion
#region Events
protected override void OnLoad(EventArgs e)
{
DataBind();
}
#endregion
#region Helpers
protected DateTime GetDate()
{
int year = Context.Request.QueryString["Y"] != null ? Int32.Parse(Context.Request.QueryString["Y"]) : 2000;
int month = Context.Request.QueryString["M"] != null ? Int32.Parse(Context.Request.QueryString["M"]) : 2000;
int day = Context.Request.QueryString["D"] != null ? Int32.Parse(Context.Request.QueryString["D"]) : 2000;
return new DateTime(year,month,day);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -