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_UserInAlphabetical : ManagePage
{
    string letter = "A";
    protected void Page_Load(object sender, EventArgs e)
    {
   
        rprSelectionList.ItemCommand += new RepeaterCommandEventHandler(rprSelectionList_ItemCommand);
        if (Request.QueryString["Letter"] != null)
        {
            letter = Request.QueryString["Letter"].Trim();
        }
        if (letter.Length > 1)
            letter = letter.Substring(1, 1);
        if (!IsPostBack)
        {
            InitLetter();
            BindUsers();
        }
    }

    void rprSelectionList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName.ToLower() == "delete")
        {
           string account=e.CommandArgument.ToString();
           Users.DelUser(account);
        }
        InitLetter();
        BindUsers();
    }

    private void InitLetter()
    {
        string ls = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        for (int i = 0; i < ls.Length; i++)
        {
            HyperLink lnk = new HyperLink();
            lnk.Text = ls[i].ToString();
            lnk.Style.Add("width","24px");
            if (ls[i] == letter[0])
            {
                lnk.Font.Bold = true;
                lnk.Font.Underline = true;
                //lnk.ForeColor=Col
                lnk.Text =string.Format("<font color=red>{0}</font>",ls[i]);
            }
            lnk.NavigateUrl = string.Format("UserInAlphabetical.aspx?Letter={0}", ls[i]);
            phLetter.Controls.Add(lnk);
            phLetter.Controls.Add(new LiteralControl(" "));
        }
       

    }

    private void BindUsers()
    {
    
        PagedUser p = new PagedUser(PostPaged.CurrentPageIndex, PostPaged.PageSize,0);
        p.Letter = letter[0];
        int count;
        DataView list = Users.GetUsersByAlphabetical(p,out count);
        rprSelectionList.DataSource = list;
        rprSelectionList.DataBind();
        PostPaged.RecordCount = count;
        txtStatus.Text = string.Format("<b><font color=red>当前检索字母:{0},[{2}/{3}]共有记录{1}条</font></b> ", letter[0], count, PostPaged.CurrentPageIndex, PostPaged.PageSize);

    }
    protected void dropPostCategory_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {

    }
    protected void PostPaged_PageChanged(object src, Xiaoxiao.WebUI.PageChangedEventArgs e)
    {
        PostPaged.CurrentPageIndex = e.NewPageIndex;
        BindUsers();
    }
}
