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