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;

public partial class Admin_index : System.Web.UI.Page
{
   
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Check_Login(string username,string password,string code)
    {
        int ii = 0;
        //比对验证码
        if (Session["CheckCode"] != null)
        {
            if (code != Session["CheckCode"].ToString())
            {
                sql.Operation.Show_Msg("验证码不正确！");
            }
            else
            {
                ii = 1;
            }
        }
        else 
        {

            sql.Operation.Show_Msg("验证码不正确！");
        }
        if (ii == 1)
        {
            sql.SqlDB sqldb = new sql.SqlDB();
            string UserName = sqldb.CheckString(username);
            string Pwd = sqldb.CheckString(password);
            string  strSql = "select * from userInfo where username='" + username + "' and pwd='" + Pwd + "'";
            DataSet ds = sqldb.GetDS(strSql);
            DataTable tb = ds.Tables[0];
            int ok = 0;
            try
            {
	
                if (tb.Rows.Count <= 0)
                {
                    Response.Write("登录用户名密码不正确!");
                   // sql.Operation.Show_Msg("登录用户名密码不正确!");                    
                    Response.End();
                }
                else
                {
                    DataRow dr = tb.Rows[0];
                    ok = 1;
                    Session.Timeout = 100;
                    Session["Admin"] = dr["username"].ToString();                    
                }

                if (ok == 1)
                {
                    Session["CheckCode"] = null;
                    Response.Redirect("default.aspx");
                    Response.End();
                }
                else
                { 
                    Response.Write("登录用户名密码不正确!");
                   // sql.Operation.Show_Msg("登录用户名密码不正确!");
                }

            }
            catch (Exception ee)
            {
                Response.Write(ee.Message);
            }
            finally
            {
               
            }
        }

    }
    //该源码首发自www.51aspx.com(５1ａsｐｘ．ｃｏｍ)

    protected void imgbtn_ServerClick(object sender, ImageClickEventArgs e)
    {
        Check_Login(Request["username"], Request["password"], Request["code1"]);
    }
}
