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

📄 login.aspx.cs

📁 学生公寓管理系统使用说明: 1.服务器运行环境 SQL 2000 .NET FRAMEWORK 1.1 .NET FRAMEWORK 1.1 CHINESE (SIMPL
💻 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 System.Web.Security;
using System.Configuration;

namespace Manage
{
	/// <summary>
	/// WebForm1 的摘要说明。
	/// </summary>
	public class Login : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.TextBox TextBox2;
		protected System.Web.UI.WebControls.Button Login_OK;
		protected System.Web.UI.WebControls.Button Login_Cannel;
		protected System.Web.UI.WebControls.Label Label3;
		protected System.Web.UI.WebControls.DropDownList DropDownList1;
		protected System.Web.UI.WebControls.TextBox TextBox1;
		protected System.Data.SqlClient.SqlConnection conn;
		protected System.Data.SqlClient.SqlCommand cmd;
		protected System.Data.SqlClient.SqlDataReader reader;
		protected string myConn;
		protected string cmdText;
		protected string nameKind;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.HtmlControls.HtmlGenericControl FONT1;
		protected System.Web.UI.WebControls.HyperLink HyperLink1;
		protected System.Web.UI.WebControls.Button Button1;
		protected string pwKind;
		

	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面


				//Response.Write(this.conn.State);


		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.Button1.Click += new System.EventHandler(this.Button1_Click);
			this.Login_OK.Click += new System.EventHandler(this.Login_OK_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
		private bool Check_Login(string name,string pw,string cmdtext,string namekind,string pwkind)
		{

			this.myConn=ConfigurationSettings.AppSettings["mySql"];
			this.conn=new System.Data.SqlClient.SqlConnection(myConn);
			this.cmd=new System.Data.SqlClient.SqlCommand(cmdtext,conn);
			int k=0;
			try
			{
				conn.Open();
				this.reader=cmd.ExecuteReader();
				while(this.reader.Read())
				{
					if(name==reader[namekind].ToString()&&pw==reader[pwkind].ToString())
					k=1;
				}
				if(k==1)
					return true;
				else return false;
			}

			finally
				   {
					conn.Close();
				   }

			
			}

		private void Login_OK_Click(object sender, System.EventArgs e)
		{
			this.Session["user"]=this.TextBox1.Text;
			if(this.DropDownList1.SelectedValue=="学生")
			{
				this.Session["kind"]="学生";
				this.nameKind="Student_ID";
				this.pwKind="Student_Password";
				this.cmdText="select * from Student";
				if( Check_Login(this.TextBox1.Text,this.TextBox2.Text,cmdText,nameKind,pwKind))
					System.Web.Security.FormsAuthentication.RedirectFromLoginPage(TextBox1.Text,false);
				else 
				{
				
					this.Label3.Text="对不起,用户名或密码错误,请重新输入!!";
				}
			}
			else if(this.DropDownList1.SelectedValue=="管理员")
			{
				this.Session["kind"]="管理员";
				this.nameKind="Manager_UserName";
				this.pwKind="Manager_Password";
				this.cmdText="SELECT * FROM Manager";
				if(this.Check_Login(this.TextBox1.Text,this.TextBox2.Text,cmdText,nameKind,pwKind))
					System.Web.Security.FormsAuthentication.RedirectFromLoginPage(TextBox1.Text,false);
				else this.Label3.Text="对不起,用户名或密码错误,请重新输入!!";
			}
			else if(this.DropDownList1.SelectedValue=="系统管理员")
			{
				//Response.Redirect("ManagerAdd.aspx");
				if(this.TextBox1.Text=="admin"&&this.TextBox2.Text=="admin")
				{
						System.Web.Security.FormsAuthentication.RedirectFromLoginPage(TextBox1.Text,false);
						Response.Redirect("ManagerAdd.aspx");
				}	
				else this.Label3.Text="对不起,用户名或密码错误,请重新输入!!";
			}
		}



		private void Button1_Click(object sender, System.EventArgs e)
		{
			System.Web.Security.FormsAuthentication.RedirectFromLoginPage(TextBox1.Text,false);
			Response.Redirect("FindPassword.aspx");
		}


	}
}

⌨️ 快捷键说明

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