landing.aspx.cs

来自「asp.net+sql2000超市管理系统」· CS 代码 · 共 80 行

CS
80
字号
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.Configuration;
using System.Data.SqlClient;

namespace Supermart
{
	/// <summary>
	/// landing 的摘要说明。
	/// </summary>
	public class landing : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox txt_username;
		protected System.Web.UI.WebControls.TextBox txt_pwd;
		protected System.Web.UI.WebControls.Button btn_landing;
		protected System.Web.UI.WebControls.Button btn_giveup;
		private string strConn=System.Configuration.ConfigurationSettings.AppSettings["SQLCONNECTION"];
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
		}

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

		}
		#endregion

		private void btn_landing_Click(object sender, System.EventArgs e)
		{
			SqlConnection con=new SqlConnection(strConn);
			con.Open();
			SqlCommand cmd=new SqlCommand("select * from personnel where perName='"+this.txt_username.Text+"' and perPwd='"+this.txt_pwd.Text+"'",con);
			SqlDataReader sdr=cmd.ExecuteReader();
			if(sdr.Read())
			{
				Session["userName"]=sdr["perName"].ToString();
				Session["relName"]=sdr["relName"].ToString();
				Session["department"]=sdr["department"].ToString();
				Response.Write("<script>alert(\"欢迎你,"+Session["department"].ToString()+""+this.txt_username.Text+"光临!!\");window.location.href='main.aspx';</script>");
			}
			else
			{
				Response.Write("<script>alert(\"用户名或密码错误,请重新输入!\");window.location.href='landing.aspx';</script>");
			}
		}

		private void btn_giveup_Click(object sender, System.EventArgs e)
		{
		
		}
	}
}

⌨️ 快捷键说明

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