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

📄 ratinglisting.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.WebControls;
using CommunityServer.Components;
using CommunityServer.Controls;
using CommunityServer.Galleries.Components;

namespace CommunityServer.Galleries.Controls
{

	public class RatingListing : GalleryThemedControl
	{

		#region Child Controls

		private Literal AverageRating;
		private Literal TotalVotes;
		private GalleryRatePost RatePost;
		private RatingImageButton RatingButton;

		#endregion

		#region Public Properties

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

		[DefaultValue( -1 )]
		public virtual int PictureID
		{
			get
			{
				Object state = ViewState["PictureID"];
				if(state != null)
					return (int)state;
				return -1;
			}
			set { ViewState["PictureID"] = value; }
		}

		private Picture picture = null;
		public Picture Picture
		{
			get { return picture; }
			set { picture = value; }
		}

		#endregion

		#region Skin

		protected override void AttachChildControls()
		{
			AverageRating = (Literal)FindControl( "AverageRating" );
			TotalVotes = (Literal)FindControl( "TotalVotes" );
			RatePost = (GalleryRatePost)FindControl( "RatePost" );
			RatingButton = (RatingImageButton)FindControl( "RatingButton" );
		}

		#endregion

		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);
			ApplicationKey = CSContext.Current.ApplicationKey;
			PictureID = CSContext.Current.PostID;
		}
		
		public override void DataBind()
		{
			base.DataBind ();
			BindRatings();
		}

		private void BindRatings()
		{
			// If we have no settings, return
			if((ApplicationKey == null) || (PictureID == -1))
				return;

			// Check if ratings were enabled
			if(!Galleries.GetGallery(ApplicationKey).EnableRatings)
			{
				this.Visible = false;
				return;
			}

			// Get the picture if we don't have one
			if(picture == null)
				picture = Pictures.GetPicture(PictureID);

			// Setup the Ratings
			if(TotalVotes != null)
				TotalVotes.Text = picture.TotalRatings.ToString();
			
			// Check if the user is allowed to vote/rate
			if(RatePost != null)
			{
				GalleryPermission permission = Galleries.GetGallery(ApplicationKey).ResolvePermission( CSContext.Current.User ) as GalleryPermission;
				if(!permission.Vote)
					RatePost.Visible = false;
				else
					RatePost.Post = picture;
			}

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

			if(RatingButton != null)
			{
				RatingButton.Thread = picture;
				RatingButton.ImagePath = Globals.GetSkinPath() + "/images/gallery/";
				RatingButton.MoreDetail = false;
			}
		}
	}
}

⌨️ 快捷键说明

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