175 lines
4.8 KiB
C#
175 lines
4.8 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using EgwCoreLib.Lux.Data.DbModel.Config;
|
|
using EgwCoreLib.Lux.Data.Services;
|
|
|
|
namespace Lux.UI.Components.Compo
|
|
{
|
|
public partial class ConfGlassMan
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public string SearchVal { get; set; } = string.Empty;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected DataLayerServices DLService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// impossta record x eliminazione
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
protected async Task DoDelete(GlassModel selRec)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Sicuro di voler eliminare il record? Dettagli: {selRec.GlassID} | {selRec.Description} | {selRec.Thickness}"))
|
|
return;
|
|
|
|
// esegue eliminazione del record...
|
|
await DLService.ConfGlassDeleteAsync(selRec);
|
|
|
|
EditRecord = null;
|
|
SelRecord = null;
|
|
await ReloadData();
|
|
UpdateTable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Edit articolo selezionato
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
protected void DoEdit(GlassModel curRec)
|
|
{
|
|
EditRecord = curRec;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset selezione
|
|
/// </summary>
|
|
protected void DoReset()
|
|
{
|
|
EditRecord = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Selezione articolo x display info
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
protected void DoSelect(GlassModel curRec)
|
|
{
|
|
SelRecord = curRec;
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await ReloadData();
|
|
UpdateTable();
|
|
}
|
|
|
|
protected void SaveNumRec(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
UpdateTable();
|
|
}
|
|
|
|
protected void SavePage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
UpdateTable();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private List<GlassModel> AllRecords = new();
|
|
private int currPage = 1;
|
|
private GlassModel? EditRecord = null;
|
|
private bool isLoading = false;
|
|
private List<GlassModel> ListRecords = new();
|
|
private int numRecord = 10;
|
|
private GlassModel? SelRecord = null;
|
|
private int totalCount = 0;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Methods
|
|
|
|
private async Task DoAdd()
|
|
{
|
|
// aggiungo un nuovo record in coda...
|
|
EditRecord = new GlassModel()
|
|
{
|
|
Description = "New Glass",
|
|
Code = "",
|
|
Thickness = 30
|
|
};
|
|
await DoSave(EditRecord);
|
|
}
|
|
|
|
private async Task DoSave(GlassModel currRec)
|
|
{
|
|
// salvo
|
|
await DLService.ConfGlassUpsertAsync(currRec);
|
|
await ResetEdit();
|
|
UpdateTable();
|
|
EditRecord = null;
|
|
SelRecord = null;
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
isLoading = true;
|
|
AllRecords = await DLService.ConfGlassGetAllAsync();
|
|
// se ho ricerca testuale faccio filtro ulteriore...
|
|
if (string.IsNullOrEmpty(SearchVal))
|
|
{
|
|
AllRecords = AllRecords
|
|
.OrderBy(x => x.Description)
|
|
.ToList();
|
|
}
|
|
else
|
|
{
|
|
AllRecords = AllRecords
|
|
.Where(x =>
|
|
x.Description.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase) ||
|
|
x.Code.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase))
|
|
.OrderBy(x => x.Description)
|
|
.ToList();
|
|
}
|
|
totalCount = AllRecords.Count;
|
|
}
|
|
|
|
private async Task ResetEdit()
|
|
{
|
|
// reset edit
|
|
EditRecord = null;
|
|
await ReloadData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Filtro e paginazione
|
|
/// </summary>
|
|
private void UpdateTable()
|
|
{
|
|
// fix paginazione
|
|
ListRecords = AllRecords
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
isLoading = false;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |