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 ListGenClass { get; set; } = null!; [Parameter] public string SearchVal { get; set; } = ""; [Parameter] public EventCallback EC_Selected { get; set; } #region Protected Fields protected List AllRecords = new List(); protected List ListRecords = new List(); #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 /// /// Clona record /// /// 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 } /// /// impossta record x eliminazione /// /// protected async Task DoDelete(GenClassModel selRec) { if (!await JSRuntime.InvokeAsync("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(); } /// /// Edit articolo selezionato /// /// protected void DoEdit(GenClassModel curRec) { editRecord = curRec; } /// /// Reset selezione /// protected async void DoReset() { editRecord = null; await EC_Selected.InvokeAsync(""); } /// /// Selezione articolo x display info /// /// 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(); } /// /// Filtro e paginazione /// private void UpdateTable() { // fix paginazione ListRecords = AllRecords .Skip(numRecord * (currPage - 1)) .Take(numRecord) .ToList(); isLoading = false; } #endregion Private Methods } }