您目前尚未登陆,请选择【登陆】或【注册
首页->博客论坛->SpaceBuilder v1.1源代码>>BasicWebControls/Utility/CommendedItemEditor.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:SpaceBuilder v1.1源代码
普通视图
		            
1//------------------------------------------------------------------------------ 2// <copyright company="Tunynet"> 3// Copyright (c) Tunynet Inc. All rights reserved. 4// </copyright> 5//------------------------------------------------------------------------------ 6 7using System; 8using System.Collections.Generic; 9using System.Text; 10using SpaceBuilder.Components; 11using SpaceBuilder.Controls.Utils; 12using System.Web.UI.HtmlControls; 13using System.Web.UI.WebControls; 14using SpaceBuilder.Controls; 15using TunyNet.Data.Utils; 16using SpaceBuilder.Controls.BaseClasses; 17using SpaceBuilder.Blogs.Components; 18using SpaceBuilder.Bookmarks.Components; 19using SpaceBuilder.Clubs.Components; 20using SpaceBuilder.Events.Components; 21using SpaceBuilder.Files.Components; 22using SpaceBuilder.Galleries.Components; 23using TunyNet.Web.UI; 24using SpaceBuilder.Posts.Permissions; 25 26namespace SpaceBuilder.Web.Controls 27{ 28 /// <summary> 29 /// 推荐信息编辑 30 /// </summary> 31 public class CommendedItemEditor : TemplatedWebControl 32 { 33 SBContext sbContext = SBContext.Current; 34 35 CommendType commendType = CommendType.BlogPost; 36 int itemID = -1; 37 38 protected override void OnInit(EventArgs e) 39 { 40 sbContext = SBContext.Current; 41 if (!(sbContext.User.IsContentAdministrator)) 42 PermissionBase.RedirectOrExcpetion(SBExceptionType.AccessDenied); 43 44 if (SkinName == null) 45 ExternalSkinFileName = "Utility/Skin-CommendedItemEditor.ascx"; 46 else 47 ExternalSkinFileName = SkinName; 48 49 base.OnInit(e); 50 } 51 52 StatusMessage statusMessage; 53 HtmlContainerControl commendItemBlock; 54 DropDownList commendTypesDropDownList; 55 LinkButton commendButton; 56 Repeater commendedRepeater; 57 TextBox sortOrder; 58 59 protected override void AttachChildControls() 60 { 61 statusMessage = FindControl("StatusMessage") as StatusMessage; 62 commendItemBlock = FindControl("CommendItemBlock") as HtmlContainerControl; 63 64 commendTypesDropDownList = FindControl("CommendTypesDropDownList") as DropDownList; 65 commendButton = FindControl("CommendButton") as LinkButton; 66 commendButton.Click += new EventHandler(CommendButton_Click); 67 68 commendedRepeater = FindControl("CommendedRepeater") as Repeater; 69 commendedRepeater.ItemDataBound += new RepeaterItemEventHandler(CommendedRepeater_ItemDataBound); 70 commendedRepeater.ItemCommand += new RepeaterCommandEventHandler(CommendedRepeater_ItemCommand); 71 72 sortOrder = FindControl("SortOrder") as TextBox; 73 } 74 75 76 protected override void OnLoad(EventArgs e) 77 { 78 base.OnLoad(e); 79 EnsureChildControls(); 80 Header.AddTitle("推荐信息", Context); 81 82 if (sbContext.GetIntFromQueryString("CommendType", -1) > 0) 83 commendType = (CommendType)sbContext.GetIntFromQueryString("CommendType", -1); 84 85 if (sbContext.GetIntFromQueryString("ItemID", -1) > 0) 86 itemID = sbContext.GetIntFromQueryString("ItemID", -1); 87 88 if (itemID <= 0) 89 return; 90 91 if (!Page.IsPostBack) 92 Bind(); 93 94 } 95 96 private void Bind() 97 { 98 CommendedItemQuery query = new CommendedItemQuery(); 99 query.CommendType = commendType; 100 query.ItemID = itemID; 101 query.PageSize = 999; 102 query.IgnorePaging = true; 103 104 PagingDataSet<CommendedItem> commendedItems = CommendedItems.GetCommendedItems(query); 105 commendedRepeater.DataSource = commendedItems.Records; 106 commendedRepeater.DataBind(); 107 108 commendItemBlock.Visible = true; 109 statusMessage.Visible = false; 110 111 112 IList<CommendedItemType> types = CommendedItems.GetCommendedItemTypes(commendType); 113 114 commendTypesDropDownList.Items.Clear(); 115 foreach (CommendedItemType type in types) 116 { 117 bool exist = false; 118 foreach (CommendedItem ci in commendedItems.Records) 119 { 120 if (type.TypeID == ci.TypeID) 121 { 122 exist = true; 123 break; 124 } 125 } 126 127 if (!exist) 128 commendTypesDropDownList.Items.Add(new ListItem(type.TypeName, type.TypeID.ToString())); 129 } 130 131 if (commendTypesDropDownList.Items.Count == 0) 132 { 133 commendItemBlock.Visible = false; 134 statusMessage.Visible = true; 135 } 136 //if (sortOrder != null) 137 //{ 138 // sortOrder.Text = Convert.ToString(0); 139 //} 140 } 141 142 143 void CommendButton_Click(object sender, EventArgs e) 144 { 145 CommendedItem ci = new CommendedItem(); 146 147 switch (commendType) 148 { 149 case CommendType.Blog: 150 Weblog currentBlog = Weblogs.GetWeblog(itemID); 151 if (currentBlog != null) 152 { 153 User blogOwner = Users.FindUserByUsername(currentBlog.ApplicationKey); 154 ci.ApplicationKey = currentBlog.ApplicationKey; 155 ci.Author = blogOwner.DisplayName; 156 ci.AuthorUserID = blogOwner.UserID; 157 ci.Commender = sbContext.User.DisplayName; 158 ci.CommenderUserID = sbContext.User.UserID; 159 ci.CommendType = commendType; 160 ci.ItemID = itemID; 161 ci.ItemName = currentBlog.SectionName; 162 ci.TypeID = int.Parse(commendTypesDropDownList.SelectedValue); 163 if (sortOrder.Text != "") 164 { 165 ci.SortOrder = int.Parse(sortOrder.Text); 166 } 167 } 168 else 169 { 170 statusMessage.Visible = true; 171 statusMessage.Text = "该博客不存在"; 172 statusMessage.MessageType = StatusMessageType.Error; 173 commendButton.Enabled = false; 174 return; 175 } 176 break; 177 case CommendType.BlogPost: 178 BlogThread currentBlogThread = BlogPosts.GetThread(itemID, false); 179 if (currentBlogThread != null) 180 { 181 ci.ApplicationKey = currentBlogThread.Weblog.ApplicationKey; 182 ci.Author = currentBlogThread.Author; 183 ci.AuthorUserID = currentBlogThread.UserID; 184 ci.Commender = sbContext.User.DisplayName; 185 ci.CommenderUserID = sbContext.User.UserID; 186 ci.CommendType = commendType; 187 ci.ItemID = itemID; 188 ci.ItemName = currentBlogThread.Subject; 189 ci.TypeID = int.Parse(commendTypesDropDownList.SelectedValue); 190 if (sortOrder.Text != "") 191 { 192 ci.SortOrder = int.Parse(sortOrder.Text); 193 } 194 } 195 else 196 { 197 statusMessage.Visible = true; 198 statusMessage.Text = "该博客不存在"; 199 statusMessage.MessageType = StatusMessageType.Error; 200 commendButton.Enabled = false; 201 } 202 break; 203 case CommendType.Bookmark: 204 Bookmark currentBookmark = SpaceBuilder.Bookmarks.Components.Bookmarks.GetBookmark(itemID, false); 205 if (currentBookmark != null) 206 { 207 ci.ApplicationKey = string.Empty; 208 ci.Author = currentBookmark.Author; 209 ci.AuthorUserID = currentBookmark.UserID; 210 ci.Commender = sbContext.User.DisplayName; 211 ci.CommenderUserID = sbContext.User.UserID; 212 ci.CommendType = commendType; 213 ci.ItemID = itemID; 214 ci.ItemName = currentBookmark.Title; 215 ci.TypeID = int.Parse(commendTypesDropDownList.SelectedValue); 216 ci.SortOrder = int.Parse(sortOrder.Text); 217 if (sortOrder.Text != "") 218 { 219 ci.SortOrder = int.Parse(sortOrder.Text); 220 } 221 } 222 else 223 { 224 statusMessage.Visible = true; 225 statusMessage.Text = "该网摘不存在"; 226 statusMessage.MessageType = StatusMessageType.Error; 227 commendButton.Enabled = false; 228 } 229 break; 230 case CommendType.Club: 231 Club currentClub = SpaceBuilder.Clubs.Components.Clubs.GetClub(itemID); 232 if (currentClub != null) 233 { 234 ci.ApplicationKey = string.Empty; 235 ci.Author = string.Empty; 236 ci.AuthorUserID = 0; 237 ci.Commender = sbContext.User.DisplayName; 238 ci.CommenderUserID = sbContext.User.UserID; 239 ci.CommendType = commendType; 240 ci.ItemID = itemID; 241 ci.ItemName = currentClub.ClubName; 242 ci.TypeID = int.Parse(commendTypesDropDownList.SelectedValue); 243 if (sortOrder.Text != "") 244 { 245 ci.SortOrder = int.Parse(sortOrder.Text); 246 } 247 } 248 else 249 { 250 statusMessage.Visible = true; 251 statusMessage.Text = "该圈子不存在"; 252 statusMessage.MessageType = StatusMessageType.Error; 253 commendButton.Enabled = false; 254 } 255 256 break; 257 case CommendType.Event: 258 EventThread currentEvent = SpaceBuilder.Events.Components.Events.GetEvent(itemID); 259 if (currentEvent != null) 260 { 261 ci.ApplicationKey = string.Empty; 262 ci.Author = currentEvent.Sponsor; 263 ci.AuthorUserID = currentEvent.UserID; 264 ci.Commender = sbContext.User.DisplayName; 265 ci.CommenderUserID = sbContext.User.UserID; 266 ci.CommendType = commendType; 267 ci.ItemID = itemID; 268 ci.ItemName = currentEvent.EventName; 269 ci.TypeID = int.Parse(commendTypesDropDownList.SelectedValue); 270 if (sortOrder.Text != "") 271 { 272 ci.SortOrder = int.Parse(sortOrder.Text); 273 } 274 } 275 else 276 { 277 statusMessage.Visible = true; 278 statusMessage.Text = "该活动不存在"; 279 statusMessage.MessageType = StatusMessageType.Error; 280 commendButton.Enabled = false; 281 } 282 283 break; 284 case CommendType.FilePost: 285 FileThread currentFileThread = FilePosts.GetThread(itemID); 286 if (currentFileThread != null) 287 { 288 ci.ApplicationKey =currentFileThread.FileSection.ApplicationKey; 289 ci.Author = currentFileThread.Author; 290 ci.AuthorUserID = currentFileThread.UserID; 291 ci.Commender = sbContext.User.DisplayName; 292 ci.CommenderUserID = sbContext.User.UserID; 293 ci.CommendType = commendType; 294 ci.ItemID = itemID; 295 ci.ItemName = currentFileThread.Subject; 296 ci.TypeID = int.Parse(commendTypesDropDownList.SelectedValue); 297 if (sortOrder.Text != "") 298 { 299 ci.SortOrder = int.Parse(sortOrder.Text); 300 } 301 } 302 else 303 { 304 statusMessage.Visible = true; 305 statusMessage.Text = "该活动不存在"; 306 statusMessage.MessageType = StatusMessageType.Error; 307 commendButton.Enabled = false; 308 } 309 310 break; 311 case CommendType.Gallery: 312 Gallery currentGallery = SpaceBuilder.Galleries.Components.Galleries.GetGallery(itemID); 313 if (currentGallery != null) 314 { 315 User galleryOwner = Users.FindUserByUsername(currentGallery.ApplicationKey); 316 ci.ApplicationKey = currentGallery.ApplicationKey; 317 ci.Author = galleryOwner.DisplayName; 318 ci.AuthorUserID = galleryOwner.UserID; 319 ci.Commender = sbContext.User.DisplayName; 320 ci.CommenderUserID = sbContext.User.UserID; 321 ci.CommendType = commendType; 322 ci.ItemID = itemID; 323 ci.ItemName = currentGallery.SectionName; 324 ci.TypeID = int.Parse(commendTypesDropDownList.SelectedValue); 325 if (sortOrder.Text != "") 326 { 327 ci.SortOrder = int.Parse(sortOrder.Text); 328 } 329 } 330 else 331 { 332 statusMessage.Visible = true; 333 statusMessage.Text = "该相册不存在"; 334