/// <summary> /// 根据条件,获取数据(分页) /// </summary> /// <param name="whereStatement">条件对象</param> /// <param name="recordCount">数据数量</param> /// <param name="pageIndex">当前页</param> /// <param name="pageSize">页容量</param> /// <param name="orderByStatement">排序对象</param> /// <returns></returns> public virtual DataTable GetDataTableByPage(WhereStatement whereStatement, out int recordCount, int pageIndex = 1, int pageSize = 50, OrderByStatement orderByStatement = null) { DataTable dataTable = new DataTable(this.CurrentTableName); whereStatement.DbHelper = this.DbHelper; SelectQueryBuilder sqlBuilder = new SelectQueryBuilder(this.DbHelper); sqlBuilder.SetSelectAllColumns(); sqlBuilder.SetFromTable(this.CurrentTableName); sqlBuilder.AddWhere(whereStatement); DbParameter[] parameters = null; string sql = sqlBuilder.BuildSQL(out parameters); recordCount = Convert.ToInt32(this.DbHelper.ExecuteScalar(PagingBuilder.CreateCountingSql(sql), parameters)); if (pageIndex * 1.0 > Math.Ceiling(recordCount * 1.0 / pageSize * 1.0)) { //超过总页数 return(dataTable); } if (orderByStatement == null) { orderByStatement = new OrderByStatement("ID", Sorting.Ascending); } string orderBySql = orderByStatement.BuildOrderByStatement(); string pagedSql = PagingBuilder.CreatePagingSql(recordCount, pageSize, pageIndex, sql, orderBySql); dataTable = this.DbHelper.Fill(pagedSql, parameters); return(dataTable); }
protected PageButtonVM[] Paging(int pageIndex, int count, string sessionKey, int pageSize = 3) { int pageCount = (int)Math.Ceiling((float)count / pageSize); if (pageIndex > pageCount - 1) { pageIndex = pageCount - 1; } Session[sessionKey] = pageIndex; PagingBuilder pb = new PagingBuilder(); pb.PageCount = pageCount; pb.PageIndex = pageIndex + 1; pb.ItemTemplates = new string[] { "{0}", "javascript:onPagingButtonClick('{0}');" }; pb.Mode = new BalancedPagingMode() { FloatingItemCount = 3, TotalItemCount = 12 }; return(pb.Build().Items.Select(i => new PageButtonVM() { ClassName = GetClassName(i), Text = i.Text, IsGap = i.IsGap, OnClick = string.Format("javascript:onPagingButtonClick({0})", int.Parse(i.Text) - 1) }).ToArray()); }
public static IQueryable <T> ApplyQueryParams <T>(this IQueryable <T> queryable, QueryParams @params) where T : class { if (@params == null) { return(queryable); } IQueryBuilder <T> expandBuilder = new IncludeBuilder <T>(); var result = expandBuilder.Build(@params, queryable); IQueryBuilder <T> filterBuilder = new QueryBuilder <T>(); result = filterBuilder.Build(@params, result); IQueryBuilder <T> orderBuilder = new OrderByBuilder <T>(); result = orderBuilder.Build(@params, result); IQueryBuilder <T> pagingBuilder = new PagingBuilder <T>(); result = pagingBuilder.Build(@params, result); return(result); }
public virtual string[] GetPropertiesByPage(string selectFieldName, WhereStatement whereStatement, out int recordCount, int pageIndex = 1, int pageSize = 50, OrderByStatement orderByStatement = null) { whereStatement.DbHelper = this.DbHelper; SelectQueryBuilder sqlBuilder = new SelectQueryBuilder(this.DbHelper); sqlBuilder.SetSelectColumns(selectFieldName); sqlBuilder.SetFromTable(this.CurrentTableName); sqlBuilder.AddWhere(whereStatement); DbParameter[] parameters = null; string sql = sqlBuilder.BuildSQL(out parameters); recordCount = Convert.ToInt32(this.DbHelper.ExecuteScalar(PagingBuilder.CreateCountingSql(sql), parameters)); if (orderByStatement == null) { orderByStatement = new OrderByStatement(this._iEntity.PrimaryKey, Sorting.Ascending); } string orderBySql = orderByStatement.BuildOrderByStatement(); string pagedSql = PagingBuilder.CreatePagingSql(recordCount, pageSize, pageIndex, sql, orderBySql); DataTable dataTable = new DataTable(this.CurrentTableName); dataTable = this.DbHelper.Fill(pagedSql, parameters); return(DataTableUtil.FieldToArray(dataTable, selectFieldName)); }
public void Paging() { PagingBuilder pagingBuilder = new PagingBuilder(null); PagingBuilder actionBuilder = null; PagingConfig config = null; _builderFactory.PagingBuilder(Arg.Do <PagingConfig>(c => config = c)).Returns(pagingBuilder); TableBuilder <TableEntity> builder = _builder.Paging(fb => actionBuilder = fb); this.RenderAndVerify(); _builderFactory.Received(1).PagingBuilder(Arg.Any <PagingConfig>()); actionBuilder.Should().BeSameAs(pagingBuilder); config.Should().BeSameAs(_config.Paging); builder.Should().BeSameAs(_builder); }