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

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

namespace CommunityServer.Galleries.Controls
{
	/// <summary>
	/// Summary description for PortalPictureListing.
	/// </summary>
	public class PortalPictureListing : GalleryThemedControl
	{
		
		#region Public Properties

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

		[DefaultValue( GalleryThreadSortBy.ThreadDate )]
		private GalleryThreadSortBy sortBy = GalleryThreadSortBy.ThreadDate;
		public virtual GalleryThreadSortBy SortBy
		{
			get { return sortBy; }
			set { sortBy = value; }
		}

		private SortOrder sortOrder = SortOrder.Descending;
		public SortOrder SortOrder
		{
			get { return sortOrder; }
			set { sortOrder = value; }
		}

		[DefaultValue( true )]
		private bool showPictures = true;
		public bool ShowPictures
		{
			get { return showPictures; }
			set { showPictures = value; }
		}

		#endregion

		#region Child Controls

		private Literal sectionTitle;
		private RepeaterPlusNone pictureList;

		#endregion

		#region Skin

		protected override void AttachChildControls()
		{
			sectionTitle = (Literal)FindControl( "SectionTitle" );
			pictureList = (RepeaterPlusNone)FindControl( "Pictures" );
			InitializeChildControls();
		}

		private void InitializeChildControls()
		{
			pictureList.ItemDataBound += new RepeaterItemEventHandler(pictureList_ItemDataBound);
			pictureList.NoneItemsDataBound += new RepeaterItemEventHandler(pictureList_NoneItemsDataBound);
		}

		#endregion

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

			if(IsParentInvisible(this))
				return;

			BindPictures();
		}

		private bool IsParentInvisible(Control control)
		{
			if(control.Parent == null)
				return false;
			else if(control.Parent.Visible == false)
				return true;
			else
				return IsParentInvisible(control.Parent);
		}

		public void BindPictures()
		{
			// Set the area title
			switch(SortBy)
			{
				case GalleryThreadSortBy.ThreadDate:
					sectionTitle.Text = ResourceManager.GetString( "Gallery_PortalPictureListing_TitlePostDate" );
					break;
				case GalleryThreadSortBy.Rating:
					sectionTitle.Text = ResourceManager.GetString( "Gallery_PortalPictureListing_TitleRating" );
					break;
				case GalleryThreadSortBy.Comments:
					sectionTitle.Text = ResourceManager.GetString( "Gallery_PortalPictureListing_TitleReplies" );
					break;
				case GalleryThreadSortBy.Views:
					sectionTitle.Text = ResourceManager.GetString( "Gallery_PortalPictureListing_TitleViews" );
					break;
			}

			// Setup the query
			GalleryThreadQuery query = new GalleryThreadQuery();
			query.SectionID = CurrentGallery.SectionID;
			query.CategoryID = CSContext.Current.CategoryID;
			query.PageSize = Count;
			query.SortBy = SortBy;
			query.SortOrder = SortOrder;

			pictureList.DataSource = Pictures.GetPictures(query).Threads;
			pictureList.DataBind();
		}

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

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

					GalleryImage pictureThumb = e.Item.FindControl("PictureThumb") as GalleryImage;
					HyperLink PictureNameLink = (HyperLink)e.Item.FindControl( "PictureName" );
					Literal fieldName = (Literal)e.Item.FindControl( "SortedName");
					Literal field = (Literal)e.Item.FindControl( "SortedField");

					if(pictureThumb != null)
					{
						pictureThumb.Visible = ShowPictures;
						if(pictureThumb.Visible == true)
						{
							pictureThumb.PostID = dataItem.PostID;
							pictureThumb.NavigateUrl = GalleryUrls.Instance().ViewPicture(dataItem.Section.ApplicationKey, CSContext.Current.CategoryID, dataItem);
							pictureThumb.Picture = dataItem;
							pictureThumb.DataBind();
						}
					}

					if (PictureNameLink != null) {
						if(dataItem.Subject != "") {
							dataItem.Subject = Globals.HtmlDecode( dataItem.Subject );
							if(dataItem.Subject.Length > 22)
								PictureNameLink.Text = dataItem.Subject.Substring(0, 22) + "...";
							else
								PictureNameLink.Text = dataItem.Subject;
						}
						else
							PictureNameLink.Text = ResourceManager.GetString( "Gallery_NoTitle" );

						PictureNameLink.NavigateUrl = GalleryUrls.Instance().ViewPicture(dataItem.Section.ApplicationKey, CSContext.Current.CategoryID, dataItem);
					}

				switch(SortBy)
				{
					case GalleryThreadSortBy.ThreadDate:
						User user = CSContext.Current.User;
						DateTime postDate = dataItem.PostDate;
						string dateFormat;

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

						if (fieldName != null)
							fieldName.Text = ResourceManager.GetString( "Gallery_PortalPictureListing_FieldPostDate" );

						if (field != null)
							field.Text = postDate.ToString(dateFormat) + " " + postDate.ToString(CSContext.Current.SiteSettings.TimeFormat);

						break;

					case GalleryThreadSortBy.Rating:
						if (fieldName != null)
							fieldName.Text = ResourceManager.GetString( "Gallery_PortalPictureListing_FieldRating" );

						if (field != null) {
							if(dataItem.TotalRatings > 0)
								field.Text = ((double)dataItem.RatingSum / (double)dataItem.TotalRatings).ToString("0.0#");
							else
								field.Text = "0";
							break;
						}
						break;

					case GalleryThreadSortBy.Comments:
						if (fieldName != null)
							fieldName.Text = ResourceManager.GetString( "Gallery_PortalPictureListing_FieldReplies" );
						
						if (field != null)
							field.Text = dataItem.Replies.ToString();

						break;
					case GalleryThreadSortBy.Views:

						if (fieldName != null)
							fieldName.Text = ResourceManager.GetString( "Gallery_PortalPictureListing_FieldViews" );

						if (field != null)
							field.Text = dataItem.Views.ToString();

						break;
				}

					break;
			}
		}

		private void pictureList_NoneItemsDataBound(object sender, RepeaterItemEventArgs e)
		{

		}
	}
}

⌨️ 快捷键说明

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