namespace LinkBars {
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
public class NavBar : System.Web.UI.WebControls.WebControl {
private ArrayList alTextUrlPairs = null;
private string strSeperator = ">";
private int iRPad = 2;
private int iLPad = 1;
private int iCutOff = 99999;
private Color clrForeColor = Color.Black;
private Color clrLinkColor = Color.Blue;
private Color clrSeperatorColor = Color.Black;
private string strCategoryLink = "", strCategoryName = "";
public ArrayList Urls {
get {
return alTextUrlPairs;
}
set {
alTextUrlPairs = value;
}
}
public string Seperator {
get {
return strSeperator;
}
set {
strSeperator = value;
}
}
public int LPad {
get {
return iLPad;
}
set {
}
}
public int RPad {
get {
return iRPad;
}
set {
}
}
public override Color ForeColor {
get {
return clrForeColor;
}
set {
clrForeColor = value;
}
}
public Color LinkColor {
get {
return clrLinkColor;
}
set {
clrLinkColor = value;
}
}
public Color SeperatorColor {
get {
return clrSeperatorColor;
}
set {
clrSeperatorColor = value;
}
}
public string CategoryName {
get {
return strCategoryName;
}
set {
strCategoryName = value;
}
}
public string CategoryLink {
get {
return strCategoryLink;
}
set {
strCategoryLink = value;
}
}
public string strRPad {
get {
string strRPad = String.Empty;
for (int i = 0; i < iRPad; i++)
{
strRPad += " ";
}
return strRPad;
}
}
public string strLPad {
get {
string strLPad = String.Empty;
for (int i = 0; i < iLPad; i++)
{
strLPad += " ";
}
return strLPad;
}
}
public Label lblSeperator {
get {
Label lblSeperator;
lblSeperator = new Label();
lblSeperator.Text = strLPad + strSeperator + strRPad;
lblSeperator.ForeColor = Color.Black;
lblSeperator.Font.Name = "Verdana";
lblSeperator.Font.Size = FontUnit.Point(8);
return lblSeperator;
}
}
protected override void CreateChildControls() {
HyperLink hl;
hl = new HyperLink();
hl.Text = "Home";
hl.NavigateUrl = "/";
hl.ForeColor = Color.FromArgb(5,5,192);
hl.Font.Name = "Verdana";
hl.Font.Size = FontUnit.Point(8);
Controls.Add(hl);
string[] aPath = Page.Request.Url.AbsolutePath.Split(new Char[] {'/'});
int cntPath = aPath.Length;
int iSchoolID = -1;
if (HttpContext.Current.Request.Params["school_id"] != null)
{
Controls.Add(lblSeperator);
hl = new HyperLink();
hl.Text = "Universities";
hl.ForeColor = Color.FromArgb(5,5,192);
hl.Font.Name = "Verdana";
hl.Font.Size = FontUnit.Point(8);
Controls.Add(hl);
Controls.Add(lblSeperator);
hl = new HyperLink();
hl.Text = DH_Schools.DH_SchoolsDB.GetSchoolNameFromID(Convert.ToInt32(HttpContext.Current.Request.Params["school_id"]));
hl.NavigateUrl = DH_Schools.DH_SchoolsDB.GetSchoolUrlFromID(Convert.ToInt32(HttpContext.Current.Request.Params["school_id"]));
hl.ForeColor = Color.FromArgb(5,5,192);
hl.Font.Name = "Verdana";
hl.Font.Size = FontUnit.Point(8);
Controls.Add(hl);
}
else if (aPath[cntPath-1] == "school_categories.aspx")
{
Controls.Add(lblSeperator);
hl = new HyperLink();
hl.Text = "Universities";
hl.ForeColor = Color.FromArgb(5,5,192);
hl.Font.Name = "Verdana";
hl.Font.Size = FontUnit.Point(8);
Controls.Add(hl);
Controls.Add(lblSeperator);
hl = new HyperLink();
iSchoolID = DH_Users.DH_UserDB.GetSchoolIDFromUserID(HttpContext.Current.User.Identity.Name);
hl.Text = DH_Schools.DH_SchoolsDB.GetSchoolNameFromID(iSchoolID);
hl.NavigateUrl = DH_Schools.DH_SchoolsDB.GetSchoolUrlFromID(iSchoolID);
hl.ForeColor = Color.FromArgb(5,5,192);
hl.Font.Name = "Verdana";
hl.Font.Size = FontUnit.Point(8);
Controls.Add(hl);
}
string strLinkText = "";
string strCompleteUrl = "";
for (int i=1;i < cntPath-1; i++) {
Controls.Add(lblSeperator);
hl = new HyperLink();
strLinkText = aPath[i];
hl.Text = Char.ToUpper(strLinkText[0]) + strLinkText.Substring(1).ToLower();
strCompleteUrl += "/"+aPath[i].ToString();
hl.NavigateUrl = strCompleteUrl;
if ((HttpContext.Current.Request.Params["school_id"] != null ||
aPath[cntPath-1] == "school_categories.aspx") &&
hl.Text == "Messages") {
hl.NavigateUrl = "/messages/school_categories.aspx";
}
hl.ForeColor = Color.FromArgb(5,5,192);
hl.Font.Name = "Verdana";
hl.Font.Size = FontUnit.Point(8);
Controls.Add(hl);
}
if (strCategoryName != String.Empty) {
Controls.Add(lblSeperator);
hl = new HyperLink();
hl.Text = strCategoryName;
hl.NavigateUrl = strCategoryLink;
hl.ForeColor = Color.FromArgb(5,5,192);
hl.Font.Name = "Verdana";
hl.Font.Size = FontUnit.Point(8);
Controls.Add(hl);
}
Controls.Add(lblSeperator);
Label lblTitle = new Label();
if (Convert.ToString(Page.FindControl("page_title")) != String.Empty) {
lblTitle.Text = ((HtmlGenericControl)Page.FindControl("page_title")).InnerText;
}
else {
lblTitle.Text = aPath[cntPath-1].ToString();
}
if (lblTitle.Text.Length > iCutOff) {
lblTitle.Text = lblTitle.Text.Substring(0, iCutOff) + "...";
}
lblTitle.ForeColor = Color.Black;
lblTitle.Font.Name = "Verdana";
lblTitle.Font.Size = FontUnit.Point(8);
lblTitle.Font.Bold = true;
Controls.Add(lblTitle);
}
}
}
|