zoukankan      html  css  js  c++  java
  • C【C#公共帮助类】分页逻辑处理类

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Common
    {
        /// <summary>
        /// 分页逻辑处理类
        /// </summary>
        public class PageCollection
        {
            /// <summary>
            /// 总页数
            /// </summary>
            public int TotalPages { get; set; }
            /// <summary>
            /// 当前页面
            /// </summary>
            public int CurrentPage { get; set; }
            /// <summary>
            /// 每页的记录数
            /// </summary>
            public int OnePageSize { get; set; }
            /// <summary>
            /// 总记录数
            /// </summary>
            public long TotalRows { get; set; }
            /// <summary>
            /// 排序
            /// </summary>
            public string OrderBy { get; set; }
    
            /// <summary>
            /// 构造无参默认为最大数
            /// </summary>
            public PageCollection()
            {
                this.CurrentPage = 0;
                this.OnePageSize = 20;//默认最大行数20条
            }
        }
        /// <summary>
        /// 分页逻辑处理类 linq to entites
        /// </summary>
        public class PageInfo<TEntity> where TEntity : class
        {
            public PageInfo(int index, int pageSize, int count, List<TEntity> list,string url="")
            {
                Index = index;
                PageSize = pageSize;
                Count = count;
                List = list;
                Url = url;
                //计算数据条数从开始到结束的值
                if (count == 0)
                {
                    BeginPage = 0;
                    EndPage = 0;
                }
                else
                {
                    int maxpage = count / pageSize;
    
                    if (count % pageSize > 0)
                    {
                        maxpage++;
                    }
                    if (index >= maxpage)
                    {
                        index = maxpage;
    
                        BeginPage = pageSize * index - pageSize + 1;
                        EndPage = count;
                    }
                    else
                    {
                        BeginPage = pageSize * index - pageSize + 1;
                        EndPage = pageSize * index;
                    }
                }
            }
    
            public int Index { get; private set; }
            public int PageSize { get; private set; }
            public int Count { get; private set; }
            public List<TEntity> List { get; set; }
            public string Url { get; set; }
            public int BeginPage { get; private set; }
            public int EndPage { get; private set; }
        }
    
        /// <summary>
        /// 分页逻辑处理类 dynamic
        /// </summary>
        public class PageInfo 
        {
            public PageInfo(int index, int pageSize, int count, dynamic list, string url = "")
            {
                Index = index;
                PageSize = pageSize;
                Count = count;
                List = list;
                Url = url;
                //计算数据条数从开始到结束的值
                if (count == 0)
                {
                    BeginPage = 0;
                    EndPage = 0;
                }
                else
                {
                    int maxpage = count / pageSize;
    
                    if (count % pageSize > 0)
                    {
                        maxpage++;
                    }
                    if (index >= maxpage)
                    {
                        index = maxpage;
    
                        BeginPage = pageSize * index - pageSize + 1;
                        EndPage = count;
                    }
                    else
                    {
                        BeginPage = pageSize * index - pageSize + 1;
                        EndPage = pageSize * index;
                    }
                }
            }
    
            public int Index { get; private set; }
            public int PageSize { get; private set; }
            public int Count { get; private set; }
            public dynamic List { get; private set; }
            public string Url { get; set; }
            public int BeginPage { get; private set; }
            public int EndPage { get; private set; }
        }
    
        /// <summary>
        /// Eazyui分页处理逻辑类
        /// </summary>
        public class PageEazyUi 
        {
            public PageEazyUi(int _page, int _pagesize, int _total, object _rows)
            {
                page = _page;
                pagesize = _pagesize;
                total = _total;
                rows = _rows;
            }
    
            public int page { get; private set; }
            public int pagesize { get; private set; }
            public int total { get; private set; }
            public object rows { get; private set; }
        }
    }
  • 相关阅读:
    ETCD集群部署 和flanne网络插件通信原理介绍
    prometheus02 nodeexporter部署及使用
    docker容器的存储资源(volume)
    ActionScript 3.0 事件机制小结
    ActionScript 3.0 装饰器模式实例
    固定头和底,中间部分自适应布局
    ActionScript 3.0 MVC模式小实例
    A*算法的Actionscript3.0实例
    [Database]sql server 2008 不允许保存更改,您所做的更改要求删除并重新创建以下表 的解决办法
    在phpstorm中svn的使用
  • 原文地址:https://www.cnblogs.com/deepalley/p/10308849.html
Copyright © 2011-2022 走看看