using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; using MP.Data.DbModels; using MP.Data.Services; using NLog; namespace MP_TAB3.Components { public partial class ScrapKitMan { #region Public Properties [Parameter] public EventCallback E_Updated { get; set; } [Parameter] public RegistroScartiModel ParentKit { get; set; } = null!; #endregion Public Properties #region Protected Properties [Inject] protected IJSRuntime JSRuntime { get; set; } = null!; protected List ListComplete { get; set; } = new List(); protected List ListPaged { get; set; } = new List(); [Inject] protected TabDataService TabDServ { get; set; } = null!; #endregion Protected Properties #region Protected Methods protected async Task DeleteKitSplit() { if (!await JSRuntime.InvokeAsync("confirm", "Sicuro di voler eliminare il dettaglio del KIT scartato?")) return; if (ParentKit != null) { await TabDServ.RegScartiKitDelete(ParentKit); await ReloadData(); await E_Updated.InvokeAsync(true); } } protected override async Task OnParametersSetAsync() { await ReloadData(); } protected void UpdateTable() { // esegue paginazione if (TotalCount > NumRecPage) { ListPaged = ListComplete.Skip((PageNum - 1) * NumRecPage).Take(NumRecPage).ToList(); } else { ListPaged = ListComplete; } } /// /// Modifica qty del record /// /// /// /// protected async Task modQty(RegistroScartiKitModel currItem, int delta) { currItem.Qta += delta; await TabDServ.RegScartiKitUpdateQty(currItem); } #endregion Protected Methods #region Private Fields private static Logger Log = LogManager.GetCurrentClassLogger(); private bool isProcessing = false; private int NumRecPage = 10; private int PageNum = 1; private int TotalCount = 0; #endregion Private Fields #region Private Methods private async Task ReloadData() { isProcessing = true; await Task.Delay(1); if (ParentKit != null) { ListComplete = await TabDServ.RegScartiKitGetFilt(ParentKit); TotalCount = ListComplete.Count; // esegue paginazione UpdateTable(); } isProcessing = false; await Task.Delay(1); } #endregion Private Methods } }