📄 adminlogin.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;
namespace myResult
{
/// <summary>
/// adminlogin 的摘要说明。
/// </summary>
public class adminlogin : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtuser;
protected System.Web.UI.WebControls.Button btnlogin;
protected System.Web.UI.WebControls.Button btnclear;
protected System.Web.UI.WebControls.TextBox txtpwd;
SqlConnection conn;//定义数据连接
SqlCommand myCmd;//定义Commamd命令
protected System.Web.UI.WebControls.RegularExpressionValidator revuser;
protected System.Web.UI.WebControls.ValidationSummary vsShow;
SqlDataReader myDr;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
private void ExecuteSelect()
{
string str_user=this.txtuser.Text.Trim().Replace("'","''");
string str_pwd=this.txtpwd.Text.Trim().Replace("'","''");
conn=connDB.createConn();
string str_sel="select AdminType from AdminInfo where Users=@Ausers and Apassword=@Apassword";
conn.Open();//打开连接
myCmd=new SqlCommand(str_sel,conn);
myCmd.Parameters.Add(new SqlParameter("@Ausers",SqlDbType.VarChar,50));
myCmd.Parameters["@Ausers"].Value=str_user;
myCmd.Parameters.Add(new SqlParameter("@Apassword",SqlDbType.VarChar,50));
myCmd.Parameters["@Apassword"].Value=System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str_pwd,"MD5").ToString();//密码加密
myDr=myCmd.ExecuteReader();
if(myDr.Read())
{
Session["Auser"]=this.txtuser.Text.Trim();//管理员用户,Session进行传值
Session["admintype"]=myDr["AdminType"].ToString().Trim();//管理员类型
Response.Redirect("main.aspx");//跳转到adminmanage.aspx页面
}
else
{
string Dhtmlalert="";
Dhtmlalert += "<script language='javascript'>\n";
Dhtmlalert += "alert('用户名或密码错误!请重新输入');";
Dhtmlalert += "</script>";
Page.RegisterStartupScript("alert_news",Dhtmlalert);
}
myDr.Close();
conn.Close();//关闭连接
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnlogin.Click += new System.EventHandler(this.btnlogin_Click);
this.btnclear.Click += new System.EventHandler(this.btnclear_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnlogin_Click(object sender, System.EventArgs e)
{
if(this.IsValid)
{
this.ExecuteSelect();
}
}
private void btnclear_Click(object sender, System.EventArgs e)
{
this.txtuser.Text="";
this.txtpwd.Text="";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -