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 index : System.Web.UI.Page
{
    public string ip = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        /*ip = DNTRequest.GetIP();
        if(ip!="116.228.89.227" && ip!="61.152.96.20")
        {
           Response.Write("<script type=text/javascript>alert('对不起，您无权登入，请联系系统管理员！'); window.open('http://www.etwservice.com');top.close(); </script>");
        }*/
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string username = adminname.Text.Trim();
        string password = adminpassword.Text.Trim();
        try
        {
            int isvalid = DbHelperSQL.GetSingleUser(username, password);
            if (isvalid > 0)
            {
                DataSet ds = DbHelperSQL.Query("select * from etw_admin where etwadminname='" + username + "' and etwadminpwd='" + password + "'");
                HttpCookie user = new HttpCookie("cook_admin", username);
                user.Values.Add("IsLogin", "ok");
                user.Values.Add("username", username);
                user.Values.Add("isvalid", ds.Tables[0].Rows[0]["roleid"].ToString());
                user.Expires = DateTime.Now.AddHours(12);
                Response.Cookies.Add(user);
                FormsAuthentication.SetAuthCookie(username, true);
                if (ds.Tables[0].Rows[0]["roleid"].ToString() == "3")
                {
                    this.Response.Redirect("../etw_f_m/translate.aspx");
                }
                else
                {
                    this.Response.Redirect("manage.aspx");
                }
            }
            else
            {
                Response.Write("<script language=\"javascript\">alert('登录失败！');window.location='index.aspx'</" + "script>");
                //System.Web.HttpContext.Current.Response.Write("<script type='text/javascript'>alert('登录失败！')</script>");
            }
        }
        catch
        {
            Response.Write("<script language=\"javascript\">alert('登录失败！');window.location='index.aspx'</" + "script>");
            //System.Web.HttpContext.Current.Response.Write("<script type='text/javascript'>alert('登录失败！')</script>");
        }
    }
}
