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

📄 managecategories.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.ComponentModel;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.Galleries.Components;

namespace CommunityServer.Galleries.Controls
{

	public class ManageCategories : GalleryAdminTemplatedWebControl
	{

		#region Child Controls

		private Repeater CategoryList;

		#endregion

		#region Public Properties

		[DefaultValue( "" )]
		public virtual string ApplicationKey
		{
			get
			{
				Object state = ViewState["ApplicationKey"];
				if(state != null)
					return (string)state;
				return "";
			}
			set { ViewState["ApplicationKey"] = value; }
		}

		#endregion

		#region Skin

		protected override void AttachChildControls()
		{
			CategoryList = (Repeater)FindControl( "CategoryList" );

			InitializeChildControls();
		}

		private void InitializeChildControls()
		{
			CategoryList.ItemDataBound += new RepeaterItemEventHandler(CategoryList_ItemDataBound);
			CategoryList.ItemCommand += new RepeaterCommandEventHandler(CategoryList_ItemCommand);
		}

		#endregion

		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);
			ApplicationKey = CSContext.Current.ApplicationKey;

			// Access check
			Permissions.AccessCheck( Galleries.GetGallery(ApplicationKey), Permission.Post, CSContext.Current.User );
		}

		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);
			if(!Page.IsPostBack)
				DataBind();
		}

		public override void DataBind()
		{
			base.DataBind();
			Gallery gallery = Galleries.GetGallery(ApplicationKey, false);
			CategoryList.DataSource = PostCategories.GetCategories( gallery.SectionID, CategoryType.GalleryPicture, false, true, -1);
			CategoryList.DataBind();
		}

		private void CategoryList_ItemDataBound(object sender, RepeaterItemEventArgs e) 
		{
			PostCategory dataItem = e.Item.DataItem as PostCategory;

			switch( e.Item.ItemType ) 
			{
				case ListItemType.Item:
				case ListItemType.AlternatingItem:

					HyperLink CategoryName = (HyperLink)e.Item.FindControl( "CategoryName" );
					Label Enabled = (Label)e.Item.FindControl( "Enabled" );
					Label PictureCount = (Label)e.Item.FindControl( "PictureCount" );

					CategoryName.Text = dataItem.Name;
					CategoryName.NavigateUrl = GalleryUrls.Instance().ViewCategory(ApplicationKey, dataItem.CategoryID);

					Enabled.Text = dataItem.IsEnabled.ToString();
					PictureCount.Text = dataItem.TotalThreads.ToString();

					Button EditButton = (Button)e.Item.FindControl( "Edit" );
					Button DeleteButton = (Button)e.Item.FindControl( "Delete" );

					EditButton.CommandArgument = dataItem.CategoryID.ToString();
					DeleteButton.CommandArgument = dataItem.CategoryID.ToString();

					EditButton.Text = ResourceManager.GetString( "Edit" );
					DeleteButton.Text = ResourceManager.GetString( "Delete" );

					break;

				case ListItemType.Footer:

					Button CreateButton = (Button)e.Item.FindControl( "Create" );
					CreateButton.Text = ResourceManager.GetString( "Create" );

					break;
			}
		}

		private void CategoryList_ItemCommand(object source, RepeaterCommandEventArgs e)
		{
			string url = "#";

			switch(e.CommandName)
			{
				case "Edit":
					url = GalleryUrls.Instance().Admin_AdminCategory(ApplicationKey, int.Parse((string)e.CommandArgument));
					break;

				case "Delete":
					PostCategories.DeleteCategory(int.Parse((string)e.CommandArgument), Galleries.GetGallery(ApplicationKey, false).SectionID);
					url = GalleryUrls.Instance().Admin_ManageCategories(ApplicationKey);
					break;

				case "Create":
                    url = GalleryUrls.Instance().Admin_AdminCategory(ApplicationKey, 0);
					break;
			}

			Context.Response.Redirect(url);
			Context.Response.End();
		}
	}
}

⌨️ 快捷键说明

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