using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using Model.DTO;
using System.Data;
using DB;
using Newtonsoft.Json;
namespace DAL
{
public class PageCommon
{
public static PageList<T> StoredList<T>(ParaModel model)
{
string sql = "up_CommodityFy";
SqlParameter[] pars = new SqlParameter[7];
pars[0] = new SqlParameter("@tableName", model.TableName);
pars[1] = new SqlParameter("@indexCol", model.IndexCOl);
pars[2] = new SqlParameter("@pageSize", model.PageSize);
pars[3] = new SqlParameter("@pageIndex", model.PageIndex);
pars[4] = new SqlParameter("@orderCol", model.OrderCol);
pars[5] = new SqlParameter("@where", model.StrWhere);
pars[6] = new SqlParameter("@columns", model.Columns);
DataSet ds = DbHelperSQL.ExecuteDataset(DbHelperSQL.ConnB2c, CommandType.StoredProcedure, sql, pars);
var list = JsonConvert.DeserializeObject<List<T>>(JsonConvert.SerializeObject(ds.Tables[0]));
PageList<T> pagelist = new PageList<T>();
pagelist.listData = list;
//总条数
int totalNum= pagelist.TotalNum = Convert.ToInt32(ds.Tables[1].Rows[0][0]);
//总页数
int totalPage = (totalNum % model.PageSize) > 0 ? (totalNum / model.PageSize) + 1 : totalNum / model.PageSize;
pagelist.TotalNum = totalNum;
pagelist.TotalPage = totalPage;
return pagelist;
}
}
}