From a1cf75e0a1eb082cff75720cc3e7820de4ce39f3 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 28 Sep 2023 16:52:01 +0200 Subject: [PATCH] TAB: - Completato riorg codice filtro --- .../MP-TAB.Client/Components/HistTCFilt.razor | 111 ++++++++++++------ .../MP-TAB/Components/Layout/MainLayout.razor | 2 +- MP-TAB/MP-TAB/Components/Layout/NavMenu.razor | 2 +- .../MP-TAB/Components/Pages/TCHistory.razor | 2 +- .../Components/Pages/TCHistory.razor.cs | 90 -------------- .../Controllers/ListSelectController.cs | 28 ++++- MP-TAB/MP-TAB/Program.cs | 2 +- .../{OprFiltData.cs => ListSelectDataSrv.cs} | 81 ++++++------- 8 files changed, 139 insertions(+), 179 deletions(-) delete mode 100644 MP-TAB/MP-TAB/Components/Pages/TCHistory.razor.cs rename MP.Data/Services/{OprFiltData.cs => ListSelectDataSrv.cs} (98%) diff --git a/MP-TAB/MP-TAB.Client/Components/HistTCFilt.razor b/MP-TAB/MP-TAB.Client/Components/HistTCFilt.razor index d6e1da1a..39cb87f3 100644 --- a/MP-TAB/MP-TAB.Client/Components/HistTCFilt.razor +++ b/MP-TAB/MP-TAB.Client/Components/HistTCFilt.razor @@ -4,17 +4,17 @@ @inject HttpClient Http -
+
-
+
- + @if (ListArticoli == null) { @@ -25,10 +25,6 @@ { } - @* @foreach (var item in ListArticoli) - { - - } *@ } @@ -36,19 +32,25 @@
- + + @if (ListMacchineAll == null) + { + + } + else + { + @foreach (var item in ListMacchineAll) + { + + } + }
- - @code { protected override async Task OnParametersSetAsync() @@ -65,12 +67,16 @@ protected async Task ReloadAllData() { - if (!string.IsNullOrEmpty(SearchVal)) + await ReloadArticoli(); + await ReloadMacchine(); + } + protected async Task ReloadArticoli() + { + bool done = false; + if (!ListArtDisabled) { - string ArtApiUrl = $"{BaseAddr}api/ListSelect/GetDictArticoli?SearchArt={SearchVal}"; - // string ArtApiUrl = $"{BaseAddr}api/ListSelect/GetArticoli?SearchArt={SearchVal}"; - // var rawData = await Http.GetFromJsonAsync>(ArtApiUrl); - var rawData = await Http.GetFromJsonAsync>(ArtApiUrl); + string ApiUrl = $"{BaseAddr}api/ListSelect/GetDictArticoli?SearchArt={SearchVal}"; + var rawData = await Http.GetFromJsonAsync>(ApiUrl); if (rawData != null) { ListArticoliAll = rawData; @@ -81,17 +87,28 @@ TotalCount = ListArticoliAll.Count; ListArticoli = ListArticoliAll.Take(Num2Displ).ToDictionary(x => x.Key, x => x.Value); DisplayCount = ListArticoli.Count; - } - else - { - TotalCount = 0; - ListArticoli = new Dictionary(); - DisplayCount = 0; + done = true; + } + } + if (!done) + { + TotalCount = 0; + ListArticoli = new Dictionary(); + DisplayCount = 0; + } + } + protected async Task ReloadMacchine() + { + if (!ListMacDisabled) + { + string ApiUrl = $"{BaseAddr}api/ListSelect/GetDictMacc?MatrOpr={MatrOpr}"; + var rawData = await Http.GetFromJsonAsync>(ApiUrl); + if (rawData != null) + { + ListMacchineAll = rawData; } } - await Task.Delay(1); } - protected bool ListArtDisabled { @@ -120,9 +137,7 @@ { var pUpd = Task.Run(async () => { - // await E_SearchUpd.InvokeAsync(value); - // await Task.Delay(1); - await ReloadAllData(); + await ReloadArticoli(); }); pUpd.Wait(); } @@ -139,14 +154,38 @@ private string searchVal { get; set; } = ""; - protected string CodArtSel { get; set; } = ""; + protected string CodArtSel + { + get => codArtSel; + set + { + if (codArtSel != value) + { + codArtSel = value; + // try + // { + var pUpd = Task.Run(async () => + { + await ReloadMacchine(); + }); + pUpd.Wait(); + // } + // catch (Exception exc) + // { + // Log.Error($"CodArtSel{Environment.NewLine}{exc}"); + // } + } + } + } + protected string IdxMaccSel { get; set; } = ""; + private string codArtSel { get; set; } = ""; + protected Dictionary ListMacchineAll { get; set; } = new Dictionary(); protected Dictionary ListArticoliAll { get; set; } = new Dictionary(); protected Dictionary? ListArticoli { get; set; } = null; - // protected List? ListArticoli { get; set; } = null; [Parameter] @@ -157,12 +196,6 @@ - [Parameter] - public List ListMacchineAll { get; set; } = new List(); - - // [Parameter] - // public List ListArticoliAll { get; set; } = new List(); - [Parameter] public int MatrOpr { get; set; } = 102; [Parameter] diff --git a/MP-TAB/MP-TAB/Components/Layout/MainLayout.razor b/MP-TAB/MP-TAB/Components/Layout/MainLayout.razor index 9c6494c5..e7b4260c 100644 --- a/MP-TAB/MP-TAB/Components/Layout/MainLayout.razor +++ b/MP-TAB/MP-TAB/Components/Layout/MainLayout.razor @@ -1,5 +1,5 @@ @inherits LayoutComponentBase -@inject OprFiltData MDataService +@inject ListSelectDataSrv MDataService
diff --git a/MP-TAB/MP-TAB/Components/Layout/NavMenu.razor b/MP-TAB/MP-TAB/Components/Layout/NavMenu.razor index b4a14c28..ad904f29 100644 --- a/MP-TAB/MP-TAB/Components/Layout/NavMenu.razor +++ b/MP-TAB/MP-TAB/Components/Layout/NavMenu.razor @@ -1,4 +1,4 @@ -@inject OprFiltData MDataService +@inject ListSelectDataSrv MDataService @*
*@ @*
diff --git a/MP-TAB/MP-TAB/Components/Pages/TCHistory.razor b/MP-TAB/MP-TAB/Components/Pages/TCHistory.razor index 58c4144b..057c85d3 100644 --- a/MP-TAB/MP-TAB/Components/Pages/TCHistory.razor +++ b/MP-TAB/MP-TAB/Components/Pages/TCHistory.razor @@ -1,4 +1,4 @@ @page "/tc-history" - + diff --git a/MP-TAB/MP-TAB/Components/Pages/TCHistory.razor.cs b/MP-TAB/MP-TAB/Components/Pages/TCHistory.razor.cs deleted file mode 100644 index a0ea8578..00000000 --- a/MP-TAB/MP-TAB/Components/Pages/TCHistory.razor.cs +++ /dev/null @@ -1,90 +0,0 @@ -using global::System; -using global::System.Collections.Generic; -using global::System.Linq; -using global::System.Threading.Tasks; -using global::Microsoft.AspNetCore.Components; -using System.Net.Http; -using System.Net.Http.Json; -using Microsoft.AspNetCore.Components.Forms; -using Microsoft.AspNetCore.Components.Routing; -using Microsoft.AspNetCore.Components.Sections; -using Microsoft.AspNetCore.Components.Web; -using Microsoft.AspNetCore.Components.Web.Virtualization; -using Microsoft.JSInterop; -using MP.Data; -using MP.Data.DatabaseModels; -using MP.Data.DTO; -using MP.Data.Services; -using MP_TAB; -using MP_TAB.Components; -using static System.Runtime.InteropServices.JavaScript.JSType; - -namespace MP_TAB.Components.Pages -{ - public partial class TCHistory - { - #region Protected Properties - - protected string azienda { get; set; } = "*"; - - protected List? ListMacchine { get; set; } = null; - - /// - /// Matricola operatore corrente (da rendere parametrico con gest operatore) - /// - protected int MatrOpr { get; set; } = 102; - - [Inject] - protected OprFiltData MDataService { get; set; } = null!; - - protected int NumRec { get; set; } = 100000; - protected List SearchArticoli { get; set; } = new List(); - protected string SearchVal { get; set; } = ""; - protected int SrcMinChar { get; set; } = 3; - protected int TotalCount { get; set; } = 0; - - #endregion Protected Properties - - #region Protected Methods - - protected async Task DoSearchUpd(string newSearch) - { - SearchVal = newSearch; - await ReloadFiltData(); - } - - protected override async Task OnInitializedAsync() - { - //await ReloadAllData(); - } - - protected override async Task OnParametersSetAsync() - { - await ReloadAllData(); - // return base.OnParametersSetAsync(); - } - - protected async Task ReloadAllData() - { - await ReloadFiltData(); - TotalCount = SearchArticoli != null ? SearchArticoli.Count : 0; - } - - protected async Task ReloadFiltData() - { - // ricarica SOLO SE ho almeno un filtro valido... - if (!string.IsNullOrEmpty(SearchVal)) - { - SearchArticoli = await MDataService.ArticoliGetSearch(NumRec, azienda, SearchVal); - } - else - { - SearchArticoli = new List(); - } - ListMacchine = await MDataService.MacchineByMatrOper(MatrOpr); - } - - - #endregion Protected Methods - } -} \ No newline at end of file diff --git a/MP-TAB/MP-TAB/Controllers/ListSelectController.cs b/MP-TAB/MP-TAB/Controllers/ListSelectController.cs index 05d88b71..564092f4 100644 --- a/MP-TAB/MP-TAB/Controllers/ListSelectController.cs +++ b/MP-TAB/MP-TAB/Controllers/ListSelectController.cs @@ -15,7 +15,7 @@ namespace MP_TAB.Controllers { #region Public Constructors - public ListSelectController(IConfiguration configuration, OprFiltData DataService) + public ListSelectController(IConfiguration configuration, ListSelectDataSrv DataService) { Log.Info("Starting ListSelectController"); _configuration = configuration; @@ -50,7 +50,6 @@ namespace MP_TAB.Controllers return answ; } - [HttpGet("GetDictArticoli")] public async Task> GetDictArticoli(string SearchArt, string Azienda = "*", int NumRec = 100000) { @@ -67,7 +66,28 @@ namespace MP_TAB.Controllers } catch (Exception exc) { - Log.Error($"Eccezione in GetArticoli | SearchArt: {SearchArt} | Azienda: {Azienda} | NumRec: {NumRec}{Environment.NewLine}{exc}"); + Log.Error($"Eccezione in GetDictArticoli | SearchArt: {SearchArt} | Azienda: {Azienda} | NumRec: {NumRec}{Environment.NewLine}{exc}"); + } + return answ; + } + + [HttpGet("GetDictMacc")] + public async Task> GetDictMacc(int MatrOpr) + { + Dictionary answ = new Dictionary(); + await Task.Delay(1); + try + { + var rawData = await FiltDataServ.MacchineByMatrOper(MatrOpr); + // trasformo! + if (rawData != null) + { + answ = rawData.ToDictionary(x => x.IdxMacchina, x => $"{x.IdxMacchina} | {x.Nome}"); + } + } + catch (Exception exc) + { + Log.Error($"Eccezione in GetDictMacc | MatrOpr: {MatrOpr}{Environment.NewLine}{exc}"); } return answ; } @@ -84,7 +104,7 @@ namespace MP_TAB.Controllers #region Private Properties - private OprFiltData FiltDataServ { get; set; } = null!; + private ListSelectDataSrv FiltDataServ { get; set; } = null!; #endregion Private Properties } diff --git a/MP-TAB/MP-TAB/Program.cs b/MP-TAB/MP-TAB/Program.cs index e453684f..b1fd9e4c 100644 --- a/MP-TAB/MP-TAB/Program.cs +++ b/MP-TAB/MP-TAB/Program.cs @@ -15,7 +15,7 @@ var redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis); // Add services x accesso dati builder.Services.AddSingleton(redisMultiplexer); builder.Services.AddSingleton(); -builder.Services.AddSingleton(); +builder.Services.AddSingleton(); // nuova versione contenuti... builder.Services.AddRazorComponents() diff --git a/MP.Data/Services/OprFiltData.cs b/MP.Data/Services/ListSelectDataSrv.cs similarity index 98% rename from MP.Data/Services/OprFiltData.cs rename to MP.Data/Services/ListSelectDataSrv.cs index 5a06dd15..456b7548 100644 --- a/MP.Data/Services/OprFiltData.cs +++ b/MP.Data/Services/ListSelectDataSrv.cs @@ -18,11 +18,11 @@ namespace MP.Data.Services /// /// Classe accesso dati filtrati per operatore /// - public class OprFiltData : BaseServ, IDisposable + public class ListSelectDataSrv : BaseServ, IDisposable { #region Public Constructors - public OprFiltData(IConfiguration configuration) + public ListSelectDataSrv(IConfiguration configuration) { _configuration = configuration; @@ -55,6 +55,43 @@ namespace MP.Data.Services #region Public Methods + /// + /// Elenco tabella Articoli da filtro + /// + /// Numero record max da recuperare + /// cod azienda, * = tutte + /// Ricerca testuale + /// + public async Task> ArticoliGetSearch(int numRecord, string azienda, string searchVal) + { + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + List? result = new List(); + // cerco in redis... + string currKey = $"{redisBaseKey}:Art:{azienda}:{searchVal}:{numRecord}"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty($"{rawData}")) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + source = "REDIS"; + } + else + { + result = await Task.FromResult(dbController.ArticoliGetSearch(numRecord, azienda, searchVal)); + // serializzp e salvo... + rawData = JsonConvert.SerializeObject(result); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + if (result == null) + { + result = new List(); + } + sw.Stop(); + Log.Debug($"ArticoliGetSearch | azienda: {azienda} | searchVal: {searchVal} | numRecord: {numRecord} | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; + } + public Task> ConfigGetAll() { return Task.FromResult(dbController.ConfigGetAll().ToList()); @@ -101,7 +138,6 @@ namespace MP.Data.Services return result; } - /// /// Elenco Macchine dato operatore secondo gruppi (macchine/operatore) /// @@ -137,45 +173,6 @@ namespace MP.Data.Services return result; } - - - /// - /// Elenco tabella Articoli da filtro - /// - /// Numero record max da recuperare - /// cod azienda, * = tutte - /// Ricerca testuale - /// - public async Task> ArticoliGetSearch(int numRecord, string azienda, string searchVal) - { - string source = "DB"; - Stopwatch sw = new Stopwatch(); - sw.Start(); - List? result = new List(); - // cerco in redis... - string currKey = $"{redisBaseKey}:Art:{azienda}:{searchVal}:{numRecord}"; - RedisValue rawData = await redisDb.StringGetAsync(currKey); - if (!string.IsNullOrEmpty($"{rawData}")) - { - result = JsonConvert.DeserializeObject>($"{rawData}"); - source = "REDIS"; - } - else - { - result = await Task.FromResult(dbController.ArticoliGetSearch(numRecord, azienda, searchVal)); - // serializzp e salvo... - rawData = JsonConvert.SerializeObject(result); - await redisDb.StringSetAsync(currKey, rawData, LongCache); - } - if (result == null) - { - result = new List(); - } - sw.Stop(); - Log.Debug($"ArticoliGetSearch | azienda: {azienda} | searchVal: {searchVal} | numRecord: {numRecord} | {source} | {sw.Elapsed.TotalMilliseconds}ms"); - return result; - } - #endregion Public Methods #region Protected Fields