一个动态菜单的例子(downmoon)


前台文件:

< SCRIPT language ="javascript" > ...

functionToggleVisible()
...{
$(arguments[
0]).toggle();
//alert($(arguments[1]).src);
if($(arguments[0]).style.display=="none")
...{
$(arguments[
1]).src="/images/toggle_gray_down.gif";
}

else
...{
$(arguments[
1]).src="/images/toggle_gray_up.gif";
}

}




</ SCRIPT >
< table width ="200"
border
="0" align ="center" cellPadding ="0" cellSpacing ="0" >

< asp:label id ="labMenuItem" runat ="server" ></ asp:label >

< tr >
< td height ="105" valign ="bottom" >< img src ="/images/favourable.gif" alt ="中国蔬菜网最新优惠消息" width ="200" height ="100" /></ td >
</ tr >


</ table >


后台文件:

using System;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data;
using System.Text.RegularExpressions;
using System.Text;
namespace Vegnet.User.Web.UI.Controls
{


/// <summary>
/// Menu的摘要说明。
/// </summary>
public class Menu:Vegnet.Common.Web.UI.Controls.BaseControl
{

#region Members
#region 菜单内容,

// Vip栏目标记
string _vipImage = " &nbsp;<imgsrc="/Images/Vip.gif"> " ;

// 其实不应加在这里,应在公用组件里,
// 此处应用Static变量,待改!! 
// downmoon2006-12-11

#region 显示菜单ID
protected int MenuExtendDivID
{
get
{
object o = ViewState[ " MenuExtendDivID " ];

if (o != null )
{
return int .Parse(o.ToString());
}
else
{
return - 1 ;
}
}
set
{
ViewState[
" MenuExtendDivID " ] = value;

}
}
#endregion
// 欢迎与邀月交流,net技术与软件架构 2006年12月4日

#region 公共菜单头

/// <summary>
/// 有些项展开
/// </summary>
protected static string publicPreExtend
{
// onmouseout='this.style.cursor=default'onmouseover=this.style.cursor='hand'
get
{
return @" <divid='{0}Section'>
<divid='{0}Head'class='leftmenu'onclick={1}ToggleVisible('Table_{0}','Img_{0}');{1}style=""cursor:pointer;"">
<imgsrc='/images/toggle_gray_up.gif'border='0'hspace='5'id='Img_{0}'><span>{2}</span>
</div>
<divid='Table_{0}'>
<tableclass='menu'cellpadding='0'cellspacing='0'align='center'ID='Table__{0}'>
<tr>
<tdalign='left'>
" ;
}
}
/// <summary>
/// 默认不展开
/// </summary>
protected static string publicPre
{

// onmouseout=this.style.cursor='default'onmouseover=this.style.cursor='hand'
get
{
return @" <divid='{0}Section'>
<divid='{0}Head'class='leftmenu'onclick={1}ToggleVisible('Table_{0}','Img_{0}');{1}style=""cursor:pointer;"">
<imgsrc='/images/toggle_gray_down.gif'border='0'hspace='5'id='Img_{0}'><span>{2}</span>
</div>
<divid='Table_{0}'style='DISPLAY:none'>
<tableclass='menu'cellpadding='0'cellspacing='0'align='center'ID='Table__{0}'>
<tr>
<tdalign='left'>
" ;
}
}
#endregion

#region 公共菜单尾
protected static string publicEnd
{
get
{
return @" </td></tr></table></div></div> " ;
}
}


#endregion

#region 会员资料
/// <summary>
/// Menuid==0
/// </summary>
protected string UserMenu
{
get
{
string s = "" ;

s
= @" <ul>
<li><Ahref='/User/Modify.aspx?dvid=0'>帐户修改</A></li>
<li><Ahref='/User/ModifyChangePwd.aspx?dvid=0'>密码修改</A></li>

</ul>
"
+ publicEnd;
// <li><Ahref='#?dvid=0'>积分管理</A></li>
s = (MenuExtendDivID == 0 ) ? (publicPreExtend + s):(publicPre + s);

s
= string .Format(s, " User " , " " " , " 会员资料 " );
return s;
}
}
#endregion 2
#region 企业管理
/// <summary>
/// Menuid==1
/// </summary>
protected string CompanyMenu
{
get
{
string s = "" ;

s
= @" <ul>
<li><Ahref='/User/Company/?dvid=1'>企业信息</A></li>
<li><Ahref='/User/news/?dvid=1&tp=4'>企业动态</A></li>
<li><Ahref='/User/CompanyExtend/Award.aspx?dvid=1'>企业荣誉</A>
" + _vipImage + @" </li>
<li><Ahref='/User/CompanyExtend/People.aspx?dvid=1'>企业家风采</A>
" + _vipImage + @" </li>
</ul>
"
+ publicEnd;
s
= (MenuExtendDivID == 1 ) ? (publicPreExtend + s):(publicPre + s);


s
= string .Format(s, " Company " , " " " , " 企业管理 " );
return s;
}
}
#endregion
#region 产品列表
/// <summary>
/// Menuid==2
/// </summary>
protected string ProductInfoMenu
{
get
{
string s = "" ;

s
= @" <ul>
<li><ahref='/User/Product/Insert.aspx?dvid=2'>新增产品</a>
" + _vipImage + @" </li>
<li><ahref='/User/Product/?dvid=2&st=1'>当前发布产品</a>
" + _vipImage + @" </li>
<li><ahref='/User/Product/?dvid=2&st=-3'>未发布产品</a>
" + _vipImage + @" </li>
<li><ahref='/User/Product/?dvid=2&st=0'>等待审核产品</a>
" + _vipImage + @" </li>
<li><ahref='/User/Product/?dvid=2&st=-1'>未通过审核产品</a>
" + _vipImage + @" </li>
<li><ahref='/User/Product/?dvid=2&st=2'>推荐产品</a>
" + _vipImage + @" </li>
</ul>
"
+ publicEnd;
// <li><ahref='/User/Product/?dvid=2&st=-1'>未通过审核产品</a></li>
s = (MenuExtendDivID == 2 ) ? (publicPreExtend + s):(publicPre + s);


s
= string .Format(s, " ProductInfo " , " " " , " 产品库 " );
return s;
}
}
#endregion
#region 供应列表
/// <summary>
/// Menuid==3
/// </summary>
protected string TradeForSellMenu
{
get
{
string s = "" ;

s
= @" <ul>
<li><ahref='/User/Trade/Insert.aspx?tp=1&dvid=3'>新增供应信息</a></li>
<li><ahref='/User/Trade/?tp=1&st=1&dvid=3'>当前发布列表</a></li>
<li><ahref='/User/Trade/?tp=1&st=0&dvid=3'>等待审核列表</a></li>
<li><ahref='/User/Trade/RejectList.aspx?tp=1&st=-1&dvid=3'>未通过审核列表</li>
<li><ahref='/User/Trade/default0.aspx?tp=1&st=1&dvid=3'>供应信息配对</a>
" + _vipImage + @" </li>

</ul>
"
+ publicEnd;
// <li><ahref='#?dvid=3'>订阅商机</a></li>
s = (MenuExtendDivID == 3 ) ? (publicPreExtend + s):(publicPre + s);

s
= string .Format(s, " TradeForSell " , " " " , " 供应信息 " );
return s;
}
}
#endregion
#region 求购列表
/// <summary>
/// Menuid==4
/// </summary>
protected string TradeForBuyMenu
{
get
{
string s = "" ;

s
= @" <ul>
<li><ahref='/User/Trade/Insert.aspx?tp=2&dvid=4'>新增求购信息</a></li>
<li><ahref='/User/Trade/Default2.aspx?tp=2&st=1&dvid=4'>当前发布列表</a></li>
<li><ahref='/User/Trade/Default2.aspx?tp=2&st=0&dvid=4'>等待审核列表</a></li>
<li><ahref='/User/Trade/RejectList.aspx?tp=2&st=-1&dvid=4'>未通过审核列表</li>
<li><ahref='/User/Trade/default20.aspx?tp=2&st=1&dvid=4'>求购信息配对</a></li>
</ul>
"
+ publicEnd;
s
= (MenuExtendDivID == 4 ) ? (publicPreExtend + s):(publicPre + s);

s
= string .Format(s, " TradeForBuy " , " " " , " 求购信息 " );
return s;
}
}
#endregion
#region 代理合作列表
/// <summary>
/// Menuid==5
/// </summary>
protected string TradeForDeleAndCorpMenu
{
get
{
string s = "" ;

s
= @" <ul>
<li><ahref='/User/Trade/Insert.aspx?tp=3&dvid=5'>新增信息</a></li>
<li><ahref='/User/Trade/Default3.aspx?tp=3&st=1&dvid=5'>当前发布列表</a></li>
<li><ahref='/User/Trade/Default3.aspx?&st=0&dvid=5'>等待审核列表</a></li>
<li><ahref='/User/Trade/RejectList.aspx?&st=-1&dvid=5'>未通过审核列表</li>
</ul>
"
+ publicEnd;
s
= (MenuExtendDivID == 5 ) ? (publicPreExtend + s):(publicPre + s);

s
= string .Format(s, " TradeForDeleAndCorp " , " " " , " 代理合作信息 " );
return s;
}
}
#endregion

#region 站内邮件
/// <summary>
/// Menuid==6
/// </summary>
protected string MessageMenu
{
get
{
string s = "" ;

s
= @" <ul>
<li><ahref='/User/Message2007/?box=0&dvid=6'>收件箱</a></li>
<li><ahref='/User/Message2007/SendList.aspx?box=1&dvid=6'>发件箱</a></li>
<li><ahref='/User/BusinessContacts/?dvid=6'>商业伙伴</a></li>
<li><ahref='/User/BlackContacts/?dvid=6'>黑名单</a></li>
<li><ahref='/User/MobileMessageSet/?dvid=6'>短信提醒设置</a>
" + _vipImage + @" </li>
</ul>
"
+ publicEnd;
s
= (MenuExtendDivID == 6 ) ? (publicPreExtend + s):(publicPre + s);

s
= string .Format(s, " Message " , " " " , " 站内邮件 " );
return s;
}
}
#endregion
#region 推荐及订阅列表
/// <summary>
/// Menuid==7
/// </summary>
protected string MagzineAndSubscribeMenu
{
get
{
string s = "" ;
s
= @" <ul>
<li><ahref='/User/Subscribe/?dvid=7'>免费索取</a></li>
<li><ahref='/User/Magzine/CoverPageList.aspx?dvid=7'>历史期刊网络版</a></li>
<li><ahref='/User/Magzine/Insert.aspx?dvid=7'>申请刊登产品</a>
" + _vipImage + @" </li>
<li><ahref='/User/Magzine/default.aspx?dvid=7'>刊登产品列表</a>
" + _vipImage + @" </li>
</ul>
"
+ publicEnd;
s
= (MenuExtendDivID == 7 ) ? (publicPreExtend + s):(publicPre + s);
s
= string .Format(s, " MagzineAndSubscribe " , " " " , " 中国农业商情蔬菜卷 " );
return s;
}
}
#endregion
#region 图片管理
/// <summary>
/// Menuid==8
/// </summary>
protected string PictureMenu
{
get
{
string s = "" ;

s
= @" <ul>
<li><ahref='#?dvid=8'>上传图片</a></li>
<li><ahref='#?dvid=8'>图片管理</a></li>
</ul>
"
+ publicEnd;
s
= (MenuExtendDivID == 8 ) ? (publicPreExtend + s):(publicPre + s);
s
= string .Format(s, " Picture " , " " " , " 图片管理 " );
return s;
}
}
#endregion
#region 其他列表
/// <summary>
/// Menuid==9
/// </summary>
protected string OtherMenu
{
get
{
string s = "" ;

s
= @" <ul>
<li><ahref='/User/News/Insert.aspx?dvid=9&tp=14'>发布评论</a></li>
<li><ahref='/User/News/?dvid=9&tp=14'>市场评论</a></li>
</ul>
"
+ publicEnd;
s
= (MenuExtendDivID == 9 ) ? (publicPreExtend + s):(publicPre + s);


s
= string .Format(s, " Other " , " " " , " 其他 " );
return s;
}
}
#endregion
#region 帮助列表
/// <summary>
/// Menuid==10
/// </summary>
protected string HelpMenu
{
get
{
string s = "" ;

s
= @" <ul>
<li><ahref='#?dvid=10'>帮助文档</a></li>
<li><ahref='#?dvid=10'>在线咨询</a></li>
</ul>
"
+ publicEnd;
s
= (MenuExtendDivID == 10 ) ? (publicPreExtend + s):(publicPre + s);
s
= string .Format(s, " Help " , " " " , " 帮助 " );
return s;
}
}
#endregion
#region 蔬菜价格
/// <summary>
/// Menuid==11
/// </summary>
protected string PriceMenu
{
get
{
string s = "" ;

s
= @" <ul>
<li><ahref='/User/Price/?dvid=11'>价格趋势图</a></li>
<li><ahref='/User/Price/Vip.aspx?dvid=11'>价格趋势图(Vip)</a>
" + _vipImage + @" </li>
</ul>
"
+ publicEnd;
s
= (MenuExtendDivID == 11 ) ? (publicPreExtend + s):(publicPre + s);
s
= string .Format(s, " Picture " , " " " , " 蔬菜价格 " );
return s;
}
}
#endregion
#region 增值推荐
/// <summary>
/// Menuid==11
/// </summary>
protected string IncrementMenu
{
get
{
string s = "" ;

s
= @" <ul>
<li><ahref='/User/Increment/DownloadTrade.aspx?dvid=12'>品种分布区域数据下载</a>
" + _vipImage + @" </li>
</ul>
"
+ publicEnd;
s
= (MenuExtendDivID == 12 ) ? (publicPreExtend + s):(publicPre + s);
s
= string .Format(s, " Increment " , " " " , " 增值推荐 " );
return s;
}
}
#endregion
#endregion
Vegnet.User.Framework.Components.Useruser
= Vegnet.User.Framework.Data.DataDTOProvider.GetUserByCach();
protected LabellabMenuItem;

#endregion


protected override void OnLoad(EventArgse)
{
base .OnLoad(e);
// Page.Response.Write(user.IsBase);
// Page.SmartNavigation=true;

// 2006年10月30日新增 欢迎与邀月交流,net技术与软件架构是否允许推荐产品到杂志,目前所有注册用户均可。推荐规则见设计文档
// 目前暂不动,合适时应改为case判断
if (user == null )
{
Page.Response.Redirect(
" /User/Login.aspx " );
return ;
}
if ( ! IsPostBack)
{
try
{
this .MenuExtendDivID = (Page.Request[ " dvid " ] != null ) ? int .Parse(Page.Request[ " dvid " ].ToString()): - 1 ;
}
catch
{
this .MenuExtendDivID =- 1 ;
}
}
if (labMenuItem != null )
{
StringBuildersb
= new StringBuilder(); // 定义临时变量
sb.Append( " <tr><tdheight='35'> " ); // 初始化头
if (user.IsAllowRecommendToMagzine)
{
#region 如果允许推荐
#region 用户类型
if (user.IsBase)
{
sb.Append(UserMenu);
sb.Append(CompanyMenu);
sb.Append(ProductInfoMenu);
sb.Append(TradeForSellMenu);
sb.Append(TradeForBuyMenu);
sb.Append(TradeForDeleAndCorpMenu);
sb.Append(MessageMenu);
sb.Append(MagzineAndSubscribeMenu);
sb.Append(PriceMenu);
// +PictureMenu
sb.Append(IncrementMenu);
sb.Append(OtherMenu);
// +HelpMenu

}
else
{
sb.Append(UserMenu);
sb.Append(CompanyMenu);
sb.Append(ProductInfoMenu);
sb.Append(TradeForSellMenu);
sb.Append(TradeForBuyMenu);
sb.Append(TradeForDeleAndCorpMenu);
sb.Append(MessageMenu);
sb.Append(MagzineAndSubscribeMenu);
sb.Append(PriceMenu);
// +PictureMenu
sb.Append(IncrementMenu);
sb.Append(OtherMenu);
// +HelpMenu

}
#endregion
#endregion
}
else
{
#region 如果不允许推荐
#region 用户类型
if (user.IsBase)
{
sb.Append(UserMenu);
sb.Append(CompanyMenu);
sb.Append(ProductInfoMenu);
sb.Append(TradeForSellMenu);
sb.Append(TradeForBuyMenu);
sb.Append(TradeForDeleAndCorpMenu);
sb.Append(MessageMenu);
sb.Append(OtherMenu);
// +HelpMenu
}
else
{
sb.Append(UserMenu);
sb.Append(CompanyMenu);
sb.Append(ProductInfoMenu);
sb.Append(TradeForSellMenu);
sb.Append(TradeForBuyMenu);
sb.Append(TradeForDeleAndCorpMenu);
sb.Append(MessageMenu);
sb.Append(OtherMenu);
// +HelpMenu

}
#endregion
#endregion
}
sb.Append(
" </td></tr> " ); // 初始化尾
this .labMenuItem.Text = sb.ToString();
}

}

}
}

你可能感兴趣的:(OO)