forked from smartstore/SmartStoreNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPagedList.cs
More file actions
153 lines (127 loc) · 3.21 KB
/
Copy pathPagedList.cs
File metadata and controls
153 lines (127 loc) · 3.21 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using System;
using System.Collections;
using System.Linq;
namespace SmartStore.Core
{
// codehint: sm-add (whole file)
public abstract class PagedListBase : IPageable
{
protected PagedListBase()
{
this.PageIndex = 0;
this.PageSize = 0;
this.TotalCount = 1;
}
protected PagedListBase(IPageable pageable)
{
this.Init(pageable);
}
protected PagedListBase(int pageIndex, int pageSize, int totalItemsCount)
{
Guard.PagingArgsValid(pageIndex, pageSize, "pageIndex", "pageSize");
this.PageIndex = pageIndex;
this.PageSize = pageSize;
this.TotalCount = totalItemsCount;
}
// only here for compat reasons with nc
public void LoadPagedList<T>(IPagedList<T> pagedList)
{
this.Init(pagedList as IPageable);
}
public virtual void Init(IPageable pageable)
{
Guard.ArgumentNotNull(pageable, "pageable");
this.PageIndex = pageable.PageIndex;
this.PageSize = pageable.PageSize;
this.TotalCount = pageable.TotalCount;
}
public int PageIndex
{
get;
set;
}
public int PageSize
{
get;
set;
}
public int TotalCount
{
get;
set;
}
public int PageNumber
{
get
{
return this.PageIndex + 1;
}
set
{
this.PageIndex = value - 1;
}
}
public int TotalPages
{
get
{
var total = this.TotalCount / this.PageSize;
if (this.TotalCount % this.PageSize > 0)
total++;
return total;
}
}
public bool HasPreviousPage
{
get
{
return this.PageIndex > 0;
}
}
public bool HasNextPage
{
get
{
return (this.PageIndex < (this.TotalPages - 1));
}
}
public int FirstItemIndex
{
get
{
return (this.PageIndex * this.PageSize) + 1;
}
}
public int LastItemIndex
{
get
{
return Math.Min(this.TotalCount, ((this.PageIndex * this.PageSize) + this.PageSize));
}
}
public bool IsFirstPage
{
get
{
return (this.PageIndex <= 0);
}
}
public bool IsLastPage
{
get
{
return (this.PageIndex >= (this.TotalPages - 1));
}
}
public virtual IEnumerator GetEnumerator()
{
return Enumerable.Empty<int>().GetEnumerator();
}
}
public class PagedList : PagedListBase
{
public PagedList(int pageIndex, int pageSize, int totalItemsCount) : base(pageIndex, pageSize, totalItemsCount)
{
}
}
}