From da4613bf8ccfb9d26fa16827756fd4131a1b134e Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 16 Apr 2025 07:40:41 +0200 Subject: [PATCH] SPEC Reparti: - OK editing - ok add --- MP.Data/Controllers/MpSpecController.cs | 239 +++++++++++------- MP.SPEC/Components/ProdKit/GestKitPodl.razor | 12 +- .../Components/ProdKit/GestKitPodl.razor.cs | 1 + MP.SPEC/Components/Reparti/ListReparti.razor | 29 ++- .../Components/Reparti/ListReparti.razor.cs | 77 ++++-- MP.SPEC/Data/MpDataService.cs | 125 +++++---- MP.SPEC/MP.SPEC.csproj | 2 +- MP.SPEC/Pages/GroupMacOprMan.razor | 2 +- MP.SPEC/Pages/GroupMacOprMan.razor.cs | 16 +- MP.SPEC/Resources/ChangeLog.html | 2 +- MP.SPEC/Resources/VersNum.txt | 2 +- MP.SPEC/Resources/manifest.xml | 2 +- 12 files changed, 336 insertions(+), 173 deletions(-) diff --git a/MP.Data/Controllers/MpSpecController.cs b/MP.Data/Controllers/MpSpecController.cs index a730df28..d9c70d23 100644 --- a/MP.Data/Controllers/MpSpecController.cs +++ b/MP.Data/Controllers/MpSpecController.cs @@ -83,6 +83,31 @@ namespace MP.Data.Controllers return AnagGruppiGetTipo("AZIENDA"); } + /// + /// Delete record AnagraficaGruppi + /// + /// + public bool AnagGruppiDelete(AnagGruppiModel updRec) + { + bool answ = false; + using (var dbCtx = new MoonProContext(_configuration)) + { + var dbRec = dbCtx + .DbSetAnagGruppi + .AsNoTracking() + .Where(x => x.CodGruppo == updRec.CodGruppo) + .FirstOrDefault(); + // se trovato aggiorno descrizione (resto immutato x sicurezza!) + if (dbRec != null) + { + dbCtx.DbSetAnagGruppi.Remove(dbRec); + } + var numRes = dbCtx.SaveChanges(); + answ = numRes != 0; + } + return answ; + } + /// /// Elenco Gruppi tipo Fasi /// @@ -91,6 +116,45 @@ namespace MP.Data.Controllers { return AnagGruppiGetTipo("FASE"); } + + /// + /// Elenco Gruppi + /// + /// + public List AnagGruppiGetAll() + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + dbResult = dbCtx + .DbSetAnagGruppi + .AsNoTracking() + .OrderBy(x => x.CodGruppo) + .ToList(); + } + return dbResult; + } + + /// + /// Gruppi x tipo + /// + /// + /// + public List AnagGruppiGetTipo(string tipoGruppo) + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + dbResult = dbCtx + .DbSetAnagGruppi + .Where(x => x.TipoGruppo == tipoGruppo) + .AsNoTracking() + .OrderBy(x => x.CodGruppo) + .ToList(); + } + return dbResult; + } + /// /// Elenco Gruppi tipo REPARTO (x associazione Macchine-Operatori) /// @@ -138,44 +202,36 @@ namespace MP.Data.Controllers return dbResult; } - - /// - /// Elenco Gruppi + /// Upsert record AnagraficaGruppi (solo codice/descrizione) /// + /// /// - public List AnagGruppiGetAll() + public bool AnagGruppiUpsert(AnagGruppiModel updRec) { - List dbResult = new List(); + bool answ = false; using (var dbCtx = new MoonProContext(_configuration)) { - dbResult = dbCtx + var dbRec = dbCtx .DbSetAnagGruppi .AsNoTracking() - .OrderBy(x => x.CodGruppo) - .ToList(); + .Where(x => x.CodGruppo == updRec.CodGruppo) + .FirstOrDefault(); + // se trovato aggiorno descrizione (resto immutato x sicurezza!) + if (dbRec != null) + { + dbRec.DescrGruppo = updRec.DescrGruppo; + dbCtx.Entry(dbRec).State = EntityState.Modified; + } + // altrimenti aggiungo + else + { + dbCtx.DbSetAnagGruppi.Add(updRec); + } + var numRes = dbCtx.SaveChanges(); + answ = numRes != 0; } - return dbResult; - } - - /// - /// Gruppi x tipo - /// - /// - /// - public List AnagGruppiGetTipo(string tipoGruppo) - { - List dbResult = new List(); - using (var dbCtx = new MoonProContext(_configuration)) - { - dbResult = dbCtx - .DbSetAnagGruppi - .Where(x => x.TipoGruppo == tipoGruppo) - .AsNoTracking() - .OrderBy(x => x.CodGruppo) - .ToList(); - } - return dbResult; + return answ; } /// @@ -196,26 +252,6 @@ namespace MP.Data.Controllers return dbResult; } - - /// - /// Elenco operatori - /// - /// - public List ElencoOperatori() - { - List dbResult = new List(); - using (var dbCtx = new MoonProContext(_configuration)) - { - dbResult = dbCtx - .DbOperatori - .Where(s => s.MatrOpr > 0) - .AsNoTracking() - .OrderBy(x => x.MatrOpr) - .ToList(); - } - return dbResult; - } - /// /// Elenco valori ammessi x Stati commessa (es Yacht Baglietto) /// @@ -628,6 +664,25 @@ namespace MP.Data.Controllers return ListLinkFilt("SpecLink"); } + /// + /// Elenco operatori + /// + /// + public List ElencoOperatori() + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + dbResult = dbCtx + .DbOperatori + .Where(s => s.MatrOpr > 0) + .AsNoTracking() + .OrderBy(x => x.MatrOpr) + .ToList(); + } + return dbResult; + } + /// /// Aggiunta record EventList /// @@ -1247,49 +1302,6 @@ namespace MP.Data.Controllers return dbResult; } - /// - /// Elenco da tabella Operatori filtro x gruppo - /// - /// - /// - public List OperatoriGetFilt(string codGruppo) - { - List dbResult = new List(); - try - { - using (var dbCtx = new MoonProContext(_configuration)) - { - if (codGruppo == "*") - { - dbResult = dbCtx - .DbOperatori - .AsNoTracking() - .OrderBy(x => x.MatrOpr) - .ToList(); - } - else - { - dbResult = dbCtx - .DbSetGrp2Oper - .Where(g => g.CodGruppo == codGruppo) - .Join(dbCtx.DbOperatori, - g => g.MatrOpr, - m => m.MatrOpr, - (g, m) => m - ) - .AsNoTracking() - .OrderBy(x => x.MatrOpr) - .ToList(); - } - } - } - catch (Exception exc) - { - Log.Error($"Eccezione in OperatoriGetFilt{Environment.NewLine}{exc}"); - } - return dbResult; - } - /// /// Elenco id Macchine che abbiano dati FLuxLog, nel periodo indicato /// @@ -1549,6 +1561,49 @@ namespace MP.Data.Controllers return dbResult; } + /// + /// Elenco da tabella Operatori filtro x gruppo + /// + /// + /// + public List OperatoriGetFilt(string codGruppo) + { + List dbResult = new List(); + try + { + using (var dbCtx = new MoonProContext(_configuration)) + { + if (codGruppo == "*") + { + dbResult = dbCtx + .DbOperatori + .AsNoTracking() + .OrderBy(x => x.MatrOpr) + .ToList(); + } + else + { + dbResult = dbCtx + .DbSetGrp2Oper + .Where(g => g.CodGruppo == codGruppo) + .Join(dbCtx.DbOperatori, + g => g.MatrOpr, + m => m.MatrOpr, + (g, m) => m + ) + .AsNoTracking() + .OrderBy(x => x.MatrOpr) + .ToList(); + } + } + } + catch (Exception exc) + { + Log.Error($"Eccezione in OperatoriGetFilt{Environment.NewLine}{exc}"); + } + return dbResult; + } + /// /// Elenco parametri validi x una data macchina /// diff --git a/MP.SPEC/Components/ProdKit/GestKitPodl.razor b/MP.SPEC/Components/ProdKit/GestKitPodl.razor index c3fce515..3d9204c4 100644 --- a/MP.SPEC/Components/ProdKit/GestKitPodl.razor +++ b/MP.SPEC/Components/ProdKit/GestKitPodl.razor @@ -93,7 +93,7 @@
- @if(ShowAllDet) + @if (ShowAllDet) { } @@ -128,11 +128,11 @@
} - + } diff --git a/MP.SPEC/Components/ProdKit/GestKitPodl.razor.cs b/MP.SPEC/Components/ProdKit/GestKitPodl.razor.cs index 655e5051..94033ae1 100644 --- a/MP.SPEC/Components/ProdKit/GestKitPodl.razor.cs +++ b/MP.SPEC/Components/ProdKit/GestKitPodl.razor.cs @@ -345,6 +345,7 @@ namespace MP.SPEC.Components.ProdKit isLoading = false; } + /// /// Toggle modale ricerca articoli /// diff --git a/MP.SPEC/Components/Reparti/ListReparti.razor b/MP.SPEC/Components/Reparti/ListReparti.razor index 44978069..a238d37a 100644 --- a/MP.SPEC/Components/Reparti/ListReparti.razor +++ b/MP.SPEC/Components/Reparti/ListReparti.razor @@ -16,13 +16,20 @@
Modifica
-
+
- + @if (string.IsNullOrEmpty(EditRec.CodGruppo)) + { + + } + else + { + + }
-
+
@@ -84,8 +91,12 @@ @foreach (var record in ListRecords) { - + + @if (SelRecord == null) + { + + } @if (SelRecord == null) { @@ -119,12 +130,12 @@
}
- + }
diff --git a/MP.SPEC/Components/Reparti/ListReparti.razor.cs b/MP.SPEC/Components/Reparti/ListReparti.razor.cs index 446cb8d2..9ed583a6 100644 --- a/MP.SPEC/Components/Reparti/ListReparti.razor.cs +++ b/MP.SPEC/Components/Reparti/ListReparti.razor.cs @@ -1,6 +1,9 @@ using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.DataProtection; +using Microsoft.JSInterop; using MP.Core.DTO; using MP.Data.DbModels; +using MP.SPEC.Data; namespace MP.SPEC.Components.Reparti { @@ -14,8 +17,21 @@ namespace MP.SPEC.Components.Reparti [Parameter] public EventCallback EC_RecordSel { get; set; } + [Parameter] + public EventCallback EC_RecordUpdated { get; set; } + #endregion Public Properties + #region Protected Properties + + [Inject] + protected IJSRuntime JSRuntime { get; set; } = null!; + + [Inject] + protected MpDataService MDService { get; set; } = null!; + + #endregion Protected Properties + #region Protected Methods protected override void OnInitialized() @@ -72,15 +88,16 @@ namespace MP.SPEC.Components.Reparti get => EditRec == null ? "btn-success" : "btn-secondary"; } - private string addNewTxt - { - get => EditRec == null ? "Add New" : "Close Add New"; - } private string addNewIcon { get => EditRec == null ? "fa-plus-square" : "fa-minus-square"; } + private string addNewTxt + { + get => EditRec == null ? "Add New" : "Close"; + } + #endregion Private Properties #region Private Methods @@ -92,27 +109,49 @@ namespace MP.SPEC.Components.Reparti return answ; } + /// + /// ELiminabile se non ha record child macchine/opr... + /// + /// + /// private bool DelEnabled(RepartiDTO currRec) { - bool answ = false; - - return answ; + int numChild = currRec.CountMacc + currRec.CountOpr; + return numChild == 0; } - private void DoUpdate(AnagGruppiModel UpdRec) - { - // salvo - - EditRec = null; - } private void DoCancel() { EditRec = null; } - private void DoDelete(RepartiDTO currRec) + private async Task DoDelete(RepartiDTO selRec) { + if (!await JSRuntime.InvokeAsync("confirm", "Eliminazione record Reparto: sei sicuro di voler procedere?")) + return; + // eliminazione + var rec2Del = new AnagGruppiModel() + { + CodGruppo = selRec.CodGruppo, + DescrGruppo = selRec.DescrGruppo, + SelEnabled = selRec.SelEnabled, + TipoGruppo = selRec.TipoGruppo + }; + MDService.AnagGruppiDelete(rec2Del); + EditRec = null; + await EC_RecordUpdated.InvokeAsync(true); + } + + private void DoEdit(RepartiDTO selRec) + { + EditRec = new AnagGruppiModel() + { + CodGruppo = selRec.CodGruppo, + DescrGruppo = selRec.DescrGruppo, + SelEnabled = selRec.SelEnabled, + TipoGruppo = selRec.TipoGruppo + }; } private async Task DoSelect(RepartiDTO currRec) @@ -122,6 +161,14 @@ namespace MP.SPEC.Components.Reparti await EC_RecordSel.InvokeAsync(currRec.CodGruppo); } + private async Task DoUpdate(AnagGruppiModel UpdRec) + { + // salvo... + MDService.AnagGruppiUpsert(UpdRec); + EditRec = null; + await EC_RecordUpdated.InvokeAsync(true); + } + private async Task ResetSel() { SelRecord = null; @@ -136,7 +183,7 @@ namespace MP.SPEC.Components.Reparti DateTime adesso = DateTime.Now; EditRec = new AnagGruppiModel() { - CodGruppo = $"NEW-GROUP-{adesso:yyyyMMdd}-{adesso:HHmmss}", + CodGruppo = "", DescrGruppo = "Descrizione", SelEnabled = false, TipoGruppo = "REPARTO" diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index b2a12e06..c90b8d48 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -155,6 +155,45 @@ namespace MP.SPEC.Data return result; } + /// + /// Delete record AnagraficaGruppi + /// + /// + public bool AnagGruppiDelete(AnagGruppiModel updRec) + { + bool result = false; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + result = dbController.AnagGruppiDelete(updRec); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{Utils.redisAnagGruppi}:*"); + bool answ = ExecFlushRedisPattern(pattern); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"AnagGruppiDelete | CodGruppo {updRec.CodGruppo} | {ts.TotalMilliseconds}ms"); + return result; + } + + /// + /// Upsert record AnagraficaGruppi + /// + /// + /// + public bool AnagGruppiUpsert(AnagGruppiModel UpdRec) + { + bool result = false; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + result = dbController.AnagGruppiUpsert(UpdRec); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{Utils.redisAnagGruppi}:*"); + bool answ = ExecFlushRedisPattern(pattern); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"AnagGruppiUpsert | CodGruppo {UpdRec.CodGruppo} | {ts.TotalMilliseconds}ms"); + return result; + } + /// /// Elenco Gruppi /// @@ -749,6 +788,11 @@ namespace MP.SPEC.Data return result; } + public Task> ElencoLink() + { + return Task.FromResult(dbController.ElencoLink()); + } + /// /// Restitusice elenco Reparti /// @@ -788,11 +832,6 @@ namespace MP.SPEC.Data return result; } - public Task> ElencoLink() - { - return Task.FromResult(dbController.ElencoLink()); - } - /// /// Aggiunta record EventList /// @@ -1325,45 +1364,6 @@ namespace MP.SPEC.Data return result; } - - /// - /// Elenco operatori filtrati x gruppo - /// - /// - /// - public List OperatoriGetFilt(string codGruppo) - { - List? result = new List(); - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - string readType = "DB"; - string keyGrp = codGruppo != "*" ? codGruppo : "ALL"; - string currKey = $"{Utils.redisOprList}:{keyGrp}"; - // cerco in redis dato valore sel idxMaccSel... - RedisValue rawData = redisDb.StringGet(currKey); - if (rawData.HasValue) - { - result = JsonConvert.DeserializeObject>($"{rawData}"); - readType = "REDIS"; - } - else - { - result = dbController.OperatoriGetFilt(codGruppo); - // serializzo e salvo... - rawData = JsonConvert.SerializeObject(result); - redisDb.StringSet(currKey, rawData, getRandTOut(redisLongTimeCache)); - } - if (result == null) - { - result = new List(); - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"OperatoriGetFilt | Read from {readType}: {ts.TotalMilliseconds}ms"); - return result; - } - - /// /// Verifica se la idxMaccSel abbia un codice PATH ricette associato /// @@ -1735,6 +1735,43 @@ namespace MP.SPEC.Data return result; } + /// + /// Elenco operatori filtrati x gruppo + /// + /// + /// + public List OperatoriGetFilt(string codGruppo) + { + List? result = new List(); + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string readType = "DB"; + string keyGrp = codGruppo != "*" ? codGruppo : "ALL"; + string currKey = $"{Utils.redisOprList}:{keyGrp}"; + // cerco in redis dato valore sel idxMaccSel... + RedisValue rawData = redisDb.StringGet(currKey); + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + readType = "REDIS"; + } + else + { + result = dbController.OperatoriGetFilt(codGruppo); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + redisDb.StringSet(currKey, rawData, getRandTOut(redisLongTimeCache)); + } + if (result == null) + { + result = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"OperatoriGetFilt | Read from {readType}: {ts.TotalMilliseconds}ms"); + return result; + } + /// /// Elenco di tutti i parametri filtrati x idxMaccSel /// diff --git a/MP.SPEC/MP.SPEC.csproj b/MP.SPEC/MP.SPEC.csproj index 62f63d4f..2efe2809 100644 --- a/MP.SPEC/MP.SPEC.csproj +++ b/MP.SPEC/MP.SPEC.csproj @@ -5,7 +5,7 @@ enable enable MP.SPEC - 6.16.2504.1519 + 6.16.2504.1607 1800a78a-6ff1-40f9-b490-87fb8bfc1394 en diff --git a/MP.SPEC/Pages/GroupMacOprMan.razor b/MP.SPEC/Pages/GroupMacOprMan.razor index 866d451c..0d74873b 100644 --- a/MP.SPEC/Pages/GroupMacOprMan.razor +++ b/MP.SPEC/Pages/GroupMacOprMan.razor @@ -26,7 +26,7 @@
- +
@if (ShowDetail) { diff --git a/MP.SPEC/Pages/GroupMacOprMan.razor.cs b/MP.SPEC/Pages/GroupMacOprMan.razor.cs index aab5d90d..dadc6544 100644 --- a/MP.SPEC/Pages/GroupMacOprMan.razor.cs +++ b/MP.SPEC/Pages/GroupMacOprMan.razor.cs @@ -1,3 +1,4 @@ +using DnsClient.Protocol; using Microsoft.AspNetCore.Components; using MP.Core.DTO; using MP.Data.DbModels; @@ -9,9 +10,9 @@ namespace MP.SPEC.Pages { #region Protected Fields - protected List? ListReparti = null; protected List? ListMacchine = null; protected List? ListOperatori = null; + protected List? ListReparti = null; #endregion Protected Fields @@ -35,6 +36,8 @@ namespace MP.SPEC.Pages private string CodGruppo = ""; + private bool isLoading = false; + #endregion Private Fields #region Private Properties @@ -53,6 +56,15 @@ namespace MP.SPEC.Pages #region Private Methods + private void ForceReload(bool doForce) + { + if (doForce) + { + CodGruppo = ""; + } + ReloadData(); + } + private void ReloadData() { isLoading = true; @@ -64,6 +76,7 @@ namespace MP.SPEC.Pages } isLoading = false; } + private void ReloadDetail() { if (!string.IsNullOrEmpty(CodGruppo)) @@ -72,7 +85,6 @@ namespace MP.SPEC.Pages ListOperatori = MDService.OperatoriGetFilt(CodGruppo); } } - private bool isLoading = false; private void SetCodGruppo(string CodGruppoSel) { diff --git a/MP.SPEC/Resources/ChangeLog.html b/MP.SPEC/Resources/ChangeLog.html index ad4a5005..290a71ed 100644 --- a/MP.SPEC/Resources/ChangeLog.html +++ b/MP.SPEC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

Versione: 6.16.2504.1519

+

Versione: 6.16.2504.1607


Note di rilascio:
  • diff --git a/MP.SPEC/Resources/VersNum.txt b/MP.SPEC/Resources/VersNum.txt index 4e2a7971..80b1e7d9 100644 --- a/MP.SPEC/Resources/VersNum.txt +++ b/MP.SPEC/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2504.1519 +6.16.2504.1607 diff --git a/MP.SPEC/Resources/manifest.xml b/MP.SPEC/Resources/manifest.xml index 1f2082b5..142008e1 100644 --- a/MP.SPEC/Resources/manifest.xml +++ b/MP.SPEC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2504.1519 + 6.16.2504.1607 https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/MP.SPEC.zip https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/ChangeLog.html false