using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class Login : System.Web.UI.Page
{
static string strconn = "Data Source=localhost;database=BOOKS;integrated security=SSPI";
SqlConnection conn = new SqlConnection(strconn);
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string sqlVistor = "SELECT COUNT(*) FROM ip";
OpenConnection();
SqlCommand cmdVistor = conn.CreateCommand();
cmdVistor.CommandText = sqlVistor;
SqlDataReader readerForVisitor = cmdVistor.ExecuteReader();
readerForVisitor.Read();
//显示访问数量
if (readerForVisitor.HasRows)
{
string visitor="";
string numberVisited= readerForVisitor[0].ToString();
for (int i = 0; i <numberVisited.Length; i++)
{
visitor += numberVisited.Substring(i, 1);
TotoalVisitor.InnerHtml = "您是第" + returnImage(visitor)+"位访客";
}
}
CloseConnection();
readerForVisitor.Close();
OpenConnection();
TimeSpan span = new TimeSpan();
sqlVistor = "SELECT* FROM ip WHERE ip='" + Request.ServerVariables["REMOTE_ADDR"].ToString() + "' ORDER BY id DESC"; ;
cmdVistor.CommandText = sqlVistor;
readerForVisitor = cmdVistor.ExecuteReader();
readerForVisitor.Read();
if (readerForVisitor.HasRows)
{
readerForVisitor.Read();
DateTime now;
now = DateTime.Now;
//一分钟内再次访问,标记为灌水
DateTime past = DateTime.Parse(readerForVisitor["time"].ToString());
span = now.Subtract(past);
if (span.TotalSeconds <= 60)
{
message.InnerHtml = "欢迎再次光临,禁止灌水...";
return;
}
}
CloseConnection();
//增加访问量
OpenConnection();
string insertSQL = "INSERT INTO ip(ip,time) values('" +
Request.ServerVariables["REMOTE_ADDR"].ToString() + "','" + DateTime.Now.ToString() + "')";
cmdVistor.CommandText = insertSQL;
try
{
cmdVistor.ExecuteNonQuery();
}
catch
{
message.InnerHtml = "服务器错误!";
}
CloseConnection();
}
}
//登陆对话框
protected void btnLogin_Click(object sender, EventArgs e)
{
CloseConnection();
string SQL = "SELECT * FROM LogInfor where username='" + TextBoxUserName.Text+"'";
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = SQL;
OpenConnection();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
reader.Read();//读取第一条记录
if (reader["password"].ToString() == TextBoxPassword.Text)
{
Label.Text = "登陆成功,请输入验证码";
//输入验证码后进入系统
//注意,要想访问图文验证控件,必须在HTML设计器加如下代码
//<asp:Image ID="imageValidate" runat="server" ImageUrl="~/Picture.aspx" />
if (check.Text.ToString() == Session["check"].ToString())
{
Response.Redirect("Default.aspx");
}
else
{
Label.Text = "验证码不正确,请重新输入";
}
}
else
{
Label.Text = "密码不正确,请重新输入!";
}
}
else
{
Label.Text = "用户名不正确,请重新输入!";
}
}
void CloseConnection()
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
}
void OpenConnection()
{
if (conn == null)
conn = new SqlConnection();
if (conn.State == ConnectionState.Closed)
conn.Open();
}
protected void Button1_Click(object sender, EventArgs e)
{
if (check.Text.ToString() == Session["check"].ToString())
{
Response.Redirect("Default.aspx");
}
else
{
Label.Text = "验证码不正确,请重新输入";
}
}
protected void BtnManager_Click(object sender, EventArgs e)
{
CloseConnection();
string SQL = "SELECT * FROM LogInfor where username='" + TextBoxUserName.Text + "'";
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = SQL;
OpenConnection();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
reader.Read();//读取第一条记录
if (reader["password"].ToString() == TextBoxPassword.Text)
{
Label.Text = "登陆成功,请输入验证码";
//图文验证码
if (check.Text.ToString() == Session["check"].ToString())
{
Response.Redirect("Manager.aspx");
}
else
{
Label.Text = "验证码不正确,请重新输入";
}
}
else
{
Label.Text = "密码不正确,请重新输入!";
}
}
else
{
Label.Text = "用户名不正确,请重新输入!";
}
}
protected void btnChange_Click(object sender, EventArgs e)
{
if (check.Text.ToString() == Session["check"].ToString())
{
Response.Redirect("Manager.aspx");
}
else
{
Label.Text = "验证码不正确,请重新输入";
}
}
private string returnImage(string number)
{
string showTotal = "";
for (int i = 0; i < number.Length; i++)
{
switch (number[i].ToString())
{
case "1":
showTotal += "<img alt='lib' src='image/1.gif' style='width: 39px; height: 39px' />";
break;
case "2":
showTotal += "<img alt='lib' src='image/2.gif' style='width: 39px; height: 39px' />";
break;
case "3":
showTotal += "<img alt='lib' src='image/3.gif' style='width: 39px; height: 39px' />";
break;
case "4":
showTotal += "<img alt='lib' src='image/4.gif' style='width: 39px; height: 39px' />";
break;
case "5":
showTotal += "<img alt='lib' src='image/5.gif' style='width: 39px; height: 39px' />";
break;
case "6":
showTotal += "<img alt='lib' src='image/6.gif' style='width: 39px; height: 39px' />";
break;
case "7":
showTotal += "<img alt='lib' src='image/7.gif' style='width: 39px; height: 39px' />";
break;
case "8":
showTotal += "<img alt='lib' src='image/8.gif' style='width: 39px; height: 39px' />";
break;
case "9":
showTotal += "<img alt='lib' src='image/9.gif' style='width: 39px; height: 39px' />";
break;
default:
showTotal += "<img alt='lib' src='image/0.gif' style='width: 39px; height: 39px' />";
break;
}
}
return showTotal;
}
}
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class Login : System.Web.UI.Page
{
static string strconn = "Data Source=localhost;database=BOOKS;integrated security=SSPI";
SqlConnection conn = new SqlConnection(strconn);
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string sqlVistor = "SELECT COUNT(*) FROM ip";
OpenConnection();
SqlCommand cmdVistor = conn.CreateCommand();
cmdVistor.CommandText = sqlVistor;
SqlDataReader readerForVisitor = cmdVistor.ExecuteReader();
readerForVisitor.Read();
//显示访问数量
if (readerForVisitor.HasRows)
{
string visitor="";
string numberVisited= readerForVisitor[0].ToString();
for (int i = 0; i <numberVisited.Length; i++)
{
visitor += numberVisited.Substring(i, 1);
TotoalVisitor.InnerHtml = "您是第" + returnImage(visitor)+"位访客";
}
}
CloseConnection();
readerForVisitor.Close();
OpenConnection();
TimeSpan span = new TimeSpan();
sqlVistor = "SELECT* FROM ip WHERE ip='" + Request.ServerVariables["REMOTE_ADDR"].ToString() + "' ORDER BY id DESC"; ;
cmdVistor.CommandText = sqlVistor;
readerForVisitor = cmdVistor.ExecuteReader();
readerForVisitor.Read();
if (readerForVisitor.HasRows)
{
readerForVisitor.Read();
DateTime now;
now = DateTime.Now;
//一分钟内再次访问,标记为灌水
DateTime past = DateTime.Parse(readerForVisitor["time"].ToString());
span = now.Subtract(past);
if (span.TotalSeconds <= 60)
{
message.InnerHtml = "欢迎再次光临,禁止灌水...";
return;
}
}
CloseConnection();
//增加访问量
OpenConnection();
string insertSQL = "INSERT INTO ip(ip,time) values('" +
Request.ServerVariables["REMOTE_ADDR"].ToString() + "','" + DateTime.Now.ToString() + "')";
cmdVistor.CommandText = insertSQL;
try
{
cmdVistor.ExecuteNonQuery();
}
catch
{
message.InnerHtml = "服务器错误!";
}
CloseConnection();
}
}
//登陆对话框
protected void btnLogin_Click(object sender, EventArgs e)
{
CloseConnection();
string SQL = "SELECT * FROM LogInfor where username='" + TextBoxUserName.Text+"'";
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = SQL;
OpenConnection();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
reader.Read();//读取第一条记录
if (reader["password"].ToString() == TextBoxPassword.Text)
{
Label.Text = "登陆成功,请输入验证码";
//输入验证码后进入系统
//注意,要想访问图文验证控件,必须在HTML设计器加如下代码
//<asp:Image ID="imageValidate" runat="server" ImageUrl="~/Picture.aspx" />
if (check.Text.ToString() == Session["check"].ToString())
{
Response.Redirect("Default.aspx");
}
else
{
Label.Text = "验证码不正确,请重新输入";
}
}
else
{
Label.Text = "密码不正确,请重新输入!";
}
}
else
{
Label.Text = "用户名不正确,请重新输入!";
}
}
void CloseConnection()
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
}
void OpenConnection()
{
if (conn == null)
conn = new SqlConnection();
if (conn.State == ConnectionState.Closed)
conn.Open();
}
protected void Button1_Click(object sender, EventArgs e)
{
if (check.Text.ToString() == Session["check"].ToString())
{
Response.Redirect("Default.aspx");
}
else
{
Label.Text = "验证码不正确,请重新输入";
}
}
protected void BtnManager_Click(object sender, EventArgs e)
{
CloseConnection();
string SQL = "SELECT * FROM LogInfor where username='" + TextBoxUserName.Text + "'";
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = SQL;
OpenConnection();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
reader.Read();//读取第一条记录
if (reader["password"].ToString() == TextBoxPassword.Text)
{
Label.Text = "登陆成功,请输入验证码";
//图文验证码
if (check.Text.ToString() == Session["check"].ToString())
{
Response.Redirect("Manager.aspx");
}
else
{
Label.Text = "验证码不正确,请重新输入";
}
}
else
{
Label.Text = "密码不正确,请重新输入!";
}
}
else
{
Label.Text = "用户名不正确,请重新输入!";
}
}
protected void btnChange_Click(object sender, EventArgs e)
{
if (check.Text.ToString() == Session["check"].ToString())
{
Response.Redirect("Manager.aspx");
}
else
{
Label.Text = "验证码不正确,请重新输入";
}
}
private string returnImage(string number)
{
string showTotal = "";
for (int i = 0; i < number.Length; i++)
{
switch (number[i].ToString())
{
case "1":
showTotal += "<img alt='lib' src='image/1.gif' style='width: 39px; height: 39px' />";
break;
case "2":
showTotal += "<img alt='lib' src='image/2.gif' style='width: 39px; height: 39px' />";
break;
case "3":
showTotal += "<img alt='lib' src='image/3.gif' style='width: 39px; height: 39px' />";
break;
case "4":
showTotal += "<img alt='lib' src='image/4.gif' style='width: 39px; height: 39px' />";
break;
case "5":
showTotal += "<img alt='lib' src='image/5.gif' style='width: 39px; height: 39px' />";
break;
case "6":
showTotal += "<img alt='lib' src='image/6.gif' style='width: 39px; height: 39px' />";
break;
case "7":
showTotal += "<img alt='lib' src='image/7.gif' style='width: 39px; height: 39px' />";
break;
case "8":
showTotal += "<img alt='lib' src='image/8.gif' style='width: 39px; height: 39px' />";
break;
case "9":
showTotal += "<img alt='lib' src='image/9.gif' style='width: 39px; height: 39px' />";
break;
default:
showTotal += "<img alt='lib' src='image/0.gif' style='width: 39px; height: 39px' />";
break;
}
}
return showTotal;
}
}
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class Login : System.Web.UI.Page
{
static string strconn = "Data Source=localhost;database=BOOKS;integrated security=SSPI";
SqlConnection conn = new SqlConnection(strconn);
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string sqlVistor = "SELECT COUNT(*) FROM ip";
OpenConnection();
SqlCommand cmdVistor = conn.CreateCommand();
cmdVistor.CommandText = sqlVistor;
SqlDataReader readerForVisitor = cmdVistor.ExecuteReader();
readerForVisitor.Read();
//显示访问数量
if (readerForVisitor.HasRows)
{
string visitor="";
string numberVisited= readerForVisitor[0].ToString();
for (int i = 0; i <numberVisited.Length; i++)
{
visitor += numberVisited.Substring(i, 1);
TotoalVisitor.InnerHtml = "您是第" + returnImage(visitor)+"位访客";
}
}
CloseConnection();
readerForVisitor.Close();
OpenConnection();
TimeSpan span = new TimeSpan();
sqlVistor = "SELECT* FROM ip WHERE ip='" + Request.ServerVariables["REMOTE_ADDR"].ToString() + "' ORDER BY id DESC"; ;
cmdVistor.CommandText = sqlVistor;
readerForVisitor = cmdVistor.ExecuteReader();
readerForVisitor.Read();
if (readerForVisitor.HasRows)
{
readerForVisitor.Read();
DateTime now;
now = DateTime.Now;
//一分钟内再次访问,标记为灌水
DateTime past = DateTime.Parse(readerForVisitor["time"].ToString());
span = now.Subtract(past);
if (span.TotalSeconds <= 60)
{
message.InnerHtml = "欢迎再次光临,禁止灌水...";
return;
}
}
CloseConnection();
//增加访问量
OpenConnection();
string insertSQL = "INSERT INTO ip(ip,time) values('" +
Request.ServerVariables["REMOTE_ADDR"].ToString() + "','" + DateTime.Now.ToString() + "')";
cmdVistor.CommandText = insertSQL;
try
{
cmdVistor.ExecuteNonQuery();
}
catch
{
message.InnerHtml = "服务器错误!";
}
CloseConnection();
}
}
//登陆对话框
protected void btnLogin_Click(object sender, EventArgs e)
{
CloseConnection();
string SQL = "SELECT * FROM LogInfor where username='" + TextBoxUserName.Text+"'";
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = SQL;
OpenConnection();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
reader.Read();//读取第一条记录
if (reader["password"].ToString() == TextBoxPassword.Text)
{
Label.Text = "登陆成功,请输入验证码";
//输入验证码后进入系统
//注意,要想访问图文验证控件,必须在HTML设计器加如下代码
//<asp:Image ID="imageValidate" runat="server" ImageUrl="~/Picture.aspx" />
if (check.Text.ToString() == Session["check"].ToString())
{
Response.Redirect("Default.aspx");
}
else
{
Label.Text = "验证码不正确,请重新输入";
}
}
else
{
Label.Text = "密码不正确,请重新输入!";
}
}
else
{
Label.Text = "用户名不正确,请重新输入!";
}
}
void CloseConnection()
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
}
void OpenConnection()
{
if (conn == null)
conn = new SqlConnection();
if (conn.State == ConnectionState.Closed)
conn.Open();
}
protected void Button1_Click(object sender, EventArgs e)
{
if (check.Text.ToString() == Session["check"].ToString())
{
Response.Redirect("Default.aspx");
}
else
{
Label.Text = "验证码不正确,请重新输入";
}
}
protected void BtnManager_Click(object sender, EventArgs e)
{
CloseConnection();
string SQL = "SELECT * FROM LogInfor where username='" + TextBoxUserName.Text + "'";
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = SQL;
OpenConnection();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
reader.Read();//读取第一条记录
if (reader["password"].ToString() == TextBoxPassword.Text)
{
Label.Text = "登陆成功,请输入验证码";
//图文验证码
if (check.Text.ToString() == Session["check"].ToString())
{
Response.Redirect("Manager.aspx");
}
else
{
Label.Text = "验证码不正确,请重新输入";
}
}
else
{
Label.Text = "密码不正确,请重新输入!";
}
}
else
{
Label.Text = "用户名不正确,请重新输入!";
}
}
protected void btnChange_Click(object sender, EventArgs e)
{
if (check.Text.ToString() == Session["check"].ToString())
{
Response.Redirect("Manager.aspx");
}
else
{
Label.Text = "验证码不正确,请重新输入";
}
}
private string returnImage(string number)
{
string showTotal = "";
for (int i = 0; i < number.Length; i++)
{
switch (number[i].ToString())
{
case "1":
showTotal += "<img alt='lib' src='image/1.gif' style='width: 39px; height: 39px' />";
break;
case "2":
showTotal += "<img alt='lib' src='image/2.gif' style='width: 39px; height: 39px' />";
break;
case "3":
showTotal += "<img alt='lib' src='image/3.gif' style='width: 39px; height: 39px' />";
break;
case "4":
showTotal += "<img alt='lib' src='image/4.gif' style='width: 39px; height: 39px' />";
break;
case "5":
showTotal += "<img alt='lib' src='image/5.gif' style='width: 39px; height: 39px' />";
break;
case "6":
showTotal += "<img alt='lib' src='image/6.gif' style='width: 39px; height: 39px' />";
break;
case "7":
showTotal += "<img alt='lib' src='image/7.gif' style='width: 39px; height: 39px' />";
break;
case "8":
showTotal += "<img alt='lib' src='image/8.gif' style='width: 39px; height: 39px' />";
break;
case "9":
showTotal += "<img alt='lib' src='image/9.gif' style='width: 39px; height: 39px' />";
break;
default:
showTotal += "<img alt='lib' src='image/0.gif' style='width: 39px; height: 39px' />";
break;
}
}
return showTotal;
}
}
登陆部分: using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; public partial class Login : System.Web.UI.Page { static string strconn = "Data Source=localhost;database=BOOKS;integrated security=SSPI"; SqlConnection conn = new SqlConnection(strconn); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string sqlVistor = "SELECT COUNT(*) FROM ip"; OpenConnection(); SqlCommand cmdVistor = conn.CreateCommand(); cmdVistor.CommandText = sqlVistor; SqlDataReader readerForVisitor = cmdVistor.ExecuteReader(); readerForVisitor.Read(); //显示访问数量 if (readerForVisitor.HasRows) { string visitor=""; string numberVisited= readerForVisitor[0].ToString(); for (int i = 0; i