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 Spaces;
using System.Collections.Generic;
using Spaces.Controls;
public partial class Manage_UserList : ManagePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        rprSelectionList.ItemCommand += new RepeaterCommandEventHandler(rprSelectionList_ItemCommand);
 
        if (!IsPostBack)
            BindUsers();
    }
    void rprSelectionList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName.ToLower() == "delete")
        {
            string account = e.CommandArgument.ToString();
            Users.DelUser(account);
        }

        BindUsers();
    }
    private void BindUsers()
    {
     
      
        string selectValue =dropGroup.SelectedValue;
        int groupID=-1;
        try{
            groupID = int.Parse(selectValue);
        }catch{groupID=-1;
        }
        PagedUser p=new PagedUser(PostPaged.CurrentPageIndex,PostPaged.PageSize,groupID);
        int count=0;
        DataView list = Users.GetUsersPaged(p, out count);
        PostPaged.RecordCount = count;
        rprSelectionList.DataSource = list;
        rprSelectionList.DataBind();

        ListItem defaultLI = new ListItem();
        defaultLI.Text = "All Users";
        defaultLI.Value = "-1";
        if (selectValue == defaultLI.Value)
        {
            defaultLI.Selected = true;
        }
       
        string sql = "select * from User_Group";
        DataView dv =SpacesDataProvider.Instance().GetDataView(sql);
        dropGroup.Items.Clear();
        dropGroup.Items.Add(defaultLI);
        foreach (DataRowView dr in dv)
        {
            ListItem li = new ListItem();
            li.Text = dr["GroupName"].ToString();
            li.Value = dr["GroupID"].ToString();
            if (li.Value == selectValue)
            {
                li.Selected = true;
            }
            dropGroup.Items.Add(li);
        }
        txtStatus.Text = string.Format("<b><font color=red>当前用户所在组:{0},[{2}/{3}]共有记录{1}条</font></b> ",dropGroup.SelectedItem.Text,count,PostPaged.CurrentPageIndex,PostPaged.PageSize);
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string sql = @"select  u.Account,c.Title,u.Created,u.Active,c.Theme,u.DateLastLogin from Users u inner join User_UserConfig c on (u.Account=c.Account) where 
 	u.Account like '%{0}%'";
        DataView dv = SpacesDataProvider.Instance().GetDataView(string.Format(sql, txtAccount.Text));
        rprSelectionList.DataSource = dv;
        rprSelectionList.DataBind();
    }
    protected void dropPostCategory_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindUsers();
    }
    protected void PostPaged_PageChanged(object src, Xiaoxiao.WebUI.PageChangedEventArgs e)
    {
        PostPaged.CurrentPageIndex = e.NewPageIndex;
        BindUsers();
    }
}
