Files
lux/Lux.UI/Components/Compo/Templates/TemplateList.razor.cs
T
2026-03-05 19:41:24 +01:00

204 lines
6.2 KiB
C#

using EgwCoreLib.Lux.Core;
using EgwCoreLib.Lux.Data.DbModel.Sales;
using EgwCoreLib.Lux.Data.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
namespace Lux.UI.Components.Compo.Templates
{
public partial class TemplateList
{
#region Public Properties
/// <summary>
/// Ricerca libera da parent
/// </summary>
[Parameter]
public string CurrSearchVal { get; set; } = "";
/// <summary>
/// Callback invocato al select
/// </summary>
[Parameter]
public EventCallback<TemplateModel?> EC_Selected { get; set; }
#endregion Public Properties
#region Protected Methods
protected override async Task OnParametersSetAsync()
{
await ReloadData();
UpdateTable();
}
#endregion Protected Methods
#region Private Fields
private List<TemplateModel> AllRecords = new List<TemplateModel>();
private EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS CurrEnvir = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW;
private int currPage = 1;
private Enums.ItemSourceType CurrSourceType = Enums.ItemSourceType.Jwd;
private TemplateModel? EditRecord = null;
private bool isLoading = false;
private List<TemplateModel> ListFilt = new List<TemplateModel>();
private List<TemplateModel> ListRecords = new List<TemplateModel>();
private int numRecord = 10;
private TemplateModel? SelRecord = null;
private int totalCount = 0;
#endregion Private Fields
#region Private Properties
/// <summary>
/// Servizi di accesso ai dati iniettati dal framework.
/// </summary>
[Inject]
private DataLayerServices DLService { get; set; } = null!;
[Inject]
private IJSRuntime JSRuntime { get; set; } = null!;
#endregion Private Properties
#region Private Methods
private string CheckSelect(TemplateModel curRec)
{
string answ = "";
if (SelRecord != null)
{
answ = curRec.TemplateID == SelRecord.TemplateID ? "table-info" : "";
}
return answ;
}
private void DoAdd()
{
DateTime adesso = DateTime.Now;
EditRecord = new TemplateModel()
{
Name = $"New Template {adesso.Year}",
Description = $"Nuovo Template {adesso:ddd yyyy.MM.dd HH:mm:ss}",
Envir = CurrEnvir,
SourceType = CurrSourceType
};
}
private async Task DoClone(TemplateModel rec2clone)
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Confermi di voler duplicare interamente il Gruppo Template selezionato?{Environment.NewLine}---------------------------{Environment.NewLine}Env: {rec2clone.Envir} | {rec2clone.Name}{Environment.NewLine}{rec2clone.Description}{Environment.NewLine}Articoli: {rec2clone.NumItems}"))
return;
// clona intera offerta + tutte le righe...
rec2clone.Name += " - clone";
rec2clone.Description += $" - cloned {DateTime.Now:yyyy.MM.dd HH:mm:ss}";
await DLService.TemplateCloneAsync(rec2clone);
await ReloadData();
UpdateTable();
}
private void DoClose()
{
SelRecord = null;
EditRecord = null;
}
private async Task DoDelete(TemplateModel curRec)
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Confermi di voler eliminare il Gruppo Template selezionato?{Environment.NewLine}---------------------------{Environment.NewLine}Env: {curRec.Envir} | {curRec.Name}{Environment.NewLine}{curRec.Description}{Environment.NewLine}Articoli: {curRec.NumItems}"))
return;
// clona intera offerta + tutte le righe...
await DLService.TemplateDeleteAsync(curRec);
await ReloadData();
UpdateTable();
}
private async Task DoEdit(TemplateModel curRec)
{
SelRecord = null;
await EC_Selected.InvokeAsync(null);
EditRecord = curRec;
}
private async Task DoReset()
{
EditRecord = null;
SelRecord = null;
await ReloadData();
UpdateTable();
await EC_Selected.InvokeAsync(null);
}
/// <summary>
/// Salva record ed avanza compilazione
/// </summary>
/// <param name="updRec"></param>
/// <returns></returns>
private async Task DoSave(TemplateModel updRec)
{
// salvo record
await DLService.TemplateUpsertAsync(updRec);
EditRecord = null;
SelRecord = null;
await ReloadData();
UpdateTable();
}
private Task DoSelect(TemplateModel curRec)
{
SelRecord = curRec;
return EC_Selected.InvokeAsync(curRec);
}
private async Task ReloadData()
{
AllRecords = await DLService.TemplateGetAllAsync();
}
private void SaveNumRec(int newNum)
{
numRecord = newNum;
UpdateTable();
}
private void SavePage(int newNum)
{
currPage = newNum;
UpdateTable();
}
private void UpdateTable()
{
//ListFilt.Clear();
ListFilt = AllRecords;
if (!string.IsNullOrEmpty(CurrSearchVal))
{
ListFilt = AllRecords
.Where(x => x.Name.Contains(CurrSearchVal, StringComparison.InvariantCultureIgnoreCase) || x.Description.Contains(CurrSearchVal, StringComparison.InvariantCultureIgnoreCase))
.ToList();
}
totalCount = ListFilt.Count;
// gestione paginazione
ListRecords = ListFilt
.Skip(numRecord * (currPage - 1))
.Take(numRecord)
.ToList();
}
#endregion Private Methods
}
}