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

📄 ratingimagebutton.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Web.UI.HtmlControls;
using CommunityServer;

using CommunityServer.Components;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CommunityServer.Controls {
	public class RatingImageButton : PlaceHolder {

		#region Member variables
	    CSContext csContext = CSContext.Current;
		#endregion

		private string _imagePath = null;// string.Empty;
		public string ImagePath
		{
			get
			{
				if(_imagePath == null)
					_imagePath = Globals.GetSkinPath() + "/images/";

				return _imagePath;
			}
			set{_imagePath = value;}
		}

		protected string BuildImagePath(string imageName)
		{
			return string.Format("{0}{1}{2}",ImagePath,ImagePath.EndsWith("/") ? string.Empty : "/", imageName);
		}

		#region Render logic
		protected override void Render(HtmlTextWriter writer) {


			if (this.Thread != null) 
			{
				this.Rating = this.Thread.ThreadRating;
				TotalRatings = Thread.TotalRatings;
				PostID = this.Thread.PostID;
			}

			if (Rating == 0)
				if (TotalRatings == 0)
					return;


			// Do we have data to display
			//
			if ((Rating == 0) && (MoreDetail)) {
				return;
			}

			HtmlAnchor anchor = new HtmlAnchor();
			HtmlImage image = new HtmlImage();
			string text;

			if (Rating <= 0.25) {
				image.Src = BuildImagePath("Star0.gif");
				text = ResourceManager.GetString("PostRating_Zero");
			} else if (Rating <= 0.5) {
				image.Src = BuildImagePath("StarHalf.gif");
				text = ResourceManager.GetString("PostRating_One");
			} else if (Rating <= 1) {
				image.Src = BuildImagePath("Star1.gif");
				text = ResourceManager.GetString("PostRating_One");
			} else if (Rating <= 1.5) {
				image.Src = BuildImagePath("Star1half.gif");
				text = ResourceManager.GetString("PostRating_Two");
			} else if (Rating <= 2) {
				image.Src = BuildImagePath("Star2.gif");
				text = ResourceManager.GetString("PostRating_Two");
			} else if (Rating <= 2.5) {
				image.Src = BuildImagePath("Star2half.gif");
				text = ResourceManager.GetString("PostRating_Three");
			} else if (Rating <= 3) {
				image.Src = BuildImagePath("Star3.gif");
				text = ResourceManager.GetString("PostRating_Three");
			} else if (Rating <= 3.5) {
				image.Src = BuildImagePath("Star3half.gif");
				text = ResourceManager.GetString("PostRating_Four");
			} else if (Rating <= 4) {
				image.Src = BuildImagePath("Star4.gif");
				text = ResourceManager.GetString("PostRating_Four");
			} else if (Rating <= 4.5) {
				image.Src = BuildImagePath("Star4Half.gif");
				text = ResourceManager.GetString("PostRating_Five");
			} else {
				image.Src = BuildImagePath("Star5.gif");
				text = ResourceManager.GetString("PostRating_Five");
			}


			image.Border = 0;

			if (this.MoreDetail) {
				if (Rating == 0)
					image.Alt = string.Format(ResourceManager.GetString("PostRating_AltText"), text, "0", TotalRatings);
				else
					image.Alt = string.Format(ResourceManager.GetString("PostRating_AltText"), text, Rating.ToString("#.##"), TotalRatings);

				anchor.Controls.Add(image);
				anchor.HRef = "javascript:OpenWindow('" + Globals.GetSiteUrls().PostRating(PostID) + "')";
				anchor.RenderControl(writer);
			} else {
				if (Rating == 0)
					image.Alt = string.Format(ResourceManager.GetString("Rating_AltText"), text, "0");
				else
					image.Alt = string.Format(ResourceManager.GetString("Rating_AltText"), text, Rating.ToString("#.##"));

				image.RenderControl(writer);
			}
		}
		#endregion

		#region Public Properties



		//TODO enable state persistence when Threads.GetThread is implemented
		public IThread Thread {
			get {
//				if ( _thread == null ) {
//					Object state = ViewState[ "ThreadID" ];
//					if ( state != null ) {
//						Int32 threadID = (Int32)state;
//						ForumsDataProvider provider = ForumsDataProvider.Instance();
//						this._thread = provider.GetThread( threadID );
//					}
//				}
				return _thread;
			}
			set { 
				_thread = value;
//				if ( _thread != null ) {
//					ViewState[ "ThreadID" ] = _thread.ThreadID;
//				} else {
//					ViewState.Remove( "ThreadID" );
//				}
			}
		}
		IThread _thread;


		[
		System.ComponentModel.DefaultValue( 0 ),
		]
		public virtual Double Rating {
			get {
				Object state = ViewState["Rating"];
				if ( state != null ) {
					return (Double)state;
				}
				return 0;
			}
			set {
				ViewState["Rating"] = value;
			}
		}

		[
		System.ComponentModel.DefaultValue( 0 ),
		]
		public virtual int TotalRatings 
		{
			get 
			{
				Object state = ViewState["TotalRatings"];
				if ( state != null ) 
				{
					return (int)state;
				}
				return 0;
			}
			set 
			{
				ViewState["TotalRatings"] = value;
			}
		}

		[
		System.ComponentModel.DefaultValue( 0 ),
		]
		public virtual int PostID 
		{
			get 
			{
				Object state = ViewState["PostID"];
				if ( state != null ) 
				{
					return (int)state;
				}
				return 0;
			}
			set 
			{
				ViewState["PostID"] = value;
			}
		}

		
		[
		System.ComponentModel.DefaultValue( true ),
		]
		public virtual Boolean MoreDetail {
			get {
				Object state = ViewState["MoreDetail"];
				if ( state != null ) {
					return (Boolean)state;
				}
				return true;
			}
			set {
				ViewState["MoreDetail"] = value;
			}
		}

		#endregion

	}
}

⌨️ 快捷键说明

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