Files
mapo-core/MP-TAB3/Components/TechSheet_ST_ObjView.razor.cs
2025-03-14 18:53:38 +01:00

174 lines
4.9 KiB
C#

using global::Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using MP.Core.Objects;
using MP.Data.DbModels;
using MP.Data.Services;
namespace MP_TAB3.Components
{
public partial class TechSheet_ST_ObjView
{
#region Public Properties
[Parameter]
public ST_ActRow CurrRec { get; set; } = null!;
/// <summary>
/// Url immagine SE richiesta
/// </summary>
public string imageUrl
{
get
{
string imgPath = "";
string fullPath = "";
//check type...
if (CurrRec.CodTipo == "IMG")
{
imgPath = CurrRec.Value;
if (!Path.IsPathRooted(imgPath))
{
// aggiungo base path
imgPath = $"images/ST_img/{imgPath}";
fullPath = Path.Combine(imgBasePath, "wwwroot", imgPath);
}
// verifico esistenza file...
if (!File.Exists(fullPath))
{
// metto segnaposto empty
imgPath = "images/ST_img/Steamware.png";
}
}
return imgPath;
}
}
#endregion Public Properties
#region Protected Properties
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
[Inject]
protected MessageService MServ { get; set; } = null!;
[Inject]
protected NavigationManager NavMan { get; set; } = null!;
[Inject]
protected SharedMemService SMServ { get; set; } = null!;
[Inject]
protected TabDataService TabDServ { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
protected async Task ForceParam()
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", Traduci("ConfirmForceParamST")))
return;
// registro abilitazione forzatura parametro per un periodo limitato
StCheckOverride newDeroga = new StCheckOverride()
{
CanForce = enableForceParamSchedaTecnica,
Num = CurrRec.Num,
Oggetto = CurrRec.Oggetto,
CodTipo = CurrRec.CodTipo,
CodGruppo = CurrRec.CodGruppo,
IdxST = CurrRec.IdxST,
Utente = CognomeNome
};
// salvo
TabDServ.ST_DerogaSet(newDeroga);
// redirect
NavMan.NavigateTo(NavMan.Uri, true);
}
protected override void OnInitialized()
{
imgBasePath = Environment.CurrentDirectory;
//baseLang = SMServ.GetConf("baseLang");
enableForceParamSchedaTecnica = SMServ.GetConfBool("enableForceParamSchedaTecnica");
}
protected override void OnParametersSet()
{
if (CurrRec != null)
{
hasDeroga = false;
var currDeroga = TabDServ.ST_DerogaGet(CognomeNome, CurrRec.IdxST);
if (currDeroga != null)
{
hasDeroga = (currDeroga.IdxST == CurrRec.IdxST && currDeroga.CanForce && currDeroga.Num == CurrRec.Num && currDeroga.CodGruppo == CurrRec.CodGruppo && currDeroga.CodTipo == CurrRec.CodTipo && currDeroga.Oggetto == CurrRec.Oggetto);
}
}
}
protected string Traduci(string lemma)
{
return SMServ.Traduci($"{baseLang}_{lemma}".ToUpper());
}
#endregion Protected Methods
#region Private Fields
private string _baseLang { get; set; } = "IT";
private string baseLang
{
get => _baseLang;
set
{
MServ.UserPrefGet("Lang");
}
}
private bool enableForceParamSchedaTecnica = false;
private bool hasDeroga = false;
private string imgBasePath = "";
#endregion Private Fields
#region Private Properties
private string dataCss
{
get
{
string answ = "";
if (CurrRec.Required)
{
if (CurrRec.Value != CurrRec.ExtCode)
{
answ = " text-danger";
}
else
{
answ = " text-success";
}
}
return answ;
}
}
private string derogaCss
{
get
{
string answ = enableForceParamSchedaTecnica && hasDeroga ? " bg-warning" : "";
return answ;
}
}
private string CognomeNome
{
get => MServ.CognomeNome;
}
#endregion Private Properties
}
}