資源簡介
登錄頁面從低級到高級的設計,里面有四個文件。

代碼片段和文件信息
using?System;
using?System.Data;
using?System.Configuration;
using?System.Web;
using?System.Web.Security;
using?System.Web.UI;
using?System.Web.UI.WebControls;
using?System.Web.UI.WebControls.WebParts;
using?System.Web.UI.HtmlControls;
using?System.Web.Configuration;
using?System.Data.SqlClient;
public?partial?class?_Default?:?System.Web.UI.Page?
{
????protected?void?Page_Load(object?sender?EventArgs?e)
????{
????????//提示信息隱藏
????????lblerr.Visible?=?false;
????}
????protected?void?btn_clear_Click(object?sender?EventArgs?e)
????{
????????//清除文本框內容
????????tbxaccount.Text?=?““;
????????tbxpwd.Text?=?““;
????}
????protected?void?btn_login_Click(object?sender?EventArgs?e)
????{
????????//獲取用戶輸入
????????string?UserName?=?tbxaccount.Text.ToString();
????????string?Password?=?tbxpwd.Text.ToString();
????????//判斷用戶是否輸入信息
????????if?(UserName?==?““?|?Password?==?““)
????????{
????????????lblerr.Visible?=?true;
????????????lblerr.Text?=?“請輸入用戶名、密碼“;
????????}
????????else
????????{
????????????//從配置文件中讀取字符串
????????????string?settings?=?Convert.ToString(ConfigurationManager.ConnectionStrings[“MySqlConnection“]);
????????????//測試字符串是否正確
????????????//Response.Write(settings);
????????????//Response.End();
????????????//創建Sql連接
????????????SqlConnection?myconn?=?new?SqlConnection(settings);
????????????//打開連接
????????????myconn.Open();
????????????//創建SQL語句
????????????string?mysql?=?“select?*?from?Employee?Where?EmpName=“?+?“‘“?+?UserName?+?“‘“?+?“And?EmpPwd=“?+?“‘“?+?Password?+?“‘“;
????????????//測試SQL語句
????????????//Response.Write(mysql);
????????????//Response.End();
????????????//創建命令對象
????????????SqlCommand?mycmd?=?new?SqlCommand(mysql?myconn);
????????????//執行命令,結果傳遞給適配器
????????????SqlDataReader?mydr?=?mycmd.ExecuteReader();
????????????try
????????????{
????????????????if?(mydr.Read())
????????????????{
????????????????????//身份驗證成功顯示成功信息
????????????????????lblerr.Visible?=?true;
????????????????????lblerr.Text?=?“登錄成功“;
????????????????}
????????????????else
????????????????{
????????????????????//身份驗證失敗顯示失敗信息
????????????????????lblerr.Visible?=?true;
????????????????????lblerr.Text?=?“用戶名或密碼錯誤“;
????????????????}
????????????}
????????????finally
????????????{
????????????????//關閉連接
????????????????mydr.Close();
????????????????myconn.Close();
????????????}
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1298??2007-04-17?13:27??第3章\ex3_1\Web.config
?????文件???????4162??2007-04-17?13:27??第3章\ex3_1\login.aspx
?????文件???????2675??2007-04-17?13:27??第3章\ex3_1\login.aspx.cs
?????目錄??????????0??2007-10-14?22:21??第3章\ex3_1\App_Data
?????目錄??????????0??2007-10-14?22:21??第3章\ex3_1
?????文件???????1968??2007-04-17?13:27??第3章\Ex3_4\Default.aspx
?????文件????????383??2007-04-17?13:27??第3章\Ex3_4\Default.aspx.cs
?????文件???????1366??2007-04-17?13:27??第3章\Ex3_4\Login.aspx
?????文件????????406??2007-04-17?13:27??第3章\Ex3_4\Login.aspx.cs
?????文件????????904??2007-04-17?13:27??第3章\Ex3_4\Web.config
?????文件????????133??2007-04-17?13:27??第3章\Ex3_4\MemberPages\web.config
?????目錄??????????0??2007-10-14?22:21??第3章\Ex3_4\MemberPages
?????目錄??????????0??2007-10-14?22:21??第3章\Ex3_4\App_Data
?????目錄??????????0??2007-10-14?22:21??第3章\Ex3_4
?????文件????????452??2007-04-17?13:27??第3章\Ex3_3\CheckCode.aspx
?????文件???????3228??2007-04-17?13:27??第3章\Ex3_3\CheckCode.aspx.cs
?????文件????????548??2007-04-17?13:27??第3章\Ex3_3\Default.aspx
?????文件???????1927??2007-04-17?13:27??第3章\Ex3_3\Default.aspx.cs
?????文件???????1125??2007-04-17?13:27??第3章\Ex3_3\Web.Config
?????文件???????5523??2007-04-17?13:27??第3章\Ex3_3\login.aspx
?????文件???????3223??2007-04-17?13:27??第3章\Ex3_3\login.aspx.cs
?????目錄??????????0??2007-10-14?22:21??第3章\Ex3_3\App_Data
?????目錄??????????0??2007-10-14?22:21??第3章\Ex3_3
?????文件????????452??2007-04-17?13:27??第3章\Ex3_2\CheckCode.aspx
?????文件???????3228??2007-04-17?13:27??第3章\Ex3_2\CheckCode.aspx.cs
?????文件???????1122??2007-04-17?13:27??第3章\Ex3_2\Web.Config
?????文件???????5050??2007-04-17?13:27??第3章\Ex3_2\login.aspx
?????文件???????2803??2007-04-17?13:27??第3章\Ex3_2\login.aspx.cs
?????目錄??????????0??2007-10-14?22:21??第3章\Ex3_2\App_Data
?????目錄??????????0??2007-10-14?22:21??第3章\Ex3_2
............此處省略4個文件信息
評論
共有 條評論