Files
StockMan/StockMan.CORE/Components/ItemList.razor.cs
T
2023-02-13 17:07:52 +01:00

114 lines
3.0 KiB
C#

using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using StockMan.CORE.Data;
using StockMan.Data.DbModels;
namespace StockMan.CORE.Components
{
public partial class ItemList : IDisposable
{
[Parameter]
public EventCallback<int> updateRecordCount { get; set; }
//[Parameter]
//public int NumRecord { get; set; } = 10;
//[Parameter]
//public int CurrPage { get; set; } = 1;
[Parameter]
public ItemSelectFilter actFilter { get; set; } = new ItemSelectFilter();
[Inject]
protected StockDataService SDService { get; set; } = null!;
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
[Inject]
protected NavigationManager NavManager { get; set; } = null!;
public List<ItemModel>? ListRecord { get; set; } = null;
public List<ItemModel>? SearchRecords { get; set; } = null;
//protected override async Task OnInitializedAsync()
//{
// //ListRecord = await SDService.ItemFamilyGetAll();
//}
protected override async Task OnParametersSetAsync()
{
//lastFilter = actFilter.clone();
await reloadData();
}
private int currPage
{
get => actFilter.CurrPage;
set => actFilter.CurrPage = value;
}
private int numRecord
{
get => actFilter.NumRec;
set => actFilter.NumRec = value;
}
public void Dispose()
{
SearchRecords = null;
ListRecord = null;
GC.Collect();
}
private int _totalCount { get; set; } = 0;
private int totalCount
{
get => _totalCount;
set
{
if (_totalCount != value)
{
_totalCount = value;
updateRecordCount.InvokeAsync(value);
}
}
}
[Inject]
private IConfiguration Configuration { get; set; } = null!;
protected bool isLoading = false;
private async Task reloadData()
{
isLoading = true;
SearchRecords = await SDService.ItemsGetAll();
totalCount = SearchRecords.Count;
ListRecord = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
await Task.Delay(1);
await InvokeAsync(() => StateHasChanged());
isLoading = false;
}
private void selItemToDet(int selItem)
{
currItem = selItem;
NavManager.NavigateTo(rawCode, true);
}
protected int? _currItem;
protected int? currItem
{
get=> _currItem;
set=> _currItem = value;
}
protected string rawCode
{
get
{
string answ = "";
answ = $"itemDetail?ItemID={currItem}";
return answ;
}
}
}
}