263 lines
7.8 KiB
C#
263 lines
7.8 KiB
C#
using GPW.CORE.Data.DbModels;
|
|
using GPW.CORE.Data.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.DataProtection;
|
|
using Microsoft.JSInterop;
|
|
using NLog.Targets.Wrappers;
|
|
|
|
namespace GPW.CORE.ADM.Components.Compo
|
|
{
|
|
public partial class FasiMan
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public bool ChkLicOk { get; set; } = true;
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> EC_update { get; set; }
|
|
|
|
[Parameter]
|
|
public bool EnableAddFasi { get; set; } = true;
|
|
|
|
[Parameter]
|
|
public List<AnagFasiExplModel>? ListRecords { get; set; } = null;
|
|
|
|
[Parameter]
|
|
public bool ShowSelect { get; set; } = true;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected MessageService AppMServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected GpwDataService GDataServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Aggiunta nuova fase/sottofase (se idxFaseAnc > 0)
|
|
/// </summary>
|
|
/// <param name="idxFaseAnc"></param>
|
|
/// <returns></returns>
|
|
protected async Task AddFase(int idxFaseAnc)
|
|
{
|
|
int idxProj = 0;
|
|
if (ListRecords != null && ListRecords.Count > 0)
|
|
{
|
|
idxProj = ListRecords.FirstOrDefault().IdxProgetto ?? 0;
|
|
}
|
|
if (idxProj > 0)
|
|
{
|
|
// creo nuovo record...
|
|
var newRec = new AnagFasiModel()
|
|
{
|
|
IdxProgetto = idxProj,
|
|
IdxFaseAncest = idxFaseAnc,
|
|
NomeFase = "__Nuova Fase",
|
|
DescrizioneFase = "Descrizione Fase"
|
|
};
|
|
// eseguo aggiunta nuovo record...
|
|
bool fatto = await GDataServ.AnagFasiUpsert(newRec);
|
|
if (fatto)
|
|
{
|
|
await EC_update.InvokeAsync(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected string CheckSel(AnagFasiExplModel curItem)
|
|
{
|
|
string answ = "";
|
|
if (RecordSel != null)
|
|
{
|
|
answ = curItem.IdxFase == RecordSel.IdxFase ? "table-info" : "";
|
|
}
|
|
// verifico stato attivo
|
|
answ += !curItem.Attivo ? " striked" : "";
|
|
return answ;
|
|
}
|
|
|
|
protected async Task DoDelete(AnagFasiExplModel? selItem)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler forzare il ricalcolo dei record?"))
|
|
return;
|
|
|
|
if (selItem != null)
|
|
{
|
|
bool fatto = await GDataServ.AnagFasiDelete(selItem.IdxFase);
|
|
if (fatto)
|
|
{
|
|
await EC_update.InvokeAsync(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected async Task DoEdit(AnagFasiExplModel? selItem)
|
|
{
|
|
RecordSel = null;
|
|
if (selItem != null)
|
|
{
|
|
RecordEdit = await GDataServ.AnagFasiByKey(selItem.IdxFase);
|
|
}
|
|
else
|
|
{
|
|
RecordEdit = null;
|
|
}
|
|
}
|
|
|
|
protected async Task DoMassTagUpd()
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler forzare il tag per tutte le fasi?"))
|
|
return;
|
|
|
|
int idxProj = 0;
|
|
if (ListRecords != null && ListRecords.Count > 0)
|
|
{
|
|
idxProj = ListRecords.FirstOrDefault().IdxProgetto ?? 0;
|
|
if (idxProj > 0)
|
|
{
|
|
bool fatto = await GDataServ.AnagFasiForceTag(idxProj, NewCodTagFase);
|
|
if (fatto)
|
|
{
|
|
await EC_update.InvokeAsync(true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void DoSelect(AnagFasiExplModel? selItem)
|
|
{
|
|
RecordSel = selItem;
|
|
RecordEdit = null;
|
|
}
|
|
|
|
protected async Task ForceReload()
|
|
{
|
|
RecordEdit = null;
|
|
RecordSel = null;
|
|
await EC_update.InvokeAsync(true);
|
|
await Task.Delay(1);
|
|
isLoading = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// init valori da config
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected async Task initConf()
|
|
{
|
|
// leggo conf standard controllo RegAtt
|
|
var sWarningRatioPerc = await GDataServ.ConfigGetKey("WarningRatioPerc");
|
|
if (sWarningRatioPerc != null)
|
|
{
|
|
double.TryParse(sWarningRatioPerc.valore, out warnRatio);
|
|
}
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await initConf();
|
|
await ReloadData();
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await Task.Delay(1);
|
|
totalCount = ListRecords.Count;
|
|
isLoading = false;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private string gridKey = "FasiMan";
|
|
private AnagFasiModel? RecordEdit = null;
|
|
private AnagFasiExplModel? RecordSel = null;
|
|
private double warnRatio = 50;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private bool isLoading { get; set; } = false;
|
|
private List<AnagTagFasiModel> ListTagFasi { get; set; } = new List<AnagTagFasiModel>();
|
|
private string NewCodTagFase { get; set; } = "ND";
|
|
private int totalCount { get; set; } = 0;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// restituisce una classe css a seconda dei valori passati:
|
|
/// green: bdgt > real
|
|
/// orange: real > bdgt*warning
|
|
/// red: real > bdgt
|
|
/// std: errore...
|
|
/// </summary>
|
|
/// <param name="real"></param>
|
|
/// <param name="bdgt"></param>
|
|
/// <returns></returns>
|
|
private string ColorByVal(object real, object bdgt)
|
|
{
|
|
string specClass = "default";
|
|
try
|
|
{
|
|
double valoreReal = Convert.ToDouble(real);
|
|
double valoreBdget = Convert.ToDouble(bdgt);
|
|
double valoreWarn = Convert.ToDouble(bdgt) * warnRatio / 100;
|
|
if (valoreReal >= valoreBdget)
|
|
{
|
|
specClass = "danger";
|
|
}
|
|
else if (valoreReal >= valoreWarn)
|
|
{
|
|
specClass = "warning";
|
|
}
|
|
else
|
|
{
|
|
specClass = "success";
|
|
}
|
|
}
|
|
catch
|
|
{ }
|
|
return $" bg-{specClass} bg-opacity-50 bg-gradient border border-{specClass} rounded";
|
|
}
|
|
|
|
private bool DelEnabled(decimal TotOre, int idxFase, int idxFaseAnc)
|
|
{
|
|
// se ha ore NON è eliminabile...
|
|
bool answ = TotOre == 0;
|
|
// se zero ore --> deve esere child oppure ancestor senza fasi...
|
|
if (answ)
|
|
{
|
|
// se ancestor
|
|
if (idxFaseAnc == 0)
|
|
{
|
|
// cerco fasi dato ancestor...
|
|
var listChild = GDataServ.AnagFasiByAncestor(idxFase);
|
|
// solo se NON ha fasi child
|
|
answ = listChild == null || listChild.Count == 0;
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
ListTagFasi = await GDataServ.AnagTagFasiAll();
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |