20230201_145_upperpc/InSituLaboratory/ViewModels/Pages/MenuManagementViewModel.cs
2024-03-11 13:12:02 +08:00

102 lines
3.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using InSituLaboratory.Base;
using InSituLaboratory.Entities;
using InSituLaboratory.IService;
using InSituLaboratory.Models;
using Prism.Events;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace InSituLaboratory.ViewModels.Pages
{
public class MenuManagementViewModel : ViewModelBase
{
IMenuService _menuService;
IDialogService _dialogService;
IEventAggregator _eventAggregator;
public MenuManagementViewModel(IRegionManager regionManager, IMenuService menuService, IDialogService dialogService, IEventAggregator eventAggregator) : base(regionManager)
{
PageTitle = "菜单数据维护";
_menuService = menuService;
_dialogService = dialogService;
_eventAggregator = eventAggregator;
Refresh();
}
public ObservableCollection<MenuItemModel> Menus { get; set; } =
new ObservableCollection<MenuItemModel>();
List<Entities.SysMenu> origMenus;
string _searchKey;
//搜索 刷新
public override void Refresh()
{
Menus.Clear();
origMenus = _menuService.GetMenuList(SearchKey).ToList();
MenuHelper.FillMenus(Menus, null, origMenus);
}
//新建 编辑菜单
public override void DoModify(object model)
{
DialogParameters ps = new DialogParameters();
ps.Add("model", model);
_dialogService.ShowDialog("ModifyMenuView", ps, result =>
{
// 判断子窗口的返回状态如果OK刷新当前页面否则不管
if (result.Result == ButtonResult.OK)
{
this.Refresh();
//通知左侧树状图菜单变化
_eventAggregator.GetEvent<RefreshMenuEvent>().Publish();
}
});
}
/// <summary>
/// 删除
/// </summary>
/// <param name="model"></param>
public override void DoDelete(object model)
{
try
{
if (MessageBox.Show("是否确定删除此项?", "提示", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
//物理删除
_menuService.Delete<SysMenu>((model as MenuItemModel).MenuId);
//逻辑删除
//通过特定字段进行数据过滤
//以下方法存在问题,菜单列表刷新需要条件过滤
//var entity = _menuService.Find<SysMenu>((model as MenuItemModel).MenuId);
//entity.State = 0;
//_menuService.Update<SysMenu>(entity);
MessageBox.Show("删除完成!", "提示");
this.Refresh();
_eventAggregator.GetEvent<RefreshMenuEvent>().Publish();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示");
}
}
}
}