111 lines
4.4 KiB
C#
111 lines
4.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace HRM.BO
|
|
{
|
|
/// <summary>
|
|
/// Common virtual-scrolling grid ("virtual grid") contracts.
|
|
///
|
|
/// Every large list screen shares ONE BO / DA / Service / Controller: a screen is just a registered
|
|
/// grid definition (HRM.DA/Service/VirtualGrid/Definitions) identified by <see cref="VirtualGridRequest.GridKey"/>.
|
|
/// The server pages, sorts, searches and exports; the browser only ever holds one window of rows.
|
|
/// See HRM.DA/Service/VirtualGrid/README.md for how to add a grid.
|
|
/// </summary>
|
|
public enum EnumVirtualGridColumnType
|
|
{
|
|
Text = 1,
|
|
Number = 2,
|
|
Money = 3,
|
|
Date = 4,
|
|
DateTime = 5
|
|
}
|
|
|
|
/// <summary>A column as the screen sees it (from the layout endpoint).</summary>
|
|
public class VirtualGridColumnInfo
|
|
{
|
|
public string Field { get; set; }
|
|
public string Title { get; set; }
|
|
public int Width { get; set; }
|
|
public EnumVirtualGridColumnType Type { get; set; }
|
|
public bool Sortable { get; set; }
|
|
}
|
|
|
|
/// <summary>Everything the screen needs to draw an empty grid before any data is requested.</summary>
|
|
public class VirtualGridLayout
|
|
{
|
|
public string GridKey { get; set; }
|
|
public string Title { get; set; }
|
|
public string DefaultSortField { get; set; }
|
|
public string DefaultSortDir { get; set; }
|
|
public int MaxPageSize { get; set; }
|
|
public List<VirtualGridColumnInfo> Columns { get; set; } = new List<VirtualGridColumnInfo>();
|
|
}
|
|
|
|
/// <summary>One window request: which grid, its filters, and the grid's skip/take, sort and search.</summary>
|
|
public class VirtualGridRequest
|
|
{
|
|
public string GridKey { get; set; }
|
|
|
|
/// <summary>
|
|
/// Screen-specific filters (e.g. fromDate / toDate as "yyyy-MM-dd"). Each grid definition reads and
|
|
/// validates the ones it needs; values are never spliced into SQL.
|
|
/// </summary>
|
|
public Dictionary<string, string> Filters { get; set; } = new Dictionary<string, string>();
|
|
|
|
public int Skip { get; set; }
|
|
public int Take { get; set; } = 100;
|
|
public string Search { get; set; }
|
|
public string SortField { get; set; }
|
|
public string SortDir { get; set; }
|
|
|
|
/// <summary>
|
|
/// True on Preview: reload the data instead of using the copy kept in server memory (list grids).
|
|
/// Scrolling, sorting and searching send false and are answered from that copy.
|
|
/// </summary>
|
|
public bool Refresh { get; set; }
|
|
}
|
|
|
|
/// <summary>Excel export: the same request plus the grid's visible columns, in order.</summary>
|
|
public class VirtualGridExportRequest : VirtualGridRequest
|
|
{
|
|
/// <summary>Fields of the columns to export, in grid order. Empty = every column of the grid.</summary>
|
|
public List<string> Fields { get; set; } = new List<string>();
|
|
}
|
|
|
|
public class VirtualGridPage
|
|
{
|
|
/// <summary>Rows matching the filters and the search.</summary>
|
|
public int Total { get; set; }
|
|
|
|
/// <summary>Rows matching the filters alone (equals Total when there is no search).</summary>
|
|
public int TotalWithoutSearch { get; set; }
|
|
|
|
/// <summary>One row per entry, keyed by column field. Values are raw (dates, numbers); the screen formats them.</summary>
|
|
public List<Dictionary<string, object>> Data { get; set; } = new List<Dictionary<string, object>>();
|
|
}
|
|
|
|
/// <summary>A generated file (Excel export).</summary>
|
|
public class VirtualGridFile
|
|
{
|
|
public string FileName { get; set; }
|
|
public string ContentType { get; set; }
|
|
public byte[] Content { get; set; }
|
|
}
|
|
|
|
/// <summary>The signed-in user, as the grid definitions need it for scoping (payroll type) and access.</summary>
|
|
public class VirtualGridContext
|
|
{
|
|
public int UserID { get; set; }
|
|
public int? EmployeeID { get; set; }
|
|
public int? PayrollTypeID { get; set; }
|
|
public EnumUserType UserType { get; set; }
|
|
}
|
|
|
|
public interface IVirtualGridService
|
|
{
|
|
VirtualGridLayout GetLayout(string gridKey, VirtualGridContext context);
|
|
VirtualGridPage GetPage(VirtualGridRequest request, VirtualGridContext context);
|
|
VirtualGridFile ExportExcel(VirtualGridExportRequest request, VirtualGridContext context);
|
|
}
|
|
}
|