From 003f8792c418d5f87e41042bd393fbf4e78fc07b Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 26 Feb 2026 18:35:53 +0100 Subject: [PATCH] Code reorg-cleanup --- GWMS.UI/Components/OrderAdminEditor.razor.cs | 140 +++++++++++-------- GWMS.UI/Data/GWMSDataService.cs | 51 +++---- 2 files changed, 109 insertions(+), 82 deletions(-) diff --git a/GWMS.UI/Components/OrderAdminEditor.razor.cs b/GWMS.UI/Components/OrderAdminEditor.razor.cs index 16a57cb..e82f72f 100644 --- a/GWMS.UI/Components/OrderAdminEditor.razor.cs +++ b/GWMS.UI/Components/OrderAdminEditor.razor.cs @@ -10,12 +10,7 @@ namespace GWMS.UI.Components { public partial class OrderAdminEditor { - - private List suppList; - private List transpList; - - protected OrderModel _currItem = new OrderModel(); - protected int _supplierId { get; set; } = 0; + #region Public Properties [Parameter] public OrderModel currItem @@ -30,10 +25,9 @@ namespace GWMS.UI.Components } } - private bool editAll { get; set; } = false; - [Parameter] public EventCallback DataReset { get; set; } + [Parameter] public EventCallback DataUpdated { get; set; } @@ -53,28 +47,83 @@ namespace GWMS.UI.Components } } + #endregion Public Properties + + #region Protected Fields + + protected OrderModel _currItem = new OrderModel(); + + #endregion Protected Fields + + #region Protected Properties + + protected int _supplierId { get; set; } = 0; [Inject] protected MessageService MServ { get; set; } = null; - - private async Task saveUpdate() + protected string rawCode { - if (_currItem != null) + get { - using var activity = StartTracing("SaveUpdate"); - await DataService.OrderUpdate(_currItem); - activity?.SetTag("order.code", _currItem.OrderCode); - activity?.SetTag("order.operator", MServ.UserName); - activity?.SetTag("order.quantity_req", _currItem.OrderQty); - await DataUpdated.InvokeAsync(1); - } - else - { - Console.WriteLine("Order null!"); + string answ = ""; + if (_currItem != null) + { + answ = _currItem.OrderCode; + } + return answ; } } + #endregion Protected Properties + + #region Protected Methods + + // Blazor: get query parm from the URL + protected string GetQueryParm(string parmName) + { + var uriBuilder = new UriBuilder(NavManager.Uri); + var q = System.Web.HttpUtility.ParseQueryString(uriBuilder.Query); + return q[parmName] ?? ""; + } + + protected override async Task OnInitializedAsync() + { + await ReloadAllData(); + await JSRuntime.InvokeVoidAsync("displayQr", "qrCodeImg", rawCode); + } + + protected async Task ReloadAllData() + { + suppList = await DataService.SuppliersGetAll(); + transpList = await DataService.TransportersGetAll(); + + // vedere anche https://www.mikesdotnetting.com/article/340/working-with-query-strings-in-blazor + var uri = NavManager.ToAbsoluteUri(NavManager.Uri); + var currMode = GetQueryParm("currMode"); + if (!string.IsNullOrEmpty(currMode)) + { + editAll = currMode.Equals("debug"); + } + } + + #endregion Protected Methods + + #region Private Fields + + private List suppList; + private List transpList; + + #endregion Private Fields + + #region Private Properties + + private bool editAll { get; set; } = false; + + #endregion Private Properties + + #region Private Methods + private async Task cancelUpdate() { await DataReset.InvokeAsync(0); @@ -100,46 +149,23 @@ namespace GWMS.UI.Components } } - protected override async Task OnInitializedAsync() + private async Task saveUpdate() { - await ReloadAllData(); - await JSRuntime.InvokeVoidAsync("displayQr", "qrCodeImg", rawCode); - } - - protected string rawCode - { - get + if (_currItem != null) { - string answ = ""; - if (_currItem != null) - { - answ = _currItem.OrderCode; - } - return answ; + using var activity = StartTracing("SaveUpdate"); + await DataService.OrderUpdate(_currItem); + activity?.SetTag("order.code", _currItem.OrderCode); + activity?.SetTag("order.operator", MServ.UserName); + activity?.SetTag("order.quantity_req", _currItem.OrderQty); + await DataUpdated.InvokeAsync(1); + } + else + { + Console.WriteLine("Order null!"); } } - protected async Task ReloadAllData() - { - suppList = await DataService.SuppliersGetAll(); - transpList = await DataService.TransportersGetAll(); - - // vedere anche https://www.mikesdotnetting.com/article/340/working-with-query-strings-in-blazor - var uri = NavManager.ToAbsoluteUri(NavManager.Uri); - var currMode = GetQueryParm("currMode"); - if (!string.IsNullOrEmpty(currMode)) - { - editAll = currMode.Equals("debug"); - } - } - - // Blazor: get query parm from the URL - protected string GetQueryParm(string parmName) - { - var uriBuilder = new UriBuilder(NavManager.Uri); - var q = System.Web.HttpUtility.ParseQueryString(uriBuilder.Query); - return q[parmName] ?? ""; - } - + #endregion Private Methods } } \ No newline at end of file diff --git a/GWMS.UI/Data/GWMSDataService.cs b/GWMS.UI/Data/GWMSDataService.cs index 58206de..7598234 100644 --- a/GWMS.UI/Data/GWMSDataService.cs +++ b/GWMS.UI/Data/GWMSDataService.cs @@ -984,7 +984,7 @@ namespace GWMS.UI.Data string cacheKey = mHash("PLANTS:ListDTO"); #if false Stopwatch sw = new Stopwatch(); - sw.Start(); + sw.Start(); #endif string source = "DB"; rawData = await redisDb.StringGetAsync(cacheKey); @@ -1003,7 +1003,7 @@ namespace GWMS.UI.Data } #if false sw.Stop(); - Log.Info($"PlantDtoGetAll | {source} | {sw.ElapsedMilliseconds} ms"); + Log.Info($"PlantDtoGetAll | {source} | {sw.ElapsedMilliseconds} ms"); #endif // elimino veto! await ExecFlushRedisPattern(cacheVetoKey); @@ -1184,7 +1184,7 @@ namespace GWMS.UI.Data string cacheKey = mHash("PLANTS:ListModel"); #if false Stopwatch sw = new Stopwatch(); - sw.Start(); + sw.Start(); #endif string rawData; rawData = await redisDb.StringGetAsync(cacheKey); @@ -1209,7 +1209,7 @@ namespace GWMS.UI.Data } #if false sw.Stop(); - Log.Debug($"PlantsList | {source} | {sw.ElapsedMilliseconds} ms"); + Log.Debug($"PlantsList | {source} | {sw.ElapsedMilliseconds} ms"); #endif activity?.SetTag("data.source", source); activity?.SetTag("result.count", result.Count); @@ -1892,6 +1892,11 @@ namespace GWMS.UI.Data #region Private Fields + /// + /// Oggetto per collezione dati Activity (span in Uptrace) + /// + private static readonly ActivitySource ActivitySource = new ActivitySource("GWMS.Data"); + private static IConfiguration _configuration; private static ILogger _logger; @@ -1943,29 +1948,10 @@ namespace GWMS.UI.Data /// private Random rnd = new Random(); - #endregion Private Fields - - /// - /// Oggetto per collezione dati Activity (span in Uptrace) - /// - private static readonly ActivitySource ActivitySource = new ActivitySource("GWMS.Data"); - - /// - /// Helper trace messaggio log (SE abilitato) - /// - /// - private void LogTrace(string traceMsg, NLog.LogLevel? reqLevel = null) - { - if (!traceEnabled) - return; - - reqLevel ??= NLog.LogLevel.Debug; - - // Loggo! - Log.Log(reqLevel, traceMsg); - } private bool traceEnabled = false; + #endregion Private Fields + #region Private Properties private string CodApp { get; set; } = ""; @@ -2058,6 +2044,21 @@ namespace GWMS.UI.Data return mHash($"SavedTask:{idxMacchina}"); } + /// + /// Helper trace messaggio log (SE abilitato) + /// + /// + private void LogTrace(string traceMsg, NLog.LogLevel? reqLevel = null) + { + if (!traceEnabled) + return; + + reqLevel ??= NLog.LogLevel.Debug; + + // Loggo! + Log.Log(reqLevel, traceMsg); + } + /// /// Recupera PlantDTO e aggiorno valori attuali (se presente...) /// ATTENZIONE: i dati sono sempre ricevuti PER SINGOLO PlantId!!!