|
@@ -9,10 +9,12 @@ using Prism.Services.Dialogs;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Collections.ObjectModel;
|
|
|
+using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
+using System.Windows.Forms;
|
|
|
|
|
|
namespace PLCTool.ViewModels.SystemManageViewModel.Dialogs
|
|
|
{
|
|
@@ -24,7 +26,7 @@ namespace PLCTool.ViewModels.SystemManageViewModel.Dialogs
|
|
|
private readonly IMenuService _iMenuService;
|
|
|
private readonly IMapper _mapper;
|
|
|
private List<MenuDto> allMenuInfoList = new List<MenuDto>();
|
|
|
-
|
|
|
+ private string basePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images");
|
|
|
|
|
|
private int id = 0;
|
|
|
public AddEditMenuViewModel(IEventAggregator aggregator, IMenuService iMenuService, IMapper mapper)
|
|
@@ -36,14 +38,13 @@ namespace PLCTool.ViewModels.SystemManageViewModel.Dialogs
|
|
|
CloseCommand = new DelegateCommand(Close);
|
|
|
SureCommand = new DelegateCommand<string>(Sure);
|
|
|
CancelCommand = new DelegateCommand(Close);
|
|
|
-
|
|
|
+ ChangeImageCommand = new DelegateCommand(ChangeImage);
|
|
|
GetMenus();
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
|
|
|
#region idialog接口实现
|
|
|
public string Title { set; get; } = "新增用户";
|
|
@@ -78,7 +79,7 @@ namespace PLCTool.ViewModels.SystemManageViewModel.Dialogs
|
|
|
MenuHeader = findMenu.MenuHeader;
|
|
|
TargetView = findMenu.TargetView;
|
|
|
ParentId = findMenu.ParentId;
|
|
|
- MenuIcon = findMenu.MenuIcon;
|
|
|
+ MenuIcon = Path.Combine(basePath, findMenu.MenuIcon);
|
|
|
Index = findMenu.Index;
|
|
|
}
|
|
|
|
|
@@ -92,17 +93,57 @@ namespace PLCTool.ViewModels.SystemManageViewModel.Dialogs
|
|
|
#endregion
|
|
|
#region 私有方法
|
|
|
|
|
|
-
|
|
|
/// <summary>
|
|
|
- /// 判断输入的数据
|
|
|
+ /// 更改ico图片
|
|
|
/// </summary>
|
|
|
- /// <param name="input"></param>
|
|
|
- /// <returns></returns>
|
|
|
+ private void ChangeImage()
|
|
|
+ {
|
|
|
+ using (OpenFileDialog openFileDialog = new OpenFileDialog())
|
|
|
+ {
|
|
|
+ openFileDialog.Title = "选择图标文件";
|
|
|
+ openFileDialog.Filter = "图像文件 (*.png)|*.png";
|
|
|
+
|
|
|
+ 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))
|
|
|
+ {
|
|
|
+ // 如果存在,可以选择覆盖或抛出异常
|
|
|
+ System.Windows.MessageBox.Show("已存在此图片名!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // 如果不存在,则复制文件
|
|
|
+ File.Copy(filePath, destinationPath);
|
|
|
+ MenuIcon = destinationPath;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
private void Close()
|
|
|
{
|
|
|
- RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
|
|
|
+ RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 确认
|
|
@@ -112,17 +153,17 @@ namespace PLCTool.ViewModels.SystemManageViewModel.Dialogs
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(MenuHeader))
|
|
|
{
|
|
|
- MessageBox.Show("请填写菜单名", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ System.Windows.MessageBox.Show("请填写菜单名", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
return;
|
|
|
}
|
|
|
if (string.IsNullOrEmpty(TargetView))
|
|
|
{
|
|
|
- MessageBox.Show("请填写菜单界面!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ System.Windows.MessageBox.Show("请填写菜单界面!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
return;
|
|
|
}
|
|
|
if (string.IsNullOrEmpty(MenuIcon))
|
|
|
{
|
|
|
- MessageBox.Show("请选择图标!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ System.Windows.MessageBox.Show("请选择图标!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -133,7 +174,7 @@ namespace PLCTool.ViewModels.SystemManageViewModel.Dialogs
|
|
|
{
|
|
|
if (Title == "新增用户")
|
|
|
{
|
|
|
- MessageBox.Show("已存在此菜单名!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ System.Windows.MessageBox.Show("已存在此菜单名!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
return;
|
|
|
}
|
|
|
else
|
|
@@ -141,7 +182,7 @@ namespace PLCTool.ViewModels.SystemManageViewModel.Dialogs
|
|
|
//修改时,若查到其他的用户名和这个重复
|
|
|
if (findResult.MenuId != id)
|
|
|
{
|
|
|
- MessageBox.Show("已存在此菜单名!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ System.Windows.MessageBox.Show("已存在此菜单名!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
@@ -158,7 +199,7 @@ namespace PLCTool.ViewModels.SystemManageViewModel.Dialogs
|
|
|
|
|
|
}
|
|
|
|
|
|
- RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
|
|
|
+ RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
|
|
|
}
|
|
|
|
|
|
private void AddUser()
|
|
@@ -195,19 +236,19 @@ namespace PLCTool.ViewModels.SystemManageViewModel.Dialogs
|
|
|
{
|
|
|
Menu menu = new Menu()
|
|
|
{
|
|
|
-
|
|
|
+ MenuId= id,
|
|
|
MenuHeader = MenuHeader,
|
|
|
TargetView = TargetView,
|
|
|
ParentId = ParentId,
|
|
|
- MenuIcon= MenuIcon,
|
|
|
- Index=Index
|
|
|
+ MenuIcon= Path.GetFileName(MenuIcon),
|
|
|
+ Index =Index
|
|
|
|
|
|
};
|
|
|
//修改到数据库user表中
|
|
|
bool isedit = _iMenuService.Edit(menu);
|
|
|
if (isedit)
|
|
|
{
|
|
|
- MessageBox.Show("修改用户成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ System.Windows.MessageBox.Show("修改用户成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -230,6 +271,8 @@ namespace PLCTool.ViewModels.SystemManageViewModel.Dialogs
|
|
|
public DelegateCommand<string> SureCommand { set; get; }
|
|
|
public DelegateCommand CancelCommand { set; get; }
|
|
|
|
|
|
+ public DelegateCommand ChangeImageCommand { set; get; }
|
|
|
+
|
|
|
|
|
|
|
|
|
#endregion
|