Files
lux/Lux.UI/Components/Pages/Items.razor.cs
T
samuele cf0d4e2aed Update pag articoli
- fix ricerca
- fix cache REDIS
- filtro search in pagina(RAM)
2025-08-09 10:04:46 +02:00

218 lines
6.2 KiB
C#

using EgwCoreLib.Lux.Data.DbModel;
using EgwCoreLib.Lux.Data.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
namespace Lux.UI.Components.Pages
{
public partial class Items
{
#region Protected Fields
protected List<ItemModel> AllRecords = new List<ItemModel>();
protected List<ItemGroupModel> ListItemGroup = new List<ItemGroupModel>();
protected List<ItemModel> ListRecords = new List<ItemModel>();
#endregion Protected Fields
#region Protected Properties
[Inject]
protected DataLayerServices DLService { get; set; } = null!;
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
protected string SearchVal
{
get => searchVal;
set
{
if (searchVal != value)
{
searchVal = value;
currPage = 1;
var pUpd = Task.Run(async () =>
{
await ReloadData();
UpdateTable();
});
pUpd.Wait();
}
}
}
protected string SelCodGroup
{
get => selCodGroup;
set
{
if (selCodGroup != value)
{
selCodGroup = value;
currPage = 1;
var pUpd = Task.Run(async () =>
{
await ReloadData();
UpdateTable();
});
pUpd.Wait();
}
}
}
protected EgwCoreLib.Lux.Core.Enums.ItemClassType SelType
{
get => selType;
set
{
if (selType != value)
{
selType = value;
currPage = 1;
var pUpd = Task.Run(async () =>
{
await ReloadData();
UpdateTable();
});
pUpd.Wait();
}
}
}
#endregion Protected Properties
#region Protected Methods
protected void DoAdd()
{
EditRecord = new ItemModel()
{
CodGroup = ListItemGroup.FirstOrDefault()?.CodGroup ?? "",
ItemType = EgwCoreLib.Lux.Core.Enums.ItemClassType.ND,
IsService = false,
ItemCode = 0,
ExtItemCode = "NEW-ITEM",
SupplCode = "",
Description = $"Nuova Offerta {DateTime.Today:ddd yyyy.MM.dd}",
Cost = 0,
Margin = 0,
QtyMin = 0,
QtyMax = 0,
UM = "#"
};
}
/// <summary>
/// impossta record x eliminazione
/// </summary>
/// <param name="selRec"></param>
protected async Task DoDelete(ItemModel selRec)
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Sicuro di voler eliminare il record? Dettagli: {selRec.ItemID} | {selRec.CodGroup} | {selRec.ItemType} | {selRec.ExtItemCode}"))
return;
//// esegue eliminazione del record...
//await DLService.ItemDeleteAsync(selRec);
EditRecord = null;
SelRecord = null;
await ReloadData();
UpdateTable();
}
protected void DoEdit(ItemModel curRec)
{
EditRecord = curRec;
}
protected void DoReset()
{
EditRecord = null;
}
protected void DoSelect(ItemModel curRec)
{
SelRecord = curRec;
}
protected override async Task OnInitializedAsync()
{
isLoading = true;
await ReloadBaseData();
await ReloadData();
UpdateTable();
}
protected void ResetSearch()
{
SearchVal = "";
}
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 ItemModel? EditRecord = null;
private bool isLoading = false;
private int numRecord = 10;
private string searchVal = "";
private string selCodGroup = "";
private ItemModel? SelRecord = null;
private EgwCoreLib.Lux.Core.Enums.ItemClassType selType = EgwCoreLib.Lux.Core.Enums.ItemClassType.ND;
private int totalCount = 0;
#endregion Private Fields
#region Private Methods
private async Task ReloadBaseData()
{
ListItemGroup = await DLService.ItemGroupGetAllAsync();
}
private async Task ReloadData()
{
isLoading = true;
AllRecords = await DLService.ItemGetFiltAsync(SelCodGroup, SelType);
// se ho ricerca testuale faccio filtro ulteriore...
if (!string.IsNullOrEmpty(SearchVal))
{
AllRecords = AllRecords
.Where(x =>
x.Description.Contains(searchVal, StringComparison.InvariantCultureIgnoreCase) ||
x.ExtItemCode.Contains(searchVal, StringComparison.InvariantCultureIgnoreCase) ||
x.SupplCode.Contains(searchVal, StringComparison.InvariantCultureIgnoreCase))
.ToList();
}
totalCount = AllRecords.Count;
}
/// <summary>
/// Filtro e paginazione
/// </summary>
private void UpdateTable()
{
// fix paginazione
ListRecords = AllRecords
.Skip(numRecord * (currPage - 1))
.Take(numRecord)
.ToList();
isLoading = false;
}
#endregion Private Methods
}
}