using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace DAL
{
///
/// 存储分页父类
///
///
public static class PageBase where T : new()
{
///
/// 分页查询
///
/// 类的对象
/// 对象区分
/// 查询的表名
/// 查询的字段名(全部字段为*)
/// 排序字段(必须!支持多字段)
/// 条件语句(不用加where)
/// 每页多少条记录
/// 指定当前为第几页
/// 返回总页数
/// 返回总条数
/// 返回集合
public static List excutePageSql(T t, string type, string tableName, string fields, string orderField, string sqlWhere, int pageSize, int pageIndex, out int totalPage, out int totalRecord, params SqlParameter[] param)
{
List spList = new List();
spList.Add(new SqlParameter("@TableName", SqlDbType.VarChar));
spList.Add(new SqlParameter("@Fields", SqlDbType.VarChar));
spList.Add(new SqlParameter("@OrderField", SqlDbType.VarChar));
spList.Add(new SqlParameter("@sqlWhere", SqlDbType.VarChar));
spList.Add(new SqlParameter("@pageSize", SqlDbType.Int));
spList.Add(new SqlParameter("@pageIndex", SqlDbType.Int));
spList.Add(new SqlParameter("@TotalPage", SqlDbType.Int));
spList.Add(new SqlParameter("@Record", SqlDbType.Int));
spList[0].Value = tableName;
spList[1].Value = fields;
spList[2].Value = orderField;
spList[3].Value = sqlWhere;
spList[4].Value = pageSize;
spList[5].Value = pageIndex;
spList[6].Direction = ParameterDirection.Output;
spList[7].Direction = ParameterDirection.Output;
List list = ServiceBase.excuteSql(new T(), type, "exec_page", CommandType.StoredProcedure, spList.ToArray());
//获取总页数
try
{
totalPage = Convert.ToInt32(spList[6].Value);
}
catch
{
totalPage = 0;
}
try
{
totalRecord = Convert.ToInt32(spList[7].Value);
}
catch
{
totalRecord = 0;
}
return list;
}
}
}