From 7fbec59c8de6ca8ed97cf558bbbe934e303945c5 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 18 Sep 2025 18:23:49 +0200 Subject: [PATCH] Completato editing dei record elenchi generico, compreso spostamenti + eliminazioni varie --- .../Controllers/LuxController.cs | 165 +++++++++++++++++- .../Services/DataLayerServices.cs | 40 +++++ Lux.UI/Components/Compo/GenClassMan.razor | 22 +-- Lux.UI/Components/Compo/GenClassMan.razor.cs | 47 ++--- Lux.UI/Components/Compo/GenValMan.razor | 94 +++++----- Lux.UI/Components/Compo/GenValMan.razor.cs | 66 +++++-- Lux.UI/Components/Pages/GenList.razor | 9 +- Lux.UI/Lux.UI.csproj | 2 +- Resources/ChangeLog.html | 2 +- Resources/VersNum.txt | 2 +- Resources/manifest.xml | 2 +- 11 files changed, 339 insertions(+), 112 deletions(-) diff --git a/EgwCoreLib.Lux.Data/Controllers/LuxController.cs b/EgwCoreLib.Lux.Data/Controllers/LuxController.cs index b26a9320..8c771e48 100644 --- a/EgwCoreLib.Lux.Data/Controllers/LuxController.cs +++ b/EgwCoreLib.Lux.Data/Controllers/LuxController.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using NLog; +using NLog.LayoutRenderers; using static EgwCoreLib.Lux.Core.Enums; namespace EgwCoreLib.Lux.Data.Controllers @@ -63,11 +64,11 @@ namespace EgwCoreLib.Lux.Data.Controllers } /// - /// Esegue eliminazione + refresh cache + /// Esegue eliminazione /// - /// + /// /// - internal async Task GenClassDeleteAsync(GenClassModel upsRec) + internal async Task GenClassDeleteAsync(GenClassModel rec2del) { bool answ = false; //using (DataLayerContext dbCtx = new DataLayerContext(configuration)) @@ -77,12 +78,12 @@ namespace EgwCoreLib.Lux.Data.Controllers { var dbResult = dbCtx .DbSetGenClass - .Where(x => x.ClassCod == upsRec.ClassCod) + .Where(x => x.ClassCod == rec2del.ClassCod) .FirstOrDefault(); var numChild = dbCtx .DbSetGenVal - .Count(x => x.ClassCod == upsRec.ClassCod); + .Count(x => x.ClassCod == rec2del.ClassCod); // se trovato e NON HA record child --> elimino if (dbResult != null && numChild == 0) { @@ -152,7 +153,8 @@ namespace EgwCoreLib.Lux.Data.Controllers dbCtx.DbSetGenClass.Add(upsRec); } // salvo... - await dbCtx.SaveChangesAsync(); + int numAct = await dbCtx.SaveChangesAsync(); + answ = numAct > 0; } catch (Exception exc) { @@ -162,6 +164,51 @@ namespace EgwCoreLib.Lux.Data.Controllers return answ; } + /// + /// Esegue eliminazione + /// + /// + /// + internal async Task GenValDeleteAsync(GenValueModel rec2del) + { + bool answ = false; + //using (DataLayerContext dbCtx = new DataLayerContext(configuration)) + using (DataLayerContext dbCtx = new DataLayerContext()) + { + try + { + var dbResult = dbCtx + .DbSetGenVal + .Where(x => x.GenValID == rec2del.GenValID) + .FirstOrDefault(); + + // se trovato --> elimino e sposto i rimanenti... + if (dbResult != null) + { + // modifico record successivi... + var list2Move = dbCtx + .DbSetGenVal + .Where(x => x.ClassCod == rec2del.ClassCod && x.Ordinal> dbResult.Ordinal) + .ToList(); + foreach (var item in list2Move) + { + item.Ordinal--; + dbCtx.Entry(item).State = EntityState.Modified; + } + // elimino + dbCtx.DbSetGenVal.Remove(dbResult); + // salvo tutto + await dbCtx.SaveChangesAsync(); + } + } + catch (Exception exc) + { + Log.Error($"Eccezione durante GenValDeleteAsync{Environment.NewLine}{exc}"); + } + } + return answ; + } + /// /// Elenco valori x classe richiesta /// @@ -191,6 +238,112 @@ namespace EgwCoreLib.Lux.Data.Controllers return dbResult; } + /// + /// Esegue spostamento nell'ordinamento relativo alla classe + /// NB: verifica spostamento sia ammissibile: se primo rec non "sale", se ultimo non "scende"... + /// + /// + /// + /// + internal async Task GenValMoveAsync(GenValueModel selRec, bool moveUp) + { + bool answ = false; + //using (DataLayerContext dbCtx = new DataLayerContext(configuration)) + using (DataLayerContext dbCtx = new DataLayerContext()) + { + try + { + var currRec = dbCtx + .DbSetGenVal + .Where(x => x.GenValID == selRec.GenValID) + .FirstOrDefault(); + + if (currRec != null) + { + // recupero info del num rec del suo gruppo + int numRec = dbCtx + .DbSetGenVal + .Count(x => x.ClassCod == selRec.ClassCod); + + // verifico NON sia primo/ultimo... + bool canMove = false; + int newPos = moveUp ? currRec.Ordinal - 1 : currRec.Ordinal + 1; + if (moveUp) + { + canMove = newPos > 0; + } + else + { + canMove = newPos <= numRec; + } + // se abilitato --> aggiorno i 2 record... + if (canMove) + { + var otherRec = dbCtx + .DbSetGenVal + .Where(x => x.ClassCod == selRec.ClassCod && x.Ordinal == newPos) + .FirstOrDefault(); + if (otherRec != null) + { + otherRec.Ordinal = currRec.Ordinal; + dbCtx.Entry(otherRec).State = EntityState.Modified; + currRec.Ordinal = newPos; + dbCtx.Entry(currRec).State = EntityState.Modified; + } + // salvo... + int numAct = await dbCtx.SaveChangesAsync(); + answ = numAct > 0; + } + } + } + catch (Exception exc) + { + Log.Error($"Eccezione durante GenValMoveAsync{Environment.NewLine}{exc}"); + } + } + return answ; + } + + /// + /// Esegue Upsert del record ricevuto + /// + /// + /// + internal async Task GenValUpsertAsync(GenValueModel upsRec) + { + bool answ = false; + //using (DataLayerContext dbCtx = new DataLayerContext(configuration)) + using (DataLayerContext dbCtx = new DataLayerContext()) + { + try + { + var currRec = dbCtx + .DbSetGenVal + .Where(x => x.GenValID == upsRec.GenValID) + .FirstOrDefault(); + // se trovato --> aggiorno + if (currRec != null) + { + currRec.ValString = upsRec.ValString; + dbCtx.Entry(currRec).State = EntityState.Modified; + } + // se mancasse --> aggiungo + else + { + dbCtx.DbSetGenVal.Add(upsRec); + } + // salvo... + int numAct = await dbCtx.SaveChangesAsync(); + answ = numAct > 0; + } + catch (Exception exc) + { + Log.Error($"Eccezione durante GenValUpsertAsync{Environment.NewLine}{exc}"); + } + } + return answ; + } + /// /// Eliminazione record item /// diff --git a/EgwCoreLib.Lux.Data/Services/DataLayerServices.cs b/EgwCoreLib.Lux.Data/Services/DataLayerServices.cs index ab810e43..b24592be 100644 --- a/EgwCoreLib.Lux.Data/Services/DataLayerServices.cs +++ b/EgwCoreLib.Lux.Data/Services/DataLayerServices.cs @@ -202,6 +202,33 @@ namespace EgwCoreLib.Lux.Data.Services return result; } + /// + /// Esegue eliminazione + refresh cache + /// + /// + /// + public async Task GenValDeleteAsync(GenValueModel selRec) + { + bool result = await dbController.GenValDeleteAsync(selRec); + await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:GenClass"); + await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:GenVal:*"); + return result; + } + + /// + /// Esegue spostamento nell'ordinamento relativo alla classe + refresh cache + /// + /// + /// + /// + public async Task GenValMoveAsync(GenValueModel selRec, bool moveUp) + { + bool result = await dbController.GenValMoveAsync(selRec, moveUp); + await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:GenClass"); + await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:GenVal:*"); + return result; + } + /// /// Elenco valori x classe richiesta /// @@ -237,6 +264,19 @@ namespace EgwCoreLib.Lux.Data.Services return result; } + /// + /// Esegue Upsert del record ricevuto + /// + /// + /// + public async Task GenValUpsertAsync(GenValueModel upsRec) + { + bool result = await dbController.GenValUpsertAsync(upsRec); + await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:GenClass"); + await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:GenVal:*"); + return result; + } + /// /// Eliminazione record item /// diff --git a/Lux.UI/Components/Compo/GenClassMan.razor b/Lux.UI/Components/Compo/GenClassMan.razor index d988515a..c35d993e 100644 --- a/Lux.UI/Components/Compo/GenClassMan.razor +++ b/Lux.UI/Components/Compo/GenClassMan.razor @@ -69,7 +69,7 @@ @item.ClassCod - + @item.NumChild @@ -88,7 +88,7 @@ @if (item.NumChild > 0) { - + } else { @@ -99,14 +99,14 @@ } - - - - @if (totalCount >= numRecord) - { + @if (totalCount >= numRecord) + { + + + - } - - - + + + + } \ No newline at end of file diff --git a/Lux.UI/Components/Compo/GenClassMan.razor.cs b/Lux.UI/Components/Compo/GenClassMan.razor.cs index 2c3a0f62..5d1cf650 100644 --- a/Lux.UI/Components/Compo/GenClassMan.razor.cs +++ b/Lux.UI/Components/Compo/GenClassMan.razor.cs @@ -45,18 +45,6 @@ namespace Lux.UI.Components.Compo #region Protected Methods - protected void ToggleAdd() - { - AddVisible = !AddVisible; - NewRecord = new GenClassModel() - { - ClassCod = "NewClass", - Description = $"Descrizione-{DateTime.Now:yyyy.MM.dd-HH.mm.ss}" - }; - } - private bool AddVisible = false; - private string ErrorMsg = ""; - /// /// Genera nuovo record e lo salva /// @@ -95,24 +83,6 @@ namespace Lux.UI.Components.Compo /// protected void DoClone(GenClassModel 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 } /// @@ -192,17 +162,26 @@ namespace Lux.UI.Components.Compo UpdateTable(); } + protected void ToggleAdd() + { + AddVisible = !AddVisible; + NewRecord = new GenClassModel() + { + ClassCod = "NewClass", + Description = $"Descrizione-{DateTime.Now:yyyy.MM.dd-HH.mm.ss}" + }; + } + #endregion Protected Methods #region Private Fields + private bool AddVisible = false; private int currPage = 1; - private GenClassModel? EditRecord = null; - private GenClassModel? NewRecord = null; - + private string ErrorMsg = ""; private bool isLoading = false; - + private GenClassModel? NewRecord = null; private int numRecord = 10; private GenClassModel? SelRecord = null; diff --git a/Lux.UI/Components/Compo/GenValMan.razor b/Lux.UI/Components/Compo/GenValMan.razor index 3931eb5a..a637a5ea 100644 --- a/Lux.UI/Components/Compo/GenValMan.razor +++ b/Lux.UI/Components/Compo/GenValMan.razor @@ -8,58 +8,74 @@ else if (totalCount == 0) } else { - if (editRecord != null) - { - @* *@ - } - - - - - - + @* *@ + + + @foreach (var item in ListRecords) { + string cssBtnUp = EditRecord == null && item.Ordinal > 1 ? "btn-outline-primary" : "btn-outline-secondary opacity-50 disabled"; + string cssBtnDown = EditRecord == null && item.Ordinal < totalCount ? "btn-outline-primary" : "btn-outline-secondary opacity-50 disabled"; - - - - - - - + @if (EditRecord != null && item.GenValID == EditRecord.GenValID) + { + + @* *@ + + + + } + else + { + + @* *@ + + + + } } - - - - - + @if (totalCount >= numRecord) + { + + + + + + }
+ IDGruppoOrdinValoreIDOrd.Valore + +
- - - - @item.GenValID - @if (item.GenClassNav != null) - { - @item.GenClassNav.Description - } - else - { - @item.ClassCod - } - @item.Ordinal@item.ValString - - + + + @* *@ + @item.GenValID + + @item.Ordinal + + + + + + + @* *@ + @item.GenValID + + @item.Ordinal + + @item.ValString + +
- -
+ +
} diff --git a/Lux.UI/Components/Compo/GenValMan.razor.cs b/Lux.UI/Components/Compo/GenValMan.razor.cs index 4698c5d9..da60f478 100644 --- a/Lux.UI/Components/Compo/GenValMan.razor.cs +++ b/Lux.UI/Components/Compo/GenValMan.razor.cs @@ -101,7 +101,7 @@ namespace Lux.UI.Components.Compo QtyMin = curRec.QtyMin, QtyMax = curRec.QtyMax, UM = curRec.UM - }; + }; #endif } @@ -113,13 +113,18 @@ namespace Lux.UI.Components.Compo { if (!await JSRuntime.InvokeAsync("confirm", $"Sicuro di voler eliminare il record? Dettagli: {selRec.ClassCod} | {selRec.ValString}")) return; - //// esegue eliminazione del record... - //await DLService.ItemDeleteAsync(selRec); - editRecord = null; - selRecord = null; + // esegue eliminazione del record... + await DLService.GenValDeleteAsync(selRec); + + EditRecord = null; + SelRecord = null; await ReloadData(); UpdateTable(); +#if false + // segnalo update x reload + await EC_Updated.InvokeAsync(true); +#endif } /// @@ -128,7 +133,7 @@ namespace Lux.UI.Components.Compo /// protected void DoEdit(GenValueModel curRec) { - editRecord = curRec; + EditRecord = curRec; } /// @@ -136,7 +141,7 @@ namespace Lux.UI.Components.Compo /// protected void DoReset() { - editRecord = null; + EditRecord = null; } /// @@ -145,7 +150,7 @@ namespace Lux.UI.Components.Compo /// protected void DoSelect(GenValueModel curRec) { - selRecord = curRec; + SelRecord = curRec; } protected override async Task OnParametersSetAsync() @@ -178,13 +183,13 @@ namespace Lux.UI.Components.Compo private int currPage = 1; - private GenValueModel? editRecord = null; + private GenValueModel? EditRecord = null; private bool isLoading = false; private int numRecord = 10; - private GenValueModel? selRecord = null; + private GenValueModel? SelRecord = null; private int totalCount = 0; @@ -192,6 +197,30 @@ namespace Lux.UI.Components.Compo #region Private Methods + private async Task DoAdd() + { + // aggiungo un nuovo record in coda... + EditRecord = new GenValueModel() + { + ClassCod = actFilt.SelCodGroup, + ValString = $"Nuovo-{DateTime.Now:yy.MM.ss HH.mm.ss}", + Ordinal = totalCount + 1 + }; + await DoSave(EditRecord); + } + + /// + /// Esegue spostamento + /// + /// + /// + /// + private async Task MoveRec(GenValueModel curRec, bool moveUp) + { + await DLService.GenValMoveAsync(curRec, moveUp); + await DoCancel(); + } + private async Task DoCancel() { await ResetEdit(); @@ -201,11 +230,11 @@ namespace Lux.UI.Components.Compo private async Task DoSave(GenValueModel currRec) { // salvo -#if false - await DLService.ItemUpsertAsync(currRec); -#endif + await DLService.GenValUpsertAsync(currRec); await ResetEdit(); UpdateTable(); + EditRecord = null; + SelRecord = null; } private async Task ReloadData() @@ -213,12 +242,19 @@ namespace Lux.UI.Components.Compo isLoading = true; AllRecords = await DLService.GenValGetFiltAsync(actFilt.SelCodGroup); // se ho ricerca testuale faccio filtro ulteriore... - if (!string.IsNullOrEmpty(actFilt.SearchVal)) + if (string.IsNullOrEmpty(actFilt.SearchVal)) + { + AllRecords = AllRecords + .OrderBy(x => x.Ordinal) + .ToList(); + } + else { AllRecords = AllRecords .Where(x => x.ClassCod.Contains(actFilt.SearchVal, StringComparison.InvariantCultureIgnoreCase) || x.ValString.Contains(actFilt.SearchVal, StringComparison.InvariantCultureIgnoreCase)) + .OrderBy(x => x.Ordinal) .ToList(); } totalCount = AllRecords.Count; @@ -227,7 +263,7 @@ namespace Lux.UI.Components.Compo private async Task ResetEdit() { // reset edit - editRecord = null; + EditRecord = null; await ReloadData(); } diff --git a/Lux.UI/Components/Pages/GenList.razor b/Lux.UI/Components/Pages/GenList.razor index 903e41a0..0a7f65ca 100644 --- a/Lux.UI/Components/Pages/GenList.razor +++ b/Lux.UI/Components/Pages/GenList.razor @@ -26,11 +26,14 @@ } else { -
+
-
- +
+ @if (!string.IsNullOrEmpty(CurrFilt.SelCodGroup)) + { + + }
}
diff --git a/Lux.UI/Lux.UI.csproj b/Lux.UI/Lux.UI.csproj index 328212b0..4d9a2dba 100644 --- a/Lux.UI/Lux.UI.csproj +++ b/Lux.UI/Lux.UI.csproj @@ -5,7 +5,7 @@ enable enable aspnet-Lux.UI-a758c101-a2f4-4e38-977d-1c4887dbbd50 - 0.9.2509.1816 + 0.9.2509.1818 diff --git a/Resources/ChangeLog.html b/Resources/ChangeLog.html index 2c553fa7..f1896895 100644 --- a/Resources/ChangeLog.html +++ b/Resources/ChangeLog.html @@ -1,6 +1,6 @@ LUX - Web Windows MES -

Versione: 0.9.2509.1816

+

Versione: 0.9.2509.1818


Note di rilascio:
  • diff --git a/Resources/VersNum.txt b/Resources/VersNum.txt index b1f250ea..08a4f762 100644 --- a/Resources/VersNum.txt +++ b/Resources/VersNum.txt @@ -1 +1 @@ -0.9.2509.1816 +0.9.2509.1818 diff --git a/Resources/manifest.xml b/Resources/manifest.xml index 90bf740f..76e01771 100644 --- a/Resources/manifest.xml +++ b/Resources/manifest.xml @@ -1,6 +1,6 @@ - 0.9.2509.1816 + 0.9.2509.1818 http://nexus.steamware.net/repository/SWS/GPW/stable/GPW.UI.zip http://nexus.steamware.net/repository/SWS/GPW/stable/ChangeLog.html false