303 lines
8.5 KiB
C#
303 lines
8.5 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using MP.Core.DTO;
|
|
using MP.Core.Conf;
|
|
|
|
namespace MP.MON.Client.Components
|
|
{
|
|
public partial class DetailViewMSE : ComponentBase
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public MappaStatoExplDTO? CurrRecord { get; set; } = null;
|
|
|
|
[Parameter]
|
|
public List<TagData>? currTagConf { get; set; } = null;
|
|
|
|
[Parameter]
|
|
public Dictionary<string, string> currTagVal { get; set; } = new Dictionary<string, string>();
|
|
|
|
[Parameter]
|
|
public bool doAnimate { get; set; } = true;
|
|
|
|
[Parameter]
|
|
public bool doBlink { get; set; } = false;
|
|
|
|
[Parameter]
|
|
public int keepAliveMin { get; set; } = 5;
|
|
|
|
[Parameter]
|
|
public int maxChar4Scroll { get; set; } = 20;
|
|
|
|
[Parameter]
|
|
public string showArt { get; set; } = "";
|
|
|
|
[Parameter]
|
|
public bool scrollText { get; set; } = false;
|
|
|
|
[Parameter]
|
|
public string brightCss { get; set; } = "";
|
|
|
|
[Parameter]
|
|
public string titleMult { get; set; } = "";
|
|
|
|
[Parameter]
|
|
public bool showTC { get; set; } = false;
|
|
|
|
#if false
|
|
protected override void OnParametersSet()
|
|
{
|
|
base.OnParametersSet();
|
|
Console.WriteLine($"{DateTime.Now} | {CurrRecord.IdxMacchina} params received!");
|
|
}
|
|
#endif
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Fields
|
|
|
|
protected int kaFactor = 60 / 2;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
protected bool dataLoaded { get; set; } = true;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// restituisce il valore data la tagLocation
|
|
/// </summary>
|
|
/// <param name="tagLocation"></param>
|
|
/// <returns></returns>
|
|
protected string currVal(string tagLocation)
|
|
{
|
|
string answ = "";
|
|
if (currTagVal.ContainsKey(tagLocation))
|
|
{
|
|
answ = currTagVal[tagLocation];
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifica se ci sia un override per la riga indicata
|
|
/// </summary>
|
|
/// <param name="numRow"></param>
|
|
/// <returns></returns>
|
|
protected bool hasRow(int numRow)
|
|
{
|
|
bool answ = false;
|
|
if (currTagConf != null)
|
|
{
|
|
if (currTagConf.Count > 0)
|
|
{
|
|
var currVals = rowValues(numRow);
|
|
answ = currVals.Count > 0;
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce (se presenti) valori di override per la riga indicata
|
|
/// </summary>
|
|
/// <param name="numRow"></param>
|
|
/// <returns></returns>
|
|
protected List<TagData> rowValues(int numRow)
|
|
{
|
|
List<TagData>? rowVals = null;
|
|
if (currTagConf != null)
|
|
{
|
|
if (currTagConf.Count > 0)
|
|
{
|
|
//cerco solo la riga corrente...
|
|
rowVals = currTagConf.Where(x => x.RowNum == numRow).ToList();
|
|
}
|
|
}
|
|
if (rowVals == null)
|
|
{
|
|
rowVals = new List<TagData>();
|
|
}
|
|
return rowVals;
|
|
}
|
|
|
|
/// <summary>
|
|
/// CSS class x testo (se descr lunga scorre...)
|
|
/// </summary>
|
|
protected string textCss(string currText)
|
|
{
|
|
string answ = "text-truncate";
|
|
if (currText.Length > maxChar4Scroll)
|
|
{
|
|
answ = scrollText ? "scroll-left" : "text-reduced";
|
|
// calcolo delta... a-b-c con 5-10-oltre
|
|
int delta = currText.Length - maxChar4Scroll;
|
|
if (delta < 5)
|
|
{
|
|
answ += "-a";
|
|
}
|
|
else if (delta < 10)
|
|
{
|
|
answ += "-b";
|
|
}
|
|
else
|
|
{
|
|
answ += "-c";
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Methods
|
|
|
|
private string cssComStatus(string semaforo, DateTime? lastUpdateN)
|
|
{
|
|
DateTime lastUpdate = lastUpdateN.HasValue ? (DateTime)lastUpdateN : DateTime.Now.AddHours(-1);
|
|
string answ = "bg-dark opacity-75"; cssStatus(semaforo, false);
|
|
if (DateTime.Now.Subtract(lastUpdate).TotalSeconds > (keepAliveMin * kaFactor))
|
|
{
|
|
answ = $"bg-danger";
|
|
// blink se secondo pari...
|
|
#if false
|
|
DateTime adesso = DateTime.Now;
|
|
int resto = 0;
|
|
Math.DivRem(adesso.Second, 2, out resto);
|
|
if (resto == 0)
|
|
{
|
|
answ += " opacity-100";
|
|
}
|
|
#endif
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
private string cssStatus(string codSemaforo, bool animate)
|
|
{
|
|
string answ = "";
|
|
// se vuoto --> mostra nero!
|
|
if (string.IsNullOrEmpty(codSemaforo))
|
|
{
|
|
codSemaforo = "sNe";
|
|
}
|
|
string codColore = codSemaforo.Substring(1, 2);
|
|
switch (codSemaforo)
|
|
{
|
|
case "sVe":
|
|
answ = "bg-success";
|
|
animate = false;
|
|
break;
|
|
|
|
case "sGi":
|
|
answ = "bg-warning";
|
|
break;
|
|
|
|
case "sGr":
|
|
answ = "bg-dark opacity-50";
|
|
animate = false;
|
|
break;
|
|
|
|
case "sRo":
|
|
answ = "bg-danger";
|
|
break;
|
|
|
|
case "sBl":
|
|
answ = "bg-primary";
|
|
break;
|
|
|
|
case "sNe":
|
|
answ = "bg-dark";
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
if (animate)
|
|
{
|
|
if (doBlink)
|
|
{
|
|
answ += " opacity-50";
|
|
}
|
|
else
|
|
{
|
|
//answ += " bright100";
|
|
textBlinkBright = brightCss;
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Valore brightness solo x elementi testuali durante lampeggio
|
|
/// </summary>
|
|
protected string textBlinkBright = "bright100";
|
|
|
|
private decimal getDecimal(object? rawData)
|
|
{
|
|
decimal answ = 0;
|
|
if (rawData != null)
|
|
{
|
|
decimal.TryParse($"{rawData}", out answ);
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
private string getMinSec(decimal? currTimeMin)
|
|
{
|
|
string answ = "nd";
|
|
TimeSpan tSpan = new TimeSpan(0);
|
|
try
|
|
{
|
|
double cTimeMin = currTimeMin != null ? (double)currTimeMin : 0;
|
|
tSpan = TimeSpan.FromMinutes(cTimeMin);
|
|
if (tSpan.TotalHours < 1)
|
|
{
|
|
answ = $"{tSpan:mm}:{tSpan:ss}";
|
|
}
|
|
else
|
|
{
|
|
answ = $"{tSpan.TotalHours:00}:{tSpan:mm}:{tSpan:ss}";
|
|
}
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
|
|
private bool showComErr(DateTime? lastUpdateN)
|
|
{
|
|
DateTime lastUpdate = lastUpdateN.HasValue ? (DateTime)lastUpdateN : DateTime.Now.AddHours(-1);
|
|
bool answ = false;
|
|
if (DateTime.Now.Subtract(lastUpdate).TotalSeconds > (keepAliveMin * kaFactor))
|
|
{
|
|
answ = true;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
private string textC101(DateTime? lastUpdateN)
|
|
{
|
|
DateTime lastUpdate = lastUpdateN.HasValue ? (DateTime)lastUpdateN : DateTime.Now.AddHours(-1);
|
|
string answ = "text-light";
|
|
if (DateTime.Now.Subtract(lastUpdate).TotalSeconds > (keepAliveMin * kaFactor))
|
|
{
|
|
// blink se secondo pari...
|
|
DateTime adesso = DateTime.Now;
|
|
int resto = 0;
|
|
Math.DivRem(adesso.Second, 2, out resto);
|
|
if (resto == 1)
|
|
{
|
|
answ = $"text-danger";
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |