📄 forumadmin.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.Controls;
using CommunityServer.Discussions.Components;
namespace CommunityServer.Discussions.Controls
{
public class ForumAdmin : TemplatedWebControl
{
#region ChildControls
private TextBox Name;
private TextBox AutoDeleteThreshold;
private TextBox Description;
private TextBox NavigateUrl; // 新增
private ForumTypeDropDownList forumType; // 新增
private ForumListBox ParentID;
private RadioButtonList IsActive;
private RadioButtonList IsSearchable;
private RadioButtonList IsModerated;
private RadioButtonList EnablePostStatistics;
private RadioButtonList EnableAutoDelete;
private RadioButtonList EnableAnonymousPosting;
private RadioButtonList EnableAnonymousPostingForUsers;
private Button Save;
private Button Delete;
private Button Moderators;
#endregion
protected override void OnLoad(EventArgs e)
{
if ( !Page.IsPostBack )
{
this.DataBind();
}
base.OnLoad (e);
}
protected override void AttachChildControls()
{
Name = (TextBox)FindControl("Name");
Description = (TextBox)FindControl("Description");
ParentID = (ForumListBox)FindControl("ParentID");
ParentID.ShowEmptyForumGroups = true;
// 新增
NavigateUrl = (TextBox)FindControl("NavigateUrl");
forumType = (ForumTypeDropDownList)FindControl("ForumType");
IsActive = (RadioButtonList)FindControl("IsActive");
IsSearchable = (RadioButtonList)FindControl("IsSearchable");
IsModerated = (RadioButtonList)FindControl("IsModerated");
EnablePostStatistics = (RadioButtonList)FindControl("EnablePostStatistics");
EnableAutoDelete = (RadioButtonList)FindControl("EnableAutoDelete");
AutoDeleteThreshold = (TextBox)FindControl("AutoDeleteThreshold");
EnableAnonymousPosting = (RadioButtonList)FindControl("EnableAnonymousPosting");
EnableAnonymousPostingForUsers = (RadioButtonList)FindControl("EnableAnonymousPostingForUsers");
Save = (Button)FindControl("Save");
Delete = (Button)FindControl("Delete");
Moderators = (Button)FindControl("Moderators");
Save.Click +=new EventHandler( Save_Click );
Delete.Click +=new EventHandler( Delete_Click );
Moderators.Click +=new EventHandler( Moderators_Click );
}
public override void DataBind()
{
base.DataBind();
Save.Text = CommunityServer.Components.ResourceManager.GetString("Save");
Delete.Text = CommunityServer.Components.ResourceManager.GetString("Delete");
Delete.Attributes["onclick"] = "if ( !confirm('" + ResourceManager.GetString("CreateEditForums_DeleteForumVerify").Replace("'", @"\'") + "') ) {return false; } ";
Moderators.Text = CommunityServer.Components.ResourceManager.GetString("ForumAdmin_ManageModerators");
Forum targetForum = Forums.GetForum( CSContext.Current.ForumID, false, true, CSContext.Current.UserID );
this.LoadForum( targetForum );
}
protected virtual void LoadForum( Forum forum )
{
if ( forum != null )
{
IsActive.Items.FindByValue( forum.IsActive.ToString() ).Selected = true;
Name.Text = forum.Name.ToString();
Description.Text = forum.Description.ToString();
//新增
NavigateUrl.Text = forum.NavigateUrl;
forumType.SelectedValue = forum.ForumType;
IsModerated.Items.FindByValue( forum.IsModerated.ToString() ).Selected = true;
EnablePostStatistics.Items.FindByValue( forum.EnablePostStatistics.ToString() ).Selected = true;
EnableAutoDelete.Items.FindByValue( forum.EnableAutoDelete.ToString() ).Selected = true;
EnableAnonymousPosting.Items.FindByValue( forum.EnableAnonymousPosting.ToString() ).Selected = true;
AutoDeleteThreshold.Text = forum.AutoDeleteThreshold.ToString();
IsSearchable.Items.FindByValue( forum.IsSearchable.ToString() ).Selected = true;
EnableAnonymousPostingForUsers.Items.FindByValue( forum.EnableAnonymousPostingForUsers.ToString() ).Selected = true;
FindControl( "EnableAnonymousPostingRow" ).Visible = CSContext.Current.SiteSettings.EnableAnonymousUserPosting;
FindControl( "EnableAnonymousPostingForUsersRow" ).Visible = CSContext.Current.SiteSettings.EnableUserPostingAsAnonymous;
if( forum.ParentID == 0 )
{
ParentID.SelectedForumGroup = forum.GroupID;
}
else
{
ParentID.SelectedForum = forum.ParentID;
}
if ((forum.ForumType == ForumType.Deleted) || (forum.ForumType == ForumType.Reporting)) {
Delete.Enabled = false;
}
}
}
protected virtual void UpdateForum( Forum forum )
{
// Make sure they didn't make a forum a parent to itself
if(forum.SectionID == ParentID.SelectedForum)
{
Label statusLabel = (Label)FindControl("StatusLabel");
statusLabel.Text = ResourceManager.GetString( "ForumAdmin_StatusFailed" );
statusLabel.ForeColor = System.Drawing.Color.Red;
statusLabel.Visible = true;
((RequiredFieldValidator)FindControl( "ParentIDValidator" )).IsValid = false;
return;
}
// Make sure a blank line for parentID isn't selected
if((ParentID.SelectedValue == "s") || (ParentID.SelectedValue == string.Empty))
{
((RequiredFieldValidator)FindControl( "ParentIDValidator" )).IsValid = false;
return;
}
forum.IsActive = Boolean.Parse( IsActive.SelectedValue );
forum.ParentID = ParentID.SelectedForum;
int groupID = ParentID.SelectedForumGroup;
if(groupID != forum.GroupID)
{
UpdateChildGroups(forum.SectionID,forum.GroupID,groupID);
forum.GroupID = groupID;
}
forum.Name = Name.Text;
//新增
forum.NavigateUrl = NavigateUrl.Text;
forum.ForumType = forumType.SelectedValue;
forum.Description = Description.Text;
forum.IsModerated = Boolean.Parse( IsModerated.SelectedValue );
forum.EnablePostStatistics = Boolean.Parse( EnablePostStatistics.SelectedValue );
forum.EnableAutoDelete = Boolean.Parse( EnableAutoDelete.SelectedValue );
forum.EnableAnonymousPosting = Boolean.Parse( EnableAnonymousPosting.SelectedValue );
forum.IsSearchable = Boolean.Parse( IsSearchable.SelectedValue );
forum.EnableAnonymousPostingForUsers = Boolean.Parse( EnableAnonymousPostingForUsers.SelectedValue );
try { forum.AutoDeleteThreshold = Int32.Parse( AutoDeleteThreshold.Text ); }
catch { ((RequiredFieldValidator)FindControl( "AutoDeleteThresholdValidator" )).IsValid = false; }
if(Page.IsValid)
{
Sections.UpdateSection(forum);
CSContext.Current.Context.Response.Redirect( Globals.GetSiteUrls().AdminManageForums, true );
}
}
/// <summary>
/// Updates the GroupID of any child forums
/// </summary>
private void UpdateChildGroups(int forumID, int oldGroupID, int newGroupID)
{
ArrayList al = Forums.GetForums(true,false,false,false);
foreach(Forum child in al)
{
if(child.ParentID == forumID && child.GroupID == oldGroupID)
{
UpdateChildGroups(child.SectionID,oldGroupID,newGroupID);
child.GroupID = newGroupID;
Sections.UpdateSection(child);
}
}
}
protected virtual void DeleteForum( Forum forum )
{
Sections.DeleteSection(forum);
}
private void Delete_Click( Object sender, EventArgs e )
{
if( CSContext.Current.User.IsForumAdministrator )
{
Forum forumToDelete = Forums.GetForum( CSContext.Current.ForumID, false, true, CSContext.Current.UserID );
DeleteForum( forumToDelete );
CSContext.Current.Context.Response.Redirect( Globals.GetSiteUrls().AdminManageForums, true );
}
else
{
throw new CSException( CSExceptionType.AdministrationAccessDenied );
}
}
private void Save_Click( Object sender, EventArgs e )
{
if( CSContext.Current.User.IsForumAdministrator )
{
Forum forumToUpdate = Forums.GetForum( CSContext.Current.ForumID, false, true, CSContext.Current.UserID );
UpdateForum( forumToUpdate );
// save is complete, update the page data
if(Page.IsValid)
{
ParentID.DataBind();
DataBind();
}
}
else
{
throw new CSException( CSExceptionType.AdministrationAccessDenied );
}
}
private void Moderators_Click( Object sender, EventArgs e )
{
CSContext.Current.Context.Response.Redirect(Globals.GetSiteUrls().AdminForumModeratorsEdit(CSContext.Current.ForumID, 0));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -