using System;
using System.Collections;
using System.Web;
using System.Text;
namespace DBWebControls.WebNavigator{
/// <summary>
/// Summary description for PageNavigator.
/// </summary>
public class PageNavigator : IDisposable
{
private Hashtable Pages = new Hashtable(2);
private static string l_SessionId = "DBControls.WebNavigator.PageNavigator";
public static string SessionID
{
get{return l_SessionId;}
}
public static PageNavigator GetNavigator(System.Web.UI.Page source)
{
return (PageNavigator)source.Session[SessionID];
}
public void AddPage(Type PageType, NavBasePageState page)
{
Pages.Add(PageType, page);
}
public void RemovePage(Type PageType)
{
Pages.Remove(PageType);
}
public void ClearPages()
{
Pages.Clear();
}
public NavBasePageState this[Type PageType]
{
get{return (NavBasePageState)Pages[PageType];}
}
public void RedirectToPage(System.Web.UI.Page source, Type PageType)
{
NavBasePageState page = this[PageType];
if(page != null)
{
PageNavigator oldnav = (PageNavigator)source.Session[SessionID];
if(oldnav != null && oldnav != this)
oldnav.Dispose();
source.Session[SessionID] = this;
source.Response.Redirect(source.ResolveUrl(page.PagePath));
}
else
throw new Exception("Page Navigator Exception Requested Page not found ");
}
public void RegisterOpenPopup(System.Web.UI.Page source, Type PageType
, int width, int height, bool toolbar, bool location
, bool scrollbars, bool resizable)
{
StringBuilder js_string = new StringBuilder(200);
NavBasePageState page = this[PageType];
int HalfWidth = width/2;
int halfHeigth = height/2;
js_string.Append("<script language=\"javascript\">\r\n");
js_string.Append("var pozx = window.screen.width/2 - " + HalfWidth.ToString() + ";\r\n");
js_string.Append("var pozy = window.screen.height/2 - " + halfHeigth.ToString() + ";\r\n");
js_string.Append("window.open('" + source.ResolveUrl(page.PagePath) + "','SelectList' ");
js_string.Append(",'top='+pozy+',left=' +pozx+',width=" + width.ToString());
js_string.Append(",height=" + height.ToString());
js_string.Append(",toolbar=" + (toolbar == true ? "yes": "no"));
js_string.Append(",location=" + (location == true ? "yes": "no"));
js_string.Append(",scrollbars=" + (scrollbars == true ? "yes": "no"));
js_string.Append(",resizable=" + (resizable == true ? "yes": "no"));
js_string.Append("');\r\n");
js_string.Append("</script>");
source.RegisterStartupScript("OpenSelectListWindow", js_string.ToString());
}
#region IDisposable Members
public void Dispose()
{
foreach(NavBasePageState page in Pages.Values)
page.Dispose();
Pages.Clear();
}
#endregion
}
}
|