自己构造公共程序(4)--BS菜单对象
using System;
using System.Text;
using System.Collections;
namespace ISDMenu
{
/// <summary>
/// ISDMenuObject 的摘要说明。
/// </summary>
public class ISDMenuObject
{
public ISDMenuObject()
{
//
// TODO: 在此处添加构造函数逻辑
//
allMenu = new ArrayList();
}
/// <summary>
/// 主菜单有多少项
/// </summary>
private int i_mainMenuItemNumber=0;
/// <summary>
/// 存储菜单的值
/// </summary>
private ArrayList allMenu = new ArrayList();
#region 属性
/// <summary>
/// 功能: 设置或者返回主菜单有多少项
/// </summary>
public int MainMenuItemNumber
{
get
{
return this.i_mainMenuItemNumber;
}
set
{
this.i_mainMenuItemNumber = value;
}
}
#endregion
#region 方法
/// <summary>
/// 功能: 添加主菜单项目
/// 创建人: Applegreen
/// 更新时间: 2004-8-19
/// </summary>
/// <param name="MainItemName">主菜单的名称</param>
/// <param name="SubItemDisplayValue">主菜单的名称</param>
public void addItem(string MainItemName,
string MainItemDisplayValue)
{
MainItem mi = new MainItem(MainItemName.Trim(),MainItemDisplayValue);
allMenu.Add(mi);
}
/// <summary>
/// 功能: 添加子菜单
/// 创建人: Applegreen
/// 更新时间: 2004-8-19
/// </summary>
/// <param name="MainItemName">父菜单的名称</param>
/// <param name="SubItemDisplayName">菜单的显示名称</param>
/// <param name="UrlStr">URL路径</param>
/// <param name="targetName">目标地址</param>
/// <param name="Visable">是否可见</param>
public void addSubItem(string MainItemName,
string SubItemDisplayName,
string UrlStr,
string targetName,
bool Visable)
{
for(int i = 0;i<allMenu.Count;i++){
MainItem mi = (MainItem)allMenu[i];
if(mi.getMainItemID()==MainItemName){
SubItem si = new SubItem(MainItemName,SubItemDisplayName,UrlStr,targetName,Visable);
mi.AddItem(si);
}
}
}
/// <summary>
/// 功能: 返回创造菜单html语句
/// 创建人: Applegreen
/// 更新时间: 2004-8-19
/// </summary>
/// <returns>返回htmll语句</returns>
public string getScript()
{
StringBuilder sb = new StringBuilder();
sb.Append("<script type='text/javascript'> \n")
.Append(" document.onclick = function() \n")
.Append(" { \n")
.Append(" if (parent.hideAllMenuScriptlets) \n")
.Append(" parent.hideAllMenuScriptlets(); \n")
.Append(" } \n")
.Append("</script>\n")
.Append("<script type='text/javascript'>\n")
.Append(" var currentSkinHref;\n")
.Append(" if (document.location.search == \"\")\n")
.Append(" currentSkinHref = 'css/main-menu.css';\n")
.Append(" else\n")
.Append(" currentSkinHref = document.location.search.substr(1);\n")
.Append( "document.write('<link type=\"text/css\" rel=\"stylesheet\" href=' + currentSkinHref + ' id=\"menuStyleSheet\">')\n")
//.Append(" document.write('<link type='text/css' rel='stylesheet' href=' + currentSkinHref + ' id='menuStyleSheet'>')\n")
.Append("</script>")
.Append("<script type='text/javascript' src='menu3.js'></script>\n")
.Append("<script type='text/javascript'>\n")
.Append(" function f_test(s)\n")
.Append(" {\n")
.Append("alert(s);\n")
.Append(" }\n")
.Append(" </script>\n")
.Append(" <base target='insFrame'>\n")
.Append(" <table class='menuBarTbl' cellSpacing='0' cellPadding='0' border='0'><tr><td>\n")
.Append(" <div id='menuBar'>\n")
.Append(" <table class='menuBar'align='center' onmouseover='menuBarOver()' onmouseout='menuBarOut()' onclick='menuBarClick()'\n")
.Append(" cellspacing='0' cellpadding='0' border='0' >\n")
.Append(" <tr>\n");
//添加主菜单
for(int i=0;i<allMenu.Count;i++){
MainItem mi = (MainItem) allMenu[i];
sb.Append(" <td align='left'>\n")
.Append(" <table cellspacing='0' cellpadding='0' class='root' menu='"+mi.getMainItemID()+"'>\n")
.Append(" <tr>\n")
.Append(" <td class='left'></td>\n")
.Append(" <td class='middle' nowrap>"+mi.getMainItemDisplayValue()+"</td>\n")
.Append(" <td class='right'></td>\n")
.Append(" </tr>\n")
.Append(" </table>\n")
.Append(" </td>\n");
}
sb.Append(" </tr></table></div>\n");
//添加子菜单
for(int i=0;i<allMenu.Count;i++)
{
MainItem mi = (MainItem) allMenu[i];
ArrayList subitems = mi.getSubItemList();
sb.Append(" <table id='"+mi.getMainItemID()+"' class='menu' cellspacing='0'>\n");
for(int j = 0 ;j<subitems.Count;j++)
{
SubItem si = (SubItem)subitems[j];
if(si.getVisable())
{
sb.Append(" <tr href='"+si.getUrlStr()+"' target='"+si.gettargetName()+"'>\n")
.Append(" <td class='left'> </td>\n")
.Append(" <td class='middle' nowrap>"+si.getSubItemDisplayName()+"</td>\n")
.Append(" <td class='right'> </td>\n")
.Append(" </tr>\n");
}
}
sb.Append(" </table>\n");
sb.Append(" </table></tr></td>\n");
}
return sb.ToString();
}
#endregion
}
/// <summary>
/// 主菜单对象
/// </summary>
public class MainItem
{
/// <summary>
/// 主菜单名
/// </summary>
private string MainItemName;
/// <summary>
/// 主菜单显示名称
/// </summary>
private string MainItemDisplayValue;
/// <summary>
/// 子菜单集合
/// </summary>
private ArrayList SubItemList = new ArrayList();
/// <summary>
/// 功能: 构造缺省菜单
/// 创建人: Applegreen
/// 更新时间: 2004-8-20
/// </summary>
public MainItem()
{
this.MainItemName = string.Empty;
this.MainItemDisplayValue = string.Empty;
}
/// <summary>
/// 功能: 得到主菜单名
/// 创建人: Applegreen
/// 更新时间: 2004-8-20
/// </summary>
/// <returns>主菜单名的字符串</returns>
public string getMainItemID()
{
return this.MainItemName;
}
/// <summary>
/// 功能: 得到主菜单显示名
/// 创建人: Applegreen
/// 更新时间: 2004-8-20
/// </summary>
/// <returns>主菜单的显示名称的字符串</returns>
public string getMainItemDisplayValue()
{
return this.MainItemDisplayValue;
}
/// <summary>
/// 功能: 得到子菜单的对象的ArrayList集合
/// 创建人: Applegreen
/// 更新时间: 2004-8-20
/// </summary>
/// <returns>子菜单的对象的ArrayList集合</returns>
public ArrayList getSubItemList()
{
return this.SubItemList;
}
/// <summary>
/// 功能: 构造自定义的主菜单
/// 创建人: Applegreen
/// 更新时间: 2004-8-20
/// </summary>
/// <param name="s_MainItemName">主菜单名</param>
/// <param name="s_MainItemDisplayValue">主菜单的显示名称</param>
public MainItem(string s_MainItemName,
string s_MainItemDisplayValue)
{
this.MainItemName =s_MainItemName;
this.MainItemDisplayValue = s_MainItemDisplayValue;
}
/// <summary>
/// 功能: 添加子菜单
/// 创建人: Applegreen
/// 更新时间: 2004-8-20
/// </summary>
/// <param name="si">子菜单对象</param>
/// <returns></returns>
public bool AddItem(SubItem si)
{
if(si.getFatherName()==this.MainItemName)
{
this.SubItemList.Add(si);
return true;
}
else
{
return false;
}
}
}
/// <summary>
/// 子菜单对象
/// </summary>
public class SubItem
{
/// <summary>
/// 父菜单名
/// </summary>
private string MainItemName;
/// <summary>
/// 菜单名称
/// </summary>
private string SubItemDisplayName;
/// <summary>
/// 菜单链接地址
/// </summary>
private string UrlStr;
/// <summary>
/// 菜单目标帧
/// </summary>
private string targetName;
/// <summary>
/// 菜单可见属性
/// </summary>
private bool Visable;
/// <summary>
/// 功能: 得到父菜单名
/// 创建人: Applegreen
/// 更新时间: 2004-8-20
/// </summary>
/// <returns>父菜单名的字符串</returns>
public string getFatherName()
{
return this.MainItemName;
}
/// <summary>
/// 功能: 得到子菜单的显示名称
/// 创建人: Applegreen
/// 更新时间: 2004-8-20
/// </summary>
/// <returns>子菜单的显示名称</returns>
public string getSubItemDisplayName()
{
return this.SubItemDisplayName;
}
/// <summary>
/// 功能: 得到子菜单的链接地址
/// 创建人: Applegreen
/// 更新时间: 2004-8-20
/// </summary>
/// <returns>子菜单的链接地址的字符串</returns>
public string getUrlStr()
{
return this.UrlStr;
}
/// <summary>
/// 功能: 得到菜单的目标帧
/// 创建人: Applegreen
/// 更新时间: 2004-8-20
/// </summary>
/// <returns>菜单的目标帧的字符串</returns>
public string gettargetName()
{
return this.targetName;
}
/// <summary>
/// 功能: 得到菜单的可见属性
/// 创建人: Applegreen
/// 更新时间: 2004-8-20
/// </summary>
/// <returns></returns>
public bool getVisable()
{
return this.Visable;
}
/// <summary>
/// 功能: 构造缺省菜单
/// 创建人: Applegreen
/// 更新时间: 2004-8-20
/// </summary>
public SubItem()
{
this.MainItemName = string.Empty;
this.SubItemDisplayName = string.Empty;
this.UrlStr = string.Empty;
this.targetName = string.Empty;
this.Visable = false;
}
/// <summary>
/// 功能: 构造自定义菜单
/// 创建人: Applegreen
/// 更新时间: 2004-8-20
/// </summary>
/// <param name="s_MainItemName">父菜单名</param>
/// <param name="s_SubItemDisplayName">菜单的显示名称</param>
/// <param name="s_UrlStr">菜单的链接地址</param>
/// <param name="s_targetName">菜单的目标帧</param>
/// <param name="b_Visable">菜单可见属性</param>
public SubItem(string s_MainItemName,
string s_SubItemDisplayName,
string s_UrlStr,
string s_targetName,
bool b_Visable)
{
this.MainItemName = s_MainItemName;
this.SubItemDisplayName = s_SubItemDisplayName;
this.UrlStr = s_UrlStr;
this.targetName = s_targetName;
this.Visable = b_Visable;
}
}
}