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 Logon : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Message.Visible = false;
            //Response.Write(Utility.StrManage.md5("modao"));

        }
    }
    protected void btn_login_Click(object sender, EventArgs e)
    {
        if (tbx_name.Text == "" || tbx_pwd.Text == "")
        {
            Message.Visible = true;
            Message.Text = "请输入用户名或密码！";
        }
        else
        {
            string strConnection = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Server.MapPath("DB_51aspx\\Data.mdb");
            //创建数据库连接对象
            OleDbConnection myconn = new OleDbConnection(strConnection);
 
            //打开数据库连接
            myconn.Open();
            //创建查询语句
            string strsql = "select * from Users Where Account=" + "'" + tbx_name.Text.Trim() + "'";
            strsql = strsql + " and Password =" + "'" + Utility.StrManage.md5(tbx_pwd.Text.Trim()) + "'";


            //创建数据库命令
            OleDbCommand mycmd = new OleDbCommand(strsql, myconn);

            OleDbDataReader dr = mycmd.ExecuteReader();
            if (dr.Read())
            {
                Session["AdminLevel"] = 1;
                Response.Redirect("AddNews.aspx?Action=Add");
            }
            else
            {
                Message.Visible = true;
                Message.Text = "用户名或密码错误！";
            }
            myconn.Close();
        }

    }
}
