using GPW_data; using SteamWare; using System; using System.Data; using System.Web.UI.WebControls; namespace GPW_Admin.WebUserControls { public partial class cmp_elencoGruppi : BaseUserControl { #region Public Properties public string gruppoSel { get { string answ = ""; if (grView.SelectedIndex >= 0) { answ = $"{grView.SelectedValue}"; } return answ; } } #endregion Public Properties #region Protected Methods /// /// gestione evento richiesta nuovo valore (mostra footer, ...) /// /// /// protected void btnNew_Click(object sender, EventArgs e) { DataProxy.DP.taGruppi.insertQuery("_New GROUP", "Descrizione", "", true); resetSelezione(); } /// /// reset della selezione /// /// /// protected void btnReset_Click(object sender, EventArgs e) { resetSelezione(); } /// /// elenco colonne del datagrid /// /// protected DataColumnCollection colonneObj() { DataColumnCollection colonne = null; using ( DS_Applicazione.AnagClientiDataTable tabella = new DS_Applicazione.AnagClientiDataTable()) { 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_SelectedIndexChanged(object sender, EventArgs e) { raiseEvent(); } /// /// 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(); } /// /// check licenze in fase di update... /// /// /// protected void ods_Updating(object sender, ObjectDataSourceMethodEventArgs e) { if (!licenzeGPW.checkLicenze) { if (e != null) { // annullo insert se licenze sforate... e.Cancel = true; grView.EditIndex = -1; grView.DataBind(); } } } protected void Page_Load(object sender, EventArgs e) { grView.PageSize = utils.pageSize; } #endregion Protected Methods #region Public Methods /// /// determina se sia eliminabile il record (=non usato) /// /// /// public bool delEnabled(object gruppo) { bool answ = true; // solo se ha diritti scrittura controllo if (gruppo != null) { answ = !hasChildObj($"{gruppo}"); } return answ; } public void doUpdate() { grView.PageSize = utils.pageSize; grView.DataBind(); } /// /// Determina se abbia child obj --> NON eliminabile /// /// /// public bool hasChildObj(string gruppo) { bool answ = false; string redKey = memLayer.ML.redHash($"gruppoHasChildObj:{gruppo}"); // cerco inc ache redis... string rawData = memLayer.ML.getRSV(redKey); if (rawData == null) { int trovati = DataProxy.DP.taVSD.getByGruppo(gruppo, false).Rows.Count; answ = (trovati > 0); memLayer.ML.setRSV(redKey, $"{answ}", 60 * 5); } else { bool.TryParse(rawData, out answ); } return answ; } /// /// resetta la selezione dei valori in caso di modifiche su altri controlli /// public void resetSelezione() { grView.SelectedIndex = -1; grView.DataBind(); raiseReset(); } #endregion Public Methods } }