在做项目中,一定会涉及到数据分页的处理,如有一个通用的分页解决办法就好了,发现在通用权限管理系统中就有这种方案。
基本上可实现所有业务共用一个分页方法。
下面是代码的核心部分:
CommonServices.cs
using DotNet.Business; using DotNet.Utilities; ////// 获取分页数据(防注入功能的) /// /// dbHelper /// 记录条数 /// 数据来源表名 /// 选择字段 /// 当前页 /// 每页显示多少条 /// 查询条件 /// 查询参数 /// 排序字段 ///数据表 public static DataTable GetDataTableByPage(IDbHelper dbHelper, BaseUserInfo userInfo, out int recordCount, string tableName, string selectField, int pageIndex, int pageSize, string conditions, List> dbParameters, string orderBy) { DataTable result = null; recordCount = 0; if (null != dbHelper) { recordCount = DbLogic.GetCount(dbHelper, tableName, conditions, dbHelper.MakeParameters(dbParameters)); result = DbLogic.GetDataTableByPage(dbHelper, tableName, selectField, pageIndex, pageSize, conditions, dbHelper.MakeParameters(dbParameters), orderBy); } return result; }
所有的实现分页的业务层直接调用这个方法即可。
还有一个是可以调用存储过程的,大家可以自己研究下。