From f4472a9eadea9f7cc97d441ceec015f5168261d0 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Sat, 23 Oct 2021 18:38:51 +0200 Subject: [PATCH] Aggiunta preliminare pagina parametri impianto --- GWMS.UI/Pages/PlantParameters.razor | 131 ++++++++ GWMS.UI/Pages/PlantParameters.razor.cs | 434 +++++++++++++++++++++++++ GWMS.UI/Shared/NavMenu.razor | 6 + 3 files changed, 571 insertions(+) create mode 100644 GWMS.UI/Pages/PlantParameters.razor create mode 100644 GWMS.UI/Pages/PlantParameters.razor.cs diff --git a/GWMS.UI/Pages/PlantParameters.razor b/GWMS.UI/Pages/PlantParameters.razor new file mode 100644 index 0000000..afb301f --- /dev/null +++ b/GWMS.UI/Pages/PlantParameters.razor @@ -0,0 +1,131 @@ +@page "/PlantParameters" + +@using Blazorise.Components +@using GWMS.UI.Components + +
+
+
+
+ Parametri Impianto +
+
+
+
+
+ +
+
+
+
+
+ + + +
+ +
+
+
+
+
+
+
+ @if (currRecord != null) + { + + } + @if (ListRecords == null) + { + + } + else if (totalCount == 0) + { +
Nessun record trovato
+ } + else + { +
+
+ + + + + + + + + + + + + @foreach (var record in ListRecords) + { + @**@ + + + + + + + + + } + +
ImpiantoDataLivello AperturaLivello ChiusuraCarico Ordine
+
@record.PlantCode
+
@record.PlantDesc
+
+
@record.DataRif.ToString("yyyy.MM.dd")
+
@record.DataRif.ToString("dddd")
+
@record.LevelStart.ToString("N0")@record.LevelEnd.ToString("N0") + @if (record.HasRefill) + { + if (record.HasOrder) + { + @record.LevelMin.ToString("N0") @record.LevelMax.ToString("N0") + } + else + { + @record.LevelMin.ToString("N0") @record.LevelMax.ToString("N0") + } + + } + + @if (record.HasOrder) + { + @if (currRecord == null) + { + + } + else + { + + } + } + else if (ShowAddNew && record.HasRefill) + { + + } +
+
+
+ } +
+ +
\ No newline at end of file diff --git a/GWMS.UI/Pages/PlantParameters.razor.cs b/GWMS.UI/Pages/PlantParameters.razor.cs new file mode 100644 index 0000000..8bd7f82 --- /dev/null +++ b/GWMS.UI/Pages/PlantParameters.razor.cs @@ -0,0 +1,434 @@ +using GWMS.Data.DatabaseModels; +using GWMS.Data.DTO; +using GWMS.UI.Data; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Authorization; +using Microsoft.JSInterop; +using NLog; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace GWMS.UI.Pages +{ + [Authorize(Roles = "SuperAdmin, Admin, User")] + public partial class PlantParameters : ComponentBase, IDisposable + { + #region Private Fields + + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + private bool _ShowOnlyRefill = false; + private OrderModel currRecord = null; + + private List ListRecords; + private List PlantsList; + private List SearchRecords; + private List SuppliersList; + + #endregion Private Fields + + #region Protected Fields + + /// + /// Valore PlantId filtrato da claim + /// + protected int ClaimPlantId = -1; + + #endregion Protected Fields + + #region Private Properties + + private int _currPage { get; set; } = 1; + + private int _numRecord { get; set; } = 10; + + private int currPage + { + get => _currPage; + set + { + if (_currPage != value) + { + _currPage = value; + var pUpd = Task.Run(async () => await ReloadData()); + pUpd.Wait(); + } + } + } + + private bool isLoading { get; set; } = false; + + private int numRecord + { + get => _numRecord; + set + { + if (_numRecord != value) + { + _numRecord = value; + var pUpd = Task.Run(async () => await ReloadData()); + pUpd.Wait(); + } + } + } + + private int SelPlantId + { + get + { + int answ = 0; + if (AppMService.Order_Filter != null) + { + answ = AppMService.Order_Filter.PlantId; + } + return answ; + } + set + { + if (!AppMService.Order_Filter.PlantId.Equals(value)) + { + AppMService.Order_Filter.PlantId = value; + var pUpd = Task.Run(async () => await ReloadData()); + pUpd.Wait(); + } + } + } + + private int SelSupplierId + { + get + { + int answ = 0; + if (AppMService.Order_Filter != null) + { + answ = AppMService.Order_Filter.SupplierId; + } + return answ; + } + set + { + if (!AppMService.Order_Filter.SupplierId.Equals(value)) + { + AppMService.Order_Filter.SupplierId = value; + var pUpd = Task.Run(async () => await ReloadData()); + pUpd.Wait(); + } + } + } + + private bool ShowOnlyRefill + { + get + { + return _ShowOnlyRefill; + } + set + { + _ShowOnlyRefill = value; + currPage = 1; + var pUpd = Task.Run(async () => await ReloadData()); + pUpd.Wait(); + } + } + + #endregion Private Properties + + #region Protected Properties + + [Inject] + protected MessageService AppMService { get; set; } + + [Inject] + protected AuthenticationStateProvider AuthenticationStateProvider { get; set; } + + [Inject] + protected GWMSDataService DataService { get; set; } + + protected DateTime DateEnd + { + get + { + DateTime answ = DateTime.Today.AddDays(1); + if (AppMService.Order_Filter != null) + { + answ = AppMService.Order_Filter.DateEnd; + } + return answ; + } + set + { + if (!AppMService.Order_Filter.DateEnd.Equals(value)) + { + AppMService.Order_Filter.DateEnd = value; + var pUpd = Task.Run(async () => await ReloadData()); + pUpd.Wait(); + } + } + } + + protected DateTime DateStart + { + get + { + DateTime answ = DateTime.Today.AddDays(-1); + if (AppMService.Order_Filter != null) + { + answ = AppMService.Order_Filter.DateStart; + } + return answ; + } + set + { + if (!AppMService.Order_Filter.DateStart.Equals(value)) + { + AppMService.Order_Filter.DateStart = value; + var pUpd = Task.Run(async () => await ReloadData()); + pUpd.Wait(); + } + } + } + + [Inject] + protected IJSRuntime JSRuntime { get; set; } + + [Inject] + protected NavigationManager NavManager { get; set; } + + protected int totalCount + { + get + { + int answ = 0; + if (SearchRecords != null) + { + answ = SearchRecords.Count; + } + return answ; + } + } + + #endregion Protected Properties + + #region Public Properties + + public bool ShowAddNew + { + get + { + bool answ = false; + answ = (SelSupplierId > 0 && SelPlantId > 0); + return answ; + } + } + + #endregion Public Properties + + #region Private Methods + + /// + /// Recupero Claims dell'utente... + /// + /// https://docs.microsoft.com/it-it/aspnet/core/blazor/security/?view=aspnetcore-5.0 + /// + /// + private async Task GetClaimsData() + { + // recupero auth + var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); + var user = authState.User; + // se autenticato --> controllo i claims + if (user.Identity.IsAuthenticated) + { + // cerco il claim PlantId... + var plantClaim = user.FindFirst(c => c.Type == "PlantId")?.Value; + int.TryParse(plantClaim, out ClaimPlantId); + } + else + { + ClaimPlantId = -1; + } + } + + private void OnDateEndChanged(DateTime? date) + { + DateEnd = (DateTime)date; + } + + private void OnDateStartChanged(DateTime? date) + { + DateStart = (DateTime)date; + } + + private async Task ReloadData() + { + isLoading = true; + ListRecords = null; + try + { + SearchRecords = await DataService.PlantsAnalisysGetByCode(AppMService.Order_Filter); + SearchRecords = SearchRecords.Where(x => x.HasRefill || !_ShowOnlyRefill).ToList(); + ListRecords = SearchRecords + + .Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); + } + catch (Exception exc) + { + Log.Error($"Eccezione in ReloadData:{Environment.NewLine}{exc}"); + } + isLoading = false; + } + + #endregion Private Methods + + #region Protected Methods + + /// + /// Creazione nuovo record Ordine + /// + protected void CreateNew(PlantLevSumDTO currItem) + { + var currPlant = PlantsList.Where(x => x.PlantId == SelPlantId).FirstOrDefault(); + var currSuppl = SuppliersList.Where(x => x.SupplierId == SelSupplierId).FirstOrDefault(); + if (currPlant != null && currSuppl != null) + { + DateTime ordDate = currItem.DataRif.AddDays(-1); + // creo un nuovo record + currRecord = new OrderModel() + { + DtOrder = ordDate, + PlantId = SelPlantId, + SupplierId = SelSupplierId, + OrderDesc = $"Ord Man {currPlant.PlantDesc} - {ordDate}", + TransporterId = 1, + OrderCode = $"O{currPlant.PlantCode}{ordDate:yyMMddHHmm}", + LevelStart = Math.Round(currItem.LevelMin), + LevelEnd = Math.Round(currItem.LevelMax), + DtExecStart = currItem.FillStart, + DtExecEnd = currItem.FillEnd, + ExecutionQty = Math.Ceiling((currItem.LevelMax - currItem.LevelMin) / currItem.DeltaMin) * currItem.DeltaMin, + OrderQty = Math.Ceiling((currItem.LevelMax - currItem.LevelMin) / 2000) * 2000 + }; + //// aggiorno filtro + //AppMService.Order_Filter = SelectOrderData.Init(5, 10); + } + } + + protected void Edit(PlantLevSumDTO selRecord) + { + // rileggo dal DB il record corrente... + var pUpd = Task.Run(async () => + { + currRecord = await DataService.OrderGetById(selRecord.OrdersIds.FirstOrDefault()); + }); + pUpd.Wait(); + } + + protected void ForceReload(int newNum) + { + numRecord = newNum; + } + + protected void ForceReloadPage(int newNum) + { + currPage = newNum; + } + + protected override async Task OnInitializedAsync() + { + AppMService.ShowSearch = false; + AppMService.PageName = "Ordini"; + AppMService.PageIcon = "fas fa-file-invoice pr-2"; + AppMService.EA_SearchUpdated += OnSeachUpdated; + await ReloadAllData(); + } + + protected async Task ReloadAllData() + { + isLoading = true; + SuppliersList = await DataService.SuppliersGetAll(); + PlantsList = null; + await GetClaimsData(); + // se ho un plantId valido --> altrimenti non abilitato + if (ClaimPlantId == 0) + { + PlantsList = await DataService.PlantsGetAll(); + } + else if (ClaimPlantId > 0) + { + var rawData = await DataService.PlantsGetAll(); + PlantsList = rawData.Where(x => x.PlantId == ClaimPlantId).ToList(); + SelPlantId = ClaimPlantId; + } + else + { + PlantsList = new List(); + } + isLoading = false; + await ReloadData(); + } + + protected void ResetData() + { + DataService.rollBackEdit(currRecord); + currRecord = null; + } + + protected async Task ResetFilter() + { + SelPlantId = 0; + currRecord = null; + SearchRecords = null; + ListRecords = null; + AppMService.Order_Filter = SelectOrderData.Init(5, 10); + await DataService.PlantsAnalisysReset(AppMService.Order_Filter); + await ReloadAllData(); + } + + protected void Select(OrderModel selRecord) + { + // applico filtro da selezione + currRecord = selRecord; + } + + protected async Task UpdateData() + { + currRecord = null; + await DataService.PlantsAnalisysReset(AppMService.Order_Filter); + await ReloadData(); + } + + #endregion Protected Methods + + #region Public Methods + + public string checkSelect(int OrderId) + { + string answ = ""; + if (currRecord != null) + { + try + { + answ = (currRecord.OrderId == OrderId) ? "table-info" : ""; + } + catch + { } + } + return answ; + } + + public void Dispose() + { + AppMService.EA_SearchUpdated -= OnSeachUpdated; + } + + public async void OnSeachUpdated() + { + await UpdateData(); + StateHasChanged(); + } + + #endregion Public Methods + } +} diff --git a/GWMS.UI/Shared/NavMenu.razor b/GWMS.UI/Shared/NavMenu.razor index 4bfc188..0cfade3 100644 --- a/GWMS.UI/Shared/NavMenu.razor +++ b/GWMS.UI/Shared/NavMenu.razor @@ -58,6 +58,12 @@ Storico Impianto +