Пример #1
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            string id = "";

            if (MenuID != null && MenuID != "")
            {
                id = MenuID;
            }
            string firstTitle    = DesTextBox.Text.Trim();
            string firstNameText = TitleTextBox.Text.Trim();
            string firstUrl      = UrlTextBox.Text.Trim();

            #region 此处逻辑在三级菜单时报异常,更改如下
            //if (Int32.Parse(SecondIndexDropDownList.SelectedItem.Value.Split(',')[1]) > 0)
            //{
            //   firstIndex= Int32.Parse(SecondIndexDropDownList.SelectedItem.Value.Split(',')[1]) - 1;
            //}
            #endregion
            string selectValue = SecondIndexDropDownList.SelectedValue;
            int    index       = int.Parse(selectValue.Substring(selectValue.LastIndexOf(",") + 1));
            int    firstIndex  = index > 0 ? index : 0;

            int    rootID   = 0;
            string parentID = selectValue.Split(',')[0];
            if (parentID == We7Helper.EmptyGUID)
            {
                Messages.ShowError("您编辑的是子菜单,不能选择主菜单的位置,请您选择子菜单。");
            }
            else
            {
                string            itemId = MenuHelper.CreateSubMenu(firstNameText, firstTitle, firstUrl, firstIndex, parentID, id, EntityID);
                MenuItemXmlHelper helper = new MenuItemXmlHelper(Server.MapPath("/user/Resource/menuItems.xml"));
                if (MenuID != null && MenuID != "")
                {
                    if (EntityID == "System.User")
                    {
                        string      xPath = "/root/items/item[@oldid='" + id + "']";
                        MenuItemXml node  = helper.GetMenuItemXml(xPath);
                        node.Lable     = firstTitle;
                        node.Url       = firstUrl;
                        node.Oldparent = parentID;
                        node.Parent    = helper.GetMenuItemXml("/root/items/item[@oldid='" + parentID + "']").ID;
                        helper.UpdateMenuItemXml(node, xPath);
                    }
                    Messages.ShowMessage("您成功修改" + firstTitle + "菜单,更新成功之后请退出重新登陆才能生效");
                }
                else
                {
                    string xPath     = "/root/items/item[@id='" + parentID + "']";
                    string oldParent = helper.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;
                    helper.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 + "']";

                    helper.AddMenuItemDisplay(item2, xPath);

                    Messages.ShowMessage("您成功创建" + firstTitle + "菜单,生成成功之后请退出重新登陆才能生效");
                }
            }
        }
Пример #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);
            }
        }