Files
lux/Lux.UI/Components/Pages/Items.razor.cs
T
2025-08-08 19:19:30 +02:00

154 lines
4.1 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>();
protected string searchVal = "";
protected string? SelCodGroup = null;
protected EgwCoreLib.Lux.Core.Enums.ItemClassType? SelType = null;
#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
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 ItemModel? SelRecord = null;
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.ItemGetSearchAsync(searchVal);
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
}
}