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 Base;
using System.Data.SqlClient;
public partial class Control_pagin : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

          //  Bind();
    
    }
    private string _where;
    private string _strurl;  //链接字符串
    private int _pagecount;  //每页的记录数
    private int _pageindex;  //当前页
    private string _table;   //查询的表

    public string Where
    {
        get { return _where; }
        set { _where = value; }
    }
    public string Table
    {
        get { return _table; }
        set { _table = value; }
    }
    public int Pageindex
    {
        get { return _pageindex; }
        set { _pageindex = value; }
    }
    public int PageCount
    {
        get { return _pagecount; }
        set { _pagecount = value; }
    }
    public string Strurl
    {
        get { return _strurl; }
        set { _strurl = value; }
    }

    //private void Bind()
    //{
    //    GetRequest core = new GetRequest();
    //    DataTable tb = core.GetDataTable(Where,Table,1);
    //    if (Pageindex < 1) Pageindex = 1;
    //    int intCount = Convert.ToInt32(tb.Rows[0]["Total"]);
    //    this.Label1.Text = GoToPager(Pageindex, PageCount, intCount, Strurl);

    //}

    /// <summary>
    /// 分页函数
    /// </summary>
    /// <param name="page">要连接的页</param>
    /// <param name="pageSize">每页的记录数</param>
    /// <param name="Count">总的记录数</param>
    /// <param name="Url">链接的参数</param>
    /// <returns></returns>
    public static string GoToPager(int page, int pageSize, int Count, string Url)
    {
        string strHtml = "";
        int prevPage = page - 1;
        int nextPage = page + 1;
        int startPage;
        int pageCount = (int)Math.Ceiling((double)Count / pageSize);
        strHtml += "<div class='pageContent' style='text-align:Left;overflow:hidden;height:25px;line-height:140%'>";
        strHtml += "<span style='float:left'>页码：" + page + "/" + pageCount + "&nbsp;总记录：" + Count + "</span>";
        strHtml += "<div class='page' style='float:Right'><ul><li class='pages'>";
        if (prevPage < 1)
        {
            strHtml += "<span title='首页'>首页&nbsp;</span>";
            strHtml += "<span title='上一页'>上一页&nbsp;</span>";
        }
        else
        {
            strHtml += "<span title='首页'><a href='" + Url + "=1'>首页</a>&nbsp;</span>";
            strHtml += "<span title='上一页'><a href='" + Url + "=" + prevPage + "'>上一页</a>&nbsp;</span>";
        }
        if (page % 10 == 0)
        {
            startPage = page - 9;
        }
        else
        {
            startPage = page - page % 10 + 1;
        }
        if (startPage > 10) strHtml += "<span title='前10页'><a href='" + Url + "=" + (startPage - 1) + "'>...</a></span>";
        for (int i = startPage; i < startPage + 10; i++)
        {
            if (i > pageCount) break;
            if (i == page)
            {
                strHtml += "<span title='页 " + i + "'> <font color='#ff0000'>[" + i + "]</font> </span>";
            }
            else
            {
                strHtml += "<span title='页 " + i + "'> <a href='" + Url + "=" + i + "'>[" + i + "]</a> </span>";
            }
        }
        if (pageCount >= startPage + 10) strHtml += "<span title='后10页'><a href='" + Url + "=" + (startPage + 10) + "'>...</a></span>";
        if (nextPage > pageCount)
        {
            strHtml += "<span title='下一页'>&nbsp;下一页&nbsp;</span>";
            strHtml += "<span title='末页'>末页&nbsp;</span>";
        }
        else
        {
            strHtml += "<span title='下一页'>&nbsp;<a href='" + Url + "=" + nextPage + "'>下一页</a>&nbsp;</span>";
            strHtml += "<span title='末页'><a href='" + Url + "=" + pageCount + "'>末页</a>&nbsp;</span>";
        }


        strHtml += "</li></ul></div></div>";
        return strHtml;
    }

    protected void GetURL_Click(object sender, EventArgs e)
    {
        Response.Redirect(Strurl + "=" + Convert.ToInt32(this.TextBox1.Text.ToString()));
    }
}
