using System;
using System.Data;
using System.Data.SqlClient;
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;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        SqlConnection sqlcon = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
        sqlcon.Open();
        SqlCommand sqlcom = sqlcon.CreateCommand();
        sqlcom.CommandText = "select count(*) from tb_User where UserLoginName='" + txtUserName.Text + "' and UserPwd='" + txtPassword.Text + "'";
        int countAdmin = Convert.ToInt32(sqlcom.ExecuteScalar());//获取SQL语句的值 强制转换成数值类型
        if (countAdmin > 0)
        {
            Session["Name"] = txtUserName.Text;
            Page.Response.Redirect("Index.aspx");
        }
        else
        {
            Response.Write("<script lanuage=javascript>alert('用户名或密码有误！');location='javascript:history.go(-1)'</script>");
            return;
        }
        sqlcon.Close();
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        txtUserName.Text = "";
        txtPassword.Text = "";
    }
}
