温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:库存管理系统V1.0源码
当前文件:
StoreManage/Login.aspx.cs,打开代码结构图
StoreManage/Login.aspx.cs,打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Collections; 5
using System.Web; 6
using System.Web.Security; 7
using System.Web.UI; 8
using System.Web.UI.WebControls; 9
using System.Web.UI.WebControls.WebParts; 10
using System.Web.UI.HtmlControls; 11
using System.Data.SqlClient; 12
13
public partial class Login : System.Web.UI.Page 14
{ 15
private readonly string ConnectionString = ConfigurationManager.AppSettings["ConnectionString"].ToString(); 16
protected void Page_Load(object sender, EventArgs e) 17
{ 18
if (!IsPostBack) 19
{ 20
Session["Admin"] = this.TextBox1.Text.Trim(); 21
} 22
23
} 24
protected void Button1_Click(object sender, EventArgs e) 25
{ 26
//创建连接字符串 27
string sqlstr; 28
sqlstr = "select Pwd from tb_User where UserName=@adminname"; 29
SqlConnection scon=new SqlConnection(ConnectionString); 30
SqlCommand scm= new SqlCommand(sqlstr,scon); 31
scm.Parameters.Add("@adminname",SqlDbType.VarChar,20); 32
scm.Parameters["@adminname"].Value=this.TextBox1.Text.Trim(); 33
scon.Open(); 34
SqlDataReader reader=scm.ExecuteReader(); 35
if (reader.Read()) 36
{ 37
38
string strPwd=reader[0].ToString(); 39
40
reader.Close(); 41
if(strPwd!=TextBox2.Text.Trim()) 42
{ 43
this.LabelMsg.Text="密码错误!"; 44
} 45
else 46
{ 47
Response.Redirect("ManageList.aspx"); 48
} 49
50
} 51
else 52
{ 53
this.LabelMsg.Text="对不起,您没有权限!"; 54
scon.Close(); 55
} 56
57
} 58
59
protected void Button2_Click(object sender, EventArgs e) 60
{ 61
this.TextBox1.Text = ""; 62
this.TextBox2.Text = ""; 63
} 64
}





}
}