513 lines
16 KiB
C#
513 lines
16 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using System.Data;
|
|
using SteamWare;
|
|
using GPW_data;
|
|
|
|
namespace GPW_Admin.WebUserControls
|
|
{
|
|
public partial class mod_adminDipendenti : BaseUserControl
|
|
{
|
|
#region Public Properties
|
|
|
|
public int attivazioniOnline
|
|
{
|
|
get => licenzeGPW.attivazioniOnline;
|
|
}
|
|
|
|
public int IdxDipSel
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
if (grView.SelectedIndex >= 0)
|
|
{
|
|
var rawIdx = grView.SelectedValue.ToString();
|
|
int.TryParse(rawIdx, out answ);
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
public bool isTicketReq
|
|
{
|
|
get
|
|
{
|
|
bool answ = false;
|
|
bool.TryParse(hfReqTicket.Value, out answ);
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
hfReqTicket.Value = $"{value}";
|
|
}
|
|
}
|
|
public bool showTickets
|
|
{
|
|
get
|
|
{
|
|
bool answ = false;
|
|
bool.TryParse(hfShowTickets.Value, out answ);
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
hfShowTickets.Value = $"{value}";
|
|
}
|
|
}
|
|
|
|
|
|
public int numLicenze
|
|
{
|
|
get => licenzeGPW.licenzeAttive;
|
|
}
|
|
|
|
public int numLicenzeOnline
|
|
{
|
|
get => licenzeGPW.licenzeOnline;
|
|
}
|
|
|
|
public int numTickets
|
|
{
|
|
get => licenzeGPW.numTickets;
|
|
}
|
|
|
|
public bool showAll
|
|
{
|
|
get
|
|
{
|
|
return chkshowAll.Checked;
|
|
}
|
|
}
|
|
|
|
public int utentiAttivi
|
|
{
|
|
get => licenzeGPW.utentiAttivi;
|
|
}
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Verifica licenza (se sia libera x modifca o prima associazione)
|
|
/// </summary>
|
|
/// <param name="idxDIp"></param>
|
|
/// <returns></returns>
|
|
public bool checkFreeEdit(object idxDip)
|
|
{
|
|
bool answ = false;
|
|
int IdxDip = 0;
|
|
int.TryParse($"{idxDip}", out IdxDip);
|
|
if (IdxDip > 0)
|
|
{
|
|
var localUserList = licenzeGPW.getDipAttivi();
|
|
// cerco!
|
|
var currUser = localUserList.Where(x => x.idxDipendente == IdxDip).FirstOrDefault();
|
|
|
|
// verifico SE sia disponibile licenza...
|
|
var activationsList = licenzeGPW.ListaAttivazioni;
|
|
var currHash = DataProxy.DP.hashCodImpiego(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>
|
|
/// Verifica licenza (se sia validata/associata a quelle in memoria)
|
|
/// </summary>
|
|
/// <param name="idxDIp"></param>
|
|
/// <returns></returns>
|
|
public bool checkLic(object idxDip)
|
|
{
|
|
bool answ = false;
|
|
int IdxDip = 0;
|
|
int.TryParse($"{idxDip}", out IdxDip);
|
|
if (IdxDip > 0)
|
|
{
|
|
var localUserList = licenzeGPW.getDipAttivi();
|
|
// cerco!
|
|
var currUser = localUserList.Where(x => x.idxDipendente == IdxDip).FirstOrDefault();
|
|
|
|
// verifico SE sia disponibile licenza...
|
|
var activationsList = licenzeGPW.ListaAttivazioni;
|
|
var currHash = DataProxy.DP.hashCodImpiego(currUser);
|
|
var currAct = activationsList.Where(x => x.CodImpiego == currHash).FirstOrDefault();
|
|
answ = (currAct != null && currAct.CodImpiego == currHash);
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// determina se sia eliminabile il record (=non usato)
|
|
/// </summary>
|
|
/// <param name="idxMaker"></param>
|
|
/// <returns></returns>
|
|
public bool delEnabled(object idxObj)
|
|
{
|
|
bool answ = true;
|
|
// solo se ha diritti scrittura controllo
|
|
if (idxObj != null)
|
|
{
|
|
int trovati = 0;
|
|
int idxDip = 0;
|
|
_ = int.TryParse(idxObj.ToString(), out idxDip);
|
|
trovati = DataProxy.DP.taTimb.getLastByDip(idxDip).Count;
|
|
// controllo se ci sono record correlati...
|
|
if (trovati > 0)
|
|
{
|
|
answ = false;
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
public void doUpdate()
|
|
{
|
|
fullRefresh();
|
|
fixVisibility();
|
|
grView.DataBind();
|
|
}
|
|
|
|
/// <summary>
|
|
/// resetta la selezione dei valori in caso di modifiche su altri controlli
|
|
/// </summary>
|
|
public void resetSelezione()
|
|
{
|
|
grView.SelectedIndex = -1;
|
|
grView.DataBind();
|
|
raiseReset();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// gestione evento richiesta nuovo valore (mostra footer, ...)
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnNew_Click(object sender, EventArgs e)
|
|
{
|
|
// reset selezione...
|
|
resetSelezione();
|
|
// mostro il footer oppure la riga dei dettagli x nuovo...
|
|
if (grView.FooterRow != null)
|
|
{
|
|
grView.FooterRow.Visible = true;
|
|
}
|
|
// sollevo evento nuovo valore...
|
|
//raiseAddNew();
|
|
}
|
|
|
|
/// <summary>
|
|
/// reset della selezione
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnReset_Click(object sender, EventArgs e)
|
|
{
|
|
isTicketReq = false;
|
|
showTickets = false;
|
|
resetSelezione();
|
|
}
|
|
|
|
protected void chkshowAll_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
grView.DataBind();
|
|
raiseReset();
|
|
}
|
|
|
|
/// <summary>
|
|
/// elenco colonne del datagrid
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected DataColumnCollection colonneObj()
|
|
{
|
|
DataColumnCollection colonne = null;
|
|
using (DS_Applicazione.DipendentiDataTable tabella = new DS_Applicazione.DipendentiDataTable())
|
|
{
|
|
colonne = tabella.Columns;
|
|
}
|
|
return colonne;
|
|
}
|
|
|
|
/// <summary>
|
|
/// traduce gli header delle colonne
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void grView_DataBound(object sender, EventArgs e)
|
|
{
|
|
if (grView.Rows.Count > 0)
|
|
{
|
|
LinkButton lb;
|
|
// aggiorno gli headers
|
|
foreach (TableCell cella in grView.HeaderRow.Cells)
|
|
{
|
|
try
|
|
{
|
|
lb = (LinkButton)cella.Controls[0];
|
|
lb.Text = traduci(lb.Text);
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
int totRecord = grView.Rows.Count + grView.PageSize * (grView.PageCount - 1);
|
|
lblNumRec.Text = string.Format("{0} records of ~ {1}", grView.Rows.Count, totRecord);
|
|
}
|
|
else
|
|
{
|
|
lblNumRec.Text = "";
|
|
}
|
|
}
|
|
|
|
protected void grView_RowEditing(object sender, GridViewEditEventArgs e)
|
|
{
|
|
resetSelezione();
|
|
}
|
|
|
|
protected void grView_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
// altrimenti mostro gestione licenza DIP
|
|
raiseAddNew();
|
|
}
|
|
|
|
/// <summary>
|
|
/// annulla inserimento nuovo valore da footer
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void lblCanc_click(object sender, EventArgs e)
|
|
{
|
|
// annullo inserimento: nascondo footer, bind controlli...
|
|
grView.FooterRow.Visible = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// inserisce nuovo valore da footer
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void lblIns_click(object sender, EventArgs e)
|
|
{
|
|
// click su inserimento, chiamo il metodo insert dell'ObjectDataSource
|
|
ods.Insert();
|
|
}
|
|
|
|
protected void lbtFixMissing_Click(object sender, EventArgs e)
|
|
{
|
|
// procedo SOLO SE il numero online/offline è differente in primis...
|
|
if (numLicenzeOnline == numLicenze && attivazioniOnline != utentiAttivi)
|
|
{
|
|
// ciclo tutti gli utenti attivi
|
|
var localUserList = licenzeGPW.getDipAttivi();
|
|
// verifico SE sia disponibile licenza...
|
|
var activationsList = licenzeGPW.ListaAttivazioni;
|
|
Dictionary<string, string> CodList = new Dictionary<string, string>();
|
|
|
|
// ciclo x ogni dip attivo...
|
|
foreach (var item in localUserList)
|
|
{
|
|
// calcolo codImpiego
|
|
string currCodImp = DataProxy.DP.hashCodImpiego(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
|
|
licenzeGPW.tryActivationMult(CodList).ConfigureAwait(false);
|
|
|
|
if (CodList.Count > 0)
|
|
{
|
|
raiseReset();
|
|
}
|
|
|
|
// cmq faccio refresh
|
|
fullRefresh();
|
|
}
|
|
}
|
|
|
|
protected void lbtRefresh_Click(object sender, EventArgs e)
|
|
{
|
|
fullRefresh();
|
|
grView.DataBind();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Richiesta selezione utente
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void lbtSelect_Click(object sender, EventArgs e)
|
|
{
|
|
isTicketReq = false;
|
|
showTickets = false;
|
|
}
|
|
|
|
protected void lbtShowTickets_Click(object sender, EventArgs e)
|
|
{
|
|
// indico richiesta showTickets
|
|
isTicketReq = false;
|
|
showTickets = true;
|
|
// sollevo evento
|
|
raiseEvent();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Richiesta inserimento ticket supporto
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void lbtTicket_Click(object sender, EventArgs e)
|
|
{
|
|
isTicketReq = true;
|
|
showTickets = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// check licenze in fase di update...
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void ods_Updating(object sender, ObjectDataSourceMethodEventArgs e)
|
|
{
|
|
if (e != null)
|
|
{
|
|
if (!licenzeGPW.checkLicenze)
|
|
{
|
|
// annullo insert se licenze sforate...
|
|
e.Cancel = true;
|
|
grView.EditIndex = -1;
|
|
grView.DataBind();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// caricamento
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!Page.IsPostBack)
|
|
{
|
|
isTicketReq = false;
|
|
showTickets=false;
|
|
//fullRefresh();
|
|
}
|
|
fixVisibility();
|
|
}
|
|
|
|
/// <summary>
|
|
/// recupera i dati di un nuovo record contenuti nel footer di un gridView;
|
|
/// questi devono essere opportunamente nominati (es: txt{0}, dl{0}, ...)
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void recuperaFooter(object sender, ObjectDataSourceMethodEventArgs e)
|
|
{
|
|
if (e != null)
|
|
{
|
|
if (chkLicOk)
|
|
{
|
|
//recupero la riga footer...
|
|
DataColumnCollection colonne = colonneObj();
|
|
string nomeCol;
|
|
string tipoColonna = "";
|
|
foreach (DataColumn colonna in colonne)
|
|
{
|
|
nomeCol = colonna.ColumnName;
|
|
// cerco un textbox o quello che sia...
|
|
if (grView.FooterRow.FindControl(string.Format("txt{0}", nomeCol)) != null)
|
|
{
|
|
tipoColonna = "textBox";
|
|
}
|
|
else if (grView.FooterRow.FindControl(string.Format("dl{0}", nomeCol)) != null)
|
|
{
|
|
tipoColonna = "dropDownList";
|
|
}
|
|
else if (grView.FooterRow.FindControl(string.Format("chk{0}", nomeCol)) != null)
|
|
{
|
|
tipoColonna = "checkBox";
|
|
}
|
|
// in base al tipo salvo negli inputparameters dell'ODS
|
|
switch (tipoColonna)
|
|
{
|
|
case "textBox":
|
|
e.InputParameters[nomeCol] = ((TextBox)grView.FooterRow.FindControl(string.Format("txt{0}", nomeCol))).Text;
|
|
break;
|
|
|
|
case "dropDownList":
|
|
e.InputParameters[nomeCol] = ((DropDownList)grView.FooterRow.FindControl(string.Format("dl{0}", nomeCol))).SelectedValue;
|
|
break;
|
|
|
|
case "checkBox":
|
|
e.InputParameters[nomeCol] = ((CheckBox)grView.FooterRow.FindControl(string.Format("chk{0}", nomeCol))).Checked;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
tipoColonna = "";
|
|
}
|
|
// attivo imposto a FALSE!
|
|
e.InputParameters["attivo"] = "false";
|
|
// imposto la sua authKey
|
|
string codCF = e.InputParameters["CF"].ToString();
|
|
if (string.IsNullOrEmpty(codCF))
|
|
{
|
|
codCF = "ABCDEF12G34H567I";
|
|
}
|
|
DateTime adesso = DateTime.Now;
|
|
string md5UserAuthKey = SteamCrypto.EncryptString($"{codCF}.{adesso:yyMMddHHmmss}", "AuthGPW");
|
|
e.InputParameters["authKey"] = $"{md5UserAuthKey}";
|
|
}
|
|
else
|
|
{
|
|
// annullo insert se licenze sforate...
|
|
e.Cancel = true;
|
|
grView.DataBind();
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Methods
|
|
|
|
private static void fullRefresh()
|
|
{
|
|
// eseguo call di recupero da online
|
|
bool refreshApp = licenzeGPW.RefreshAppInfo().Result;
|
|
bool refreshAct = licenzeGPW.RefreshActInfo().Result;
|
|
bool refreshPayload = licenzeGPW.RefreshPayload().Result;
|
|
//bool refreshLic = licenzeGPW.RefreshLicInfo().Result;
|
|
}
|
|
|
|
private void fixVisibility()
|
|
{
|
|
lbtFixMissing.Visible = (numLicenzeOnline == numLicenze && attivazioniOnline != utentiAttivi);
|
|
grView.PageSize = utils.pageSize;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |