📄 itemdiscussicon.cs
字号:
namespace ASPNET.StarterKit.Communities {
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using ASPNET.StarterKit.Communities.Discuss;
//*********************************************************************
//
// ItemDiscussIcon Class
//
// Displays different images indicating the type of post:
//
// * Pinned
// * Announcement
// * Popular
//
//*********************************************************************
public class ItemDiscussIcon : WebControl {
int _popularCount = 0;
string _popularImage = "~/Communities/Common/Images/HasRead/Popular.Gif";
string _readImage = "~/Communities/Common/Images/HasRead/Read.Gif";
string _notReadImage = "~/Communities/Common/Images/HasRead/NotRead.Gif";
string _announcementReadImage = "~/Communities/Common/Images/Discuss/Announce_Read.Gif";
string _announcementNotReadImage = "~/Communities/Common/Images/Discuss/Announce_NotRead.Gif";
string _pinnedReadImage = "~/Communities/Common/Images/Discuss/Pinned_Read.Gif";
string _pinnedNotReadImage = "~/Communities/Common/Images/Discuss/Pinned_NotRead.Gif";
string _pinnedLockedReadImage = "~/Communities/Common/Images/Discuss/PinnedLocked_Read.Gif";
string _pinnedLockedNotReadImage = "~/Communities/Common/Images/Discuss/PinnedLocked_NotRead.Gif";
string _lockedReadImage = "~/Communities/Common/Images/Discuss/Locked_Read.Gif";
string _lockedNotReadImage = "~/Communities/Common/Images/Discuss/Locked_NotRead.Gif";
//*********************************************************************
//
// ReadImage Property
//
// The path to the image that is displayed when user has read item
//
//*********************************************************************
public string ReadImage {
get {return _readImage; }
set {_readImage = value; }
}
//*********************************************************************
//
// NotReadImage Property
//
// The path to the image that is displayed when user has not read item
//
//*********************************************************************
public string NotReadImage {
get {return _notReadImage; }
set {_notReadImage = value; }
}
//*********************************************************************
//
// PopularImage Property
//
// The path to the image that is displayed when item is popular
//
//*********************************************************************
public string PopularImage {
get {return _popularImage; }
set {_popularImage = value; }
}
//*********************************************************************
//
// PopularCount Property
//
// How many users must read to make this item popular
//
//*********************************************************************
public int PopularCount {
get {return _popularCount; }
set {_popularCount = value; }
}
//*********************************************************************
//
// HasRead Property
//
// Store the HasRead property in View State
//
//*********************************************************************
public bool HasRead {
get {
if (ViewState["HasRead"] == null)
return false;
else
return (bool)ViewState["HasRead"];
}
set { ViewState["HasRead"] = value; }
}
//*********************************************************************
//
// ViewCount Property
//
// Store the ViewCount property in View State
//
//*********************************************************************
public int ViewCount {
get {
if (ViewState["ViewCount"] == null)
return 0;
else
return (int)ViewState["ViewCount"];
}
set { ViewState["ViewCount"] = value; }
}
//*********************************************************************
//
// Pinned Property
//
// Store the Pinned property in View State
//
//*********************************************************************
public bool Pinned {
get {
if (ViewState["Pinned"] == null)
return false;
else
return (bool)ViewState["Pinned"];
}
set { ViewState["Pinned"] = value; }
}
//*********************************************************************
//
// Announcement Property
//
// Store the Announcement property in View State
//
//*********************************************************************
public bool Announcement {
get {
if (ViewState["Announcement"] == null)
return false;
else
return (bool)ViewState["Announcement"];
}
set { ViewState["Announcement"] = value; }
}
//*********************************************************************
//
// Locked Property
//
// Store the Locked property in View State
//
//*********************************************************************
public bool Locked {
get {
if (ViewState["Locked"] == null)
return false;
else
return (bool)ViewState["Locked"];
}
set { ViewState["Locked"] = value; }
}
//*********************************************************************
//
// ItemDiscussIcon Constructor
//
// Assign a default css style (the user can override)
//
//*********************************************************************
public ItemDiscussIcon() {
CssClass = "itemDiscussIcon";
EnableViewState = false;
}
//*********************************************************************
//
// OnDataBinding Method
//
// Get the read status from the container's DataItem property
//
//*********************************************************************
override protected void OnDataBinding(EventArgs e) {
ContentItem item;
if (NamingContainer is ContentItem)
item = (ContentItem)NamingContainer;
else
item = (ContentItem)NamingContainer.NamingContainer;
PostInfo objPostInfo = (PostInfo)item.DataItem;
HasRead = objPostInfo.HasRead;
ViewCount = objPostInfo.ViewCount;
Announcement = objPostInfo.IsAnnouncement;
Pinned = objPostInfo.IsPinned;
Locked = objPostInfo.IsLocked;
}
//*********************************************************************
//
// RenderContents Method
//
// Display the HasRead image
//
//*********************************************************************
override protected void RenderContents(HtmlTextWriter writer) {
// if popular, than just show that
if (_popularCount > 0 && ViewCount > _popularCount) {
writer.Write(String.Format("<img src=\"{0}\">", Page.ResolveUrl(_popularImage)));
return;
}
// Otherwise, show Pinned and Locked
if (Pinned && Locked) {
if (HasRead)
writer.Write(String.Format("<img src=\"{0}\">", Page.ResolveUrl(_pinnedLockedReadImage)));
else
writer.Write(String.Format("<img src=\"{0}\">", Page.ResolveUrl(_pinnedLockedNotReadImage)));
return;
}
// Otherwise, show Pinned
if (Pinned) {
if (HasRead)
writer.Write(String.Format("<img src=\"{0}\">", Page.ResolveUrl(_pinnedReadImage)));
else
writer.Write(String.Format("<img src=\"{0}\">", Page.ResolveUrl(_pinnedNotReadImage)));
return;
}
// Otherwise, show announcement
if (Announcement) {
if (HasRead)
writer.Write(String.Format("<img src=\"{0}\">", Page.ResolveUrl(_announcementReadImage)));
else
writer.Write(String.Format("<img src=\"{0}\">", Page.ResolveUrl(_announcementNotReadImage)));
return;
}
// Otherwise, show locked
if (Locked) {
if (HasRead)
writer.Write(String.Format("<img src=\"{0}\">", Page.ResolveUrl(_lockedReadImage)));
else
writer.Write(String.Format("<img src=\"{0}\">", Page.ResolveUrl(_lockedNotReadImage)));
return;
}
// Finally, just show Read status
if (HasRead)
writer.Write(String.Format("<img src=\"{0}\">", Page.ResolveUrl(_readImage)));
else
writer.Write(String.Format("<img src=\"{0}\">", Page.ResolveUrl(_notReadImage)));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -