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

📄 subsectionmenu.cs

📁 ASP开发网站的 关于网站的设计和说明 还有SQL的程序 数据库
💻 CS
字号:
namespace ASPNET.StarterKit.Communities {

    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.Caching;
    using System.Configuration;
    using System.Collections;
    using System.Data;



    //*********************************************************************
    //
    // SubSectionMenu Class
    //
	// SMR - Enh - New class for the multilevel section menu
	//
    // WebControl that displays sub level sections. This control
    // takes into account the roles of the current user and displays
    // private sections only to users who have the right roles. 
    //
    //*********************************************************************
    
    public class SubSectionMenu : SkinnedCommunityControl 
	{
        string _skinFileName = "Sections_SubSectionMenu.ascx";
        Repeater rptSections;
        
		int _sectionId;
		bool _expandAll = false; //
		bool _showSelection = true; //
		int _currentLevel = 2;
		int _expandLevels = 0; //

		public int SectionId
		{
			get { return _sectionId; }
			set { _sectionId = value; }
		}

		public int CurrentLevel
		{
			get { return _currentLevel; }
			set { _currentLevel = value; }
		}

		public bool ShowSelection
		{
			get { return _showSelection; }
			set { _showSelection = value; }
		}

		// SMR - Enh - indicates how many levels deep the tree can be exapanded
		public int ExpandLevels
		{
			get { return _expandLevels; }
			set { _expandLevels = value; }
		}

		// SMR - Enh - indicates if the section tree should always be expanded for all nodes
		public bool ExpandAll
		{
			get { return _expandAll; }
			set { _expandAll = value; }
		}


        //*********************************************************************
        //
        // SubSectionMenu Constructor
        //
        // Calls the base SkinnedCommunityControl constructor
        // and assigns the default page skin.
        //
        //*********************************************************************
        public SubSectionMenu() : base() {
            // Assign a default template name
            if (SkinFileName == null)
                SkinFileName = _skinFileName;
        }


        //*********************************************************************
        //
        // SkinType Property
        //
        // Specifies the skins directory where this page's skin file is located.
        //
        //*********************************************************************
        override protected string SkinType {
            get { return "ControlSkins"; }
        }

   
        //*********************************************************************
        //
        // InitializeSkin Method
        //
        // Retrieves all the controls from the page skin.
        //
        //*********************************************************************
        override protected void InitializeSkin(Control skin) {

            // Get the Repeater from the Skin
            rptSections = (Repeater)GetControl( skin, "SubSections" );
            rptSections.EnableViewState = false;
            rptSections.ItemDataBound += new RepeaterItemEventHandler(Repeater_ItemDataBound);
        }



        //*********************************************************************
        //
        // Repeater_ItemDataBound Method
        //
        // Assigns values to the controls contained in the item and 
        // alternating item templates of the Repeater used to display
        // the list of sections.
        //
        //*********************************************************************
        private void Repeater_ItemDataBound(Object s, RepeaterItemEventArgs e) {
            HyperLink lnkSection;
			Image spaceImg;
            SectionMenuLink _sectionMenuLink;
            SubSectionMenu _subSectionCtrl;
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
                lnkSection = (HyperLink)GetControl(e.Item, "lnkSubSection");
				spaceImg = (Image)GetControl( e.Item, "spaceImg" );
                _sectionMenuLink = (SectionMenuLink)e.Item.DataItem;
                _subSectionCtrl = (SubSectionMenu)GetControl(e.Item, "SubSectionMenu");
                
				lnkSection.Text = _sectionMenuLink.SectionMenuTitle;
                lnkSection.NavigateUrl = _sectionMenuLink.SectionPath;
				spaceImg.ImageUrl = ResolveUrl("../../Images/spacer.gif");
				spaceImg.Width = 10 * (_currentLevel - 1);
				spaceImg.Height = 1;

				if(_showSelection && _sectionMenuLink.SectionID == objSectionInfo.ID)
				{
					lnkSection.CssClass = this.CssClass + "_SelectedMenuItem";
				}

				if(SubSectionUtility.ShowSubSectionsForThisSection(_sectionMenuLink,_expandAll,objSectionInfo) && _expandLevels != _currentLevel)
				{	
					_subSectionCtrl.ShowSelection = _showSelection;
					_subSectionCtrl.ExpandAll = _expandAll;
					_subSectionCtrl.CurrentLevel = _currentLevel + 1;
					_subSectionCtrl.ExpandLevels = _expandLevels;
					_subSectionCtrl.SectionId = _sectionMenuLink.SectionID;
				}
				else
				{
					_subSectionCtrl.Visible = false;
				}
            }
        }
        

        //*********************************************************************
        //
        // OnPreRender Method
        //
        // Binds the sections to the Repeater control.
        //
        //*********************************************************************
        override protected void OnPreRender(EventArgs e) {
            // Bind the results to the DataList
            rptSections.DataSource = GetThisLevelSections(objUserInfo);
            rptSections.DataBind();  
        }


        //*********************************************************************
        //
        // GetThisLevelSections Method
        //
        // Gets list of top-level sections. Displays different sections
        // depending on whether the current user is authenticated.
        //
        //*********************************************************************
        private ArrayList GetThisLevelSections(UserInfo user) {
			if (!user.IsAuthenticated)
			{
				return GetPublicThisLevelSections();
			}
            return GetThisLevelSectionsForUser(user);
        }
    

        //*********************************************************************
        //
        // GetPublicThisLevelSections Method
        //
        // Returns top-level sections from the cache, or if not available,
        // calculates top-level sections.
        //
        //*********************************************************************
        private ArrayList GetPublicThisLevelSections() {   
            ArrayList sections = (ArrayList)Context.Cache[CommunityGlobals.CacheKey(objSectionInfo.Name + "_PublicThisLevelSections")];
            if (sections == null) {
                sections = CalculatePublicThisLevelSections();
                Context.Cache.Insert
                (
                    CommunityGlobals.CacheKey(objSectionInfo.Name + "_PublicThisLevelSections"),
                    sections,
                    new CacheDependency( null, new string[] {CommunityGlobals.CacheKey(objSectionInfo.Name + "_Sections")})
                );
            }
            return sections;
        }
        

        //*********************************************************************
        //
        // CalculatePublicThisLevelSections Method
        //
        // Determines public top-level sections by iterating through
        // the list of sections and finding sections that Everyone or
        // Authenticated can access.
        //
        //*********************************************************************
        private ArrayList CalculatePublicThisLevelSections() {
            ArrayList publicThisLevelSections = new ArrayList();
            
            ArrayList thisLevelSections = GetThisLevelSections();
            foreach (SectionInfo section in thisLevelSections)
                if (Array.IndexOf(section.ViewRoles, "Community-Everyone") != -1 || Array.IndexOf(section.ViewRoles, "Community-Authenticated") != -1)
                    publicThisLevelSections.Add(new SectionMenuLink(section.MenuTitle, section.Path, section.ID, section.ParentSectionID));        
            return publicThisLevelSections;
        }
        


        //*********************************************************************
        //
        // GetThisLevelSections Method
        //
        // Retrieves all top-level sections.
        //
        //*********************************************************************   
        private ArrayList GetThisLevelSections() {
            ArrayList thisLevelSections = (ArrayList)Context.Cache[CommunityGlobals.CacheKey(objSectionInfo.Name + "_ThisLevelSections")];
            
            if (thisLevelSections == null) {
                ArrayList sections = SectionUtility.GetAllEnabledSections().GetOrderedSections();
                thisLevelSections = new ArrayList();
                foreach (SectionInfo section in sections)
                    if (section.ParentSectionID == _sectionId)
                        thisLevelSections.Add(section);
            }
            return thisLevelSections;
        }


        //*********************************************************************
        //
        // GetThisLevelSectionsForUser Method
        //
        // Determines top-level sections for an authenticated user.
        // This might include private sections.
        //
        //*********************************************************************
        private ArrayList GetThisLevelSectionsForUser(UserInfo user) {
            ArrayList colSections = new ArrayList();
            bool mayView = false;
            
            ArrayList thisLevelSections = GetThisLevelSections();
            foreach (SectionInfo section in thisLevelSections) {
                mayView = false;
                foreach (string role in section.ViewRoles) {
                    if (objUserInfo.IsInRole(role) || role=="Community-Everyone" || role=="Community-Authenticated")
                        mayView = true;
                }
                if (mayView)        
                    colSections.Add( new SectionMenuLink(section.MenuTitle, section.Path, section.ID, section.ParentSectionID));
            }
            return colSections;
        }
    }
}

⌨️ 快捷键说明

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