Files
lux/Lux.UI/Components/Compo/GenClassMan.razor.cs
T
2025-09-18 13:08:45 +02:00

205 lines
5.6 KiB
C#

using EgwCoreLib.Lux.Data.DbModel;
using EgwCoreLib.Lux.Data.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using NLog.LayoutRenderers;
namespace Lux.UI.Components.Compo
{
public partial class GenClassMan
{
[Parameter]
public List<GenClassModel> ListGenClass { get; set; } = null!;
[Parameter]
public string SearchVal { get; set; } = "";
[Parameter]
public EventCallback<string> EC_Selected { get; set; }
#region Protected Fields
protected List<GenClassModel> AllRecords = new List<GenClassModel>();
protected List<GenClassModel> ListRecords = new List<GenClassModel>();
#endregion Protected Fields
#region Protected Properties
[Inject]
protected DataLayerServices DLService { get; set; } = null!;
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
/// <summary>
/// Clona record
/// </summary>
/// <param name="curRec"></param>
protected void DoClone(GenClassModel curRec)
{
#if false
editRecord = new ItemModel()
{
ItemIDParent = curRec.ItemType == Enums.ItemClassType.Bom ? curRec.ItemID : curRec.ItemIDParent,
CodGroup = curRec.CodGroup,
ItemType = curRec.ItemType == Enums.ItemClassType.Bom ? Enums.ItemClassType.BomAlt : curRec.ItemType,
IsService = curRec.IsService,
ItemCode = curRec.ItemCode,
ExtItemCode = $"{curRec.ExtItemCode} - COPY",
SupplCode = curRec.ItemType == Enums.ItemClassType.Bom ? $"{curRec.SupplCode} ALT" : curRec.SupplCode,
Description = $"{curRec.Description} - COPY",
Cost = curRec.Cost,
Margin = curRec.Margin,
QtyMin = curRec.QtyMin,
QtyMax = curRec.QtyMax,
UM = curRec.UM
};
#endif
}
/// <summary>
/// impossta record x eliminazione
/// </summary>
/// <param name="selRec"></param>
protected async Task DoDelete(GenClassModel selRec)
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Sicuro di voler eliminare il record? Dettagli: {selRec.ClassCod} | {selRec.Description}"))
return;
//// esegue eliminazione del record...
//await DLService.ItemDeleteAsync(selRec);
editRecord = null;
selRecord = null;
ReloadData();
UpdateTable();
}
/// <summary>
/// Edit articolo selezionato
/// </summary>
/// <param name="curRec"></param>
protected void DoEdit(GenClassModel curRec)
{
editRecord = curRec;
}
/// <summary>
/// Reset selezione
/// </summary>
protected async void DoReset()
{
editRecord = null;
await EC_Selected.InvokeAsync("");
}
/// <summary>
/// Selezione articolo x display info
/// </summary>
/// <param name="curRec"></param>
protected async void DoSelect(GenClassModel curRec)
{
selRecord = curRec;
await EC_Selected.InvokeAsync(curRec.ClassCod);
}
protected override void OnParametersSet()
{
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 int currPage = 1;
private GenClassModel? editRecord = null;
private bool isLoading = false;
private int numRecord = 10;
private GenClassModel? selRecord = null;
private int totalCount = 0;
#endregion Private Fields
#region Private Methods
private void DoCancel()
{
ResetEdit();
UpdateTable();
}
private async Task DoSave(GenClassModel currRec)
{
// salvo
await Task.Delay(10);
#if false
await DLService.ItemUpsertAsync(currRec);
#endif
ResetEdit();
UpdateTable();
}
private void ReloadData()
{
isLoading = true;
AllRecords = ListGenClass;
// se ho ricerca testuale faccio filtro ulteriore...
if (!string.IsNullOrEmpty(SearchVal))
{
AllRecords = AllRecords
.Where(x =>
x.ClassCod.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase) ||
x.Description.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase))
.ToList();
}
totalCount = AllRecords.Count;
}
private void ResetEdit()
{
// reset edit
editRecord = null;
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
}
}