⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 postview.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.Controls;
using CommunityServer.GuestBooks.Components;

namespace CommunityServer.GuestBooks.Controls
{
	/// <summary>
	/// Summary description for PostView.
	/// </summary>
	public class PostView : BaseGuestBookControl
	{
		public PostView()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		#region Private Members
		private Repeater PostList;
		private Pager PostPager;
		#endregion

		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad (e);

			if(!Page.IsPostBack || !Page.EnableViewState)
			{
				DataBind();
			}
		}

		public override void DataBind()
		{
			base.DataBind ();

			int pageIndex = PostPager.PageIndex;

			if(!Page.IsPostBack)
			{
				pageIndex = Globals.SafeInt(Context.Request.QueryString["p"],pageIndex);
			}

			PostSet ps = GBPosts.GetPosts(CurrentBook.SectionID,pageIndex,PostPager.PageSize,true);
			PostPager.TotalRecords = ps.TotalRecords;
			PostPager.PageSize = 20;

			count = PostPager.PageIndex * 20;

		

			PostList.DataSource = ps.Posts;
			PostList.DataBind();

		}



		protected override void AttachChildControls()
		{
			PostList = FindControl("PostList") as Repeater;
			PostPager = FindControl("PostPager") as Pager;
			PostPager.CausesValidation = false;
			PostList.ItemDataBound +=new RepeaterItemEventHandler(PostList_ItemDataBound);
			PostList.ItemCommand +=new RepeaterCommandEventHandler(PostList_ItemCommand);
			IsAdmin = Permissions.ValidatePermissions(CurrentBook,Permission.Post,CurrentUser);
		}

		private bool IsAdmin = false;
		int count = 0;

		private void PostList_ItemDataBound(object sender, RepeaterItemEventArgs e)
		{
			if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.SelectedItem)
			{
				GBPost post = e.Item.DataItem as GBPost;
				if(post != null)
				{
					count ++;

					Literal subject = e.Item.FindControl("Subject") as Literal;
					Literal body = e.Item.FindControl("PostBody") as Literal;
					Literal date = e.Item.FindControl("PostDate") as Literal;
					HyperLink userLink = e.Item.FindControl("UserLink") as HyperLink;
					HyperLink permaLink = e.Item.FindControl("PermaLink") as HyperLink;
					LinkButton removeButton = e.Item.FindControl("removeButton") as LinkButton;

					subject.Text = string.Format("{0}. {1}",count, post.Subject);
					body.Text = post.FormattedBody;
					date.Text = post.PostDate.ToString(this.CurrentUser.Profile.DateFormat);
					
					userLink.Text = post.Username;
					userLink.NavigateUrl = GBUrls.Instance().Book(post.Username);
					userLink.ToolTip = ResourceManager.GetString("GuestBook_ViewMy");

					permaLink.Text = "#";
					permaLink.NavigateUrl = GBUrls.Instance().PostList(this.CurrentBook.ApplicationKey,post.PostID,PostPager.PageIndex);

					removeButton.Visible = IsAdmin;
					removeButton.CommandName = post.PostID.ToString();
					removeButton.Attributes.Add("onclick",string.Format("return confirm(\"{0}\");",string.Format(ResourceManager.GetString("GuestBook_ConfirmDelete"),post.Subject)));
					removeButton.CommandArgument = post.PostID.ToString();
					removeButton.CausesValidation = false;
					removeButton.Text = ResourceManager.GetString("GuestBook_Remove");



				}
				
			}
		}

		private void PostList_ItemCommand(object source, RepeaterCommandEventArgs e)
		{
			int postID = Int32.Parse(e.CommandArgument as string);
			GBPosts.DeletePost(CurrentBook.SectionID,postID);
			DataBind();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -