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 /// /// Verifica licenza (se sia libera x modifca o prima associazione) /// /// /// 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; } /// /// Verifica licenza (se sia validata/associata a quelle in memoria) /// /// /// 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; } /// /// determina se sia eliminabile il record (=non usato) /// /// /// 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(); } /// /// resetta la selezione dei valori in caso di modifiche su altri controlli /// public void resetSelezione() { grView.SelectedIndex = -1; grView.DataBind(); raiseReset(); } #endregion Public Methods #region Protected Methods /// /// gestione evento richiesta nuovo valore (mostra footer, ...) /// /// /// 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(); } /// /// reset della selezione /// /// /// protected void btnReset_Click(object sender, EventArgs e) { isTicketReq = false; showTickets = false; resetSelezione(); } protected void chkshowAll_CheckedChanged(object sender, EventArgs e) { grView.DataBind(); raiseReset(); } /// /// elenco colonne del datagrid /// /// protected DataColumnCollection colonneObj() { DataColumnCollection colonne = null; using (DS_Applicazione.DipendentiDataTable tabella = new DS_Applicazione.DipendentiDataTable()) { colonne = tabella.Columns; } return colonne; } /// /// traduce gli header delle colonne /// /// /// 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(); } /// /// annulla inserimento nuovo valore da footer /// /// /// protected void lblCanc_click(object sender, EventArgs e) { // annullo inserimento: nascondo footer, bind controlli... grView.FooterRow.Visible = false; } /// /// inserisce nuovo valore da footer /// /// /// 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 CodList = new Dictionary(); // 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(); } /// /// Richiesta selezione utente /// /// /// 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(); } /// /// Richiesta inserimento ticket supporto /// /// /// protected void lbtTicket_Click(object sender, EventArgs e) { isTicketReq = true; showTickets = false; } /// /// check licenze in fase di update... /// /// /// 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(); } } } /// /// caricamento /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { isTicketReq = false; showTickets=false; //fullRefresh(); } fixVisibility(); } /// /// recupera i dati di un nuovo record contenuti nel footer di un gridView; /// questi devono essere opportunamente nominati (es: txt{0}, dl{0}, ...) /// /// /// 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 } }