Пример #1
0
        private void tsmiDelete_Click(object sender, EventArgs e)
        {
            //设置上级菜单
            TreeNode trSelect = tvLeftMenu.SelectedNode;

            if (trSelect == null)
            {
                return;
            }
            if (trSelect.GetNodeCount(true) > 0)
            {
                MsgHelper.ShowErr("请先删除子节点!");
                return;
            }

            if (MsgHelper.ShowOkCancel("确定要删除该菜单?") == DialogResult.Cancel)
            {
                return;
            }

            DMenu       selectMenu = trSelect.Tag as DMenu;
            XmlDocument xmlMenu    = DMenu.ReadMenuXmlFile(AppType.WinForm);

            #region  除
            XmlNode xnNew;
            switch (_saveMenu.MenuType)
            {
            case MenuTypeEnum.Modul:
                xnNew = xmlMenu.SelectSingleNode("xml/Model[@Guid='" + selectMenu.Guid + "']");
                xnNew.ParentNode.RemoveChild(xnNew);
                break;

            case MenuTypeEnum.Class:
                //第一个分类
                xnNew = xmlMenu.SelectSingleNode("xml/Model/Class[@Guid='" + selectMenu.Guid + "']");

                if (xnNew == null)
                {
                    //第二个菜单分类
                    xnNew = xmlMenu.SelectSingleNode("xml/Model/Class/Class[@Guid='" + selectMenu.Guid + "']");
                }

                if (xnNew == null)
                {
                    //最多支持第三个菜单分类
                    xnNew = xmlMenu.SelectSingleNode("xml/Model/Class/Class/Class[@Guid='" + selectMenu.Guid + "']");
                }
                xnNew.ParentNode.RemoveChild(xnNew);
                break;

            case MenuTypeEnum.Menu:
            default:
                //第一个分类
                xnNew = xmlMenu.SelectSingleNode("xml/Model/Class/Menu[@Guid='" + selectMenu.Guid + "']");

                if (xnNew == null)
                {
                    //第二个菜单分类
                    xnNew = xmlMenu.SelectSingleNode("xml/Model/Class/Class/Menu[@Guid='" + selectMenu.Guid + "']");
                }

                if (xnNew == null)
                {
                    //最多支持第三个菜单分类
                    xnNew = xmlMenu.SelectSingleNode("xml/Model/Class/Class/Class/Menu[@Guid='" + selectMenu.Guid + "']");
                }

                xnNew.ParentNode.RemoveChild(xnNew);
                break;
            }
            #endregion

            //保存
            xmlMenu.Save(DMenu.MenuXmlFilePath);
            MsgHelper.ShowInfo("删除成功!");
            UIHelper.ResetControl(grpEdit);
            //重新加载菜单
            LoadMenu();
        }
Пример #2
0
        private void tsbSave_Click(object sender, EventArgs e)
        {
            _saveMenu.Name        = txbMenuName.Text.Trim();
            _saveMenu.Code        = txbMenuCode.Text.Trim();
            _saveMenu.DLLName     = cbbDLL.Text;
            _saveMenu.FormName    = txbClassFullPath.Text.Trim();
            _saveMenu.ShortCutKey = txbShortCutKey.Text.Trim();
            if (string.IsNullOrEmpty(_saveMenu.Name))
            {
                MsgHelper.ShowErr("【菜单名称】不能为空!");
                return;
            }
            bool        isAdd   = false;
            XmlDocument xmlMenu = DMenu.ReadMenuXmlFile(AppType.WinForm);

            if (string.IsNullOrEmpty(_saveMenu.Guid))
            {
                isAdd = true;
            }

            #region 新增
            XmlElement xnNew;
            switch (_saveMenu.MenuType)
            {
            case MenuTypeEnum.Modul:
                xnNew = xmlMenu.CreateElement("Model");
                if (isAdd)
                {
                    xnNew.SetAttribute(MemuAttrString.Guid, StringHelper.GetGUID());
                    xmlMenu.DocumentElement.AppendChild(xnNew);
                }
                else
                {
                    xnNew = xmlMenu.SelectSingleNode("xml/Model[@Guid='" + _saveMenu.Guid + "']") as XmlElement;
                }
                break;

            case MenuTypeEnum.Class:
                xnNew = xmlMenu.CreateElement("Class");
                if (isAdd)
                {
                    xnNew.SetAttribute(MemuAttrString.Guid, StringHelper.GetGUID());
                    //先找模块
                    XmlNode xnParent = xmlMenu.SelectSingleNode("xml/Model[@Guid='" + _saveMenu.ParentGuid + "']");
                    if (xnParent != null)
                    {
                        xnParent.AppendChild(xnNew);
                    }
                }
                if (xnNew.ParentNode == null)
                {
                    //第一个分类
                    GetClassNode(isAdd, xmlMenu, "xml/Model/Class", ref xnNew);
                }

                if (xnNew.ParentNode == null)
                {
                    //第二个菜单分类
                    GetClassNode(isAdd, xmlMenu, "xml/Model/Class/Class", ref xnNew);
                }

                if (xnNew.ParentNode == null)
                {
                    //最多支持第三个菜单分类
                    GetClassNode(isAdd, xmlMenu, "xml/Model/Class/Class/Class", ref xnNew);
                }
                break;

            case MenuTypeEnum.Menu:
            default:
                if (string.IsNullOrEmpty(_saveMenu.DLLName))
                {
                    MsgHelper.ShowErr("【所在DLL文件】不能为空!");
                    return;
                }
                if (string.IsNullOrEmpty(_saveMenu.FormName))
                {
                    MsgHelper.ShowErr("【全路径类名】不能为空!");
                    return;
                }

                xnNew = xmlMenu.CreateElement("Menu");
                if (isAdd)
                {
                    xnNew.SetAttribute(MemuAttrString.Guid, StringHelper.GetGUID());
                }
                //第一个分类
                GetMenuNode(isAdd, xmlMenu, "xml/Model/Class", "xml /Model/Class/Menu", ref xnNew);

                if (xnNew.ParentNode == null)
                {
                    //第二个菜单分类
                    GetMenuNode(isAdd, xmlMenu, "xml/Model/Class/Class", "xml/Model/Class/Class/Menu", ref xnNew);
                }

                if (xnNew.ParentNode == null)
                {
                    //最多支持第三个菜单分类
                    GetMenuNode(isAdd, xmlMenu, "xml/Model/Class/Class/Class", "xml/Model/Class/Class/Class/Menu", ref xnNew);
                }
                break;
            }
            #endregion

            xnNew.SetAttribute(MemuAttrString.Name, _saveMenu.Name);
            xnNew.SetAttribute(MemuAttrString.Code, _saveMenu.Code);
            xnNew.SetAttribute(MemuAttrString.DLLName, _saveMenu.DLLName);
            xnNew.SetAttribute(MemuAttrString.FormName, _saveMenu.FormName);
            xnNew.SetAttribute(MemuAttrString.ShortCutKey, _saveMenu.ShortCutKey);
            //保存
            xmlMenu.Save(DMenu.MenuXmlFilePath);
            MsgHelper.ShowInfo("保存成功!");
            UIHelper.ResetControl(grpEdit);
            //重新加载菜单
            LoadMenu();
        }