568 lines
19 KiB
C#
568 lines
19 KiB
C#
using EgwCoreLib.Razor;
|
|
using GPW.CORE.Data.DbModels;
|
|
using GPW.CORE.Data.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
using NLog;
|
|
using System.Buffers;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace GPW.CORE.ADM.Components.Compo
|
|
{
|
|
public partial class DipendentiMan : IDisposable
|
|
{
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
AppMServ.EA_SearchUpdated -= AppMServ_EA_SearchUpdated;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Fields
|
|
|
|
protected int NumLicActLocal = 0;
|
|
|
|
protected int NumLicActOnline = 0;
|
|
|
|
protected int NumLicDispLocal = 0;
|
|
|
|
protected int NumLicDispOnline = 0;
|
|
|
|
protected int NumTicket = 0;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected MessageService AppMServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected GpwDataService GDataServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected LicenseService LicServ { get; set; } = null!;
|
|
|
|
protected List<DipendentiModel> ListDipendentiAttiviOrd
|
|
{
|
|
get => ListDipendenti != null ? ListDipendenti.Where(x => x.Attivo ?? false).OrderBy(x => x.Cognome).ThenBy(x => x.Nome).ToList() : new List<DipendentiModel>();
|
|
}
|
|
|
|
protected List<DipendentiModel> ListDipendentiOrd
|
|
{
|
|
get => ListDipendenti != null ? ListDipendenti.OrderBy(x => x.Cognome).ThenBy(x => x.Nome).ToList() : new List<DipendentiModel>();
|
|
}
|
|
|
|
protected string modalSize
|
|
{
|
|
get => CtrlMode == DipendentiEdit.EditMode.FullEdit ? "modal-xl" : "modal-lg";
|
|
}
|
|
|
|
protected bool NeedAllocation
|
|
{
|
|
get => NumLicActOnline == NumLicActLocal && NumLicActOnline != NumLicActLocal;
|
|
}
|
|
|
|
protected string TextQrLinkCore
|
|
{
|
|
get => ShowLinkCore ? "GPW Core" : "GPW Legacy";
|
|
}
|
|
|
|
protected string TextQrLinkInt
|
|
{
|
|
get => ShowLinkInt ? "Link Interno" : "Link Esterno";
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected string CheckSel(DipendentiModel curItem)
|
|
{
|
|
string answ = curItem.Attivo ?? false ? "" : "text-secondary striked";
|
|
if (RecordEdit != null)
|
|
{
|
|
answ = curItem.Cf == RecordEdit.Cf ? "table-info" : "";
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected async Task CreateNew()
|
|
{
|
|
}
|
|
|
|
protected void DoEdit(DipendentiModel? selItem)
|
|
{
|
|
CtrlMode = DipendentiEdit.EditMode.FullEdit;
|
|
RecordEdit = selItem;
|
|
}
|
|
protected void RequestReset(DipendentiModel? selItem)
|
|
{
|
|
CtrlMode = DipendentiEdit.EditMode.ResetRequest;
|
|
RecordEdit = selItem;
|
|
}
|
|
|
|
protected async Task DoFixMissing()
|
|
{
|
|
// procedo SOLO SE il numero online/offline è differente in primis...
|
|
if (NeedAllocation)
|
|
{
|
|
// ciclo tutti gli utenti attivi
|
|
// verifico SE sia disponibile licenza...
|
|
var activationsList = LicServ.ActivList;
|
|
Dictionary<string, string> CodList = new Dictionary<string, string>();
|
|
|
|
// ciclo x ogni dip attivo...
|
|
foreach (var item in ListDipendentiAttiviOrd)
|
|
{
|
|
// calcolo codImpiego
|
|
string currCodImp = LicServ.HashDip(item);
|
|
// cerco se abbia attivazione
|
|
var currActiv = activationsList.Where(x => x.CodImpiego == currCodImp).FirstOrDefault();
|
|
if (currActiv == null || currActiv.CodImpiego != currCodImp)
|
|
{
|
|
CodList.Add(currCodImp, item.AuthKey);
|
|
}
|
|
}
|
|
// provo attivazione in blocco
|
|
await LicServ.TryActivationMult(CodList);
|
|
// cmq faccio refresh
|
|
await FullRefresh();
|
|
// ricalcolo licenze
|
|
await RefreshLicData(true);
|
|
}
|
|
await ReloadData();
|
|
}
|
|
|
|
protected async Task DoRefresh()
|
|
{
|
|
isLoading = true;
|
|
await LicServ.resetActivList();
|
|
await FullRefresh();
|
|
await ReloadData();
|
|
// ricalcolo licenze
|
|
await RefreshLicData(false);
|
|
isLoading = false;
|
|
}
|
|
|
|
protected void DoSelect(DipendentiModel currRec)
|
|
{
|
|
CtrlMode = DipendentiEdit.EditMode.KeyRegen;
|
|
RecordEdit = currRec;
|
|
}
|
|
|
|
protected async Task ForceReload()
|
|
{
|
|
currPage = 1;
|
|
CtrlMode = DipendentiEdit.EditMode.None;
|
|
RecordEdit = null;
|
|
await ReloadData();
|
|
// ricalcolo licenze
|
|
await RefreshLicData(false);
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await ReloadConfData();
|
|
await ReloadData();
|
|
await RefreshLicData(true);
|
|
AppMServ.EA_SearchUpdated += AppMServ_EA_SearchUpdated;
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
private int currPage = 1;
|
|
|
|
private DipendentiEdit.EditMode CtrlMode = DipendentiEdit.EditMode.None;
|
|
|
|
private string gridKey = "DipendentiMan";
|
|
|
|
private bool isLoading = false;
|
|
|
|
private int numRecord = 10;
|
|
|
|
private DipendentiModel? RecordEdit = null;
|
|
|
|
private string searchVal = "";
|
|
|
|
private bool ShowInatt = false;
|
|
|
|
private bool ShowLinkCore = true;
|
|
|
|
private bool ShowLinkInt = true;
|
|
|
|
private bool ShowQrCode = false;
|
|
|
|
private bool sortAsc = true;
|
|
|
|
private string sortField = "";
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private List<DipendentiModel>? ListDipendenti { get; set; } = null;
|
|
|
|
private List<AnagOrariModel> ListOrari { get; set; } = null!;
|
|
|
|
private List<DipendentiModel>? ListRecords { get; set; } = null;
|
|
|
|
private List<DipendentiModel>? SearchRecords { get; set; } = null;
|
|
|
|
private int totalCount { get; set; } = 0;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private void AppMServ_EA_SearchUpdated()
|
|
{
|
|
ReloadData().ConfigureAwait(false);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Verifica licenza (se sia libera x modifica o prima associazione)
|
|
/// </summary>
|
|
/// <param name="IdxDip"></param>
|
|
/// <returns></returns>
|
|
public bool CheckFreeEdit(int IdxDip)
|
|
{
|
|
bool answ = false;
|
|
if (IdxDip > 0)
|
|
{
|
|
// cerco!
|
|
var currUser = ListDipendentiAttiviOrd.Where(x => x.IdxDipendente == IdxDip).FirstOrDefault();
|
|
if (currUser != null)
|
|
{
|
|
// verifico SE sia disponibile licenza...
|
|
var activationsList = LicServ.ActivList;
|
|
var currHash = LicServ.HashDip(currUser);
|
|
var currAct = activationsList.Where(x => x.CodImpiego == currHash).FirstOrDefault();
|
|
// se NON c'è licenza è ok (editabile)
|
|
answ = (currAct == null);
|
|
// ora verifico: se NON ha licenza OK, altrimenti deve essere scaduta...
|
|
if (!answ)
|
|
{
|
|
answ = currAct.VetoUnlock <= DateTime.Today;
|
|
}
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// Rilascia licenza e rilegge conf
|
|
/// </summary>
|
|
/// <param name="CurrRecord"></param>
|
|
/// <returns></returns>
|
|
private async Task ReleaseLicense(DipendentiModel CurrRecord)
|
|
{
|
|
// verifica SE ci sono licenze disponibili
|
|
if (NumLicDispOnline > NumLicActOnline)
|
|
{
|
|
// chiamo rimozione licenza
|
|
var CodImpiego = LicServ.HashDip(CurrRecord);
|
|
bool fatto = await LicServ.TryRemoveActivation(CodImpiego, CurrRecord.AuthKey);
|
|
if (fatto)
|
|
{
|
|
// disattiva utente
|
|
GDataServ.DipUpdateActive(CurrRecord.IdxDipendente, false);
|
|
}
|
|
LicServ.ResetLicenseData();
|
|
}
|
|
// disattivo record mostrato...
|
|
RecordEdit = null;
|
|
// ricarico
|
|
await ReloadData();
|
|
// ricalcolo licenze
|
|
await RefreshLicData(true);
|
|
}
|
|
|
|
private async Task DoActivate(DipendentiModel CurrRecord)
|
|
{
|
|
// verifica SE ci sono licenze disponibili
|
|
if (NumLicDispOnline > NumLicActOnline)
|
|
{
|
|
// attiva utente
|
|
GDataServ.DipUpdateActive(CurrRecord.IdxDipendente, true);
|
|
|
|
string CodImpiego = LicServ.HashDip(CurrRecord);
|
|
|
|
// effettua riassegnazione
|
|
bool fatto = LicServ.TryActivation(CodImpiego, CurrRecord.AuthKey);
|
|
}
|
|
await ReloadData();
|
|
// ricalcolo licenze
|
|
await RefreshLicData(true);
|
|
}
|
|
|
|
private async Task FullRefresh()
|
|
{
|
|
LicServ.ResetLicenseData();
|
|
// eseguo call di recupero da online
|
|
bool refreshApp = await LicServ.RefreshApplic();
|
|
bool refreshAct = await LicServ.RefreshLicense();
|
|
bool refreshPay = LicServ.RefreshPayload();
|
|
// chiama update di TUTTE le authKey verso il server online
|
|
int numLoc = 0;
|
|
foreach (var item in ListDipendentiAttiviOrd)
|
|
{
|
|
var CodImpiego = LicServ.HashDip(item);
|
|
bool fatto = await LicServ.TryRefreshActivation(CodImpiego, item.AuthKey);
|
|
if (fatto)
|
|
numLoc++;
|
|
}
|
|
Log.Trace($"NumLoc: {numLoc}");
|
|
}
|
|
|
|
private async Task RefreshLicData(bool forceReload)
|
|
{
|
|
if (!LicServ.HasAppData || forceReload)
|
|
{
|
|
await FullRefresh();
|
|
}
|
|
NumLicDispLocal = LicServ.NumLicDb;
|
|
NumLicActLocal = LicServ.ActivList.Count();
|
|
NumLicDispOnline = LicServ.AppLicense.NumLicenze;
|
|
NumLicActOnline = LicServ.AppLicense.NumLicenzeAttive;
|
|
}
|
|
|
|
private async Task ReloadConfData()
|
|
{
|
|
ListOrari = await GDataServ.AnagOrarioAll();
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
isLoading = true;
|
|
ListRecords = null;
|
|
ListDipendenti = await GDataServ.DipendentiGetAll();
|
|
if (ShowInatt)
|
|
{
|
|
SearchRecords = ListDipendenti;
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = ListDipendenti.Where(x => (x.Attivo ?? false)).ToList();
|
|
}
|
|
|
|
// eseguo filtro ricerca
|
|
try
|
|
{
|
|
if (!string.IsNullOrEmpty(searchVal))
|
|
{
|
|
SearchRecords = SearchRecords
|
|
.Where(x => x.Cognome.Contains(searchVal) || x.Nome.Contains(searchVal) || x.Cf.Contains(searchVal) || x.Email.Contains(searchVal))
|
|
.ToList();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error($"Eccezione in recupero dati{Environment.NewLine}{ex}");
|
|
}
|
|
totalCount = SearchRecords.Count;
|
|
SortTable();
|
|
isLoading = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sorting e paging tabella
|
|
/// </summary>
|
|
private void SortTable()
|
|
{
|
|
if (SearchRecords != null)
|
|
{
|
|
// se ho ordinamento riordino...
|
|
if (!string.IsNullOrEmpty(sortField))
|
|
{
|
|
switch (sortField)
|
|
{
|
|
case "Cognome":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.Cognome).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.Cognome).ToList();
|
|
}
|
|
break;
|
|
|
|
case "Nome":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.Nome).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.Nome).ToList();
|
|
}
|
|
break;
|
|
|
|
case "Matricola":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.Matricola).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.Matricola).ToList();
|
|
}
|
|
break;
|
|
|
|
case "Profilo":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.CodOrario).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.CodOrario).ToList();
|
|
}
|
|
break;
|
|
|
|
case "Dominio":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.Dominio).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.Dominio).ToList();
|
|
}
|
|
break;
|
|
|
|
case "Utente":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.Utente).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.Utente).ToList();
|
|
}
|
|
break;
|
|
|
|
case "Email":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.Email).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.Email).ToList();
|
|
}
|
|
break;
|
|
|
|
case "CF":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.Cf).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.Cf).ToList();
|
|
}
|
|
break;
|
|
|
|
case "CodeHw":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.CodHw).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.CodHw).ToList();
|
|
}
|
|
break;
|
|
|
|
case "DatiAnag":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.LuogoNascita).ThenBy(x => x.ProvNascita).ThenBy(x => x.NazNascita).ThenBy(x => x.DataNascita).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.LuogoNascita).ThenBy(x => x.ProvNascita).ThenBy(x => x.NazNascita).ThenBy(x => x.DataNascita).ToList();
|
|
}
|
|
break;
|
|
|
|
case "Gruppo":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.Gruppo).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.Gruppo).ToList();
|
|
}
|
|
break;
|
|
|
|
case "StatoLic":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.DataAssunzione).ThenBy(x => x.DataCessazione).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.DataAssunzione).ThenBy(x => x.DataCessazione).ToList();
|
|
}
|
|
break;
|
|
|
|
case "Responsabile":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.idxResp).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.idxResp).ToList();
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// filtro x display
|
|
ListRecords = SearchRecords
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
}
|
|
else
|
|
{
|
|
ListRecords = new List<DipendentiModel>();
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |