Пример #1
0
        void BindChildIndex()
        {
            string            filePath   = Server.MapPath("/user/Resource/menuItems.xml");
            MenuItemXmlHelper menuHelper = new MenuItemXmlHelper(filePath);

            string xPath = "/root/menuTree";
            List <We7.CMS.Common.MenuItemXml> lsItemsLevel1 = menuHelper.GetMenuItemXmls(xPath);

            int count = menuHelper.GetMenuItemXmls("/root/items").Count;

            foreach (We7.CMS.Common.MenuItemXml menuItem in lsItemsLevel1)
            {
                string   name  = "├" + menuItem.Lable.ToString();
                string   value = menuItem.ID + "," + menuItem.ID;
                ListItem item  = new ListItem(name, value);
                SecondIndexDropDownList.Items.Add(item);
                int i = 0;
                List <MenuItemXml> lsItemsLevel2 = menuHelper.GetMenuItemXmls(xPath + "/menu[@id='" + menuItem.ID + "']");

                foreach (We7.CMS.Common.MenuItemXml submenu in lsItemsLevel2)
                {
                    string   sname  = "├──" + submenu.Lable.ToString();
                    string   svalue = menuItem.ID + "," + submenu.ID.ToString();
                    ListItem sitem  = new ListItem(sname, svalue);
                    i = Convert.ToInt32(submenu.ID);
                    SecondIndexDropDownList.Items.Add(sitem);

                    List <We7.CMS.Common.MenuItemXml> lsItemsLevel3 = menuHelper.GetMenuItemXmls(xPath + "/menu[@id='" + menuItem.ID + "']" + "/menu[@id='" + submenu.ID + "']");
                    foreach (We7.CMS.Common.MenuItemXml subSubMenu in lsItemsLevel3)
                    {
                        string   ssname  = "├────" + subSubMenu.Lable.ToString();
                        string   ssvalue = menuItem.ID + "," + submenu.ID + "," + subSubMenu.ID.ToString();
                        ListItem ssitem  = new ListItem(ssname, ssvalue);
                        i = Convert.ToInt32(subSubMenu.ID);
                        SecondIndexDropDownList.Items.Add(ssitem);
                    }
                    int      result     = Convert.ToInt32(menuHelper.GetMenuItemXmls("/root/items")[count - 1].ID) + 1;
                    ListItem appendItem = new ListItem("├────(追加到这里)", menuItem.ID + "," + submenu.ID + "," + result);
                    SecondIndexDropDownList.Items.Add(appendItem);
                }
            }
        }
Пример #2
0
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            string            filePath      = Server.MapPath("/user/Resource/menuItems.xml");
            MenuItemXmlHelper menuXmlHelper = new MenuItemXmlHelper(filePath);

            try
            {
                int count = menuXmlHelper.GetMenuItemXmls("/root/items").Count;

                int firstIndex = Convert.ToInt32(menuXmlHelper.GetMenuItemXmls("/root/items")[count - 1].ID) + 1;

                if (SecondIndexDropDownList.SelectedValue.Split(new char[] { ',' }).Length < 3)
                {
                    Messages.ShowError("请选择(追加到这里)选项!");
                    return;
                }
                string parentID = SecondIndexDropDownList.SelectedItem.Value.Split(',')[1];
                string rootID   = SecondIndexDropDownList.SelectedItem.Value.Split(',')[0];

                string firstTitle    = DesTextBox.Text.Trim();
                string firstNameText = TitleTextBox.Text.Trim();
                string firstUrl      = UrlTextBox.Text.Trim();



                /*
                 * parentID:
                 * 存入数据时 应为GUID,并且与该节点的oldParent保持一致
                 * 存入XML时 为int类型
                 * 勾立国 2011-7-13
                 */
                string xPath     = "/root/items/item[@id='" + parentID + "']";
                string oldParent = menuXmlHelper.GetMenuItemXml(xPath).Oldid;
                string oldId     = MenuHelper.CreateModelMenu(oldParent, firstIndex, firstNameText, firstTitle, firstUrl, firstIndex, EntityID);

                MenuItemXml item1 = new MenuItemXml();
                item1.ID             = firstIndex.ToString();
                item1.Lable          = firstNameText;
                item1.MatchParameter = "true";
                item1.Name           = "";
                item1.NodeName       = "item";
                item1.Oldid          = oldId;
                item1.Oldparent      = oldParent;
                item1.Parent         = parentID;
                item1.Url            = firstUrl;
                item1.Group          = "1"; //自定义菜单
                item1.Type           = 0;   //显示
                menuXmlHelper.AddMenuItemXmls(item1, "/root/items");

                MenuItemXml item2 = new MenuItemXml();
                item2.ID       = firstIndex.ToString();
                item2.Lable    = firstNameText;
                item2.NodeName = "menu";
                item2.Link     = "";
                xPath          = "/root/menuTree/menu[@id='" + rootID + "']/menu[@id='" + parentID + "']";

                menuXmlHelper.AddMenuItemDisplay(item2, xPath);
                Messages.ShowMessage("保存成功!");

                //string url = We7Helper.AddParamToUrl(ReturnHyperLink.NavigateUrl, "reload", "menu");
                //url = We7Helper.AddParamToUrl(url, "add", firstTitle + "("+ secondTitle + ")");
                //HttpContext.Current.Session.Clear();
                //Response.Redirect(url);
            }
            catch (Exception ex)
            {
                Messages.ShowError("无法保存:" + ex.Message);
            }
        }