?? default.aspx.cs
字號(hào):
?using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.Data.SqlClient;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
private static string sValidator = "";
private StringBuilder LetterList = new StringBuilder();
private readonly string sValidatorImageUrl = "ValidateImage.aspx?Validator=";
protected void Page_Load(object sender,EventArgs e)
{
///添加頁面初始化代碼
if(!Page.IsPostBack)
{
///創(chuàng)建驗(yàn)證字符串
sValidator = CreateValidateString(6);
ValidateImage.ImageUrl = sValidatorImageUrl + sValidator;
}
}
protected void LoginBtn_Click(object sender,EventArgs e)
{
///如果頁面輸入合法
if(Page.IsValid == true)
{
if(Validator.Text != sValidator)
{
Message.Text = "驗(yàn)證碼輸入錯(cuò)誤,請(qǐng)重新輸入驗(yàn)證碼!!!";
sValidator = CreateValidateString(6);
ValidateImage.ImageUrl = sValidatorImageUrl + sValidator;
return;
}
String userId = "";
///定義類并獲取用戶的登陸信息
IUser user = new User();
SqlDataReader recu = user.GetUserLogin(UserName.Text.Trim(),
Password.Text.Trim());
///判斷用戶是否合法
if(recu.Read())
{
userId = recu["UserID"].ToString();
}
recu.Close();
///驗(yàn)證用戶合法性,并跳轉(zhuǎn)到系統(tǒng)平臺(tái)
if((userId != null) && (userId != ""))
{
Session["UserID"] = userId;
//跳轉(zhuǎn)到登錄后的第一個(gè)頁面
Response.Redirect("~/VoteDesktop.aspx");
}
else
{
///創(chuàng)建驗(yàn)證字符串
sValidator = CreateValidateString(6);
ValidateImage.ImageUrl = sValidatorImageUrl + sValidator;
///顯示錯(cuò)誤信息
Message.Text = "你輸入的用戶名稱或者密碼有誤,請(qǐng)重新輸入!";
}
}
}
protected void CancelBtn_Click(object sender,EventArgs e)
{
///清空用戶名稱和密碼輸入框
UserName.Text = Password.Text = "";
///創(chuàng)建驗(yàn)證字符串
sValidator = CreateValidateString(6);
ValidateImage.ImageUrl = sValidatorImageUrl + sValidator;
}
/// <summary>
/// 創(chuàng)建一個(gè)隨機(jī)數(shù)
/// </summary>
/// <param name="min"></param>
/// <param name="max"></param>
/// <returns></returns>
private int GetRandomint(int min,int max)
{
Random random = new Random();
return (random.Next(min,max));
}
/// <summary>
/// 創(chuàng)建驗(yàn)證字符串
/// </summary>
/// <param name="nLen"></param>
/// <returns></returns>
private string CreateValidateString(int nLen)
{
///初始化
InitLetterList();
///創(chuàng)建一個(gè)StringBuilder對(duì)象
StringBuilder sb = new StringBuilder(nLen);
for(int i = 0; i < nLen; i++)
{
int index = GetRandomint(0,LetterList.Length - 1);
sb.Append(LetterList[index].ToString());
LetterList.Remove(index,1);
}
return (sb.ToString());
}
/// <summary>
/// 創(chuàng)建所有字符,為創(chuàng)建驗(yàn)證字符串做準(zhǔn)備
/// </summary>
private void InitLetterList()
{
for(int i = 0; i < 10; i++)
{
LetterList.Append(i.ToString());
}
for(int i = 0; i < 26; i++)
{
LetterList.Append(((char)((int)'a' + i)).ToString());
}
for(int i = 0; i < 26; i++)
{
LetterList.Append(((char)((int)'A' + i)).ToString());
}
}
protected void GuestBtn_Click(object sender,EventArgs e)
{
Response.Redirect("~/VoteDesktop.aspx");
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -