温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:SpaceBuilder v1.1源代码
当前文件:
SpaceBuider11/BlogControls/Admin/ContentList.cs,打开代码结构图
SpaceBuider11/BlogControls/Admin/ContentList.cs,打开代码结构图1//------------------------------------------------------------------------------ 2
// <copyright company="Tunynet"> 3
// Copyright (c) Tunynet Inc. All rights reserved. 4
// </copyright> 5
//------------------------------------------------------------------------------ 6
7
using System; 8
using System.Web.UI.WebControls; 9
10
using SpaceBuilder.Blogs.Components; 11
using SpaceBuilder.Components; 12
using SpaceBuilder.Controls; 13
using SpaceBuilder.Controls.Utils; 14
using SpaceBuilder.Security; 15
using SpaceBuilder.Utils; 16
using SpaceBuilder.Posts.Permissions; 17
using TunyNet.Utils; 18
using TunyNet.Data.Utils; 19
20
namespace SpaceBuilder.Blogs.Controls 21
{ 22
/// <summary> 23
/// 管理我的文章 24
/// </summary> 25
public class ContentList : WeblogThemedControl 26
{ 27
/// <summary> 28
/// 验证当前用户身份 29
/// </summary> 30
protected override void Authorize(Weblog w) 31
{ 32
base.Authorize(w); 33
if (CurrentUser.IsAnonymous) 34
PermissionBase.RedirectOrExcpetion(SBExceptionType.AccessDenied, "不允许匿名用户访问"); 35
36
if (!CurrentUser.IsBlogAdministrator) 37
Permissions.AccessCheck(w, Permission.Post, CurrentUser); 38
} 39
Child Controls 67
/// <summary> 68
/// 从加载的皮肤文件中获取具体控件 69
/// </summary> 70
protected override void AttachChildControls() 71
{ 72
pageTitle = FindControl("PageTitle") as Literal; 73
createWebPostButton = FindControl("CreateWebPostButton") as HyperLink; 74
manageTagsButton = FindControl("ManageTagsButton") as HyperLink; 75
//获取删除按钮控件 76
batchDeleteButton = FindControl("BatchDeleteButton") as LinkButton; 77
if (batchDeleteButton != null) 78
{ 79
//注册删除按钮单击事件 80
batchDeleteButton.Click += new EventHandler(BatchDelete_Click); 81
//添加客户端单击属性,弹出删除提示框。按钮被单击时,会首先触发它 82
batchDeleteButton.Attributes.Add("onclick", "if ( !confirm('是否删除选中的所有文章?') ) {return false; } "); 83
} 84
pager = FindControl("Pager") as PostBackPager; 85
pager.PageIndexChanged += new PagerEventHandler(pager_PageIndexChanged); 86
87
postListRepeater = FindControl("PostListRepeater") as Repeater; 88
89
if (postListRepeater != null) 90
{ 91
postListRepeater.ItemDataBound += new RepeaterItemEventHandler(PostListRepeater_ItemDataBound); 92
postListRepeater.ItemCommand += new RepeaterCommandEventHandler(PostListRepeater_ItemCommand); 93
} 94
} 95
96
protected override void OnLoad(EventArgs e) 97
{ 98
base.OnLoad(e); 99
EnsureChildControls(); 100
if (!Page.IsPostBack) 101
Bind(); 102
} 103
104
void Bind() 105
{ 106
if (pageTitle != null) 107
//设置控件标题 108
pageTitle.Text = "管理我的文章"; 109
this.SetPageTitle("管理我的文章"); 110
//设置发布文章的链接地址为当前博客的文章编辑页地址 111
createWebPostButton.NavigateUrl = BlogUrls.Instance().PostEditor(CurrentWeblog.ApplicationKey); 112
manageTagsButton.NavigateUrl = GlobalUrls.Instance().ManageUserTags(CurrentDomainUser.UserName, CurrentDomainUser.UserType, TagType.Blog); 113
//实例化一个博客主题查询对象 114
BlogThreadQuery query = new BlogThreadQuery(); 115
//博客ID 116
query.SectionID = this.CurrentWeblog.SectionID; 117
//设置文章实体的限定条件为近期的文章 118
query.BlogThreadType = BlogThreadType.Recent; 119
//获取的实体集中带有文章的标签 120
query.IncludeTags = true; 121
//只显示公开博客主题 122
query.IsPublicFilter = false; 123
//设置当前页页码为分页控件的当前页码 124
query.PageIndex = pager.PageIndex; 125
//设置一页显示的记录数 126
query.PageSize = this.displayItemCount; 127
//设置排序顺序为降序 128
query.SortOrder = SortOrder.Descending; 129
//设置排序依据为按最近时间排序 130
query.SortBy = BlogThreadSortBy.MostRecent; 131
//按查询条件获取博客文章集合 132
PagingDataSet<BlogThread> threads = BlogPosts.GetBlogThreads(query); 133
postListRepeater.DataSource = threads.Records; 134
postListRepeater.DataBind(); 135
136
if (threads.Records != null) 137
{ 138
pager.TotalRecords = threads.TotalRecords; 139
pager.PageSize = query.PageSize; 140
if (pager.TotalRecords <= pager.PageSize) 141
pager.ShowTotalSummary = false; 142
} 143
} 144
145
private void PostListRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) 146
{ 147
BlogThread wet = e.Item.DataItem as BlogThread; 148
if (wet != null) 149
{ 150
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 151
{ 152
//获取选中复选框 153
CheckBox selector = e.Item.FindControl("Selector") as CheckBox; 154
if (selector != null) 155
{ 156
//绑定博客主题ID 157
selector.Attributes["value"] = wet.PostID.ToString(); 158
} 159
160
HyperLink litTitle = e.Item.FindControl("Title") as HyperLink; 161
if (litTitle != null) 162
{ 163
litTitle.Text = StringUtils.Trim(wet.Subject, 15); 164
litTitle.NavigateUrl = BlogUrls.Instance().ShowPost(wet, CurrentWeblog); 165
litTitle.ToolTip = string.Format("{0}:{1}", ResourceManager.GetString("View"), WebUtils.HtmlDecode(wet.Subject)); 166
switch (wet.BlogPostType) 167
{ 168
case BlogPostType.Post: 169
litTitle.Text += "[原创]"; 170
break; 171
case BlogPostType.Article: 172
litTitle.Text += "[转帖]"; 173
break; 174
} 175
} 176
177
Literal tags = e.Item.FindControl("Tags") as Literal; 178
if (tags != null) 179
{ 180
if (wet.Tags.Count > 0) 181
{ 182
foreach (UserTag tag in wet.Tags) 183
{ 184
tags.Text += string.Format("<a href='{0}' title='此标签下还有{1}篇文章'>{2}</a> ", GlobalUrls.Instance().ShowBlogPostsByTag(CurrentDomainUser.UserName, tag.TagName), tag.ItemCount, tag.TagName); 185
} 186
} 187
} 188
189
Literal litPubDate = e.Item.FindControl("PubDate") as Literal; 190
if (litPubDate != null) 191
litPubDate.Text = Formatter.FormatDate(wet.PostDate); 192
193
Image publishStatus = e.Item.FindControl("PublishStatus") as Image; 194
if (wet.IsPublic) 195
{ 196
publishStatus.ImageUrl = "~/Utility/Icons/icon_true.gif"; 197
publishStatus.ToolTip = "此文章已发布"; 198
} 199
else 200
{ 201
publishStatus.ToolTip = "此文章未发布"; 202
publishStatus.ImageUrl = "~/Utility/Icons/icon_false.gif"; 203
} 204
205
Literal litReads = e.Item.FindControl("Reads") as Literal; 206
if (litReads != null) 207
litReads.Text = wet.HitTimes.ToString(); 208
209
Literal litAggReads = e.Item.FindControl("AggReads") as Literal; 210
if (litAggReads != null) 211
litAggReads.Text = wet.RssViewTimes.ToString(); 212
213
Literal litComments = e.Item.FindControl("Comments") as Literal; 214
if (litComments != null) 215
litComments.Text = wet.ReplyCount.ToString(); 216
217
ImageButton EditButton = e.Item.FindControl("Edit") as ImageButton; 218
if (EditButton != null) 219
{ 220
EditButton.CommandArgument = wet.PostID.ToString(); 221
//EditButton.Text = ResourceManager.GetString("Edit"); 222
} 223
224
ImageButton DeleteButton = e.Item.FindControl("Delete") as ImageButton; 225
if (DeleteButton != null) 226
{ 227
DeleteButton.CommandArgument = wet.PostID.ToString(); 228
//DeleteButton.Text = ResourceManager.GetString("Delete"); 229
DeleteButton.Attributes["onclick"] = "if ( !confirm('确认要删除此篇文章吗?') ) {return false; } "; 230
} 231
232
HyperLink referrals = e.Item.FindControl("ReferralLink") as HyperLink; 233
if (referrals != null) 234
{ 235
referrals.NavigateUrl = BlogUrls.Instance().ReferralToPost(this.CurrentWeblog.ApplicationKey, wet.PostID); 236
referrals.Text = "访问记录"; 237
} 238
} 239
} 240
} 241
242
private void PostListRepeater_ItemCommand(object source, RepeaterCommandEventArgs e) 243
{ 244
switch (e.CommandName) 245
{ 246
case "Edit": 247
Context.Response.Redirect(BlogUrls.Instance().PostEditor(CurrentWeblog.ApplicationKey, int.Parse((string)e.CommandArgument)), true); 248
break; 249
case "Delete": 250
BlogPosts.DeletePost(int.Parse((string)e.CommandArgument)); 251
//Context.Response.Redirect(BlogUrls.Instance().ManageContents(CurrentWeblog.ApplicationKey), true); 252
Bind(); 253
break; 254
} 255
} 256
257
private void BatchDelete_Click(object sender, EventArgs e) 258
{ 259
foreach (RepeaterItem item in this.postListRepeater.Items) 260
{ 261
CheckBox selector = item.FindControl("Selector") as CheckBox; 262
if (selector != null && selector.Checked) 263
{ 264
Int32 postID = Convert.ToInt32(selector.Attributes["value"]); 265
BlogPosts.DeletePost(postID); 266
} 267
} 268
Bind(); 269
} 270
271
void pager_PageIndexChanged(object sender, PagerEventArgs e) 272
{ 273
Bind(); 274
} 275
276
公有属性




