|
@@ -2,6 +2,7 @@
|
|
|
using BizService;
|
|
|
using Model.Dto;
|
|
|
using Model.Entities;
|
|
|
+using PLCTool.Models;
|
|
|
using Prism.Commands;
|
|
|
using Prism.Events;
|
|
|
using Prism.Mvvm;
|
|
@@ -9,6 +10,7 @@ using Prism.Services.Dialogs;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Collections.ObjectModel;
|
|
|
+using System.Data;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
@@ -27,7 +29,7 @@ namespace PLCTool.ViewModels.SystemManageViewModel.Dialogs
|
|
|
private readonly IMapper _mapper;
|
|
|
private List<MenuDto> allMenuInfoList = new List<MenuDto>();
|
|
|
private string basePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images");
|
|
|
-
|
|
|
+ private string initMenuHeader;
|
|
|
private int id = 0;
|
|
|
public AddEditMenuViewModel(IEventAggregator aggregator, IMenuService iMenuService, IMapper mapper)
|
|
|
{
|
|
@@ -39,15 +41,72 @@ namespace PLCTool.ViewModels.SystemManageViewModel.Dialogs
|
|
|
SureCommand = new DelegateCommand<string>(Sure);
|
|
|
CancelCommand = new DelegateCommand(Close);
|
|
|
ChangeImageCommand = new DelegateCommand(ChangeImage);
|
|
|
+
|
|
|
+ UpCommand = new DelegateCommand<object>(DataUp);
|
|
|
+ DownCommand = new DelegateCommand<object>(DataDown);
|
|
|
GetMenus();
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private void DataDown(object obj)
|
|
|
+ {
|
|
|
+ {
|
|
|
+ int id = Convert.ToInt32(obj);
|
|
|
+ var findScheExist = MenuList.FirstOrDefault(x => x.Index == id);
|
|
|
+ if (findScheExist != null)
|
|
|
+ {
|
|
|
+
|
|
|
+ int index = MenuList.IndexOf(findScheExist);
|
|
|
+ if (index != -1)
|
|
|
+ {
|
|
|
+ if (index == MenuList.Count - 1)
|
|
|
+ return;
|
|
|
+ MenuList.RemoveAt(index);
|
|
|
+ index = index + 1;
|
|
|
+ MenuList.Insert(index, findScheExist);
|
|
|
+ //现在d的排序
|
|
|
+ IndexOrder = MenuList.ToList().FindIndex(x => x.MenuHeader == initMenuHeader) + 1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void DataUp(object obj)
|
|
|
+ {
|
|
|
+ int id = Convert.ToInt32(obj);
|
|
|
+ var findScheExist = MenuList.FirstOrDefault(x => x.Index == id);
|
|
|
+ if (findScheExist != null)
|
|
|
+ {
|
|
|
+
|
|
|
+ int index = MenuList.IndexOf(findScheExist);
|
|
|
+ if (index != -1)
|
|
|
+ {
|
|
|
+ if (index == 0)
|
|
|
+ return;
|
|
|
+ MenuList.RemoveAt(index);
|
|
|
+ index = index - 1;
|
|
|
+ MenuList.Insert(index, findScheExist);
|
|
|
+ //现在d的排序
|
|
|
+ IndexOrder = MenuList.ToList().FindIndex(x => x.MenuHeader == initMenuHeader)+1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ChangeOrder()
|
|
|
+ {
|
|
|
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
#region idialog接口实现
|
|
|
- public string Title { set; get; } = "新增用户";
|
|
|
+ public string Title { set; get; } = "新增菜单";
|
|
|
|
|
|
public event Action<IDialogResult> RequestClose;
|
|
|
|
|
@@ -76,13 +135,34 @@ namespace PLCTool.ViewModels.SystemManageViewModel.Dialogs
|
|
|
var findMenu = allMenuInfoList.FirstOrDefault(x => x.MenuId == id);
|
|
|
if (findMenu != null)
|
|
|
{
|
|
|
+ //防止改名后找不到
|
|
|
+ initMenuHeader = findMenu.MenuHeader;
|
|
|
MenuHeader = findMenu.MenuHeader;
|
|
|
TargetView = findMenu.TargetView;
|
|
|
ParentId = findMenu.ParentId;
|
|
|
- MenuIcon = Path.Combine(basePath, findMenu.MenuIcon);
|
|
|
- Index = findMenu.Index;
|
|
|
+ if (!string.IsNullOrEmpty(findMenu.MenuIcon))
|
|
|
+ {
|
|
|
+ IsChangeImg = true;
|
|
|
+ MenuIcon = Path.Combine(basePath, findMenu.MenuIcon);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ IsChangeImg = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ IndexOrder = findMenu.Index;
|
|
|
+ //查找这个ParentId下的所有菜单
|
|
|
+ var findMenus=_iMenuService.FindAllByParentId(ParentId).OrderBy(x=>x.Index);
|
|
|
+ foreach(var each in findMenus)
|
|
|
+ {
|
|
|
+ MenuList.Add(new MenuDto
|
|
|
+ {
|
|
|
+ MenuHeader= each.MenuHeader,
|
|
|
+ Index=each.Index,
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -105,33 +185,42 @@ namespace PLCTool.ViewModels.SystemManageViewModel.Dialogs
|
|
|
|
|
|
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
{
|
|
|
- // 用户选择了文件
|
|
|
- string filePath = openFileDialog.FileName;
|
|
|
- string fileName = Path.GetFileName(filePath);
|
|
|
- string directoryPath = Path.GetDirectoryName(filePath);
|
|
|
- string destinationPath = Path.Combine(basePath, fileName);
|
|
|
- //就是选择当前文件下的图片,就不复制图片了
|
|
|
- if(directoryPath == basePath)
|
|
|
- {
|
|
|
- MenuIcon = destinationPath;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // 检查目标文件夹中是否已存在同名文件
|
|
|
- if (File.Exists(destinationPath))
|
|
|
+ try {
|
|
|
+ // 用户选择了文件
|
|
|
+ string filePath = openFileDialog.FileName;
|
|
|
+ string fileName = Path.GetFileName(filePath);
|
|
|
+ string directoryPath = Path.GetDirectoryName(filePath);
|
|
|
+ string destinationPath = Path.Combine(basePath, fileName);
|
|
|
+ //就是选择当前文件下的图片,就不复制图片了
|
|
|
+ if (directoryPath == basePath)
|
|
|
{
|
|
|
- // 如果存在,可以选择覆盖或抛出异常
|
|
|
- System.Windows.MessageBox.Show("已存在此图片名!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
- return;
|
|
|
+ MenuIcon = destinationPath;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- // 如果不存在,则复制文件
|
|
|
- File.Copy(filePath, destinationPath);
|
|
|
- MenuIcon = destinationPath;
|
|
|
-
|
|
|
+ // 检查目标文件夹中是否已存在同名文件
|
|
|
+ if (File.Exists(destinationPath))
|
|
|
+ {
|
|
|
+ // 如果存在,可以选择覆盖或抛出异常
|
|
|
+ System.Windows.MessageBox.Show("已存在此图片名!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // 如果不存在,则复制文件
|
|
|
+ File.Copy(filePath, destinationPath);
|
|
|
+ MenuIcon = destinationPath;
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ catch(Exception ex)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -161,18 +250,18 @@ namespace PLCTool.ViewModels.SystemManageViewModel.Dialogs
|
|
|
System.Windows.MessageBox.Show("请填写菜单界面!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
return;
|
|
|
}
|
|
|
- if (string.IsNullOrEmpty(MenuIcon))
|
|
|
- {
|
|
|
- System.Windows.MessageBox.Show("请选择图标!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
- return;
|
|
|
- }
|
|
|
+ //if (string.IsNullOrEmpty(MenuIcon))
|
|
|
+ //{
|
|
|
+ // System.Windows.MessageBox.Show("请选择图标!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ // return;
|
|
|
+ //}
|
|
|
|
|
|
//判断是否存在用户名
|
|
|
|
|
|
var findResult = allMenuInfoList.FirstOrDefault(x => x.MenuHeader == MenuHeader);
|
|
|
if (findResult != null)
|
|
|
{
|
|
|
- if (Title == "新增用户")
|
|
|
+ if (Title == "新增菜单")
|
|
|
{
|
|
|
System.Windows.MessageBox.Show("已存在此菜单名!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
return;
|
|
@@ -189,20 +278,20 @@ namespace PLCTool.ViewModels.SystemManageViewModel.Dialogs
|
|
|
}
|
|
|
|
|
|
|
|
|
- if (Title == "新增用户")
|
|
|
+ if (Title == "新增菜单")
|
|
|
{
|
|
|
- AddUser();
|
|
|
+ AddMenu();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- EditUser();
|
|
|
+ EditMenu();
|
|
|
|
|
|
}
|
|
|
|
|
|
RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
|
|
|
}
|
|
|
|
|
|
- private void AddUser()
|
|
|
+ private void AddMenu()
|
|
|
{
|
|
|
|
|
|
////添加到数据库user表中
|
|
@@ -232,7 +321,7 @@ namespace PLCTool.ViewModels.SystemManageViewModel.Dialogs
|
|
|
//}
|
|
|
|
|
|
}
|
|
|
- private void EditUser()
|
|
|
+ private void EditMenu()
|
|
|
{
|
|
|
Menu menu = new Menu()
|
|
|
{
|
|
@@ -241,14 +330,28 @@ namespace PLCTool.ViewModels.SystemManageViewModel.Dialogs
|
|
|
TargetView = TargetView,
|
|
|
ParentId = ParentId,
|
|
|
MenuIcon= Path.GetFileName(MenuIcon),
|
|
|
- Index =Index
|
|
|
+ Index =IndexOrder
|
|
|
|
|
|
};
|
|
|
//修改到数据库user表中
|
|
|
bool isedit = _iMenuService.Edit(menu);
|
|
|
+ //修改其他的排序编号
|
|
|
+ var otherMenus = _iMenuService.FindAllByParentId(ParentId);
|
|
|
+ foreach(var otherMenu in otherMenus )
|
|
|
+ {
|
|
|
+ if(otherMenu.MenuId == id )
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //更新排序
|
|
|
+ otherMenu.Index = MenuList.ToList().FindIndex(x => x.MenuHeader == otherMenu.MenuHeader) + 1; ;
|
|
|
+
|
|
|
+ _iMenuService.Edit(otherMenu);
|
|
|
+
|
|
|
+ }
|
|
|
if (isedit)
|
|
|
{
|
|
|
- System.Windows.MessageBox.Show("修改用户成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ System.Windows.MessageBox.Show("修改菜单成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -272,9 +375,10 @@ namespace PLCTool.ViewModels.SystemManageViewModel.Dialogs
|
|
|
public DelegateCommand CancelCommand { set; get; }
|
|
|
|
|
|
public DelegateCommand ChangeImageCommand { set; get; }
|
|
|
-
|
|
|
-
|
|
|
+ public DelegateCommand ChangeOrderCommand { set; get; }
|
|
|
|
|
|
+ public DelegateCommand<object> DownCommand { set; get; }
|
|
|
+ public DelegateCommand<object> UpCommand { set; get; }
|
|
|
#endregion
|
|
|
#region 变量绑定
|
|
|
private string menuHeader;
|
|
@@ -303,11 +407,11 @@ namespace PLCTool.ViewModels.SystemManageViewModel.Dialogs
|
|
|
get { return menuIcon; }
|
|
|
set { menuIcon = value; RaisePropertyChanged(); }
|
|
|
}
|
|
|
- private int index;
|
|
|
- public int Index
|
|
|
+ private int indexOrder;
|
|
|
+ public int IndexOrder
|
|
|
{
|
|
|
- get { return index; }
|
|
|
- set { index = value; RaisePropertyChanged(); }
|
|
|
+ get { return indexOrder; }
|
|
|
+ set { indexOrder = value; RaisePropertyChanged(); }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -318,6 +422,19 @@ namespace PLCTool.ViewModels.SystemManageViewModel.Dialogs
|
|
|
get { return describe; }
|
|
|
set { describe = value; RaisePropertyChanged(); }
|
|
|
}
|
|
|
+ private bool isChangeImg=true;
|
|
|
+ public bool IsChangeImg
|
|
|
+ {
|
|
|
+ get { return isChangeImg; }
|
|
|
+ set { isChangeImg = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ private ObservableCollection<MenuDto> menuList = new ObservableCollection<MenuDto>();
|
|
|
+ public ObservableCollection<MenuDto> MenuList
|
|
|
+ {
|
|
|
+ get { return menuList; }
|
|
|
+ set { SetProperty(ref menuList, value); }
|
|
|
+ }
|
|
|
|
|
|
#endregion
|
|
|
}
|