private void Query()
{
DateTime STime = dtpStart.Value;
DateTime ETime = dtpEnd.Value;
if(ETime < STime)
{
MessageBox.Show("开始时间不能大于结束时间");
return;
}
Func<GasData, bool> where;
Func<GasData, object> orderby;
where = (a => a.Dbtime > STime && a.Dbtime < ETime);
orderby = (a => a.Dbtime);
List<GasData> data = DataProcess.GetPageList<GasData>(where, orderby, rows, page, out total);
allPage = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(total) / rows));
lbTatol.Text = "共"+ allPage + "页,共"+ total + "条记录";
}
public static List<T> GetPageList<T>(Func<T, bool> whereLambda, Func<T, object> orderLambda, int pageSize,
int pageIndex, out int total) where T : class
{
using (var db = new DBConn())
{
var list = db.Set<T>().Where<T>(whereLambda).OrderBy(orderLambda).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
total = db.Set<T>().Where<T>(whereLambda).Count();
return list;
}
}