📄 admin.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 bbs
{
/// <summary>
/// admin 的摘要说明。
/// </summary>
public class houtai : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox_PWD;
protected System.Web.UI.WebControls.Button Button_login;
protected System.Web.UI.WebControls.TextBox TextBox_UserName;
protected System.Web.UI.WebControls.Button Button_Clear;
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.Button_login.Click += new System.EventHandler(this.Button_login_Click);
this.Button_Clear.Click += new System.EventHandler(this.Button_Clear_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button_login_Click(object sender, System.EventArgs e)
{
string ConnectionString=System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
string sqlstr="select * from users where username='"+this.TextBox_UserName.Text+"'and pwd='"+this.TextBox_PWD.Text+"' and iPowerLevels=2";
SqlConnection conn = new SqlConnection(ConnectionString);
SqlCommand cmd=new SqlCommand(sqlstr,conn);
try
{
if(conn.State!=ConnectionState.Open)
{
conn.Open();
}
int count=Convert.ToInt32(cmd.ExecuteScalar());
if(count>0)
{
Session["UserName"]=this.TextBox_UserName.Text;
Response.Redirect("Manage.aspx");
}
else
{
Response.Write("用户名不存在或密码不正确!");
}
}
catch(Exception ex)
{
Response.Write(ex.Message);
conn.Close();
}
finally
{
conn.Close();
conn.Dispose();
conn=null;
}
}
private void Button_Clear_Click(object sender, System.EventArgs e)
{
Response.Redirect("index.aspx");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -