default.aspx.cs

来自「一阵子」· CS 代码 · 共 135 行

CS
135
字号
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;

namespace PSP
{
	/// <summary>
	/// Summary description for _default.
	/// </summary>
	public class _default : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Literal Literal1;
		protected System.Web.UI.WebControls.Literal Literal2;
		protected System.Web.UI.WebControls.Literal Literal3;
		protected System.Web.UI.WebControls.Literal Literal4;
		protected System.Web.UI.WebControls.TextBox TextBox1;
		protected System.Web.UI.WebControls.TextBox TextBox2;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.Button Button2;
		protected System.Web.UI.WebControls.Label lblUser;
		protected System.Web.UI.WebControls.Label lblItem;
		protected System.Web.UI.WebControls.Label lblComment;
		protected System.Web.UI.WebControls.Label lblToday;
		protected System.Web.UI.WebControls.Panel pnlLogin;
		protected System.Web.UI.WebControls.Literal Literal5;
		protected System.Web.UI.WebControls.Label lblMsg;

		string _userID;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			_userID = PSP.User.GetUserID(Page);
			
			if(!Page.IsPostBack)
			{
				if(_userID != "-1")
					this.pnlLogin.Visible = false;

				DataTable dt = Framework.GetRecentUsers();				
				this.Literal5.Text = CMS.GenerateUserList(dt);				

				dt = Framework.GetRecentItems();				
				this.Literal1.Text = CMS.GenerateItemList(dt);

				dt = Framework.GetTopItems();
				this.Literal2.Text = CMS.GenerateItemList(dt);

				//right part
				this.Literal3.Text = CMS.GenerateItemListHome(dt);

				dt = Framework.GetTopUsers();
				this.Literal4.Text = CMS.GenerateUserList(dt);

				//Right Bottom Part
				this.lblUser.Text = MISC.GetTotalUsers();
				this.lblItem.Text = MISC.GetTotalItems();;
				this.lblComment.Text = MISC.GetTotalComments();;
				this.lblToday.Text = MISC.GetTodayPosts();
				
			}
		}

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

		}
		#endregion

		private void Button2_Click(object sender, System.EventArgs e)
		{
			this.Response.Redirect("reg.aspx");
		}

		private void Button1_Click(object sender, System.EventArgs e)
		{
			string userID = Framework.Login(this.TextBox1.Text, this.TextBox2.Text);

			if(userID =="-1")
			{
				this.lblMsg.Text = "用户名或密码错误!";
				this.lblMsg.Visible = true;
			}
			else
			{
				//Remove Cookie
				HttpCookie aCookie; 
				int limit = Request.Cookies.Count - 1; 
				for (int i = 0; i <= limit; i++) 
				{ 
					aCookie = Request.Cookies[i]; 
					aCookie.Expires = DateTime.Now.AddDays(-1); 
					Response.Cookies.Add(aCookie);   			
				} 

				//Set Cookie
				HttpCookie cookie = new HttpCookie("PSP_UserID");
				cookie.Value = userID.ToString() ;
				cookie.Expires = DateTime.Now.AddDays(2000);
				Response.Cookies.Add(cookie);

				HttpCookie cookie2 = new HttpCookie("PSP_UserName");
				cookie2.Value = this.TextBox1.Text;
				cookie2.Expires = DateTime.Now.AddDays(2000);
				Response.Cookies.Add(cookie2);

				this.Response.Redirect("default.aspx");
			}
		}
	}
}

⌨️ 快捷键说明

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