Files
2022-05-05 17:27:08 +02:00

517 lines
11 KiB
C#

using SteamWare;
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class mod_filtro : ApplicationUserControl
{
#region Protected Fields
protected bool _changeCheckEnabled = true;
protected bool _changeCheckVisible = true;
protected bool _changeSelEnabled = true;
protected string _css;
protected SteamWare.tipoVistaMod _modo = SteamWare.tipoVistaMod.editing;
protected ObjectDataSource _ods;
protected string _where = "";
#endregion Protected Fields
#region Public Events
public event EventHandler eh_selValore;
#endregion Public Events
#region Protected Properties
protected string _showAll
{
get
{
return hfShowAll.Value; ;
}
set
{
hfShowAll.Value = value;
if (!string.IsNullOrEmpty(value))
{
traduciObj();
}
}
}
protected string _showFiltered
{
get
{
return hfShowFiltered.Value;
}
set
{
hfShowFiltered.Value = value;
if (!string.IsNullOrEmpty(value))
{
traduciObj();
}
}
}
protected string _valore
{
get
{
return memLayer.ML.StringSessionObj($"valFiltro_{this.UniqueID}".Replace("$", "_"));
}
set
{
memLayer.ML.setSessionVal($"valFiltro_{this.UniqueID}".Replace("$", "_"), value, false);
}
}
/// <summary>
/// calcola se ci sia in sessione il valore del filtro
/// </summary>
protected bool valueInSession
{
get
{
bool answ = false;
try
{
memLayer.ML.isInSessionObject($"valFiltro_{this.UniqueID}".Replace("$", "_"));
}
catch
{ }
return answ;
}
}
#endregion Protected Properties
#region Public Properties
/// <summary>
/// determina se sia possibile (de)selezionare il check di filtraggio, altrimenti sempre attivo
/// </summary>
public bool changeCheckEnabled
{
get
{
return _changeCheckEnabled;
}
set
{
_changeCheckEnabled = value;
updateChk();
}
}
/// <summary>
/// determina se sia possibile visibile il check di filtraggio
/// </summary>
public bool changeCheckVisible
{
get
{
return _changeCheckVisible;
}
set
{
_changeCheckVisible = value;
updateChkLbl();
}
}
/// <summary>
/// determina se sia possibile modificare la selezione
/// </summary>
public bool changeSelEnabled
{
get
{
return _changeSelEnabled;
}
set
{
_changeSelEnabled = value;
updateSel();
}
}
/// <summary>
/// get/set per la larghezza della combo dropdown
/// </summary>
public int comboWidth
{
get
{
return Convert.ToInt32(dlFilt.Width);
}
set
{
dlFilt.Width = value;
}
}
/// <summary>
/// condizione where per ridurre elementi mostrati in selettore
/// </summary>
public string condizione
{
get
{
return _where;
}
set
{
_where = value;
}
}
/// <summary>
/// css applicato agli elementi del controllo
/// </summary>
public string css
{
get
{
return _css;
}
set
{
_css = value;
}
}
/// <summary>
/// get/set messaggio di attivazione filtraggio
/// </summary>
public string filterCheckText
{
get
{
return _showFiltered;
}
set
{
_showFiltered = value;
}
}
/// <summary>
/// get/set messaggio di disattivazione filtraggio
/// </summary>
public string filterUnchekText
{
get
{
return _showAll;
}
set
{
_showAll = value;
}
}
/// <summary>
/// get/set della checkbox
/// </summary>
public bool isChecked
{
get
{
return chkFilt.Checked;
}
set
{
chkFilt.Checked = value;
dlFilt.Visible = value;
updateChkLbl();
}
}
/// <summary>
/// oggetto ODS con cui popolare il selettore, VINCOLO abbia campi value(key) / label
/// </summary>
public ObjectDataSource ods
{
get
{
return _ods;
}
set
{
_ods = value;
fixValore();
}
}
/// <summary>
/// primo valore di una chiave multicampo
/// </summary>
public string val_1
{
get
{
string answ = "";
if (chkFilt.Checked)
{
try
{
string[] _dataKey = dlFilt.SelectedValue.Split('#');
answ = _dataKey[0];
}
catch
{ }
}
else
{
answ = "*";
}
return answ;
}
}
/// <summary>
/// secondo valore di una chiave multicampo
/// </summary>
public string val_2
{
get
{
string answ = "";
if (chkFilt.Checked)
{
try
{
string[] _dataKey = dlFilt.SelectedValue.Split('#');
answ = _dataKey[1];
}
catch
{ }
}
else
{
answ = "*";
}
return answ;
}
}
/// <summary>
/// fornisce il valore scelto o "*" se nulla selezionato
/// </summary>
public string valore
{
get
{
string answ = "*";
if (chkFilt.Checked)
{
answ = dlFilt.SelectedValue;
}
return answ;
}
set
{
_valore = value;
traduciObj();
}
}
/// <summary>
/// fornisce il valore scelto o "0" se nulla selezionato o non valido
/// </summary>
public int valoreInt
{
get
{
int answ = -1;
try
{
if (chkFilt.Checked)
{
answ = Convert.ToInt32(dlFilt.SelectedValue);
}
}
catch
{ }
return answ;
}
}
#endregion Public Properties
#region Protected Methods
protected override void bindControlli()
{
updateChk();
fixValore();
where.Text = _where;
traduciObj();
}
protected void chkFilt_CheckedChanged(object sender, EventArgs e)
{
// cambio modalità visualizzazione del filtro...
dlFilt.Visible = !dlFilt.Visible;
raiseSelEvent();
}
protected void dlFilt_SelectedIndexChanged(object sender, EventArgs e)
{
raiseSelEvent();
}
/// <summary>
/// sistema visualizzazione
/// </summary>
protected void fixValore()
{
if (_ods != null)
{
try
{
dlFilt.DataSource = _ods;
dlFilt.DataBind();
if (string.IsNullOrEmpty(_valore))
{
if (dlFilt.Items.Count > 0)
{
dlFilt.SelectedIndex = 0;
}
}
else
{
if (dlFilt.Items.Count > 0)
{
dlFilt.SelectedValue = _valore;
dlFilt.Visible = true;
chkFilt.Checked = true;
}
}
}
catch (Exception exc)
{
logger.lg.scriviLog($"Eccezione:{Environment.NewLine}{exc}", tipoLog.EXCEPTION);
_valore = "";
if (dlFilt.Items.Count > 0)
{
dlFilt.SelectedIndex = 0;
}
}
}
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (!Page.IsPostBack)
{
if (string.IsNullOrEmpty(_showFiltered)) _showFiltered = "mostraSoloSelez";
if (string.IsNullOrEmpty(_showAll)) _showAll = "mostraTutti";
}
}
protected void raiseSelEvent()
{
if (!dlFilt.Visible)
{
memLayer.ML.setSessionVal($"valFiltro_{this.UniqueID}".Replace("$", "_"), "", false);
}
else
{
_valore = dlFilt.SelectedValue;
}
if (eh_selValore != null)
{
eh_selValore(this, new EventArgs());
}
}
/// <summary>
/// traduzione oggetti
/// </summary>
protected override void traduciObj()
{
if (_changeCheckVisible)
{
if (!chkFilt.Checked)
{
if (!string.IsNullOrEmpty(_showFiltered))
{
chkFilt.Text = traduci(_showFiltered);
}
}
else
{
if (!string.IsNullOrEmpty(_showAll))
{
chkFilt.Text = traduci(_showAll);
}
}
}
}
protected void updateChk()
{
chkFilt.Enabled = _changeCheckEnabled;
if (!_changeCheckEnabled)
{
chkFilt.Checked = true;
dlFilt.Visible = true;
}
}
protected void updateChkLbl()
{
chkFilt.Visible = _changeCheckVisible;
}
protected void updateSel()
{
dlFilt.Enabled = _changeSelEnabled;
}
#endregion Protected Methods
#region Public Methods
/// <summary>
/// resetta e seleziona primo valore
/// </summary>
public void reselFirst()
{
try
{
dlFilt.DataBind();
bindControlli();
dlFilt.SelectedIndex = 0;
}
catch (Exception exc)
{
logger.lg.scriviLog($"Eccezione:{Environment.NewLine}{exc}", tipoLog.EXCEPTION);
}
}
/// <summary>
/// resetta il controllo (un-checked)
/// </summary>
public void reset()
{
chkFilt.Checked = false;
dlFilt.Visible = false;
memLayer.ML.emptySessionVal($"valFiltro_{this.UniqueID}".Replace("$", "_"));
}
#endregion Public Methods
}