Asp.net源码专业站
首页->博客空间->SpaceBuilder v1.1源代码>>BasicWebControls/Manage/File/ManageFiles.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:SpaceBuilder v1.1源代码
当前文件:文件类型 SpaceBuider11/BasicWebControls/Manage/File/ManageFiles.cs[10K,2009-6-12 11:54:33]打开代码结构图
普通视图
		            
1//------------------------------------------------------------------------------ 2// <copyright company="Tunynet"> 3// Copyright (c) Tunynet Inc. All rights reserved. 4// </copyright> 5//------------------------------------------------------------------------------ 6using System; 7using System.Collections.Generic; 8using System.Text; 9using SpaceBuilder.Components; 10using SpaceBuilder.Posts.Permissions; 11using System.Web.UI.WebControls; 12using SpaceBuilder.Controls.Utils; 13using SpaceBuilder.Files.Components; 14using TunyNet.Data.Utils; 15using TunyNet.Utils; 16using SpaceBuilder.Files.Controls; 17using SpaceBuilder.Utils; 18using System.Web; 19 20namespace SpaceBuilder.Web.Manage.Controls 21{ 22 /// <summary> 23 /// 后台管理文件 24 /// </summary> 25 public class ManageFiles : ManageBaseControl 26 { 27 28 protected override void OnInit(EventArgs e) 29 { 30 if (SkinName == null) 31 SkinName = "Files/Skin-ManageFiles.ascx"; 32 33 base.OnInit(e); 34 } 35 36 /// <summary> 37 /// 验证权限 38 /// </summary> 39 protected override void Authorize() 40 { 41 base.Authorize(); 42 43 if (!SBContext.Current.User.IsFileAdministrator) 44 PermissionBase.RedirectOrExcpetion(SBExceptionType.AccessDenied); 45 } 46 47 protected override void OnLoad(EventArgs e) 48 { 49 base.OnLoad(e); 50 EnsureChildControls(); 51 if (!Page.IsPostBack) 52 { 53 this.Bind(); 54 } 55 SetPageTitle("站点文件管理"); 56 } 57 58 Child Controls 89 90 protected override void AttachChildControls() 91 { 92 subjectKeywords = FindControl("SubjectKeywords") as TextBox; 93 isPublicFilter = FindControl("IsPublicFilter") as CheckBox; 94 userID = FindControl("UserID") as TextBox; 95 96 searchButton = FindControl("SearchButton") as LinkButton; 97 if (searchButton != null) 98 searchButton.Click += new EventHandler(SearchButton_Click); 99 100 101 //获取删除按钮控件 102 batchDeleteButton = FindControl("BatchDeleteButton") as LinkButton; 103 if (batchDeleteButton != null) 104 { 105 //注册删除按钮单击事件 106 batchDeleteButton.Click += new EventHandler(BatchDelete_Click); 107 //添加客户端单击属性,弹出删除提示框。按钮被单击时,会首先触发它 108 batchDeleteButton.Attributes.Add("onclick", "if ( !confirm('是否删除选中的所有文件?') ) {return false; } "); 109 } 110 111 pager = FindControl("Pager") as PostBackPager; 112 if (pager != null) 113 pager.PageIndexChanged += new PagerEventHandler(pager_PageIndexChanged); 114 115 fileRepeater = FindControl("FileRepeater") as Repeater; 116 if (fileRepeater != null) 117 { 118 fileRepeater.ItemDataBound += new RepeaterItemEventHandler(FileRepeater_ItemDataBound); 119 fileRepeater.ItemCommand += new RepeaterCommandEventHandler(FileRepeater_ItemCommand); 120 } 121 } 122 123 124 void Bind() 125 { 126 FileThreadQuery query = new FileThreadQuery(); 127 query.OnlyApproved = false; 128 query.PageIndex = pager.PageIndex; 129 query.PageSize = pager.PageSize; 130 query.SortOrder = SortOrder.Descending; 131 query.SortBy = FileThreadsSortBy.PostDate; 132 133 if (!ValueHelper.IsNullOrEmpty(subjectKeywords.Text)) 134 query.SubjectKeywords = subjectKeywords.Text.Trim(); 135 if (!ValueHelper.IsNullOrEmpty(userID.Text)) 136 query.UserID = int.Parse(userID.Text.Trim()); ; 137 if (isPublicFilter.Checked) 138 query.OnlyApproved = true; 139 else 140 query.OnlyApproved = false; 141 142 PagingDataSet<FileThread> threads = FilePosts.GetThreads(query); 143 fileRepeater.DataSource = threads.Records; 144 fileRepeater.DataBind(); 145 146 if (threads.Records != null) 147 { 148 pager.TotalRecords = threads.TotalRecords; 149 } 150 } 151 152 private void FileRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) 153 { 154 FileThread thread = e.Item.DataItem as FileThread; 155 if (thread != null) 156 { 157 if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 158 { 159 //获取选中复选框 160 CheckBox selector = e.Item.FindControl("Selector") as CheckBox; 161 if (selector != null) 162 { 163 //绑定博客主题ID 164 selector.Attributes["PostID"] = thread.PostID.ToString(); 165 } 166 167 HyperLink litSubject = e.Item.FindControl("Subject") as HyperLink; 168 if (litSubject != null) 169 { 170 litSubject.Text = StringUtils.Trim(thread.Subject, 15); 171 litSubject.NavigateUrl = FileUrls.Instance().ViewFile(thread.SectionID, thread.PostID); 172 litSubject.ToolTip = thread.Subject; 173 } 174 175 FileThumbnail fileThumbnail = e.Item.FindControl("FileThumbnail") as FileThumbnail; 176 if (fileThumbnail != null) 177 fileThumbnail.Thread = thread; 178 179 //获取作者链接控件 180 HyperLink PostedBy = e.Item.FindControl("PostedBy") as HyperLink; 181 if (PostedBy != null) 182 { 183 //获取作者的用户名 184 PostedBy.Text = HttpUtility.HtmlEncode(thread.Author); 185 if (thread.UserID > 0) 186 PostedBy.NavigateUrl = UserUrls.Instance().UserChannelHome(thread.UserID, UserDomainMenuType.FileGallery); 187 } 188 189 Image publishStatus = e.Item.FindControl("PublishStatus") as Image; 190 if (thread.IsPublic) 191 { 192 publishStatus.ImageUrl = "~/Utility/Icons/icon_true.gif"; 193 publishStatus.ToolTip = "此文件已公开"; 194 } 195 else 196 { 197 publishStatus.ToolTip = "此文件未公开"; 198 publishStatus.ImageUrl = "~/Utility/Icons/icon_false.gif"; 199 } 200 201 Literal fileSize = e.Item.FindControl("FileSize") as Literal; 202 if (fileSize != null) 203 fileSize.Text = thread.FriendlyFileSize; 204 205 Literal litPostDate = e.Item.FindControl("PostDate") as Literal; 206 if (litPostDate != null) 207 litPostDate.Text = Formatter.FormatDate(thread.PostDate); 208 209 Literal litReplyCount = e.Item.FindControl("ReplyCount") as Literal; 210 if (litReplyCount != null) 211 litReplyCount.Text = thread.ReplyCount.ToString(); 212 213 Literal downloads = e.Item.FindControl("Downloads") as Literal; 214 if (downloads != null) 215 downloads.Text = thread.Downloads.ToString(); 216 217 218 Literal hitTimes = e.Item.FindControl("HitTimes") as Literal; 219 if (hitTimes != null) 220 hitTimes.Text = thread.HitTimes.ToString(); 221 222 ModalLink CommendButton = e.Item.FindControl("CommendButton") as ModalLink; 223 if (CommendButton != null) 224 { 225 CommendButton.Url = GlobalUrls.Instance().CreateCommendedItem(CommendType.FilePost, thread.PostID); 226 } 227 228 HyperLink editButton = e.Item.FindControl("EditButton") as HyperLink; 229 if (editButton != null) 230 editButton.NavigateUrl = FileUrls.Instance().UpdateFile(thread.FileSection.ApplicationKey, thread.PostID); 231 LinkButton deleteButton = e.Item.FindControl("DeleteButton") as LinkButton; 232 if (deleteButton != null) 233 { 234 deleteButton.Attributes.Add("onclick", "if ( !confirm('是否删除选中的文件?') ) {return false; } "); 235 deleteButton.CommandArgument = thread.PostID.ToString(); 236 } 237 } 238 } 239 } 240 241 void pager_PageIndexChanged(object sender, PagerEventArgs e) 242 { 243 Bind(); 244 } 245 246 void SearchButton_Click(object sender, EventArgs e) 247 { 248 Bind(); 249 } 250 251 private void BatchDelete_Click(object sender, EventArgs e) 252 { 253 foreach (RepeaterItem item in this.fileRepeater.Items) 254 { 255 CheckBox selector = item.FindControl("Selector") as CheckBox; 256 if (selector != null && selector.Checked) 257 { 258 int postID = Convert.ToInt32(selector.Attributes["PostID"]); 259 FileThread thread = FilePosts.GetThread(postID); 260 if (thread != null) 261 FilePosts.DeleteThread(thread); 262 } 263 } 264 Bind(); 265 } 266 267 private void FileRepeater_ItemCommand(object source, RepeaterCommandEventArgs e) 268 { 269 switch (e.CommandName) 270 { 271 case "Delete": 272 FileThread thread = FilePosts.GetThread(int.Parse((string)e.CommandArgument)); 273 FilePosts.DeleteThread(thread); 274 Bind(); 275 break; 276 } 277 } 278 } 279} 280
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:SpaceBuilder v1.1源代码