温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:SpaceBuilder v1.0正式版源码
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.Controls.Utils; 12
using System.Web.UI.WebControls; 13
using SpaceBuilder.Posts.Components; 14
using SpaceBuilder.Blogs.Components; 15
using SpaceBuilder.Blogs.Configuration; 16
using TunyNet.Utils; 17
18
namespace SpaceBuilder.Blogs.Controls 19
{ 20
public class ManageAttachments : WeblogAdminThemedControl 21
{ 22
SBContext wlContext = SBContext.Current; 23
24
protected override void OnInit(EventArgs e) 25
{ 26
if (SkinName == null) 27
SkinName = "Skin-ManageAttachments.ascx"; 28
29
wlContext = SBContext.Current; 30
base.OnInit(e); 31
//this.EnableViewState = false; 32
} 33
34
ModalLink addBlogAttachments; 35
Repeater postListRepeater; 36
37
protected override void AttachChildControls() 38
{ 39
addBlogAttachments = FindControl("AddBlogAttachments") as ModalLink; 40
postListRepeater = FindControl("PostListRepeater") as Repeater; 41
42
if (postListRepeater != null) 43
{ 44
postListRepeater.ItemDataBound += new RepeaterItemEventHandler(postListRepeater_ItemDataBound); 45
postListRepeater.ItemCommand += new RepeaterCommandEventHandler(postListRepeater_ItemCommand); 46
} 47
if (addBlogAttachments != null) 48
{ 49
addBlogAttachments.Url = BlogUrls.Instance().UploadBlogAttachment(CurrentWeblog.ApplicationKey); 50
} 51
} 52
53
protected override void OnLoad(EventArgs e) 54
{ 55
base.OnLoad(e); 56
EnsureChildControls(); 57
RefreshJavaScript.RegisterRefresh(this.Page); 58
if (!Page.IsPostBack) 59
Bind(); 60
} 61
62
void Bind() 63
{ 64
List<PostAttachment> attachments = PostAttachments.GetPostAttachtmentMetaDatasBySectionID(CurrentWeblog.SectionID, ApplicationType.Blog); 65
if (attachments != null && attachments.Count > 0) 66
{ 67
postListRepeater.DataSource = attachments; 68
postListRepeater.DataBind(); 69
} 70
} 71
72
void postListRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) 73
{ 74
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 75
{ 76
PostAttachment attachment = e.Item.DataItem as PostAttachment; 77
if (attachment != null) 78
{ 79
HyperLink title = e.Item.FindControl("Title") as HyperLink; 80
if (title != null) 81
{ 82
title.Text = StringUtils.Trim(attachment.FriendlyFileName, 30); 83
title.ToolTip = attachment.FriendlyFileName; 84
title.NavigateUrl = WeblogConfiguration.Instance().AttachmentSettings.DirectPath(attachment); 85
} 86
Literal size = e.Item.FindControl("Size") as Literal; 87
if (size != null) 88
{ 89
size.Text = string.Format("{0}K", Math.Round(Convert.ToDouble(attachment.Length) / 1024, 2)); 90
91
} 92
Literal pubDate = e.Item.FindControl("PubDate") as Literal; 93
if (pubDate != null) 94
{ 95
pubDate.Text = Convert.ToString(attachment.CreateDate); 96
} 97
ImageButton delete = e.Item.FindControl("Delete") as ImageButton; 98
if (delete != null) 99
{ 100
delete.CommandArgument = attachment.AttachmentID.ToString(); 101
delete.Attributes["onclick"] = "if(!confirm('确认要删除此附件吗?')){return false;}"; 102
} 103
Literal blogAttachmentPrefix = e.Item.FindControl("BlogAttachmentPrefix") as Literal; 104
if (blogAttachmentPrefix != null) 105
{ 106
//blogAttachmentPrefix.Text = WeblogConfiguration.Instance().AttachmentSettings.GetImageThumbnail(attachment, 15, CurrentWeblog.ApplicationKey); 107
blogAttachmentPrefix.Text = WeblogConfiguration.Instance().AttachmentSettings.PreviewHTML(attachment, CurrentWeblog.ApplicationKey, FileThumbnailSize.Small); 108
} 109
} 110
} 111
} 112
113
void postListRepeater_ItemCommand(object source, RepeaterCommandEventArgs e) 114
{ 115
switch (e.CommandName) 116
{ 117
case "Delete": 118
int attachmentID = int.Parse((string)e.CommandArgument); 119
PostAttachmentMetaData pa = PostAttachments.GetPostAttachtmentMetaData(attachmentID, ApplicationType.Blog); 120
if (pa != null) 121
{ 122
WeblogConfiguration.Instance().AttachmentSettings.DeleteAttachmentFromDisk(pa); 123
PostAttachments.Delete(int.Parse((string)e.CommandArgument), ApplicationType.Blog); 124
Bind(); 125
} 126
break; 127
} 128
} 129
} 130
} 131






}