using SteamWare; using System; using System.Linq; using System.Web.UI; namespace WebLCP.WUC { public partial class cmp_header : System.Web.UI.UserControl { public event EventHandler eh_doRefresh; protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { showSearch = false; searchVal = ""; ulLinks.DataBind(); hlReset.DataBind(); hlLogin.DataBind(); checkAuth(); } } protected string safePages { get { string answ = ""; try { answ = $"{memLayer.ML.confReadString("_safePages")}#{memLayer.ML.confReadString("_loginPages")}"; } catch { } return answ; } } private void checkAuth() { string lastPage = Request.Url.LocalPath.Split('/').Last(); // se l'utente NON c'è torno a login... if (!userIsAuth) { if (lastPage != "" && lastPage != "login") { Session["nextPage"] = lastPage; } // SE non sono in "safe page" if (safePages.ToLower().IndexOf(lastPage.ToLower()) < 0) { Response.Redirect("~/login"); } } else { PagCorrente(); } } /// /// Indica se user sia autorizzato /// public bool userIsAuth { get { return devicesAuthProxy.stObj.isAuth; } } /// /// salva in variabile pagina il nome della pagina corrente /// protected void PagCorrente() { string[] uri = Request.Url.LocalPath.Split('/'); // salvo pagina corrente devicesAuthProxy.pagCorrente = uri.Last(); if (devicesAuthProxy.pagPrecedente == "") { devicesAuthProxy.pagPrecedente = devicesAuthProxy.pagCorrente; } } /// /// imposta visibilità search globale /// 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 (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()); } } /// /// Valore ricerca attivo /// protected string searchVal { get { return txtSearch.Text.Trim(); } set { txtSearch.Text = value.Trim(); } } protected void lbtSearch_Click(object sender, EventArgs e) { doSearch(); } public string checkPage(string tgtName) { string answ = ""; if (titolo == tgtName) { answ = "active"; } return answ; } /// /// titolo pagina /// public string titolo { get { return devicesAuthProxy.getPage(Request.Url).Replace(".aspx", ""); } } /// /// restituisce il nome della pagina corrente /// public static string getPage(Uri MyUrl) { string answ = ""; try { answ = MyUrl.LocalPath.Split('/').Last(); } catch (Exception exc) { logger.lg.scriviLog(exc.ToString(), tipoLog.EXCEPTION); } return answ; } } }