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.Text;

public partial class Common_Login : System.Web.UI.Page
{
    UserManage usermanage = new UserManage();
    HostManage hostmanage = new HostManage();
    AdminManage adminmanage = new AdminManage();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["id"] == "0")
        {
            Label1.Text = "〖用户登录〗";
        }
        if (Request.QueryString["id"] == "1")
        {
            Label1.Text = "〖版主登录〗";
        }
        if (Request.QueryString["id"] == "2")
        {
            Label1.Text = "〖管理员登录〗";
        }
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        if (txtName.Text == string.Empty)
        {
            Response.Write("<script language=javascript>alert('登录名不能为空！')</script>");
            return;
        }
        else
        {
            if (Request.QueryString["id"] == "0")
            {
                Session["ID"] = "0";
                DataSet ds = null;
                usermanage.UserName = txtName.Text;
                usermanage.UserPwd = txtPwd.Text;
                ds = usermanage.Login(usermanage);
                if (ds.Tables[0].Rows.Count > 0 && txtCode.Text == Request.Cookies["CheckCode"].Value)
                {
                    Session["Name"] = txtName.Text;
                    Session["Pop"] = "用户";
                    Response.Redirect("../Default.aspx");
                }
                else
                {
                    Response.Write("<script language=javascript>alert('用户名称或密码不正确！')</script>");
                }
            }
            if (Request.QueryString["id"] == "1")
            {
                Session["ID"] = "1";
                DataSet ds = null;
                hostmanage.HostName = txtName.Text;
                hostmanage.HostPwd = txtPwd.Text;
                ds = hostmanage.Login(hostmanage);
                if (ds.Tables[0].Rows.Count > 0 && txtCode.Text == Request.Cookies["CheckCode"].Value)
                {
                    Session["Name"] = txtName.Text;
                    Session["Pop"] = "版主";
                    Response.Redirect("../Default.aspx");
                }
                else
                {
                    Response.Write("<script language=javascript>alert('版主名称或密码不正确！')</script>");
                }
            }
            if (Request.QueryString["id"] == "2")
            {
                Session["ID"] = "2";
                DataSet ds = null;
                adminmanage.AdminName = txtName.Text;
                adminmanage.AdminPwd = txtPwd.Text;
                ds = adminmanage.Login(adminmanage);
                if (ds.Tables[0].Rows.Count > 0 && txtCode.Text == Request.Cookies["CheckCode"].Value)
                {
                    Session["Name"] = txtName.Text;
                    Session["Pop"] = "管理员";
                    Response.Redirect("../Default.aspx");
                }
                else
                {
                    Response.Write("<script language=javascript>alert('管理员名称或密码不正确！')</script>");
                }
            }
        }
    }
    protected void btnClose_Click(object sender, EventArgs e)
    {
        Response.Write("<script language=javascript>window.close();</script>");
    }
}
