📄 forummembersview.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.Controls;
namespace CommunityServer.Discussions.Controls
{
/// <summary>
/// This server control is used to display all the members of the current forum.
/// </summary>
[
ParseChildren(true)
]
public class ForumMembersView : SkinnedWebControl
{
#region Member variables and constructor
protected Repeater userList;
protected LinkButtonPager pager;
protected AlphaPicker alphaPicker;
protected CurrentPage currentPage;
protected TextBox searchForUser;
protected Button searchButton;
protected MemberSortDropDownList sort;
protected SortOrderDropDownList sortOrder;
protected Label sectionTitle;
protected Label sectionDescription;
bool enableAlphaPicker = true;
bool includeEmailInFilter = false;
UserAccountStatus accountStatus = UserAccountStatus.Approved;
CSContext csContext = CSContext.Current;
HtmlTableRow accountStatusRow = null;
AccountStatusDropDownList currentAccountStatus = null;
// HtmlTableRow noRecordsRow = null;
UserSet userSet = null;
// Define the default skin for this control
private const string skinFilename = "View-ForumMembers.ascx";
// *********************************************************************
// ForumMembersView
//
/// <summary>
/// Constructor
/// </summary>
///
// ********************************************************************/
public ForumMembersView()
{
// Assign a default template name
if (SkinFilename == null)
SkinFilename = skinFilename;
}
#endregion
#region Render functions
// *********************************************************************
// InitializeControlTemplate
//
/// <summary>
/// Initializes the user control loaded in CreateChildControls. Initialization
/// consists of finding well known control names and wiring up any necessary events.
/// </summary>
///
// ********************************************************************/
override protected void InitializeSkin(Control skin)
{
// LN 5/20/04: Use AccountStatus Selector for Admin Mode only
//
if (Mode == ControlUserMode.Administrator || Mode == ControlUserMode.Moderator)
{
accountStatusRow = (HtmlTableRow) skin.FindControl("AccountStatusPanel");
if (accountStatusRow != null)
{
accountStatusRow.Visible = true;
currentAccountStatus = (AccountStatusDropDownList) skin.FindControl("CurrentAccountStatus");
if (currentAccountStatus != null)
{
currentAccountStatus.AutoPostBack = true;
currentAccountStatus.SelectedIndexChanged += new EventHandler(FilterChanged_Click);
if (!Page.IsPostBack)
currentAccountStatus.Items.FindByValue(accountStatus.ToString());
}
}
}
// Find the user list repeater
//
userList = (Repeater) skin.FindControl("UserList");
// Find the sort drop down list
//
sort = (MemberSortDropDownList) skin.FindControl("Sort");
sort.AutoPostBack = true;
sort.SelectedIndexChanged += new EventHandler(FilterChanged_Click);
// Find the sort order drop down list
//
sortOrder = (SortOrderDropDownList) skin.FindControl("SortOrder");
sortOrder.AutoPostBack = true;
sortOrder.SelectedIndexChanged += new EventHandler(FilterChanged_Click);
// Find the search textbox/button
//
searchForUser = (TextBox) skin.FindControl("SearchForUser");
searchButton = (Button) skin.FindControl("SearchButton");
// Do we have search text?
//
if ((!Page.IsPostBack) && csContext.QueryText != null)
{
SearchText = csContext.QueryText;
IsSearchMode = true;
}
// Set text
searchButton.Text = CommunityServer.Components.ResourceManager.GetString("ForumMembers_SearchButton");
// Find the Pager and current page controls
//
pager = (LinkButtonPager) skin.FindControl("Pager");
if(pager != null)
pager.IndexChanged +=new EventHandler(PageIndex_Changed);
currentPage = (CurrentPage) skin.FindControl("CurrentPage");
// Event wire-up
//
alphaPicker = (AlphaPicker) skin.FindControl("AlphaPicker");
alphaPicker.Letter_Changed += new EventHandler(FilterChanged_Click);
if (!EnableAlphaPicker)
alphaPicker.Visible = false;
searchButton.Click += new EventHandler(Search_Click);
// Set the title and description if they haven't been set by a derived class
//
if ((sectionTitle == null) && (sectionDescription == null))
{
// Swith the displayed text depending on the mode the control is in
//
sectionTitle = (Label) skin.FindControl("SectionTitle");
if (Mode == ControlUserMode.User)
sectionTitle.Text = ResourceManager.GetString("CommunityServerMembers_Inline1");
else if (Mode == ControlUserMode.Administrator)
sectionTitle.Text = ResourceManager.GetString("CommunityServerMembers_AdminTitle");
sectionDescription = (Label) skin.FindControl("SectionDescription");
if (Mode == ControlUserMode.User)
sectionDescription.Text = ResourceManager.GetString("CommunityServerMembers_Inline2");
else if (Mode == ControlUserMode.Administrator)
sectionDescription.Text = ResourceManager.GetString("CommunityServerMembers_AdminDescription");
}
// Only databind if we're not posting back
//
this.DataBind();
}
#endregion
#region Events
private void PageIndex_Changed(Object sender, EventArgs e)
{
DataBind();
}
// *********************************************************************
// Search_Click
//
/// <summary>
/// Event raised when searching for a user
/// </summary>
///
// ********************************************************************/
private void Search_Click(Object sender, EventArgs e)
{
if (Mode == ControlUserMode.User)
{
if (!CSContext.Current.SiteSettings.EnablePublicAdvancedMemberSearch)
{
if (searchForUser.Text.IndexOf("*") > 0)
Page.Response.Redirect( Globals.GetSiteUrls().Message(CSExceptionType.UserSearchNotFound), true );
}
csContext.Context.Response.Redirect( Globals.GetSiteUrls().SearchForUser( searchForUser.Text ));
csContext.Context.Response.End();
}
else if (Mode == ControlUserMode.Administrator)
{
csContext.Context.Response.Redirect( Globals.GetSiteUrls().SearchForUserAdmin( searchForUser.Text ));
csContext.Context.Response.End();
}
}
// *********************************************************************
// FilterChanged_Click
//
/// <summary>
/// Event raised when the filter conditions set during post-back change
/// </summary>
///
// ********************************************************************/
private void FilterChanged_Click(Object sender, EventArgs e)
{
// We are not in search mode
//
IsSearchMode = false;
// Clear the search text
//
searchForUser.Text = "";
// LN 5/20/04: Get selected account status in Admin Mode only
//
if ((Mode == ControlUserMode.Administrator || Mode == ControlUserMode.Moderator) &&
currentAccountStatus != null)
{
accountStatus = currentAccountStatus.SelectedValue;
}
// Reset the pager
//
pager.PageIndex = 0;
currentPage.PageIndex = 0;
DataBind();
}
#endregion
#region Databinding
public override void DataBind()
{
bool showHiddenUsers = false;
if (this.Mode == CommunityServer.Components.ControlUserMode.Administrator || this.Mode == CommunityServer.Components.ControlUserMode.Moderator)
showHiddenUsers = true;
if (Mode != ControlUserMode.User)
includeEmailInFilter = true;
pager.PageSize = CSContext.Current.SiteSettings.MembersPerPage;
// Are we in search mode?
//
if (IsSearchMode)
{
// Does the text box have data?
//
if (searchForUser.Text == string.Empty)
{
searchForUser.Text = SearchText;
}
else
{
SearchText = searchForUser.Text;
}
// TDD 3/6/04
// force a pull of all users if we are in admin mode
//
// EAD 6/27/04
// only cache if not admin/moderator
//
userSet = Users.GetUsers(pager.PageIndex, pager.PageSize, sort.SelectedSortOrder, sortOrder.SelectedValue, SearchText, includeEmailInFilter, (showHiddenUsers) ? false : true, accountStatus, true, showHiddenUsers );
}
else
{
// TDD 3/6/04
// force a pull of all users if we are in admin mode
//
// EAD 6/27/04
// only cache if not admin/moderator
//
userSet = Users.GetUsers(pager.PageIndex, pager.PageSize, sort.SelectedSortOrder, sortOrder.SelectedValue, alphaPicker.SelectedLetter, includeEmailInFilter, (showHiddenUsers) ? false : true, accountStatus, true, showHiddenUsers);
}
// EAD 6/27/2004: If in admin/moderator mode, we can not edit the user.
// This should show a list, even if just 1, so the user cna search again. Do not redirect.
//
// If this is a user search and we only have a single results, redirect to that user
//
// if ((IsSearchMode) && (userSet.TotalRecords == 1)) {
// Page.Response.Redirect( Globals.GetSiteUrls().UserProfile( ((User) userSet.Users[0]).UserID ));
// Page.Response.End();
// }
// remove the Anonymous user from being listed for administrators.
//
if (showHiddenUsers)
{
foreach (User testAnonUser in userSet.Users)
{
if (testAnonUser.UserID < 1)
{
userSet.Users.Remove(testAnonUser);
break;
}
}
}
userList.DataSource = userSet.Users;
userList.DataBind();
pager.TotalRecords = currentPage.TotalRecords = userSet.TotalRecords;
currentPage.TotalPages = pager.CalculateTotalPages();
currentPage.PageIndex = pager.PageIndex;
}
#endregion
#region Private properties
// *********************************************************************
// IsSearchMode
//
/// <summary>
/// Private property to determine if we're in search mode or doing a linear
/// walkthrough of users
/// </summary>
///
// ********************************************************************/
protected bool IsSearchMode
{
get
{
if (ViewState["SearchMode"] == null)
return false;
return (bool) ViewState["SearchMode"];
}
set
{
ViewState["SearchMode"] = value;
}
}
// *********************************************************************
// SearchText
//
/// <summary>
/// Private property u
/// </summary>
///
// ********************************************************************/
protected string SearchText
{
get
{
return (string) ViewState["SearchText"];
}
set
{
ViewState["SearchText"] = value;
}
}
#endregion
#region Public properties
public bool EnableAlphaPicker
{
get { return enableAlphaPicker; }
set { enableAlphaPicker = value; }
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -