📄 ratingimagebutton.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using CommunityServer.Components;
using CommunityServer.Discussions.Components;
namespace CommunityServer.Discussions.Controls
{
public class RatingImageButton : PlaceHolder
{
#region Member variables
CSContext csContext = CSContext.Current;
#endregion
#region Render logic
protected override void Render(HtmlTextWriter writer)
{
int totalRatings = 0;
if (this.Thread != null)
{
this.Rating = this.Thread.ThreadRating;
totalRatings = this.Thread.TotalRatings;
}
// Do we have data to display
//
if ((Rating == 0) && (totalRatings == 0) && (MoreDetail))
{
return;
}
HtmlAnchor anchor = new HtmlAnchor();
HtmlImage image = new HtmlImage();
string text;
if (Rating <= 0.25)
{
image.Src = Globals.GetSkinPath() + "/images/Star0.gif";
text = ResourceManager.GetString("PostRating_Zero");
}
else if (Rating <= 0.5)
{
image.Src = Globals.GetSkinPath() + "/images/StarHalf.gif";
text = ResourceManager.GetString("PostRating_One");
}
else if (Rating <= 1)
{
image.Src = Globals.GetSkinPath() + "/images/Star1.gif";
text = ResourceManager.GetString("PostRating_One");
}
else if (Rating <= 1.5)
{
image.Src = Globals.GetSkinPath() + "/images/Star1half.gif";
text = ResourceManager.GetString("PostRating_Two");
}
else if (Rating <= 2)
{
image.Src = Globals.GetSkinPath() + "/images/Star2.gif";
text = ResourceManager.GetString("PostRating_Two");
}
else if (Rating <= 2.5)
{
image.Src = Globals.GetSkinPath() + "/images/Star2half.gif";
text = ResourceManager.GetString("PostRating_Three");
}
else if (Rating <= 3)
{
image.Src = Globals.GetSkinPath() + "/images/Star3.gif";
text = ResourceManager.GetString("PostRating_Three");
}
else if (Rating <= 3.5)
{
image.Src = Globals.GetSkinPath() + "/images/Star3half.gif";
text = ResourceManager.GetString("PostRating_Four");
}
else if (Rating <= 4)
{
image.Src = Globals.GetSkinPath() + "/images/Star4.gif";
text = ResourceManager.GetString("PostRating_Four");
}
else if (Rating <= 4.5)
{
image.Src = Globals.GetSkinPath() + "/images/Star4Half.gif";
text = ResourceManager.GetString("PostRating_Five");
}
else
{
image.Src = Globals.GetSkinPath() + "/images/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", Thread.TotalRatings);
else
image.Alt = string.Format(ResourceManager.GetString("PostRating_AltText"), text, Rating.ToString("#.##"), Thread.TotalRatings);
anchor.Controls.Add(image);
anchor.HRef = "javascript:OpenWindow('" + Globals.GetSiteUrls().PostRating(Thread.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 Thread 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" );
// }
}
}
Thread _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( 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 + -