📄 postview.cs
字号:
} else {
newThreadLink.Text = " New Thread ";
}
}
}
// *********************************************************************
// InitializePostListControlTemplate
//
/// <summary>
/// Render the post list view
/// </summary>
///
// ********************************************************************/
private void InitializePostListControlTemplate() {
// Initialize common display elements
InitializeCommonTemplateItems();
// Find the postList control
postList = (PostList) controlTemplate.FindControl("PostList");
// Ascending or descending
sortOrder = (DropDownList) controlTemplate.FindControl("SortOrder");
if (sortOrder != null) {
if (user != null)
sortOrder.Items.FindByValue(Convert.ToInt32(user.ShowPostsAscending).ToString()).Selected = true;
sortOrder.AutoPostBack = true;
sortOrder.SelectedIndexChanged += new System.EventHandler(SortOrder_Changed);
}
// Find the pager
pager = (Paging) controlTemplate.FindControl("Pager");
pager.PageIndex_Changed += new System.EventHandler(PageIndex_Changed);
// Get the total records used in the pager
pager.TotalRecords = Threads.GetTotalPostsForThread(PostID);
// Set the datasource
// If we're in a post back someone else probably wants to render the view
// Set the datasource
if (user != null) {
postList.DataSource = Posts.GetThreadByPostID(PostID, pager.PageIndex, pager.PageSize, 0, Convert.ToInt32(user.ShowPostsAscending));
Posts.MarkPostAsRead(PostID, user.Username);
} else {
postList.DataSource = Posts.GetThreadByPostID(PostID, pager.PageIndex, pager.PageSize, 0, Convert.ToInt32(sortOrder.SelectedItem.Value));
}
}
// *********************************************************************
// SortOrder_Changed
//
/// <summary>
/// Event handler used when the user wants to toggle between flat and
/// threaded view.
/// </summary>
///
// ********************************************************************/
private void SortOrder_Changed(Object sender, EventArgs e) {
postList.DataSource = Posts.GetThreadByPostID(PostID, pager.PageIndex, pager.PageSize, 0, Convert.ToInt32(sortOrder.SelectedItem.Value));
}
// *********************************************************************
// DisplayMode_Changed
//
/// <summary>
/// Event handler used when the user wants to toggle between flat and
/// threaded view.
/// </summary>
///
// ********************************************************************/
private void DisplayMode_Changed(Object sender, EventArgs e) {
if (displayMode.SelectedItem.Value == "Threaded") {
ViewMode = ViewOptions.Threaded;
} else {
ViewMode = ViewOptions.Flat;
}
// Display the appropriate view
SetViewMode();
}
// *********************************************************************
// Toggle_ThreadTracking
//
/// <summary>
/// Event raised when the user wants to enable or disable thread tracking
/// </summary>
///
// ********************************************************************/
private void Toggle_ThreadTracking(Object sender, EventArgs e) {
Posts.ReverseThreadTrackingOptions(user.Username, PostID);
}
// *********************************************************************
// PageIndex_Changed
//
/// <summary>
/// Event raised when the selected index of the page has changed.
/// </summary>
///
// ********************************************************************/
private void PageIndex_Changed(Object sender, EventArgs e) {
// Set the datasource
postList.DataSource = Posts.GetThreadByPostID(PostID, pager.PageIndex, pager.PageSize, 0, Convert.ToInt32(sortOrder.SelectedItem.Value));
}
// *********************************************************************
// OnPreRender
//
/// <summary>
/// Override OnPreRender and databind
/// </summary>
///
// ********************************************************************/
protected override void OnPreRender(EventArgs e) {
DataBind();
}
/// <summary>
/// Specifies the ID for the post that you wish to view.
/// </summary>
/// <remarks>If this property is not specified, an Exception will be thrown. If the PostID
/// passed in refrences a post that does not exist, or one that has been posted to a moderated
/// forum and has not yet been approved, the user will be automatically redirected to a message
/// page explaining the situation.</remarks>
[
Category("Required"),
Description("Specifies the ID for the post that you wish to view.")
]
public int PostID {
get {
// the postID is stuffed in the ViewState so that
// it is persisted across postbacks.
if (ViewState["postID"] == null)
return -1; // if it's not found in the ViewState, return the default value
return Convert.ToInt32(ViewState["postID"].ToString());
}
set {
// set the viewstate
ViewState["postID"] = value;
}
}
/// <summary>
/// Specifies whether or not to show the poster's Signature in the post body content.
/// </summary>
[
Category("Style"),
Description("Specifies whether or not to show the poster's Signature in the post body content."),
DefaultValue(true)
]
public bool ShowSignature {
get {
if (ViewState["showSignature"] == null)
return defaultShowSignature;
return (bool) ViewState["showSignature"];
}
set { ViewState["showSignature"] = value; }
}
/// <summary>
/// Indicates whether or not to show all of the messages in this thread.
/// </summary>
[
Category("Style"),
Description("Indicates whether or not to show all of the messages in this thread.")
]
public ViewOptions ViewMode {
get {
/*
if (user != null) {
if (user.ViewPostsInFlatView)
return ViewOptions.Threaded;
else
return ViewOptions.Flat;
} else {
*/
if (ViewState["PostViewMode"] == null)
return postView;
else
return (ViewOptions) ViewState["PostViewMode"];
// }
}
set {
/*
if (user != null)
Users.ToggleOptions(user.Username, user.HideReadThreads, value);
else
*/
ViewState["PostViewMode"] = value;
}
}
/// <summary>
/// Specifies the date/time format to display the post date in.
/// The string should contain valid DateTimeFormatInfo characters. For example, to display the
/// date range as MM/DD/YYYY - HH:MM AM/PM, use the string: MM/dd/yyyy - HH:mm tt
/// </summary>
[
Category("Style"),
Description("Specifies the date/time format to display the post date in."),
DefaultValue("MMM d, yyyy - h:mm tt")
]
public String PostDateTimeFormat {
get { return defaultPostDateTimeFormat; }
set { defaultPostDateTimeFormat = value; }
}
// *********************************************************************
// Threshhold
//
/// <summary>
/// Controls the depth at which the body of the thread is no longer displayed
/// </summary>
///
// ********************************************************************/
[
Description("Controls the depth at which the body of the thread is no longer displayed.")
]
public int ThreshHoldForThreadedView {
get { return threshHold; }
set {threshHold = value; }
}
public string TemplateName {
get { return templateName; }
set { templateName = value; }
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -