From 38ba4c2ca26fb659e4d9b5fb0fdc72c9a6364306 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 12 Feb 2024 19:24:54 +0100 Subject: [PATCH] Completato sposta item tra Categorie --- SHERPA.BBM.CORE/Controllers/BBMController.cs | 33 ++++ SHERPA.BBM.UI/Components/ItemMovList.razor | 38 ++++ SHERPA.BBM.UI/Components/ItemMovList.razor.cs | 166 ++++++++++++++++++ SHERPA.BBM.UI/Data/BBM_EFService.cs | 21 +++ SHERPA.BBM.UI/Pages/ItemMover.razor | 4 +- SHERPA.BBM.UI/Pages/ItemMover.razor.cs | 4 +- 6 files changed, 262 insertions(+), 4 deletions(-) create mode 100644 SHERPA.BBM.UI/Components/ItemMovList.razor create mode 100644 SHERPA.BBM.UI/Components/ItemMovList.razor.cs diff --git a/SHERPA.BBM.CORE/Controllers/BBMController.cs b/SHERPA.BBM.CORE/Controllers/BBMController.cs index 2baa139..14d707e 100644 --- a/SHERPA.BBM.CORE/Controllers/BBMController.cs +++ b/SHERPA.BBM.CORE/Controllers/BBMController.cs @@ -1530,6 +1530,39 @@ namespace SHERPA.BBM.CORE.Controllers return numDone; } + /// + /// Sposta Item nella categoria indicata + /// + /// Item + /// Categoria + /// + public bool ItemMoveResType(int itemId, int resTypeId) + { + bool done = false; + using (SHERPABBMContext dbCtx = new SHERPABBMContext(_configuration)) + { + try + { + var currData = dbCtx + .DbSetItems + .Where(x => x.ItemId == itemId) + .FirstOrDefault(); + if (currData != null) + { + currData.ResTypeId = resTypeId; + dbCtx.Entry(currData).State = EntityState.Modified; + } + dbCtx.SaveChanges(); + done = true; + } + catch (Exception exc) + { + LogException("Eccezione in ItemMoveResType", exc); + } + } + return done; + } + /// /// Eliminazione record /// diff --git a/SHERPA.BBM.UI/Components/ItemMovList.razor b/SHERPA.BBM.UI/Components/ItemMovList.razor new file mode 100644 index 0000000..090a825 --- /dev/null +++ b/SHERPA.BBM.UI/Components/ItemMovList.razor @@ -0,0 +1,38 @@ +@using SHERPA.BBM.UI.Data + +@inject BBM_EFService BBMService +@inject MessageService MessageService + + + + + + + + + + + + @foreach (var record in ListRecords) + { + + + + + + + } + +
CodDescrizioneImporto
+ + +
@record.CodItem
+
@record.UM
+
+
@record.Descript
+
@record.UnitPrice.ToString("C2")
+
+ +
+ + diff --git a/SHERPA.BBM.UI/Components/ItemMovList.razor.cs b/SHERPA.BBM.UI/Components/ItemMovList.razor.cs new file mode 100644 index 0000000..6fef947 --- /dev/null +++ b/SHERPA.BBM.UI/Components/ItemMovList.razor.cs @@ -0,0 +1,166 @@ +using Microsoft.AspNetCore.Components; +using SHERPA.BBM.CORE.DbModels; + +namespace SHERPA.BBM.UI.Components +{ + public partial class ItemMovList + { + #region Public Properties + + [Parameter] + public int ResTypeId + { + get => baskIdSour; + set + { + baskIdSour = value; + // condiziono visualizzazione... + var pUpd = Task.Run(async () => await ReloadAllData()); + pUpd.Wait(); + } + } + + [Parameter] + public EventCallback MoveRequested { get; set; } + + #endregion Public Properties + + #region Public Methods + + public string btnFromState(bool isActive) + { + string answ = isActive ? "btn-success" : "btn-outline-warning"; + return answ; + } + + public string checkSelect(int ItemId) + { + string answ = ""; + if (currItem != null) + { + try + { + answ = (currItem.ItemId == ItemId) ? "table-info" : ""; + } + catch + { + } + } + + return answ; + } + + public async void OnSeachUpdated() + { + await InvokeAsync(() => + { + Task task = UpdateData(); + StateHasChanged(); + }); + } + + public string tooltipFromState(bool isActive) + { + string answ = isActive ? "Attivo" : "Imposta Attivo"; + return answ; + } + + #endregion Public Methods + + #region Protected Fields + + protected int totalCount = 0; + + #endregion Protected Fields + + #region Protected Methods + + protected async Task ForceReload(int newNum) + { + numRecord = newNum; + await ReloadAllData(); + } + + protected async Task ForceReloadPage(int newNum) + { + currPage = newNum; + await ReloadAllData(); + } + + protected async Task Move(vItemsDataModel currRecord) + { + // riporto richiesta spostamento + await MoveRequested.InvokeAsync(currRecord.ItemId); + } + + protected override async Task OnInitializedAsync() + { + MessageService.ShowSearch = true; + MessageService.SearchVal = ""; + MessageService.EA_SearchUpdated += OnSeachUpdated; + await ReloadAllData(); + } + + protected async Task ReloadAllData() + { + await updateTable(); + } + + protected void ResetData() + { + if (currItem != null) + { + BBMService.rollBackEdit(currItem); + } + currItem = null; + } + + protected async Task UpdateData() + { + currItem = null; + await ReloadAllData(); + } + + protected async Task updateTable() + { + SearchRecords = await BBMService.ItemsGetFilt(ResTypeId, MessageService.SearchVal); + totalCount = SearchRecords.Count(); + ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); + } + + #endregion Protected Methods + + #region Private Fields + + private bool _showAllDoc = false; + private vItemsDataModel? currItem = null; + private bool isLoading = false; + private List ListRecords = new List(); + private List SearchRecords = new List(); + + #endregion Private Fields + + #region Private Properties + + private int baskIdSour { get; set; } = 0; + private int currPage { get; set; } = 1; + private int custId { get; set; } = 0; + private int numRecord { get; set; } = 10; + + private bool ShowAllDoc + { + get + { + return _showAllDoc; + } + + set + { + _showAllDoc = value; + updateTable().ConfigureAwait(false); + } + } + + #endregion Private Properties + } +} \ No newline at end of file diff --git a/SHERPA.BBM.UI/Data/BBM_EFService.cs b/SHERPA.BBM.UI/Data/BBM_EFService.cs index 9e4dc24..9fdcebf 100644 --- a/SHERPA.BBM.UI/Data/BBM_EFService.cs +++ b/SHERPA.BBM.UI/Data/BBM_EFService.cs @@ -1069,6 +1069,27 @@ namespace SHERPA.BBM.UI.Data } } + /// + /// Sposta Item nella categoria indicata + /// + /// Item + /// Categoria + /// + public async Task ItemMoveResType(int ItemId, int ResTypeId) + { + bool answ = false; + try + { + answ = dbController.ItemMoveResType(ItemId, ResTypeId); + await FlushRedisCache(); + } + catch (Exception exc) + { + LogException("Eccezione durante ItemMoveResType", exc); + } + return answ; + } + /// /// Eliminazione record /// diff --git a/SHERPA.BBM.UI/Pages/ItemMover.razor b/SHERPA.BBM.UI/Pages/ItemMover.razor index 17491ed..2694445 100644 --- a/SHERPA.BBM.UI/Pages/ItemMover.razor +++ b/SHERPA.BBM.UI/Pages/ItemMover.razor @@ -51,7 +51,7 @@ - @* *@ +
@@ -83,7 +83,7 @@
- @* *@ + } diff --git a/SHERPA.BBM.UI/Pages/ItemMover.razor.cs b/SHERPA.BBM.UI/Pages/ItemMover.razor.cs index d806a8c..b67fb48 100644 --- a/SHERPA.BBM.UI/Pages/ItemMover.razor.cs +++ b/SHERPA.BBM.UI/Pages/ItemMover.razor.cs @@ -38,7 +38,7 @@ namespace SHERPA.BBM.UI.Pages if (SelResTypeIdSx > 0) { // eseguo spostamento... - await BBMService.NegotiationMoveBasket(currIdx, SelResTypeIdSx); + await BBMService.ItemMoveResType(currIdx, SelResTypeIdSx); } } @@ -47,7 +47,7 @@ namespace SHERPA.BBM.UI.Pages if (SelResTypeIdDx > 0) { // eseguo spostamento... - await BBMService.NegotiationMoveBasket(currIdx, SelResTypeIdDx); + await BBMService.ItemMoveResType(currIdx, SelResTypeIdDx); } }