?? moderatedforums.cs
字號:
/***************************** ModeratedForums Web control **********************************
*
* SUMMARY:
* This Web control has two purposes: it can display the forums that a particular user can
* moderate, and provide a means for the end user to add and remove from this list of forums
* that can be moderated by a particular user; also, it can list the users that can moderate
* a particular forum. However, this control does not allow for users to be added and removed
* as moderators for a particular forum.
*
* GENERAL COMMENTS:
* Chances are, the end developer will never need to use this control from a page itself.
* An instance of this control is created in both the UserAdmin and EditForum user
* controls.
*
******************************************************************************************/
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Web;
using System.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetForums;
using AspNetForums.Components;
using System.ComponentModel;
namespace AspNetForums.Controls.Moderation {
[ ToolboxItemAttribute(false) ]
/// <summary>
/// This Web control has two purposes: it can display the forums that a particular user can
/// moderate, and provide a means for the end user to add and remove from this list of forums
/// that can be moderated by a particular user; also, it can list the users that can moderate
/// a particular forum. However, this control does not allow for users to be added and removed
/// as moderators for a particular forum.
/// </summary>
/// <remarks>Chances are, the end developer will never need to use this control from a page itself.
/// An instance of this control is created in both the UserAdmin and EditForum user
/// controls.</remarks>
public class ModeratedForums : WebControl, INamingContainer {
/********** DECLARE PRIVATE CONSTANTS **************/
// the default ModeratedForumMode setting
const ModeratedForumMode _defaultMode = ModeratedForumMode.ViewForUser;
const int _defaultCellPadding = 3; // the default cell padding for the datagrid
const int _defaultCellSpacing = 0; // the default cell spacing for the datagrid
readonly String _defaultForUserDataGridTitle = "Currently Moderator of the Following Forums:" + Globals.HtmlNewLine;
readonly String _defaultForForumDataGridTitle = "This Forum Currently is Moderated by the Following Users:" + Globals.HtmlNewLine;
/***************************************************/
/********** DECLARE PRIVATE VARIABLES **************/
// Create the styles
TableItemStyle _headerStyle = new TableItemStyle(); // the style for the datagrid's header
TableItemStyle _itemStyle = new TableItemStyle(); // the style for each item in the datagrid
// Create the datagrid
DataGrid dgModeratedForums;
/***************************************************/
/***********************************************************************
CreateChildControls Event Handler
---------------------------------
This event handler adds the children controls.
************************************************************************/
protected override void CreateChildControls() {
if (this.CheckUserPermissions && !((User) Users.GetUserInfo(Context.User.Identity.Name, true)).IsAdministrator)
// this user isn't an administrator
Context.Response.Redirect(Globals.UrlMessage + Convert.ToInt32(Messages.UnableToAdminister));
// make sure we have a username/forumID
if (Mode == ModeratedForumMode.ViewForUser && Username.Length == 0)
throw new Exception("When specifying Mode as ViewForUser you must pass in the Username of the user whose forum moderation informaion you wish to view.");
if (Mode == ModeratedForumMode.ViewForForum && ForumID == -1)
throw new Exception("When specifying Mode as ViewForForum you must pass in the ForumID of the forum whose moderators you wish to view.");
// add the title
Label lblTmp = new Label();
lblTmp.CssClass = "head";
lblTmp.Text = DataGridTitle + Globals.HtmlNewLine;
Controls.Add(lblTmp);
// add the datagrid
dgModeratedForums = new DataGrid();
dgModeratedForums.AutoGenerateColumns = false;
dgModeratedForums.CellPadding = CellPadding;
dgModeratedForums.CellSpacing = CellSpacing;
dgModeratedForums.ItemCommand += new DataGridCommandEventHandler(dgModeratedForums_RemoveForum);
// build up the DataGrid's columns
BuildDataGridColumns();
Controls.Add(dgModeratedForums);
// if we are viewing this from the User Admin page (that is, we are viewing a list of the
// forums administrated by a particular user), then we need to show the panel that allows
// the end user to add/remove forums that this particular user can administer.
if (Mode == ModeratedForumMode.ViewForUser) {
Panel tmpPanel = new Panel();
tmpPanel.ID = "panelAddForum";
// add the listbox that lists the forums that the user can add
tmpPanel.Controls.Add(new LiteralControl(Globals.HtmlNewLine + "<b>Add a Forum for this User to Moderate:</b>" + Globals.HtmlNewLine));
ListBox lstTmp = new ListBox();
lstTmp.ID = "lstForums";
lstTmp.Rows = 1;
lstTmp.CssClass = "normalListbox";
lstTmp.DataValueField = "ForumID";
lstTmp.DataTextField = "Name";
tmpPanel.Controls.Add(lstTmp);
CheckBox chkTmp = new CheckBox();
chkTmp.ID = "chkEmailNotification";
chkTmp.Checked = true;
tmpPanel.Controls.Add(chkTmp);
tmpPanel.Controls.Add(new LiteralControl("Receive Email Notification when a New Post Needs to be Moderated..." + Globals.HtmlNewLine));
// add a submit button
Button btnTmp = new Button();
btnTmp.Text = "Add Forum";
btnTmp.CssClass = "normalButton";
btnTmp.ToolTip = "Click to add the selected forum to this user's list of moderateable forums.";
btnTmp.Click += new EventHandler(btnAddForum_Click);
btnTmp.ID = "btnAddForum";
tmpPanel.Controls.Add(btnTmp);
Controls.Add(tmpPanel);
}
else {
// add a label that explains to moderate the users of a forum, you
// must visit the user's admin page
lblTmp = new Label();
lblTmp.Text = Globals.HtmlNewLine + "In order to alter the moderators for this forum, you must visit the administration page for the specific user.";
lblTmp.CssClass = "warning";
Controls.Add(lblTmp);
}
}
/***********************************************************************
btnAddForum_Click Event Handler
-------------------------------
This event handler is fired when the user clicks on the Add Forum button.
It needs to add a new forum to this users list of moderatable forums.
Fortunately, the AddModeratedForumForUser statis method of the Users
class does all of the nitty gritty work for us.
************************************************************************/
private void btnAddForum_Click(Object sender, EventArgs e) {
// add to the users list of acceptable forums the selected forum
int iForumID = Convert.ToInt32(((ListBox) FindControl("lstForums")).SelectedItem.Value);
bool bolEmailNotification = ((CheckBox) FindControl("chkEmailNotification")).Checked;
ModeratedForum forum = new ModeratedForum();
forum.Username = Username;
forum.ForumID = iForumID;
forum.EmailNotification = bolEmailNotification;
Users.AddModeratedForumForUser(forum);
// rebind the datagrid
RebindData();
}
/***********************************************************************
void BuildDataGridColumns function
----------------------------------
This helper function builds up the columns for the datagrid. The columns
that are built-up depend on whether the page is being viewed for a particular
user or for a particular forum. If for a user, four columns are constructed:
1.) The Remove Button
2.) A hidden column that stores the Forum's ID
3.) The name of the forum that is moderated
4.) The date the user was assigned to moderate this forum
If we are viewing the users who moderate a particular forum, only two
columns are created - the Username of each of the forum's moderators, and
the Date/Time they were given moderation privledges.
************************************************************************/
private void BuildDataGridColumns() {
ButtonColumn btcolTmp;
BoundColumn bndcolTmp;
if (Mode == ModeratedForumMode.ViewForUser) {
// add the pushbutton to remove existing forums, but only if we are viewing
// the list of forums moderated by a particular user
btcolTmp = new ButtonColumn();
btcolTmp.ButtonType = ButtonColumnType.PushButton;
btcolTmp.Text = "Remove";
btcolTmp.HeaderStyle.CopyFrom(this._headerStyle);
btcolTmp.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
btcolTmp.ItemStyle.CssClass = "normalButton";
btcolTmp.HeaderText = "Remove";
dgModeratedForums.Columns.Add(btcolTmp);
// add a hidden bound column to perserve the forum id to remove
bndcolTmp = new BoundColumn();
bndcolTmp.Visible = false;
bndcolTmp.DataField = "ForumID";
dgModeratedForums.Columns.Add(bndcolTmp);
// display the forumname
bndcolTmp = new BoundColumn();
bndcolTmp.HeaderStyle.CopyFrom(this._headerStyle);
bndcolTmp.ItemStyle.CopyFrom(this._itemStyle);
bndcolTmp.DataField = "Name";
bndcolTmp.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
bndcolTmp.HeaderText = "Forum";
dgModeratedForums.Columns.Add(bndcolTmp);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -