499 lines
16 KiB
C#
499 lines
16 KiB
C#
using EgwCoreLib.Razor;
|
|
using GPW.CORE.Data.DbModels;
|
|
using GPW.CORE.Data.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.DataProtection;
|
|
using Microsoft.JSInterop;
|
|
using NLog;
|
|
using static EgwCoreLib.Razor.Toggler;
|
|
|
|
namespace GPW.CORE.ADM.Components.Compo
|
|
{
|
|
public partial class ProgettiMan : IDisposable
|
|
{
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
AppMServ.EA_SearchUpdated -= AppMServ_EA_SearchUpdated;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected MessageService AppMServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected AppAuthService AuthServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected GpwDataService GDataServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
protected List<AnagClientiModel> ListClienti { get; set; } = new List<AnagClientiModel>();
|
|
|
|
protected List<AnagGruppiModel> ListGruppi { get; set; } = new List<AnagGruppiModel>();
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected string CheckSel(CalcOreProgettiModel curItem)
|
|
{
|
|
string answ = "";
|
|
if (RecordEdit != null)
|
|
{
|
|
answ = curItem.IdxProgetto == RecordEdit.IdxProgetto ? "table-info" : "";
|
|
}
|
|
// verifico stato attivo
|
|
answ += !(curItem.Attivo ?? false) ? " striked" : "";
|
|
return answ;
|
|
}
|
|
|
|
protected async Task CreateNew()
|
|
{
|
|
FullEdit = true;
|
|
RecordSel = null;
|
|
RecordEdit = new AnagProgettiModel()
|
|
{
|
|
NomeProj = "__Nuovo Progetto",
|
|
DescrProj = "Descrizione nuovo progetto",
|
|
Gruppo = "",
|
|
IdxCliente = 0,
|
|
Attivo = true
|
|
};
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
protected async void DoDelete(CalcOreProgettiModel selItem)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler eliminare il record?"))
|
|
return;
|
|
|
|
isLoading = true;
|
|
await Task.Delay(1);
|
|
await InvokeAsync(StateHasChanged);
|
|
RecordSel = null;
|
|
RecordEdit = GDataServ.AnagProjByKey(selItem.IdxProgetto);
|
|
bool fatto = await GDataServ.AnagProjDelete(RecordEdit);
|
|
if (fatto)
|
|
{
|
|
await Task.Delay(1);
|
|
await GDataServ.AnagProjForceUpdate();
|
|
}
|
|
RecordEdit = null;
|
|
await ReloadData();
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
protected void DoEdit(CalcOreProgettiModel? selItem)
|
|
{
|
|
FullEdit = true;
|
|
ShowFasi = false;
|
|
RecordSel = null;
|
|
RecordEdit = GDataServ.AnagProjByKey(selItem.IdxProgetto);
|
|
}
|
|
|
|
protected async Task DoRecalc()
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler forzare il ricalcolo dei record?"))
|
|
return;
|
|
|
|
isLoading = true;
|
|
await Task.Delay(1);
|
|
await InvokeAsync(StateHasChanged);
|
|
await GDataServ.AnagProjForceUpdate();
|
|
await Task.Delay(1);
|
|
await ReloadData();
|
|
}
|
|
|
|
protected void DoSelect(CalcOreProgettiModel? selItem)
|
|
{
|
|
FullEdit = false;
|
|
ShowFasi = false;
|
|
RecordSel = selItem;
|
|
RecordEdit = null;
|
|
}
|
|
|
|
protected async Task DoShowFasi(CalcOreProgettiModel? selItem)
|
|
{
|
|
FullEdit = false;
|
|
// carico le fasi e le asso al controllo!
|
|
ListFasiSel = await GDataServ.AnagFasiExplByProj(selItem.IdxProgetto);
|
|
ShowFasi = true;
|
|
RecordSel = selItem;
|
|
RecordEdit = null;
|
|
}
|
|
|
|
protected async Task ForceReload()
|
|
{
|
|
await salvaFiltToggle();
|
|
await salvaFiltGrpCli();
|
|
FullEdit = false;
|
|
ShowFasi = false;
|
|
RecordEdit = null;
|
|
RecordSel = null;
|
|
currPage = 1;
|
|
await ReloadData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// init valori da config
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected async Task initConf()
|
|
{
|
|
// leggo conf standard controllo RegAtt
|
|
var sWarningRatioPerc = await GDataServ.ConfigGetKeyAsync("WarningRatioPerc");
|
|
if (sWarningRatioPerc != null)
|
|
{
|
|
double.TryParse(sWarningRatioPerc.valore, out warnRatio);
|
|
}
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await initConf();
|
|
CurrSearch = "";
|
|
AppMServ.SearchVal = "";
|
|
AppMServ.EA_SearchUpdated += AppMServ_EA_SearchUpdated;
|
|
// recupero preferenze utente...
|
|
await InitUserPref();
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await ReloadData();
|
|
}
|
|
|
|
protected async Task ReloadFasi()
|
|
{
|
|
// rileggo fasi associate...
|
|
ListFasiSel = new List<AnagFasiExplModel>();
|
|
await Task.Delay(1);
|
|
//await InvokeAsync(StateHasChanged);
|
|
// carico le fasi e le asso al controllo!
|
|
ListFasiSel = await GDataServ.AnagFasiExplByProj(RecordSel.IdxProgetto);
|
|
await Task.Delay(1);
|
|
//await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
protected async Task SetNumRec(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
currPage = 1;
|
|
await AppMServ.NumRowGridSet(gridKey, newNum);
|
|
await InvokeAsync(ReloadData);
|
|
}
|
|
|
|
protected async Task SetPage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
await InvokeAsync(ReloadData);
|
|
}
|
|
|
|
protected async Task SortRequested(Sorter.SortCallBack e)
|
|
{
|
|
sortField = e.ParamName;
|
|
sortAsc = e.IsAscending;
|
|
await ReloadData();
|
|
}
|
|
|
|
protected string UserLang
|
|
{
|
|
get => AppMServ.UserLang;
|
|
}
|
|
|
|
protected string Traduci(string lemma)
|
|
{
|
|
return AuthServ.Traduci(lemma, UserLang);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
private bool FullEdit = false;
|
|
|
|
private string gridKey = "ProgettiMan";
|
|
|
|
private AnagProgettiModel? RecordEdit = null;
|
|
|
|
private CalcOreProgettiModel? RecordSel = null;
|
|
|
|
private bool ShowFasi = false;
|
|
|
|
private bool sortAsc = true;
|
|
|
|
private string sortField = "";
|
|
|
|
private double warnRatio = 50;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private int currPage { get; set; } = 1;
|
|
|
|
private string CurrSearch { get; set; } = "";
|
|
|
|
private string Gruppo { get; set; } = "";
|
|
|
|
private int IdxCliente { get; set; } = 0;
|
|
|
|
private bool isLoading { get; set; } = false;
|
|
|
|
private List<AnagFasiExplModel>? ListFasiSel { get; set; } = null;
|
|
|
|
private List<CalcOreProgettiModel>? ListRecords { get; set; } = null;
|
|
|
|
private string modalSize
|
|
{
|
|
get => FullEdit ? "modal-xl" : "";
|
|
}
|
|
|
|
private int numRecord { get; set; } = 10;
|
|
|
|
private List<CalcOreProgettiModel>? SearchRecords { get; set; } = null;
|
|
|
|
private string SelCliText
|
|
{
|
|
get => ShowCli ? "Elimina Filt." : "Filt.Clienti";
|
|
}
|
|
|
|
private string SelGrpText
|
|
{
|
|
get => ShowGruppo ? "Elimina Filt." : "Filt.Gruppo";
|
|
}
|
|
|
|
private bool ShowCli { get; set; } = false;
|
|
|
|
private bool ShowGruppo { get; set; } = false;
|
|
|
|
private bool ShowPrjArc { get; set; } = false;
|
|
|
|
private bool ShowPrjStr { get; set; } = false;
|
|
|
|
private bool ShowPrjZH { get; set; } = true;
|
|
|
|
private int totalCount { get; set; } = 0;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async void AppMServ_EA_SearchUpdated()
|
|
{
|
|
CurrSearch = AppMServ.SearchVal;
|
|
await ReloadData();
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
/// <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 async Task FixFilt()
|
|
{
|
|
if (!ShowGruppo)
|
|
{
|
|
Gruppo = "";
|
|
}
|
|
if (!ShowCli)
|
|
{
|
|
IdxCliente = 0;
|
|
}
|
|
currPage = 1;
|
|
await salvaFiltGrpCli();
|
|
await ReloadData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Init preferenze utente
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private async Task InitUserPref()
|
|
{
|
|
try
|
|
{
|
|
numRecord = await AppMServ.NumRowGridGet(gridKey);
|
|
ShowPrjArc = await AppMServ.UserPrefGet<bool>("ShowPrjArc");
|
|
ShowPrjStr = await AppMServ.UserPrefGet<bool>("ShowPrjStr");
|
|
ShowPrjZH = await AppMServ.UserPrefGet<bool>("ShowPrjZH");
|
|
ShowGruppo = await AppMServ.UserPrefGet<bool>("ShowGruppo");
|
|
ShowCli = await AppMServ.UserPrefGet<bool>("ShowCli");
|
|
Gruppo = await AppMServ.UserPrefGet<string>("Gruppo") ?? "";
|
|
IdxCliente = await AppMServ.UserPrefGet<int>("IdxCliente");
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in InitUserPref{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
isLoading = true;
|
|
ListRecords = null;
|
|
ListGruppi = await GDataServ.AnagGruppiAll();
|
|
ListClienti = await GDataServ.AnagClientiAllAsync();
|
|
try
|
|
{
|
|
SearchRecords = await GDataServ.AnagProjCalcFilt(Gruppo, IdxCliente, ShowPrjArc, ShowPrjZH, ShowPrjStr);
|
|
// verifico filtro per ricerca
|
|
if (!string.IsNullOrEmpty(CurrSearch))
|
|
{
|
|
SearchRecords = SearchRecords
|
|
.Where(x => x.NomeProj.Contains(CurrSearch, StringComparison.InvariantCultureIgnoreCase)
|
|
|| x.DescrProj.Contains(CurrSearch, StringComparison.InvariantCultureIgnoreCase))
|
|
.ToList();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error($"Eccezione in recupero dati{Environment.NewLine}{ex}");
|
|
}
|
|
totalCount = SearchRecords.Count;
|
|
SortTable();
|
|
isLoading = false;
|
|
}
|
|
|
|
private async Task salvaFiltGrpCli()
|
|
{
|
|
// salvo
|
|
await AppMServ.UserPrefSet("ShowGruppo", $"{ShowGruppo}");
|
|
await AppMServ.UserPrefSet("ShowCli", $"{ShowCli}");
|
|
await AppMServ.UserPrefSet("Gruppo", $"{Gruppo}");
|
|
await AppMServ.UserPrefSet("IdxCliente", $"{IdxCliente}");
|
|
}
|
|
|
|
private async Task salvaFiltToggle()
|
|
{
|
|
// salvo le preferenze...
|
|
await AppMServ.UserPrefSet("ShowPrjArc", $"{ShowPrjArc}");
|
|
await AppMServ.UserPrefSet("ShowPrjStr", $"{ShowPrjStr}");
|
|
await AppMServ.UserPrefSet("ShowPrjZH", $"{ShowPrjZH}");
|
|
}
|
|
|
|
private void SortTable()
|
|
{
|
|
if (SearchRecords != null)
|
|
{
|
|
// se ho ordinamento riordino...
|
|
if (!string.IsNullOrEmpty(sortField))
|
|
{
|
|
switch (sortField)
|
|
{
|
|
case "Gruppo":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.Gruppo).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.Gruppo).ToList();
|
|
}
|
|
break;
|
|
|
|
case "RagSoc":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.RagSociale).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.RagSociale).ToList();
|
|
}
|
|
break;
|
|
|
|
case "NomeProj":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.NomeProj).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.NomeProj).ToList();
|
|
}
|
|
break;
|
|
|
|
case "OreTot":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.totOre).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.totOre).ToList();
|
|
}
|
|
break;
|
|
|
|
case "Money":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.budgetMoney).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.budgetMoney).ToList();
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// filtro x display
|
|
ListRecords = SearchRecords
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
}
|
|
else
|
|
{
|
|
ListRecords = new List<CalcOreProgettiModel>();
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |