Skip Navigation Links.

Northwind\WebControls\SessionManagerBase.cs

D:\NorthwindForWeb\Northwind\CS\DotNet\ADO.Net\Northwind\WebControls\SessionManagerBase.cs
/*
 * This file was generated by ProCG version 2.0
 *
 * File name:	Northwind\WebControls\SessionManagerBase.cs
 * Language:	C# - ADO.Net 
 * Database:	My Sql
 *
 * Copyright (c) 2002-2019 iGenXSoft.
 * For more information visit http://www.igenxsoft.com
 */


using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using Northwind.General;
using Northwind.Data;
using System.Web.SessionState;
using log4net;

namespace Northwind.WebControls
{
	public class SessionManagerBase
	{
		private static readonly ILog log = LogManager.GetLogger(typeof(SessionManagerBase));

		static public void CreateNewSession()
		{
			SessionIDManager Manager = new SessionIDManager();
			string NewID = Manager.CreateSessionID(HttpContext.Current);
			string OldID = HttpContext.Current.Session.SessionID;
			bool redirected = false;
			bool IsAdded = false;
			//Manager.RemoveSessionID(HttpContext.Current);
			
			Manager.SaveSessionID(HttpContext.Current, NewID, out redirected, out IsAdded);
			//HttpContext.Current.Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", NewID));
		}

		static public CNorthwindUser User
		{
			get
			{
				if (HttpContext.Current != null)
				{
					if (HttpContext.Current.Session["User"] != null)
						return (CNorthwindUser)HttpContext.Current.Session["User"];

					if (HttpContext.Current.Request.Url.ToString().IndexOf("Login.aspx") == -1)
						HttpContext.Current.Session["NextURL"] = HttpContext.Current.Request.Url.ToString();
					HttpContext.Current.Response.Redirect(NorthwindGeneral.GetLoginPage(), true);
					return null;
				}
				return null;
			}
			set
			{
				if (value == null)
				{
					if (HttpContext.Current.Session["User"] != null)
						HttpContext.Current.Session.Remove("User");
				}
				else
					HttpContext.Current.Session["User"] = value;
			}
		}

		static public bool UserExist
		{
			get
			{

				if (HttpContext.Current != null && HttpContext.Current.Session["User"] != null)
					return true;
				return false;
			}
		}

		static public HttpSessionState Session
		{
			get { return HttpContext.Current.Session; }
		}

		static public string TabControlTheme
		{
			get
			{
				if (HttpContext.Current.Session["TabControlTheme"] != null)
					return (string)HttpContext.Current.Session["TabControlTheme"];
				return "ajax__tab_yuitabview-theme";
			}
			set
			{
				HttpContext.Current.Session["TabControlTheme"] = value;
			}
		}

		static public  void GetFromSession(string symbolName, ref int symbolValue, int defaultValue)
		{
			if (HttpContext.Current.Session[symbolName] != null)
			{
				symbolValue = Convert.ToInt32(HttpContext.Current.Session[symbolName].ToString());
			}
			else
			{
				symbolValue = defaultValue;
			}
		}

		static public  int SetToSession(string symbolName, int symbolValue)
		{
			HttpContext.Current.Session[symbolName] = symbolValue;
			return (symbolValue);
		}

		static public  void GetFromSession(string symbolName, ref bool symbolValue, bool defaultValue)
		{
			if (HttpContext.Current.Session[symbolName] != null)
			{
				symbolValue = Convert.ToBoolean(HttpContext.Current.Session[symbolName].ToString());
			}
			else
			{
				symbolValue = defaultValue;
			}
		}

		static public  bool SetToSession(string symbolName, bool symbolValue)
		{
			HttpContext.Current.Session[symbolName] = symbolValue;
			return (symbolValue);
		}

		static public void GetFromSession(string symbolName, ref string symbolValue, string defaultValue)
		{
			if (HttpContext.Current.Session[symbolName] != null)
			{
				symbolValue = (string)HttpContext.Current.Session[symbolName];
			}
			else
			{
				symbolValue = defaultValue;
			}
		}

		static public string SetToSession(string symbolName, string symbolValue)
		{
			HttpContext.Current.Session[symbolName] = symbolValue;
			return (symbolValue);
		}

		static public int ActiveMainMenuId
		{
			get
			{
				if (HttpContext.Current.Session["ActiveMainMenuId"] != null)
					return (int)HttpContext.Current.Session["ActiveMainMenuId"];
				return 0;
			}
			set
			{
				HttpContext.Current.Session["ActiveMainMenuId"] = value;
			}
		}

		static public int ActiveSubMenuId
		{
			get
			{
				if (HttpContext.Current.Session["ActiveSubMenuId"] != null)
					return (int)HttpContext.Current.Session["ActiveSubMenuId"];
				return 0;
			}
			set
			{
				HttpContext.Current.Session["ActiveSubMenuId"] = value;
			}
		}

		static public  void ClearAll()
		{
			if (HttpContext.Current != null)
			{
				HttpContext.Current.Session.Clear();
			}
		}

		static public LastValuesManager LastValuesManager
		{
			get
			{
				if (HttpContext.Current.Session["LastValuesManager"] != null)
					return (LastValuesManager)HttpContext.Current.Session["LastValuesManager"];
				if (UserExist)
				{
					LastValuesManager lastValueManager = new LastValuesManager(User.Id);
					HttpContext.Current.Session["LastValuesManager"] = lastValueManager;
					return lastValueManager;
				}
				return null;
			}
			set
			{
				HttpContext.Current.Session["LastValuesManager"] = value;
			}
		}

	}
}



  //      5334 ProCG uses this line - don't edit it