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 person : System.Web.UI.Page
{
    public int page = 1;
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpCookie GetCookie = Request.Cookies["cook_admin"];
        if (Request.Cookies["cook_admin"] == null)
        {
            Response.Redirect("index.aspx");
        }
        if (!IsPostBack)
        {
            BindDrpClass();
            int totalOrders = (int)DbHelperSQL.GetSingle("select count(id) from etw_admin");
            Cache["totalproduct"] = totalOrders;
            Pager1.RecordCount = totalOrders;
        }
        DataUser();
    }
    private void BindDrpClass()
    {
        DataSet ds = DbHelperSQL.Query("select * from etw_role order by id");
        if (ds.Tables[0].Rows.Count > 0)
        {
            role.DataSource = ds.Tables[0].DefaultView;
            role.DataTextField = "rolename";
            role.DataValueField = "id";
            role.DataBind();
        }
        DataSet ds1 = DbHelperSQL.Query("select * from etw_language order by id");
        if (ds1.Tables[0].Rows.Count > 0)
        {
            langlist.DataSource = ds1.Tables[0].DefaultView;
            langlist.DataTextField = "language";
            langlist.DataValueField = "id";
            langlist.DataBind();
        }
    }
    protected void Pager1_PageChanging1(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        Pager1.CurrentPageIndex = e.NewPageIndex;
        page = Pager1.CurrentPageIndex;
        DataUser();
    }
    public void DataUser()
    {
        int i = 1;
        if (Request.QueryString["page"] != null)
        {
            i = Convert.ToInt32(Request.QueryString["page"].ToString());
        }
        int mun = (i - 1) * 20;
        DataSet ds = DbHelperSQL.Query("select top 20 * from etw_admin where id not in(select top " + mun + " id from etw_admin order by id) order by id");
        if (ds.Tables[0].Rows.Count > 0)
        {
            Repeater1.DataSource = ds.Tables[0].DefaultView;
            Repeater1.DataBind();
        }
    }
    public string Cutrole(string str)
    {
        DataSet ds = DbHelperSQL.Query("select * from etw_role where id="+str+"");
        if (ds.Tables[0].Rows.Count > 0)
        {
            str = ds.Tables[0].Rows[0]["rolename"].ToString();
        }
        else
        {
            str = "";
        }
        return str;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        etw.etw_admin lead = new etw.etw_admin();
        lead.roleid = Convert.ToInt32(role.SelectedValue);
        if (role.SelectedValue.ToString() == "3")
        {
            lead.transid = Convert.ToInt32(langlist.SelectedValue);
        }
        lead.realname = Fun.Encode(realname.Text.Trim());
        lead.etwadminname = Fun.Encode(etwadminname.Text.Trim());
        lead.etwadminpwd = etwadminpwd.Text.Trim();
        lead.Add();
        Fun.JsAlerT("添加成功", "person.aspx");
    }
}
