温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:SpaceBuilder v1.1源代码
1//------------------------------------------------------------------------------ 2
// <copyright company="Tunynet"> 3
// Copyright (c) Tunynet Inc. All rights reserved. 4
// </copyright> 5
//------------------------------------------------------------------------------ 6
7
using System; 8
using System.Collections.Generic; 9
using System.Text; 10
using System.Web.UI.WebControls; 11
using SpaceBuilder.Posts.Components; 12
using SpaceBuilder.Components; 13
using SpaceBuilder.Controls.BaseClasses; 14
using SpaceBuilder.Galleries.Components; 15
using TunyNet.Utils; 16
using TunyNet.Data.Utils; 17
using System.Web.UI.HtmlControls; 18
using TunyNet.Web.UI; 19
using System.Web.UI; 20
using SpaceBuilder.Galleries.Configuration; 21
using SpaceBuilder.Blogs.Components; 22
using SpaceBuilder.Blogs.Configuration; 23
using SpaceBuilder.Posts.Configuration; 24
using SpaceBuilder.Files.Components; 25
using SpaceBuilder.Files.Controls; 26
using SpaceBuilder.Controls; 27
using SpaceBuilder.Controls.Utils; 28
29
[assembly: WebResource("SpaceBuilder.Web.Controls.Utility.ContentSelector.js", "text/javascript")] 30
namespace SpaceBuilder.Web.Controls 31
{ 32
/// <summary> 33
/// 内容选择器 34
/// </summary> 35
public class ContentSelector : TemplatedWebControl 36
{ 37
const string BlogTag = "b"; 38
const string GalleryTag = "g"; 39
const string FileTag = "f"; 40
41
SBContext wlContext = SBContext.Current; 42
Weblog currentBlog = null; 43
Gallery currentGallery = null; 44
FileSection currentFileGallery = null; 45
46
protected override void OnInit(EventArgs e) 47
{ 48
if (SkinName == null) 49
ExternalSkinFileName = "Utility/Skin-ContentSelector.ascx"; 50
else 51
ExternalSkinFileName = SkinName; 52
53
wlContext = SBContext.Current; 54
55
base.OnInit(e); 56
} 57
58
TreeView categoryTreeView; 59
60
HtmlContainerControl emptyArea; 61
62
HtmlContainerControl galleryArea; 63
Repeater picturesRepeater; 64
DropDownList imageSizeDropDownList; 65
DropDownList imageLinkDropDownList; 66
HyperLink addPictureLink; 67
68
69
HtmlContainerControl blogArea; 70
Repeater blogAttachmentsRepeater; 71
SpaceBuilder.Controls.Utils.ModalLink addBlogAttachment; 72
73
//FileUpload blogAttachmentFile; 74
//CustomValidator blogAttachmentFileCustomValidator; 75
//TextBox blogAttachmentSaveAsFileName; 76
//LinkButton uploadBlogAttachmentButton; 77
78
HtmlContainerControl fileArea; 79
Repeater filesRepeater; 80
HyperLink addNewFileLink; 81
82
HiddenField currentSelectedItemKey; 83
84
LinkButton selectButton; 85
LinkButton cancelButton; 86
87
protected override void AttachChildControls() 88
{ 89
categoryTreeView = FindControl("CategoryTreeView") as TreeView; 90
categoryTreeView.SelectedNodeChanged += new EventHandler(CategoryTreeView_SelectedNodeChanged); 91
92
emptyArea = FindControl("EmptyArea") as HtmlContainerControl; 93
94
galleryArea = FindControl("GalleryArea") as HtmlContainerControl; 95
picturesRepeater = FindControl("PicturesRepeater") as Repeater; 96
picturesRepeater.ItemDataBound += new RepeaterItemEventHandler(PicturesRepeater_ItemDataBound); 97
imageSizeDropDownList = FindControl("ImageSizeDropDownList") as DropDownList; 98
imageLinkDropDownList = FindControl("ImageLinkDropDownList") as DropDownList; 99
addPictureLink = FindControl("AddPictureLink") as HyperLink; 100
101
blogArea = FindControl("BlogArea") as HtmlContainerControl; 102
blogAttachmentsRepeater = FindControl("BlogAttachmentsRepeater") as Repeater; 103
blogAttachmentsRepeater.ItemDataBound += new RepeaterItemEventHandler(BlogAttachmentsRepeater_ItemDataBound); 104
addBlogAttachment = FindControl("AddBlogAttachment") as SpaceBuilder.Controls.Utils.ModalLink; 105
//blogAttachmentFile = FindControl("BlogAttachmentFile") as FileUpload; 106
//blogAttachmentFileCustomValidator = FindControl("BlogAttachmentFileCustomValidator") as CustomValidator; 107
//blogAttachmentSaveAsFileName = FindControl("BlogAttachmentSaveAsFileName") as TextBox; 108
//uploadBlogAttachmentButton = FindControl("UploadBlogAttachmentButton") as LinkButton; 109
//uploadBlogAttachmentButton.Click += new EventHandler(UploadBlogAttachmentButton_Click); 110
111
fileArea = FindControl("FileArea") as HtmlContainerControl; 112
filesRepeater = FindControl("FilesRepeater") as Repeater; 113
filesRepeater.ItemDataBound += new RepeaterItemEventHandler(FilesRepeater_ItemDataBound); 114
addNewFileLink = FindControl("AddNewFileLink") as HyperLink; 115
116
currentSelectedItemKey = FindControl("CurrentSelectedItemKey") as HiddenField; 117
118
selectButton = FindControl("selectButton") as LinkButton; 119
selectButton.Click += new EventHandler(SelectButton_Click); 120
121
cancelButton = FindControl("cancelButton") as LinkButton; 122
cancelButton.Click += new EventHandler(CancelButton_Click); 123
} 124
125
protected override void OnLoad(EventArgs e) 126
{ 127
base.OnLoad(e); 128
if (wlContext.User.IsAnonymous) 129
{ 130
this.Visible = false; 131
return; 132
} 133
RefreshJavaScript.RegisterRefresh(this.Page); 134
135
currentBlog = Weblogs.GetWeblog(wlContext.User.UserName); 136
currentGallery = SpaceBuilder.Galleries.Components.Galleries.GetGallery(wlContext.User.UserName); 137
currentFileGallery = FileSections.GetSection(wlContext.User.UserName); 138
139
EnsureChildControls(); 140
if (!Page.IsPostBack) 141
{ 142
Header.AddTitle(string.Format("用户内容选择器{0}{1}", Globals.BrowserTitleSeparator, Globals.SiteName), Context); 143
BindTreeView(); 144
} 145
} 146
147
148
/// <summary> 149
/// 绑定TreeView 150
/// </summary> 151
void BindTreeView() 152
{ 153
categoryTreeView.Nodes.Clear(); 154
155
TreeNode blogRootNode = new TreeNode("博客附件", BlogTag + ":all"); 156
categoryTreeView.Nodes.Add(blogRootNode); 157
158
TreeNode galleryRootNode = new TreeNode("我的相册<span class='italic'>(" + currentGallery.PostCount + ")</span>", GalleryTag + ":all"); 159
List<PostCategory> galleryCategories = PostCategories.GetCategories(ApplicationType.Gallery, currentGallery.SectionID); 160
galleryRootNode.Expanded = true; 161
categoryTreeView.Nodes.Add(galleryRootNode); 162
foreach (PostCategory cat in galleryCategories) 163
{ 164
galleryRootNode.ChildNodes.Add(new TreeNode(StringUtils.Trim(cat.CategoryName, 8) + "<span class='italic'>(" + cat.TotalThreads + ")</span>", GalleryTag + ":" + cat.CategoryID)); 165
} 166
167
TreeNode fileGalleryRootNode = new TreeNode("我的文件<span class='italic'>(" + currentFileGallery.TotalThreads + ")</span>", FileTag + ":all"); 168
fileGalleryRootNode.Expanded = true; 169
categoryTreeView.Nodes.Add(fileGalleryRootNode); 170
List<PostCategory> fileCategories = PostCategories.GetCategories(ApplicationType.FileGallery, currentFileGallery.SectionID); 171
foreach (PostCategory cat in fileCategories) 172
{ 173
fileGalleryRootNode.ChildNodes.Add(new TreeNode(StringUtils.Trim(cat.CategoryName, 8) + "<span class='italic'>(" + cat.TotalThreads + ")</span>", FileTag + ":" + cat.CategoryID)); 174
} 175
} 176
177
void CategoryTreeView_SelectedNodeChanged(object sender, EventArgs e) 178
{ 179
string[] selectedValueArray = categoryTreeView.SelectedValue.Split(':'); 180
181
string tag = selectedValueArray[0]; 182
switch (tag) 183
{ 184
case GalleryTag: 185
galleryArea.Visible = true; 186
blogArea.Visible = false; 187
emptyArea.Visible = false; 188
fileArea.Visible = false; 189
BindPictures(selectedValueArray[1]); 190
BindPictureOptions(); 191
break; 192
case BlogTag: 193
blogArea.Visible = true; 194
galleryArea.Visible = false; 195
emptyArea.Visible = false; 196
fileArea.Visible = false; 197
BindBlogAttachments(); 198
break; 199
case FileTag: 200
fileArea.Visible = true; 201
blogArea.Visible = false; 202
galleryArea.Visible = false; 203
emptyArea.Visible = false; 204
BindFiles(selectedValueArray[1]); 205
break; 206
} 207
} 208
209
210
Blog 282
283
相册




