Fix lettura dati con/senza filtro

This commit is contained in:
Samuele Locatelli
2022-09-14 17:38:16 +02:00
parent f120bb6c28
commit d5f2ed3950
5 changed files with 154 additions and 108 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ else
</th>
<th>Data</th>
<th>Macchina</th>
<th>Flusso</th>
<th>Parametro</th>
<th style="text-align: right">Valore</th>
<th></th>
</tr>
+57 -27
View File
@@ -9,19 +9,49 @@ namespace MP.SPEC.Components
{
#region Public Properties
[Parameter]
public int MaxRecord
{
get => _maxRecord;
set
{
if (_maxRecord != value)
{
_maxRecord = value;
var pUpd = Task.Run(async () => await reloadData(true));
pUpd.Wait();
}
}
}
[Parameter]
public EventCallback<bool> PagerResetReq { get; set; }
[Parameter]
public string SelFlux
{
get => _selFlux;
set
{
if (_selFlux != value)
{
_selFlux = value;
var pUpd = Task.Run(async () => await reloadData(false));
pUpd.Wait();
}
}
}
[Parameter]
public string SelMacchina
{
get => _statoMacchina;
get => _selMacchina;
set
{
if (_statoMacchina != value)
if (_selMacchina != value)
{
_statoMacchina = value;
var pUpd = Task.Run(async () => await reloadData());
_selMacchina = value;
var pUpd = Task.Run(async () => await reloadData(false));
pUpd.Wait();
}
}
@@ -31,8 +61,6 @@ namespace MP.SPEC.Components
#region Public Methods
public string checkSelect(string IdxMacchina)
{
string answ = "";
@@ -48,6 +76,20 @@ namespace MP.SPEC.Components
return answ;
}
public async Task reloadData(bool setChanged)
{
isLoading = true;
SearchRecords = await MDService.FluxLogGetLastFilt(SelMacchina, SelFlux, MaxRecord);
totalCount = SearchRecords.Count;
ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
await Task.Delay(1);
if (setChanged)
{
await InvokeAsync(() => StateHasChanged());
}
isLoading = false;
}
#endregion Public Methods
#region Protected Properties
@@ -60,7 +102,7 @@ namespace MP.SPEC.Components
[Inject]
protected MessageService MessageService { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
@@ -69,8 +111,8 @@ namespace MP.SPEC.Components
{
MessageService.EA_PageUpdated += MessageService_EA_PageUpdated;
MessageService.EA_SearchUpdated += OnSeachUpdated;
await reloadData();
await reloadData(true);
}
protected async void OnSeachUpdated()
@@ -87,17 +129,16 @@ namespace MP.SPEC.Components
protected async Task UpdateData()
{
currRecord = null;
await reloadData();
await reloadData(true);
}
#endregion Protected Methods
#region Private Fields
private string _statoMacchina = "*";
private int _maxRecord = 300;
private string _selFlux = "*";
private string _selMacchina = "*";
private FluxLog? currRecord = null;
private List<FluxLog>? ListRecords;
@@ -139,20 +180,9 @@ namespace MP.SPEC.Components
private async void MessageService_EA_PageUpdated()
{
await reloadData();
}
public async Task reloadData()
{
isLoading = true;
SearchRecords = await MDService.FluxLogGetLastFilt(SelMacchina, "*", 300);
totalCount = SearchRecords.Count;
ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
await Task.Delay(1);
await InvokeAsync(() => StateHasChanged());
isLoading = false;
await reloadData(true);
}
#endregion Private Methods
}
}
}
+8 -2
View File
@@ -323,9 +323,15 @@ namespace MP.SPEC.Data
/// <param name="CodFlux">*=tutti, altrimenti solo selezionato</param>
/// <param name="MaxRec">numero massimo record da restituire</param>
/// <returns></returns>
public Task<List<FluxLog>> FluxLogGetLastFilt(string IdxMacchina, string CodFlux, int MaxRec)
public async Task<List<FluxLog>> FluxLogGetLastFilt(string IdxMacchina, string CodFlux, int MaxRec)
{
return Task.FromResult(dbController.FluxLogGetLastFilt(IdxMacchina, CodFlux, MaxRec));
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
var results = await Task.FromResult(dbController.FluxLogGetLastFilt(IdxMacchina, CodFlux, MaxRec));
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"FluxLogGetLastFilt | Read from DB: {ts.TotalMilliseconds}ms");
return results;
}
/// <summary>
+17 -9
View File
@@ -6,12 +6,21 @@
<div class="col-5">
<div class="d-flex justify-content-around">
<div class="px-2">
<h3><b>PARAMETERS</b></h3>
<h3><b>PARAMETERS</b></h3>
</div>
<button class="btn btn-primary" type="button" >
<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
Valori live
</button>
@if (!liveUpdate)
{
<button class="btn btn-secondary" type="button" @onclick="() => toggleUpdate()">
<small>@lastUpdate</small>
</button>
}
else
{
<button class="btn btn-primary" type="button" @onclick="() => toggleUpdate()">
<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
Valori live
</button>
}
<div class="px-2">
</div><div class="px-2">
</div>
@@ -24,7 +33,7 @@
<div class="px-2">
</div>
<div class="px-2">
<select @bind="@selMacchina" class="form-select">
<select @bind="@selMacchina" class="form-select">
<option value="*">--- Tutti ---</option>
@if (ListMacchine != null)
{
@@ -36,7 +45,7 @@
</select>
</div>
<div class="px-2">
<select @bind="@selFlux" class="form-select">
<select @bind="@selFlux" class="form-select">
<option value="*">--- Tutti ---</option>
@if (ListFlux != null)
{
@@ -50,10 +59,9 @@
</div>
</div>
</div>
</div>*@
</div>
<div class="card-body">
<ListPARAMS SelMacchina="@selMacchina"></ListPARAMS>
<ListPARAMS SelMacchina="@selMacchina" SelFlux="@selFlux"></ListPARAMS>
</div>
<div class="card-footer py-1">
<DataPager @ref="pagerODL" PageSize="numRecord" currPage="currPage" numRecordChanged="ForceReload" numPageChanged="ForceReloadPage" totalCount="totalCount" showLoading="isLoading" />
+71 -69
View File
@@ -1,14 +1,14 @@
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using MP.Data.DatabaseModels;
using MP.SPEC.Components;
using MP.SPEC.Data;
namespace MP.SPEC.Pages
{
public partial class PARAMS
public partial class PARAMS : IDisposable
{
#region Protected Properties
#region Public Methods
public void Dispose()
{
//aTimer.Elapsed -= ElapsedTimer;
@@ -18,7 +18,7 @@ namespace MP.SPEC.Pages
public void ElapsedTimer(object? source, System.Timers.ElapsedEventArgs e)
{
if (!isLoading)
if (!isLoading && liveUpdate)
{
var pUpd = Task.Run(async () =>
{
@@ -29,7 +29,6 @@ namespace MP.SPEC.Pages
}
}
public void StartTimer()
{
int tOutPeriod = 2000;
@@ -37,9 +36,25 @@ namespace MP.SPEC.Pages
aTimer = new System.Timers.Timer(tOutPeriod);
aTimer.Elapsed += ElapsedTimer;
aTimer.Enabled = true;
//aTimer.AutoReset = true;
aTimer.Start();
}
private static System.Timers.Timer aTimer = null!;
#endregion Public Methods
#region Protected Fields
protected string _selFlux = "*";
protected string _selMacchina = "*";
protected string lastUpdate = "-";
protected bool liveUpdate = false;
protected DataPager pagerODL;
protected bool reqNew = false;
#endregion Protected Fields
#region Protected Properties
[Inject]
protected IJSRuntime JSRuntime { get; set; }
@@ -56,8 +71,6 @@ namespace MP.SPEC.Pages
#region Protected Methods
protected void ForceReload(int newNum)
{
numRecord = newNum;
@@ -68,29 +81,6 @@ namespace MP.SPEC.Pages
currPage = newNum;
}
protected async Task pgResetReq(bool doReset)
{
if (doReset)
{
await pagerODL.resetCurrPage();
}
}
protected DataPager pagerODL;
protected bool reqNew = false;
/// <summary>
/// Crea nuovo record e va in editing...
/// </summary>
/// <returns></returns>
protected async Task reqNewPODL()
{
reqNew = !reqNew;
await Task.Delay(1);
}
protected override async Task OnInitializedAsync()
{
// abilito ricerca...
@@ -104,34 +94,50 @@ namespace MP.SPEC.Pages
ListMacchine = await MDService.MacchineGetAll();
StartTimer();
// carico dati
lastUpdate = $"Last Snapshot: {DateTime.Now:yyyy/MM/dd HH:mm:ss}";
await reloadFilters();
await reloadData();
}
private async void MsgService_EA_MacchUpdated()
protected async Task pgResetReq(bool doReset)
{
await reloadData();
if (doReset)
{
await pagerODL.resetCurrPage();
}
}
private string currAziend { get; set; } = "*";
/// <summary>
/// Crea nuovo record e va in editing...
/// </summary>
/// <returns></returns>
protected async Task reqNewPODL()
{
reqNew = !reqNew;
await Task.Delay(1);
}
private List<MP.Data.DatabaseModels.AnagGruppi>? ListAziende;
protected async Task toggleUpdate()
{
liveUpdate = !liveUpdate;
await reloadData();
}
#endregion Protected Methods
#region Private Fields
private List<MP.Data.DatabaseModels.ListValues>? ListStati;
private List<MP.Data.DatabaseModels.Macchine>? ListMacchine;
private static System.Timers.Timer aTimer = null!;
private List<string>? ListFlux;
private List<MP.Data.DatabaseModels.Macchine>? ListMacchine;
#endregion Private Fields
#region Private Properties
private string currAziend { get; set; } = "*";
private int currPage
{
@@ -147,40 +153,22 @@ namespace MP.SPEC.Pages
set => MsgService.numRecord = value;
}
private string selFlux
{
get => _selFlux;
set => _selFlux = value;
}
private string selMacchina
{
get => _selMacchina;
set => _selMacchina = value;
#if false
get => MsgService.SelMacchina;
set => MsgService.SelMacchina = value;
}
private string selFlux { get; set; } = "*";
#if false
private string selStato
{
get => _selStato;
set
{
if (!_selStato.Equals(value))
{
_selStato = value;
addEnabled = selStato != "*";
////StateHasChanged();
//var pUpd = Task.Run(async () =>
//{
// //await reloadData();
// await Task.Delay(1);
// await InvokeAsync(() => StateHasChanged());
//});
//pUpd.Wait();
}
}
}
#endif
private bool addEnabled = false;
}
private int totalCount
{
@@ -192,15 +180,29 @@ namespace MP.SPEC.Pages
#region Private Methods
private async void MsgService_EA_MacchUpdated()
{
await reloadFilters();
}
private async Task reloadData()
{
isLoading = true;
await Task.Delay(1);
ListFlux = await MDService.ParametriGetFilt(selMacchina);
if (!liveUpdate)
{
lastUpdate = $"Last Snapshot: {DateTime.Now:yyyy/MM/dd HH:mm:ss}";
}
isLoading = false;
await Task.Delay(1);
}
private async Task reloadFilters()
{
await Task.Delay(1);
ListFlux = await MDService.ParametriGetFilt(selMacchina);
}
#endregion Private Methods
}
}
}