From c3da657b260be3e51d101cfdfdab73661f10e464 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 27 Oct 2021 17:47:56 +0200 Subject: [PATCH] Update gestione setup parametri a scadenza --- GWMS.Data/Controllers/GWMSController.cs | 4 +- GWMS.UI/Components/ParamEditor.razor | 19 ++- GWMS.UI/Components/ParamEditor.razor.cs | 89 ++++++++++ GWMS.UI/Components/ParamSet.razor | 181 ++++++++------------- GWMS.UI/Components/ParamSet.razor.cs | 52 +++++- GWMS.UI/Components/ParamSetEditor.razor | 55 +++++++ GWMS.UI/Components/ParamSetEditor.razor.cs | 98 +++++++++++ GWMS.UI/Components/TValue.cs | 6 + GWMS.UI/Data/GWMSDataService.cs | 6 +- GWMS.UI/GWMS.UI.csproj | 5 +- GWMS.UI/Pages/PlantParameters.razor | 2 +- Resources/ChangeLog.html | 2 +- Resources/VersNum.txt | 2 +- Resources/manifest.xml | 2 +- 14 files changed, 389 insertions(+), 134 deletions(-) create mode 100644 GWMS.UI/Components/ParamSetEditor.razor create mode 100644 GWMS.UI/Components/ParamSetEditor.razor.cs create mode 100644 GWMS.UI/Components/TValue.cs diff --git a/GWMS.Data/Controllers/GWMSController.cs b/GWMS.Data/Controllers/GWMSController.cs index 4fb6910..823b6d8 100644 --- a/GWMS.Data/Controllers/GWMSController.cs +++ b/GWMS.Data/Controllers/GWMSController.cs @@ -158,14 +158,14 @@ namespace GWMS.Data.Controllers return dbResult; } - public List GetParamSet(int PlantId) + public List GetParamSet(int PlantId, string ParamUid) { List dbResult = new List(); using (GWMSContext localDbCtx = new GWMSContext(_configuration)) { dbResult = localDbCtx .DbSetParamSet - .Where(x => (x.PlantId == PlantId || PlantId == 0)) + .Where(x => (x.PlantId == PlantId || PlantId == 0) && (x.ParamUid == ParamUid || ParamUid == "")) .OrderBy(x => x.Scadenza) .ToList(); } diff --git a/GWMS.UI/Components/ParamEditor.razor b/GWMS.UI/Components/ParamEditor.razor index 1ee6e2d..1964e81 100644 --- a/GWMS.UI/Components/ParamEditor.razor +++ b/GWMS.UI/Components/ParamEditor.razor @@ -12,12 +12,15 @@
-
-
-
+
+ +
+
+
+
@_currItem.uid
-
+
@_currItem.name
@@ -25,13 +28,11 @@
- - Valore rilevato: @_currItem.value - +
- +
- + Act: @_currItem.value
diff --git a/GWMS.UI/Components/ParamEditor.razor.cs b/GWMS.UI/Components/ParamEditor.razor.cs index 2b95e90..7117d52 100644 --- a/GWMS.UI/Components/ParamEditor.razor.cs +++ b/GWMS.UI/Components/ParamEditor.razor.cs @@ -1,9 +1,11 @@ using AutoMapper.Configuration; +using GWMS.Data.DatabaseModels; using GWMS.Data.DTO; using GWMS.UI.Data; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Identity; using Microsoft.JSInterop; +using NLog; using System; using System.Collections.Generic; using System.Linq; @@ -14,9 +16,18 @@ namespace GWMS.UI.Components { public partial class ParamEditor { + #region Private Fields + + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + private List ListRecords; + + #endregion Private Fields + #region Protected Fields protected objItem _currItem = new objItem(); + protected int _plantId = 0; + protected string ParamUid = ""; #endregion Protected Fields @@ -29,9 +40,46 @@ namespace GWMS.UI.Components #region Protected Properties + protected decimal CalcVal + { + get + { + decimal answ = currItem.reqValDec; + if (totalCount > 0) + { + // prendo i 2 valori precedente e successivo + DateTime oggi = DateTime.Today; + var prevPar = ListRecords.Where(x => x.Scadenza <= oggi).OrderByDescending(x => x.Scadenza).FirstOrDefault(); + var nextPar = ListRecords.Where(x => x.Scadenza >= oggi).OrderBy(x => x.Scadenza).FirstOrDefault(); + // se ho valori + if (prevPar != null && nextPar != null) + { + double num = oggi.Subtract(prevPar.Scadenza).TotalDays; + double den = nextPar.Scadenza.Subtract(prevPar.Scadenza).TotalDays; + den = den != 0 ? den : 1; + answ = prevPar.TargetVal + (nextPar.TargetVal - prevPar.TargetVal) * (decimal)(num / den); + } + } + return answ; + } + } + [Inject] protected GWMSDataService DataService { get; set; } + protected int totalCount + { + get + { + int answ = 0; + if (ListRecords != null) + { + answ = ListRecords.Count; + } + return answ; + } + } + #endregion Protected Properties #region Public Properties @@ -46,6 +94,7 @@ namespace GWMS.UI.Components set { _currItem = value; + ParamUid = _currItem.uid; } } @@ -58,6 +107,19 @@ namespace GWMS.UI.Components [Parameter] public string IdxMacchina { get; set; } = ""; + [Parameter] + public int PlantId + { + get + { + return _plantId; + } + set + { + _plantId = value; + } + } + #endregion Public Properties #region Private Methods @@ -67,6 +129,19 @@ namespace GWMS.UI.Components await DataReset.InvokeAsync(0); } + private async Task ReloadData() + { + ListRecords = null; + try + { + ListRecords = await DataService.ParamSetGetFilt(PlantId, ParamUid); + } + catch (Exception exc) + { + Log.Error($"Eccezione in ReloadData:{Environment.NewLine}{exc}"); + } + } + private async Task saveUpdate() { if (!await JSRuntime.InvokeAsync("confirm", "Sicuro di voler inviare il valore per parametro richiesto?")) @@ -84,5 +159,19 @@ namespace GWMS.UI.Components } #endregion Private Methods + + #region Protected Methods + + protected override async Task OnInitializedAsync() + { + await ReloadData(); + } + + protected void setCalc() + { + currItem.reqValDec = Math.Round(CalcVal * 1000) / 1000; + } + + #endregion Protected Methods } } \ No newline at end of file diff --git a/GWMS.UI/Components/ParamSet.razor b/GWMS.UI/Components/ParamSet.razor index 4b22ab4..1a82c41 100644 --- a/GWMS.UI/Components/ParamSet.razor +++ b/GWMS.UI/Components/ParamSet.razor @@ -1,117 +1,74 @@ @using GWMS.UI.Components -
-
-
-
- Programmazione Parametri -
-
- @*
-
-
- -
-
-
-
-
- - - +@if (currRecord != null) +{ + +} +@if (ListRecords == null) +{ + +} +else if (totalCount == 0) +{ +
Nessun record trovato
+ +} +else +{ +
+
+ + + + + + + + + + + + + @foreach (var record in ListRecords) + { + + + + + + + + + } + +
ParametroScadenzaValoreNote
+ @if (currRecord == null) + { + + } + else + { + + } + +
@record.ParamUid
+
+
@record.Scadenza.ToString("yyyy.MM.dd")
+
+
@record.TargetVal.ToString("N2")
+
+
+ @record.Note
- - - - *@ - +
+ +
-
- @if (currRecord != null) - { - Editor singoloparametro - @**@ - } - @if (ListRecords == null) - { - - } - else if (totalCount == 0) - { -
Nessun record trovato
- } - else - { -
-
- - - - - - - - - - @* - *@ - - - - @foreach (var record in ListRecords) - { - - - - - - - - - } - -
ParametroScadenzaValore ProgrammatoNoteCarico Ordine
- @if (currRecord == null) - { - - } - else - { - - } - -
@record.ParamUid
-
-
@record.Scadenza.ToString("yyyy.MM.dd HH:mm:ss")
-
-
@record.TargetVal
-
-
- @record.Note -
-
- -
-
-
- } -
- -
\ No newline at end of file +} \ No newline at end of file diff --git a/GWMS.UI/Components/ParamSet.razor.cs b/GWMS.UI/Components/ParamSet.razor.cs index 2cc1ace..896e5b6 100644 --- a/GWMS.UI/Components/ParamSet.razor.cs +++ b/GWMS.UI/Components/ParamSet.razor.cs @@ -23,6 +23,7 @@ namespace GWMS.UI.Components #region Protected Fields + protected string _paramUid = ""; protected int _plantId = 0; #endregion Protected Fields @@ -59,7 +60,22 @@ namespace GWMS.UI.Components #region Public Properties [Parameter] - public int PlantId + public string ParamUidSel + { + get + { + return _paramUid; + } + set + { + _paramUid = value; + var pUpd = Task.Run(async () => await ReloadData()); + pUpd.Wait(); + } + } + + [Parameter] + public int PlantIdSel { get { @@ -68,7 +84,6 @@ namespace GWMS.UI.Components set { _plantId = value; - var pUpd = Task.Run(async () => await ReloadData()); pUpd.Wait(); } @@ -78,13 +93,31 @@ namespace GWMS.UI.Components #region Private Methods + /// + /// Aggiunta nuovo record + /// + private async void AddNew() + { + // creo un nuovo evento su oggi... + var newRecord = new ParamSetModel() + { + ParamUid = ParamUidSel, + PlantId = PlantIdSel, + Scadenza = DateTime.Today.AddDays(1), + TargetVal = 0, + Note = "Nuovo record" + }; + await DataService.ParamSetUpdate(newRecord); + await ReloadData(); + } + private async Task ReloadData() { isLoading = true; ListRecords = null; try { - ListRecords = await DataService.ParamSetGetByPlant(PlantId); + ListRecords = await DataService.ParamSetGetFilt(PlantIdSel, ParamUidSel); } catch (Exception exc) { @@ -119,6 +152,19 @@ namespace GWMS.UI.Components await ReloadData(); } + protected void ResetData() + { + DataService.rollBackEdit(currRecord); + currRecord = null; + } + + protected async Task UpdateData() + { + currRecord = null; + await DataService.ParamSetUpdate(currRecord); + await ReloadData(); + } + #endregion Protected Methods #region Public Methods diff --git a/GWMS.UI/Components/ParamSetEditor.razor b/GWMS.UI/Components/ParamSetEditor.razor new file mode 100644 index 0000000..ebc39c0 --- /dev/null +++ b/GWMS.UI/Components/ParamSetEditor.razor @@ -0,0 +1,55 @@ +@using Blazorise +@using GWMS.UI.Components +@using Microsoft.AspNetCore.Components.Authorization +@using GWMS.UI.Data +@using Microsoft.Extensions.Configuration + +
+
+ Modifica +
+
+ + +
+
+ @_currItem.ParamUid +
+
+
+
+ Note: +
+ +
+
+
+
+
+
+
+ Scadenza +
+ +
+
+
+
+
+ Valore +
+ +
+
+
+
+
+ +
+
+ +
+
+
+
+
\ No newline at end of file diff --git a/GWMS.UI/Components/ParamSetEditor.razor.cs b/GWMS.UI/Components/ParamSetEditor.razor.cs new file mode 100644 index 0000000..7ddd25e --- /dev/null +++ b/GWMS.UI/Components/ParamSetEditor.razor.cs @@ -0,0 +1,98 @@ +using AutoMapper.Configuration; +using GWMS.Data.DatabaseModels; +using GWMS.Data.DTO; +using GWMS.UI.Data; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Identity; +using Microsoft.JSInterop; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using static GWMS.Data.IobObjects; + +namespace GWMS.UI.Components +{ + public partial class ParamSetEditor + { + #region Protected Fields + + protected ParamSetModel _currItem = new ParamSetModel(); + + #endregion Protected Fields + + #region Private Properties + + [Inject] + private IJSRuntime JSRuntime { get; set; } + + #endregion Private Properties + + #region Protected Properties + + [Inject] + protected GWMSDataService DataService { get; set; } + + #endregion Protected Properties + + #region Public Properties + + [Parameter] + public ParamSetModel currItem + { + get + { + return _currItem; + } + set + { + _currItem = value; + } + } + + [Parameter] + public EventCallback DataReset { get; set; } + + [Parameter] + public EventCallback DataUpdated { get; set; } + + [Parameter] + public string IdxMacchina { get; set; } = ""; + + #endregion Public Properties + + #region Private Methods + + private async Task cancelUpdate() + { + await DataReset.InvokeAsync(0); + } + + private async Task saveUpdate() + { + if (!await JSRuntime.InvokeAsync("confirm", "Sicuro di voler modificare la programmazione del parametro?")) + return; + + if (_currItem != null) + { + await DataService.ParamSetUpdate(_currItem); + await DataUpdated.InvokeAsync(0); + } + else + { + Console.WriteLine("Record null!"); + } + } + + #endregion Private Methods + + #region Protected Methods + + protected string? FormatValueAsString(TValue? value) + { + return $"{value:N3}"; + } + + #endregion Protected Methods + } +} \ No newline at end of file diff --git a/GWMS.UI/Components/TValue.cs b/GWMS.UI/Components/TValue.cs new file mode 100644 index 0000000..0c1a698 --- /dev/null +++ b/GWMS.UI/Components/TValue.cs @@ -0,0 +1,6 @@ +namespace GWMS.UI.Components +{ + public class TValue + { + } +} \ No newline at end of file diff --git a/GWMS.UI/Data/GWMSDataService.cs b/GWMS.UI/Data/GWMSDataService.cs index dff4249..193083c 100644 --- a/GWMS.UI/Data/GWMSDataService.cs +++ b/GWMS.UI/Data/GWMSDataService.cs @@ -938,17 +938,17 @@ namespace GWMS.UI.Data } /// - /// Recupera ParamSet dato plant + /// Recupera ParamSet dato plant e UID parametro /// /// /// - public async Task> ParamSetGetByPlant(int PlantId) + public async Task> ParamSetGetFilt(int PlantId, string ParamUid) { List dbResult = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - dbResult = dbController.GetParamSet(PlantId); + dbResult = dbController.GetParamSet(PlantId, ParamUid); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"Effettuata lettura da DB per ParamSetGetByPlant: {ts.TotalMilliseconds} ms"); diff --git a/GWMS.UI/GWMS.UI.csproj b/GWMS.UI/GWMS.UI.csproj index c4dae47..37a2d69 100644 --- a/GWMS.UI/GWMS.UI.csproj +++ b/GWMS.UI/GWMS.UI.csproj @@ -2,7 +2,7 @@ net5.0 - 1.0.2110.2711 + 1.0.2110.2717 95c9f021-52d1-4390-a670-5810b7b777b0 true true @@ -65,6 +65,9 @@ + + ParamEditor.razor.cs + Transporters - Copy.razor.cs diff --git a/GWMS.UI/Pages/PlantParameters.razor b/GWMS.UI/Pages/PlantParameters.razor index 2d34c80..d9a6da7 100644 --- a/GWMS.UI/Pages/PlantParameters.razor +++ b/GWMS.UI/Pages/PlantParameters.razor @@ -42,7 +42,7 @@
@if (currRecord != null) { - + } @if (ListRecords == null) { diff --git a/Resources/ChangeLog.html b/Resources/ChangeLog.html index 99f2a9e..c1a0e7f 100644 --- a/Resources/ChangeLog.html +++ b/Resources/ChangeLog.html @@ -1,6 +1,6 @@ GWMS - Gas Warehouse Management System -

Versione: 1.0.2110.2711

+

Versione: 1.0.2110.2717


Note di rilascio:
  • diff --git a/Resources/VersNum.txt b/Resources/VersNum.txt index 884c201..174aa17 100644 --- a/Resources/VersNum.txt +++ b/Resources/VersNum.txt @@ -1 +1 @@ -1.0.2110.2711 +1.0.2110.2717 diff --git a/Resources/manifest.xml b/Resources/manifest.xml index ca92a9c..b0c3116 100644 --- a/Resources/manifest.xml +++ b/Resources/manifest.xml @@ -1,6 +1,6 @@ - 1.0.2110.2711 + 1.0.2110.2717 http://nexus.steamware.net/repository/SWS/GWMS/stable/0/GWMS.UI.zip http://nexus.steamware.net/repository/SWS/GWMS/stable/0/ChangeLog.html false