コード例 #1
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
        {
            if (!_clsLoginModel.PermissionsFunc(_currentMenuId, (int)PermissionsEnum.添加))
            {
                _metroWindow.ShowMessageAsync("友情提示", "您没有添加菜单信息的权限");
                return;
            }
            if (!Verify())
            {
                return;
            }
            if (!LeftMenuManager.JudgeDisplayNameNotRootName(_metroWindow, DisplayName))
            {
                return;
            }

            Action addAction = () =>
            {
                var requestModel = new TopMenusAddRequestModel
                {
                    DisplayName   = DisplayName,
                    DllPath       = DllPath,
                    EntryFunction = EntryFunction,
                    MenuId        = MenuId,
                    ParentId      = ParentId,
                    Sort          = int.MaxValue,
                    Timestamp     = _topMenusManage.ServerTime.ToUnixTimestamp()
                };
                var result = _topMenusManage.Add(requestModel);
                if (result.ResultStatus == ResultStatus.Success)
                {
                    ClearMenuData();

                    var newItem = GenerateTreeViewItem(result.Data);
                    if (TreeViewMain.SelectedItem == null || ((TreeViewItem)TreeViewMain.SelectedItem).Header.ToString() == Config.RootDisplayName)
                    {
                        TreeViewMain.Items.Add(newItem);
                    }
                    else
                    {
                        ((TreeViewItem)TreeViewMain.SelectedItem).Items.Add(newItem);
                    }

                    _topMenusList = _topMenusManage.GetAll();
                }
                _metroWindow.ShowMessageAsync(result.ResultStatus == ResultStatus.Success ? "添加成功提示" : "添加失败提示", result.Message);
            };


            var setting = new MetroDialogSettings
            {
                AnimateShow           = true,
                AnimateHide           = true,
                AffirmativeButtonText = "是",
                NegativeButtonText    = "否",
                DefaultButtonFocus    = MessageDialogResult.Negative
            };

            if (_topMenusManage.Exist(a => a.DisplayName == DisplayName.Trim()))
            {
                _metroWindow.ShowMessageAsync("信息重复提示", $"菜单名称“{DisplayName}”,在系统中已存在,是否仍使用该名称?", MessageDialogStyle.AffirmativeAndNegative, setting).ContinueWith(
                    t =>
                {
                    _metroWindow.Dispatcher.Invoke((Action)(() =>
                    {
                        if (t.Result == MessageDialogResult.Affirmative)
                        {
                            addAction();
                        }
                    }));
                });
            }
            else
            {
                addAction();
            }
        }
コード例 #2
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSave_OnClick(object sender, RoutedEventArgs e)
        {
            if (!_clsLoginModel.PermissionsFunc(_currentMenuId, (int)PermissionsEnum.修改))
            {
                _metroWindow.ShowMessageAsync("友情提示", "您没有修改菜单信息的权限");
                return;
            }
            if (!Verify())
            {
                return;
            }
            if (!LeftMenuManager.JudgeDisplayNameNotRootName(_metroWindow, DisplayName))
            {
                return;
            }

            Action updateAction = () =>
            {
                var requestModel = new TopMenusUpdateRequestModel
                {
                    DisplayName   = DisplayName,
                    DllPath       = DllPath,
                    EntryFunction = EntryFunction,
                    Ico           = null,
                    MenuId        = MenuId,
                    ParentId      = ParentId,
                    Timestamp     = _topMenusManage.ServerTime.ToUnixTimestamp()
                };
                var result = _topMenusManage.Update(TopMenuId, Timestamp, requestModel);
                if (result.ResultStatus == ResultStatus.Success)
                {
                    Timestamp = result.Data.Timestamp;
                    ((TopMenus)((TreeViewItem)(TreeViewMain.SelectedItem)).DataContext).Timestamp = result.Data.Timestamp;

                    UpdateSelectedItemPosition(TopMenuId);
                    UpdateSort(TreeViewMain.Items);
                    UpdateSelectedItem(TreeViewMain.Items, TopMenuId);

                    _topMenusList = _topMenusManage.GetAll();
                }
                _metroWindow.ShowMessageAsync(result.ResultStatus == ResultStatus.Success ? "更新成功" : "更新失败", result.Message);
            };

            var setting = new MetroDialogSettings
            {
                AnimateShow           = true,
                AnimateHide           = true,
                AffirmativeButtonText = "确定",
                NegativeButtonText    = "取消",
                DefaultButtonFocus    = MessageDialogResult.Negative
            };

            _metroWindow.ShowMessageAsync("更新节点提示", "您确定要更新此节点信息吗?", MessageDialogStyle.AffirmativeAndNegative, setting).ContinueWith(
                t =>
            {
                _metroWindow.Dispatcher.Invoke((Action)(() =>
                {
                    if (t.Result == MessageDialogResult.Affirmative)
                    {
                        if (_topMenusManage.Exist(a => a.Id != TopMenuId && a.DisplayName == DisplayName))
                        {
                            _metroWindow.ShowMessageAsync("信息重复提示", $"菜单名称“{DisplayName}”,在系统中已存在,是否仍使用该名称?", MessageDialogStyle.AffirmativeAndNegative, setting)
                            .ContinueWith(z =>
                            {
                                if (z.Result == MessageDialogResult.Affirmative)
                                {
                                    _metroWindow.Dispatcher.Invoke((Action)(() =>
                                    {
                                        updateAction();
                                    }));
                                }
                            });
                        }
                        else
                        {
                            updateAction();
                        }
                    }
                }));
            });
        }