using EgwCoreLib.Lux.Data.DbModel.Utils; using EgwCoreLib.Lux.Data.Services.Utils; using EgwCoreLib.Razor; namespace Lux.UI.Components.Compo.Generic { public partial class GenValMan { #region Public Properties [Parameter] public List ListGenClass { get; set; } = null!; [Parameter] public FiltSelect SelFilt { get; set; } = null!; #endregion Public Properties #region Public Classes /// /// Filtro selezione items /// public class FiltSelect { #region Public Properties public string SearchVal { get; set; } = ""; public string SelCodGroup { get; set; } = ""; #endregion Public Properties #region Public Methods public override bool Equals(object? obj) { if (obj == null) return false; if (!(obj is FiltSelect item)) return false; if (SelCodGroup != item.SelCodGroup) return false; if (SearchVal != item.SearchVal) return false; return true; } public override int GetHashCode() { return base.GetHashCode(); } #endregion Public Methods } #endregion Public Classes #region Protected Methods protected override async Task OnParametersSetAsync() { if (!SelFilt.Equals(actFilt) || true) { actFilt = SelFilt; await ReloadDataAsync(); UpdateTable(); } } #endregion Protected Methods #region Private Fields private FiltSelect actFilt = new FiltSelect(); private List AllRecords = new List(); private int currPage = 1; private GenValueModel? EditRecord = null; private bool isLoading = false; private List ListRecords = new List(); private int numRecord = 10; private GenValueModel? SelRecord = null; private int totalCount = 0; private BootstrapModal Modal = new(); private string mTitle = ""; private string mMessage = ""; private BootstrapModal.ModalMode mMode = BootstrapModal.ModalMode.ND; private Dictionary modalOpt = new Dictionary(); #endregion Private Fields #region Private Properties [Inject] private IGenValService GVService { get; set; } = null!; [Inject] private IJSRuntime JSRuntime { get; set; } = null!; #endregion Private Properties #region Private Methods private Task DoAdd() { // aggiungo un nuovo record in coda... EditRecord = new GenValueModel() { ClassCod = actFilt.SelCodGroup, ValString = $"Nuovo-{DateTime.Now:yy.MM.ss HH.mm.ss}", Index = totalCount + 1 }; return DoSave(EditRecord); } private async Task DoCancel() { await ResetEdit(); UpdateTable(); } /// /// Clona record /// /// private void DoClone(GenValueModel 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 /// /// private async Task DoDelete(GenValueModel selRec) { mTitle = "Attenzione"; mMessage = "Sicuro di voler eliminare il record?\n" + $"Dettagli: {selRec.ClassCod} | {selRec.ValString}"; mMode = BootstrapModal.ModalMode.Confirm; modalOpt = new(); modalOpt.Add(true, "Si"); modalOpt.Add(false, "No"); if (!await Modal!.ShowAsync()) return; // esegue eliminazione del record... await GVService.DeleteAsync(selRec); EditRecord = null; SelRecord = null; await ReloadDataAsync(); UpdateTable(); } /// /// Edit articolo selezionato /// /// private void DoEdit(GenValueModel curRec) { EditRecord = curRec; } /// /// Reset selezione /// private void DoReset() { EditRecord = null; } private async Task DoSave(GenValueModel currRec) { // salvo await GVService.UpsertAsync(currRec); await ResetEdit(); UpdateTable(); EditRecord = null; SelRecord = null; } /// /// Selezione articolo x display info /// /// private void DoSelect(GenValueModel curRec) { SelRecord = curRec; } /// /// Esegue spostamento /// /// /// /// private async Task MoveRec(GenValueModel curRec, bool moveUp) { await GVService.MoveAsync(curRec, moveUp); await DoCancel(); } private async Task ReloadDataAsync() { isLoading = true; AllRecords = await GVService.GetFiltAsync(actFilt.SelCodGroup); // se ho ricerca testuale faccio filtro ulteriore... if (string.IsNullOrEmpty(actFilt.SearchVal)) { AllRecords = AllRecords .OrderBy(x => x.Index) .ToList(); } else { AllRecords = AllRecords .Where(x => x.ClassCod.Contains(actFilt.SearchVal, StringComparison.InvariantCultureIgnoreCase) || x.ValString.Contains(actFilt.SearchVal, StringComparison.InvariantCultureIgnoreCase)) .OrderBy(x => x.Index) .ToList(); } totalCount = AllRecords.Count; } private Task ResetEdit() { // reset edit EditRecord = null; return ReloadDataAsync(); } private void SaveNumRec(int newNum) { numRecord = newNum; UpdateTable(); } private void SavePage(int newNum) { currPage = newNum; UpdateTable(); } /// /// Filtro e paginazione /// private void UpdateTable() { // fix paginazione ListRecords = AllRecords .Skip(numRecord * (currPage - 1)) .Take(numRecord) .ToList(); isLoading = false; } #endregion Private Methods } }