Files
mapo-core/MP-TAB-SERV/Components/MachineBlock.razor.cs
T
Samuele Locatelli d40c682673 Code reorg
2023-12-12 16:51:28 +01:00

279 lines
8.4 KiB
C#

using EgwCoreLib.Razor;
using global::Microsoft.AspNetCore.Components;
using Microsoft.EntityFrameworkCore.SqlServer.Query.Internal;
using Microsoft.JSInterop;
using MP.Data.DatabaseModels;
using MP.Data.Services;
using NLog;
namespace MP_TAB_SERV.Components
{
public partial class MachineBlock
{
#region Public Properties
public string currIpv4 { get; set; } = "";
[Parameter]
public bool FullMode { get; set; } = true;
[Parameter]
public int Height { get; set; } = 0;
[Parameter]
public string IdxMacchSub { get; set; } = "";
[Parameter]
public int keepAliveMin { get; set; } = 5;
[Parameter]
public MappaStatoExpl? RecMSE { get; set; } = null;
[Parameter]
public bool showCard { get; set; }
[Parameter]
public int Width { get; set; } = 0;
#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 = "??";
TimeSpan tempo = TimeSpan.FromMinutes(minuti ?? 0);
if (tempo.TotalMinutes < 60)
{
answ = $"{tempo.Minutes:00}:{tempo.Seconds:00}";
}
else if (tempo.TotalHours < 24)
{
answ = $"{tempo.Hours}h {tempo.Minutes}m";
}
else
{
answ = $"{tempo.Days}g {tempo.Hours}h";
}
return answ;
}
/// <summary>
/// url completo immagine
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public string ImgUrlMacc(string url)
{
if (string.IsNullOrEmpty(url.ToString()))
{
url = "Steamware.png";
}
string fullPath = Path.Combine(imgBasePath, url);
return fullPath;
}
#endregion Public Methods
#region Protected Fields
protected string baseCss = "sem";
protected int currMaxVal = 1000;
protected List<CircleGaugeMulti.CircSegm> innerCircleVals = new List<CircleGaugeMulti.CircSegm>();
protected int kaFactor = 60 / 2;
protected int maxVal = 1000;
protected List<CircleGaugeMulti.CircSegm> outerCircleVals = new List<CircleGaugeMulti.CircSegm>();
#endregion Protected Fields
#region Protected Properties
[Inject]
protected IConfiguration config { get; set; } = null!;
protected ProdAdvDispl.ProdCounter CurrCount
{
get
{
ProdAdvDispl.ProdCounter answ = new ProdAdvDispl.ProdCounter();
if (RecMSE != null)
{
answ = new ProdAdvDispl.ProdCounter()
{
numPzConf = (int)RecMSE.PezziConf,
numPzOrd = (int)RecMSE.NumPezzi,
numPzProd = (int)RecMSE.PezziProd
};
}
return answ;
}
}
/// <summary>
/// Dati produzioen rilevati
/// </summary>
protected StatoProdModel? datiProdAct { get; set; } = null;
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
[Inject]
protected MessageService MServ { get; set; } = null!;
[Inject]
protected NavigationManager NavMan { get; set; } = null!;
[Inject]
protected StatusData SDService { get; set; } = null!;
[Inject]
protected TabDataService TabDServ { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
protected override async Task OnAfterRenderAsync(bool firstRender)
{//await Task.Delay(500);
if (firstRender)
{
//await getWDim();
StateHasChanged();
}
isLoading = RecMSE == null;
await Task.Delay(1);
//return base.OnAfterRenderAsync(firstRender);
}
protected override async Task OnInitializedAsync()
{
isLoading = true;
// se configurata uso cartella virtuale... altrimenti cartella processo
var sImgBasePath = config.GetValue<string>("OptConf:ImgBasePath");
if (!string.IsNullOrEmpty(sImgBasePath))
{
imgBasePath = sImgBasePath;
}
else
{
imgBasePath = $"{Environment.CurrentDirectory}/images/";
}
await Task.Delay(1);
}
protected override async Task OnParametersSetAsync()
{
DateTime adesso = DateTime.Now;
isLoading = RecMSE == null;
// controllo SE avessi idxMacchSub --> rileggo!
if (RecMSE != null)
{
if (SDService.MachNumPzGet(RecMSE.IdxMacchina) != RecMSE.NumPezzi)
{
datiProdAct = await TabDServ.StatoProdMacchina(RecMSE.IdxMacchina, adesso);
SDService.MachProdStSet(RecMSE.IdxMacchina, datiProdAct);
SDService.MachNumPzSet(RecMSE.IdxMacchina, RecMSE.NumPezzi);
}
else
{
datiProdAct = SDService.MachProdStGet(RecMSE.IdxMacchina);
}
}
if (!string.IsNullOrEmpty(IdxMacchSub) && RecMSE != null)
{
RecMSE = TabDServ.MseGetSub(RecMSE.IdxMacchina, IdxMacchSub, true);
}
setGaugeVals();
}
protected void setGaugeVals()
{
if (RecMSE != null)
{
innerCircleVals.Clear();
outerCircleVals.Clear();
currMaxVal = int.Parse(RecMSE.NumPezzi.ToString()!);
innerCircleVals.Add(new CircleGaugeMulti.CircSegm() { Color = "#FFC107", Value = RecMSE.PezziProd });
if (RecMSE.PezziConf > 0)
{
innerCircleVals.Add(new CircleGaugeMulti.CircSegm() { Color = "#198754", Value = RecMSE.PezziConf });
}
if (RecMSE.extraVal > 0)
{
outerCircleVals.Add(new CircleGaugeMulti.CircSegm() { Color = "#1367FD", Value = RecMSE.extraVal });
}
//Log.Trace($"MBlock | {RecMSE.IdxMacchina} | 03");
}
else
{
Log.Info("MBlock NO DATA");
}
}
protected async Task ShowDetail()
{
// salvo idxMacch
await MServ.IdxMaccSet(RecMSE!.IdxMacchina);
await MServ.LastOpenedPageSet("machine-detail");
// navigo!
NavMan.NavigateTo($"machine-detail");
}
#endregion Protected Methods
#region Private Fields
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
private string imgBasePath = "";
private bool isLoading = false;
#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
}
}