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

📄 categorylisting.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.Data.SqlTypes;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.Controls;
using CommunityServer.Galleries.Components;

namespace CommunityServer.Galleries.Controls
{

	public class CategoryListing : GalleryThemedControl
	{

		#region Private Members

		private int columnCount = 0;
		private int rowCount = 0;
		private int totalColumns = 0;
		private bool totalColumnsFound = false;
		private int totalCategories = 0;

		#endregion

		#region Child Controls

		private RepeaterPlusNone Categories;
		private RssButton rssButton;
		private PagingControl pagination;
		private HtmlTableCell footerRow;

		#endregion

		#region Public Properties

		private ArrayList dataSource = null;
		public ArrayList DataSource
		{
			get { return dataSource; }
			set { dataSource = value; }
		}

		[DefaultValue( 1 )]
		public int CurrentPage
		{
			get { return currentPage; }
			set { currentPage = value; }
			}
		private int currentPage = 1;

		[DefaultValue( 2 )]
		public int Columns
		{
			get { return columns; }
			set { columns = value; }
			}
		public int columns = 2;

		[DefaultValue( 3 )]
		public int Rows
		{
			get { return rows; }
			set { rows = value; }
			}
		private int rows = 3;

		#endregion

		#region Skin

		protected override void AttachChildControls()
		{
			Categories = (RepeaterPlusNone)FindControl( "Categories" );
			rssButton = (RssButton)FindControl( "RssButton" );
			pagination = (PagingControl)FindControl( "Pagination" );
			footerRow = FindControl( "FooterRow" ) as HtmlTableCell;
			InitializeChildControls();
		}

		private void InitializeChildControls()
		{
			Categories.ItemDataBound += new RepeaterItemEventHandler(Categories_ItemDataBound);
			Categories.NoneItemsDataBound += new RepeaterItemEventHandler(Categories_NoneItemsDataBound);

			if(rssButton != null)
			{
				rssButton.NavigateUrl = GalleryUrls.Instance().Rss(RssType.Categories, CSContext.Current.ApplicationKey);
				rssButton.ImageUrl = Globals.GetSkinPath() + "/images/gallery_xml.gif";
			}
		}

		#endregion

		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);

			// Get the default columns and rows
			Columns = CurrentGallery.CategoryListingColumns;
			Rows = CurrentGallery.CategoryListingRows;

			// Grab the page number
			if(this.Page.Request.QueryString["cpage"] != null)
				CurrentPage = int.Parse(this.Page.Request.QueryString["cpage"]);
		}

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

		private void BindCategories()
		{
			// If no categories, hide it and return
			/*if((DataSource == null) || (DataSource.Count == 0))
			{
				this.Visible = false;
				return;
			}*/
			if(DataSource == null)
			{
				int categoryID = CSContext.Current.CategoryID > 0 ? CSContext.Current.CategoryID : 0;
				DataSource = PostCategories.GetCategories(CurrentGallery.SectionID, CategoryType.GalleryPicture, categoryID);
			}

			if(DataSource.Count == 0)
			{
				this.Visible = false;
				return;
			}

			// Calculate pagination
			totalCategories = DataSource.Count;
			int pageCount = DataSource.Count;
			pageCount -= (CurrentPage-1)*Columns*Rows;
			if(pageCount > (Columns*Rows))
				pageCount = Columns*Rows;

			// Setup the pagination
			pagination.CurrentPage = CurrentPage;
			pagination.TotalPages = (int)Math.Ceiling( (double)totalCategories / (double)(Columns*Rows) );
			pagination.PrefixText = "page";
			pagination.QueryName = "cpage";
			pagination.NavigateUrl = Page.Request.RawUrl;
			pagination.BindPages();

			// Grab the items for the current page
			PostCategory[] pageItems = new PostCategory[pageCount];
			DataSource.CopyTo((CurrentPage-1)*Columns*Rows, pageItems, 0, pageCount);

			// Set the datasource and bind
			Categories.DataSource = pageItems;
			Categories.DataBind();

			// Set the footer row colspan
			if(footerRow != null)
				footerRow.ColSpan = totalColumns;
		}

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

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

					HyperLink NameLink = (HyperLink)e.Item.FindControl( "Name" );
					Literal DescLabel = (Literal)e.Item.FindControl( "Description" );
					Literal DateChangedLabel = (Literal)e.Item.FindControl( "DateChanged" );
					Literal TotalPicturesLabel = (Literal)e.Item.FindControl( "TotalPictures" );
					GalleryImage folderImage = (GalleryImage)e.Item.FindControl( "folderImage" );

					folderImage.NavigateUrl = GalleryUrls.Instance().ViewCategory(CurrentGallery.ApplicationKey, dataItem.CategoryID);

					NameLink.Text = dataItem.Name;
					NameLink.NavigateUrl = GalleryUrls.Instance().ViewCategory(CurrentGallery.ApplicationKey, dataItem.CategoryID);
					TotalPicturesLabel.Text = dataItem.TotalSubThreads.ToString();

					if (DescLabel != null) {
						if(dataItem.Description.Length > 50)
							DescLabel.Text = dataItem.Description.Substring(0, 50) + "...";
						else
							DescLabel.Text = dataItem.Description;
						if(DescLabel.Text != string.Empty)
							DescLabel.Text += "<br/>";
					}

					// If there are no posts, the MostRecentPostDate field has a funky value... lets show when the album was created
					if(dataItem.MostRecentSubPostDate <= SqlDateTime.MinValue.Value)
					{
						DateChangedLabel.Visible = false;
						if(e.Item.FindControl("ChangedTitle") != null)
							e.Item.FindControl( "ChangedTitle" ).Visible = false;
					}
					else
					{
						User user = CSContext.Current.User;
						DateTime changedDate = dataItem.MostRecentSubPostDate;
						string dateFormat;

						if(!user.IsAnonymous)
						{
							changedDate = user.GetTimezone(changedDate);
							dateFormat = user.Profile.DateFormat;
						}
						else
							dateFormat = CSContext.Current.SiteSettings.DateFormat;

						if (DateChangedLabel != null)
							DateChangedLabel.Text = changedDate.ToString(dateFormat);
					}

					// Set column width
					HtmlTableCell tableColumn = e.Item.FindControl("TableColumn") as HtmlTableCell;
					if(tableColumn != null)
						tableColumn.Width = (100 / Columns).ToString() + "%";

					// Begin a column, if necessary
					if(columnCount == 0)
					{
						Literal BeginRowLabel = (Literal)e.Item.FindControl( "BeginRow" );
						BeginRowLabel.Text = "<tr>";
					}
					columnCount++;
					if(!totalColumnsFound)
						totalColumns++;

					// End a column, if necessary
					if((columnCount == Columns) || ((rowCount*Columns+columnCount) == totalCategories))
					{
						Literal EndRowLabel = (Literal)e.Item.FindControl( "EndRow" );
						EndRowLabel.Text = "</tr>";
						columnCount = 0;
						totalColumnsFound = true;
						rowCount++;
					}

					break;
			}
		}

		private void Categories_NoneItemsDataBound(object sender, RepeaterItemEventArgs e)
		{
			Literal NoRecordsLabel = (Literal)e.Item.FindControl( "NoRecords" );
			NoRecordsLabel.Text = ResourceManager.GetString( "ForumMembers_NoRecords" );
		}
	}
}

⌨️ 快捷键说明

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