📄 galleryratepost.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Text;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.Galleries.Components;
namespace CommunityServer.Galleries.Controls
{
/// <summary>
/// Summary description for BlogRatePost.
/// </summary>
public class GalleryRatePost : GalleryThemedControl
{
public event EventHandler RatingsChanged;
#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;
public Picture Post
{
get
{
if(picture == null)
picture = Pictures.GetPicture(PictureID);
return picture;
}
set { picture = value; }
}
#endregion
#region Skin
protected override void AttachChildControls()
{
LinkButton l;
l = (LinkButton) FindControl("RateZero");
l.CommandArgument = "0";
l.Text = ResourceManager.GetString("PostRating_Zero");
l.Click += new EventHandler(RateTopic_Click);
l = (LinkButton) FindControl("RateOne");
l.CommandArgument = "1";
l.Text = ResourceManager.GetString("PostRating_One");
l.Click += new EventHandler(RateTopic_Click);
l = (LinkButton) FindControl("RateTwo");
l.CommandArgument = "2";
l.Text = ResourceManager.GetString("PostRating_Two");
l.Click += new EventHandler(RateTopic_Click);
l = (LinkButton) FindControl("RateThree");
l.CommandArgument = "3";
l.Text = ResourceManager.GetString("PostRating_Three");
l.Click += new EventHandler(RateTopic_Click);
l = (LinkButton) FindControl("RateFour");
l.CommandArgument = "4";
l.Text = ResourceManager.GetString("PostRating_Four");
l.Click += new EventHandler(RateTopic_Click);
l = (LinkButton) FindControl("RateFive");
l.CommandArgument = "5";
l.Text = ResourceManager.GetString("PostRating_Five");
l.Click += new EventHandler(RateTopic_Click);
string imagePath = Globals.GetSkinPath() + "/images/ratetopic.gif";
string imagePathDown = Globals.GetSkinPath() + "/images/ratetopic.gif";
string imagePathOver = Globals.GetSkinPath() + "/images/ratetopic_Over.gif";
HyperLink RateLink = FindControl("RateLink") as HyperLink;
RateLink.Attributes.Add("onMouseOver", "src='" + imagePathOver + "'");
RateLink.Attributes.Add("onMouseOut", "src='" + imagePath + "'");
RateLink.Attributes.Add("onMouseDown", "src='" + imagePathDown + "'");
RateLink.Text = ResourceManager.GetString("Gallery_RatingListing_AddRating");
RateLink.NavigateUrl = "javascript:ToggleRateMenu()";
}
#endregion
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
ApplicationKey = CSContext.Current.ApplicationKey;
PictureID = CSContext.Current.PostID;
}
void RateTopic_Click (object sender, EventArgs e)
{
LinkButton l = (LinkButton) sender;
int rate = int.Parse(l.CommandArgument);
if(SelectedValue != rate)
{
Ratings.Rate( this.Post.ThreadID, CSContext.Current.User.UserID, rate);
SelectedValue = rate;
OnRatingsChange(e);
Page.Response.Redirect(Page.Request.RawUrl);
}
}
protected int SelectedValue
{
get
{
object obj = ViewState["SelectedValue"];
if(obj == null)
return -1;
else
return (int)obj;
}
set {ViewState["SelectedValue"] = value;}
}
protected void OnRatingsChange(EventArgs e)
{
if(RatingsChanged != null)
RatingsChanged(this,e);
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender (e);
StringBuilder sb = new StringBuilder();
sb.Append("<script language =\"javascript\">");
sb.Append(" function ToggleRateMenu() {");
sb.Append(" rateMenu = document.getElementById('RateMenu');");
sb.Append(" rateButton = document.getElementById('RateButton');");
sb.Append("");
sb.Append(" rateMenu.style.left = getposOffset(rateButton, \"left\");");
sb.Append(" rateMenu.style.top = getposOffset(rateButton, \"top\") + rateButton.offsetHeight;");
sb.Append("");
sb.Append(" if (rateMenu.style.visibility == \"hidden\") {");
sb.Append(" rateMenu.style.visibility = \"visible\";");
sb.Append(" rateMenu.style.display = 'block';");
sb.Append(" } else {");
sb.Append(" rateMenu.style.visibility = \"hidden\";");
sb.Append(" rateMenu.style.display = 'none';");
sb.Append(" }");
sb.Append(" }");
sb.Append(" ");
sb.Append(" function getposOffset(what, offsettype){");
sb.Append(" var totaloffset=(offsettype==\"left\")? what.offsetLeft : what.offsetTop;");
sb.Append(" var parentEl=what.offsetParent;");
sb.Append(" while (parentEl!=null){");
sb.Append(" totaloffset=(offsettype==\"left\")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;");
sb.Append(" parentEl=parentEl.offsetParent;");
sb.Append(" }");
sb.Append(" return totaloffset;");
sb.Append("}");
sb.Append("</script>");
Page.RegisterClientScriptBlock("RatePost",sb.ToString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -