📄 threadlist.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.Collections.Specialized;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetForums;
using AspNetForums.Components;
using System.ComponentModel;
using System.IO;
namespace AspNetForums.Controls {
/// <summary>
/// This control is a specialized datalist that is capable of rendering a list
/// of threads that are provided through a Threads property.
/// </summary>
[
ParseChildren(true)
]
public class ThreadList : DataList {
User user;
String siteStyle;
// *********************************************************************
// CreateChildControls
//
/// <summary>
/// This event handler adds the children controls and is resonsible
/// for determining the template type used for the control.
/// </summary>
///
// ********************************************************************/
protected override void CreateChildControls() {
// Do we have a user?
if (Page.Request.IsAuthenticated) {
user = Users.GetUserInfo(HttpContext.Current.User.Identity.Name, true);
}
// Set the siteStyle for the page
if (user != null)
siteStyle = user.SiteStyle;
else
siteStyle = Globals.SiteStyle;
// Viewstate is disabled
this.EnableViewState = false;
// Apply Template
ApplyTemplates();
}
// *********************************************************************
// RenderHeaderTempalte
//
/// <summary>
/// Renders each the header using a default template
/// </summary>
///
// ********************************************************************/
private Control RenderHeaderTemplate() {
Table table;
TableRow tr;
TableHeaderCell th;
table = new Table();
tr = new TableRow();
// Column 1
th = new TableHeaderCell();
th.ColumnSpan = 2;
th.Height = 25;
th.CssClass = "tableHeaderText";
th.HorizontalAlign = HorizontalAlign.Left;
th.Text = " Thread ";
tr.Controls.Add(th);
// Column 3
th = new TableHeaderCell();
th.CssClass = "tableHeaderText";
th.Text = " Started By ";
th.HorizontalAlign = HorizontalAlign.Center;
th.Wrap = false;
tr.Controls.Add(th);
// Replies Column
th = new TableHeaderCell();
th.CssClass = "tableHeaderText";
th.Text = " Replies ";
th.HorizontalAlign = HorizontalAlign.Center;
tr.Controls.Add(th);
// Views Column
th = new TableHeaderCell();
th.CssClass = "tableHeaderText";
th.Text = " Views ";
th.HorizontalAlign = HorizontalAlign.Center;
tr.Controls.Add(th);
// Last Post
th = new TableHeaderCell();
th.CssClass = "tableHeaderText";
th.Text = " Last Post ";
th.HorizontalAlign = HorizontalAlign.Center;
th.Wrap = false;
tr.Controls.Add(th);
table.Controls.Add(tr);
return table;
}
// *********************************************************************
// RenderItemTempalte
//
/// <summary>
/// Renders each item using a default template
/// </summary>
///
// ********************************************************************/
private Control RenderItemTemplate() {
Table table;
TableRow tr;
TableCell td;
LiteralControl literal;
HyperLink link;
PlaceHolder placeHolder;
Label label;
// Create a new table
table = new Table();
// Create a new table row
tr = new TableRow();
// Column 1
td = new TableCell();
td.Width = 25;
td.HorizontalAlign = HorizontalAlign.Center;
td.VerticalAlign = VerticalAlign.Middle;
td.CssClass = "forumRow";
System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
img.DataBinding += new System.EventHandler(HandleDataBindingForImage);
td.Controls.Add(img);
tr.Controls.Add(td);
// Column 2
td = new TableCell();
td.Height = 25;
td.CssClass = "forumRow";
placeHolder = new PlaceHolder();
placeHolder.DataBinding += new System.EventHandler(HandleDatabindingForPostSubject);
td.Controls.Add(placeHolder);
tr.Controls.Add(td);
// Author Column
td = new TableCell();
td.CssClass = "forumRowHighlight";
td.Width = 100;
td.HorizontalAlign = HorizontalAlign.Left;
link = new HyperLink();
link.CssClass = "linkSmall";
link.DataBinding += new System.EventHandler(HandleDatabindingForAuthor);
td.Controls.Add(new LiteralControl(" "));
td.Controls.Add(link);
tr.Controls.Add(td);
// Replies Column
td = new TableCell();
td.CssClass = "forumRowHighlight";
td.Width = 50;
td.HorizontalAlign = HorizontalAlign.Center;
label = new Label();
label.CssClass = "normalTextSmaller";
label.DataBinding += new System.EventHandler(HandleDatabindingForTotalReplies);
td.Controls.Add(label);
tr.Controls.Add(td);
// Views Column
td = new TableCell();
td.CssClass = "forumRowHighlight";
td.Width = 50;
td.HorizontalAlign = HorizontalAlign.Center;
label = new Label();
label.CssClass = "normalTextSmaller";
label.DataBinding += new System.EventHandler(HandleDatabindingForTotalViews);
td.Controls.Add(label);
tr.Controls.Add(td);
// Post Date Column
td = new TableCell();
td.CssClass = "forumRowHighlight";
td.HorizontalAlign = HorizontalAlign.Center;
td.Width = 140;
placeHolder = new PlaceHolder();
placeHolder.DataBinding += new System.EventHandler(HandleDatabindingForPostDetails);
td.Controls.Add(placeHolder);
td.Wrap = false;
tr.Controls.Add(td);
table.Controls.Add(tr);
return table;
}
// *********************************************************************
// RenderFooterTempalte
//
/// <summary>
/// Renders each the footer using a default template
/// </summary>
///
// ********************************************************************/
private Control RenderFooterTemplate() {
Table table;
TableRow tr;
TableCell td;
table = new Table();
tr = new TableRow();
// Single column
td = new TableCell();
td.CssClass = "forumHeaderBackgroundAlternate";
td.Text = " ";
td.ColumnSpan = 6;
tr.Controls.Add(td);
table.Controls.Add(tr);
return table;
}
// *********************************************************************
// ApplyTemplates
//
/// <summary>
/// Applies templates to control the ui generated by the control. If no
/// template is specified a custom template is used. If a template is found
/// in the skins directory, that template is loaded and used. If a user defined
/// template is found, that template takes priority.
/// </summary>
///
// ********************************************************************/
private void ApplyTemplates() {
string pathToHeaderTemplate;
string pathToFooterTemplate;
string pathToItemTemplate;
string pathToAlternatingItemTemplate;
string keyForHeaderTemplate;
string keyForItemTemplate;
string keyForAlternatingItemTemplate;
string keyForFooterTemplate;
// Are we using skinned template?
if (Page != null) {
// Set the file paths to where the templates should be found
keyForHeaderTemplate = siteStyle + "/Templates/ThreadList-Header.ascx";
keyForItemTemplate = siteStyle + "/Templates/ThreadList-Item.ascx";
keyForAlternatingItemTemplate = siteStyle + "/Templates/ThreadList-AlternatingItem.ascx";
keyForFooterTemplate = siteStyle + "/Templates/ThreadList-Footer.ascx";
// Set the file paths to where the templates should be found
pathToHeaderTemplate = Globals.ApplicationVRoot + "/Skins/" + keyForHeaderTemplate;
pathToItemTemplate = Globals.ApplicationVRoot + "/Skins/" + keyForItemTemplate;
pathToAlternatingItemTemplate = Globals.ApplicationVRoot + "/Skins/" + keyForAlternatingItemTemplate;
pathToFooterTemplate = Globals.ApplicationVRoot + "/skins/" + keyForFooterTemplate;
// Attempt to get the skinned header template
if (HeaderTemplate == null)
HeaderTemplate = Globals.LoadSkinnedTemplate(pathToHeaderTemplate, keyForHeaderTemplate, Page);
// Attempt to get the skinned item template
if (ItemTemplate == null)
ItemTemplate = Globals.LoadSkinnedTemplate(pathToItemTemplate, keyForItemTemplate, Page);
// Attempt to get the skinned alternating item template
if (AlternatingItemTemplate == null)
AlternatingItemTemplate = Globals.LoadSkinnedTemplate(pathToAlternatingItemTemplate, keyForAlternatingItemTemplate, Page);
// Attempt to get the footer template
if (FooterTemplate == null)
FooterTemplate = Globals.LoadSkinnedTemplate(pathToFooterTemplate, keyForFooterTemplate, Page);
}
// If the item template is null we force our view
if (ItemTemplate == null) {
ExtractTemplateRows = true;
HeaderTemplate = new CompiledTemplateBuilder(new BuildTemplateMethod(BuildHeaderTemplate));
ItemTemplate = new CompiledTemplateBuilder(new BuildTemplateMethod(BuildItemTemplate));
FooterTemplate = new CompiledTemplateBuilder(new BuildTemplateMethod(BuildFooterTemplate));
}
}
// *********************************************************************
// BuildHeaderTemplate
//
/// <summary>
/// This function is called to create the template for the header
/// </summary>
///
// ********************************************************************/
private void BuildHeaderTemplate(Control _ctrl) {
System.Web.UI.IParserAccessor __parser = ((System.Web.UI.IParserAccessor)(_ctrl));
__parser.AddParsedSubObject(RenderHeaderTemplate());
}
// *********************************************************************
// BuildItemTemplate
//
/// <summary>
/// This function is called to create the template for the header
/// </summary>
///
// ********************************************************************/
private void BuildItemTemplate(Control _ctrl) {
System.Web.UI.IParserAccessor __parser = ((System.Web.UI.IParserAccessor)(_ctrl));
__parser.AddParsedSubObject(RenderItemTemplate());
}
// *********************************************************************
// BuildFooterTemplate
//
/// <summary>
/// This function is called to create the template for the footer
/// </summary>
///
// ********************************************************************/
private void BuildFooterTemplate(Control _ctrl) {
System.Web.UI.IParserAccessor __parser = ((System.Web.UI.IParserAccessor)(_ctrl));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -