From cab86305cfe10c01cf1e9da5db24022e6b1f6850 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 28 Dec 2022 12:11:56 +0100 Subject: [PATCH] Fix gestione rimbalzo doppio update totalcount --- MP.INVE/Components/ListQrOpr.razor | 4 +- MP.INVE/Components/ListQrOpr.razor.cs | 179 ++++++++++++++---------- MP.INVE/Data/SelectQrOperatoreParams.cs | 19 +-- MP.INVE/MP.INVE.csproj | 2 +- MP.INVE/Pages/OperatoreQR.razor | 2 +- MP.INVE/Pages/OperatoreQR.razor.cs | 116 ++++++++------- MP.INVE/Resources/ChangeLog.html | 2 +- MP.INVE/Resources/VersNum.txt | 2 +- MP.INVE/Resources/manifest.xml | 2 +- 9 files changed, 187 insertions(+), 141 deletions(-) diff --git a/MP.INVE/Components/ListQrOpr.razor b/MP.INVE/Components/ListQrOpr.razor index 2dacecea..0a35a81b 100644 --- a/MP.INVE/Components/ListQrOpr.razor +++ b/MP.INVE/Components/ListQrOpr.razor @@ -1,8 +1,8 @@ -@if (elencoOPeratori != null) +@if (elencoOperatori != null) {
- @foreach (var item in elencoOPeratori) + @foreach (var item in elencoOperatori) {
diff --git a/MP.INVE/Components/ListQrOpr.razor.cs b/MP.INVE/Components/ListQrOpr.razor.cs index de0eb3a7..7817e756 100644 --- a/MP.INVE/Components/ListQrOpr.razor.cs +++ b/MP.INVE/Components/ListQrOpr.razor.cs @@ -1,65 +1,58 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Components; -using System.Net.Http; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Components.Authorization; -using Microsoft.AspNetCore.Components.Forms; -using Microsoft.AspNetCore.Components.Routing; -using Microsoft.AspNetCore.Components.Web; -using Microsoft.AspNetCore.Components.Web.Virtualization; using Microsoft.JSInterop; -using MP.INVE; -using MP.INVE.Shared; -using MP.INVE.Components; -using MP.INVE.Data; using MP.Data.DatabaseModels; +using MP.INVE.Data; namespace MP.INVE.Components { public partial class ListQrOpr { + #region Public Properties + [Parameter] public SelectQrOperatoreParams currParams { get; set; } = null!; [Parameter] public bool isLoading { get; set; } - [Inject] - protected MiDataService MIService { get; set; } = null!; - [Inject] - private IConfiguration Configuration { get; set; } = null!; - protected List? elencoOPeratori = new List(); + [Parameter] + public EventCallback TotalChanged { get; set; } + + + private SelectQrOperatoreParams? lastParams { get; set; } = null; + + #endregion Public Properties + + #region Protected Fields + + protected List? elencoOperatori = new List(); + protected List? SearchRecords = new List(); - [Inject] - protected IJSRuntime JSRuntime { get; set; } = null!; - protected override async Task OnAfterRenderAsync(bool firstRender) - { - await Task.Delay(50); - if (firstRender) - { - //await reloadData(true); - } - } - protected override async Task OnParametersSetAsync() - { - await reloadData(true); - } - private int _idOperatore = 0; - protected int idOperatore - { - get => _idOperatore; - set => _idOperatore = value; - } - private string _authKey = ""; + + #endregion Protected Fields + + #region Protected Properties + protected string authKey { get => _authKey; set => _authKey = value; } + protected string BaseUrlTab { get => $"{Configuration["ServerConf:BaseUrlJumper"]}"; } + + protected int idOperatore + { + get => _idOperatore; + set => _idOperatore = value; + } + + [Inject] + protected IJSRuntime JSRuntime { get; set; } = null!; + + [Inject] + protected MiDataService MIService { get; set; } = null!; + protected string rawCode { get @@ -70,23 +63,89 @@ namespace MP.INVE.Components } } + #endregion Protected Properties + + #region Protected Methods + + //protected override async Task OnAfterRenderAsync(bool firstRender) + //{ + // await Task.Delay(50); + // if (firstRender) + // { + // //await reloadData(true); + // } + //} + + protected override async Task OnParametersSetAsync() + { + bool doReload = lastParams == null; + if (doReload || !currParams.Equals(lastParams)) + { + lastParams = currParams.Clone(); + await reloadData(true); + } + } + + #endregion Protected Methods + + #region Private Fields + + private string _authKey = ""; + + private int _idOperatore = 0; + + private int _totalCount = 0; + + #endregion Private Fields + + #region Private Properties + + [Inject] + private IConfiguration Configuration { get; set; } = null!; + + private int currPage + { + get => currParams.CurrPage; + } + + private int numRecord + { + get => currParams.NumRec; + } + + private int totalCount + { + get => _totalCount; + set + { + if (_totalCount != value) + { + _totalCount = value; + TotalChanged.InvokeAsync(value); + } + } + } + + #endregion Private Properties + + #region Private Methods + private async Task reloadData(bool first) { - elencoOPeratori = null; + elencoOperatori = null; isLoading = true; SearchRecords = MIService.ElencoOperatori(); totalCount = SearchRecords.Count; - elencoOPeratori = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); + elencoOperatori = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); await Task.Delay(1); await InvokeAsync(() => StateHasChanged()); await Task.Delay(1); if (first) { - if (elencoOPeratori != null) + if (elencoOperatori != null) { - - foreach (var item in elencoOPeratori) + foreach (var item in elencoOperatori) { idOperatore = item.MatrOpr; authKey = MIService.EncriptData(item.authKey); @@ -98,33 +157,7 @@ namespace MP.INVE.Components } isLoading = false; } - private int numRecord - { - get => currParams.NumRec; - set - { - currParams.NumRec = value; - StateHasChanged(); - } - } - private int currPage - { - get => currParams.CurrPage; - set - { - currParams.CurrPage = value; - StateHasChanged(); - } - } - private int totalCount - { - get => currParams.TotCount; - set - { - currParams.TotCount = value; - StateHasChanged(); - } - } + #endregion Private Methods } } \ No newline at end of file diff --git a/MP.INVE/Data/SelectQrOperatoreParams.cs b/MP.INVE/Data/SelectQrOperatoreParams.cs index 7389981c..2bf61c34 100644 --- a/MP.INVE/Data/SelectQrOperatoreParams.cs +++ b/MP.INVE/Data/SelectQrOperatoreParams.cs @@ -1,6 +1,4 @@ -using MP.Data; - -namespace MP.INVE.Data +namespace MP.INVE.Data { public class SelectQrOperatoreParams { @@ -14,15 +12,21 @@ namespace MP.INVE.Data #region Public Properties public int CurrPage { get; set; } = 1; + + public int MaxRecord { get; set; } = 100; + public int NumRec { get; set; } = 6; - public int TotCount { get; set; } = 0; - public int MaxRecord { get; set; } = 100; public string searchVal { get; set; } = ""; #endregion Public Properties #region Public Methods + public SelectQrOperatoreParams Clone() + { + return (SelectQrOperatoreParams)this.MemberwiseClone(); + } + public override bool Equals(object obj) { if (!(obj is SelectQrOperatoreParams item)) @@ -34,15 +38,12 @@ namespace MP.INVE.Data if (MaxRecord != item.MaxRecord) return false; - if (TotCount != item.TotCount) - return false; - if (NumRec != item.NumRec) + return false; if (CurrPage != item.CurrPage) return false; - return true; } diff --git a/MP.INVE/MP.INVE.csproj b/MP.INVE/MP.INVE.csproj index d76a5476..0b353cef 100644 --- a/MP.INVE/MP.INVE.csproj +++ b/MP.INVE/MP.INVE.csproj @@ -5,7 +5,7 @@ enable enable MP.INVE - 6.16.2212.2811 + 6.16.2212.2812 diff --git a/MP.INVE/Pages/OperatoreQR.razor b/MP.INVE/Pages/OperatoreQR.razor index 0248ee20..a3e0cc4c 100644 --- a/MP.INVE/Pages/OperatoreQR.razor +++ b/MP.INVE/Pages/OperatoreQR.razor @@ -13,7 +13,7 @@ } else { - + }