diff --git a/EgwProxy.MagMan/DTO/MaterialDTO.cs b/EgwProxy.MagMan/DTO/MaterialDTO.cs index 7965698..576b9ca 100644 --- a/EgwProxy.MagMan/DTO/MaterialDTO.cs +++ b/EgwProxy.MagMan/DTO/MaterialDTO.cs @@ -41,6 +41,6 @@ namespace EgwProxy.MagMan.DTO /// /// Elenco item e giancenze /// - public List ItemNav { get; set; } = new List(); + public List ItemList { get; set; } = new List(); } } diff --git a/EgwProxy.MagMan/DataSyncro.cs b/EgwProxy.MagMan/DataSyncro.cs index de7206e..3da4e60 100644 --- a/EgwProxy.MagMan/DataSyncro.cs +++ b/EgwProxy.MagMan/DataSyncro.cs @@ -8,6 +8,7 @@ using System.Net.NetworkInformation; using System.Net; using System.Text; using System.Text.Json.Serialization; +using RestSharp.Serializers.NewtonsoftJson; using System.Threading.Tasks; using System.Web; @@ -82,7 +83,7 @@ namespace EgwProxy.MagMan /// /// Elenco Materiali dato RestToken /// - public async Task> GetMaterials() + public async Task> MaterialsGet() { List answ = new List(); // cerco online @@ -91,21 +92,42 @@ namespace EgwProxy.MagMan var request = new RestRequest($"Materials/{MKeyEnc}", Method.Get); var response = await client.GetAsync(request); // controllo risposta - if (response.StatusCode == System.Net.HttpStatusCode.OK) + if (response.StatusCode == HttpStatusCode.OK) { - // salvo in redis contenuto serializzato + // contenuto serializzato string rawData = $"{response.Content}"; answ = JsonConvert.DeserializeObject>(rawData); } return await Task.FromResult(answ); } + /// + /// Invia un elenco (anche parziale) di Materiali, il server farà il merge + /// + public async Task MaterialsSend(List List2Merge) + { + bool answ = false; + // cerco online + var client = new RestClient(apiUrl); + string MKeyEnc = HttpUtility.UrlEncode(RestToken); + var jsonBody = JsonConvert.SerializeObject(List2Merge); + var request = new RestRequest($"Materials/upsert/{MKeyEnc}", Method.Post).AddJsonBody(jsonBody); + var response = await client.PostAsync(request); + // controllo risposta + if (response.StatusCode == HttpStatusCode.OK) + { + // contenuto serializzato + string rawData = $"{response.Content}"; + answ = rawData == "OK"; + } + return await Task.FromResult(answ); + } /// /// Inventario per materiale /// /// Se 0 = tutto /// - public async Task> GetInventario(int MatID) + public async Task> InventoryGet(int MatID) { List answ = new List(); // cerco online @@ -114,14 +136,35 @@ namespace EgwProxy.MagMan var request = new RestRequest($"Inventory/{MKeyEnc}?MatId={MatID}", Method.Get); var response = await client.GetAsync(request); // controllo risposta - if (response.StatusCode == System.Net.HttpStatusCode.OK) + if (response.StatusCode == HttpStatusCode.OK) { - // salvo in redis contenuto serializzato + // contenuto serializzato string rawData = $"{response.Content}"; answ = JsonConvert.DeserializeObject>(rawData); } return await Task.FromResult(answ); } + /// + /// Invia un elenco di RawItems associati ad un singolo materiale, il server farà il merge + /// + public async Task InventorySend(MaterialDTO Mat2Merge) + { + bool answ = false; + // cerco online + var client = new RestClient(apiUrl); + string MKeyEnc = HttpUtility.UrlEncode(RestToken); + var jsonBody = JsonConvert.SerializeObject(Mat2Merge.ItemList); + var request = new RestRequest($"Inventory/upsert/{MKeyEnc}", Method.Post).AddJsonBody(jsonBody); + var response = await client.PostAsync(request); + // controllo risposta + if (response.StatusCode == HttpStatusCode.OK) + { + // contenuto serializzato + string rawData = $"{response.Content}"; + answ = rawData == "OK"; + } + return await Task.FromResult(answ); + } #endregion Public Methods diff --git a/EgwProxy.MagMan/EgwProxy.MagMan.csproj b/EgwProxy.MagMan/EgwProxy.MagMan.csproj index 52d493b..25c7dfa 100644 --- a/EgwProxy.MagMan/EgwProxy.MagMan.csproj +++ b/EgwProxy.MagMan/EgwProxy.MagMan.csproj @@ -35,7 +35,7 @@ ..\packages\Microsoft.Bcl.AsyncInterfaces.7.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll - ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll + ..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll ..\packages\RestSharp.110.2.0\lib\net471\RestSharp.dll @@ -58,8 +58,8 @@ ..\packages\System.Text.Encodings.Web.7.0.0\lib\net462\System.Text.Encodings.Web.dll - - ..\packages\System.Text.Json.7.0.2\lib\net462\System.Text.Json.dll + + ..\packages\System.Text.Json.7.0.3\lib\net462\System.Text.Json.dll ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll diff --git a/EgwProxy.MagMan/app.config b/EgwProxy.MagMan/app.config index 1696df6..8922cd8 100644 --- a/EgwProxy.MagMan/app.config +++ b/EgwProxy.MagMan/app.config @@ -6,6 +6,14 @@ + + + + + + + + \ No newline at end of file diff --git a/EgwProxy.MagMan/packages.config b/EgwProxy.MagMan/packages.config index f734988..c5ca275 100644 --- a/EgwProxy.MagMan/packages.config +++ b/EgwProxy.MagMan/packages.config @@ -1,14 +1,14 @@  - + - + \ No newline at end of file diff --git a/MagMan.Core/DTO/ItemDTO.cs b/MagMan.Core/DTO/ItemDTO.cs index 0fcdf5b..ab807f2 100644 --- a/MagMan.Core/DTO/ItemDTO.cs +++ b/MagMan.Core/DTO/ItemDTO.cs @@ -12,7 +12,12 @@ namespace MagMan.Core.DTO /// /// Ext ref for Material /// - public int MatID { get; set; } = 0; + public int MatId { get; set; } = 0; + + /// + /// Key del RawItem di riferimento (se zero da verificare con quote) + /// + public int RawItemId { get; set; } = 0; /// /// Check if is a Remnant diff --git a/MagMan.Core/DTO/MaterialDTO.cs b/MagMan.Core/DTO/MaterialDTO.cs index a6fddc3..5ab8283 100644 --- a/MagMan.Core/DTO/MaterialDTO.cs +++ b/MagMan.Core/DTO/MaterialDTO.cs @@ -9,7 +9,7 @@ namespace MagMan.Core.DTO public class MaterialDTO { /// - /// Primary Key AUTO, 0 se proviente da EgtBeamWall + /// Primary Key Materiale, 0 se proviente da EgtBeamWall /// public int MatId { get; set; } = 0; diff --git a/MagMan.Core/DTO/ProjectDTO.cs b/MagMan.Core/DTO/ProjectDTO.cs new file mode 100644 index 0000000..b8bb59c --- /dev/null +++ b/MagMan.Core/DTO/ProjectDTO.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static MagMan.Core.Enums; + +namespace MagMan.Core.DTO +{ + public class ProjectDTO + { + /// + /// Id macchina (MagMan) + /// + public int MachineID { get; set; } = 0; + + /// + /// Key di riferimento per il progetto + /// + public int KeyNum { get; set; } = 0; + + /// + /// ID del DB EgtBW, univoco con KeyNum + /// + public int ProjExtDbId { get; set; } = 0; + + /// + /// ID esterno (da EgtBW) + /// + public int ProjExtId { get; set; } = 0; + + /// + /// Nome file BTL originale + /// + public string BTLFileName { get; set; } = ""; + + /// + /// Tipologia del progetto (Travi, Pareti, ...) + /// + public BWType PType { get; set; } = BWType.NULL; + + /// + /// Macchina (Costruttore/Modello) + /// + public string Machine { get; set; } = ""; + + /// + /// Descrizione progetto (copiata da BTLFileName inizialmente) + /// + public string ProjDescription { get; set; } = ""; + + /// + /// Data Creazione progetto + /// + public DateTime DtCreated { get; set; } = DateTime.Now; + + /// + /// Data di schedulazione (prevista) + /// + public DateTime DtSchedule { get; set; } = DateTime.Today.AddMonths(3); + + /// + /// Data Inizio Produzione + /// + public DateTime DtStartProd { get; set; } = DateTime.MinValue; + + /// + /// Data ora ultima operazione registrata + /// + public DateTime DtLastAction { get; set; } = DateTime.MinValue; + + /// + /// ListName del BTL + /// + public string ListName { get; set; } = ""; + + /// + /// Tempo lavorazione previsto (stima) in minuti + /// + public double ProcTimeEst { get; set; } = 0; + + /// + /// Tempo lavorazione reale in minuti (parziale o totale se chiuso/completato/archiviato) + /// + public double ProcTimeReal { get; set; } = 0; + + /// + /// Record attivo (se false == cancellazione logica) + /// + public bool IsActive { get; set; } = true; + + /// + /// Stato Archiviato = NON visualizzabile normalmente, già prodotto/chiuso + /// + public bool IsArchived { get; set; } = false; + + } +} diff --git a/MagMan.Core/DTO/ResourceDTO.cs b/MagMan.Core/DTO/ResourceDTO.cs new file mode 100644 index 0000000..510bf11 --- /dev/null +++ b/MagMan.Core/DTO/ResourceDTO.cs @@ -0,0 +1,22 @@ +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 ResourceDTO + { + /// + /// Ext ref for Material + /// + public int RawItemId { get; set; } = 0; + /// + /// Qty, se > 0 rappresenta un IMPEGNO di qualsiasi tipo, se < 0 è un CONSUMO + /// + public int Qty { get; set; } = 0; + + } +} diff --git a/MagMan.Core/Enums.cs b/MagMan.Core/Enums.cs index 6b76686..4df7c47 100644 --- a/MagMan.Core/Enums.cs +++ b/MagMan.Core/Enums.cs @@ -22,11 +22,27 @@ namespace MagMan.Core Request, } - public enum RequestStatus + public enum ProjResState { - None = 0, + /// + /// Registrazione consumo effettivo (update giacenza su tab RawItemList) + /// + Consumed = -1, + /// + /// Non definito + /// + ND = 0, + /// + /// Consumo stimato da nesting (solo simulazione) + /// Estimated, + /// + /// Consumo confermato (da ordinare) + /// Confirmed, + /// + /// Riservato (utile x calcolo quantità da ordinare) + /// Reserved } @@ -37,6 +53,7 @@ namespace MagMan.Core RESULT = 2 } + #endregion Public Enums } } \ No newline at end of file diff --git a/MagMan.Core/MagMan.Core.csproj b/MagMan.Core/MagMan.Core.csproj index 3636131..934f236 100644 --- a/MagMan.Core/MagMan.Core.csproj +++ b/MagMan.Core/MagMan.Core.csproj @@ -7,7 +7,7 @@ - + diff --git a/MagMan.Core/RestPayload.cs b/MagMan.Core/RestPayload.cs index 106465b..7566fc5 100644 --- a/MagMan.Core/RestPayload.cs +++ b/MagMan.Core/RestPayload.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using MagMan.Core.DTO; +using static MagMan.Core.Enums; namespace MagMan.Core { @@ -23,5 +24,21 @@ namespace MagMan.Core /// public List? ItemList { get; set; } } + + public class Resources + { + /// + /// ID progetto univoco esterno (da associare a KEY) + /// + public int ProjDbId { get; set; } = 0; + /// + /// Tipo di registrazione dato inviata (previsione consumo, consumo effettivo...) + /// + public ProjResState ReqState { get; set; } = ProjResState.ND; + /// + /// Elenco Risorse x invio POST + /// + public List? ResourceList { get; set; } + } } } diff --git a/MagMan.Core/Services/MessageService.cs b/MagMan.Core/Services/MessageService.cs index f7278a0..a3dc8dc 100644 --- a/MagMan.Core/Services/MessageService.cs +++ b/MagMan.Core/Services/MessageService.cs @@ -131,6 +131,23 @@ namespace MagMan.Core.Services } } + /// + /// Cliente selezionato (da browser data cache) + /// + public async Task ClientIdGet() + { + var answ = await localStore.GetItemAsync("ClientID"); + return answ; + } + + /// + /// Imposta Cliente selezionato (browser data cache) + /// + public async Task ClientIdSet(int machSel) + { + await localStore.SetItemAsync("ClientID", machSel); + } + #endregion Public Properties #region Public Methods diff --git a/MagMan.Data.Admin/MagMan.Data.Admin.csproj b/MagMan.Data.Admin/MagMan.Data.Admin.csproj index 2406b07..b222b78 100644 --- a/MagMan.Data.Admin/MagMan.Data.Admin.csproj +++ b/MagMan.Data.Admin/MagMan.Data.Admin.csproj @@ -15,7 +15,7 @@ - + diff --git a/MagMan.Data.Tenant/Controllers/TenantController.cs b/MagMan.Data.Tenant/Controllers/TenantController.cs index 1826f8f..44fe134 100644 --- a/MagMan.Data.Tenant/Controllers/TenantController.cs +++ b/MagMan.Data.Tenant/Controllers/TenantController.cs @@ -1,4 +1,5 @@ using MagMan.Data.Tenant.DbModels; +using MagMan.Data.Tenant.Services; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using NLog; @@ -117,6 +118,43 @@ namespace MagMan.Data.Tenant.Controllers return dbResult; } + /// Aggiunge/Modifica un item in magazzino Stringa connessione (variabile x cliente) Record da aggiornare quantità da + /// aggiornare (se <0 è consumo) + public bool ItemModQty(string connString, RawItemModel rec2upd, int deltaQty) + { + bool done = false; + using (MagManContext dbCtx = new MagManContext(connString)) + { + try + { + /* + * Verifica se esistesse: deve essere valido TUTTO + * - stesso materiale + * - stesse dimensioni + * */ + var currData = dbCtx + .DbSetItems + .Where(x => (x.RawItemId == rec2upd.RawItemId) || + (x.MatId == rec2upd.MatId && (x.WMm == rec2upd.WMm && x.HMm == rec2upd.HMm && x.LMm == rec2upd.LMm))) + .FirstOrDefault(); + if (currData != null) + { + currData.QtyAvail += deltaQty; + dbCtx.Entry(currData).State = EntityState.Modified; + } + dbCtx.SaveChanges(); + done = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione in ItemModQty{Environment.NewLine}{exc}"); + } + } + return done; + } + /// /// Aggiunge/Modifica un item in magazzino /// @@ -238,12 +276,11 @@ namespace MagMan.Data.Tenant.Controllers } return dbResult; } /// - /// Elenco Materiali gestiti a magazzino - /// - /// Stringa connessione (variabile x cliente) - /// Materiale richiesto, 0 = tutti - /// Se true allora include record child (Items) - /// + + /// Elenco Materiali gestiti a magazzino Stringa + /// connessione (variabile x cliente) Materiale richiesto, 0 + /// = tutti Se true allora include record child + /// (Items) public List MaterialGetFilt(string connString, int matID, bool withChild) { List dbResult = new List(); @@ -290,8 +327,8 @@ namespace MagMan.Data.Tenant.Controllers try { /* - * Ricerca equal: corrisponde se - * - MatID identico + * Ricerca equal: corrisponde se + * - MatId identico * - se Uguali + NonNulli [MatCode oppure MatDescript] + uguali [W/H/L]... */ var currData = dbCtx @@ -327,6 +364,165 @@ namespace MagMan.Data.Tenant.Controllers return done; } + /// + /// Elimina record Project + /// + /// Stringa connessione (variabile x cliente) + /// Item da eliminare + /// + public bool ProjectDelete(string connString, ProjModel rec2del) + { + bool done = false; + using (MagManContext dbCtx = new MagManContext(connString)) + { + try + { + var currData = dbCtx + .DbSetProjects + .Where(x => x.ProjDbId == rec2del.ProjDbId) + .FirstOrDefault(); + if (currData != null) + { + dbCtx + .DbSetProjects + .Remove(currData); + dbCtx.SaveChanges(); + done = true; + } + } + catch (Exception exc) + { + Log.Error($"Eccezione in ProjectDelete{Environment.NewLine}{exc}"); + } + } + return done; + } + + /// + /// Elenco Projects (all) + /// + /// Stringa connessione (variabile x cliente) + /// + public List ProjectGetAll(string connString) + { + List dbResult = new List(); + using (MagManContext dbCtx = new MagManContext(connString)) + { + dbResult = dbCtx + .DbSetProjects + .OrderBy(x => x.DtCreated) + .ToList(); + } + return dbResult; + } + + /// + /// Elenco Items gestiti a magazzino dato Materiale + /// + /// Stringa connessione (variabile x cliente) + /// ID del materiale x cui filtrare, 0 = tutti + /// + public List ProjectGetByNumKey(string connString, int numKey) + { + List dbResult = new List(); + using (MagManContext dbCtx = new MagManContext(connString)) + { + dbResult = dbCtx + .DbSetProjects + .Where(x => numKey == 0 || x.KeyNum == numKey) + .OrderBy(x => x.DtCreated) + .ToList(); + } + return dbResult; + } + + /// + /// Elenco Items gestiti a magazzino dato Materiale + /// + /// Stringa connessione (variabile x cliente) + /// ID master key, 0 = tutti + /// periodo x filtraggio + /// + public List ProjectGetFilt(string connString, int numKey, SelectData period) + { + List dbResult = new List(); + using (MagManContext dbCtx = new MagManContext(connString)) + { + dbResult = dbCtx + .DbSetProjects + .Where(x => (numKey == 0 || x.KeyNum == numKey) && + ((x.DtCreated >= period.DateStart && x.DtCreated <= period.DateEnd) + || (x.DtSchedule >= period.DateStart && x.DtSchedule <= period.DateEnd) + || (x.DtLastAction >= period.DateStart && x.DtLastAction <= period.DateEnd) + )) + .OrderBy(x => x.DtCreated) + .ToList(); + } + return dbResult; + } + + /// + /// Aggiunge/Modifica un record Project + /// + /// Stringa connessione (variabile x cliente) + /// Record da aggiungere/aggiornare + /// + public bool ProjectUpdate(string connString, ProjModel rec2upd) + { + bool done = false; + using (MagManContext dbCtx = new MagManContext(connString)) + { + try + { + /* + * Ricerca: + * - DbId corrisponde + * - Key + Id remoti corrispondono + * */ + var currData = dbCtx + .DbSetProjects + .Where(x => (x.ProjDbId == rec2upd.ProjDbId) || + (x.ProjExtDbId == rec2upd.ProjExtDbId && x.KeyNum == rec2upd.KeyNum) || + (x.ProjExtId == rec2upd.ProjExtId && x.KeyNum == rec2upd.KeyNum)) + .FirstOrDefault(); + if (currData != null) + { + currData.MachineID = rec2upd.MachineID; + currData.KeyNum = rec2upd.KeyNum; + currData.ProjExtDbId = rec2upd.ProjExtDbId; + currData.ProjExtId = rec2upd.ProjExtId; + currData.BTLFileName = rec2upd.BTLFileName; + currData.PType = rec2upd.PType; + currData.Machine = rec2upd.Machine; + currData.ProjDescription = rec2upd.ProjDescription; + currData.DtCreated = rec2upd.DtCreated; + currData.DtLastAction = rec2upd.DtLastAction; + currData.DtSchedule = rec2upd.DtSchedule; + currData.DtStartProd = rec2upd.DtStartProd; + currData.ListName = rec2upd.ListName; + currData.ProcTimeEst = rec2upd.ProcTimeEst; + currData.ProcTimeReal = rec2upd.ProcTimeReal; + currData.IsActive = rec2upd.IsActive; + currData.IsArchived = rec2upd.IsArchived; + dbCtx.Entry(currData).State = EntityState.Modified; + } + else + { + dbCtx + .DbSetProjects + .Add(rec2upd); + } + dbCtx.SaveChanges(); + done = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione in ItemUpdate{Environment.NewLine}{exc}"); + } + } + return done; + } + #endregion Public Methods #region Private Fields diff --git a/MagMan.Data.Tenant/DbModels/MaterialModel.cs b/MagMan.Data.Tenant/DbModels/MaterialModel.cs index a0da42a..4217ef9 100644 --- a/MagMan.Data.Tenant/DbModels/MaterialModel.cs +++ b/MagMan.Data.Tenant/DbModels/MaterialModel.cs @@ -93,18 +93,21 @@ namespace MagMan.Data.Tenant.DbModels [NotMapped] public bool IsBeam { - get => LMm == 0; + get => (LMm == 0 && (HMm > 0 && WMm > 0)); } - + /// - /// Verifica che sia Wall, quando W/H == 0 + /// Verifica che sia Wall, quando W/L == 0 /// [NotMapped] public bool IsWall { - get => (HMm == 0 && WMm==0); + get => (HMm > 0 && (LMm == 0 && WMm == 0)); } + /// + /// Navigazione ad oggetti child + /// public virtual ICollection? RawItemList { get; set; } } } diff --git a/MagMan.Data.Tenant/DbModels/ProjModel.cs b/MagMan.Data.Tenant/DbModels/ProjModel.cs index 551fe40..0a124b6 100644 --- a/MagMan.Data.Tenant/DbModels/ProjModel.cs +++ b/MagMan.Data.Tenant/DbModels/ProjModel.cs @@ -20,10 +20,7 @@ namespace MagMan.Data.Tenant.DbModels [Table("ProjList")] [Index(nameof(MachineID))] [Index(nameof(KeyNum))] - [Index(nameof(DtCreated))] - [Index(nameof(DtStartProd))] - [Index(nameof(DtLastAction))] - [Index(nameof(ProjId))] + [Index(nameof(ProjExtDbId))] [Index(nameof(IsActive))] [Index(nameof(IsArchived))] public class ProjModel @@ -33,14 +30,28 @@ namespace MagMan.Data.Tenant.DbModels /// /// Chiave univoca su DB /// - [Key, Column("ProjDbId"), DatabaseGenerated(DatabaseGeneratedOption.Identity)] + [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int ProjDbId { get; set; } /// - /// ID da modello ext + /// Id macchina (MagMan) /// - [Column("Id")] - public int ProjId { get; set; } + public int MachineID { get; set; } = 0; + + /// + /// Key di riferimento per il progetto + /// + public int KeyNum { get; set; } = 0; + + /// + /// ID del DB EgtBW, univoco con KeyNum + /// + public int ProjExtDbId { get; set; } = 0; + + /// + /// ID esterno (da EgtBW) + /// + public int ProjExtId { get; set; } = 0; /// /// Nome file BTL originale @@ -52,16 +63,6 @@ namespace MagMan.Data.Tenant.DbModels /// public BWType PType { get; set; } = BWType.NULL; - /// - /// Id macchina (diMagMan) - /// - public int MachineID { get; set; } = 0; - - /// - /// Key di riferimento per il progetto - /// - public int KeyNum { get; set; } = 0; - /// /// Macchina (Costruttore/Modello) /// diff --git a/MagMan.Data.Tenant/DbModels/RequestPlanModel.cs b/MagMan.Data.Tenant/DbModels/RequestPlanModel.cs index b1b2d93..cfa204a 100644 --- a/MagMan.Data.Tenant/DbModels/RequestPlanModel.cs +++ b/MagMan.Data.Tenant/DbModels/RequestPlanModel.cs @@ -5,6 +5,7 @@ using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; +using static MagMan.Core.Enums; namespace MagMan.Data.Tenant.DbModels { @@ -17,9 +18,17 @@ namespace MagMan.Data.Tenant.DbModels [Table("RequestPlan")] public class RequestPlanModel { - [Key, Column("RequestId"), DatabaseGenerated(DatabaseGeneratedOption.Identity)] + /// + /// Init classe + /// + public RequestPlanModel() + { + ResourcesList = new HashSet(); + } + + [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int RequestId { get; set; } - + /// /// Progetto di riferimento /// @@ -28,12 +37,21 @@ namespace MagMan.Data.Tenant.DbModels /// /// Data richiesta /// - public DateTime DtRequest{ get; set; } - + public DateTime DtRequest { get; set; } /// - /// Record attivo (se false == NON è il piano scelto) + /// Tipo richiesta + /// + public ProjResState ReqState { get; set; } = ProjResState.ND; + + /// + /// Record attivo (se false == NON è il piano scelto per i casi "previsionali" = ReqState >0 ) /// public bool IsActive { get; set; } = true; + + /// + /// Navigazione ad oggetti child + /// + public virtual ICollection? ResourcesList { get; set; } } } diff --git a/MagMan.Data.Tenant/DbModels/RequestDetailModel.cs b/MagMan.Data.Tenant/DbModels/ResourceModel.cs similarity index 51% rename from MagMan.Data.Tenant/DbModels/RequestDetailModel.cs rename to MagMan.Data.Tenant/DbModels/ResourceModel.cs index fadaf41..e8e2a45 100644 --- a/MagMan.Data.Tenant/DbModels/RequestDetailModel.cs +++ b/MagMan.Data.Tenant/DbModels/ResourceModel.cs @@ -13,29 +13,33 @@ namespace MagMan.Data.Tenant.DbModels // This is here so CodeMaid doesn't reorganize this document // /// - /// Tabella esplosione richieste come items + /// Tabella esplosione risorse (richiesta + items) /// - [Table("RequestDetail")] - public class RequestDetailModel + [Table("ResourceList")] + public class ResourceModel { + [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int ResourceId { get; set; } + /// - /// Riferimento Richiesta + /// Riferimento richiesta parent /// public int RequestId { get; set; } = 0; /// - /// Riferimento Item specifico + /// Riferimento RawItem specifico /// - public int ItemID { get; set; } = 0; + public int RawItemId { get; set; } = 0; /// - /// Quantità necessaria + /// Qty, se > 0 rappresenta un IMPEGNO di qualsiasi tipo, se < 0 è un CONSUMO /// - public int QtyReq { get; set; } = 0; + public int Qty { get; set; } = 0; /// - /// Stato richeista + /// Navigation property to RequestPlan /// - public RequestStatus ReqState { get; set; } = RequestStatus.None; + [ForeignKey("RequestId")] + public virtual RequestPlanModel RequestNav { get; set; } = null!; } } diff --git a/MagMan.Data.Tenant/MagMan.Data.Tenant.csproj b/MagMan.Data.Tenant/MagMan.Data.Tenant.csproj index 1986e8e..b27104d 100644 --- a/MagMan.Data.Tenant/MagMan.Data.Tenant.csproj +++ b/MagMan.Data.Tenant/MagMan.Data.Tenant.csproj @@ -17,7 +17,7 @@ - + diff --git a/MagMan.Data.Tenant/MagManContext.cs b/MagMan.Data.Tenant/MagManContext.cs index 02e8cdd..0be9330 100644 --- a/MagMan.Data.Tenant/MagManContext.cs +++ b/MagMan.Data.Tenant/MagManContext.cs @@ -43,8 +43,9 @@ namespace MagMan.Data.Tenant public virtual DbSet DbSetMaterials { get; set; } = null!; public virtual DbSet DbSetRawItem { get; set; } = null!; public virtual DbSet DbSetAlias { get; set; } = null!; + public virtual DbSet DbSetProjects { get; set; } = null!; public virtual DbSet DbSetReqPlan { get; set; } = null!; - public virtual DbSet DbSetReqDet{ get; set; } = null!; + public virtual DbSet DbSetResources { get; set; } = null!; #if false @@ -90,9 +91,6 @@ namespace MagMan.Data.Tenant .HasComment("Valore di default/riferimento per la variabile"); }); - modelBuilder.Entity() - .HasKey(c => new { c.RequestId, c.ItemID }); - modelBuilder.Entity() .HasKey(c => new { c.Family, c.ValueOriginal}); diff --git a/MagMan.Data.Tenant/Migrations/20240118161646_InitDb.Designer.cs b/MagMan.Data.Tenant/Migrations/20240122174314_InitDb.Designer.cs similarity index 64% rename from MagMan.Data.Tenant/Migrations/20240118161646_InitDb.Designer.cs rename to MagMan.Data.Tenant/Migrations/20240122174314_InitDb.Designer.cs index f6c513d..e10b66d 100644 --- a/MagMan.Data.Tenant/Migrations/20240118161646_InitDb.Designer.cs +++ b/MagMan.Data.Tenant/Migrations/20240122174314_InitDb.Designer.cs @@ -11,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace MagMan.Data.Tenant.Migrations { [DbContext(typeof(MagManContext))] - [Migration("20240118161646_InitDb")] + [Migration("20240122174314_InitDb")] partial class InitDb { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -97,6 +97,82 @@ namespace MagMan.Data.Tenant.Migrations b.ToTable("MaterialsList"); }); + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.ProjModel", b => + { + b.Property("ProjDbId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("BTLFileName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("DtCreated") + .HasColumnType("datetime(6)"); + + b.Property("DtLastAction") + .HasColumnType("datetime(6)"); + + b.Property("DtSchedule") + .HasColumnType("datetime(6)"); + + b.Property("DtStartProd") + .HasColumnType("datetime(6)"); + + b.Property("IsActive") + .HasColumnType("tinyint(1)"); + + b.Property("IsArchived") + .HasColumnType("tinyint(1)"); + + b.Property("KeyNum") + .HasColumnType("int"); + + b.Property("ListName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Machine") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("MachineID") + .HasColumnType("int"); + + b.Property("PType") + .HasColumnType("int"); + + b.Property("ProcTimeEst") + .HasColumnType("double"); + + b.Property("ProcTimeReal") + .HasColumnType("double"); + + b.Property("ProjDescription") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ProjExtDbId") + .HasColumnType("int"); + + b.Property("ProjExtId") + .HasColumnType("int"); + + b.HasKey("ProjDbId"); + + b.HasIndex("IsActive"); + + b.HasIndex("IsArchived"); + + b.HasIndex("KeyNum"); + + b.HasIndex("MachineID"); + + b.HasIndex("ProjExtDbId"); + + b.ToTable("ProjList"); + }); + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.RawItemModel", b => { b.Property("RawItemId") @@ -139,31 +215,11 @@ namespace MagMan.Data.Tenant.Migrations b.ToTable("RawItemList"); }); - modelBuilder.Entity("MagMan.Data.Tenant.DbModels.RequestDetailModel", b => - { - b.Property("RequestId") - .HasColumnType("int"); - - b.Property("ItemID") - .HasColumnType("int"); - - b.Property("QtyReq") - .HasColumnType("int"); - - b.Property("ReqState") - .HasColumnType("int"); - - b.HasKey("RequestId", "ItemID"); - - b.ToTable("RequestDetail"); - }); - modelBuilder.Entity("MagMan.Data.Tenant.DbModels.RequestPlanModel", b => { b.Property("RequestId") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasColumnName("RequestId"); + .HasColumnType("int"); b.Property("DtRequest") .HasColumnType("datetime(6)"); @@ -174,11 +230,36 @@ namespace MagMan.Data.Tenant.Migrations b.Property("ProjDbId") .HasColumnType("int"); + b.Property("ReqState") + .HasColumnType("int"); + b.HasKey("RequestId"); b.ToTable("RequestPlan"); }); + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.ResourceModel", b => + { + b.Property("ResourceId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Qty") + .HasColumnType("int"); + + b.Property("RawItemId") + .HasColumnType("int"); + + b.Property("RequestId") + .HasColumnType("int"); + + b.HasKey("ResourceId"); + + b.HasIndex("RequestId"); + + b.ToTable("ResourceList"); + }); + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.RawItemModel", b => { b.HasOne("MagMan.Data.Tenant.DbModels.MaterialModel", "MaterialNav") @@ -190,10 +271,26 @@ namespace MagMan.Data.Tenant.Migrations b.Navigation("MaterialNav"); }); + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.ResourceModel", b => + { + b.HasOne("MagMan.Data.Tenant.DbModels.RequestPlanModel", "RequestNav") + .WithMany("ResourcesList") + .HasForeignKey("RequestId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("RequestNav"); + }); + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.MaterialModel", b => { b.Navigation("RawItemList"); }); + + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.RequestPlanModel", b => + { + b.Navigation("ResourcesList"); + }); #pragma warning restore 612, 618 } } diff --git a/MagMan.Data.Tenant/Migrations/20240118161646_InitDb.cs b/MagMan.Data.Tenant/Migrations/20240122174314_InitDb.cs similarity index 63% rename from MagMan.Data.Tenant/Migrations/20240118161646_InitDb.cs rename to MagMan.Data.Tenant/Migrations/20240122174314_InitDb.cs index 2760326..57b8471 100644 --- a/MagMan.Data.Tenant/Migrations/20240118161646_InitDb.cs +++ b/MagMan.Data.Tenant/Migrations/20240122174314_InitDb.cs @@ -70,17 +70,36 @@ namespace MagMan.Data.Tenant.Migrations .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( - name: "RequestDetail", + name: "ProjList", columns: table => new { - RequestId = table.Column(type: "int", nullable: false), - ItemID = table.Column(type: "int", nullable: false), - QtyReq = table.Column(type: "int", nullable: false), - ReqState = table.Column(type: "int", nullable: false) + ProjDbId = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + MachineID = table.Column(type: "int", nullable: false), + KeyNum = table.Column(type: "int", nullable: false), + ProjExtDbId = table.Column(type: "int", nullable: false), + ProjExtId = table.Column(type: "int", nullable: false), + BTLFileName = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + PType = table.Column(type: "int", nullable: false), + Machine = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + ProjDescription = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + DtCreated = table.Column(type: "datetime(6)", nullable: false), + DtSchedule = table.Column(type: "datetime(6)", nullable: false), + DtStartProd = table.Column(type: "datetime(6)", nullable: false), + DtLastAction = table.Column(type: "datetime(6)", nullable: false), + ListName = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + ProcTimeEst = table.Column(type: "double", nullable: false), + ProcTimeReal = table.Column(type: "double", nullable: false), + IsActive = table.Column(type: "tinyint(1)", nullable: false), + IsArchived = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_RequestDetail", x => new { x.RequestId, x.ItemID }); + table.PrimaryKey("PK_ProjList", x => x.ProjDbId); }) .Annotation("MySql:CharSet", "utf8mb4"); @@ -92,6 +111,7 @@ namespace MagMan.Data.Tenant.Migrations .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), ProjDbId = table.Column(type: "int", nullable: false), DtRequest = table.Column(type: "datetime(6)", nullable: false), + ReqState = table.Column(type: "int", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => @@ -130,10 +150,62 @@ namespace MagMan.Data.Tenant.Migrations }) .Annotation("MySql:CharSet", "utf8mb4"); + migrationBuilder.CreateTable( + name: "ResourceList", + columns: table => new + { + ResourceId = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + RequestId = table.Column(type: "int", nullable: false), + RawItemId = table.Column(type: "int", nullable: false), + Qty = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ResourceList", x => x.ResourceId); + table.ForeignKey( + name: "FK_ResourceList_RequestPlan_RequestId", + column: x => x.RequestId, + principalTable: "RequestPlan", + principalColumn: "RequestId", + onDelete: ReferentialAction.Restrict); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateIndex( + name: "IX_ProjList_IsActive", + table: "ProjList", + column: "IsActive"); + + migrationBuilder.CreateIndex( + name: "IX_ProjList_IsArchived", + table: "ProjList", + column: "IsArchived"); + + migrationBuilder.CreateIndex( + name: "IX_ProjList_KeyNum", + table: "ProjList", + column: "KeyNum"); + + migrationBuilder.CreateIndex( + name: "IX_ProjList_MachineID", + table: "ProjList", + column: "MachineID"); + + migrationBuilder.CreateIndex( + name: "IX_ProjList_ProjExtDbId", + table: "ProjList", + column: "ProjExtDbId"); + migrationBuilder.CreateIndex( name: "IX_RawItemList_MatId", table: "RawItemList", column: "MatId"); + + migrationBuilder.CreateIndex( + name: "IX_ResourceList_RequestId", + table: "ResourceList", + column: "RequestId"); } protected override void Down(MigrationBuilder migrationBuilder) @@ -144,17 +216,20 @@ namespace MagMan.Data.Tenant.Migrations migrationBuilder.DropTable( name: "Config"); + migrationBuilder.DropTable( + name: "ProjList"); + migrationBuilder.DropTable( name: "RawItemList"); migrationBuilder.DropTable( - name: "RequestDetail"); - - migrationBuilder.DropTable( - name: "RequestPlan"); + name: "ResourceList"); migrationBuilder.DropTable( name: "MaterialsList"); + + migrationBuilder.DropTable( + name: "RequestPlan"); } } } diff --git a/MagMan.Data.Tenant/Migrations/MagManContextModelSnapshot.cs b/MagMan.Data.Tenant/Migrations/MagManContextModelSnapshot.cs index fea0ff6..37bfa7e 100644 --- a/MagMan.Data.Tenant/Migrations/MagManContextModelSnapshot.cs +++ b/MagMan.Data.Tenant/Migrations/MagManContextModelSnapshot.cs @@ -95,6 +95,82 @@ namespace MagMan.Data.Tenant.Migrations b.ToTable("MaterialsList"); }); + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.ProjModel", b => + { + b.Property("ProjDbId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("BTLFileName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("DtCreated") + .HasColumnType("datetime(6)"); + + b.Property("DtLastAction") + .HasColumnType("datetime(6)"); + + b.Property("DtSchedule") + .HasColumnType("datetime(6)"); + + b.Property("DtStartProd") + .HasColumnType("datetime(6)"); + + b.Property("IsActive") + .HasColumnType("tinyint(1)"); + + b.Property("IsArchived") + .HasColumnType("tinyint(1)"); + + b.Property("KeyNum") + .HasColumnType("int"); + + b.Property("ListName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Machine") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("MachineID") + .HasColumnType("int"); + + b.Property("PType") + .HasColumnType("int"); + + b.Property("ProcTimeEst") + .HasColumnType("double"); + + b.Property("ProcTimeReal") + .HasColumnType("double"); + + b.Property("ProjDescription") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ProjExtDbId") + .HasColumnType("int"); + + b.Property("ProjExtId") + .HasColumnType("int"); + + b.HasKey("ProjDbId"); + + b.HasIndex("IsActive"); + + b.HasIndex("IsArchived"); + + b.HasIndex("KeyNum"); + + b.HasIndex("MachineID"); + + b.HasIndex("ProjExtDbId"); + + b.ToTable("ProjList"); + }); + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.RawItemModel", b => { b.Property("RawItemId") @@ -137,31 +213,11 @@ namespace MagMan.Data.Tenant.Migrations b.ToTable("RawItemList"); }); - modelBuilder.Entity("MagMan.Data.Tenant.DbModels.RequestDetailModel", b => - { - b.Property("RequestId") - .HasColumnType("int"); - - b.Property("ItemID") - .HasColumnType("int"); - - b.Property("QtyReq") - .HasColumnType("int"); - - b.Property("ReqState") - .HasColumnType("int"); - - b.HasKey("RequestId", "ItemID"); - - b.ToTable("RequestDetail"); - }); - modelBuilder.Entity("MagMan.Data.Tenant.DbModels.RequestPlanModel", b => { b.Property("RequestId") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasColumnName("RequestId"); + .HasColumnType("int"); b.Property("DtRequest") .HasColumnType("datetime(6)"); @@ -172,11 +228,36 @@ namespace MagMan.Data.Tenant.Migrations b.Property("ProjDbId") .HasColumnType("int"); + b.Property("ReqState") + .HasColumnType("int"); + b.HasKey("RequestId"); b.ToTable("RequestPlan"); }); + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.ResourceModel", b => + { + b.Property("ResourceId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Qty") + .HasColumnType("int"); + + b.Property("RawItemId") + .HasColumnType("int"); + + b.Property("RequestId") + .HasColumnType("int"); + + b.HasKey("ResourceId"); + + b.HasIndex("RequestId"); + + b.ToTable("ResourceList"); + }); + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.RawItemModel", b => { b.HasOne("MagMan.Data.Tenant.DbModels.MaterialModel", "MaterialNav") @@ -188,10 +269,26 @@ namespace MagMan.Data.Tenant.Migrations b.Navigation("MaterialNav"); }); + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.ResourceModel", b => + { + b.HasOne("MagMan.Data.Tenant.DbModels.RequestPlanModel", "RequestNav") + .WithMany("ResourcesList") + .HasForeignKey("RequestId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("RequestNav"); + }); + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.MaterialModel", b => { b.Navigation("RawItemList"); }); + + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.RequestPlanModel", b => + { + b.Navigation("ResourcesList"); + }); #pragma warning restore 612, 618 } } diff --git a/MagMan.Data.Tenant/Services/MessageService.cs b/MagMan.Data.Tenant/Services/MessageService.cs deleted file mode 100644 index 0ad9e5c..0000000 --- a/MagMan.Data.Tenant/Services/MessageService.cs +++ /dev/null @@ -1,481 +0,0 @@ -using Blazored.LocalStorage; -using Blazored.SessionStorage; -using Microsoft.Extensions.Configuration; -using NLog; -using NLog.Fluent; -using StackExchange.Redis; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Reflection.Metadata; -using System.Text; -using System.Threading.Tasks; - -namespace MagMan.Data.Tenant.Services -{ - public class MessageService - { - #region Public Events - - public event Action EA_FilterUpdated = null!; - - public event Action EA_HideSearch = null!; - - public event Action EA_PageUpdated = null!; - - public event Action EA_SearchUpdated = null!; - - public event Action EA_ShowSearch = null!; - - #endregion Public Events - - #region Public Properties - - public SelectData DetailFilter - { - get => _detailFilter; - set - { - if (_detailFilter != value) - { - _detailFilter = value; - - if (EA_FilterUpdated != null) - { - EA_FilterUpdated?.Invoke(); - } - } - } - } - - public SelectOrderData Order_Filter { get; set; } = SelectOrderData.Init(5, 30); - - public string PageIcon - { - get => _pageIcon; - set - { - if (_pageIcon != value) - { - _pageIcon = value; - ReportPageUpd(); - } - } - } - - public string PageName - { - get => _pageName; - set - { - if (_pageName != value) - { - _pageName = value; - ReportPageUpd(); - } - } - } - - public string SearchVal - { - get => _searchVal; - set - { - if (_searchVal != value) - { - _searchVal = value; - - if (EA_SearchUpdated != null) - { - EA_SearchUpdated?.Invoke(); - } - } - } - } - - public string SelOrderCode { get; set; } = ""; - public string SelPlantId { get; set; } = "0"; - - public bool ShowSearch - { - get => _showSearch; - set - { - if (_showSearch != value) - { - _showSearch = value; - if (_showSearch) - { - if (EA_ShowSearch != null) - { - EA_ShowSearch?.Invoke(); - } - } - else - { - if (EA_HideSearch != null) - { - EA_HideSearch?.Invoke(); - } - } - } - } - } - - #endregion Public Properties - - public MessageService(IConfiguration configuration, ILocalStorageService genLocalStorage, ISessionStorageService sessStore) - { - _configuration = configuration; - // gestione sessioni in browser - localStore = genLocalStorage; - sessionStore = sessStore; - // setup compoenti REDIS - redisConn = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("Redis")); - redisDb = redisConn.GetDatabase(); - } - protected static IConfiguration _configuration = null!; - - #region Public Methods - - /// - /// Svuota localstorage (clear) - /// - /// - public async Task StoreLocalClear() - { - bool answ = false; - try - { - await localStore.ClearAsync(); - answ = true; - } - catch (Exception ex) - { - Log.Error($"Eccezione in StoreLocalClear{Environment.NewLine}{ex}"); - } - return answ; - } - - /// - /// Restituisce il valore richiesto da localstorage - /// - /// Chiave - /// - public async Task StoreLocalGet(string sKey) - { - string answ = ""; - var result = await localStore.GetItemAsync(sKey); - if (result != null) - { - answ = result; - } - return answ; - } - - /// - /// Scrive il valore nel localstorage - /// - /// Chiave - /// Valore associato - /// - public async Task StoreLocalSet(string sKey, string sVal) - { - bool answ = false; - try - { - await localStore.SetItemAsStringAsync(sKey, sVal); - answ = true; - } - catch (Exception ex) - { - Log.Error($"Eccezione in StoreLocalSet{Environment.NewLine}{ex}"); - } - return answ; - } - - /// - /// Svuota sessionstorage (clear) - /// - /// - public async Task StoreSessClear() - { - bool answ = false; - try - { - await sessionStore.ClearAsync(); - answ = true; - } - catch (Exception ex) - { - Log.Error($"Eccezione in StoreLocalClear{Environment.NewLine}{ex}"); - } - return answ; - } - - /// - /// Restituisce il valore richiesto da sessionstorage - /// - /// Chiave - /// - public async Task StoreSessGet(string sKey) - { - string answ = ""; - var result = await sessionStore.GetItemAsync(sKey); - if (result != null) - { - answ = result; - } - return answ; - } - - /// - /// Scrive il valore nel sessionstorage (tab) - /// - /// Chiave - /// Valore associato - /// - public async Task StoreSessSet(string sKey, string sVal) - { - bool answ = false; - try - { - await sessionStore.SetItemAsStringAsync(sKey, sVal); - answ = true; - } - catch (Exception ex) - { - Log.Error($"Eccezione in StoreSessSet{Environment.NewLine}{ex}"); - } - return answ; - } - - #endregion Public Methods - - #region Protected Properties - - protected ILocalStorageService localStore { get; set; } = null!; - protected ISessionStorageService sessionStore { get; set; } = null!; - - #endregion Protected Properties - - #region Private Fields - - private SelectData _detailFilter = SelectData.Init(5, 15); - private string _pageIcon = ""; - private string _pageName = ""; - private string _searchVal = ""; - private bool _showSearch = false; - private Logger Log = LogManager.GetCurrentClassLogger(); - - #endregion Private Fields - - #region Private Methods - - private void ReportPageUpd() - { - if (EA_PageUpdated != null) - { - EA_PageUpdated?.Invoke(); - } - } - - private void ReportSearch() - { - if (EA_SearchUpdated != null) - { - EA_SearchUpdated?.Invoke(); - } - } - - #endregion Private Methods - - /// - /// Recupero HashSet redis come Dictionary - /// - /// - /// - private Dictionary RedisHashDictGet(RedisKey currKey) - { - Dictionary answ = new Dictionary(); - try - { - answ = redisDb - .HashGetAll(currKey) - .ToDictionary(x => $"{x.Name}", x => $"{x.Value}"); - } - catch (Exception exc) - { - Log.Info($"Errore RedisHashDictGet | currKey: {currKey}{Environment.NewLine}{exc}"); - } - return answ; - } - /// - /// Oggetto per connessione a REDIS - /// - protected ConnectionMultiplexer redisConn = null!; - - /// - /// Oggetto DB redis da impiegare x chiamate R/W - /// - protected IDatabase redisDb = null!; - - /// - /// Salvataggio Dictionary come HashSet Redis - /// - /// - /// - private bool RedisHashDictSet(RedisKey currKey, Dictionary dict) - { - bool fatto = false; - try - { - HashEntry[] data2ins = new HashEntry[dict.Count]; - int i = 0; - foreach (KeyValuePair kvp in dict) - { - data2ins[i] = new HashEntry(kvp.Key, kvp.Value); - i++; - } - // salvo! - redisDb.HashSet(currKey, data2ins); - fatto = true; - } - catch (Exception exc) - { - Log.Error($"Eccezione in RedisHashDictSet | currKey: {currKey}{Environment.NewLine}{exc}"); - } - return fatto; - } - /// - /// Salvataggio Dictionary come HashSet Redis - /// - /// - /// - /// - private bool RedisHashDictSet(RedisKey currKey, Dictionary dict, TimeSpan ttl) - { - bool fatto = false; - try - { - HashEntry[] data2ins = new HashEntry[dict.Count]; - int i = 0; - foreach (KeyValuePair kvp in dict) - { - data2ins[i] = new HashEntry(kvp.Key, kvp.Value); - i++; - } - // salvo! - redisDb.HashSet(currKey, data2ins); - redisDb.KeyExpire(currKey, ttl); - fatto = true; - } - catch (Exception exc) - { - Log.Error($"Eccezione in RedisHashDictSet(+TTL) | currKey: {currKey} | ttl: {ttl}{Environment.NewLine}{exc}"); - } - return fatto; - } - /// - /// Effettua upsert in HasList redis - /// - /// Chiave redis della Hashlist - /// Chiave nella HashList - /// Valore da salvare - /// Num record nella HashList - protected async Task RedisHashUpsert(RedisKey currKey, string chiave, string valore) - { - long numReq = 0; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - await redisDb.HashSetAsync(currKey, chiave, valore); - numReq = await redisDb.HashLengthAsync(currKey); - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Trace($"RedisHashUpsert | {currKey} | in: {ts.TotalMilliseconds} ms"); - return numReq; - } - /// - /// Get single hash record - /// - /// Redis Key for Hashlist - /// Requested key on list - /// Value as Int - public async Task RedisHashGetInt(RedisKey currKey, string chiave) - { - int result = 0; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - var hasVal = await redisDb.HashExistsAsync(currKey, chiave); - if (hasVal) - { - var rawRes = await redisDb.HashGetAsync(currKey, chiave); - if (rawRes.HasValue) - { - int.TryParse($"{rawRes}", out result); - } - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Trace($"RedisHashGetInt | {currKey} | in: {ts.TotalMilliseconds} ms"); - return result; - } - - /// - /// Get single hash record - /// - /// Redis Key for Hashlist - /// Requested key on list - /// Value as string - public async Task RedisHashGetString(RedisKey currKey, string chiave) - { - string result = ""; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - var hasVal = await redisDb.HashExistsAsync(currKey, chiave); - if (hasVal) - { - var rawRes = await redisDb.HashGetAsync(currKey, chiave); - if (rawRes.HasValue) - { - result = $"{rawRes}"; - } - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Trace($"RedisHashGetString | {currKey} | in: {ts.TotalMilliseconds} ms"); - return result; - } - - /// - /// Remove for single hash record - /// - /// Chiave redis della Hashlist - /// Chiave nella HashList - /// Esito rimozione - public async Task RedisHashRemove(RedisKey currKey, string chiave) - { - bool fatto = false; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - fatto = await redisDb.HashDeleteAsync(currKey, chiave); - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Trace($"RedisHashRemove | {currKey} | in: {ts.TotalMilliseconds} ms"); - return fatto; - } - - -#if false - /// - /// Dizionario totale preferenze utente - /// - public Dictionary UsersPrefDict - { - get => RedisHashDictGet((RedisKey)$"{redisBaseKey}:{MatrOpr}"); - set => RedisHashDictSet((RedisKey)$"{redisBaseKey}:{MatrOpr}", value); - } -#endif - } -} \ No newline at end of file diff --git a/MagMan.Data.Tenant/Services/TenantService.cs b/MagMan.Data.Tenant/Services/TenantService.cs index a223559..177061e 100644 --- a/MagMan.Data.Tenant/Services/TenantService.cs +++ b/MagMan.Data.Tenant/Services/TenantService.cs @@ -82,20 +82,22 @@ namespace MagMan.Data.Tenant.Services /// /// Converte il DTO in ItemModel /// - /// + /// DTO di partenza + /// Parametro active da impostare /// - public RawItemModel ItemFromDto(ItemDTO origItem) + public RawItemModel ItemFromDto(ItemDTO origItem, bool isActive) { RawItemModel answ = new RawItemModel() { - MatId = origItem.MatID, + MatId = origItem.MatId, Note = origItem.Note, LMm = origItem.LMm, WMm = origItem.WMm, HMm = origItem.HMm, IsRemn = origItem.IsRemn, Location = origItem.Location, - QtyAvail = origItem.QtyAvail + QtyAvail = origItem.QtyAvail, + IsActive = isActive }; return answ; @@ -164,7 +166,7 @@ namespace MagMan.Data.Tenant.Services List? dbResult = new List(); try { - string currKey = $"{Const.rKeyConfig}:{nKey}:{matID}:ItemList"; + string currKey = $"{Const.rKeyConfig}:{nKey}:ItemList:{matID}"; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); string? rawData = await redisDb.StringGetAsync(currKey); @@ -202,11 +204,33 @@ namespace MagMan.Data.Tenant.Services return dbResult; } + /// Update record Item + refresh cache Key di + /// riferimento Item interesato quantità da aggiornare (se <0 è consumo) + public async Task ItemModQty(int nKey, RawItemModel currItem, int deltaQty) + { + bool fatto = false; + string cString = ConnString(nKey); + try + { + fatto = dbController.ItemModQty(cString, currItem, deltaQty); + if (fatto) + { + await FlushRedisCache(); + } + } + catch (Exception exc) + { + Log.Error($"Error during ItemModQty:{Environment.NewLine}{exc}"); + } + return fatto; + } + /// /// Update record Item + refresh cache /// /// Key di riferimento - /// + /// Item interesato /// public async Task ItemUpdate(int nKey, RawItemModel currItem) { @@ -329,6 +353,7 @@ namespace MagMan.Data.Tenant.Services } return dbResult; } + /// /// Lista Materiali gestiti a magazzino /// @@ -413,6 +438,188 @@ namespace MagMan.Data.Tenant.Services return fatto; } + /// + /// Elimina record Project + refresh cache + /// + /// Key di riferimento + /// Item da eliminare + /// + public async Task ProjectDelete(int nKey, ProjModel rec2del) + { + bool fatto = false; + string cString = ConnString(nKey); + try + { + fatto = dbController.ProjectDelete(cString, rec2del); + if (fatto) + { + await FlushRedisCache(); + } + } + catch (Exception exc) + { + Log.Error($"Error during ProjectDelete:{Environment.NewLine}{exc}"); + } + return fatto; + } + + /// + /// Converte il DTO in ItemModel + /// + /// DTO di partenza + /// + public ProjModel ProjectFromDto(ProjectDTO origItem) + { + ProjModel answ = new ProjModel() + { + MachineID = origItem.MachineID, + KeyNum = origItem.KeyNum, + ProjExtDbId = origItem.ProjExtDbId, + ProjExtId = origItem.ProjExtId, + BTLFileName = origItem.BTLFileName, + PType = origItem.PType, + Machine = origItem.Machine, + ProjDescription = origItem.ProjDescription, + DtCreated = origItem.DtCreated, + DtLastAction = origItem.DtLastAction, + DtSchedule = origItem.DtSchedule, + DtStartProd = origItem.DtStartProd, + ListName = origItem.ListName, + ProcTimeEst = origItem.ProcTimeEst, + ProcTimeReal = origItem.ProcTimeReal, + IsActive = origItem.IsActive, + IsArchived = origItem.IsArchived + }; + + return answ; + } + + /// + /// Lista Projects gestiti a magazzino + /// + /// Key di riferimento + /// + public async Task> ProjectGetAll(int nKey) + { + string source = "DB"; + string cString = ConnString(nKey); + List? dbResult = new List(); + try + { + string currKey = $"{Const.rKeyConfig}:ProjList:{nKey}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.ProjectGetAll(cString); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"ProjectGetAll | {source} in: {ts.TotalMilliseconds} ms"); + } + catch (Exception exc) + { + Log.Error($"Error during ProjectGetAll:{Environment.NewLine}{exc}"); + } + return dbResult; + } + + /// + /// Lista Items gestiti a magazzino x materiale + /// + /// Key di riferimento + /// ID del materiale x cui filtrare, 0 = tutti + /// + public async Task> ProjectGetByNumKey(int nKey, int numKey) + { + string source = "DB"; + string cString = ConnString(nKey); + List? dbResult = new List(); + try + { + string currKey = $"{Const.rKeyConfig}:{nKey}:ProjList:{numKey}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.ProjectGetByNumKey(cString, numKey); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"ProjectGetByNumKey | {source} in: {ts.TotalMilliseconds} ms"); + } + catch (Exception exc) + { + Log.Error($"Error during ProjectGetByNumKey:{Environment.NewLine}{exc}"); + } + return dbResult; + } + + /// + /// Update record Item + refresh cache + /// + /// Key di riferimento + /// Item interesato + /// + public async Task ProjectUpdate(int nKey, ProjModel currItem) + { + bool fatto = false; + string cString = ConnString(nKey); + try + { + fatto = dbController.ProjectUpdate(cString, currItem); + if (fatto) + { + await FlushRedisCache(); + } + } + catch (Exception exc) + { + Log.Error($"Error during ProjectUpdate:{Environment.NewLine}{exc}"); + } + return fatto; + } + #endregion Public Methods #region Private Fields @@ -459,40 +666,5 @@ namespace MagMan.Data.Tenant.Services } #endregion Private Methods - -#if false - /// - /// Dizionario dei token 2 connectionStrings - /// - private Dictionary TokenList { get; set; } = new Dictionary(); - - /// - /// Recupera ConnectionString dal dizionario dei token noti o cercando sul DB - /// - /// - /// - public string ConnStringByToken(string RestToken) - { - string answ = ""; - if (TokenList.ContainsKey(RestToken)) - { - answ = TokenList[RestToken]; - } - else - { - // cerco nel DB - var custList = dbController.CustomerGetAll(); - var custRow = custList.FirstOrDefault(x => x.RestToken == RestToken); - // se trovato salvo - if (custRow != null) - { - answ = DbConfig.CustomerConnString(DbServerAddr, nKey); - TokenList.Add(RestToken, answ); - Log.Info($"TokenList: added {RestToken} --> {answ}"); - } - } - return answ; - } -#endif } } \ No newline at end of file diff --git a/MagMan.UI/Components/CmpSelCliente.razor b/MagMan.UI/Components/CmpSelCliente.razor new file mode 100644 index 0000000..c236799 --- /dev/null +++ b/MagMan.UI/Components/CmpSelCliente.razor @@ -0,0 +1,15 @@ +
+ + +
+ + diff --git a/MagMan.UI/Components/CmpSelCliente.razor.cs b/MagMan.UI/Components/CmpSelCliente.razor.cs new file mode 100644 index 0000000..75240e1 --- /dev/null +++ b/MagMan.UI/Components/CmpSelCliente.razor.cs @@ -0,0 +1,68 @@ +using MagMan.Core.Services; +using MagMan.Data.Admin.DbModels; +using MagMan.Data.Admin.Services; +using Microsoft.AspNetCore.Components; + +namespace MagMan.UI.Components +{ + public partial class CmpSelCliente + { + #region Public Properties + + [Parameter] + public EventCallback E_CustSelected { get; set; } + + #endregion Public Properties + + #region Protected Properties + + [Inject] + protected MessageService AppMService { get; set; } = null!; + + protected int CustomerID + { + get => customerID; + set + { + if (customerID != value) + { + customerID = value; + E_CustSelected.InvokeAsync(value); + InvokeAsync(() => AppMService.ClientIdSet(value)); + } + } + } + + [Inject] + protected MTAdminService MTService { get; set; } = null!; + + #endregion Protected Properties + + #region Protected Methods + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + CustomerID = await AppMService.ClientIdGet(); + } + + protected override async Task OnInitializedAsync() + { + await ReloadData(); + } + + protected async Task ReloadData() + { + CustomersList = await MTService.CustomerGetAll(); + } + + #endregion Protected Methods + + #region Private Fields + + private int customerID = 0; + + private List? CustomersList = null; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/MagMan.UI/Components/ItemEdit.razor b/MagMan.UI/Components/ItemEdit.razor new file mode 100644 index 0000000..abe3b1f --- /dev/null +++ b/MagMan.UI/Components/ItemEdit.razor @@ -0,0 +1,44 @@ +@if (CurrRecord != null) +{ +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+
+
+ @if (CurrRecord.MaterialNav.IsWall) + { +
+ + +
+ } + @*
+ + +
*@ +
+ + +
+ + @* *@ +
+
+
+
+} diff --git a/MagMan.UI/Components/ItemEdit.razor.cs b/MagMan.UI/Components/ItemEdit.razor.cs new file mode 100644 index 0000000..451b3ec --- /dev/null +++ b/MagMan.UI/Components/ItemEdit.razor.cs @@ -0,0 +1,50 @@ +using MagMan.Data.Tenant.DbModels; +using MagMan.Data.Tenant.Services; +using Microsoft.AspNetCore.Components; + +namespace MagMan.UI.Components +{ + public partial class ItemEdit + { + #region Public Properties + + [Parameter] + public RawItemModel? CurrRecord { get; set; } = null; + + [Parameter] + public int KeyNum { get; set; } = 0; + [Parameter] + public EventCallback EC_update { get; set; } + + #endregion Public Properties + + #region Protected Properties + + [Inject] + protected TenantService TService { get; set; } = null!; + + #endregion Protected Properties + + #region Protected Methods + + protected async Task DoSave() + { + bool fatto = false; + await Task.Delay(1); + if (CurrRecord != null) + { + fatto = await TService.ItemUpdate(KeyNum, CurrRecord); + } + if (fatto) + { + await EC_update.InvokeAsync(true); + } + } + protected async Task DoCancel() + { + await EC_update.InvokeAsync(true); + } + + #endregion Protected Methods + } +} \ No newline at end of file diff --git a/MagMan.UI/Components/ItemMan.razor b/MagMan.UI/Components/ItemMan.razor index 0e1fac5..e2fa44f 100644 --- a/MagMan.UI/Components/ItemMan.razor +++ b/MagMan.UI/Components/ItemMan.razor @@ -1,5 +1,117 @@ -

ItemMan

+
+
+
+
+

Articoli

+
+
+
+
+ @if (CurrItem == null) + { + + } + else + { + + } +
+
+
+
+ @if (CurrItem != null) + { +
+ + } +
+
+ @if (ListRecords == null || isLoading) + { + + } + else if (totalCount == 0) + { +
Nessun record trovato
+ } + else + { + + + + + + + + + @if (MaterialSel.IsWall) + { + + } + @* *@ + + @* *@ + + + + @foreach (var item in ListRecords) + { + + + + + + + @if (MaterialSel.IsWall) + { + + } + @* *@ + + @* *@ + + } + +
+ + Qty ID Note Posizione W (mm) H (mm) L (mm)
+ @* *@ + + + @item.QtyAvail + + @if (item.IsActive) + { + + + + } + else + { + + + + } +  @item.RawItemId + + @item.Note + + @item.Location + + @($"{item.WMm:N2}") + + @($"{item.HMm:N2}") + + @($"{item.LMm:N2}") + + +
+ } + +
+ +
-@code { -} diff --git a/MagMan.UI/Components/ItemMan.razor.cs b/MagMan.UI/Components/ItemMan.razor.cs new file mode 100644 index 0000000..5604f4f --- /dev/null +++ b/MagMan.UI/Components/ItemMan.razor.cs @@ -0,0 +1,346 @@ +using EgwCoreLib.Razor; +using MagMan.Core.Services; +using MagMan.Data.Tenant.DbModels; +using MagMan.Data.Tenant.Services; +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; + +namespace MagMan.UI.Components +{ + public partial class ItemMan + { + #region Public Properties + + [Parameter] + public int CustomerId { get; set; } = 0; + + [Parameter] + public EventCallback E_RawItemSel { get; set; } + + [Parameter] + public int KeyNum { get; set; } = 0; + + [Parameter] + public MaterialModel MaterialSel { get; set; } = null!; + + #endregion Public Properties + + #region Protected Properties + + [Inject] + protected MessageService AppMService { get; set; } = null!; + + [Inject] + protected IConfiguration Configuration { get; set; } = null!; + + [Inject] + protected IJSRuntime JSRuntime { get; set; } = null!; + + protected int totalCount { get; set; } = 0; + + [Inject] + protected TenantService TService { get; set; } = null!; + + #endregion Protected Properties + + #region Protected Methods + + protected string CheckSel(RawItemModel curItem) + { + string answ = ""; + if (CurrItem != null) + { + answ = curItem.RawItemId == CurrItem.RawItemId ? "table-info" : ""; + } + else + { + answ = curItem.RawItemId == RawItemId ? "table-info" : ""; + } + return answ; + } + + + protected async Task CreateNew() + { + CurrItem = new RawItemModel() + { + MatId = MaterialSel.MatId, + Location = "nd", + Note = "...", + QtyAvail = 0, + IsActive = true, + IsRemn = false, + HMm = MaterialSel.HMm, + LMm = MaterialSel.LMm, + WMm = MaterialSel.WMm + }; + await InvokeAsync(StateHasChanged); + } + + protected async Task DeleteRecord(RawItemModel selItem) + { + if (!await JSRuntime.InvokeAsync("confirm", "Sicuro di voler eliminare il record?")) + return; + await TService.ItemDelete(KeyNum, selItem); + await ReloadData(); + } + + protected void DoEdit(RawItemModel? selItem) + { + CurrItem = selItem; + if (selItem == null) + { + DoSelect(null); + } + } + + protected void DoSelect(RawItemModel? selItem) + { + if (selItem != null) + { + RawItemId = selItem.MatId; + } + else + { + RawItemId = 0; + } + E_RawItemSel.InvokeAsync(RawItemId); + } + + protected async Task ForceReload(bool force) + { + CurrItem = null; + await ReloadData(); + } + + protected override void OnInitialized() + { + currSearch = ""; + AppMService.EA_SearchUpdated += AppMService_EA_SearchUpdated; + } + + protected override async Task OnParametersSetAsync() + { + CurrItem = null; + await ReloadData(); + } + + protected void SetNumRec(int newNum) + { + numRecord = newNum; + currPage = 1; + InvokeAsync(ReloadData); + } + + protected void SetPage(int newNum) + { + currPage = newNum; + InvokeAsync(ReloadData); + } + + protected async Task SortRequested(Sorter.SortCallBack e) + { + sortField = e.ParamName; + sortAsc = e.IsAscending; + await ReloadData(); + } + + #endregion Protected Methods + + #region Private Fields + + private RawItemModel? CurrItem = null; + private string currSearch = ""; + private int filtType = 0; + private List? ListRecords = null; + private int RawItemId = 0; + private List? SearchRecords = null; + + private bool sortAsc = true; + + private string sortField = ""; + + #endregion Private Fields + + #region Private Properties + + private int currPage { get; set; } = 1; + + private int FiltType + { + get => filtType; + set + { + if (filtType != value) + { + filtType = value; + InvokeAsync(ReloadData); + InvokeAsync(StateHasChanged); + } + } + } + + private bool isLoading { get; set; } = false; + + private int numRecord { get; set; } = 10; + + #endregion Private Properties + + #region Private Methods + + private async void AppMService_EA_SearchUpdated() + { + currSearch = AppMService.SearchVal; + await ReloadData(); + } + + private async Task ReloadData() + { + isLoading = true; + await InvokeAsync(StateHasChanged); + ListRecords = null; + SearchRecords = await TService.ItemGetByMat(KeyNum, MaterialSel.MatId); + // verifico filtro per ricerca + if (!string.IsNullOrEmpty(currSearch)) + { + SearchRecords = SearchRecords.Where(x => x.Note.Contains(currSearch, StringComparison.InvariantCultureIgnoreCase)).ToList(); + } + totalCount = SearchRecords.Count; + SortTable(); + isLoading = false; + await InvokeAsync(StateHasChanged); + } + + private void SortTable() + { + if (SearchRecords != null) + { + // se ho ordinamento riordino... + if (!string.IsNullOrEmpty(sortField)) + { + switch (sortField) + { + case "RawItemId": + if (sortAsc) + { + SearchRecords = SearchRecords.OrderBy(x => x.RawItemId).ThenBy(x => x.Note).ToList(); + } + else + { + SearchRecords = SearchRecords.OrderByDescending(x => x.RawItemId).ThenByDescending(x => x.Note).ToList(); + } + break; + + case "Location": + if (sortAsc) + { + SearchRecords = SearchRecords.OrderBy(x => x.Location).ToList(); + } + else + { + SearchRecords = SearchRecords.OrderByDescending(x => x.Location).ToList(); + } + break; + + case "QtyAvail": + if (sortAsc) + { + SearchRecords = SearchRecords.OrderBy(x => x.QtyAvail).ToList(); + } + else + { + SearchRecords = SearchRecords.OrderByDescending(x => x.QtyAvail).ToList(); + } + break; + + case "Note": + if (sortAsc) + { + SearchRecords = SearchRecords.OrderBy(x => x.Note).ToList(); + } + else + { + SearchRecords = SearchRecords.OrderByDescending(x => x.Note).ToList(); + } + break; + + case "IsActive": + if (sortAsc) + { + SearchRecords = SearchRecords.OrderBy(x => x.IsActive).ToList(); + } + else + { + SearchRecords = SearchRecords.OrderByDescending(x => x.IsActive).ToList(); + } + break; + + case "IsRemn": + if (sortAsc) + { + SearchRecords = SearchRecords.OrderBy(x => x.IsRemn).ToList(); + } + else + { + SearchRecords = SearchRecords.OrderByDescending(x => x.IsRemn).ToList(); + } + break; + + case "W": + if (sortAsc) + { + SearchRecords = SearchRecords.OrderBy(x => x.WMm).ToList(); + } + else + { + SearchRecords = SearchRecords.OrderByDescending(x => x.WMm).ToList(); + } + break; + + case "H": + if (sortAsc) + { + SearchRecords = SearchRecords.OrderBy(x => x.HMm).ToList(); + } + else + { + SearchRecords = SearchRecords.OrderByDescending(x => x.HMm).ToList(); + } + break; + + case "L": + if (sortAsc) + { + SearchRecords = SearchRecords.OrderBy(x => x.LMm).ToList(); + } + else + { + SearchRecords = SearchRecords.OrderByDescending(x => x.LMm).ToList(); + } + break; + + default: + break; + } + } + + // filtro x display + ListRecords = SearchRecords + .Skip(numRecord * (currPage - 1)) + .Take(numRecord) + .ToList(); + } + else + { + ListRecords = new List(); + } + } + + private string textCss(bool isActive) + { + return isActive ? "text-dark" : "text-secondary text-decoration-line-through"; + } + + #endregion Private Methods + } +} \ No newline at end of file diff --git a/MagMan.UI/Components/MaterialEdit.razor b/MagMan.UI/Components/MaterialEdit.razor index 98ebd06..2bcbad3 100644 --- a/MagMan.UI/Components/MaterialEdit.razor +++ b/MagMan.UI/Components/MaterialEdit.razor @@ -5,7 +5,7 @@
- +
diff --git a/MagMan.UI/Components/MaterialMan.razor b/MagMan.UI/Components/MaterialMan.razor index 87b767f..4130b17 100644 --- a/MagMan.UI/Components/MaterialMan.razor +++ b/MagMan.UI/Components/MaterialMan.razor @@ -36,7 +36,7 @@ }
- @if (ListRecords == null) + @if (ListRecords == null || isLoading) { } @@ -55,9 +55,9 @@ ID Mat.Code Descr. - W (mm) - H (mm) - L (mm) + W (mm) + H (mm) + @* L (mm) *@ @* *@ @@ -66,10 +66,23 @@ { + - @item.MatId + @if (item.IsBeam) + { + + + + } + else if (@item.IsWall) + { + + + + } +  @item.MatId @item.MatCode @@ -77,15 +90,22 @@ @item.MatDesc - - @($"{item.WMm:N2}") + + @if (item.IsBeam) + { + @($"{item.WMm:N2}") + } + else + { + - + } - + @($"{item.HMm:N2}") - - @($"{item.LMm:N2}") - + @* + @($"{item.LMm:N2}") + *@ @* *@ diff --git a/MagMan.UI/Components/MaterialMan.razor.cs b/MagMan.UI/Components/MaterialMan.razor.cs index 12dd2b8..fbb97ec 100644 --- a/MagMan.UI/Components/MaterialMan.razor.cs +++ b/MagMan.UI/Components/MaterialMan.razor.cs @@ -1,6 +1,7 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. +// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this +// file to you under the MIT license. using EgwCoreLib.Razor; +using MagMan.Core.Services; using MagMan.Data.Admin.DbModels; using MagMan.Data.Admin.Services; using MagMan.Data.Tenant.DbModels; @@ -18,6 +19,9 @@ namespace MagMan.UI.Components [Parameter] public int CustomerId { get; set; } = 0; + [Parameter] + public EventCallback E_MaterialSel { get; set; } + [Parameter] public int KeyNum { get; set; } = 0; @@ -25,17 +29,20 @@ namespace MagMan.UI.Components #region Protected Properties + [Inject] + protected MessageService AppMService { get; set; } = null!; + [Inject] protected IConfiguration Configuration { get; set; } = null!; [Inject] protected IJSRuntime JSRuntime { get; set; } = null!; + protected int totalCount { get; set; } = 0; + [Inject] protected TenantService TService { get; set; } = null!; - protected int totalCount { get; set; } = 0; - #endregion Protected Properties #region Protected Methods @@ -45,7 +52,11 @@ namespace MagMan.UI.Components string answ = ""; if (CurrItem != null) { - answ = curItem.MatId == CurrItem.MatId? "table-info" : ""; + answ = curItem.MatId == CurrItem.MatId ? "table-info" : ""; + } + else + { + answ = curItem.MatId == MaterialId ? "table-info" : ""; } return answ; } @@ -71,6 +82,22 @@ namespace MagMan.UI.Components protected void DoEdit(MaterialModel? selItem) { CurrItem = selItem; + if (selItem == null) + { + DoSelect(null); + } + } + protected void DoSelect(MaterialModel? selItem) + { + if (selItem != null) + { + MaterialId = selItem.MatId; + } + else + { + MaterialId = 0; + } + E_MaterialSel.InvokeAsync(selItem); } protected async Task ForceReload(bool force) @@ -79,6 +106,12 @@ namespace MagMan.UI.Components await ReloadData(); } + protected override void OnInitialized() + { + currSearch = ""; + AppMService.EA_SearchUpdated += AppMService_EA_SearchUpdated; + } + protected override async Task OnParametersSetAsync() { await ReloadData(); @@ -88,11 +121,14 @@ namespace MagMan.UI.Components { numRecord = newNum; currPage = 1; + InvokeAsync(ReloadData); } protected void SetPage(int newNum) { currPage = newNum; + DoSelect(null); + InvokeAsync(ReloadData); } protected async Task SortRequested(Sorter.SortCallBack e) @@ -104,11 +140,13 @@ namespace MagMan.UI.Components #endregion Protected Methods - #region Private Fields private MaterialModel? CurrItem = null; + private int MaterialId = 0; + private string currSearch = ""; + private int filtType = 0; private List? ListRecords = null; private List? SearchRecords = null; @@ -123,30 +161,6 @@ namespace MagMan.UI.Components private int currPage { get; set; } = 1; - private bool isLoading { get; set; } = false; - - private int numRecord { get; set; } = 10; - - #endregion Private Properties - - #region Private Methods - - private async Task ReloadData() - { - isLoading = true; - ListRecords = null; - SearchRecords = await TService.MaterialGetAll(KeyNum, false); - // verifico se filtrare x beam/wall - if (FiltType> 0) - { - SearchRecords = SearchRecords.Where(x => (x.IsBeam && FiltType == 1) || (x.IsWall && FiltType == 2)).ToList(); - } - totalCount = SearchRecords.Count; - SortTable(); - isLoading = false; - } - - private int filtType = 0; private int FiltType { get => filtType; @@ -155,12 +169,48 @@ namespace MagMan.UI.Components if (filtType != value) { filtType = value; - var pUpd = Task.Run(async () => await ReloadData()); - pUpd.Wait(); + InvokeAsync(ReloadData); + InvokeAsync(StateHasChanged); } } } + private bool isLoading { get; set; } = false; + + private int numRecord { get; set; } = 10; + + #endregion Private Properties + + #region Private Methods + + private async void AppMService_EA_SearchUpdated() + { + currSearch = AppMService.SearchVal; + await ReloadData(); + } + + private async Task ReloadData() + { + isLoading = true; + await InvokeAsync(StateHasChanged); + ListRecords = null; + SearchRecords = await TService.MaterialGetAll(KeyNum, false); + // verifico se filtrare x beam/wall + if (FiltType > 0) + { + SearchRecords = SearchRecords.Where(x => (x.IsBeam && FiltType == 1) || (x.IsWall && FiltType == 2)).ToList(); + } + // verifico filtro per ricerca + if (!string.IsNullOrEmpty(currSearch)) + { + SearchRecords = SearchRecords.Where(x => x.MatCode.Contains(currSearch, StringComparison.InvariantCultureIgnoreCase) || x.MatDesc.Contains(currSearch, StringComparison.InvariantCultureIgnoreCase)).ToList(); + } + totalCount = SearchRecords.Count; + SortTable(); + isLoading = false; + await InvokeAsync(StateHasChanged); + } + private void SortTable() { if (SearchRecords != null) @@ -170,7 +220,7 @@ namespace MagMan.UI.Components { switch (sortField) { - case "MatId": + case "RawItemId": if (sortAsc) { SearchRecords = SearchRecords.OrderBy(x => x.MatId).ThenBy(x => x.MatCode).ToList(); diff --git a/MagMan.UI/Components/SearchMod.razor b/MagMan.UI/Components/SearchMod.razor index 05ade27..cc1a2b1 100644 --- a/MagMan.UI/Components/SearchMod.razor +++ b/MagMan.UI/Components/SearchMod.razor @@ -3,8 +3,6 @@
-
- -
+
diff --git a/MagMan.UI/Controllers/InventoryController.cs b/MagMan.UI/Controllers/InventoryController.cs index 0fa8fc4..f71323c 100644 --- a/MagMan.UI/Controllers/InventoryController.cs +++ b/MagMan.UI/Controllers/InventoryController.cs @@ -1,4 +1,6 @@ -using MagMan.Core; +using k8s.Models; +using MagMan.Core; +using MagMan.Core.DTO; using MagMan.Core.Services; using MagMan.Data.Admin.DbModels; using MagMan.Data.Admin.Services; @@ -20,12 +22,12 @@ namespace MagMan.UI.Controllers /// Classe per logging /// private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); - private MTAdminService MTAdminService { get; set; } = null!; + private MTAdminService MTAdmService { get; set; } = null!; private static JsonSerializerSettings? JSSettings; private TenantService TService { get; set; } = null!; public InventoryController(MTAdminService MTDataService, TenantService TDataService) { - MTAdminService = MTDataService; + MTAdmService = 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() @@ -68,7 +70,7 @@ namespace MagMan.UI.Controllers public async Task> Get(string id, int MatId) { // in primis recupero codice chiave da token... - int nKey = await MTAdminService.MainKeyByToken(id); + int nKey = await MTAdmService.MainKeyByToken(id); // ora recupero direttametne i materiali var ListRecords = await TService.MaterialGetFilt(nKey, MatId, true); return ListRecords; @@ -89,11 +91,11 @@ namespace MagMan.UI.Controllers if (!string.IsNullOrEmpty(id) && rawList != null && rawList.ItemList != null) { // in primis recupero codice chiave da token... - int nKey = await MTAdminService.MainKeyByToken(id); + int nKey = await MTAdmService.MainKeyByToken(id); if (nKey > 0) { // creo oggetti materiale da lista ricevuta - List matList = rawList.ItemList.Select(jpl => TService.ItemFromDto(jpl)).ToList(); + List matList = rawList.ItemList.Select(jpl => TService.ItemFromDto(jpl, true)).ToList(); foreach (var item in matList) { @@ -108,10 +110,14 @@ namespace MagMan.UI.Controllers fatto = false; } } + // resetto cache redis + await MTAdmService.FlushRedisCache(); } } answ = fatto ? "OK" : "NO"; return answ; } + + } } diff --git a/MagMan.UI/Controllers/MaterialsController.cs b/MagMan.UI/Controllers/MaterialsController.cs index 3534796..ef8aa5f 100644 --- a/MagMan.UI/Controllers/MaterialsController.cs +++ b/MagMan.UI/Controllers/MaterialsController.cs @@ -19,12 +19,12 @@ namespace MagMan.UI.Controllers /// Classe per logging /// private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); - private MTAdminService MTAdminService { get; set; } = null!; + private MTAdminService MTAdmService { get; set; } = null!; private static JsonSerializerSettings? JSSettings; private TenantService TService { get; set; } = null!; public MaterialsController(MTAdminService MTDataService, TenantService TDataService) { - MTAdminService = MTDataService; + MTAdmService = 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() @@ -66,7 +66,7 @@ namespace MagMan.UI.Controllers public async Task> Get(string id) { // in primis recupero codice chiave da token... - int nKey = await MTAdminService.MainKeyByToken(id); + int nKey = await MTAdmService.MainKeyByToken(id); // ora recupero direttametne i materiali var ListRecords = await TService.MaterialGetAll(nKey, false); return ListRecords; @@ -87,7 +87,7 @@ namespace MagMan.UI.Controllers if (!string.IsNullOrEmpty(id) && rawList != null && rawList.MatList != null) { // in primis recupero codice chiave da token... - int nKey = await MTAdminService.MainKeyByToken(id); + int nKey = await MTAdmService.MainKeyByToken(id); if (nKey > 0) { // creo oggetti materiale da lista ricevuta @@ -106,6 +106,8 @@ namespace MagMan.UI.Controllers fatto = false; } } + // resetto cache redis + await MTAdmService.FlushRedisCache(); } } answ = fatto ? "OK" : "NO"; diff --git a/MagMan.UI/Controllers/ProjectsController.cs b/MagMan.UI/Controllers/ProjectsController.cs index 1ef0461..38b575a 100644 --- a/MagMan.UI/Controllers/ProjectsController.cs +++ b/MagMan.UI/Controllers/ProjectsController.cs @@ -1,8 +1,15 @@ -using MagMan.Data.Admin.DbModels; +using k8s.Models; +using MagMan.Core; +using MagMan.Core.DTO; +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 System.Diagnostics; namespace MagMan.UI.Controllers { @@ -14,10 +21,18 @@ namespace MagMan.UI.Controllers /// Classe per logging /// private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); - private MTAdminService _DataService { get; set; } = null!; - public ProjectsController(MTAdminService DataService) + private MTAdminService MTAdmService { get; set; } = null!; + private static JsonSerializerSettings? JSSettings; + private TenantService TService { get; set; } = null!; + public ProjectsController(MTAdminService MTDataService, TenantService TDataService) { - _DataService = DataService; + MTAdmService = 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 ProjectsController"); } @@ -52,8 +67,47 @@ namespace MagMan.UI.Controllers [HttpGet("{id}")] public async Task> Get(string id, int KeyNum) { - var ListRecords = await _DataService.MachineGetByToken(id); + var ListRecords = await MTAdmService.MachineGetByToken(id); return ListRecords; } + + /// + /// Processa una chiamata POST per l'invio di un oggetto di aggiornamento progetto + /// PUT: api/Inventory/upsert/00000000-0000-0000-0000-000000000000 + /// + /// token comunicazione + /// + [HttpPost("upsert/{id}")] + public async Task upsert(string id, [FromBody] ProjectDTO projectData) + { + string answ = "ND"; + bool fatto = false; + // verifico ci sia valore + if (!string.IsNullOrEmpty(id) && projectData != null) + { + // in primis recupero codice chiave da token... + int nKey = await MTAdmService.MainKeyByToken(id); + if (nKey > 0) + { + // converto ProjDto --> DB + var currRec = TService.ProjectFromDto(projectData); + try + { + await TService.ProjectUpdate(nKey, currRec); + fatto = true; + } + catch (Exception exc) + { + Log.Error($"ProjectsController.upsert | Errore in fase salvataggio ProjectDTO{Environment.NewLine}{exc}"); + fatto = false; + } + // resetto cache redis + await MTAdmService.FlushRedisCache(); + + } + } + answ = fatto ? "OK" : "NO"; + return answ; + } } } diff --git a/MagMan.UI/Controllers/ResourcesController.cs b/MagMan.UI/Controllers/ResourcesController.cs new file mode 100644 index 0000000..81edb1b --- /dev/null +++ b/MagMan.UI/Controllers/ResourcesController.cs @@ -0,0 +1,117 @@ +using k8s.Models; +using MagMan.Core; +using MagMan.Core.DTO; +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; + +namespace MagMan.UI.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ResourcesController : ControllerBase + { + /// + /// Classe per logging + /// + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + private MTAdminService MTAdmService { get; set; } = null!; + private static JsonSerializerSettings? JSSettings; + private TenantService TService { get; set; } = null!; + public ResourcesController(MTAdminService MTDataService, TenantService TDataService) + { + MTAdmService = 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 ResourcesController"); + } + + /// + /// Controllo status Alive + /// GET: api/Machines/alive + /// + /// + [HttpGet("alive")] + public string alive() + { + //Log.Debug("Chiamata alive"); + return $"OK"; + } + + // GET api/Machines/5 + [HttpGet] + public async Task> Get() + { + // se non ho chaive --> vuoto! + List ListRecords = new List(); + await Task.Delay(100); + return ListRecords; + } + + /// + /// Elenco Macchine dato RestToken + /// + /// Rest Token cliente + /// + // GET api/Machines/2cba60c7-7be4-40b1-aa0d-52e7c71fc1a7 + [HttpGet("{id}")] + public async Task> Get(string id, int KeyNum) + { + var ListRecords = await MTAdmService.MachineGetByToken(id); + return ListRecords; + } + + /// + /// Processa una chiamata POST per l'invio di un oggetto di aggiornamento risorse progetto (RestPayload.Resources) + /// PUT: api/Inventory/upsert/00000000-0000-0000-0000-000000000000 + /// + /// token comunicazione + /// + [HttpPost("upsert/{id}")] + public async Task upsert(string id, [FromBody] RestPayload.Resources projectData) + { + string answ = "ND"; + bool fatto = false; + // verifico ci sia valore + if (!string.IsNullOrEmpty(id) && projectData != null) + { + // in primis recupero codice chiave da token... + int nKey = await MTAdmService.MainKeyByToken(id); + if (nKey > 0) + { +#if false + // creo oggetti materiale da lista ricevuta + List matList = item2Consume.ItemList.Select(jpl => TService.ItemFromDto(jpl, true)).ToList(); + + foreach (var item in matList) + { + try + { + await TService.ItemUpdate(nKey, item); + fatto = true; + } + catch (Exception exc) + { + Log.Error($"InventoryController.upsert | Errore in fase salvataggio ItemDto{Environment.NewLine}{exc}"); + fatto = false; + } + } +#endif + // resetto cache redis + await MTAdmService.FlushRedisCache(); + } + } + answ = fatto ? "OK" : "NO"; + return answ; + } + } +} diff --git a/MagMan.UI/MagMan.UI.csproj b/MagMan.UI/MagMan.UI.csproj index 963cf73..1a68aab 100644 --- a/MagMan.UI/MagMan.UI.csproj +++ b/MagMan.UI/MagMan.UI.csproj @@ -2,7 +2,7 @@ net6.0 - 1.0.2401.1911 + 1.0.2401.2220 enable enable true @@ -36,7 +36,7 @@ - + diff --git a/MagMan.UI/Pages/AdminArea.razor b/MagMan.UI/Pages/AdminArea.razor index c15ffb1..d925cba 100644 --- a/MagMan.UI/Pages/AdminArea.razor +++ b/MagMan.UI/Pages/AdminArea.razor @@ -22,19 +22,7 @@
@if (currMode != CtMode.Company) { -
- - -
+ }
diff --git a/MagMan.UI/Pages/AdminArea.razor.cs b/MagMan.UI/Pages/AdminArea.razor.cs index 1e2e4e1..c035dc3 100644 --- a/MagMan.UI/Pages/AdminArea.razor.cs +++ b/MagMan.UI/Pages/AdminArea.razor.cs @@ -31,12 +31,16 @@ namespace MagMan.UI.Pages #region Protected Methods - protected override async Task OnInitializedAsync() + protected override void OnInitialized() { AppMService.ShowSearch = false; AppMService.PageName = "Admin Area"; AppMService.PageIcon = "fa-solid fa-house pr-2"; - await ReloadData(); + } + + protected void SaveCust(int newCustId) + { + CustomerID = newCustId; } #endregion Protected Methods @@ -44,14 +48,12 @@ namespace MagMan.UI.Pages #region Private Fields private CtMode currMode = CtMode.Company; - private int CustomerID = 0; - private List? CustomersList = null; #endregion Private Fields #region Private Properties - private bool isLoading { get; set; } = false; + private int CustomerID { get; set; } = 0; [Inject] private NavigationManager NavMan { get; set; } = null!; @@ -66,13 +68,6 @@ namespace MagMan.UI.Pages return answ; } - private async Task ReloadData() - { - isLoading = true; - CustomersList = await MTService.CustomerGetAll(); - isLoading = false; - } - private void SetMode(CtMode newMode) { currMode = newMode; diff --git a/MagMan.UI/Pages/Index.razor b/MagMan.UI/Pages/Index.razor index ba53cc2..d1470ea 100644 --- a/MagMan.UI/Pages/Index.razor +++ b/MagMan.UI/Pages/Index.razor @@ -55,7 +55,7 @@
- +

Dati Macchine

@@ -65,7 +65,7 @@
- +

Magazzino

diff --git a/MagMan.UI/Pages/WareHouse.razor b/MagMan.UI/Pages/WareHouse.razor index 9990900..91abc55 100644 --- a/MagMan.UI/Pages/WareHouse.razor +++ b/MagMan.UI/Pages/WareHouse.razor @@ -4,29 +4,9 @@
-
-
- - -
+
@if (CustomerID == 0) @@ -40,12 +20,15 @@ } else { - @if (currMode == CtMode.Materials) - { - - } - else if (currMode == CtMode.Items) - { - - } +
+
+ +
+ @if (MaterialSel != null) + { +
+ +
+ } +
} \ No newline at end of file diff --git a/MagMan.UI/Pages/WareHouse.razor.cs b/MagMan.UI/Pages/WareHouse.razor.cs index 864137c..3a501b0 100644 --- a/MagMan.UI/Pages/WareHouse.razor.cs +++ b/MagMan.UI/Pages/WareHouse.razor.cs @@ -1,72 +1,83 @@ using MagMan.Core.Services; using MagMan.Data.Admin.DbModels; using MagMan.Data.Admin.Services; +using MagMan.Data.Tenant.DbModels; using Microsoft.AspNetCore.Components; +using YamlDotNet.Core.Tokens; namespace MagMan.UI.Pages { public partial class WareHouse { + #region Protected Fields + + protected int nKey = 0; + + #endregion Protected Fields + + #region Protected Properties + [Inject] protected MessageService AppMService { get; set; } = null!; + protected int CustomerID { get; set; } = 0; + + protected string mainCss + { + get => MaterialSel == null ? "col-12" : "col-6 small"; + } + [Inject] protected MTAdminService MTService { get; set; } = null!; + + #endregion Protected Properties + + #region Protected Methods + protected override async Task OnInitializedAsync() { - AppMService.ShowSearch = false; + AppMService.ShowSearch = true; 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(); + } + + protected void SaveMat(MaterialModel? newMat) + { + MaterialSel = newMat; + } + + #endregion Protected Methods + + #region Private Fields + + private int KeyNum = 0; + private MaterialModel? MaterialSel = null; + + #endregion Private Fields + + #region Private Properties + + private bool isLoading { get; set; } = false; + + #endregion Private Properties + + #region Private Methods + private async Task ReloadData() { isLoading = true; - CustomersList = await MTService.CustomerGetAll(); 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 - { - 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; - - protected enum CtMode - { - Materials, - Items, - //Deposit, - //Pickup - } - - private string IsActive(CtMode modeReq) - { - string answ = currMode == modeReq ? "active" : ""; - return answ; - } - - private void SetMode(CtMode newMode) - { - currMode = newMode; - } + #endregion Private Methods } } \ No newline at end of file diff --git a/MagMan.UI/Shared/NavMenu.razor b/MagMan.UI/Shared/NavMenu.razor index 8c09629..8d63bc6 100644 --- a/MagMan.UI/Shared/NavMenu.razor +++ b/MagMan.UI/Shared/NavMenu.razor @@ -46,6 +46,11 @@ Dati Macchine
+