/// <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); }
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)); }