Files
mapo-core/MP.SPEC/Pages/FluxLogStatus.razor.cs
T
Samuele Locatelli afd3ec34bb SPEC:
- Completata procedura adv x ricalcolo FluxLog
2023-10-23 12:07:57 +02:00

194 lines
5.4 KiB
C#

using global::Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using MP.SPEC.Data;
using NLog;
using static EgwCoreLib.Utils.DtUtils;
using static MP.Data.Enum;
namespace MP.SPEC.Pages
{
public partial class FluxLogStatus
{
#region Protected Fields
protected DataInterval IntReq = DataInterval.hour;
protected int numRecPage = 10;
protected int pageNum = 1;
protected int totalCount = 0;
protected ValSelection ValMode = ValSelection.Center;
#endregion Protected Fields
#region Protected Properties
protected List<string> fluxList { get; set; } = new List<string>();
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
protected Dictionary<string, string> ListMacchineAll { get; set; } = new Dictionary<string, string>();
[Inject]
protected MpDataService MDataServ { get; set; } = null!;
protected int NumItem
{
get => numItem;
set
{
if (numItem != value)
{
// controllo valori ammissibili
numItem = value >= 1 ? value : 1;
}
}
}
#endregion Protected Properties
#region Protected Methods
/// <summary>
/// Esegue cleanup dati
/// </summary>
/// <returns></returns>
protected async Task DoCleanup()
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Attenzione! il task di Data Cleanup eliminerà in modo definitivo i dati in eccesso secondo lo schema impostato, sei sicuro di voler procedere?"))
return;
isProcessing = true;
int currStep = 1;
int stepVal = 1;
foreach (var item in fluxList)
{
await InvokeAsync(StateHasChanged);
// aggiorno valori
currVal = (currStep - 1) * stepVal;
nextVal = currStep * stepVal;
// processo i flussi 1:1 x mandare update ad avanzamento
await MDataServ.FluxLogDataRedux(idxMaccSel, new List<string> { item }, CurrPeriodo, ValMode, IntReq, NumItem);
currStep++;
}
//await MDataServ.FluxLogDataRedux(idxMaccSel, fluxList, CurrPeriodo, ValMode, IntReq, maxItem);
isProcessing = false;
}
/// <summary>
/// Esegue cleanup dati
/// </summary>
/// <returns></returns>
protected async Task IdxRebuild()
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Manutenzione Database: si tratta di un operazione che può richiedere un tempo levato sei sicuro di voler procedere?"))
return;
isProcessing = true;
await MDataServ.ForceDbMaint(true, true, true, 1000, 10, 50);
isProcessing = false;
}
protected override async Task OnInitializedAsync()
{
await ReloadData();
}
protected async Task ReloadMacchine()
{
if (ListMacchineAll == null || ListMacchineAll.Count == 0)
{
var rawData = await MDataServ.MacchineGetFilt("*");
// trasformo!
if (rawData != null)
{
ListMacchineAll = rawData.ToDictionary(x => x.IdxMacchina, x => $"{x.IdxMacchina} | {x.Nome}");
}
}
}
protected async Task SaveFluxList(List<string> newList)
{
fluxList = newList;
await Task.Delay(1);
}
protected void SaveNumRec(int newNum)
{
if (numRecPage != newNum)
{
numRecPage = newNum;
}
}
protected void SavePage(int newNum)
{
if (pageNum != newNum)
{
pageNum = newNum;
}
}
protected async Task SetPeriodo(Periodo newPeriodo)
{
if (!CurrPeriodo.Equals(newPeriodo))
{
CurrPeriodo = newPeriodo;
}
await Task.Delay(1);
}
protected async Task SetTotCount(int numRec)
{
totalCount = numRec;
await Task.Delay(1);
}
#endregion Protected Methods
#region Private Fields
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
/// <summary>
/// Tempo atteso processing
/// - da calcolare in base al num eventi e alla tab logProcessing...
/// </summary>
private int expTimeMsec = 3000;
#endregion Private Fields
#region Private Properties
private Periodo CurrPeriodo { get; set; } = new Periodo();
private string idxMaccSel { get; set; } = "";
private bool isProcessing { get; set; } = false;
protected double currVal = 0;
protected double nextVal = 0;
protected int MaxVal
{
get => fluxList.Count;
}
private int numItem { get; set; } = 1;
#endregion Private Properties
#region Private Methods
private async Task ReloadData()
{
await ReloadMacchine();
DateTime dtEnd = DateTime.Today.AddDays(1);
DateTime dtStart = dtEnd.AddMonths(-1);
CurrPeriodo = new Periodo(dtStart, dtEnd);
}
#endregion Private Methods
}
}