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;

public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
		//if (DateTime.Now.ToShortDateString() == "2009-6-1")
		//{
		//    Session["username"] = "";
		//    Response.Redirect("TestDateTimeOut.html");
		//}
    }

	protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
	{
		string username = Request["username"];
		string userpwd = Request["userpwd"];
		if (Tools.validate(username))
		{
			Response.Write("<script>alert('用户名中不能含有非法字符');history.back()</script>");
			return;
		}
		if (Tools.validate(userpwd))
		{
			Response.Write("<script>alert('密码中不能含有非法字符');history.back()</script>");
			return;
		}
		string sqlCmd = "select count(*) as ff from System_Users where username='" + username + "' and userpwd='" + userpwd + "'";
		using (SqlConnection sqlconn = new SqlConnection(Tools.strConn))
		{
			sqlconn.Open();
			SqlCommand cmd = new SqlCommand(sqlCmd, sqlconn);
			int count = Convert.ToInt32(cmd.ExecuteScalar());
			if (count > 0)
			{
				Session["username"] = username;
				Response.Redirect("Index.aspx");
			}
			else
			{
				Response.Write("<script>alert('用户名或者密码错误，请重新输入！');history.back()</script>");
				return;
			}
		}
	}
}
