📄 postlist.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Collections.Specialized;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetForums;
using AspNetForums.Controls.Moderation;
using AspNetForums.Components;
using System.ComponentModel;
namespace AspNetForums.Controls {
/// <summary>
/// This Web control displays a thread in a flat display. The developer must pass in
/// either a PostID. If a PostID is passed in, the thread that that Post belongs
/// to is constructed.
/// </summary>
[
ParseChildren(true)
]
public class PostList : 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 (HttpContext.Current.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;
// Apply Template
ApplyTemplates();
// Viewstate is disabled
EnableViewState = false;
}
// *********************************************************************
// HandleDataBindingForPostCell
//
/// <summary>
/// Databinds the post cell
/// </summary>
/// <remarks>
/// Used only if a user defined template is not provided.
/// </remarks>
///
// ********************************************************************/
private void HandleDataBindingForPostCell(Object sender, EventArgs e) {
Table table;
TableRow tr;
TableCell td;
Label label;
string dateFormat;
DateTime postDateTime;
User postUser;
// Get the sender
TableCell postInfo = (TableCell) sender;
DataListItem container = (DataListItem) postInfo.NamingContainer;
Post post = (Post) container.DataItem;
// Get the user that created the post
postUser = Users.GetUserInfo(post.Username, false);
// Create the table
table = new Table();
table.CellPadding = 3;
table.CellSpacing = 0;
table.Width = Unit.Percentage(100);
// Row 1
tr = new TableRow();
td = new TableCell();
td.CssClass = "forumRowHighlight";
// Add in Subject
label = new Label();
label.CssClass = "normalTextSmallBold";
label.Text = post.Subject + "<a name=\"" + post.PostID + "\"/>";
td.Controls.Add(label);
td.Controls.Add(new LiteralControl("<br>"));
// Add in 'Posted: '
label = new Label();
label.CssClass = "normalTextSmaller";
label.Text = " Posted: ";
td.Controls.Add(label);
// Get the postDateTime
postDateTime = post.PostDate;
// Personalize
if (user != null) {
dateFormat = user.DateFormat;
postDateTime = Users.AdjustForTimezone(postDateTime, user);
} else {
dateFormat = Globals.DateFormat;
}
// Add in PostDateTime
label = new Label();
label.CssClass = "normalTextSmaller";
label.Text = postDateTime.ToString(dateFormat + " " + Globals.TimeFormat);
td.Controls.Add(label);
// Add row 1
tr.Controls.Add(td);
table.Controls.Add(tr);
// Row 2 (body)
tr = new TableRow();
td = new TableCell();
// Add Body
label = new Label();
label.CssClass = "normalTextSmall";
label.Text = Globals.FormatPostBody(post.Body);
td.Controls.Add(label);
// Add row 2
tr.Controls.Add(td);
table.Controls.Add(tr);
// Row 3 (Signature)
tr = new TableRow();
td = new TableCell();
label = new Label();
label.CssClass = "normalTextSmaller";
if (postUser.Signature != "") {
label.Text = Globals.FormatSignature(postUser.Signature);
}
td.Controls.Add(label);
tr.Controls.Add(td);
table.Controls.Add(tr);
// Add whitespace
tr = new TableRow();
td = new TableCell();
td.Height = 2;
tr.Controls.Add(td);
table.Controls.Add(tr);
// Add buttons for user options
tr = new TableRow();
td = new TableCell();
// Add the reply button
if (!post.IsLocked) {
// Reply button
HyperLink replyButton = new HyperLink();
replyButton.Text = "<img border=0 src=" + Globals.ApplicationVRoot + "/skins/" + Globals.Skin + "/images/newpost.gif" + ">";
replyButton.NavigateUrl = Globals.UrlReplyToPost + post.PostID + "&mode=flat";
td.Controls.Add(replyButton);
}
if ((user != null) && (user.Username.ToLower() == post.Username.ToLower()) && (user.IsTrusted)) {
// Edit button
HyperLink editButton = new HyperLink();
editButton.Text = "<img border=0 src=" + Globals.ApplicationVRoot + "/skins/" + Globals.Skin + "/images/editpost.gif" + ">";
editButton.NavigateUrl = Globals.UrlUserEditPost + post.PostID;
td.Controls.Add(editButton);
}
// Anything to add to the table control?
if (td.Controls.Count > 0) {
tr.Controls.Add(td);
table.Controls.Add(tr);
}
// Is the current user a moderator?
if ((user != null) && (user.IsModerator)) {
tr = new TableRow();
td = new TableCell();
// Find the moderation menu
ModerationMenu moderationMenu = new ModerationMenu();
moderationMenu.PostID = post.PostID;
moderationMenu.ThreadID = post.ThreadID;
moderationMenu.UsernamePostedBy = post.Username;
moderationMenu.SkinFilename = "Moderation/Skin-ModeratePost.ascx";
td.Controls.Add(moderationMenu);
tr.Controls.Add(td);
table.Controls.Add(tr);
}
postInfo.Controls.Add(table);
}
// *********************************************************************
// HandleDataBindingForAuthorCell
//
/// <summary>
/// Databinds the name of the author.
/// </summary>
/// <remarks>
/// Used only if a user defined template is not provided.
/// </remarks>
///
// ********************************************************************/
private void HandleDataBindingForAuthorCell(Object sender, EventArgs e) {
TableCell userInfo = (TableCell) sender;
DataListItem container = (DataListItem) userInfo.NamingContainer;
Post post = (Post) container.DataItem;
User user;
HyperLink link;
Label label;
Image image;
Uri url;
// Get the user object - note, we are using
// the cache under the covers, so this doesn't
// result in a db lookup for each request
user = Users.GetUserInfo(post.Username, false);
// Build user info table
Table table = new Table();
TableRow tr;
TableCell td;
// Author
tr = new TableRow();
td = new TableCell();
label = new Label();
label.CssClass = "normalTextSmallBold";
label.Text = user.Username;
td.Controls.Add(label);
tr.Controls.Add(td);
table.Controls.Add(tr);
// About
tr = new TableRow();
td = new TableCell();
link = new HyperLink();
link.CssClass = "normalTextSmaller";
link.NavigateUrl = Globals.UrlUserProfile + user.Username;
link.Text = "Profile";
td.Controls.Add(link);
// whitespace
td.Controls.Add(new LiteralControl("<br>"));
// Web Site
if (user.Url != "") {
url = new Uri(user.Url);
link = new HyperLink();
link.CssClass = "normalTextSmaller";
link.NavigateUrl = user.Url;
link.Text = url.Host;
link.Target = "_new";
td.Controls.Add(link);
}
tr.Controls.Add(td);
table.Controls.Add(tr);
// Do we have any Icon for the user?
if ((user.HasIcon) && (user.ShowIcon)) {
tr = new TableRow();
td = new TableCell();
image = new Image();
image.Width = 80;
image.Height = 80;
image.ImageUrl = user.ImageUrl;
td.Controls.Add(image);
tr.Controls.Add(td);
table.Controls.Add(tr);
}
// Top 25 user?
if (Users.IsTop25User(user.Username)) {
tr = new TableRow();
td = new TableCell();
image = new Image();
image.ImageUrl = Globals.ApplicationVRoot + "/skins/" + siteStyle + "/images/users_top25.gif";
image.AlternateText = "Top 25 Poster";
td.Controls.Add(image);
tr.Controls.Add(td);
table.Controls.Add(tr);
// Top 50 user?
} else if (Users.IsTop50User(user.Username)) {
tr = new TableRow();
td = new TableCell();
image = new Image();
image.ImageUrl = Globals.ApplicationVRoot + "/skins/" + siteStyle + "/images/users_top50.gif";
image.AlternateText = "Top 50 Poster";
td.Controls.Add(image);
tr.Controls.Add(td);
table.Controls.Add(tr);
} else if (Users.IsTop100User(user.Username)) {
tr = new TableRow();
td = new TableCell();
image = new Image();
image.ImageUrl = Globals.ApplicationVRoot + "/skins/" + siteStyle + "/images/users_top100.gif";
image.AlternateText = "Top 100 Poster";
td.Controls.Add(image);
tr.Controls.Add(td);
table.Controls.Add(tr);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -