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

📄 login.aspx.cs

📁 PURPOSE OF THE PROJECT: This Application would facilitate the huge process of managing the Ad detai
💻 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.Data.SqlClient;
using System.Configuration;


namespace MegaMartAudio
{
	/// <summary>
	/// Summary description for WebForm1.
	/// </summary>
	public class WebForm1 : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
		protected System.Web.UI.WebControls.TextBox txtUserID;
		protected System.Web.UI.WebControls.Label lblHeading;
		protected System.Web.UI.WebControls.Panel pnlHeading;
		protected System.Web.UI.WebControls.Label lblError;
		protected System.Web.UI.WebControls.Button cmdSubmit;
		protected System.Web.UI.WebControls.Label lblPWD;
		protected System.Web.UI.WebControls.Label lblUID;
		protected System.Web.UI.WebControls.TextBox txtPassword;
		protected System.Web.UI.WebControls.Button cmdReset;
		protected System.Web.UI.WebControls.Label lblLogin;
		protected System.Web.UI.WebControls.Label lblAbout;
		protected System.Web.UI.WebControls.TextBox TextBox1;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
		   lblError.Visible=false;	
		}

		#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.cmdSubmit.Click += new System.EventHandler(this.cmdSubmit_Click);
			this.cmdReset.Click += new System.EventHandler(this.cmdReset_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void cmdSubmit_Click(object sender, System.EventArgs e)
		{
             //string strCon=ConfigurationSettings.AppSettings["DB"];
			string strCon="Server=.;database=MegaMartAudio;uid=sa;pwd=sa";
			SqlConnection con = new SqlConnection(strCon);
			
			string strCmd="SELECT * FROM MMA_USERS_TB";
			SqlCommand com = new SqlCommand(strCmd,con);

			DataSet ds=new DataSet();
			SqlDataAdapter da=new SqlDataAdapter(com);
			
 			da.Fill(ds,"MMA_USERS_TB");
			int intlogged = 0;

			for(int i=0;i<ds.Tables[0].Rows.Count;i++)
			{
				//If the given user id is present in the database 
				if(ds.Tables[0].Rows[i][0].ToString().Equals((txtUserID.Text)))
				{
					//If the password given corresponds to the userid in the database
					if(ds.Tables[0].Rows[i][2].ToString().Equals(txtPassword.Text))
					{
						//Storing the user id,name and role as session variables
						Session["sintID"]=txtUserID.Text;
						Session["sstrName"]=ds.Tables[0].Rows[i][1].ToString();
						Session["sstrRole"]=ds.Tables[0].Rows[i][3].ToString();

						//If the user's role is 'manager'
						if(ds.Tables[0].Rows[i][3].ToString().Equals("m"))
					
						{								
							//Redirecting the user to the Advertisements web page
							Response.Redirect("Advertisements.aspx");
							intlogged = 1;
						}
						//If the user's role is 'staff'
						else if(ds.Tables[0].Rows[i][3].ToString().Equals("s"))
						{
							 //Redirecting the user to the StaffHome web page
							Response.Redirect("StaffHome.aspx");
							intlogged = 1;
						
						}
					}
					else
					{
						//If the password given does not corresponds to the userid in the database
						//Display a "Invalid Password" Message.
						lblError.Visible = true;
						lblError.Text="Invalid Password";
						txtPassword.Text="";
						intlogged=1;
					}


				}
			}
				
		//If the given user id could not be found in the database
		if(intlogged == 0)
		{			//Display a "Invalid User" Message.
					lblError.Visible = true;
					lblError.Text="Invalid User";
					txtUserID.Text="";
					txtPassword.Text="";	
				}
			

		}
		
		private void cmdReset_Click(object sender, System.EventArgs e)
		{
			//Reset the password and user id text fields
			txtUserID.Text="";
			txtPassword.Text="";
		}

		

		
	}
}

⌨️ 快捷键说明

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