7d289a3b64
pulizia codice...
458 lines
11 KiB
C#
458 lines
11 KiB
C#
using SteamWare;
|
|
using System;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
|
|
[ValidationProperty("valore")]
|
|
public partial class mod_selettore : ApplicationUserControl
|
|
{
|
|
|
|
protected bool _chkVisibile = false;
|
|
protected bool _isValueVisible = false;
|
|
protected bool _cambioTipo = false;
|
|
|
|
protected string _valoreFull;
|
|
protected string _val1;
|
|
protected string _val2;
|
|
#region gestione eventi
|
|
|
|
public event EventHandler eh_selDone;
|
|
|
|
#endregion
|
|
|
|
#region gestione pagina
|
|
|
|
protected override void Page_Load(object sender, EventArgs e)
|
|
{
|
|
base.Page_Load(sender, e);
|
|
updateChkOpzione();
|
|
if (!Page.IsPostBack)
|
|
{
|
|
memLayer.ML.emptySessionVal(searchSessionName);
|
|
}
|
|
}
|
|
|
|
protected override void traduciObj()
|
|
{
|
|
base.traduciObj();
|
|
lblCerca.Text = traduci("lblCerca");
|
|
btnCerca.Text = traduci("search");
|
|
if (_chkVisibile)
|
|
{
|
|
updateChkOpzione();
|
|
}
|
|
}
|
|
|
|
protected override void OnInit(EventArgs e)
|
|
{
|
|
base.OnInit(e);
|
|
if (!Page.IsPostBack)
|
|
{
|
|
_val1 = "";
|
|
_val2 = "";
|
|
traduciObj();
|
|
}
|
|
if (vistaModulo == tipoVistaMod.editing)
|
|
{
|
|
setSearchValue();
|
|
impostaCampoRicerca();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// imposta il valore della ricerca da quello in session
|
|
/// </summary>
|
|
private void setSearchValue()
|
|
{
|
|
if (memLayer.ML.isInSessionObject(searchSessionName))
|
|
{
|
|
testoRicerca = memLayer.ML.StringSessionObj(searchSessionName);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// imposta i campi del filtro ricerca in session
|
|
/// </summary>
|
|
private void impostaCampoRicerca()
|
|
{
|
|
// imposto il nome del valore session x ricerca a campo univoco...
|
|
SessionParameter parametroFiltro = new SessionParameter();
|
|
parametroFiltro.SessionField = searchSessionName;
|
|
parametroFiltro.Name = searchSessionName;
|
|
parametroFiltro.DefaultValue = "*";
|
|
ods.FilterParameters.Clear();
|
|
ods.FilterParameters.Add(parametroFiltro);
|
|
}
|
|
/// <summary>
|
|
/// setta il nome del campo di ricerca
|
|
/// </summary>
|
|
protected string searchSessionName
|
|
{
|
|
get
|
|
{
|
|
return string.Format("ricerca_{0}", _tipoSelettore);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region area protected
|
|
|
|
protected string _conditio = "";
|
|
protected string testoRicerca
|
|
{
|
|
get
|
|
{
|
|
return txtCerca.Text.Trim();
|
|
}
|
|
set
|
|
{
|
|
txtCerca.Text = value;
|
|
}
|
|
}
|
|
|
|
protected selettori _selettori = new selettori();
|
|
/// <summary>
|
|
/// a seconda del tipo di selettore cambierà l'origine ods
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void chkOpzione_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
fixChkOds();
|
|
}
|
|
|
|
protected void setCheck()
|
|
{
|
|
if (_tipoSelettore == tipoSelettore.utentiAll || _tipoSelettore == tipoSelettore.utentiCdc)
|
|
{
|
|
_chkVisibile = true;
|
|
}
|
|
else
|
|
{
|
|
_chkVisibile = false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// aggiorna visualizzazione del check opzionale con label e visibilità
|
|
/// </summary>
|
|
protected void updateChkOpzione()
|
|
{
|
|
// se definito il tipo decido SE mostrare il check e tradurre la label...
|
|
if (_tipoSelettore == tipoSelettore.utentiAll || _tipoSelettore == tipoSelettore.utentiCdc)
|
|
{
|
|
chkOpzione.Visible = true;
|
|
chkOpzione.Text = traduci("chkSoloGer");
|
|
if (_tipoSelettore == tipoSelettore.utentiCdc)
|
|
{
|
|
chkOpzione.Checked = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
chkOpzione.Visible = false;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// aggiorna label e valore principale da una chiave multipart
|
|
/// </summary>
|
|
private void aggiornaDaValMulti()
|
|
{
|
|
// eseguo SE E SOLO SE entrambi i valori sono popolati
|
|
if (val1 != "" && val1 != null)
|
|
{
|
|
if (val2 != "" && val2 != null && val2 != "na")
|
|
{
|
|
_valoreFull = string.Format("{0}#{1}", val1, val2);
|
|
}
|
|
else
|
|
{
|
|
_valoreFull = val1;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// tipo di valori mostrati
|
|
/// </summary>
|
|
protected tipoSelettore _tipoSelettore = tipoSelettore.cdc;
|
|
/// <summary>
|
|
/// nome del controllo gestito dal nostro popup
|
|
/// </summary>
|
|
protected string _targetControl = "";
|
|
/// <summary>
|
|
/// sistemo gli ods
|
|
/// </summary>
|
|
protected override void bindControlli()
|
|
{
|
|
base.bindControlli();
|
|
fixChkOds();
|
|
fixOds();
|
|
}
|
|
/// <summary>
|
|
/// sistema l'ods dato lo stato del chk
|
|
/// </summary>
|
|
protected void fixChkOds()
|
|
{
|
|
if (_tipoSelettore == tipoSelettore.utentiAll || _tipoSelettore == tipoSelettore.utentiCdc)
|
|
{
|
|
// verifico se sia o meno checked "solo cdc utente"...
|
|
if (chkOpzione.Checked)
|
|
{
|
|
//imposto nuovo tipo selettore
|
|
_tipoSelettore = tipoSelettore.utentiCdc;
|
|
fixOds();
|
|
}
|
|
else
|
|
{
|
|
//imposto nuovo tipo selettore
|
|
_tipoSelettore = tipoSelettore.utentiAll;
|
|
fixOds();
|
|
}
|
|
// faccio databind...
|
|
grView.PageIndex = 0;
|
|
grView.DataBind();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// sistemazione fonte ods...
|
|
/// </summary>
|
|
protected void fixOds()
|
|
{
|
|
string _selectMethod = "";
|
|
switch (_tipoSelettore)
|
|
{
|
|
case tipoSelettore.cdc:
|
|
_selectMethod = "getSelAllCdC";
|
|
break;
|
|
case tipoSelettore.impianti:
|
|
_selectMethod = "getSelImpianti";
|
|
break;
|
|
case tipoSelettore.macchine:
|
|
_selectMethod = "getSelMacchine";
|
|
break;
|
|
case tipoSelettore.utentiAll:
|
|
_selectMethod = "getSelAllUsers";
|
|
break;
|
|
case tipoSelettore.utentiCdc:
|
|
_selectMethod = "getSelUsersGer";
|
|
break;
|
|
}
|
|
ods.SelectMethod = _selectMethod;
|
|
}
|
|
|
|
/// <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>
|
|
/// selezione annullata su cambio pagina
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void grView_PageIndexChanged(object sender, EventArgs e)
|
|
{
|
|
grView.SelectedIndex = -1;
|
|
}
|
|
/// <summary>
|
|
/// aggiornamento filtro da stringa di ricerca del popup
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void txtCerca_TextChanged(object sender, EventArgs e)
|
|
{
|
|
// se cambio filtro tolgo il selected...
|
|
grView.SelectedIndex = -1;
|
|
// salvo la ricerca in session e filter dell'ods...
|
|
memLayer.ML.setSessionVal(searchSessionName, txtCerca.Text);
|
|
impostaCampoRicerca();
|
|
fixChkOds();
|
|
fixOds();
|
|
}
|
|
/// <summary>
|
|
/// salvo il valore selezionato
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void grView_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
string valore = grView.SelectedValue.ToString();
|
|
// se ho una chiave multiparte salvo nei 2 valori...
|
|
if (valore.IndexOf('#') > -1)
|
|
{
|
|
string[] valori = valore.Split('#');
|
|
val1 = valori[0];
|
|
val2 = valori[1];
|
|
}
|
|
if (eh_selDone != null)
|
|
{
|
|
eh_selDone(this, new EventArgs());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// resetta ricerca e selezione
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnReset_Click(object sender, EventArgs e)
|
|
{
|
|
grView.SelectedIndex = -1;
|
|
testoRicerca = "";
|
|
memLayer.ML.emptySessionVal(searchSessionName);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region area public
|
|
|
|
/// <summary>
|
|
/// tipo di selettore da istanziare
|
|
/// </summary>
|
|
public tipoSelettore tipo
|
|
{
|
|
get
|
|
{
|
|
return _tipoSelettore;
|
|
}
|
|
set
|
|
{
|
|
_tipoSelettore = value;
|
|
setCheck();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// effettua update del controllo
|
|
/// </summary>
|
|
public void doUpdate()
|
|
{
|
|
// svuoto ricerca...
|
|
memLayer.ML.emptySessionVal(searchSessionName);
|
|
testoRicerca = "";
|
|
// imposto valori cercati...
|
|
setSearchValue();
|
|
impostaCampoRicerca();
|
|
// continuo con update
|
|
updateChkOpzione();
|
|
fixOds();
|
|
aggiornaDaValMulti();
|
|
// faccio databind...
|
|
grView.PageIndex = 0;
|
|
grView.DataBind();
|
|
}
|
|
|
|
/// <summary>
|
|
/// valore mostrato nel campo testo del selettore
|
|
/// </summary>
|
|
public string valore
|
|
{
|
|
get
|
|
{
|
|
return grView.SelectedValue.ToString();
|
|
}
|
|
set
|
|
{
|
|
_valoreFull = value;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// valore di una chiave multiparte
|
|
/// </summary>
|
|
public string val1
|
|
{
|
|
get
|
|
{
|
|
return _val1;
|
|
}
|
|
set
|
|
{
|
|
_val1 = value;
|
|
aggiornaDaValMulti();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// valore di una chiave multiparte
|
|
/// </summary>
|
|
public string val2
|
|
{
|
|
get
|
|
{
|
|
return _val2;
|
|
}
|
|
set
|
|
{
|
|
_val2 = value;
|
|
aggiornaDaValMulti();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// impone una condizione di filtro sui valori mostrati
|
|
/// </summary>
|
|
public string conditio
|
|
{
|
|
get
|
|
{
|
|
return _conditio;
|
|
}
|
|
set
|
|
{
|
|
_conditio = value;
|
|
if (_conditio != "")
|
|
{
|
|
ods.SelectParameters.Clear();
|
|
ods.SelectParameters.Add("where", string.Format(" conditio = '{0}' ", _conditio));
|
|
}
|
|
else
|
|
{
|
|
ods.SelectParameters.Clear();
|
|
ods.SelectParameters.Add("where", " conditio = '*' ");
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// determina se il valore da selezionare sia da visualizzare o meno
|
|
/// </summary>
|
|
public bool isValueVisible
|
|
{
|
|
get
|
|
{
|
|
return _isValueVisible;
|
|
}
|
|
set
|
|
{
|
|
_isValueVisible = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|