using GPW_data; using SteamWare; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; 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; } } /// /// Cod impiego calcolato /// 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 ParamList = new Dictionary(); 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; } /// /// Verifica se sia attivo ma non attivato e si possa attivare... /// 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; } 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); if (isAttivo) { DateTime.TryParse($"{dtAssunzione}", out assunto); // verifica date coerenti inizio if (oggi.Subtract(assunto).TotalDays < 365 * 60) { // verifica attivazione < 2 mesi if (oggi.Subtract(assunto).TotalDays > 60) { // recupero record utente #if false var tabDip = DataProxy.DP.taDipendenti.getByIdx(idxDipSel); if (tabDip != null && tabDip.Rows.Count == 1) #endif if (DataProxy.DP.getRowDip(idxDipSel) != null) { // verifica sia sbloccabile la licenza (online) answ = licenzeGPW.checkActivationUnlocked(CodImpiego).Result; } } } } return answ; } #endregion Public Methods } }