private DataList GetRows(long start, long numOfRows) { var dl = new DataList(); _bp.ForEachRow(() => { if (_bp.Counter > start) { dl.AddItem(GetItem()); } if (_bp.Counter == start + numOfRows) { _bp.Exit(); } }); return(dl); }
public static DataList ToDataList(this ENV.Data.Entity entity, FilterBase where = null, Sort orderBy = null, params ColumnBase[] columns) { var result = new DataList(); int pageSize = 100; int pageNum = 0; { var s = System.Web.HttpContext.Current.Request["PageNum"]; if (!string.IsNullOrEmpty(s)) { pageNum = int.Parse(s); } } var bp = new BusinessProcess { From = entity }; if (where != null) { bp.Where.Add(where); } if (orderBy != null) { bp.OrderBy = orderBy; } bp.ForEachRow(() => { int currentPage = ((int)bp.Counter - 1) / pageSize; if (currentPage == pageNum) { if (columns != null) { result.AddItem(columns); } else { result.AddItem(entity); } } else if (currentPage > pageNum) { bp.Exit(); } }); return(result); }
public DataList GetRows() { init(); var dl = new DataList(); foreach (var item in _colsPerKey) { item.Value.addFilter(HttpContext.Value.GetRequestParam(item.Key), _tempFilter, new equalToFilter()); item.Value.addFilter(HttpContext.Value.GetRequestParam(item.Key + "_gt"), _tempFilter, new greater()); item.Value.addFilter(HttpContext.Value.GetRequestParam(item.Key + "_gte"), _tempFilter, new greaterEqual()); item.Value.addFilter(HttpContext.Value.GetRequestParam(item.Key + "_lt"), _tempFilter, new lesser()); item.Value.addFilter(HttpContext.Value.GetRequestParam(item.Key + "_lte"), _tempFilter, new lessOrEqual()); item.Value.addFilter(HttpContext.Value.GetRequestParam(item.Key + "_ne"), _tempFilter, new different()); } long start = 0; long numOfRows = 25; { var limit = HttpContext.Value.GetRequestParam("_limit"); if (!string.IsNullOrEmpty(limit)) { numOfRows = Number.Parse(limit); } if (Number.IsNullOrZero(numOfRows)) { numOfRows = 25; } } if (numOfRows > 0) { var page = HttpContext.Value.GetRequestParam("_page"); if (!string.IsNullOrEmpty(page)) { var x = Number.Parse(page); if (x > 0) { start = (x - 1) * numOfRows; } } } var ob = _bp.OrderBy; var sort = HttpContext.Value.GetRequestParam("_sort"); if (!string.IsNullOrEmpty(sort)) { var orderBy = new Sort(); var s = sort.Split(','); var ord = HttpContext.Value.GetRequestParam("_order") ?? ""; var o = ord.Split(','); for (int i = 0; i < s.Length; i++) { ColumnInViewModel cvm; if (_colsPerKey.TryGetValue(s[i], out cvm)) { var so = SortDirection.Ascending; if (o.Length > i && o[i].ToLower().StartsWith("d")) { so = SortDirection.Descending; } cvm.AddSort(orderBy, so); } } if (orderBy.Segments.Count > 0) { _bp.OrderBy = orderBy; } } try { _bp.ForEachRow(() => { if (_bp.Counter > start) { dl.AddItem(GetItem()); } if (_bp.Counter == start + numOfRows) { _bp.Exit(); } }); return(dl); } finally { _bp.OrderBy = ob; _tempFilter.Clear(); } }