236 lines
7.6 KiB
C#
236 lines
7.6 KiB
C#
using GPW_data;
|
|
using SteamWare;
|
|
using System;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
|
|
namespace GPW_Smart.WebUserControls
|
|
{
|
|
public partial class cmp_menuTop : System.Web.UI.UserControl
|
|
{
|
|
/// <summary>
|
|
/// user agent corrente
|
|
/// </summary>
|
|
protected string userAgent = "";
|
|
/// <summary>
|
|
/// IP corrente
|
|
/// </summary>
|
|
protected string postazione_IP = "";
|
|
/// <summary>
|
|
/// gestione evento refresh
|
|
/// </summary>
|
|
public event EventHandler eh_doRefresh;
|
|
protected bool _disableCheckCookie = false;
|
|
public bool disableCheckCookie
|
|
{
|
|
get
|
|
{
|
|
return _disableCheckCookie;
|
|
}
|
|
set
|
|
{
|
|
_disableCheckCookie = value;
|
|
}
|
|
}
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!Page.IsPostBack)
|
|
{
|
|
checkPages();
|
|
searchVal = "";
|
|
ulLinks.DataBind();
|
|
}
|
|
if (!disableCheckCookie)
|
|
{
|
|
// controllo se c'è utente in sessione.. SE NON disabilitato...
|
|
checkUser();
|
|
}
|
|
// sistemo visualizzazione
|
|
postazione_IP = Request.UserHostName;
|
|
try
|
|
{
|
|
lblSwData.Text = memLayer.ML.StringSessionObj("cognomeNome");
|
|
}
|
|
catch
|
|
{
|
|
lblSwData.Text = "GPW";
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Verifica le pagine x capire se siano cambiate...
|
|
/// </summary>
|
|
private void checkPages()
|
|
{
|
|
if (nomePagina != user_std.pagCorrente)
|
|
{
|
|
user_std.pagPrecedente = !string.IsNullOrEmpty(user_std.pagCorrente) ? user_std.pagCorrente : nomePagina;
|
|
user_std.pagCorrente = nomePagina;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Nome pagina (parte finale url)
|
|
/// </summary>
|
|
public string nomePagina
|
|
{
|
|
get
|
|
{
|
|
return devicesAuthProxy.getPage(Request.Url).Replace(".aspx", "");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// verifica presenza utente autorizzato in sessione
|
|
/// </summary>
|
|
private void checkUser()
|
|
{
|
|
if (!memLayer.ML.isInSessionObject("idxDipendente"))
|
|
{
|
|
// controllo cookie device...
|
|
checkAuthCookieGPW();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// verifica al presenza di un cookie VALIDO per autorizzare il device
|
|
/// </summary>
|
|
private void checkAuthCookieGPW()
|
|
{
|
|
try
|
|
{
|
|
HttpCookie cookie = Request.Cookies["AuthGPW"];
|
|
if (cookie == null || string.IsNullOrEmpty(cookie.Value))
|
|
{
|
|
// rimando pagina x registrazione devices
|
|
Response.Redirect("~/regNewDevice.aspx");
|
|
}
|
|
else
|
|
{
|
|
// ricavo utente da cookie...
|
|
string devSecret = cookie.Value;
|
|
DS_Applicazione.AnagDevicesRow device = null;
|
|
// cerco il device...ogni dipendente può averne + di 1 registrato a suo nome...
|
|
int idxDipendente = 0;
|
|
try
|
|
{
|
|
device = DataProxy.DP.taAnagDev.getByDeviceSecret(devSecret)[0];
|
|
idxDipendente = device.idxDipendente;
|
|
}
|
|
catch
|
|
{ }
|
|
if (idxDipendente > 0)
|
|
{
|
|
// aggiorno descrizione (user agent) ed IP...
|
|
userAgent = Request.UserAgent;
|
|
postazione_IP = Request.UserHostName;
|
|
// controllo IP e DeviceDescription x eventuale update
|
|
if ((device.lastIPv4 != postazione_IP) || (device.Description != userAgent))
|
|
{
|
|
// salvo ultimo "contatto" del device aggiornando descrizione ed IP
|
|
DataProxy.DP.taAnagDev.updateIP(device.IdxDevice, DateTime.Now, postazione_IP, userAgent);
|
|
}
|
|
// salvo in sessione utente
|
|
memLayer.ML.setSessionVal("idxDipendente", idxDipendente);
|
|
string CognomeNome = "";
|
|
string email = "";
|
|
string hashEmail = "";
|
|
try
|
|
{
|
|
DS_Applicazione.DipendentiRow rigaDip = DataProxy.DP.taDipendenti.getByIdx(idxDipendente)[0];
|
|
CognomeNome = string.Format("{0} {1}", rigaDip.Cognome, rigaDip.Nome);
|
|
email = rigaDip.email;
|
|
hashEmail = SteamCrypto.getHashStringMD5(email);
|
|
}
|
|
catch
|
|
{ }
|
|
memLayer.ML.setSessionVal("cognomeNome", CognomeNome);
|
|
memLayer.ML.setSessionVal("email", email);
|
|
memLayer.ML.setSessionVal("hashEmail", hashEmail);
|
|
}
|
|
else
|
|
{
|
|
// svuoto cookie...
|
|
memLayer.ML.emptyCookieVal("AuthGPW");
|
|
// rimando pagina x registrazione devices
|
|
Response.Redirect("~/regNewDevice.aspx");
|
|
}
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
logger.lg.scriviLog(string.Format("Errore in checkAuthCookie:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// imposta visibilità search globale
|
|
/// </summary>
|
|
public bool showSearch
|
|
{
|
|
get
|
|
{
|
|
return divSearch.Visible;
|
|
}
|
|
set
|
|
{
|
|
divSearch.Visible = value;
|
|
}
|
|
}
|
|
|
|
protected void txtSearch_TextChanged(object sender, EventArgs e)
|
|
{
|
|
doSearch();
|
|
}
|
|
|
|
private void doSearch()
|
|
{
|
|
// se searchVal !=""
|
|
if (!string.IsNullOrEmpty(searchVal))
|
|
{
|
|
memLayer.ML.setSessionVal("valoreSearch", searchVal);
|
|
}
|
|
else
|
|
{
|
|
memLayer.ML.emptySessionVal("valoreSearch");
|
|
}
|
|
// se qualcuno ascolta sollevo evento nuovo valore...
|
|
if (eh_doRefresh != null)
|
|
{
|
|
eh_doRefresh(this, new EventArgs());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Valore ricerca attivo
|
|
/// </summary>
|
|
protected string searchVal
|
|
{
|
|
get
|
|
{
|
|
return txtSearch.Text.Trim();
|
|
}
|
|
set
|
|
{
|
|
txtSearch.Text = value.Trim();
|
|
}
|
|
}
|
|
|
|
protected void lbtSearch_Click(object sender, EventArgs e)
|
|
{
|
|
doSearch();
|
|
}
|
|
/// <summary>
|
|
/// calcola SE aggiungere "active" alla pag corrente
|
|
/// </summary>
|
|
/// <param name="pageName"></param>
|
|
/// <returns></returns>
|
|
public string cssActive(string pageName)
|
|
{
|
|
string answ = "";
|
|
//if (pageName == PagCorrente())
|
|
if (pageName == nomePagina)
|
|
{
|
|
answ = "active";
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
} |