158 lines
8.5 KiB
C#
158 lines
8.5 KiB
C#
using System;
|
|
using System.Resources;
|
|
using Kreta.Enums.ManualEnums;
|
|
|
|
namespace Kreta.Core.CustomAttributes
|
|
{
|
|
/// <summary>
|
|
/// Model, Co vagy egyéb objektumok property-jéhez használható attribute, ami egy excel export egy oszlopát definiálja.
|
|
/// </summary>
|
|
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
|
|
public class SimpleExportColumnAttribute : Attribute
|
|
{
|
|
#region Fields
|
|
|
|
private string _columnHeaderName;
|
|
|
|
private string _dropDownColumnSourceSheetGroupName;
|
|
|
|
#endregion Fields
|
|
|
|
#region Properties
|
|
|
|
/// <summary>
|
|
/// Az attribute egyedi "azonosítója".
|
|
/// Ez azért kell, hogyha egy property-t, akár több export-hoz használunk, akkor egyértelműen be tudjuk azonosítani.
|
|
/// Javaslat, hogy erre legyen egy kivezett konstans, aminek nameof()-al adunk értéket, hogy ha át akaruk nevezni, akkor ne egy string-et kelljen.
|
|
/// Pl.: public const string ExportPropertyId = nameof(ExportPropertyId);
|
|
/// Használat: ExportPropertyId
|
|
/// </summary>
|
|
public string AttributeId { get; }
|
|
|
|
/// <summary>
|
|
/// Az oszlop indexe az excelben, ahová export-áljuk.
|
|
/// 0-tól indexelünk!
|
|
/// Használat: 00 vagy 12 vagy stb...
|
|
/// </summary>
|
|
public int Index { get; }
|
|
|
|
/// <summary>
|
|
/// Az oszlop header-jének a neve, azaz ami az első sorba fog kerülni export-áláskor a tényleges adatok felett.
|
|
/// Használat: nameof(ImportExportEszkozResource.ImportHeaderNameMennyiseg)
|
|
/// </summary>
|
|
public string HeaderName
|
|
{
|
|
get => new ResourceManager(HeaderNameResourceType).GetString(_columnHeaderName);
|
|
|
|
set => _columnHeaderName = value;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Az oszlop header-jének a Resource típusa, hogy honnan szedjük elő a header-nek a nevét.
|
|
/// Használat: typeof(ImportExportEszkozResource)
|
|
/// </summary>
|
|
public Type HeaderNameResourceType { get; }
|
|
|
|
/// <summary>
|
|
/// Ha megadjuk, akkor az oszlophoz tartozó lenyíló lista adatforrásának sheet neve lesz.
|
|
/// Ezt akkor kell használni, ha több lenyíló listának kell használni egy sheet-et adatforrásként. Pl.: Állampolgárság/Állampolgárság2
|
|
/// FONTOS: Ha ennek értéket adtunk, akkor kötelező a DropDownColumnSourceSheetGroupNameResourceType-nak is értéket adni!
|
|
/// Használat: nameof(ImportExportEszkozResource.ImportHeaderNameMennyiseg)
|
|
/// </summary>
|
|
public string DropDownColumnSourceSheetGroupName
|
|
{
|
|
get => !string.IsNullOrWhiteSpace(_dropDownColumnSourceSheetGroupName) ? new ResourceManager(DropDownColumnSourceSheetGroupNameResourceType).GetString(_dropDownColumnSourceSheetGroupName) : null;
|
|
set => _dropDownColumnSourceSheetGroupName = value;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ha megadjuk, akkor az oszlop header-jének a Resource típusa, hogy honnan szedjük elő az oszlophoz tartozó lenyíló lista adatforrásának sheet nevét.
|
|
/// FONTOS: Ha ennek értéket adtunk, akkor kötelező a DropDownColumnSourceSheetGroupName-nak is értéket adni!
|
|
/// Használat: typeof(ImportExportEszkozResource)
|
|
/// </summary>
|
|
public Type DropDownColumnSourceSheetGroupNameResourceType { get; }
|
|
|
|
/// <summary>
|
|
/// Ha megadjuk, akkor az oszlophoz generál egy aggregált értéket az oszlop értékeiből az utolsó sor után.
|
|
/// FONTOS: AGGREGATE function is designed vertical ranges, not horizontal ranges.
|
|
/// https://support.microsoft.com/en-us/office/aggregate-function-43b9278e-6aa7-4f17-92b6-e19993fa26df
|
|
/// Default értéke: ExcelAggregateFunctionEnum.NONE és így nem lesz figyelembe véve.
|
|
/// Használat: AggregateFunction = ExcelAggregateFunctionEnum.SUM
|
|
/// </summary>
|
|
public ExcelAggregateFunctionEnum AggregateFunction { get; set; } = ExcelAggregateFunctionEnum.NONE;
|
|
|
|
/// <summary>
|
|
/// Ha az oszlop bool típusú, akkor annak a megjelenítéséhez használható paraméter.
|
|
/// Default értéke: BooleanDisplayFormatEnum.Teljes(azaz Igen/Nem fog megjelenni)
|
|
/// Használat: BooleanDisplayFormat = BooleanDisplayFormatEnum.IN
|
|
/// </summary>
|
|
public BooleanDisplayFormatEnum BooleanDisplayFormat { get; set; } = BooleanDisplayFormatEnum.Teljes;
|
|
|
|
/// <summary>
|
|
/// Ha az oszlop DateTime típusú, akkor annak a formázáshoz használható paraméter.
|
|
/// Default értéke: Kreta.Core.Constants.ToStringPattern.HungarianDate
|
|
/// Használat: DateTimeToStringPattern = Constants.ToStringPattern.HungarianDateTimeWithoutSeconds
|
|
/// </summary>
|
|
public string DateTimeToStringPattern { get; set; } = Constants.ToStringPattern.HungarianDate;
|
|
|
|
/// <summary>
|
|
/// Ha az oszlop decimal/decimal?/double/double? típusú, akkor az excel-ben megjelenő tizedesjegyek számának meghatározásához használható paraméter.
|
|
/// Default értéke: 2
|
|
/// Használat: DecimalDigitCount = 0
|
|
/// </summary>
|
|
public int DecimalDigitCount { get; set; } = 2;
|
|
|
|
/// <summary>
|
|
/// Force-olhatunk egy oszlopot, hogy az excel-ben milyen típusént viselkedjen, az eredeti típusához képest.
|
|
/// Erre példa, hogyha egy van egy string mezőnk, de mi szeretnénk, hogy bool-ként viselkedjen és az oszlophoz tartozzon egy bool lenyíló lista.
|
|
/// Ezzel óvatosan kell bánni, mert ha nagyon eltér az excel-ben a mező értéke és a típusa az hibát okozhat vagy rosszul jelenhet meg.
|
|
/// Pl.: DateTime int-ként nem dátum formátumú lesz, hanem a az adot dátum-ból csinál egy int-et az excel(2020.08.01. -> 44044).
|
|
/// Használat: ForcedType = typeof(int)
|
|
/// </summary>
|
|
public Type ForcedType { get; set; } = null;
|
|
|
|
/// <summary>
|
|
/// Ez alapján dől el, hogy a szöveget a cellában HTML-ként, vagy sima szövegként fogja megjeleníteni.
|
|
/// Default értéke: false
|
|
/// Használat: AsHtml = true
|
|
/// </summary>
|
|
public bool AsHtml { get; set; } = false;
|
|
|
|
#endregion Properties
|
|
|
|
#region Constructors
|
|
|
|
/// <summary>
|
|
/// Model, Co vagy egyéb objektumok property-jéhez használható attribute, ami egy excel export egy oszlopát definiálja.
|
|
/// </summary>
|
|
/// <param name="attributeId">Az attribute egyedi "azonosítója".</param>
|
|
/// <param name="index">Az oszlop indexe az excelben, ahová export-áljuk.</param>
|
|
/// <param name="headerName">Az oszlop header-jének a neve, azaz ami az első sorba fog kerülni export-áláskor a tényleges adatok felett.</param>
|
|
/// <param name="headerNameResourceType">Az oszlop header-jének a Resource típusa, hogy honnan szedjük elő a header-nek a nevét.</param>
|
|
/// <param name="dropDownColumnSourceSheetGroupName">Ha megadjuk, akkor az oszlophoz tartozó lenyíló lista adatforrásának sheet neve lesz.</param>
|
|
/// <param name="dropDownColumnSourceSheetGroupNameResourceType">Ha megadjuk, akkor az oszlop header-jének a Resource típusa, hogy honnan szedjük elő az oszlophoz tartozó lenyíló lista adatforrásának sheet nevét.</param>
|
|
public SimpleExportColumnAttribute(
|
|
string attributeId,
|
|
int index,
|
|
string headerName,
|
|
Type headerNameResourceType,
|
|
string dropDownColumnSourceSheetGroupName = null,
|
|
Type dropDownColumnSourceSheetGroupNameResourceType = null)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(dropDownColumnSourceSheetGroupName) && dropDownColumnSourceSheetGroupNameResourceType != null ||
|
|
!string.IsNullOrWhiteSpace(dropDownColumnSourceSheetGroupName) && dropDownColumnSourceSheetGroupNameResourceType == null)
|
|
{
|
|
throw new ArgumentException($"Ha bármelyiknek a kettőből érték lett adva, akkor kötelező a másiknak is: {nameof(dropDownColumnSourceSheetGroupName)}, {nameof(dropDownColumnSourceSheetGroupNameResourceType)}");
|
|
}
|
|
|
|
AttributeId = attributeId;
|
|
Index = index;
|
|
HeaderName = headerName;
|
|
HeaderNameResourceType = headerNameResourceType;
|
|
DropDownColumnSourceSheetGroupName = dropDownColumnSourceSheetGroupName;
|
|
DropDownColumnSourceSheetGroupNameResourceType = dropDownColumnSourceSheetGroupNameResourceType;
|
|
}
|
|
|
|
#endregion Constructors
|
|
}
|
|
}
|