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

📄 forum.aspx.cs

📁 企业内部管理系统
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using infoWeb.WebModules.Accounts.Business;

namespace infoWeb.WebModules.Forums.Web
{
	/// <summary>
	/// Summary description for Forum.
	/// </summary>
	public class Forum : infoWeb.ThePhile.Web.PhilePage
	{
		protected System.Web.UI.WebControls.DataGrid TopicsGrid;
		protected System.Web.UI.WebControls.Label PageNumber;
		protected System.Web.UI.WebControls.Label TotalPages;
		protected System.Web.UI.WebControls.LinkButton FirstPage;
		protected System.Web.UI.WebControls.LinkButton PreviousPage;
		protected System.Web.UI.WebControls.LinkButton NextPage;
		protected System.Web.UI.WebControls.LinkButton LastPage;
		protected System.Web.UI.WebControls.HyperLink NewTopic1;
		protected System.Web.UI.WebControls.HyperLink NewTopic2;
		protected System.Web.UI.WebControls.HyperLink LinkToCategories;
		protected System.Web.UI.WebControls.Label ForumName;
		protected Web.Controls.User.Header Header;

		private bool canModerateForums;

		protected void Page_Load(object sender, EventArgs e)
		{
			// check if the user has the permission to moderate the forums
			canModerateForums = (Context.User.Identity.IsAuthenticated &&
				((SitePrincipal)Context.User).HasPermission((int)ForumsPermissions.ModerateForums));		

			// get the ForumID from the QueryString
			string forumID = Request.Params["ForumID"];
			
			if (!Page.IsPostBack)
			{
				// set the hyperlinks to jump to the parent category
				NewTopic1.NavigateUrl += forumID;
				NewTopic2.NavigateUrl = NewTopic1.NavigateUrl;
				Header.ForumID = int.Parse(forumID);
				// bind the data to the grid
				TopicsGrid.Attributes["ForumID"] = forumID;
				BindGrid();

				// hides the first 2 columns for editing/deleting a record, if the
				// current user does not have the permission to do that
				TopicsGrid.Columns[0].Visible = canModerateForums;
				TopicsGrid.Columns[1].Visible = canModerateForums;
			}
		}

		public bool CanModerateForums
		{
			get { return canModerateForums; }
		}

		protected void BindGrid() 
		{
			// get the ForumID value from the Grid's attributes.
			// if null, redirect to the Default.aspx page
			if (TopicsGrid.Attributes["ForumID"] == null)
				Response.Redirect("Default.aspx", true);

			// get the current forum's ID
			int forumID = int.Parse(TopicsGrid.Attributes["ForumID"]);
			// get the number of topics per page
			int pageSize = Configuration.ModuleConfig.GetSettings().TopicsPerPage;
			
			// get the current forum page
			int pageNumber = (PageNumber.Text == "0" ? 1 : int.Parse(PageNumber.Text));

			// retrieve and bind the records to the grid
			Business.Forum forum = new Business.Forum(forumID);
			DataSet topics = forum.GetTopics(pageNumber);
			TopicsGrid.DataSource = topics.Tables[0].DefaultView;
			TopicsGrid.DataBind();

			// show the total number of pages
			int totalPages = (int)Math.Ceiling((double)forum.Topics/pageSize);
			if (totalPages == 0) totalPages = 1;
			TotalPages.Text = totalPages.ToString();
			// enable/disable the links to navigate through the pages
			FirstPage.Enabled = (pageNumber != 1);
			PreviousPage.Enabled = (pageNumber != 1);
			NextPage.Enabled = (pageNumber != totalPages);
			LastPage.Enabled = (pageNumber != totalPages);
		}

		public string GetAuthorText(object memberName, object eMail, object showEmail)
		{
			// return the member Name only or a link to its e-mail address, according to the ShowEmail value
			if (!Convert.ToBoolean(showEmail))
				return memberName.ToString();
			else
				return string.Format("<a href=\"mailto:{0}\">{1}</a>", eMail.ToString(), memberName.ToString());
		}

		protected void TopicsGrid_Delete(object sender, DataGridCommandEventArgs e)
		{		
			// if the user cannot moderate forums redirect to the login page
			if (!canModerateForums)
			{
				Response.Redirect("/ThePhile/Modules/Users/Login.aspx?ShowError=true", true);
			}

			// delete this topic
			Business.Topic topic = new Business.Topic((int)TopicsGrid.DataKeys[e.Item.ItemIndex]);
			topic.Delete();
			BindGrid();
		}

		protected void TopicsGrid_PageChanged(object sender, CommandEventArgs e)
		{	
			if (PageNumber.Text.Trim().Length == 0) return;

			switch (e.CommandName)
			{
				case "FirstPage":
					PageNumber.Text = "1";
					break;
				case "PreviousPage":
					PageNumber.Text = (int.Parse(PageNumber.Text) -1).ToString();
					break;
				case "NextPage":
					PageNumber.Text = (int.Parse(PageNumber.Text) +1).ToString();
					break;
				case "LastPage":
					PageNumber.Text = TotalPages.Text;
					break;
			}
			
			// show the new page
			BindGrid();
		}

	
		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			base.OnInit(e);
			InitializeComponent();
			
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
	}
}

⌨️ 快捷键说明

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