using Microsoft.AspNetCore.Components;
using MP.Data.DatabaseModels;
using MP.Data.Services;
using MP_TAB_SERV.Shared;
namespace MP_TAB_SERV.Components
{
public partial class CheckControls
{
#region Public Properties
[Parameter]
public MappaStatoExpl? RecMSE { get; set; } = null;
#endregion Public Properties
#region Protected Properties
[Inject]
protected NavigationManager NavMan { get; set; } = null!;
///
/// Determina se dato lo stato dell'impianto si debba mostrare btn fermata perché
/// - fermo > xx min (da web.config, es 20')
/// - impianto fermo (controllando idxStato: priorità > 1)
///
protected bool ShowInsFermata
{
get
{
bool answ = false;
int idxStato = 0;
double durata = 0;
int durMinWarning = SMServ.GetConfInt("durMinWarning");
if (RecMSE != null)
{
idxStato = RecMSE.IdxStato ?? 0;
durata = RecMSE.Durata ?? 0;
if (durata >= durMinWarning)
{
try
{
// in questo caso controllo idxStato... e recupero priorità se > 1 -->
// richiesta qualifica
answ = SMServ.GetStateRow(idxStato).Priorita > 1;
}
catch
{ }
}
}
return answ;
}
}
///
/// Verifica necessità visualizzare il check controlli
///
protected bool ShowReqControls
{
get
{
bool answ = false;
if (RecMSE != null)
{
// SE abilitata gestione controlli...
bool enableCtrl = SMServ.GetConfBool("enableControlli");
if (enableCtrl)
{
int intervalloControlli = SMServ.GetConfInt("intervalloControlli");
// cerco ultimo controllo fatto
DateTime lastControl = DateTime.Now.AddYears(-1);
try
{
var pUpd = Task.Run(async () =>
{
await Task.Delay(1);
var tabCtrls = await TabDServ.RegControlliLast(RecMSE.IdxMacchina);
if (tabCtrls != null && tabCtrls.Count > 0)
{
var thisRec = tabCtrls.FirstOrDefault();
if (thisRec != null)
{
lastControl = thisRec.DataOra;
if (Math.Abs(DateTime.Now.Subtract(lastControl).TotalMinutes) >= intervalloControlli)
{
answ = true;
}
}
}
});
pUpd.Wait();
}
catch
{ }
}
}
return answ;
}
}
[Inject]
protected SharedMemService SMServ { get; set; } = null!;
[Inject]
protected TabDataService TabDServ { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
protected void GoToControls()
{
NavMan.NavigateTo("controls");
}
protected void GoToFermate()
{
NavMan.NavigateTo("prod-stop");
}
#endregion Protected Methods
}
}