OA项目之分页

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DigitalCampus.Web.Common
{
    public class PageFuntion
    {
        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="DataCount">数据总数</param>
        /// <param name="pageSize">每页显示数据数</param>
        /// <param name="CurrentPage">当前页码</param>
        /// <param name="para">传参</param>
        /// <param name="pageName">页面</param>
        /// <returns></returns>
        public static string GetStrPage(int DataCount, int pageSize, int CurrentPage, string para)
        {
            //得到总页数

            double tempcount = Math.Ceiling(Double.Parse(DataCount.ToString()) / Double.Parse(pageSize.ToString()));
            int pageCount = int.Parse(tempcount.ToString());

            string strPage = string.Empty;
            double pf = Math.Ceiling(double.Parse(CurrentPage.ToString()) / 10);
            int ptotemp = 0;
            int pfrom = int.Parse(pf.ToString());
            int pto = pfrom * 10;

            if (CurrentPage == 1)
            {
                strPage += "<li class=\"active\"><a href='javascript:void(0);'>首 页</a></li>";
            }
            else
            {
                strPage += "<li><a href='?pNum=1";
                strPage += para;
                strPage += "'>首 页</a></li>";
            }
            //上一页
            if (CurrentPage <= 1)
            {
                strPage += "<li class=\"active\"><a href='javascript:void(0);'>上一页</a></li>";
            }
            else
            {
                strPage += "<li><a href ='?pNum=" + (CurrentPage - 1 + para) + "' >上一页</a></li>";
            }
            //上一组
            if ((pto - 10) > 0)
            {
                strPage += "<li><a href='?pNum=" + (pto - 10) + para + "'>...</a></li>";
            }
            else
            {
                //strPage += " ...&nbsp;";
            }
            //总页数与组最大最比较
            if (pto > pageCount)
            {
                ptotemp = pageCount;
            }
            else
            {
                ptotemp = pto;
            }
            //显示面码
            for (int i = pto - 9; i <= ptotemp; i++)
            {
                if (i == CurrentPage)
                {
                    strPage += "<li class=\"active\"><a href='javascript:void(0);'>" + i + "</a></li>";
                }
                else
                {
                    strPage += "<li><a href='?pNum=" + i + para + "'>" + i + "</a></li>";
                }
            }
            //下一组
            if ((pto) < pageCount)
            {
                strPage += "<li><a href='?pNum=" + (pto + 1) + para + "'>...</a></li>";
            }
            else
            {

            }
            //下一页
            if (CurrentPage >= pageCount)
            {
                strPage += "<li class=\"active\"><a href='javascript:void(0);'>下一页</a></li>";
            }
            else
            {
                strPage += "<li><a href ='?pNum=" + (CurrentPage + 1) + para + "' >下一页</a></li>";
            }

            int page = 0;
            if (DataCount % pageSize != 0)
            {
                page = DataCount / pageSize + 1;
            }
            else
            {
                page = DataCount / pageSize;
            }

            if (CurrentPage == page || page == 0)
            {
                strPage += "<li class=\"active\"><a href='javascript:void(0);'>末 页</a></li>";
            }
            else
            {
                strPage += "<li><a href='?pNum=";
                strPage += page + para;
                strPage += "'>末 页</a></li>";
            }
            strPage += "<li class=\"active\"><a href='javascript:void(0);'>共" + DataCount + "条数据</a></li>";
            strPage += "<li class=\"active\"><a href='javascript:void(0);'>页码:" + CurrentPage + "/" + page + "</a></li>";
            //string[] strPArray = new string[] { "10", "15", "20", "30", "50" };
            //string strP = string.Empty;
            //for (int i = 0; i < strPArray.Length; i++)
            //{
            //    string strSelected = string.Empty;
            //    strSelected = pageSize.ToString() == strPArray[i].ToString() ? "selected" : "";
            //    strP += "<option value='" + strPArray[i] + "' " + strSelected + ">" + strPArray[i] + "</option>\n\r";
            //}

            //strPage += "<li><span  class=\"spanfont\">显示:</span><select class=\"select1\" onchange=\"PageSizeChange('" + pageName + "?" + para + "',this);\">" + strP + "</select></li>";
            return strPage;
        }

        /// <summary>
        /// 分页 JS跳转
        /// </summary>
        /// <param name="DataCount">数据总数</param>
        /// <param name="pageSize">每页显示数据数</param>
        /// <param name="CurrentPage">当前页码</param>
        /// <param name="para">传参</param>
        /// <param name="pageName">页面</param>
        /// <returns></returns>
        public static string GetStrPage2(int DataCount, int pageSize, int CurrentPage, string para)
        {
            //得到总页数

            double tempcount = Math.Ceiling(Double.Parse(DataCount.ToString()) / Double.Parse(pageSize.ToString()));
            int pageCount = int.Parse(tempcount.ToString());

            string strPage = string.Empty;
            double pf = Math.Ceiling(double.Parse(CurrentPage.ToString()) / 6);
            int ptotemp = 0;
            int pfrom = int.Parse(pf.ToString());
            int pto = pfrom * 6;

            if (CurrentPage == 1)
            {
                strPage += "<li class=\"active\"><a href='javascript:void(0);'>首 页</a></li>";
            }
            else
            {
                strPage += "<li><a href='javascript:void(0);' onclick=\"UcPageChange('1','" + pageSize + "');\">首 页</a></li>";
            }
            //上一页
            if (CurrentPage <= 1)
            {
                strPage += "<li class=\"active\"><a href='javascript:void(0);'>上一页</a></li>";
            }
            else
            {
                strPage += "<li><a href ='javascript:void(0);' onclick=\"UcPageChange('" + (CurrentPage - 1) + "','" + pageSize + "');\">上一页</a></li>";
            }
            //上一组
            if ((pto - 6) > 0)
            {
                strPage += "<li><a href='javascript:void(0);' onclick=\"UcPageChange('" + (pto - 6) + "','" + pageSize + "');\">...</a></li>";
            }
            else
            {
                //strPage += " ...&nbsp;";
            }
            //总页数与组最大最比较
            if (pto > pageCount)
            {
                ptotemp = pageCount;
            }
            else
            {
                ptotemp = pto;
            }
            //显示面码
            for (int i = pto - 5; i <= ptotemp; i++)
            {
                if (i == CurrentPage)
                {
                    strPage += "<li class=\"active\"><a href='javascript:void(0);'>" + i + "</a></li>";
                }
                else
                {
                    strPage += "<li><a href='javascript:void(0);' onclick=\"UcPageChange('" + (i) + "','" + pageSize + "');\">" + i + "</a></li>";
                }
            }
            //下一组
            if ((pto) < pageCount)
            {
                strPage += "<li><a href='javascript:void(0);' onclick=\"UcPageChange('" + (pto + 1) + "','" + pageSize + "');\">...</a></li>";
            }
            else
            {

            }
            //下一页
            if (CurrentPage >= pageCount)
            {
                strPage += "<li class=\"active\"><a href='javascript:void(0);'>下一页</a></li>";
            }
            else
            {
                strPage += "<li><a href ='javascript:void(0);' onclick=\"UcPageChange('" + (CurrentPage + 1) + "','" + pageSize + "');\">下一页</a></li>";
            }

            int page = 0;
            if (DataCount % pageSize != 0)
            {
                page = DataCount / pageSize + 1;
            }
            else
            {
                page = DataCount / pageSize;
            }
            if (CurrentPage == page || page == 0)
            {
                strPage += "<li class=\"active\"><a href='javascript:void(0);'>末 页</a></li>";
            }
            else
            {
                strPage += "<li><a href='javascript:void(0);'  onclick=\"UcPageChange('" + page + "','" + pageSize + "');\">末 页</a></li>";
            }

            strPage += "<li class=\"active\"><a href='javascript:void(0);'>共" + DataCount + "条数据</a></li>";
            strPage += "<li class=\"active\"><a href='javascript:void(0);'>页码:" + CurrentPage + "/" + page + "</a></li>";
            return strPage;
        }

    }
}

 

你可能感兴趣的:(分页)