⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 forumdropdownlist.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 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.Discussions.Components;

namespace CommunityServer.Discussions.Controls 
{

	/// <summary>
	/// This server control displays a list of all forums with grouping and formatting to make them readable.
	/// </summary>
	public class ForumDropDownList : DropDownList 
	{

		/// <remarks>
		/// Fills ForumDropDownList with data.
		/// </remarks>
		public ForumDropDownList() 
		{
			DataBind();
		}

		public override void DataBind() 
		{
			ArrayList forumGroups;

			// Get all forum groups
			if (this.ForumMode == ControlUserMode.User)
				forumGroups = ForumGroups.GetForumGroups(false, false);
			else
				forumGroups = ForumGroups.GetForumGroups(false);

			foreach (Group group in forumGroups) 
			{
				User user = CSContext.Current.User;

				// quick hack to keep recursive from showing
				if (Items.FindByValue("g-" + group.GroupID) == null) 
				{

					// Get the sections for the group
					if(this.ForumMode == ControlUserMode.User)
						group.Sections = Forums.GetForumsByForumGroupID(group.GroupID,true,false);
					else
						group.Sections = Forums.GetForumsByForumGroupID(group.GroupID,false,true);

					if(group.HasSections) 
					{
						// Add the forum group
						//
						Items.Add(new ListItem(group.Name, "g-" + group.GroupID));

						RecursiveAddForum (0,  group.Sections);

						// Add the forum group
						//
						Items.Add(new ListItem("", "s"));

					}

				}

			}
			Items.Insert(0, new ListItem( "All Forums", "f--1"));
		}

		public int SelectedForum 
		{
			get 
			{
				if (base.SelectedValue.StartsWith("f-"))
					return int.Parse(base.SelectedValue.Replace("f-", ""));
				return 0;
			}
			set 
			{
				if (value > 0) 
				{
					if (base.SelectedValue != "")
						Items.FindByValue( base.SelectedValue ).Selected = false;

					Items.FindByValue("f-" + value).Selected = true;
				}
			}
		}


		public int SelectedForumGroup 
		{
			get 
			{
				if (base.SelectedValue.StartsWith("f")) 
				{
					return Forums.GetForum(int.Parse(base.SelectedValue.Replace("f-", ""))).GroupID;
				} 
				else if(base.SelectedValue.StartsWith("g"))
				{
					return int.Parse(base.SelectedValue.Replace("g-", ""));
				}
				else
					return 0;
			}
			set 
			{ 
				// Deselect current item
				if (base.SelectedValue != "")
					Items.FindByValue( base.SelectedValue ).Selected = false;

				Items.FindByValue("g-" + value).Selected = true;
			}
		}

		private void RecursiveAddForum (int depth, ArrayList forums) 
		{

            
			foreach (Forum forum in forums) 
			{
				// We only go 3 deep
				//
				switch (depth) 
				{
					case 0:
						Items.Add(new ListItem(ResourceManager.GetString("Navigation_JumpDropDownList_Indent1") + forum.Name, "f-" + forum.SectionID.ToString()));
						if (forum.Sections.Count > 0)
							RecursiveAddForum((depth + 1), forum.Sections);
						break;

					case 1:
						Items.Add(new ListItem(ResourceManager.GetString("Navigation_JumpDropDownList_Indent2") + forum.Name, "f-" + forum.SectionID.ToString()));
						if (forum.Sections.Count > 0)
							RecursiveAddForum((depth + 1), forum.Sections);
						break;

					case 2:
						Items.Add(new ListItem(ResourceManager.GetString("Navigation_JumpDropDownList_Indent3") + forum.Name, "f-" + forum.SectionID.ToString()));
						if (forum.Sections.Count > 0)
							RecursiveAddForum((depth + 1), forum.Sections);
						break;

					default:
						return;

				}
			}
		}


		[
		System.ComponentModel.DefaultValue( ControlUserMode.User ),
		]
		public virtual ControlUserMode ForumMode 
		{
			get 
			{
				Object state = ViewState["ForumMode"];
				if ( state != null ) 
				{
					return (ControlUserMode)state;
				}
				return ControlUserMode.User;
			}
			set 
			{
				ViewState["ForumMode"] = value;
			}
		}

	}
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -