Quellcode durchsuchen

添加菜单修改功能

ltwork vor 1 Jahr
Ursprung
Commit
c356647726

+ 2 - 2
BlankApp1/BlankApp1/Common/Appsession.cs

@@ -9,8 +9,8 @@ namespace PLCTool.Common
 {
     public  class Appsession
     {
-        public static string UserName = "Admin"; 
-
+        public static string UserName = "Admin";
+        public static int UserId=0;
         public static int RoleId = -1;
   
     }

+ 15 - 2
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/DeviceTestViewModel.cs

@@ -33,6 +33,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         private readonly IBasicPlcTestSchemeService _basicPlcTestSchemeService;
         private readonly IBizTestRecordService _iBizTestRecordService;
         private readonly IBizTestRecordDtlService _iBizTestRecordDtlService;
+        private readonly IUserDeviceService _iUserDeviceService;
         private readonly IMapper _mapper;
         private readonly IDialogService _dialog;
         private readonly ILogger _logger;
@@ -41,7 +42,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         private List<BasDeviceWithSchModel> allDeviceList = new List<BasDeviceWithSchModel>();//所有设备
         private List<BasDeviceWithSchModel> conditionDevices = new List<BasDeviceWithSchModel>();//符合条件的方案
         private string selectProjectName;
-        public DeviceTestViewModel(IRegionManager regionManager,IBasicDeviceService iBasicDeviceService, IBasicDeviceKindService iBasicDeviceKindService, IBasicProjectService iBasicProjectService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBizTestRecordService iBizTestRecordService, IBizTestRecordDtlService iBizTestRecordDtlService, IMapper mapper, IDialogService dialog, ILogger logger, IEventAggregator aggregator)
+        public DeviceTestViewModel(IRegionManager regionManager,IBasicDeviceService iBasicDeviceService, IBasicDeviceKindService iBasicDeviceKindService, IBasicProjectService iBasicProjectService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBizTestRecordService iBizTestRecordService, IBizTestRecordDtlService iBizTestRecordDtlService, IUserDeviceService iUserDeviceService,IMapper mapper, IDialogService dialog, ILogger logger, IEventAggregator aggregator)
         {
             _regionManager = regionManager;
             _iBasicDeviceService = iBasicDeviceService;
@@ -50,6 +51,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             _basicPlcTestSchemeService = basicPlcTestSchemeService;
             _iBizTestRecordService = iBizTestRecordService;
             _iBizTestRecordDtlService=iBizTestRecordDtlService;
+            _iUserDeviceService = iUserDeviceService;
             _mapper = mapper;
             _dialog = dialog;
             _logger = logger;
@@ -320,7 +322,17 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                 int count = 0;
                 foreach (var item in allDeviceKinds)
                 {
-
+                    //用户查找拥有设备
+                    var deviceAllByUser = _iUserDeviceService.FindAllByUserId(Appsession.UserId);
+                    if (deviceAllByUser != null)
+                    {
+                        var findDevice = deviceAllByUser.FirstOrDefault(x => x.DeviceId == item.DeviceId);
+                        if (findDevice == null)
+                        {
+                            //用户没有这个设备 跳出
+                            continue;
+                        }
+                    }
 
                     string projectName = _iBasicProjectService.Find((int)item.ProjectId)?.project_name;
                     string deviceKindName = _iBasicDeviceKindService.Find((int)item.DeviceKindId)?.devicekind_name;
@@ -367,6 +379,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                     //只添加选择的项目
                     if (projectName == selectProjectName)
                     {
+                       
                         count++;
                         allDeviceList.Add(new BasDeviceWithSchModel()
                         {   

+ 15 - 2
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/ResultQueryViewModel.cs

@@ -22,6 +22,7 @@ using System.Windows;
 using Prism.Regions;
 using PLCTool.Events;
 using Prism.Events;
+using PLCTool.Common;
 
 namespace PLCTool.ViewModels.BusinessManageViewModel
 {
@@ -37,6 +38,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         private readonly IBizTestRecordDtlService _iBizTestRecordDtlService;
         private readonly IBizTestRecordService _iBizTestRecordService;
         private readonly IBasicPlcTestSchemeDtlService _iBasicPlcTestSchemeDtlService;
+        private readonly IUserDeviceService _iUserDeviceService;
         private readonly IMapper _mapper;
         private readonly IDialogService _dialog;
         private readonly ILogger _logger;
@@ -45,7 +47,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         private List<DeviceDtlWithResultModel> allDeviceList = new List<DeviceDtlWithResultModel>();//所有方案
         private List<DeviceDtlWithResultModel> conditionDevices = new List<DeviceDtlWithResultModel>();//符合条件的方案
         private string selectProjectName;
-        public ResultQueryViewModel(IBasicDeviceService iBasicDeviceService, IBasicDeviceKindService iBasicDeviceKindService, IBasicProjectService iBasicProjectService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBizTestRecordDtlService iBizTestRecordDtlService, IBizTestRecordService iBizTestRecordService, IBasicPlcTestSchemeDtlService iBasicPlcTestSchemeDtlService, IRegionManager regionManager,IMapper mapper, IDialogService dialog, ILogger logger, IEventAggregator aggregator)
+        public ResultQueryViewModel(IBasicDeviceService iBasicDeviceService, IBasicDeviceKindService iBasicDeviceKindService, IBasicProjectService iBasicProjectService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBizTestRecordDtlService iBizTestRecordDtlService, IBizTestRecordService iBizTestRecordService, IBasicPlcTestSchemeDtlService iBasicPlcTestSchemeDtlService, IUserDeviceService iUserDeviceService, IRegionManager regionManager,IMapper mapper, IDialogService dialog, ILogger logger, IEventAggregator aggregator)
         {
             _iBasicDeviceService = iBasicDeviceService;
             _iBasicDeviceKindService = iBasicDeviceKindService;
@@ -54,6 +56,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             _iBizTestRecordService= iBizTestRecordService;
             _iBizTestRecordDtlService= iBizTestRecordDtlService;
             _iBasicPlcTestSchemeDtlService = iBasicPlcTestSchemeDtlService;
+            _iUserDeviceService = iUserDeviceService;
             _regionManager = regionManager;
             _mapper = mapper;
             _dialog = dialog;
@@ -275,7 +278,17 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                 List<DateTime> endDateTimes = new List<DateTime>();
                 var deviceMsg = _iBasicDeviceService.Find(((int)deviceId));
                 if(deviceMsg != null)
-                {
+                {   //用户查找拥有设备
+                    var deviceAllByUser = _iUserDeviceService.FindAllByUserId(Appsession.UserId);
+                    if (deviceAllByUser != null)
+                    {
+                        var findDevice = deviceAllByUser.FirstOrDefault(x => x.DeviceId == deviceMsg.device_id);
+                        if (findDevice == null)
+                        {  //用户没有这个设备 跳出
+                            continue;
+                        }
+                    }
+
                     string deviceKind = _iBasicDeviceKindService.Find((int)deviceMsg.device_kind_id)?.devicekind_name;
                     string projectName = _iBasicProjectService.Find((int)deviceMsg.project_id)?.project_name;
                     //记录设备下的方案通过个数

+ 1 - 0
BlankApp1/BlankApp1/ViewModels/LoginViewModel.cs

@@ -72,6 +72,7 @@ namespace PLCTool.ViewModels
                 {
                     Appsession.RoleId = (int)userRole.RoleId;
                     Appsession.UserName=userName;
+                    Appsession.UserId = userId;
                 }
                 RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
             }

+ 63 - 20
BlankApp1/BlankApp1/ViewModels/SystemManageViewModel/Dialogs/AddEditMenuViewModel.cs

@@ -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

+ 7 - 1
BlankApp1/BlankApp1/ViewModels/SystemManageViewModel/MenuManageViewModel.cs

@@ -58,7 +58,9 @@ namespace PLCTool.ViewModels.SystemManageViewModel
             _aggregator.GetEvent<BreadEvent>().Publish(breadCrumbs);
         }
         private void AddMenu(object obj)
-        {
+        { 
+            //蒙层显示
+            _aggregator.GetEvent<MaskEvent>().Publish(true);
             _dialog.ShowDialog("AddEditMenuView", async callback =>
             {
                 if (callback.Result == ButtonResult.OK)
@@ -67,6 +69,8 @@ namespace PLCTool.ViewModels.SystemManageViewModel
                 }
 
             });
+            //蒙层显示
+            _aggregator.GetEvent<MaskEvent>().Publish(false);
         }
 
         private void EditMenu(object obj)
@@ -85,6 +89,8 @@ namespace PLCTool.ViewModels.SystemManageViewModel
                 }
 
             });
+            //蒙层
+            _aggregator.GetEvent<MaskEvent>().Publish(false);
         }
 
         private void Delete(object obj)

+ 4 - 3
BlankApp1/BlankApp1/Views/SystemManageView/Dialogs/AddEditMenuView.xaml

@@ -4,7 +4,7 @@
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:local="clr-namespace:PLCTool.Views.SystemManageView.Dialogs"
-                         xmlns:prism="http://prismlibrary.com/"
+             xmlns:prism="http://prismlibrary.com/"
              xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
              xmlns:pass="clr-namespace:PLCTool.Common.Extension"
              Height="300" Width="400" BorderBrush="#CBCBCB" BorderThickness="1">
@@ -27,11 +27,12 @@
       
         <StackPanel Orientation="Horizontal" Grid.Row="2" HorizontalAlignment="Center">
             <TextBlock Text="父Id:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0" TextAlignment="Right" Width="80"/>
-            <TextBox  Height="28" Width="120" Text="{Binding ParentId}" />
+            <TextBox  Height="28" Width="120" Text="{Binding ParentId}"  />
         </StackPanel>
         <StackPanel Orientation="Horizontal" Grid.Row="3" HorizontalAlignment="Center">
             <TextBlock Text="图标:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0" TextAlignment="Right" Width="80"/>
-            <TextBox  Height="28" Width="120" Text="{Binding MenuIcon}" />
+            <Image Source="{Binding MenuIcon}" Width="20" Height="20" HorizontalAlignment="Left"></Image>
+            <Button  Content="更换图标" Width="80"  Margin="5,0"  Command="{Binding ChangeImageCommand}"  Style="{StaticResource NormalButtonStyle}" />
         </StackPanel>