温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:SpaceBuilder v1.0正式版源码
当前文件:
SpaceBuiderV10Source/BlogControls/Channel/PostRanks.cs,打开代码结构图
SpaceBuiderV10Source/BlogControls/Channel/PostRanks.cs,打开代码结构图1//------------------------------------------------------------------------------ 2
// <copyright company="Tunynet"> 3
// Copyright (c) Tunynet Network Technology Co., Ltd. All rights reserved. 4
// </copyright> 5
//------------------------------------------------------------------------------ 6
7
using System; 8
using System.Collections.Generic; 9
using System.Text; 10
using SpaceBuilder.Components; 11
using SpaceBuilder.Blogs.Components; 12
using System.Web.UI.HtmlControls; 13
using System.Web.UI.WebControls; 14
using SpaceBuilder.Controls.BaseClasses; 15
using SpaceBuilder.Controls.Utils; 16
using SpaceBuilder.Utils; 17
using SpaceBuilder.Controls; 18
using TunyNet.Utils; 19
using TunyNet.Data.Utils; 20
using System.Threading; 21
22
namespace SpaceBuilder.Blogs.Controls 23
{ 24
public class PostRanks : TemplatedWebControl 25
{ 26
SBContext wlContext; 27
28
protected override void OnInit(EventArgs e) 29
{ 30
if (SkinName == null) 31
ExternalSkinFileName = "Blogs/Skin-PostRanks.ascx"; 32
else 33
ExternalSkinFileName = SkinName; 34
35
wlContext = SBContext.Current; 36
37
base.OnInit(e); 38
} 39
40
Child Controls 58
59
protected override void AttachChildControls() 60
{ 61
rankByMostRecentLi = FindControl("RankByMostRecentLi") as HtmlControl; 62
rankByMostRecent = FindControl("RankByMostRecent") as HyperLink; 63
rankByTotalViewsLi = FindControl("RankByTotalViewsLi") as HtmlControl; 64
rankByTotalViews = FindControl("RankByTotalViews") as HyperLink; 65
rankByTotalRepliesLi = FindControl("RankByTotalRepliesLi") as HtmlControl; 66
rankByTotalReplies = FindControl("RankByTotalReplies") as HyperLink; 67
rankByTotalRatingsLi = FindControl("RankByTotalRatingsLi") as HtmlControl; 68
rankByTotalRatings = FindControl("RankByTotalRatings") as HyperLink; 69
70
71
pager = FindControl("Pager") as PostBackPager; 72
pager.PageIndexChanged += new PagerEventHandler(Pager_PageIndexChanged); 73
74
75
pager2 = FindControl("Pager2") as Pager; 76
77
postsRepeater = FindControl("PostsRepeater") as Repeater; 78
postsRepeater.ItemDataBound += new RepeaterItemEventHandler(PostsRepeater_ItemDataBound); 79
} 80
81
void Pager_PageIndexChanged(object sender, PagerEventArgs e) 82
{ 83
Bind(); 84
} 85
86
protected override void OnLoad(EventArgs e) 87
{ 88
base.OnLoad(e); 89
EnsureChildControls(); 90
91
/* 92
RankBy={0} 93
*/ 94
if (wlContext.GetIntFromQueryString("RankBy", 0) > 0) 95
this.SortBy = (BlogThreadSortBy)wlContext.GetIntFromQueryString("RankBy", 0); 96
97
if (!Page.IsPostBack) 98
Bind(); 99
} 100
101
void Bind() 102
{ 103
Header.AddTitle(wlContext.SiteName + " :: 博客 - 文章排行", Context); 104
switch (this.SortBy) 105
{ 106
case BlogThreadSortBy.MostRecent: 107
rankByMostRecentLi.Attributes["class"] = "selected"; 108
break; 109
case BlogThreadSortBy.TotalViews: 110
rankByTotalViewsLi.Attributes["class"] = "selected"; 111
break; 112
case BlogThreadSortBy.TotalReplies: 113
rankByTotalRepliesLi.Attributes["class"] = "selected"; 114
break; 115
case BlogThreadSortBy.TotalRatings: 116
rankByTotalRatingsLi.Attributes["class"] = "selected"; 117
break; 118
} 119
//测试用 120
// string asdfasdf= ChannelUrls.Instance().BlogsForTab(10, (int)SortBlogsBy.WeekHitTimes, SortOrder.Descending); 121
rankByMostRecent.NavigateUrl = ChannelUrls.Instance().WeblogPostRanks((int)BlogThreadSortBy.MostRecent); 122
rankByTotalViews.NavigateUrl = ChannelUrls.Instance().WeblogPostRanks((int)BlogThreadSortBy.TotalViews); 123
rankByTotalReplies.NavigateUrl = ChannelUrls.Instance().WeblogPostRanks((int)BlogThreadSortBy.TotalReplies); 124
rankByTotalRatings.NavigateUrl = ChannelUrls.Instance().WeblogPostRanks((int)BlogThreadSortBy.TotalRatings); 125
126
BlogThreadQuery query = new BlogThreadQuery(); 127
query.IsPublicFilter = true; 128
query.IncludeTags = false; 129
//query.MaxRecords = 500; 130
query.SortBy = this.SortBy; 131
query.SortOrder = SortOrder.Descending; 132
query.PageIndex = pager.PageIndex; 133
134
PagingDataSet<BlogThread> pds = BlogPosts.GetBlogThreads(query); 135
136
if (pds != null) 137
{ 138
if (pager != null) 139
{ 140
pager.TotalRecords = pds.TotalRecords; 141
pager.PageSize = query.PageSize; 142
} 143
if (pager2 != null) 144
{ 145
pager2.TotalRecords = pds.TotalRecords; 146
pager2.PageSize = query.PageSize; 147
} 148
} 149
150
postsRepeater.DataSource = pds.Records; 151
postsRepeater.DataBind(); 152
} 153
154
private void PostsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) 155
{ 156
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 157
{ 158
BlogThread post = (BlogThread)e.Item.DataItem; 159
if (post != null) 160
{ 161
HyperLink subject = e.Item.FindControl("Subject") as HyperLink; 162
if (subject != null) 163
{ 164
subject.Text = StringUtils.Trim(post.Subject, 30); 165
subject.ToolTip = post.Subject; 166
subject.NavigateUrl = BlogUrls.Instance().ShowPost(post); 167
subject.Attributes["target"] = "_blank"; 168
} 169
170
Literal blogPostType = e.Item.FindControl("BlogPostType") as Literal; 171
if (blogPostType != null) 172
blogPostType.Text = post.BlogPostTypeText; 173
174
Literal postDate = e.Item.FindControl("PostDate") as Literal; 175
if (postDate != null) 176
postDate.Text = Formatter.FormatDate(post.PostDate); 177
178
Literal totalReplies = e.Item.FindControl("TotalReplies") as Literal; 179
if (totalReplies != null) 180
totalReplies.Text = post.ReplyCount.ToString(); 181
182
Literal totalViews = e.Item.FindControl("TotalViews") as Literal; 183
if (totalViews != null) 184
totalViews.Text = post.HitTimes.ToString(); 185
RatingButton ratingButton = e.Item.FindControl("PostRating") as RatingButton; 186
if (ratingButton != null) 187
{ 188
ratingButton.TotalRatings = post.TotalRatings; 189
ratingButton.RatingSum = post.RatingSum; 190
ratingButton.ThreadID = post.ThreadID; 191
ratingButton.ApplicationType = ApplicationType.Blog; 192
} 193
194
HyperLink blogName = e.Item.FindControl("BlogName") as HyperLink; 195
if (blogName != null) 196
{ 197
blogName.Text = post.Weblog.SectionName; 198
if (ValueHelper.IsNullOrEmpty(blogName.Text)) 199
blogName.Text = post.User.DisplayName; 200
201
blogName.ToolTip = string.Format("查看 {0} 的博客", blogName.Text); 202
blogName.NavigateUrl = UserUrls.Instance().BlogHome(post.Weblog.ApplicationKey); 203
blogName.Attributes["target"] = "_blank"; 204
} 205
} 206
} 207
} 208
209
210
属性 223
224
} 225
}





}
}