279 lines
9.1 KiB
C#
279 lines
9.1 KiB
C#
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
|
|
|
|
/// <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)
|
|
{
|
|
resetSelezione();
|
|
}
|
|
|
|
/// <summary>
|
|
/// elenco colonne del datagrid
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected DataColumnCollection colonneObj()
|
|
{
|
|
DataColumnCollection colonne = null;
|
|
using (
|
|
DS_Applicazione.AnagClientiDataTable tabella = new DS_Applicazione.AnagClientiDataTable())
|
|
{
|
|
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 = "";
|
|
}
|
|
}
|
|
|
|
/// <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();
|
|
}
|
|
|
|
/// <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 (!licenzeGPW.checkLicenze)
|
|
{
|
|
if (e != null)
|
|
{
|
|
// 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)
|
|
{
|
|
hfShowAll.Value = $"{cmp_toggle.toggleValue}";
|
|
}
|
|
grView.PageSize = utils.pageSize;
|
|
cmp_toggle.ehToggle += Cmp_toggle_ehToggle;
|
|
}
|
|
|
|
/// <summary>
|
|
/// recupera i dati di un nuovo record contenuti nel footer di un gridView;
|
|
/// questi devono esses 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 = "";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// annullo insert se licenze sforate...
|
|
e.Cancel = true;
|
|
grView.DataBind();
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Public Methods
|
|
|
|
/// <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 idxCli = 0;
|
|
_ = int.TryParse($"{idxObj}", out idxCli);
|
|
answ = !hasChildObj(idxCli);
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
public void doUpdate()
|
|
{
|
|
grView.PageSize = utils.pageSize;
|
|
grView.DataBind();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Determina se abbia child obj --> NON eliminabile
|
|
/// </summary>
|
|
/// <param name="idxCli"></param>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
|
|
/// <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
|
|
}
|
|
} |