using GPW_data;
using SteamWare;
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace GPW_Admin.WebUserControls
{
public partial class mod_adminClienti : BaseUserControl
{
#region Private Methods
private void Cmp_toggle_ehToggle(object sender, EventArgs e)
{
hfShowAll.Value = $"{cmp_toggle.toggleValue}";
doUpdate();
}
#endregion Private 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)
{
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 = "";
}
}
///
/// 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();
}
}
}
///
/// caricamento
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
hfShowAll.Value = $"{cmp_toggle.toggleValue}";
}
grView.PageSize = utils.pageSize;
cmp_toggle.ehToggle += Cmp_toggle_ehToggle;
}
///
/// recupera i dati di un nuovo record contenuti nel footer di un gridView;
/// questi devono esses 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 = "";
}
}
else
{
// annullo insert se licenze sforate...
e.Cancel = true;
grView.DataBind();
}
}
}
#endregion Protected Methods
#region Public Methods
///
/// 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 idxCli = 0;
_ = int.TryParse($"{idxObj}", out idxCli);
answ = !hasChildObj(idxCli);
}
return answ;
}
public void doUpdate()
{
grView.PageSize = utils.pageSize;
grView.DataBind();
}
///
/// Determina se abbia child obj --> NON eliminabile
///
///
///
public bool hasChildObj(int idxCli)
{
bool answ = false;
string redKey = memLayer.ML.redHash($"clienteHasChildObj:{idxCli}");
// cerco inc ache redis...
string rawData = memLayer.ML.getRSV(redKey);
if (rawData == null)
{
int trovati = DataProxy.DP.taAP.getByIdxCli(idxCli, true, 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
}
}