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

📄 categoryeditor.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;
using CommunityServer.Controls;

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

		public CategoryEditor()
		{
		
		}

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

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

            base.OnLoad (e);
        }

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


        #endregion

        #region AttachChildControls
        protected override void AttachChildControls()
        {
            Name = (TextBox)FindControl( "Name" );
            Description = (TextBox)FindControl( "Description" );
            IsEnabled = (YesNoRadioButtonList)FindControl( "IsEnabled" );
            ErrorLabel = (Label)FindControl( "ErrorLabel" );

            Save = (Button)FindControl( "Save" );
            Cancel = (Button)FindControl( "Cancel" );

           InitializeChildControls();
        }

        private void InitializeChildControls()
        {
            Save.Click += new EventHandler(Save_Click);
            Cancel.Click += new EventHandler(Cancel_Click);
       }

        void BindData()
        {
            
            Name.Text = string.Empty;
            Description.Text = string.Empty;
            IsEnabled.SelectedValue = true;
            ErrorLabel.Visible = false;

            if(Context.Request.QueryString["CategoryID"] != null)
            {

                CategoryID = int.Parse(Context.Request.QueryString["CategoryID"]);
                PostCategory pc = PostCategories.GetCategory(CategoryID,this.CategoryType,CurrentWeblog.SectionID,true);
                if(pc == null)
                    throw new CSException(CSExceptionType.PostCategoryNotFound,string.Format("Category {0} was not found",CategoryID));

                Name.Text = Globals.HtmlDecode(pc.Name);
				

                Description.Text = pc.Description;
                IsEnabled.SelectedValue = pc.IsEnabled;
            }
            

        }

        #endregion

        #region Events

        private void Save_Click(Object sender, EventArgs e)
        {
            PostCategory category = null;

            if(CategoryID == 0)
                category = new PostCategory();
            else
                category = PostCategories.GetCategory(CategoryID,this.CategoryType,CurrentWeblog.SectionID,true);

            category.Name = Name.Text;
            category.Description = Description.Text;
            category.IsEnabled =  IsEnabled.SelectedValue;

            // Some basic settings we should always have...
           

            try
            {
                if(CategoryID == 0)
                {
                    category.CategoryType = this.CategoryType;
                    category.ParentID = 0;
                    category.SectionID = CurrentWeblog.SectionID;
                    PostCategories.CreateCategory(category);
                    
                }
                else
                {
                    PostCategories.UpdateCategory(category);
                }
            }
            catch(CSException ex)
            {
                if(ex.ExceptionType == CSExceptionType.PostDuplicate)
                {
                    ErrorLabel.Text = "A category with this name already exists in the gallery.  Please choose another name.";
                    ErrorLabel.Visible = true;
                    Name.ForeColor = System.Drawing.Color.Red;
                    return;
                }
            }

            Cancel_Click(sender,e);


        }

        private void Cancel_Click(Object sender, EventArgs e)
        {
            Context.Response.Redirect(BlogUrls.Instance().AdminCategories(CurrentWeblog.ApplicationKey,CategoryType));
        }

        #endregion


        #region Child Controls

        private TextBox Name;
        private TextBox Description;
        private YesNoRadioButtonList IsEnabled;
        private Label ErrorLabel;

        private Button Save;
        private Button Cancel;

        #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 + -