📄 adminforumpostlisting.cs
字号:
// ********************************************************************/
private void BindData() {
PostCollection posts;
// Make sure all of our child controls have been created
this.EnsureChildControls();
// Get info about the forum
Forum forum = Forums.GetForumInfo(ForumID);
int iUserTimeZone = Globals.DBTimezone;
// Read in user information, if applicable and set iUserTimeZone
if (Context.User.Identity.Name.Length > 0)
iUserTimeZone = ((User) Users.GetUserInfo(Context.User.Identity.Name, true)).Timezone;
// Get all of the messages for the forum
if (ViewMode == ViewOptions.NotSet)
posts = Posts.GetAllMessages(ForumID, ViewOptions.Threaded, 0);
else
posts = Posts.GetAllMessages(ForumID, ViewMode, 0);
// Bind the data
dlForumView.DataSource = posts;
dlForumView.DataBind();
}
// *********************************************************************
//
// CreateChildControls
//
/// <summary>
/// This event handler adds the children controls.
/// </summary>
//
// ********************************************************************/
protected override void CreateChildControls() {
Panel panelTmp;
Label lblTmp;
Button btnTmp;
// Is this user an administrator?
if (this.CheckUserPermissions && !((User) Users.GetUserInfo(Context.User.Identity.Name, true)).IsAdministrator)
Context.Response.Redirect(Globals.UrlMessage + Convert.ToInt32(Messages.UnableToAdminister));
// Make sure we have a valid ForumID
if (ForumID == -1)
throw new Exception("The ForumView control requires that you pass in a valid ForumID. No such value was passed in.");
// Create the panel
panelTmp = new Panel();
panelTmp.ID = "panelPosts";
// if the user indicated to show the forum title, do that now.
if (ShowForumTitle) {
lblTmp = new Label();
lblTmp.ID = "txtForumTitle";
lblTmp.CssClass = "head";
panelTmp.Controls.Add(lblTmp);
}
// add a Refresh button
btnTmp = new Button();
btnTmp.CssClass = "normalButton";
btnTmp.Text = "Refresh Post Listings for this Forum";
btnTmp.ToolTip = "Click to update the below view of posts for this forum.";
btnTmp.Click += new EventHandler(ButtonRefresh_Click);
panelTmp.Controls.Add(btnTmp);
// Add to the control collection of the panel
panelTmp.Controls.Add(dlForumView);
// Add the panel to the parent controls collection
Controls.Add(panelTmp);
// create the confirm delete panel
CreateConfirmDeletePanel();
}
// *********************************************************************
//
// OnPreRender Event Handler
//
/// <summary>
/// This event handler binds the template to the datalist - this action
/// is only carried out if the user DID NOT specify an ItemTemplate.
/// In such a case, the default databinding is used.
/// </summary>
/// <param name="e"></param>
//
// ********************************************************************/
protected override void OnPreRender(EventArgs e) {
// bind the data on our first load
if (!Page.IsPostBack)
BindData();
}
// *********************************************************************
//
// OnPreRender Event Handler
//
/// <summary>
/// This event handler fires when the user clicks the Refresh button. All
/// we need to do is rebind the data.
/// </summary>
//
// ********************************************************************/
private void ButtonRefresh_Click(Object sender, EventArgs e) {
BindData();
}
// *********************************************************************
//
// PostAction_Click Event Handler
//
/// <summary>
/// This event handler fires when the user clicks one of the two ImageButtons
/// (edit/delete) or when the user clicks the "Confirm Delete" button in
/// the Confirm Delete panel. Appropriate action is taken based upon
/// the user's command.
/// </summary>
//
// ********************************************************************/
private void PostAction_Click(Object sender, CommandEventArgs e) {
// Read in the postID
int iPostID = Convert.ToInt32(e.CommandArgument);
// Decide what action to take
switch (e.CommandName) {
// Edit the post, so send the user to the proper URL
case "edit":
Context.Response.Redirect(Globals.UrlEditPostFromAdmin + iPostID.ToString() + "&ForumID=" + ForumID.ToString());
break;
// Delete the post, hide/show the appropriate panels
case "delete":
((Panel) FindControl("panelConfirmDelete")).Visible = true;
((Panel) FindControl("panelPosts")).Visible = false;
// set the Confirm Delete button's CommandArgument to the PostID passed in
((Button) FindControl("btnConfirmDelete")).CommandArgument = iPostID.ToString();
break;
// Delete the post
case "confirmdelete":
if (deletePostStyle.ShowReasonsForDeletingTextBox)
Posts.DeletePost(iPostID, ((TextBox) FindControl("txtDeleteReason")).Text, "undone");
else
Posts.DeletePost(iPostID, "undone", "undone");
// Show the posts
((Panel) FindControl("panelConfirmDelete")).Visible = false;
((Panel) FindControl("panelPosts")).Visible = true;
// rebind the data
BindData();
break;
}
}
// *********************************************************************
//
// ButtonCancelDelete_Click Event Handler
//
/// <summary>
/// This event handler fires when the user clicks the Cancel Delete button.
/// It hides/shows the appropriate panels and rebinds the data.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
//
// ********************************************************************/
private void ButtonCancelDelete_Click(Object sender, EventArgs e) {
// flip the panel visibility back
((Panel) FindControl("panelConfirmDelete")).Visible = false;
((Panel) FindControl("panelPosts")).Visible = true;
// rebind the data
this.BindData();
}
// *********************************************************************
//
// CreateConfirmDeletePanel
//
/// <summary>
/// This function creates the controls for the delete post panel. The Delete
/// Post panel is displayed when the user clicks on the "Delete Post" link.
/// It pops up two buttons, a cancel and confirm, allowing the user to
/// ensure that they do, indeed, want to delete the post.
/// </summary>
///
// ********************************************************************/
void CreateConfirmDeletePanel() {
// Start off by creating the panel control
Panel panelTmp = new Panel();
panelTmp.ID = "panelConfirmDelete";
panelTmp.Visible = false;
Label lblTmp;
Button btnTmp;
panelTmp.Controls.Add(new LiteralControl("<table class=\"postText\" align=\"center\" border=\"0\"><tr><th>\n"));
// Create the header title
lblTmp = new Label();
lblTmp.Text = "DELETING A MESSAGE";
lblTmp.CssClass = "head";
panelTmp.Controls.Add(lblTmp);
panelTmp.Controls.Add(new LiteralControl("\n</th></tr>\n<tr><td align=\"center\">"));
// Display the reasons why (or why not) to delete the post. Also notify the user that
// deleting a post will delete all of its children (replies).
lblTmp = new Label();
lblTmp.Text = deletePostStyle.DeletePostText + Globals.HtmlNewLine + Globals.HtmlNewLine +
"<b>Also, all of this post's replies will be deleted as well.</b>" + Globals.HtmlNewLine + Globals.HtmlNewLine ;
lblTmp.ApplyStyle(deletePostStyle);
panelTmp.Controls.Add(lblTmp);
// Create the cancel button
btnTmp = new Button();
btnTmp.ID = "btnCancelDelete";
btnTmp.Text = "Cancel Delete";
btnTmp.CssClass = "normalButton";
btnTmp.ToolTip = "Click this to cancel the delete, leaving this post in-tact.";
btnTmp.Click += new EventHandler(ButtonCancelDelete_Click);
panelTmp.Controls.Add(btnTmp);
panelTmp.Controls.Add(new LiteralControl(" "));
// Create the confirm button
btnTmp = new Button();
btnTmp.ID = "btnConfirmDelete";
btnTmp.Text = "Confirm Delete";
btnTmp.CssClass = "normalButton";
btnTmp.ToolTip = "Click this to permanently delete the post.";
btnTmp.Command += new CommandEventHandler(PostAction_Click);
btnTmp.CommandName = "confirmdelete";
panelTmp.Controls.Add(btnTmp);
// Display a textbox for the reason why a post was deleted,
// only if ShowReasonsForDeletingTextBox is true
if (deletePostStyle.ShowReasonsForDeletingTextBox) {
// Show the "Reasons for Deleting" message
lblTmp = new Label();
lblTmp.Text += Globals.HtmlNewLine + Globals.HtmlNewLine + deletePostStyle.ReasonsTextBoxMessage + Globals.HtmlNewLine;
lblTmp.ApplyStyle(deletePostStyle);
panelTmp.Controls.Add(lblTmp);
// Create the reasons textbox
TextBox txtTmp = new TextBox();
txtTmp.ID = "txtDeleteReason";
txtTmp.TextMode = TextBoxMode.MultiLine;
txtTmp.ApplyStyle(deletePostStyle);
txtTmp.Columns = deletePostStyle.ReasonsTextBoxColumns;
txtTmp.Rows = deletePostStyle.ReasonsTextBoxRows;
panelTmp.Controls.Add(txtTmp);
panelTmp.Controls.Add(new LiteralControl("</td></tr><tr><td align=\"center\">\n\t"));
}
panelTmp.Controls.Add(new LiteralControl("\n</td></tr></table>"));
Controls.Add(panelTmp);
}
// *********************************************************************
//
// DisplayIndent
//
/// <summary>
/// This functions simply renders the html needed for the identation for
/// a particular item in a post. Only called if displaying a threaded forum
/// </summary>
/// <param name="iPostLevel"></param>
/// <returns>String</returns>
//
// ********************************************************************/
private String DisplayIndent(int iPostLevel) {
String retVal = "";
// if we're showing a new thread, display the thread separator
if (iPostLevel == 1)
retVal += ThreadSeparator;
// display the appropriate number of idents based on the PostLevel
for (int iLoop=0; iLoop < iPostLevel-1; iLoop++)
retVal += IndentString;
// Add the LiteralControl to the Controls collection
return retVal;
}
// *********************************************************************
//
// ForumID
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -