public MenuDataItem(SecPageEntity page, MenuDataItem parentMenu) { ParentMenu = parentMenu; Page = page; SubMenu = new List<MenuDataItem>(); ValidControls = new List<SecPermissionEntity>(); }
void GetTopParentItem(MenuDataItem currentMenu, out MenuDataItem topParentItem) { topParentItem = null; if (currentMenu.Page.ParentId == "0") { topParentItem = currentMenu; } else { GetTopParentItem(currentMenu.ParentMenu, out topParentItem); } }
void CreateMenuItemHtml(StringBuilder sbHtml, List<MenuDataItem> menuDataItems, MenuDataItem currentMenu) { //if (currentMenu == null && menuDataItems != null && menuDataItems.Count > 0 && menuDataItems[0].SubMenu.Count > 0) //{ // currentMenu = menuDataItems[0].SubMenu[0]; //} // sbHtml.Append("<ul class='homeIco'><li><a href=''><img class='icoImage' src='/App_Themes/VSA/images/icon/home.png' Visible='false' /></a></li></ul>"); if (menuDataItems.Count > 0) { MenuDataItem topParentItem = null; if (currentMenu != null) { GetTopParentItem(currentMenu, out topParentItem); } foreach (MenuDataItem child in menuDataItems) { sbHtml.Append("<ul class='topmenu'>"); string url = this.ResolveClientUrl(child.Page.PageUrl); if (!url.ToUpper().Contains(".ASPX")) { url = "#"; } if (child.Page.ParentId == "0") { string pageUrl = child.SubMenu.Count > 0 ? child.SubMenu[0].Page.PageUrl : "#"; if (topParentItem != null && child.Page.PageId == topParentItem.Page.PageId) { // sbHtml.AppendFormat(@"<li style='background: url(/App_Themes/VSA/images/top_link_bg_on.png) repeat-x center top;'> // <a style='color: #FFFFFF' href='{0}'>{1}", pageUrl.Substring(pageUrl.LastIndexOf("~") + 1) + "?MenuID=" + child.Page.PageId, child.Page.PageName); sbHtml.AppendFormat(@"<li style='background: url(../App_Themes/VSA/images/top_link_bg_on.png) repeat-x center top;'> <a style='color: #FFFFFF' href='#'>{1}", pageUrl.Substring(pageUrl.LastIndexOf("~") + 1) + "?MenuID=" + child.Page.PageId, child.Page.PageName); } else { //sbHtml.AppendFormat("<li><a href='{0}'>{1}", pageUrl.Substring(pageUrl.LastIndexOf("~") + 1) + "?MenuID=" + child.Page.PageId, child.Page.PageName); sbHtml.AppendFormat("<li><a href='#'>{1}", pageUrl.Substring(pageUrl.LastIndexOf("~") + 1) + "?MenuID=" + child.Page.PageId, child.Page.PageName); } if (!string.IsNullOrEmpty(child.Page.IcoCssclass)) { sbHtml.AppendFormat("<img class='icoImage' src='{0}' />", "../App_Themes/VSA/images/icon/" + child.Page.IcoCssclass); } } else { sbHtml.AppendFormat("<li><a href='{0}'>{1}", url, child.Page.PageName); } sbHtml.Append("</a>"); if (child.SubMenu.Count > 0) { sbHtml.Append( CreateSubMenu(child)); } sbHtml.AppendFormat("</li>"); sbHtml.AppendFormat("</ul>"); } } }
private string CreateSubMenu(MenuDataItem subParentItem) { StringBuilder sbHtml = new StringBuilder(); sbHtml.Append(" <ul class='submenu1'>"); foreach (MenuDataItem item in subParentItem.SubMenu) { if (subParentItem != null && item.Page.PageId == subParentItem.Page.PageId) { sbHtml.Append(@"<li><a href=" + ResolveUrl(item.Page.PageUrl) + " >" + item.Page.PageName); } else { sbHtml.Append(@"<li><a href=" + ResolveUrl(item.Page.PageUrl) + " >" + item.Page.PageName); } //if (!string.IsNullOrEmpty(item.Page.IcoCssclass)) //{ // sbHtml.Append("<img class='icoImage' src='../App_Themes/VSA/images/icon/" + item.Page.IcoCssclass + " />"); //} //sbHtml.Append("<img class='icoImage' src='../App_Themes/VSA/images/icon/sitemap.png' />"); sbHtml.Append("</a>"); if (item.SubMenu.Count > 0) { sbHtml.Append(CreateSubMenu(item)); } sbHtml.AppendFormat("</li>"); } sbHtml.Append("</ul>"); return sbHtml.ToString(); }
private void Bind(MenuDataItem rootMenuDataItem, PageDomain pageDomain, string userId) { Dictionary<string, decimal> pageDataScopes = GetPageDataScope(userId);//页面数据权限 2011-04-08 lucas.zong foreach (PageDomain page in pageDomain.ChildsDomain) { if (GetPageIds(userId).Contains(page.SecPageEntity.PageId)) { MenuDataItem childMenuDataItem = pageDataScopes.ContainsKey(page.SecPageEntity.PageId) ? new MenuDataItem(page.SecPageEntity, rootMenuDataItem, (DataScope)Enum.Parse(typeof(DataScope), pageDataScopes[page.SecPageEntity.PageId].ToString())) : new MenuDataItem(page.SecPageEntity, rootMenuDataItem); foreach (PermissionDomain permissionDomain in page.PermissionDomainList) { if (GetPermissionIds(userId).Contains(permissionDomain.SecPermissionEntity.PermissionId)) { childMenuDataItem.ValidControls.Add(permissionDomain.SecPermissionEntity); } } Bind(childMenuDataItem, page, userId); rootMenuDataItem.SubMenu.Add(childMenuDataItem); } } }
void GetCurrentSubParentItem(MenuDataItem currentMenu, out MenuDataItem subParentItem) { subParentItem = null; if (currentMenu.ParentMenu.Page.ParentId == "0") { subParentItem = currentMenu; } else { GetCurrentSubParentItem(currentMenu.ParentMenu, out subParentItem); } }
MenuDataItem GetPage(string url, MenuDataItem menu) { if (menu.Page.PageUrl.ToUpper().Contains(url.ToUpper())) { return menu; } foreach (var item in menu.SubMenu) { MenuDataItem m = GetPage(url, item); if (m != null) { return m; } } return null; }