Self-built public program (4)-BS menu object

Source: Internet
Author: User

Using system;

Using system. text;

Using system. collections;

Namespace isdmenu

{

/// <Summary>

/// Summary of isdmenuobject.

/// </Summary>

Public class isdmenuobject

{

Public isdmenuobject ()

{

//

// Todo: add the constructor logic here

//

Allmenu = new arraylist ();

}

/// <Summary>

/// Number of items in the main menu

/// </Summary>

Private int I _mainmenuitemnumber = 0;



/// <Summary>

/// Store the menu Value

/// </Summary>

Private arraylist allmenu = new arraylist ();

# Region attributes

/// <Summary>

/// Function: set or return the number of items in the main menu

/// </Summary>

Public int mainmenuitemnumber

{

Get

{

Return this. I _mainmenuitemnumber;

}

Set

{

This. I _mainmenuitemnumber = value;

}

}



# Endregion

# Region Method

/// <Summary>

/// Function: Add a main menu item

/// Created by applegreen

/// Update Time:

/// </Summary>

/// <Param name = "mainitemname"> name of the Main Menu </param>

/// <Param name = "subitemdisplayvalue"> name of the Main Menu </param>

Public void additem (string mainitemname,

String mainitemdisplayvalue)

{

Mainitem MI = new mainitem (mainitemname. Trim (), mainitemdisplayvalue );

Allmenu. Add (MI );

}

/// <Summary>

/// Function: add a sub-menu

/// Created by applegreen

/// Update Time:

/// </Summary>

/// <Param name = "mainitemname"> name of the parent menu </param>

/// <Param name = "subitemdisplayname"> display name of the menu </param>

/// <Param name = "urlstr"> URL path </param>

/// <Param name = "targetname"> target address </param>

/// <Param name = "visable"> visible </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>

/// Function: return the HTML statement of the menu Creation

/// Created by applegreen

/// Update Time:

/// </Summary>

/// <Returns> returns the htmll statement </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 ");



// Add the main menu

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 ");



// Add a sub-menu

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'> & nbsp; </TD> \ n ")

. Append ("<TD class = 'middle' nowrap>" + Si. getsubitemdisplayname () + "</TD> \ n ")

. Append ("<TD class = 'right'> & nbsp; </TD> \ n ")

. Append ("</tr> \ n ");

}

}

SB. append ("</table> \ n ");

SB. append ("</table> </tr> </TD> \ n ");

}

Return sb. tostring ();



}

# Endregion

}

/// <Summary>

/// Main Menu object

/// </Summary>

Public class mainitem

{

/// <Summary>

/// Main menu name

/// </Summary>

Private string mainitemname;

/// <Summary>

/// Display name of the Main Menu

/// </Summary>

Private string mainitemdisplayvalue;

/// <Summary>

/// Submenu set

/// </Summary>

Private arraylist subitemlist = new arraylist ();



/// <Summary>

/// Function: Create a default menu

/// Created by applegreen

/// Update Time:

/// </Summary>

Public mainitem ()

{

This. mainitemname = string. empty;

This. mainitemdisplayvalue = string. empty;

}



/// <Summary>

/// Function: Obtain the name of the main menu.

/// Created by applegreen

/// Update Time:

/// </Summary>

/// <Returns> string of the main menu name </returns>

Public String getmainitemid ()

{

Return this. mainitemname;

}

/// <Summary>

/// Function: Get the display name of the Main Menu

/// Created by applegreen

/// Update Time:

/// </Summary>

/// <Returns> string of the display name of the Main Menu </returns>

Public String getmainitemdisplayvalue ()

{

Return this. mainitemdisplayvalue;

}

/// <Summary>

/// Function: Get the arraylist set of the sub-menu object

/// Created by applegreen

/// Update Time:

/// </Summary>

/// <Returns> arraylist set of the sub-menu object </returns>

Public arraylist getsubitemlist ()

{

Return this. subitemlist;

}

/// <Summary>

/// Function: create a custom Main Menu

/// Created by applegreen

/// Update Time:

/// </Summary>

/// <Param name = "s_mainitemname"> main menu name </param>

/// <Param name = "s_mainitemdisplayvalue"> display name of the Main Menu </param>

Public mainitem (string s_mainitemname,

String s_mainitemdisplayvalue)

{

This. mainitemname = s_mainitemname;

This. mainitemdisplayvalue = s_mainitemdisplayvalue;

}

/// <Summary>

/// Function: add a sub-menu

/// Created by applegreen

/// Update Time:

/// </Summary>

/// <Param name = "Si"> sub-menu object </param>

/// <Returns> </returns>

Public bool additem (subitem Si)

{

If (Si. getfathername () = This. mainitemname)

{

This. subitemlist. Add (SI );

Return true;

}

Else

{

Return false;

}

}

}

/// <Summary>

/// Submenu object

/// </Summary>

Public class subitem

{

/// <Summary>

/// Parent menu name

/// </Summary>

Private string mainitemname;

/// <Summary>

/// Menu name

/// </Summary>

Private string subitemdisplayname;

/// <Summary>

/// Menu URL

/// </Summary>

Private string urlstr;

/// <Summary>

/// Menu target Frame

/// </Summary>

Private string targetname;

/// <Summary>

/// Menu visible attribute

/// </Summary>

Private bool visable;

/// <Summary>

/// Function: Obtain the parent menu name.

/// Created by applegreen

/// Update Time:

/// </Summary>

/// <Returns> string of the parent menu name </returns>

Public String getfathername ()

{

Return this. mainitemname;

}

/// <Summary>

/// Function: Obtain the name of the sub-menu.

/// Created by applegreen

/// Update Time:

/// </Summary>

/// <Returns> display name of the sub-menu </returns>

Public String getsubitemdisplayname ()

{

Return this. subitemdisplayname;

}

 

/// <Summary>

/// Function: Obtain the URL of the sub-menu

/// Created by applegreen

/// Update Time:

/// </Summary>

/// <Returns> the URL string of the sub-menu </returns>

Public String geturlstr ()

{

Return this. urlstr;

}

/// <Summary>

/// Function: Obtain the target frame of the menu.

/// Created by applegreen

/// Update Time:

/// </Summary>

/// <Returns> string of the target frame in the menu </returns>

Public String gettargetname ()

{

Return this.tar getname;

}

/// <Summary>

/// Function: Obtain the visible properties of the menu.

/// Created by applegreen

/// Update Time:

/// </Summary>

/// <Returns> </returns>

Public bool getvisable ()

{

Return this. visable;

}

/// <Summary>

/// Function: Create a default menu

/// Created by applegreen

/// Update Time:

/// </Summary>

Public Subitem ()

{

This. mainitemname = string. empty;

This. subitemdisplayname = string. empty;

This. urlstr = string. empty;

This.tar getname = string. empty;

This. visable = false;

}

/// <Summary>

/// Function: create a custom menu

/// Created by applegreen

/// Update Time:

/// </Summary>

/// <Param name = "s_mainitemname"> parent menu name </param>

/// <Param name = "s_subitemdisplayname"> display name of the menu </param>

/// <Param name = "s_urlstr"> URL of the menu </param>

/// <Param name = "s_targetname"> Target frame of the menu </param>

/// <Param name = "B _visable"> menu visible attributes </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.tar getname = s_targetname;

This. visable = B _visable;

}

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.