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

📄 categorymanager.cs

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

using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

using CommunityServer;
using CommunityServer.Blogs.Components;
using CommunityServer.Components;


namespace CommunityServer.Blogs.Controls
{
	/// <summary>
	/// Summary description for CategoryManager.
	/// </summary>
	public class CategoryManager : WeblogAdminTemplatedWebControl
	{
  
        private CSContext csContext = null;

		public CategoryManager()
		{
		
		}

        #region OnInit
        protected override void OnInit(EventArgs e)
        {
            csContext = CSContext.Current;
            base.OnInit (e);
        }

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


        public override void DataBind()
        {
            base.DataBind ();
            BindCategories();
        }


        #endregion

        #region AttachChildControls
        protected override void AttachChildControls()
        {
            CategoriesList = (Repeater)FindControl( "CategoriesList" );
            InitializeChildControls();
        }

        private void InitializeChildControls()
        {
            CategoriesList.ItemDataBound +=new RepeaterItemEventHandler(CategoriesList_ItemDataBound);
            CategoriesList.ItemCommand +=new RepeaterCommandEventHandler(CategoriesList_ItemCommand);
        }

        void BindCategories()
        {
            ArrayList al = PostCategories.GetCategories(CurrentWeblog.SectionID,this.CategoryType,false,true);
            CategoriesList.DataSource = al;
            CategoriesList.DataBind();
        }

        #endregion

        #region Events

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

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

                    if(dataItem == null)
                        return;

                    Literal ID = (Literal)e.Item.FindControl( "ID" );
                    Literal Name = (Literal)e.Item.FindControl( "CategoryName" );
                    Literal ItemCount = (Literal)e.Item.FindControl( "ItemCount" );
                    Literal IsEnabled =(Literal)e.Item.FindControl( "IsEnabled" );
                    Literal MostRecent =(Literal)e.Item.FindControl( "MostRecent" );
			
                    ID.Text = dataItem.CategoryID.ToString();
                    Name.Text = dataItem.Name;
                    ItemCount.Text = dataItem.TotalThreads.ToString();
                    IsEnabled.Text = dataItem.IsEnabled.ToString();
                    if(dataItem.TotalThreads > 0)
                        MostRecent.Text = dataItem.MostRecentPostDate.ToString("f");


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

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

                    DeleteButton.Attributes["onclick"] = "if ( !confirm('" + ResourceManager.GetString("Category_Delete").Replace("'", @"\'") + "') ) {return false; } ";								
                    DeleteButton.Text = ResourceManager.GetString( "Delete" );
                    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 CategoriesList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            switch(e.CommandName)
            {
                case "View":
                    break;
                case "Edit":
                    
                    int categoryID = int.Parse((string)e.CommandArgument);
                     Context.Response.Redirect(BlogUrls.Instance().AdminCategoriesEditor(CurrentWeblog.ApplicationKey,CategoryType,categoryID));
                    break;
                case "Delete":
                    PostCategories.DeleteCategory(int.Parse((string)e.CommandArgument),CurrentWeblog.SectionID);
                    BindCategories();
                    break;
                case "Create":
                        Context.Response.Redirect(BlogUrls.Instance().AdminCategoriesEditor(CurrentWeblog.ApplicationKey,CategoryType));
                    break;
            }
        }

  

        #endregion


        #region Child Controls

        private Repeater CategoriesList;

        #endregion

        #region Public Properties

        /// <summary>
        /// Property CategoryType (CategoryType)
        /// </summary>
        public CategoryType CategoryType
        {
            get
            { 
                return (CategoryType)Enum.Parse(typeof(CategoryType),Context.Request.QueryString["CT"],true);
            }
        }

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

        #endregion


    }
}

⌨️ 快捷键说明

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