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 Fm.Bussiness;

public partial class admin_user_sys_user_list : BasePage
{
  
   
    protected void Page_Load(object sender, EventArgs e)
    {
       
       
        if (!IsPostBack)
        {
            public_select ps = new public_select();
            //用户组
            DropDownList2.DataSource = ps.Getps("Fm_role","*","");
            DropDownList2.DataTextField = "r_name";
            DropDownList2.DataValueField = "r_id";
            DropDownList2.DataBind();
            DropDownList2.Items.Insert(0,"所有组");
            //级别
            DropDownList3.DataSource = ps.Getps("Fm_group","*","");
            DropDownList3.DataTextField = "g_name";
            DropDownList3.DataValueField = "g_id";
            DropDownList3.DataBind();
            DropDownList3.Items.Insert(0,"所有级别");
        }  
        string where="";
        if (Request.QueryString["where"] != null&&Request.QueryString["where"].ToString()!="")
        {
            where = Request.QueryString["where"].ToString().Replace("$"," ");
            where=where.Replace("*","%");
        }
       // Response.Write(where);
        GetPage(where);
    }
    //查询数据并且分页
    void GetPage(string where)
    {
        FormPaging1.TableName = "Fm_user_view";
        FormPaging1.ColName = "u_id";
        FormPaging1.Where = where;
        FormPaging1.Gv = GridView1;
    }
    //编辑会员信息
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        Response.Redirect("sys_user_edit.aspx?u_id="+int.Parse(GridView1.DataKeys[e.NewEditIndex].Value.ToString())+"", false);
    }
    //删除会员信息
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        sys_user_user sys = new sys_user_user();
        Fm.EntityClass.User user = new Fm.EntityClass.User();
        user.u_id=int.Parse( GridView1.DataKeys[e.RowIndex].Value.ToString());
        if (sys.sys_user_del(user))
        {
            Response.Redirect("../Erro.aspx?eid=该会员记录删除成功!&url=user/sys_user_list.aspx", false);
        }
    }
    //删除所选的
    protected void Button1_Click(object sender, EventArgs e)
    {
        sys_user_user sys = new sys_user_user();

        Fm.EntityClass.User user = new Fm.EntityClass.User();
        int cont = GridView1.Rows.Count;
        for (int i = 0; i < cont; i++)
        {
            CheckBox che = GridView1.Rows[i].FindControl("CheckBox1") as CheckBox;
            if (che.Checked)
            {
                user.u_id = int.Parse(GridView1.DataKeys[i].Value.ToString());
                sys.sys_user_del(user);
            }
        }
        Response.Redirect("../Erro.aspx?eid=所选会员记录删除成功!&url=user/sys_user_list.aspx", false);
    }
    //根据输入查询
    protected void Button2_Click(object sender, EventArgs e)
    {
        string where = "";
        if (DropDownList1.SelectedValue == "1")
        {
            where = "$u_name$like$'*"+TextBox1.Text+"*'";
        }
        else if (DropDownList1.SelectedValue == "2")
        {
            where = "$r_name$like$'*" + TextBox1.Text + "*'";
        }
        else
        {
            where = "$g_name$like$'*"+TextBox1.Text+"*'";
        }
        Response.Redirect("sys_user_list.aspx?where="+where,false);
    }
    //查询全部
    protected void Button3_Click(object sender, EventArgs e)
    {
        Response.Redirect("sys_user_list.aspx", false);
    }
    //按用户组
    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {
        string where = "";
        if (DropDownList2.Text != "所有组")
        {
            where = "$r_id="+int.Parse(DropDownList2.SelectedValue)+"";
        }
      
        Response.Redirect("sys_user_list.aspx?where=" + where, false);
    }
    //按默认级别
    protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
    {
        string where = "";
        if (DropDownList3.Text != "所有级别")
        {
            where = "$g_id=" + int.Parse(DropDownList3.SelectedValue) + "";
        }
        
        Response.Redirect("sys_user_list.aspx?where=" + where, false);
    }
}
