ltwork 1 سال پیش
والد
کامیت
a431c1ed8c

+ 25 - 0
BlankApp1/BlankApp1/App.xaml.cs

@@ -133,6 +133,31 @@ namespace BlankApp1
          
           
         }
+        /// <summary>
+        /// 退出登录
+        /// </summary>
+        /// <param name="containerProvider"></param>
+        public static void LoginOut(IContainerProvider containerProvider)
+        {
+            Current.MainWindow.Hide();
+
+            var dialog = containerProvider.Resolve<IDialogService>();
+
+            dialog.ShowDialog("LoginView", callback =>
+            {
+                if (callback.Result != ButtonResult.OK)
+                {
+                    Environment.Exit(0);
+                    return;
+                }
+
+                //调试发现service为MainViewModel
+                var service = App.Current.MainWindow.DataContext as IConfigureService;
+                if (service != null)
+                    service.Configure();
+                Current.MainWindow.Show();
+            });
+        }
 
     }
 }

+ 25 - 10
BlankApp1/BlankApp1/ViewModels/MainWindowViewModel.cs

@@ -10,6 +10,7 @@ using PLCTool.Events;
 using PLCTool.Models;
 using Prism.Commands;
 using Prism.Events;
+using Prism.Ioc;
 using Prism.Mvvm;
 using Prism.Regions;
 
@@ -27,7 +28,7 @@ namespace BlankApp1.ViewModels
         private readonly ILogger _logger;
         private readonly IRegionManager _regionManager;
         private readonly IMapper _mapper;
-
+        private readonly IContainerProvider _containerProvider;
         private string _title = "Prism Application";
         private IRegionNavigationJournal journal;
         public string Title
@@ -36,16 +37,18 @@ namespace BlankApp1.ViewModels
             set { SetProperty(ref _title, value); }
         }
 
-        public MainWindowViewModel(IRegionManager regionManager,ILogger logger, IEventAggregator aggregator, IProductService productService, IMapper mapper)
+        public MainWindowViewModel(IRegionManager regionManager,ILogger logger, IEventAggregator aggregator, IMapper mapper, IContainerProvider containerProvider)
         {
             this._regionManager = regionManager;
             this._logger = logger;
             this._mapper = mapper;
-        
+            this._containerProvider = containerProvider;
             ButtonNavigateCommand = new DelegateCommand<string>(ButtonNavigate);
             BackCommand = new DelegateCommand(GoBack);
             NextCommand = new DelegateCommand(GoNext);
             BreadChangedCommand = new DelegateCommand<object>(BreadChangedC);
+            LoginOutCommand = new DelegateCommand<object>(LoginOut);
+            OnLoadCommand = new DelegateCommand(OnLoad);
             JudgePLC();
             logger.LogInformation("info");
             logger.LogError("error");
@@ -55,6 +58,16 @@ namespace BlankApp1.ViewModels
          
         }
 
+        private void OnLoad()
+        {
+  
+        }
+
+        private void LoginOut(object obj)
+        {
+            App.LoginOut(_containerProvider);
+        }
+
         private void DisplayMask(bool isVis)
         {
             IsMaskVisible=isVis;
@@ -111,12 +124,12 @@ namespace BlankApp1.ViewModels
         /// </summary>
         public void Configure()
         {
-
+            UserName = Appsession.UserName;
             //默认进入简报页面
             _regionManager.Regions["ContentRegion"].RequestNavigate("LogView");
             _regionManager.Regions["MenuRegion"].RequestNavigate("TreeMenuView");
             _regionManager.Regions["ContentRegion"].RequestNavigate("StatisticsView");
-            UserName=Appsession.UserName;
+         
         }
         /// <summary>
         /// 连接PLC
@@ -146,14 +159,16 @@ namespace BlankApp1.ViewModels
         public DelegateCommand<string> ButtonNavigateCommand { set; get; }
         public DelegateCommand NextCommand { set; get; }
         public DelegateCommand BackCommand { set; get; }
-
+        public DelegateCommand OnLoadCommand { set; get; }
         public DelegateCommand<object> BreadChangedCommand { set; get; }
-      
+        public DelegateCommand<object> LoginOutCommand { set; get; }
+        
+
         #endregion
         #region 数据绑定
-            /// <summary>
-            /// 面包削
-            /// </summary>
+        /// <summary>
+        /// 面包削
+        /// </summary>
         private ObservableCollection<CrumbViewModel> _path = new ObservableCollection<CrumbViewModel>();
         public ObservableCollection<CrumbViewModel> Path
         {

+ 5 - 0
BlankApp1/BlankApp1/ViewModels/SystemManageViewModel/UserManageViewModel.cs

@@ -117,6 +117,11 @@ namespace PLCTool.ViewModels.SystemManageViewModel
         private void Delete(object obj)
         {
             int id = Convert.ToInt32(obj);
+            var user = _iUserService.Find(id);
+            if (user != null)
+            {
+                 MessageBox.Show("管理员用户无法删除!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
+            }
             MessageBoxResult boxResult = MessageBox.Show("确认删除此条数据?", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Question);
             if (boxResult == MessageBoxResult.OK)
             {

+ 27 - 9
BlankApp1/BlankApp1/ViewModels/TreeMenuViewModel.cs

@@ -2,6 +2,8 @@
 using BlankApp1.Models;
 using Model.Entities;
 using PLCTool.Common;
+using Prism.Commands;
+using Prism.Mvvm;
 using Prism.Regions;
 using SqlSugar;
 using System;
@@ -15,10 +17,12 @@ using static System.Windows.Forms.VisualStyles.VisualStyleElement;
 
 namespace BlankApp1.ViewModels
 {
-    public class TreeMenuViewModel
+    public class TreeMenuViewModel:BindableBase
     {
+        private readonly IMenuService _menuService;
+        private readonly IRoleMenuService _iRoleMenuService;
         public List<MenuItemModel> Menus { get; set; } = new List<MenuItemModel>();
-
+    
         // 列表,没有树型结构
         private List<Model.Entities.Menu> origMenus = new List<Model.Entities.Menu>();
         private string basePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images");
@@ -27,29 +31,42 @@ namespace BlankApp1.ViewModels
         public TreeMenuViewModel(IRegionManager regionManager, IMenuService menuService,IRoleMenuService iRoleMenuService)
         {
             _regionManager = regionManager;
+            _iRoleMenuService = iRoleMenuService;
+            _menuService = menuService;
+            OnLoadCommand = new DelegateCommand(OnLoad);
+            GetMenu();
+        }
+
+        private void OnLoad()
+        {
+            
+
+        }
+
+        private void GetMenu()
+        {
             // 需要获取菜单数据
             try
             {
                 //查找这个角色的菜单
 
-                var roleMenus= iRoleMenuService.FindAllByRoleId(Appsession.RoleId);
-                foreach(var menu in roleMenus)
+                var roleMenus = _iRoleMenuService.FindAllByRoleId(Appsession.RoleId);
+                foreach (var menu in roleMenus)
                 {
-                    var findMenu = menuService.Find((int)menu.MenuId);
-                    if(findMenu != null)
+                    var findMenu = _menuService.Find((int)menu.MenuId);
+                    if (findMenu != null)
                     {
                         origMenus.Add(findMenu);
                     }
-                   
+
                 }
                 this.FillMenus(Menus, 0);
             }
-             catch(Exception ex)
+            catch (Exception ex)
             {
                 MessageBoxResult boxResult = MessageBox.Show("初始化失败,请检查与数据库的链接!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                 return;
             }
-
         }
 
         public  string EscapeUnicode( string str)  // 将字符串编码为unicode转义序列(\uxxxx)
@@ -107,5 +124,6 @@ namespace BlankApp1.ViewModels
                 }
             }
         }
+        public DelegateCommand OnLoadCommand { set; get; }
     }
 }

+ 13 - 2
BlankApp1/BlankApp1/Views/MainWindow.xaml

@@ -3,7 +3,7 @@
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:prism="http://prismlibrary.com/"
         xmlns:convt="clr-namespace:PLCTool.Controls.Convert"
-          xmlns:wpfdev="https://github.com/WPFDevelopersOrg/WPFDevelopers"
+        xmlns:wpfdev="https://github.com/WPFDevelopersOrg/WPFDevelopers"
         xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
         Title="MainWindow" 
         prism:ViewModelLocator.AutoWireViewModel="True"
@@ -87,10 +87,16 @@
                 </Trigger>
             </Style.Triggers>
         </Style>
+     
         <convt:Bool2ColorConverter x:Key="boolToColorConvert"/>
         <convt:BooleanToVisibilityConverter x:Key="BoolToVis"/>
     </Window.Resources>
     <Grid>
+        <b:Interaction.Triggers>
+            <b:EventTrigger EventName="Loaded">
+                <b:InvokeCommandAction Command="{Binding OnLoadCommand}"/>
+            </b:EventTrigger>
+        </b:Interaction.Triggers>
         <Grid.RowDefinitions>
             <RowDefinition Height="60"/>
             <RowDefinition />
@@ -106,7 +112,12 @@
             <StackPanel  Orientation="Horizontal" HorizontalAlignment="Right" Margin=" 0,0,14,0">
                 <TextBlock x:Name="txtTime" Foreground="#ffffff" VerticalAlignment="Center" Margin="0,0,18,0"/>
                 <Image Source="../Assets/Images/register.png" Height="21" Width="21"></Image>
-                <TextBlock Text="{Binding UserName}"  VerticalAlignment="Center" Margin="5,0,8,0"/>
+               
+                <Menu VerticalAlignment="Center" Width="auto">
+                    <MenuItem Header="{Binding UserName}" Width="auto" Command="{Binding LoginOutCommand}">
+                        <!--<MenuItem Header="注销" Width="60" Command="{Binding LoginOutCommand}"/>-->
+                    </MenuItem>
+                </Menu>
                 <TextBlock Text="|" Style="{StaticResource txtHeadStyle}" Margin="0,0,17,0" Width="2" Height=" 20"></TextBlock>
                 <Button  x:Name="btnMin" Content="—"  Click="btnMin_Click"  Style="{StaticResource IconButtonStyle}"/>
                 <Button  x:Name="btnMax" Click="btnMax_Click" Content="&#xe60d;" FontFamily="../Assets/Fonts/#iconfont"   Style="{StaticResource IconButtonStyle}"/>

+ 7 - 1
BlankApp1/BlankApp1/Views/TreeMenuView.xaml

@@ -4,11 +4,17 @@
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:local="clr-namespace:BlankApp1.Views"
-              xmlns:cvt="clr-namespace:PLCTool.Controls.Convert"
+             xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
+             xmlns:cvt="clr-namespace:PLCTool.Controls.Convert"
              mc:Ignorable="d" 
              d:DesignHeight="450" d:DesignWidth="800">
 
     <Grid Background="White" >
+        <b:Interaction.Triggers>
+            <b:EventTrigger EventName="Loaded">
+                <b:InvokeCommandAction Command="{Binding OnLoadCommand}"/>
+            </b:EventTrigger>
+        </b:Interaction.Triggers>
         <Grid.Resources>
             <cvt:StringToImageSourceConverter x:Key="MyImageConverter"/>
             <ControlTemplate TargetType="ToggleButton" x:Key="ArrowButtonTemplate">