251 lines
6.6 KiB
C#
251 lines
6.6 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using MP.Data.DatabaseModels;
|
|
using MP.SPEC.Data;
|
|
using System.Diagnostics;
|
|
|
|
namespace MP.SPEC.Components
|
|
{
|
|
public partial class ListPARAMS : IDisposable
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> PagerResetReq { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<FluxLog> RecordSel { get; set; }
|
|
|
|
[Parameter]
|
|
public SelectFluxParams SelFilter { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public EventCallback<int> TotRecordChanged { get; set; }
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public string checkSelect(FluxLog selRecord)
|
|
{
|
|
string answ = "";
|
|
if (currRecord != null)
|
|
{
|
|
try
|
|
{
|
|
answ = (currRecord.IdxMacchina == selRecord.IdxMacchina && currRecord.dtEvento == selRecord.dtEvento && currRecord.CodFlux == selRecord.CodFlux) ? "table-info" : "";
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await Task.Delay(1);
|
|
// se sono live + parametri cambiati --> rileggo...
|
|
if (SelFilter.LiveUpdate)
|
|
{
|
|
await reloadData(false);
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
aTimer.Elapsed -= ElapsedTimer;
|
|
MessageService.EA_PageUpdated -= MessageService_EA_PageUpdated;
|
|
MessageService.EA_SearchUpdated -= OnSeachUpdated;
|
|
aTimer.Stop();
|
|
aTimer.Dispose();
|
|
}
|
|
|
|
public void ElapsedTimer(object? source, System.Timers.ElapsedEventArgs e)
|
|
{
|
|
if (!isLoading && LiveUpdate)
|
|
{
|
|
aTimer.Stop();
|
|
// inizio misura esecuzione
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
var pUpd = Task.Run(async () =>
|
|
{
|
|
await Task.Delay(1);
|
|
await InvokeAsync(() => reloadData(true));
|
|
});
|
|
pUpd.Wait();
|
|
// misuro tempo esecuzione
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
int deltaTime = RefreshPeriod - (int)ts.TotalMilliseconds;
|
|
aTimer.Interval = deltaTime > 100 ? deltaTime : 100;
|
|
aTimer.Start();
|
|
}
|
|
}
|
|
|
|
public async Task reloadData(bool setChanged)
|
|
{
|
|
isLoading = true;
|
|
DateTime limitData = DateTime.Now;
|
|
if (SelDtMax != null)
|
|
{
|
|
limitData = (DateTime)SelDtMax;
|
|
}
|
|
SearchRecords = await MDService.FluxLogGetLastFilt(limitData, 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;
|
|
}
|
|
|
|
public void StartTimer()
|
|
{
|
|
aTimer = new System.Timers.Timer(RefreshPeriod);
|
|
aTimer.Elapsed += ElapsedTimer;
|
|
aTimer.Enabled = true;
|
|
aTimer.Start();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected MpDataService MDService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected MessageService MessageService { get; set; } = null!;
|
|
|
|
protected int RefreshPeriod
|
|
{
|
|
get => SelFilter.TempoAgg;
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
MessageService.EA_PageUpdated += MessageService_EA_PageUpdated;
|
|
MessageService.EA_SearchUpdated += OnSeachUpdated;
|
|
StartTimer();
|
|
|
|
await reloadData(true);
|
|
}
|
|
|
|
//protected int RefreshPeriod { get; set; } = 5000;
|
|
protected async void OnSeachUpdated()
|
|
{
|
|
await InvokeAsync(() =>
|
|
{
|
|
PagerResetReq.InvokeAsync(false);
|
|
//currPage = 1;
|
|
Task task = UpdateData();
|
|
StateHasChanged();
|
|
});
|
|
}
|
|
|
|
protected async Task resetSel()
|
|
{
|
|
currRecord = null;
|
|
await RecordSel.InvokeAsync(null);
|
|
}
|
|
|
|
protected async Task selRecord(FluxLog selRec)
|
|
{
|
|
currRecord = selRec;
|
|
await RecordSel.InvokeAsync(selRec);
|
|
}
|
|
|
|
protected async Task UpdateData()
|
|
{
|
|
currRecord = null;
|
|
await reloadData(true);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static System.Timers.Timer aTimer = null!;
|
|
|
|
private int _totalCount = 0;
|
|
private FluxLog? currRecord = null;
|
|
private List<FluxLog>? ListRecords;
|
|
private List<FluxLog>? SearchRecords;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private int currPage
|
|
{
|
|
get => MessageService.currPage;
|
|
set => MessageService.currPage = value;
|
|
}
|
|
|
|
private bool isLoading { get; set; } = false;
|
|
|
|
private bool LiveUpdate
|
|
{
|
|
get => SelFilter.LiveUpdate;
|
|
}
|
|
|
|
private int MaxRecord
|
|
{
|
|
get => SelFilter.MaxRecord;
|
|
}
|
|
|
|
private int numRecord
|
|
{
|
|
get => MessageService.numRecord;
|
|
set => MessageService.numRecord = value;
|
|
}
|
|
|
|
private string SelFlux
|
|
{
|
|
get => SelFilter.CodFlux;
|
|
}
|
|
|
|
private string SelMacchina
|
|
{
|
|
get => SelFilter.IdxMacchina;
|
|
}
|
|
private DateTime? SelDtMax
|
|
{
|
|
get => SelFilter.dtMax;
|
|
}
|
|
|
|
private int totalCount
|
|
{
|
|
get => _totalCount;
|
|
set
|
|
{
|
|
if (_totalCount != value)
|
|
{
|
|
_totalCount = value;
|
|
TotRecordChanged.InvokeAsync(value);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async void MessageService_EA_PageUpdated()
|
|
{
|
|
await reloadData(true);
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |