songjun
2024-09-04 cc908053e0b5075fbfd27350b6da4b39bca9e550
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace BatchService.Framework.Utility
{
    public class PageList
    {
        public int ItemCount { get; set; }
        public int CurrentPageIndex { get; set; }
        public int PageCount { get; set; }
        public string Description { get; set; }
        public List<int> Pages { get; set; }
        public string KeyWord { get; set; }
        public string OrderColumn { get; set; }
        public string OrderAsc { get; set; }
 
        public static PageList GetPageList(int ItemCount, int PageSize, int PageIndex)
        {
            PageList pages = new PageList();
            pages.ItemCount = ItemCount;
            pages.CurrentPageIndex = PageIndex;
            if (ItemCount % PageSize == 0)
            {
                pages.PageCount = ItemCount / PageSize;
            }
            else
            {
                pages.PageCount = ItemCount / PageSize + 1;
            }
            if (pages.CurrentPageIndex == 0)
            {
                pages.CurrentPageIndex = 1;
            }
            if (pages.CurrentPageIndex == 999)
            {
                pages.CurrentPageIndex = pages.PageCount;
            }
            pages.Description = string.Format("当前第{0}页:,共{1}页", pages.CurrentPageIndex, pages.PageCount);
            //开始页码
            int PageStart = pages.CurrentPageIndex - 4;
            if (PageStart <= 0)
            {
                PageStart = 1;
            }
            //结束页码
            int PageEnd = pages.CurrentPageIndex + 4 + (4 - PageStart <= 0 ? 0 : 4 - PageStart);
            if (PageEnd > pages.PageCount)
            {
                PageEnd = pages.PageCount;
            }
            pages.Pages = new List<int>();
            pages.Pages.Add(0);
            for (int x = PageStart; x <= PageEnd; x++)
            {
                pages.Pages.Add(x);
            }
            pages.Pages.Add(999);
            return pages;
        }
        /// <summary>
        /// 分页集合
        /// </summary>
        /// <param name="CountSizi">总条数</param>
        /// <param name="PageSizi">每一页总条数</param>
        /// <returns></returns>
        public static List<int> GetPages(int CountSizi, int PageSizi, int Pageindex)
        {
            int pageCount = 0;
            if (CountSizi % PageSizi == 0)
            {
                pageCount = CountSizi / PageSizi;
            }
            else
            {
                pageCount = CountSizi / PageSizi + 1;
            }
            if (Pageindex == 0)
            {
                Pageindex = 1;
            }
            if (Pageindex == 999)
            {
                Pageindex = pageCount;
            }
            //开始页码
            int PageStart = Pageindex - 4;
            if (PageStart <= 0)
            {
                PageStart = 1;
            }
            //结束页码
            int PageEnd = Pageindex + 4;
            if (PageEnd > pageCount)
            {
                PageEnd = pageCount;
            }
            List<int> list = new List<int>();
            list.Add(0);
            for (int x = PageStart; x <= PageEnd; x++)
            {
                list.Add(x);
            }
            list.Add(999);
            return list;
        }
    }
}