266 lines
7.4 KiB
C#
266 lines
7.4 KiB
C#
using GPW_data;
|
|
using SteamWare;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace GPW_Admin
|
|
{
|
|
public class BaseUserControl : System.Web.UI.UserControl
|
|
{
|
|
#region Public Events
|
|
|
|
/// <summary>
|
|
/// Generico evento di richiesta AddNew
|
|
/// </summary>
|
|
public event EventHandler eh_addNew;
|
|
|
|
/// <summary>
|
|
/// Generico evento di richiesta refresh a parent
|
|
/// </summary>
|
|
public event EventHandler eh_doRefresh;
|
|
|
|
/// <summary>
|
|
/// Generico evento di richiesta refresh a parent
|
|
/// </summary>
|
|
public event EventHandler eh_doReset;
|
|
|
|
#endregion Public Events
|
|
|
|
#region Public Properties
|
|
|
|
/// <summary>
|
|
/// pagina corrente (URL finale)
|
|
/// </summary>
|
|
public string _paginaCorrente { get; set; }
|
|
|
|
/// <summary>
|
|
/// controllo stato licenze!
|
|
/// </summary>
|
|
public bool chkLicOk => doChkLicOk();
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Verifica se il valore sia > limitValue
|
|
/// </summary>
|
|
/// <param name="_valore"></param>
|
|
/// <param name="minVal"></param>
|
|
/// <param name="maxVal"></param>
|
|
/// <returns></returns>
|
|
public bool betweenVal(object _valore, double minVal, double maxVal)
|
|
{
|
|
bool answ = false;
|
|
if (_valore != null)
|
|
{
|
|
double valore = 0;
|
|
_ = double.TryParse(_valore.ToString(), out valore);
|
|
answ = valore <= maxVal && valore >= minVal;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifica se il valore sia > limitValue
|
|
/// </summary>
|
|
/// <param name="_valore"></param>
|
|
/// <param name="maxVal"></param>
|
|
/// <returns></returns>
|
|
public bool gtVal(object _valore, double maxVal)
|
|
{
|
|
bool answ = false;
|
|
if (_valore != null)
|
|
{
|
|
double valore = 0;
|
|
_ = double.TryParse(_valore.ToString(), out valore);
|
|
answ = valore > maxVal;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifica se il valore sia > 0
|
|
/// </summary>
|
|
/// <param name="_valore"></param>
|
|
/// <returns></returns>
|
|
public bool gtZero(object _valore)
|
|
{
|
|
bool answ = false;
|
|
if (_valore != null)
|
|
{
|
|
decimal valore = 0;
|
|
_ = decimal.TryParse(_valore.ToString(), out valore);
|
|
answ = valore > 0;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// risponde alla domanda se l'utente abbia permesso tipo writable (S) nel permessi2funzione
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool isWritable()
|
|
{
|
|
bool answ = false;
|
|
if (_paginaCorrente == null)
|
|
{
|
|
PagCorrente();
|
|
}
|
|
answ = user_std.UtSn.isPageWriteEnabled(_paginaCorrente) && chkLicOk;
|
|
return answ;
|
|
}
|
|
|
|
/// <summary> Verifica se il valore sia < minVal </summary> <param name="_valore"></param>
|
|
/// <param name="minVal"></param> <returns></returns>
|
|
public bool ltVal(object _valore, double minVal)
|
|
{
|
|
bool answ = false;
|
|
if (_valore != null)
|
|
{
|
|
double valore = 0;
|
|
_ = double.TryParse(_valore.ToString(), out valore);
|
|
answ = valore < minVal;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Chiamata evento add New
|
|
/// </summary>
|
|
public void raiseAddNew()
|
|
{
|
|
// se qualcuno ascolta sollevo evento nuovo valore...
|
|
if (eh_addNew != null)
|
|
{
|
|
eh_addNew(this, new EventArgs());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Chiamata evento
|
|
/// </summary>
|
|
public void raiseEvent()
|
|
{
|
|
// se qualcuno ascolta sollevo evento nuovo valore...
|
|
if (eh_doRefresh != null)
|
|
{
|
|
eh_doRefresh(this, new EventArgs());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Chiamata evento
|
|
/// </summary>
|
|
public void raiseReset()
|
|
{
|
|
// se qualcuno ascolta sollevo evento nuovo valore...
|
|
if (eh_doReset != null)
|
|
{
|
|
eh_doReset(this, new EventArgs());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// converte valore in booleano
|
|
/// </summary>
|
|
/// <param name="valore"></param>
|
|
/// <returns></returns>
|
|
public bool toBool(object valore)
|
|
{
|
|
bool answ = false;
|
|
string strVal = $"{valore}";
|
|
// se è lungh 1 (0/1) converto 0=false, 1 = true...
|
|
if (strVal.Length == 1)
|
|
{
|
|
answ = strVal == "1" ? true : false;
|
|
}
|
|
else
|
|
{
|
|
// se è un valore testuale --> converisone boolean
|
|
bool.TryParse($"{valore}", out answ);
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// effettua traduzione del lemma
|
|
/// </summary>
|
|
/// <param name="lemma"></param>
|
|
/// <returns></returns>
|
|
public string traduci(string lemma)
|
|
{
|
|
return user_std.UtSn.Traduci(lemma);
|
|
}
|
|
|
|
/// <summary>
|
|
/// wrapper traduzione
|
|
/// </summary>
|
|
/// <param name="lemma"></param>
|
|
/// <returns></returns>
|
|
public string traduci(object lemma)
|
|
{
|
|
string answ = "";
|
|
if (lemma != null)
|
|
answ = traduci(lemma.ToString());
|
|
return answ;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
protected DS_Applicazione.DipendentiDataTable listaDip { get; set; }
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Calcola email del responsabile dato idx
|
|
/// </summary>
|
|
/// <param name="idxResp"></param>
|
|
/// <returns></returns>
|
|
protected string emailResp(int idxResp)
|
|
{
|
|
string answ = "";
|
|
// recupero email resp...
|
|
if (idxResp > 0)
|
|
{
|
|
var recResp = listaDip.FirstOrDefault(x => x.idxDipendente == idxResp);
|
|
if (recResp != null)
|
|
{
|
|
answ = $"{recResp.email}";
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// salva in variabile pagina il nome della pagina corrente
|
|
/// </summary>
|
|
protected void PagCorrente()
|
|
{
|
|
Uri MyUrl = Request.Url;
|
|
string delimStr = "/";
|
|
char[] delimiter = delimStr.ToCharArray();
|
|
string[] finalUrl = MyUrl.LocalPath.ToString().Split(delimiter);
|
|
int n = finalUrl.Length;
|
|
_paginaCorrente = finalUrl[n - 1].ToString();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// controllo stato licenze!
|
|
/// </summary>
|
|
private bool doChkLicOk()
|
|
{
|
|
return (licenzeGPW.checkLicenze && licenzeGPW.checkPayload);
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |