using System; using System.Collections.Generic; using System.Globalization; namespace HRM.BO { /// /// What <app-virtual-grid> sends to a page endpoint: the page's own filters plus the grid's /// scroll position, search text and sort. The same class is used by every page, so no page needs a /// request class of its own. See HRM.DA/Service/VirtualPaging/README.md. /// public class VirtualPageRequest { /// The page's filters, e.g. { fromDate: "2025-01-01", toDate: "2025-12-31" }. Read them with GetDate / GetInt / GetString. public Dictionary Filters { get; set; } = new Dictionary(); /// The grid's columns (property names). Only these are sent back and searched. public List Fields { get; set; } = new List(); public int Skip { get; set; } /// Rows wanted. 0 = all rows (used by Export to Excel). public int Take { get; set; } = 100; public string Search { get; set; } public string SortField { get; set; } /// "asc" or "desc". public string SortDir { get; set; } /// True on Preview: load the data again. False on scroll/sort/search/export: use the kept copy. public bool Refresh { get; set; } /// A filter as text, or null when it was not sent. public string GetString(string name) { string value; if (Filters != null && Filters.TryGetValue(name, out value) && !string.IsNullOrWhiteSpace(value)) return value.Trim(); return null; } /// A "yyyy-MM-dd" filter. Throws a message fit for the user when it is missing or invalid. public DateTime GetDate(string name, string label = null) { DateTime value; if (!DateTime.TryParseExact(GetString(name), "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out value)) throw new ArgumentException("Please select a valid " + (label ?? name) + "."); return value; } /// A whole-number filter. Throws a message fit for the user when it is missing or invalid. public int GetInt(string name, string label = null) { int value; if (!int.TryParse(GetString(name), NumberStyles.Integer, CultureInfo.InvariantCulture, out value)) throw new ArgumentException("Please select a valid " + (label ?? name) + "."); return value; } } /// One window of rows for the grid. public class VirtualPageResult { /// Rows matching the search (all rows when there is no search). public int Total { get; set; } /// All rows, ignoring the search. public int TotalWithoutSearch { get; set; } /// The rows of this window, holding only the requested fields. public List> Data { get; set; } = new List>(); } }