250 lines
7.9 KiB
C#
250 lines
7.9 KiB
C#
using GPW_data;
|
|
using SteamWare;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace GPW_Admin.WebUserControls
|
|
{
|
|
public partial class cmp_userLicense : BaseUserControl
|
|
{
|
|
#region Protected Properties
|
|
|
|
protected string ChiaveUtente
|
|
{
|
|
get
|
|
{
|
|
string answ = "";
|
|
if (currRowDip != null)
|
|
{
|
|
answ = currRowDip.authKey;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Cod impiego calcolato
|
|
/// </summary>
|
|
protected string CodImpiego
|
|
{
|
|
get
|
|
{
|
|
return DataProxy.DP.hashCodImpiego(currRowDip);
|
|
}
|
|
}
|
|
|
|
protected DS_Applicazione.DipendentiRow currRowDip
|
|
{
|
|
get
|
|
{
|
|
return DataProxy.DP.getRowDip(idxDipSel);
|
|
}
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Public Properties
|
|
|
|
public int idxDipSel
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
int.TryParse(hfIdxDip.Value, out answ);
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
hfIdxDip.Value = $"{value}";
|
|
}
|
|
}
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected void lbrRelease_Click(object sender, EventArgs e)
|
|
{
|
|
// riesegue controllo ed disattiva
|
|
Dictionary<string, string> ParamList = new Dictionary<string, string>();
|
|
ParamList.Add(CodImpiego, ChiaveUtente);
|
|
bool fatto = licenzeGPW.tryDeactivation(ParamList).Result;
|
|
if (fatto)
|
|
{
|
|
DataProxy.DP.taDipendenti.updateActive(false, idxDipSel);
|
|
}
|
|
frmView.DataBind();
|
|
raiseReset();
|
|
}
|
|
|
|
protected void lbtActivate_Click(object sender, EventArgs e)
|
|
{
|
|
// verifica SE ci sono licenze disponibili
|
|
if (licenzeGPW.licenzeOnline > licenzeGPW.attivazioniOnline)
|
|
{
|
|
// attiva utente
|
|
DataProxy.DP.taDipendenti.updateActive(true, idxDipSel);
|
|
|
|
// effettua riassegnazione
|
|
bool fatto = licenzeGPW.tryActivation(CodImpiego, ChiaveUtente).Result;
|
|
}
|
|
|
|
frmView.DataBind();
|
|
raiseAddNew();
|
|
}
|
|
|
|
protected void lbtReissue_Click(object sender, EventArgs e)
|
|
{
|
|
// verifica SE ci sono licenze disponibili
|
|
if (licenzeGPW.licenzeOnline > licenzeGPW.attivazioniOnline)
|
|
{
|
|
// effettua riassegnazione
|
|
bool fatto = licenzeGPW.tryActivation(CodImpiego, ChiaveUtente).Result;
|
|
frmView.DataBind();
|
|
raiseAddNew();
|
|
}
|
|
}
|
|
|
|
protected void lbtResync_Click(object sender, EventArgs e)
|
|
{
|
|
// genero nuova authKey x SMART device
|
|
var rigaDip = DataProxy.DP.getRowDip(idxDipSel);
|
|
if (rigaDip != null)
|
|
{
|
|
DateTime adesso = DateTime.Now;
|
|
string newKey = $"{rigaDip.CF}-{adesso:yyMMdd-HHmmss}";
|
|
string md5UserAuthKey = SteamCrypto.EncryptString(newKey, "AuthGPW");
|
|
// aggiorno su DB
|
|
DataProxy.DP.taDipendenti.stp_Dip_setAuthKey(idxDipSel, md5UserAuthKey);
|
|
// chiama resync dati licenza (cod impiego / codAuth)
|
|
bool fatto = licenzeGPW.tryRefreshActivation(CodImpiego, md5UserAuthKey).Result;
|
|
frmView.DataBind();
|
|
raiseAddNew();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Public Methods
|
|
|
|
public bool canActivate(object attivo, object dtAssunzione, object dtCessazione)
|
|
{
|
|
bool answ = false;
|
|
bool isAttivo = true;
|
|
DateTime oggi = DateTime.Today;
|
|
DateTime assunto = DateTime.Today;
|
|
DateTime cessato = DateTime.Today.AddDays(1);
|
|
bool.TryParse($"{attivo}", out isAttivo);
|
|
if (!isAttivo)
|
|
{
|
|
DateTime.TryParse($"{dtAssunzione}", out assunto);
|
|
// verifica date coerenti inizio
|
|
if (oggi.Subtract(assunto).TotalDays < 365 * 60)
|
|
{
|
|
// verifica ci siano licenze...
|
|
if (licenzeGPW.checkLicenze && (licenzeGPW.licenzeAttive > licenzeGPW.utentiAttivi))
|
|
{
|
|
// ora verifico online...
|
|
answ = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifica se sia attivo ma non attivato e si possa attivare...
|
|
/// </summary>
|
|
public bool canReissue(object attivo, object dtAssunzione, object dtCessazione)
|
|
{
|
|
bool answ = false;
|
|
bool isAttivo = false;
|
|
bool.TryParse($"{attivo}", out isAttivo);
|
|
|
|
// solo se già attivo
|
|
if (isAttivo)
|
|
{
|
|
// refresh licenze
|
|
licenzeGPW.RefreshActInfo().ConfigureAwait(false);
|
|
// verifico se ci sia licenza locale..
|
|
if (!licenzeGPW.checkActivation(CodImpiego).Result)
|
|
{
|
|
// verifica sia sbloccabile la licenza (online)
|
|
answ = !licenzeGPW.checkActivationUnlocked(CodImpiego).Result;
|
|
}
|
|
}
|
|
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restitusice la data di unlock del dipendente
|
|
/// </summary>
|
|
public DateTime lockExpiry(object attivo, object dtCessazione)
|
|
{
|
|
DateTime cessato = DateTime.Today.AddDays(1);
|
|
DateTime.TryParse($"{dtCessazione}", out cessato);
|
|
bool isAttivo = false;
|
|
bool.TryParse($"{attivo}", out isAttivo);
|
|
DateTime answ = isAttivo ? DateTime.Today.AddDays(90) : cessato;
|
|
|
|
// verifico SE sia disponibile licenza...
|
|
var activationsList = licenzeGPW.ListaAttivazioni;
|
|
var currAct = activationsList.Where(x => x.CodImpiego == CodImpiego).FirstOrDefault();
|
|
// se trovo record
|
|
if (currAct != null)
|
|
{
|
|
answ = currAct.VetoUnlock;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
public bool lockExpired(object attivo, object dtCessazione)
|
|
{
|
|
DateTime oggi = DateTime.Today;
|
|
DateTime dateUnlock = lockExpiry(attivo, dtCessazione);
|
|
return dateUnlock <= oggi;
|
|
}
|
|
|
|
public bool canRemove(object attivo, object dtAssunzione, object dtCessazione)
|
|
{
|
|
bool answ = false;
|
|
bool isAttivo = false;
|
|
DateTime oggi = DateTime.Today;
|
|
DateTime assunto = DateTime.Today;
|
|
DateTime cessato = DateTime.Today.AddDays(1);
|
|
bool.TryParse($"{attivo}", out isAttivo);
|
|
DateTime.TryParse($"{dtAssunzione}", out assunto);
|
|
DateTime.TryParse($"{dtCessazione}", out cessato);
|
|
if (isAttivo)
|
|
{
|
|
// verifica date coerenti inizio: max 60 anni lavoro
|
|
if (oggi.Subtract(assunto).TotalDays < 365 * 60)
|
|
{
|
|
//// verifica assunzione da almeno 2 settimane
|
|
//if (oggi.Subtract(assunto).TotalDays > 15)
|
|
//{
|
|
// recupero record utente
|
|
if (DataProxy.DP.getRowDip(idxDipSel) != null)
|
|
{
|
|
// verifica sia sbloccabile la licenza (online)
|
|
answ = licenzeGPW.checkActivationUnlocked(CodImpiego).Result;
|
|
}
|
|
//}
|
|
}
|
|
}
|
|
|
|
return answ;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |