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.OleDb;
public partial class admini_login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (Session["CheckImg"] == null)
            Response.Redirect("login.aspx");
        if (Session["CheckImg"].ToString().ToLower() == this.cImg.Value.Trim().ToLower())
        {
            string name = this.adminName.Value.Trim();
            string pwd = this.adminPwd.Value.Trim();
            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(pwd))
                WebHelper.SendJSMsg(this, "用户名或密码不能为空！");
            else 
            {
                pwd = DESEncrypt.Encrypt(pwd);
                if (adLogin(name, pwd))
                    Response.Redirect("index.aspx");
                else
                    WebHelper.SendJSMsg(this, "用户名或密码错误！");
            }
        }
        else
            WebHelper.SendJSMsg(this,"验证码错误！");
    }


    bool adLogin(string name,string pwd)
    {
        //string sql =string.Format("SELECT COUNT(*) FROM T_ADMIN WHERE ANAME='{0}' AND APWD='{1}'",name,pwd);
        string sql = string.Format("SELECT COUNT(*) FROM T_ADMIN WHERE ANAME=@ANAME AND APWD=@APWD ", name, pwd);
        OleDbParameter[] dbParms = new OleDbParameter[] { new OleDbParameter("@ANAME", OleDbType.VarChar, 50), new OleDbParameter("@APWD", OleDbType.VarChar, 50) };
        dbParms[0].Value = name;
        dbParms[1].Value = pwd;
        object o = SqlHelper.GetSingle(sql,dbParms);
        if (int.Parse(o.ToString()) > 0)
        {
            Session["admin"] = name;
            return true;
        }//5$1$a$s$p$x
        return false;
    }
}
