From fc8e5339837a831a405d17bd6d2a5eaf72d891c4 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 16 Jan 2024 12:21:26 +0100 Subject: [PATCH 01/37] Bozza modifica gestione Items oltre a materiali, errore 470/000 --- MagMan.Core/DTO/ItemDTO.cs | 52 +++++++++ MagMan.Core/RestPayload.cs | 7 ++ MagMan.Data.Admin/Services/MTAdminService.cs | 33 +++++- MagMan.Data.Tenant/Services/TenantService.cs | 21 ++++ MagMan.UI/Controllers/ItemsController.cs | 113 +++++++++++++++++++ MagMan.UI/Controllers/MaterialsController.cs | 8 +- MagMan.UI/MagMan.UI.csproj | 2 +- MagMan.UI/Pages/Index.razor | 12 +- MagMan.UI/Pages/MachineStatus.razor | 1 + MagMan.UI/Pages/WareHouse.razor | 17 +-- MagMan.UI/Pages/WareHouse.razor.cs | 6 +- MagMan.UI/Shared/NavMenu.razor | 2 +- Resources/ChangeLog.html | 2 +- Resources/VersNum.txt | 2 +- Resources/manifest.xml | 2 +- 15 files changed, 248 insertions(+), 32 deletions(-) create mode 100644 MagMan.Core/DTO/ItemDTO.cs create mode 100644 MagMan.UI/Controllers/ItemsController.cs diff --git a/MagMan.Core/DTO/ItemDTO.cs b/MagMan.Core/DTO/ItemDTO.cs new file mode 100644 index 0000000..5516f1f --- /dev/null +++ b/MagMan.Core/DTO/ItemDTO.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MagMan.Core.DTO +{ + public class ItemDTO + { + /// + /// Ext ref for Material + /// + public int MatID { get; set; } = 0; + + /// + /// Check if is a Remnant + /// + public bool IsRemn { get; set; } = false; + + /// + /// Location + /// + public string Location { get; set; } = ""; + + /// + /// Qty available on wharehouse + /// + public int QtyAvail { get; set; } = 0; + + /// + /// Item's Lenght + /// + public decimal LMm { get; set; } = 0; + + /// + /// Item's Width + /// + public decimal WMm { get; set; } = 0; + + /// + /// Item's Thikness + /// + public decimal TMm { get; set; } = 0; + + /// + /// Note (optional) + /// + public string Note { get; set; } = ""; + } +} diff --git a/MagMan.Core/RestPayload.cs b/MagMan.Core/RestPayload.cs index 6eeaf40..106465b 100644 --- a/MagMan.Core/RestPayload.cs +++ b/MagMan.Core/RestPayload.cs @@ -16,5 +16,12 @@ namespace MagMan.Core /// public List? MatList { get; set; } } + public class Items + { + /// + /// Elenco Items x invio POST + /// + public List? ItemList { get; set; } + } } } diff --git a/MagMan.Data.Admin/Services/MTAdminService.cs b/MagMan.Data.Admin/Services/MTAdminService.cs index 808fa58..dc73740 100644 --- a/MagMan.Data.Admin/Services/MTAdminService.cs +++ b/MagMan.Data.Admin/Services/MTAdminService.cs @@ -427,7 +427,7 @@ namespace MagMan.Data.Admin.Services return answ; } /// - /// Recupera CustomerID dal dizionario dei token noti o cercando sul DB + /// Recupera MainKey dal dizionario dei token noti o cercando sul DB /// /// /// @@ -453,6 +453,33 @@ namespace MagMan.Data.Admin.Services } return answ; } + /// + /// Recupera CustomerID dal dizionario dei token noti o cercando sul DB + /// + /// + /// + public async Task MainKeyByCustomer(int CustID) + { + int answ = -1; + if (CustMKeyList.ContainsKey(CustID)) + { + answ = CustMKeyList[CustID]; + } + else + { + // cerco nel DB + var custList = await CustomerGetAll(); + var custRow = custList.FirstOrDefault(x => x.CustomerID == CustID); + // se trovato salvo + if (custRow != null) + { + answ = custRow.MainKey; + CustMKeyList.Add(CustID, answ); + Log.Info($"TokenMKeyList: added {CustID} --> {answ}"); + } + } + return answ; + } #endregion Protected Methods @@ -502,6 +529,10 @@ namespace MagMan.Data.Admin.Services /// Dizionario dei token 2 MainKey (x calcolo DB) /// private Dictionary TokenMKeyList { get; set; } = new Dictionary(); + /// + /// Dizionario customer 2 MainKey (x calcolo DB) + /// + private Dictionary CustMKeyList { get; set; } = new Dictionary(); #endregion Private Properties diff --git a/MagMan.Data.Tenant/Services/TenantService.cs b/MagMan.Data.Tenant/Services/TenantService.cs index 6ddc4d2..1344b13 100644 --- a/MagMan.Data.Tenant/Services/TenantService.cs +++ b/MagMan.Data.Tenant/Services/TenantService.cs @@ -324,6 +324,27 @@ namespace MagMan.Data.Tenant.Services return answ; } + /// + /// Converte il DTO in ItemModel + /// + /// + /// + public ItemModel ItemFromDto(ItemDTO origItem) + { + ItemModel answ = new ItemModel() + { + MatID = origItem.MatID, + Note = origItem.Note, + LMm = origItem.LMm, + WMm = origItem.WMm, + TMm = origItem.TMm, + IsRemn= origItem.IsRemn, + Location = origItem.Location, + QtyAvail = origItem.QtyAvail + }; + + return answ; + } #endregion Public Methods diff --git a/MagMan.UI/Controllers/ItemsController.cs b/MagMan.UI/Controllers/ItemsController.cs new file mode 100644 index 0000000..0543984 --- /dev/null +++ b/MagMan.UI/Controllers/ItemsController.cs @@ -0,0 +1,113 @@ +using MagMan.Core; +using MagMan.Data.Admin.DbModels; +using MagMan.Data.Admin.Services; +using MagMan.Data.Tenant.DbModels; +using MagMan.Data.Tenant.Services; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using NLog; +using Org.BouncyCastle.Asn1.Pkcs; + +namespace MagMan.UI.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ItemsController : ControllerBase + { + /// + /// Classe per logging + /// + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + private MTAdminService MTAdminService { get; set; } = null!; + private static JsonSerializerSettings? JSSettings; + private TenantService TService { get; set; } = null!; + public ItemsController(MTAdminService MTDataService, TenantService TDataService) + { + MTAdminService = MTDataService; + TService = TDataService; + // json serializer... FIX errore loop circolare https://www.ryadel.com/en/jsonserializationexception-self-referencing-loop-detected-error-fix-entity-framework-asp-net-core/ + JSSettings = new JsonSerializerSettings() + { + ReferenceLoopHandling = ReferenceLoopHandling.Ignore + }; + Log.Info("Avviata classe ItemsController"); + } + + /// + /// Controllo status Alive + /// GET: api/Items/alive + /// + /// + [HttpGet("alive")] + public string alive() + { + //Log.Debug("Chiamata alive"); + return $"OK"; + } + + // GET api/Items + [HttpGet] + public async Task> Get() + { + // se non ho chaive --> vuoto! + List ListRecords = new List(); + await Task.Delay(100); + return ListRecords; + } + + /// + /// Elenco Materiali dato RestToken + /// + /// Rest Token cliente + /// ID del materiale cercato + /// + // GET api/Items/00000000-0000-0000-0000-000000000000 + [HttpGet("{id}")] + public async Task> Get(string id, int MatId) + { + // in primis recupero codice chiave da token... + int nKey = await MTAdminService.MainKeyByToken(id); + // ora recupero direttametne i materiali + var ListRecords = await TService.ItemGetByMat(nKey, MatId); + return ListRecords; + } + + /// + /// Processa una chiamata POST per l'invio di un array Json di oggetti MaterialModel da salvare + /// PUT: api/Items/upsert/00000000-0000-0000-0000-000000000000 + /// + /// token comunicazione + /// + [HttpPost("upsert/{id}")] + public async Task upsert(string id, [FromBody] RestPayload.Items rawList) + { + string answ = "ND"; + bool fatto = false; + // verifico ci sia valore + if (!string.IsNullOrEmpty(id) && rawList != null && rawList.ItemList != null) + { + // in primis recupero codice chiave da token... + int nKey = await MTAdminService.MainKeyByToken(id); + // creo oggetti materiale da lista ricevuta + List matList = rawList.ItemList.Select(jpl => TService.ItemFromDto(jpl)).ToList(); + + foreach (var item in matList) + { + try + { + await TService.ItemUpdate(nKey, item); + fatto = true; + } + catch (Exception exc) + { + Log.Error($"ItemsController.upsert | Errore in fase salvataggio ItemDto{Environment.NewLine}{exc}"); + fatto = false; + } + } + } + answ = fatto ? "OK" : "NO"; + return answ; + } + } +} diff --git a/MagMan.UI/Controllers/MaterialsController.cs b/MagMan.UI/Controllers/MaterialsController.cs index 6599c8f..754dafc 100644 --- a/MagMan.UI/Controllers/MaterialsController.cs +++ b/MagMan.UI/Controllers/MaterialsController.cs @@ -74,12 +74,12 @@ namespace MagMan.UI.Controllers /// /// Processa una chiamata POST per l'invio di un array Json di oggetti MaterialModel da salvare - /// PUT: api/Materials/upsertMat/00000000-0000-0000-0000-000000000000 + /// PUT: api/Materials/upsert/00000000-0000-0000-0000-000000000000 /// /// token comunicazione /// - [HttpPost("upsertMat/{id}")] - public async Task upsertMat(string id, [FromBody] RestPayload.Materials rawList) + [HttpPost("upsert/{id}")] + public async Task upsert(string id, [FromBody] RestPayload.Materials rawList) { string answ = "ND"; bool fatto = false; @@ -100,7 +100,7 @@ namespace MagMan.UI.Controllers } catch (Exception exc) { - Log.Error($"Errore in fase salvataggio MaterialDto{Environment.NewLine}{exc}"); + Log.Error($"MaterialsController.upsert | Errore in fase salvataggio MaterialDto{Environment.NewLine}{exc}"); fatto = false; } } diff --git a/MagMan.UI/MagMan.UI.csproj b/MagMan.UI/MagMan.UI.csproj index 26bccc8..45ad936 100644 --- a/MagMan.UI/MagMan.UI.csproj +++ b/MagMan.UI/MagMan.UI.csproj @@ -2,7 +2,7 @@ net6.0 - 1.0.2401.1610 + 1.0.2401.1612 enable enable true diff --git a/MagMan.UI/Pages/Index.razor b/MagMan.UI/Pages/Index.razor index ffb5bb5..ba53cc2 100644 --- a/MagMan.UI/Pages/Index.razor +++ b/MagMan.UI/Pages/Index.razor @@ -46,8 +46,8 @@ - -
Admin Area
+ +

Admin Area

@@ -56,8 +56,8 @@ - -
Macchine
+ +

Dati Macchine

@@ -66,8 +66,8 @@ - -
Magazzino
+ +

Magazzino

diff --git a/MagMan.UI/Pages/MachineStatus.razor b/MagMan.UI/Pages/MachineStatus.razor index b690dc2..2da7b02 100644 --- a/MagMan.UI/Pages/MachineStatus.razor +++ b/MagMan.UI/Pages/MachineStatus.razor @@ -3,3 +3,4 @@

MachineStatus

+Work In Progress \ No newline at end of file diff --git a/MagMan.UI/Pages/WareHouse.razor b/MagMan.UI/Pages/WareHouse.razor index e1b6625..b3a219d 100644 --- a/MagMan.UI/Pages/WareHouse.razor +++ b/MagMan.UI/Pages/WareHouse.razor @@ -26,27 +26,16 @@ } } - - -@if (KeyNum == 0) +@if (CustomerID == 0) {
- Key Undef + Customer Undef
- Prego selezionare Key valida per visualizzare dati Magazzino + Prego selezionare Cliente per visualizzare dati Magazzino
} else diff --git a/MagMan.UI/Pages/WareHouse.razor.cs b/MagMan.UI/Pages/WareHouse.razor.cs index dfcf9d4..e48c733 100644 --- a/MagMan.UI/Pages/WareHouse.razor.cs +++ b/MagMan.UI/Pages/WareHouse.razor.cs @@ -27,9 +27,12 @@ namespace MagMan.UI.Pages { isLoading = true; CustomersList = await MTService.CustomerGetAll(); - KeyList = await MTService.AuthKeyByCustId(CustomerID); + nKey = await MTService.MainKeyByCustomer(CustomerID); isLoading = false; } + + protected int nKey = 0; + private bool isLoading { get; set; } = false; private CtMode currMode = CtMode.Materials; protected int CustomerID @@ -49,7 +52,6 @@ namespace MagMan.UI.Pages private int customerID = 0; private int KeyNum = 0; private List? CustomersList = null; - private List? KeyList = null; protected enum CtMode { diff --git a/MagMan.UI/Shared/NavMenu.razor b/MagMan.UI/Shared/NavMenu.razor index 04ca961..8c09629 100644 --- a/MagMan.UI/Shared/NavMenu.razor +++ b/MagMan.UI/Shared/NavMenu.razor @@ -43,7 +43,7 @@
-
- - -
+
@if (CustomerID == 0) diff --git a/MagMan.UI/Pages/WareHouse.razor.cs b/MagMan.UI/Pages/WareHouse.razor.cs index 864137c..611f8a5 100644 --- a/MagMan.UI/Pages/WareHouse.razor.cs +++ b/MagMan.UI/Pages/WareHouse.razor.cs @@ -2,53 +2,19 @@ using MagMan.Core.Services; using MagMan.Data.Admin.DbModels; using MagMan.Data.Admin.Services; using Microsoft.AspNetCore.Components; +using YamlDotNet.Core.Tokens; namespace MagMan.UI.Pages { public partial class WareHouse { - [Inject] - protected MessageService AppMService { get; set; } = null!; - - [Inject] - protected MTAdminService MTService { get; set; } = null!; - protected override async Task OnInitializedAsync() - { - AppMService.ShowSearch = false; - AppMService.PageName = "Warehouse Area"; - AppMService.PageIcon = "fa-solid fa-warehouse pr-2"; - await ReloadData(); - } - - private async Task ReloadData() - { - isLoading = true; - CustomersList = await MTService.CustomerGetAll(); - nKey = await MTService.MainKeyByCustomer(CustomerID); - isLoading = false; - } + #region Protected Fields protected int nKey = 0; - private bool isLoading { get; set; } = false; - private CtMode currMode = CtMode.Materials; - protected int CustomerID - { - get => customerID; - set - { - if (customerID != value) - { - customerID = value; - // update keys - var pUpd = Task.Run(async () => await ReloadData()); - pUpd.Wait(); - } - } - } - private int customerID = 0; - private int KeyNum = 0; - private List? CustomersList = null; + #endregion Protected Fields + + #region Protected Enums protected enum CtMode { @@ -58,15 +24,73 @@ namespace MagMan.UI.Pages //Pickup } + #endregion Protected Enums + + #region Protected Properties + + [Inject] + protected MessageService AppMService { get; set; } = null!; + + protected int CustomerID { get; set; } = 0; + + [Inject] + protected MTAdminService MTService { get; set; } = null!; + + #endregion Protected Properties + + #region Protected Methods + + protected override async Task OnInitializedAsync() + { + AppMService.ShowSearch = false; + AppMService.PageName = "Warehouse Area"; + AppMService.PageIcon = "fa-solid fa-warehouse pr-2"; + // rileggo dati + await ReloadData(); + } + + protected async Task SaveCust(int newCustId) + { + CustomerID = newCustId; + await ReloadData(); + } + + #endregion Protected Methods + + #region Private Fields + + private CtMode currMode = CtMode.Materials; + + private int KeyNum = 0; + + #endregion Private Fields + + #region Private Properties + + private bool isLoading { get; set; } = false; + + #endregion Private Properties + + #region Private Methods + private string IsActive(CtMode modeReq) { string answ = currMode == modeReq ? "active" : ""; return answ; } + private async Task ReloadData() + { + isLoading = true; + nKey = await MTService.MainKeyByCustomer(CustomerID); + isLoading = false; + } + private void SetMode(CtMode newMode) { currMode = newMode; } + + #endregion Private Methods } } \ No newline at end of file diff --git a/Resources/ChangeLog.html b/Resources/ChangeLog.html index 5205fbd..7f7dd06 100644 --- a/Resources/ChangeLog.html +++ b/Resources/ChangeLog.html @@ -1,6 +1,6 @@ MagMan - Wood Warehouse Management System -

Versione: 1.0.2401.1911

+

Versione: 1.0.2401.1916


Note di rilascio: