1
#region
数据源提供(PageData)
2
///
<summary>
3
///
数据源提供
4
///
</summary>
5
public
class
PageData
6
{
7
DataSet ds
=
null
;
8
private
int
_PageSize
=
50
;
//
分页大小
9
private
int
_PageIndex
=
1
;
//
当前页
10
private
int
_PageCount
=
0
;
//
总页数
11
private
int
_TotalCount
=
0
;
//
总记录数
12
private
string
_QueryFieldName
=
"
*
"
;
//
表字段FieldStr
13
private
bool
_isQueryTotalCounts
=
true
;
//
是否查询总的记录条数
14
private
string
_TableName
=
string
.Empty;
//
表名
15
private
string
_OrderStr
=
string
.Empty;
//
排序_SortStr
16
private
string
_QueryCondition
=
string
.Empty;
//
查询的条件 RowFilter
17
private
string
_PrimaryKey
=
string
.Empty;
//
主键
18
19
///
<summary>
20
///
是否查询总的记录条数
21
///
</summary>
22
public
bool
IsQueryTotalCounts
23
{
24
get
{
return
_isQueryTotalCounts; }
25
set
{ _isQueryTotalCounts
=
value; }
26
}
27
28
///
<summary>
29
///
分页大小(每页显示多少条数据)
30
///
</summary>
31
public
int
PageSize
32
{
33
get
34
{
35
return
_PageSize;
36
37
}
38
set
39
{
40
_PageSize
=
value;
41
}
42
}
43
44
///
<summary>
45
///
当前页
46
///
</summary>
47
public
int
PageIndex
48
{
49
get
50
{
51
return
_PageIndex;
52
}
53
set
54
{
55
_PageIndex
=
value;
56
}
57
}
58
59
///
<summary>
60
///
总页数
61
///
</summary>
62
public
int
PageCount
63
{
64
get
65
{
66
return
_PageCount;
67
}
68
}
69
70
///
<summary>
71
///
总记录数
72
///
</summary>
73
public
int
TotalCount
74
{
75
get
76
{
77
return
_TotalCount;
78
}
79
}
80
81
///
<summary>
82
///
表名或视图名
83
///
</summary>
84
public
string
TableName
85
{
86
get
87
{
88
return
_TableName;
89
}
90
set
91
{
92
_TableName
=
value;
93
}
94
}
95
96
///
<summary>
97
///
表字段FieldStr
98
///
</summary>
99
public
string
QueryFieldName
100
{
101
get
102
{
103
return
_QueryFieldName;
104
}
105
set
106
{
107
_QueryFieldName
=
value;
108
}
109
}
110
111
///
<summary>
112
///
排序字段
113
///
</summary>
114
public
string
OrderStr
115
{
116
get
117
{
118
return
_OrderStr;
119
}
120
set
121
{
122
_OrderStr
=
value;
123
}
124
}
125
126
///
<summary>
127
///
查询条件
128
///
</summary>
129
public
string
QueryCondition
130
{
131
get
132
{
133
return
_QueryCondition;
134
}
135
set
136
{
137
_QueryCondition
=
value;
138
}
139
}
140
141
///
<summary>
142
///
主键
143
///
</summary>
144
public
string
PrimaryKey
145
{
146
get
147
{
148
return
_PrimaryKey;
149
}
150
set
151
{
152
_PrimaryKey
=
value;
153
}
154
}
155
156
///
<summary>
157
///
得到分页数据
158
///
</summary>
159
///
<param name="connectionstring">
连接字符串
</param>
160
///
<returns>
DataSet
</returns>
161
public
DataSet QueryDataTable(
string
connectionstring)
162
{
163
SqlParameter[] parameters
=
{
164
new
SqlParameter(
"
@Tables
"
, SqlDbType.VarChar,
255
),
165
new
SqlParameter(
"
@PrimaryKey
"
, SqlDbType.VarChar ,
255
),
166
new
SqlParameter(
"
@Sort
"
, SqlDbType.VarChar ,
255
),
167
new
SqlParameter(
"
@CurrentPage
"
, SqlDbType.Int ),
168
new
SqlParameter(
"
@PageSize
"
, SqlDbType.Int ),
169
new
SqlParameter(
"
@Fields
"
, SqlDbType.VarChar,
255
),
170
new
SqlParameter(
"
@Filter
"
, SqlDbType.VarChar,
1000
),
171
new
SqlParameter(
"
@Group
"
, SqlDbType.VarChar,
1000
)
172
};
173
parameters[
0
].Value
=
_TableName;
174
parameters[
1
].Value
=
_PrimaryKey;
175
parameters[
2
].Value
=
_OrderStr;
176
parameters[
3
].Value
=
PageIndex;
177
parameters[
4
].Value
=
PageSize;
178
parameters[
5
].Value
=
_QueryFieldName;
179
parameters[
6
].Value
=
_QueryCondition;
180
parameters[
7
].Value
=
string
.Empty;
181
ds
=
null
;
182
ds
=
new
DataSet();
183
ds
=
DbHelperSQL.RunProcedure(connectionstring,
"
uspDividePage
"
, parameters,
"
tbPageData
"
);
184
185
if
(_isQueryTotalCounts)
186
{
187
_TotalCount
=
GetTotalCount(connectionstring);
188
}
189
190
if
(_TotalCount
==
0
)
191
{
192
_PageIndex
=
0
;
193
_PageCount
=
0
;
194
}
195
else
196
{
197
_PageCount
=
_TotalCount
%
_PageSize
==
0
?
_TotalCount
/
_PageSize : _TotalCount
/
_PageSize
+
1
;
198
199
if
(_PageIndex
>
_PageCount)
200
{
201
_PageIndex
=
_PageCount;
202
parameters[
4
].Value
=
_PageSize;
203
ds
=
QueryDataTable(connectionstring);
204
}
205
}
206
207
return
ds;
208
}
209
210
///
<summary>
211
///
得到总的记录数
212
///
</summary>
213
///
<param name="connectionstring">
连接字符串
</param>
214
///
<returns>
总的记录数
</returns>
215
public
int
GetTotalCount(
string
connectionstring)
216
{
217
string
strSql
=
"
select count(1) from
"
+
_TableName;
218
219
if
(_QueryCondition
!=
string
.Empty)
220
{
221
strSql
+=
"
where
"
+
_QueryCondition;
222
}
223
224
return
Convert.ToInt32(DbHelperSQL.GetSingle(strSql.ToString(), connectionstring));
225
}
226
}
227
#endregion