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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
 
namespace sbcLabSystem.Models.Backstage
{
    public class PageNavigationViewModel
    {
        public PageNavigationViewModel() { } 
        public PageNavigationViewModel(int pageIndex, int pageItemCount, int maxItemCountInPage)
        {
            this.PageIndex = pageIndex;
            this.PageItemCount = pageItemCount;
            this.LastPageIndex = pageItemCount % maxItemCountInPage == 0 ? pageItemCount / maxItemCountInPage : (pageItemCount / maxItemCountInPage) + 1;
            this.Pages = new List<int>();
            this.Pages.Add(1);
            for (int i = pageIndex - 4; i < pageIndex + 4; i++)
            {
                if (i < 2 || i > LastPageIndex - 1)
                {
                    continue;
                }
                this.Pages.Add(i);
            } 
            if (LastPageIndex > 1)
            {
                this.Pages.Add(LastPageIndex);
            }
        }
        public int PageIndex { get; set; }
        public int PageItemCount { get; set; }
        public int LastPageIndex { get; set; }
        public List<int> Pages { get; set; }
    }
}