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





}