using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Web.Security;
namespace norke
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Buffer = true;
            Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
            Response.Expires = 0;
            Response.CacheControl = "no-cache";

        }
        private bool isAdmin(string strAdmin, string strPassword)//检查 管理员名和密码是否正确
        {
            bool bTemp = false;

            strPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(strPassword, "MD5");

            DBConn myDB = new DBConn();
            string mySql = "select hyname,pws from Muser where hyname='" + strAdmin + "' and pws='" + strPassword + "'";
            SqlDataReader mydr = myDB.getDataReader(mySql);
            if (mydr.Read())
            {
                bTemp = true;
            }
            else
            {
                bTemp = false;
            }

            mydr.Close();
            myDB.Close();

            return bTemp;
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string strAdminname = CleanString.htmlInputText(username.Value.Trim());
            string strAdminPW = CleanString.htmlInputText(pws.Value.Trim());         

            if (isAdmin(strAdminname, strAdminPW))
            {
                HttpCookie myCookie = new HttpCookie("norkeyangjian", strAdminname);//写入Cookies
                Response.Cookies.Add(myCookie);
                Response.Redirect("~/viste/default.aspx");
            }
            else
            {
                //Response.Write("<script>");
               // Response.Write("alert('用户名/密码不正确!!!');");
               // Response.Write("</script>");
                Page.RegisterStartupScript("msgOnlyAlert", "<script>alert('用户名/密码不正确！');</script>");

            }

        }
    }
}
