197 lines
5.4 KiB
C#
197 lines
5.4 KiB
C#
using global::Microsoft.AspNetCore.Components;
|
|
using MP.Data.DatabaseModels;
|
|
using MP.Data.Services;
|
|
|
|
namespace MP_TAB_SERV.Components
|
|
{
|
|
public partial class MachineBlock
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public bool FullMode { get; set; } = true;
|
|
|
|
[Parameter]
|
|
public int keepAliveMin { get; set; } = 5;
|
|
|
|
[Parameter]
|
|
public MappaStatoExpl? RecMSE { get; set; } = null;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// formatta la durata in minuti in un modo "human readable" gg/ore/min
|
|
/// </summary>
|
|
/// <param name="minuti">minuti</param>
|
|
/// <returns></returns>
|
|
public static string formatDurata(double? minuti)
|
|
{
|
|
string answ = "??";
|
|
if (minuti != null)
|
|
{
|
|
DateTime tempo = new DateTime();
|
|
tempo = tempo.AddMinutes((double)minuti);
|
|
if (minuti < 60)
|
|
{
|
|
answ = $"{tempo.Minute:00}:{tempo.Second:00}";
|
|
}
|
|
else if (minuti < 1440)
|
|
{
|
|
answ = $"{tempo.Hour}h {tempo.Minute}m";
|
|
}
|
|
else
|
|
{
|
|
answ = $"{tempo.DayOfYear}g {tempo.Hour}h";
|
|
}
|
|
}
|
|
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// url completo immagine
|
|
/// </summary>
|
|
/// <param name="url"></param>
|
|
/// <returns></returns>
|
|
public string ImgUrlMacc(string url)
|
|
{
|
|
string answ = "";
|
|
if (string.IsNullOrEmpty(url.ToString()))
|
|
{
|
|
url = "Steamware.png";
|
|
}
|
|
|
|
// verifico esistenza macchina SMALL...
|
|
answ = $"images/macchine/small/{url}";
|
|
string fullPath = Path.Combine(imgBasePath, "wwwroot", answ);
|
|
if (!File.Exists(fullPath))
|
|
{
|
|
// se non ci fosse cerco immagine fullsize
|
|
answ = $"images/macchine/{url}";
|
|
fullPath = Path.Combine(imgBasePath, "wwwroot", answ);
|
|
}
|
|
|
|
// altrimenti metto default Steamware
|
|
if (!File.Exists(fullPath))
|
|
{
|
|
answ = "images/macchine/Steamware.png";
|
|
}
|
|
|
|
return answ;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Fields
|
|
|
|
protected string baseCss = "sem";
|
|
|
|
protected int kaFactor = 60 / 2;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
protected ProdAdvDispl.ProdCounter CurrCount
|
|
{
|
|
get
|
|
{
|
|
ProdAdvDispl.ProdCounter answ = new ProdAdvDispl.ProdCounter()
|
|
{
|
|
numPzConf = (int)RecMSE.PezziConf,
|
|
numPzOrd = (int)RecMSE.NumPezzi,
|
|
numPzProd = (int)RecMSE.PezziProd
|
|
};
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
[Inject]
|
|
protected MessageService MServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected NavigationManager NavMan { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
isLoading = true;
|
|
// se configurata uso cartella virtuale... altrimenti cartella processo
|
|
imgBasePath = Environment.CurrentDirectory; // @"C:\Steamware\macchine";
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
isLoading = RecMSE == null;
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
isLoading = RecMSE == null;
|
|
await Task.Delay(1);
|
|
//return base.OnAfterRenderAsync(firstRender);
|
|
}
|
|
|
|
|
|
protected async Task ShowDetail()
|
|
{
|
|
// salvo idxMacch
|
|
await MServ.IdxMaccSet(RecMSE!.IdxMacchina);
|
|
// navigo!
|
|
NavMan.NavigateTo($"machine-detail");
|
|
}
|
|
|
|
private bool isLoading = false;
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private string imgBasePath = "";
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Methods
|
|
|
|
private string cssComStatus(string semaforo, DateTime? lastUpdateN)
|
|
{
|
|
DateTime lastUpdate = lastUpdateN.HasValue ? (DateTime)lastUpdateN : DateTime.Now.AddHours(-1);
|
|
string answ = cssStatus(semaforo);
|
|
if (DateTime.Now.Subtract(lastUpdate).TotalSeconds > (keepAliveMin * kaFactor))
|
|
{
|
|
answ = $"{baseCss}Ro";
|
|
// blink se secondo pari...
|
|
DateTime adesso = DateTime.Now;
|
|
int resto = 0;
|
|
Math.DivRem(adesso.Second, 2, out resto);
|
|
if (resto == 0)
|
|
{
|
|
answ += "_b";
|
|
}
|
|
}
|
|
|
|
return answ;
|
|
}
|
|
|
|
private string cssStatus(string codSemaforo)
|
|
{
|
|
// se vuoto --> mostra nero!
|
|
if (string.IsNullOrEmpty(codSemaforo))
|
|
{
|
|
codSemaforo = "sNe";
|
|
}
|
|
|
|
string codColore = codSemaforo.Substring(1, 2);
|
|
string answ = $"{baseCss}{codColore}";
|
|
return answ;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |