From fcf3bc84002afc706d157fb411d7b531089a76be Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 27 May 2026 16:20:09 +0200 Subject: [PATCH] Update ricerfa articoli x tipo --- MP.Data/Controllers/MpSpecController.cs | 48 +++++++-- MP.SPEC/Components/ListDossiers.razor.cs | 2 +- MP.SPEC/Components/SelectCodArt.razor.cs | 2 +- MP.SPEC/Data/MpDataService.cs | 9 +- MP.SPEC/Pages/Articoli.razor | 75 ++++++++++---- MP.SPEC/Pages/Articoli.razor.cs | 122 +++++++---------------- 6 files changed, 137 insertions(+), 121 deletions(-) diff --git a/MP.Data/Controllers/MpSpecController.cs b/MP.Data/Controllers/MpSpecController.cs index 9808cc32..969105e9 100644 --- a/MP.Data/Controllers/MpSpecController.cs +++ b/MP.Data/Controllers/MpSpecController.cs @@ -502,25 +502,51 @@ namespace MP.Data.Controllers /// Elenco tabella Articoli da filtro /// /// + /// /// /// /// - public async Task> ArticoliGetSearchAsync(int numRecord, string azienda = "*", string searchVal = "") + public async Task> ArticoliGetSearchAsync(int numRecord, string tipoArt = "*", string azienda = "*", string searchVal = "") { - List dbResult = new List(); - using (var dbCtx = new MoonProContext(options)) + using var dbCtx = new MoonProContext(options); + IQueryable query = dbCtx.DbSetArticoli + .AsNoTracking(); + + // filtro tipo articolo + if (tipoArt != "*") { - dbResult = await dbCtx - .DbSetArticoli - .AsNoTracking() - .Where(x => (azienda == "*" || x.Azienda.ToUpper() == azienda.ToUpper()) && (string.IsNullOrEmpty(searchVal) || x.CodArticolo.Contains(searchVal) || x.DescArticolo.Contains(searchVal) || x.Disegno.Contains(searchVal))) - .OrderBy(x => x.CodArticolo) - .Take(numRecord) - .ToListAsync(); + //query = query.Where(x => x.Tipo.ToLower() == tipoArt.ToLower()); + query = query.Where(x => EF.Functions.Like(x.Tipo, tipoArt)); + } - return dbResult; + // filtro azienda + if (azienda != "*") + { + //query = query.Where(x => x.Azienda.ToLower() == azienda.ToLower()); + query = query.Where(x => EF.Functions.Like(x.Azienda, azienda)); + + } + // filtro ricerca + if (!string.IsNullOrWhiteSpace(searchVal)) + { + //query = query.Where(x => + // x.CodArticolo.Contains(searchVal) || + // x.DescArticolo.Contains(searchVal) || + // x.Disegno.Contains(searchVal)); + string pattern = $"%{searchVal}%"; + query = query.Where(x => + EF.Functions.Like(x.CodArticolo, pattern) || + EF.Functions.Like(x.DescArticolo, pattern) || + EF.Functions.Like(x.Disegno, pattern)); + } + + return await query + .OrderBy(x => x.CodArticolo) + .Take(numRecord) + .ToListAsync(); } + /// /// Elenco tabella Articoli NON IMPIEGATI (da stored stp_ART_getUsed) Async /// diff --git a/MP.SPEC/Components/ListDossiers.razor.cs b/MP.SPEC/Components/ListDossiers.razor.cs index f26032dd..2947870b 100644 --- a/MP.SPEC/Components/ListDossiers.razor.cs +++ b/MP.SPEC/Components/ListDossiers.razor.cs @@ -234,7 +234,7 @@ namespace MP.SPEC.Components ListStati = await MDService.AnagStatiComm(); selAzienda = await MDService.ConfigTryGetAsync("AZIENDA"); giacenzeConf = await MDService.ConfigTryGetAsync("SPEC_ShowGiacenze"); - ListArticoli = await MDService.ArticoliGetSearchAsync(100000, selAzienda, ""); + ListArticoli = await MDService.ArticoliGetSearchAsync(100000, "*", selAzienda, ""); ListMacchine = MDService.MacchineGetFilt("*"); await ReloadData(true); } diff --git a/MP.SPEC/Components/SelectCodArt.razor.cs b/MP.SPEC/Components/SelectCodArt.razor.cs index 29b051aa..36cb41db 100644 --- a/MP.SPEC/Components/SelectCodArt.razor.cs +++ b/MP.SPEC/Components/SelectCodArt.razor.cs @@ -108,7 +108,7 @@ namespace MP.SPEC.Components if (!ListArtDisabled) { Log.Debug("START GetArticoli"); - var rawData = await MDataService.ArticoliGetSearch(10000, "*", searchVal); + var rawData = await MDataService.ArticoliGetSearch(10000, "*", "*", searchVal); // trasformo! if (rawData != null) { diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index 08d03270..5bb2bfd7 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -416,19 +416,18 @@ namespace MP.SPEC.Data /// /// /// - public async Task> ArticoliGetSearchAsync(int numRecord, string azienda, string searchVal) + public async Task> ArticoliGetSearchAsync(int numRecord, string tipoArt, string azienda, string searchVal) { string sKey = string.IsNullOrWhiteSpace(searchVal) ? "***" : searchVal.Trim(); - string memKey = $"ART_SEARCH_MEM:{azienda}:{sKey}:{numRecord}"; - string redisKey = $"{Utils.redisArtList}:{azienda}:{sKey}:{numRecord}"; + string redisKey = $"{Utils.redisArtList}:{tipoArt}:{azienda}:{sKey}:{numRecord}"; return await GetOrFetchAsync( operationName: "ArticoliGetSearchAsync", cacheKey: redisKey, - expiration: TimeSpan.FromMinutes(2), + expiration: TimeSpan.FromMinutes(redisLongTimeCache), fetchFunc: async () => - await dbController.ArticoliGetSearchAsync(numRecord, azienda, searchVal) + await dbController.ArticoliGetSearchAsync(numRecord, tipoArt, azienda, searchVal) ?? new List() ); } diff --git a/MP.SPEC/Pages/Articoli.razor b/MP.SPEC/Pages/Articoli.razor index 4a655d60..6d484868 100644 --- a/MP.SPEC/Pages/Articoli.razor +++ b/MP.SPEC/Pages/Articoli.razor @@ -12,17 +12,31 @@

Articoli

- + @if (CanAdd) + { + + }
+ + - - + + - @if (ListAziende != null) { foreach (var item in ListAziende) @@ -47,11 +61,11 @@
Codice - @if(isNewArt) + @if (isNewArt) { } - else + else { } @@ -83,15 +97,31 @@
Tipo - + @if (ListTipoArt != null) { - + foreach (var item in ListTipoArt) + { + + } } - } - + + } + else + { + + } +
@@ -102,12 +132,12 @@
- +
- +
@@ -154,8 +184,15 @@ { - - + + @if (record.Tipo.Equals("KIT")) + { + + } + else + { + + }
@record.CodArticolo
@@ -171,7 +208,7 @@ @record.Azienda - @if (ArticoloDelEnabled(record.CodArticolo)) + @if (ArticoloDelEnabled(record)) { } @@ -191,7 +228,7 @@
\ No newline at end of file diff --git a/MP.SPEC/Pages/Articoli.razor.cs b/MP.SPEC/Pages/Articoli.razor.cs index ce9bd81e..7e531d58 100644 --- a/MP.SPEC/Pages/Articoli.razor.cs +++ b/MP.SPEC/Pages/Articoli.razor.cs @@ -26,16 +26,6 @@ namespace MP.SPEC.Pages GC.Collect(); } - public async void OnSeachUpdated() - { - await InvokeAsync(() => - { - currPage = 1; - Task task = UpdateData(); - StateHasChanged(); - }); - } - #endregion Public Methods #region Protected Properties @@ -49,10 +39,7 @@ namespace MP.SPEC.Pages [Inject] protected NavigationManager NavManager { get; set; } = null!; - protected string searchCss - { - get => string.IsNullOrEmpty(searchVal) ? "btn-secondary" : "btn-primary"; - } + private string searchCss => string.IsNullOrEmpty(searchVal) ? "btn-secondary" : "btn-primary"; protected string SearchVal { @@ -62,35 +49,12 @@ namespace MP.SPEC.Pages // salvo solo se 3+ chars if (value.Length > 2 || string.IsNullOrEmpty(value)) { - if (searchVal != value) - { - searchVal = value; -#if false - var pUpd = Task.Run(async () => - { - ListRecords = null; - await Task.Delay(1); - await ReloadDataAsync(); - }); - pUpd.Wait(); -#endif - } + searchVal = value; } } } - protected int totalCount - { - get - { - int answ = 0; - if (SearchRecords != null) - { - answ = SearchRecords.Count; - } - return answ; - } - } + protected int totalCount = 0; #endregion Protected Properties @@ -100,30 +64,26 @@ namespace MP.SPEC.Pages /// Crea nuovo record e va in editing... /// /// - protected async Task addNew() + protected void AddNew() { isNewArt = true; currRecord = new AnagArticoliModel() { CodArticolo = $"_NEW_{DateTime.Now:yyyyMMdd.HHmmss}", DescArticolo = "Nuovo articolo", - Azienda = selAzienda != "*" ? selAzienda : "MAPO", + Azienda = !selAzienda.Equals("*") ? selAzienda : "MAPO", Disegno = "", - Tipo = "ART", + Tipo = !selTipoArt.Equals("*") ? selTipoArt : "ART", CurrRev = "", ProdRev = "" }; - await Task.Delay(1); } - protected async Task cancel() - { - currRecord = null; - await ReloadDataAsync(); - await Task.Delay(1); - } - - protected async Task cloneRecord(AnagArticoliModel selRec) + /// + /// Cloning record + /// + /// + protected void cloneRecord(AnagArticoliModel selRec) { isNewArt = true; // creo record duplicato... @@ -138,7 +98,6 @@ namespace MP.SPEC.Pages ProdRev = "" }; currRecord = newRec; - await Task.Delay(1); } /// @@ -184,10 +143,10 @@ namespace MP.SPEC.Pages currRecord = null; } - protected async Task resetSearch() + protected async Task ResetSearch() { SearchVal = ""; - await ReloadDataAsync(); + await ResetDataAsync(); } protected async Task resetSel() @@ -204,19 +163,18 @@ namespace MP.SPEC.Pages await Task.Delay(1); } - protected async Task update(AnagArticoliModel selRec) + protected async Task UpdateAsync(AnagArticoliModel selRec) { if (!await JSRuntime.InvokeAsync("confirm", "Confermi di voler salvare le modifiche?")) return; - await Task.Delay(1); + var done = await MDService.ArticoliUpdateRecord(selRec); - currRecord = null; - await ReloadDataAsync(); - await Task.Delay(1); + await ResetDataAsync(); } - protected async Task UpdateData() + protected async Task ResetDataAsync() { + currPage = 1; currRecord = null; await ReloadDataAsync(); } @@ -239,9 +197,8 @@ namespace MP.SPEC.Pages #region Private Properties - private int _currPage { get; set; } = 1; - private int _numRecord { get; set; } = 10; - private string chkDisabled => isNewArt ? "" : "disabled"; + private int _currPage = 1; + private int _numRecord = 10; private int currPage { @@ -281,26 +238,14 @@ namespace MP.SPEC.Pages if (value != _selAzienda) { _selAzienda = value; -#if false - var pUpd = Task.Run(async () => - { - // svuoto cache redis... - ConfigModel updRec = new ConfigModel() - { - Chiave = "AZIENDA", - Valore = value - }; - MDService.ConfigUpdate(updRec); - await MDService.ConfigResetCache(); - // ricarico - await Task.Delay(1); - await ReloadDataAsync(); - }); - pUpd.Wait(); -#endif } } } + /// + /// Tipo articolo selezionato + /// + private string selTipoArt = "*"; + private async Task ReloadAziendaAsync() { isLoading = true; @@ -313,7 +258,7 @@ namespace MP.SPEC.Pages await MDService.ConfigUpdateAsync(updRec); await MDService.ConfigResetCache(); // ricarico - await ReloadDataAsync(); + await ResetDataAsync(); } @@ -328,9 +273,12 @@ namespace MP.SPEC.Pages /// /// /// - private bool ArticoloDelEnabled(string codArt) + private bool ArticoloDelEnabled(AnagArticoliModel currRec) { - return MDService.ArticoloDelEnabled(codArt); + if (currRec.Tipo.Equals("KIT")) + return false; + + return MDService.ArticoloDelEnabled(currRec.CodArticolo); } private async Task ReloadBaseData() @@ -345,10 +293,16 @@ namespace MP.SPEC.Pages ListTipoArt = await MDService.AnagTipoArtLvAsync(); } + /// + /// Verifica cablata x add tutto tranne KIT + /// + private bool CanAdd => !selTipoArt.Equals("KIT"); + private async Task ReloadDataAsync() { isLoading = true; - SearchRecords = await MDService.ArticoliGetSearchAsync(maxNumRecord, selAzienda, SearchVal); + SearchRecords = await MDService.ArticoliGetSearchAsync(maxNumRecord, selTipoArt, selAzienda, SearchVal); + totalCount = SearchRecords.Count; UpdateTable(); }