?? default.aspx.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 Emplog
{
/// <summary>
/// WebForm1 的摘要說明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox id;
protected System.Web.UI.WebControls.TextBox password;
protected System.Web.UI.WebControls.Button Btn_login;
protected System.Web.UI.WebControls.Label Lbl_note;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此處放置用戶代碼以初始化頁面
}
#region Web 窗體設(shè)計器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調(diào)用是 ASP.NET Web 窗體設(shè)計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設(shè)計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內(nèi)容。
/// </summary>
private void InitializeComponent()
{
this.Btn_login.Click += new System.EventHandler(this.Btn_login_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Btn_login_Click(object sender, System.EventArgs e)
{
string strconn=ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection conn=new SqlConnection(strconn);
conn.Open();
string strsql="select * from Emp where Emp_login='"+id.Text+"' and password='"+password.Text+"'";
SqlCommand cm=new SqlCommand(strsql,conn);
SqlDataReader dr=cm.ExecuteReader();
if(dr.Read())
{
//保存用戶權(quán)限
Session["jb"]=dr["jb"];
Session["Emp_id"]=dr["Emp_id"];
if(Session["jb"].ToString()=="0")
{
//系統(tǒng)管理員登錄
Response.Redirect("main/Emp.aspx");
}
else if(Session["jb"].ToString()=="1")
{
//員工登錄
Response.Redirect("main/addlog.aspx");
}
else if(Session["jb"].ToString()=="2")
{
//領(lǐng)導(dǎo)登錄
Response.Redirect("main/logselect.aspx");
}
else
{
//錯誤登錄
Response.Redirect("main/Error.aspx");
}
}
else
{
Lbl_note.Text="登錄失敗,請檢查用戶名、密碼輸入!";
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -