分页非常的常见,基本任何项目都会涉及到分页,这没什么好谈的,大多数我们分页对单表的分页比较多,对多表的分页我们可以通过视图来实现,当然还有其他的方式,在这儿,我以一个实例展示下使用我们的RDIFramework.NET来实现多表联合查询分页的实现,我以Web的形式展示,WinForm方法一样,分页后的界面如下图所示:
UI上看不出什么,现在我们以代码说明如何实现,使用RDIFramework.NET实现上面的界面代码非常的简单,首先我们看下页面代码,代码如下:
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
|
<%@ Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ProductInMuliPage.aspx.cs" Inherits="RDIFramework.WebApp.demo.ProductInMuliPage" %>
<
asp:Content
ID
=
"Content1"
ContentPlaceHolderID
=
"head"
runat
=
"server"
>
</
asp:Content
>
<
asp:Content
ID
=
"Content2"
ContentPlaceHolderID
=
"ContentPlaceHolder1"
runat
=
"server"
>
<
div
id
=
"toolbar"
>
<
a
id
=
"a_add"
style
=
"float:left"
href
=
"javascript:;"
plain
=
"true"
class
=
"easyui-linkbutton"
icon
=
"icon-add"
title
=
"新增"
>新增</
a
>
<
div
class
=
'datagrid-btn-separator'
>
</
div
>
<
a
id
=
"a_edit"
style
=
"float:left"
href
=
"javascript:;"
plain
=
"true"
class
=
"easyui-linkbutton"
icon
=
"icon-pencil"
title
=
"修改"
>修改</
a
>
<
div
class
=
'datagrid-btn-separator'
></
div
>
<
a
id
=
"a_delete"
style
=
"float:left"
href
=
"javascript:;"
plain
=
"true"
class
=
"easyui-linkbutton"
icon
=
"icon-delete"
title
=
"***"
>***</
a
>
</
div
>
<
table
id
=
"list1"
></
table
>
<
script
type
=
"text/javascript"
>
$(function () {
autoResize({ dataGrid: '#list1', gridType: 'datagrid', callback: grid.bind, height: 0 });
$('#a_add').click(CRUD.add);
$('#a_edit').click(CRUD.edit);
$('#a_delete').click(CRUD.del);
});
var grid = {
bind: function (winSize) {
$('#list1').datagrid({
url: '/demo/handler/ProductIn.ashx?action=GetMultiPage',
toolbar: '#toolbar',
title: "数据列表",
iconCls: 'icon icon-list',
width: winSize.width,
height: winSize.height,
nowrap: false, //折行
rownumbers: true, //行号
striped: true, //隔行变色
idField: 'ID', //主键
sortName: 'CREATEON',
sortOrder: 'desc',
singleSelect: true, //单选
frozenColumns: [[]],
columns: [[
{ title: '主键', field: 'ID', width: 120, hidden: true },
{ title: '入库单编码', field: 'CODE', width: 130 },
{ title: '入库日期', field: 'INDATE', width: 150 },
{ title: '入库类型', field: 'INTYPE', width: 100 },
{ title: '保管员', field: 'CUSTODIAN', width: 70 },
{ title: '品名', field: 'FULLNAME', width: 100 },
{ title: '数量', field: 'AMOUNT', width: 80 },
{ title: '单价', field: 'UNITPRICE', width: 150 }
]],
pagination: true,
pageSize: 5,
pageList: [5, 10, 20]
});
},
getSelectedRow: function () {
return $('#list1').datagrid('getSelected');
},
reload: function () {
$('#list1').datagrid('clearSelections').datagrid('reload', { filter: '' });
}
};
</
script
>
</
asp:Content
>
|
上面的代码,我们就实现了页面部分,现在我们来看下分页的代码,分页在我们框架中已经做了很完美的支持,可以通过多种方式,支持不同类型的数据库的分页实现,直接调用接口方法即可实现。我们看下上面的页面部分调用的ashx中的方法“/demo/handler/ProductIn.ashx?action=GetMultiPage”代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
private
string
GetProductMultiPage()
{
var
returnJson =
"[]"
;
var
managerMain =
new
CASE_PRODUCTIN_MAINManager(
this
.dbHelper, Utils.UserInfo);
var
_pageindex = pageindex > 0 ? pageindex : 1;
var
_pagesize = pagesize > 0 ? pagesize : 20;
int
recordCount;
managerMain.CurrentTableName =
@"(SELECT tab1.ID,tab1.CODE,tab1.INDATE,tab1.INTYPE,tab1.CUSTODIAN,tab1.CREATEON,tab2.FULLNAME,tab2.AMOUNT,tab2.UNITPRICE
FROM dbo.CASE_PRODUCTIN_MAIN tab1
INNER JOIN dbo.CASE_PRODUCTIN_DETAIL tab2
ON tab1.ID = tab2.CASE_PRODUCTIN_MAIN_ID) pageData"
;
managerMain.SelectField =
"*"
;
var
dtProductIn = managerMain.GetDTByPage(
out
recordCount, _pageindex, _pagesize,
null
,
"CREATEON DESC"
);
if
(dtProductIn !=
null
&& dtProductIn.Rows.Count > 0)
{
returnJson = JSONhelper.FormatJSONForEasyuiDataGrid(recordCount, dtProductIn);
}
return
returnJson;
}
|
上面的代码可供开发者参考,这样不管你是多少表的关联查询,分页的问题都可以迎刃而解,WinForm的类似。
本文转自yonghu86 51CTO博客,原文链接:http://blog.51cto.com/yonghu/1421976,如需转载请自行联系原作者