From 86f8fda10890e85faaebf98b16551c951104d9b0 Mon Sep 17 00:00:00 2001 From: taoye Date: Mon, 1 Aug 2022 13:14:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Pages/Model/Config.cs | 8 +- .../Pages/Model/MessageLog.cs | 2 +- .../Pages/Model/UserInfo.cs | 12 +- .../Pages/View/UserManageView.xaml | 422 ++++++++++++++++++ .../Pages/View/UserManageView.xaml.cs | 28 ++ .../Pages/ViewModel/LoginViewModel.cs | 8 +- .../Pages/ViewModel/UserManageViewModel.cs | 79 ++++ FryPot_DosingSystem/View/UserManageView.xaml | 186 ++++++-- .../View/UserManageView.xaml.cs | 6 + .../ViewModel/UserManageViewModel.cs | 30 +- 10 files changed, 713 insertions(+), 68 deletions(-) create mode 100644 BPASmartClient.CustomResource/Pages/View/UserManageView.xaml create mode 100644 BPASmartClient.CustomResource/Pages/View/UserManageView.xaml.cs create mode 100644 BPASmartClient.CustomResource/Pages/ViewModel/UserManageViewModel.cs diff --git a/BPASmartClient.CustomResource/Pages/Model/Config.cs b/BPASmartClient.CustomResource/Pages/Model/Config.cs index 16abf147..46ddd0e2 100644 --- a/BPASmartClient.CustomResource/Pages/Model/Config.cs +++ b/BPASmartClient.CustomResource/Pages/Model/Config.cs @@ -38,10 +38,10 @@ namespace BPASmartClient.CustomResource.Pages.Model private void AddData() { - Global.userManager.userInfos.Add(new UserInfo() { permission = Permission.管理员, UserName = "admin", Password = "admin" }); - Global.userManager.userInfos.Add(new UserInfo() { permission = Permission.操作员, UserName = "czy", Password = "123456" }); - Global.userManager.userInfos.Add(new UserInfo() { permission = Permission.观察员, UserName = "gcy", Password = "654321" }); - Global.userManager.userInfos.Add(new UserInfo() { permission = Permission.技术员, UserName = "jsy", Password = "88888888" }); + Global.userManager.userInfos.Add(new UserInfo() { Permission = Permission.管理员, UserName = "admin", Password = "admin" }); + Global.userManager.userInfos.Add(new UserInfo() { Permission = Permission.操作员, UserName = "czy", Password = "123456" }); + Global.userManager.userInfos.Add(new UserInfo() { Permission = Permission.观察员, UserName = "gcy", Password = "654321" }); + Global.userManager.userInfos.Add(new UserInfo() { Permission = Permission.技术员, UserName = "jsy", Password = "88888888" }); SaveUser(); } diff --git a/BPASmartClient.CustomResource/Pages/Model/MessageLog.cs b/BPASmartClient.CustomResource/Pages/Model/MessageLog.cs index da1d1e0e..0ca755ee 100644 --- a/BPASmartClient.CustomResource/Pages/Model/MessageLog.cs +++ b/BPASmartClient.CustomResource/Pages/Model/MessageLog.cs @@ -46,7 +46,7 @@ namespace BPASmartClient.CustomResource.Pages.Model { Date = DateTime.Now.ToString("yyyy-MM-dd"), Time = DateTime.Now.ToString("HH:mm:ss"), - Permission = Global.userInfo.permission.ToString(), + Permission = Global.userInfo.Permission.ToString(), UserName = Global.userInfo.UserName, LogInfo = info }; diff --git a/BPASmartClient.CustomResource/Pages/Model/UserInfo.cs b/BPASmartClient.CustomResource/Pages/Model/UserInfo.cs index 1164d95f..9bd88ea6 100644 --- a/BPASmartClient.CustomResource/Pages/Model/UserInfo.cs +++ b/BPASmartClient.CustomResource/Pages/Model/UserInfo.cs @@ -1,4 +1,5 @@ using BPASmartClient.CustomResource.Pages.Enums; +using Microsoft.Toolkit.Mvvm.ComponentModel; using System; using System.Collections.Generic; using System.Linq; @@ -7,11 +8,14 @@ using System.Threading.Tasks; namespace BPASmartClient.CustomResource.Pages.Model { - public class UserInfo + public class UserInfo:ObservableObject { - public Permission permission { get; set; } - public string UserName { get; set; } - public string Password { get; set; } + public Permission Permission { get { return _permission; } set { if (value is Permission per) { _permission = value; } else { _permission =(Permission) Enum.Parse(typeof(Permission), value.ToString()); } OnPropertyChanged(); } } + private Permission _permission; + public string UserName { get { return _userName; } set { _userName = value;OnPropertyChanged(); } } + private string _userName; + public string Password { get { return _password; } set { _password = value; OnPropertyChanged(); } } + private string _password; } } diff --git a/BPASmartClient.CustomResource/Pages/View/UserManageView.xaml b/BPASmartClient.CustomResource/Pages/View/UserManageView.xaml new file mode 100644 index 00000000..aa93f831 --- /dev/null +++ b/BPASmartClient.CustomResource/Pages/View/UserManageView.xaml @@ -0,0 +1,422 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BPASmartClient.CustomResource/Pages/View/UserManageView.xaml.cs b/BPASmartClient.CustomResource/Pages/View/UserManageView.xaml.cs new file mode 100644 index 00000000..9bbfe9f2 --- /dev/null +++ b/BPASmartClient.CustomResource/Pages/View/UserManageView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace BPASmartClient.CustomResource.Pages.View +{ + /// + /// UserManageView.xaml 的交互逻辑 + /// + public partial class UserManageView : UserControl + { + public UserManageView() + { + InitializeComponent(); + } + } +} diff --git a/BPASmartClient.CustomResource/Pages/ViewModel/LoginViewModel.cs b/BPASmartClient.CustomResource/Pages/ViewModel/LoginViewModel.cs index 75945eeb..60c66490 100644 --- a/BPASmartClient.CustomResource/Pages/ViewModel/LoginViewModel.cs +++ b/BPASmartClient.CustomResource/Pages/ViewModel/LoginViewModel.cs @@ -29,22 +29,22 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel var res = Global.userManager.userInfos.FirstOrDefault(p => p.UserName == UserName && p.Password == Password); if (res != null) { - Global.userInfo.permission = res.permission; + Global.userInfo.Permission = res.Permission; Global.userInfo.UserName = res.UserName; Global.userInfo.Password = res.Password; for (int i = 0; i < MenuManage.GetInstance.menuModels.Count; i++) { - if (MenuManage.GetInstance.menuModels.ElementAt(i).MainMenuPermission.Contains(res.permission)) + if (MenuManage.GetInstance.menuModels.ElementAt(i).MainMenuPermission.Contains(res.Permission)) MenuManage.GetInstance.menuModels.ElementAt(i).MainMenuVisibility = Visibility.Visible; else MenuManage.GetInstance.menuModels.ElementAt(i).MainMenuVisibility = Visibility.Collapsed; - if (MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.FirstOrDefault(p => p.SubMenuPermission.Contains(res.permission)) == null) + if (MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.FirstOrDefault(p => p.SubMenuPermission.Contains(res.Permission)) == null) MenuManage.GetInstance.menuModels.ElementAt(i).MainMenuVisibility = Visibility.Collapsed; for (int m = 0; m < MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.Count; m++) { - if (MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.ElementAt(m).SubMenuPermission.Contains(res.permission)) + if (MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.ElementAt(m).SubMenuPermission.Contains(res.Permission)) MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.ElementAt(m).SubMenuVisibility = Visibility.Visible; else MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.ElementAt(m).SubMenuVisibility = Visibility.Collapsed; diff --git a/BPASmartClient.CustomResource/Pages/ViewModel/UserManageViewModel.cs b/BPASmartClient.CustomResource/Pages/ViewModel/UserManageViewModel.cs new file mode 100644 index 00000000..9b42b786 --- /dev/null +++ b/BPASmartClient.CustomResource/Pages/ViewModel/UserManageViewModel.cs @@ -0,0 +1,79 @@ +using BPA.Message; +using BPASmartClient.CustomResource.Pages.Enums; +using BPASmartClient.CustomResource.Pages.Model; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; +using Newtonsoft.Json; +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; + +namespace BPASmartClient.CustomResource.Pages.ViewModel +{ + internal class UserManageViewModel:ObservableObject + { + public ObservableCollection usersInfo { get; set; } = new ObservableCollection(); + + public List Authorities { get; set; } = new List(); + + public RelayCommand SaveCommand { get; set; } + public RelayCommand DeleteCommand { get; set; } + public UserManageViewModel() + { + var userManager = JsonConvert.DeserializeObject(File.ReadAllText("up.hbl").AESDecrypt()); + usersInfo = userManager.userInfos; + AddAuthorities(); + SaveCommand = new RelayCommand((str) => + { + if (str != string.Empty && str != null) + { + int num = usersInfo.Where(p => p.UserName == str).Count(); + if (num > 0 && num >= 2) + { + MessageBox.Show("用户名重复", "提示", MessageBoxButton.OK, MessageBoxImage.Information); + } + else + { + Global.userManager.userInfos = usersInfo; + File.WriteAllText("up.hbl", JsonConvert.SerializeObject(Global.userManager).AESEncrypt()); + MessageBox.Show("保存成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information); + } + + } + }); + DeleteCommand = new RelayCommand((str) => + { + if (str != string.Empty && str != null) + { + var userInfo = usersInfo.FirstOrDefault(p => p.UserName == str); + if (userInfo != null) + { + if (usersInfo.Remove(userInfo)) + { + Global.userManager.userInfos = usersInfo; + File.WriteAllText("up.hbl", JsonConvert.SerializeObject(Global.userManager).AESEncrypt()); + } + } + else + { + MessageBox.Show("未找到对应记录", "提示", MessageBoxButton.OK, MessageBoxImage.Information); + } + } + }); + } + + private void AddAuthorities() + { + foreach (Permission aut in System.Enum.GetValues(typeof(Permission))) + { + Authorities.Add(aut.ToString()); + } + + } + } +} diff --git a/FryPot_DosingSystem/View/UserManageView.xaml b/FryPot_DosingSystem/View/UserManageView.xaml index 21955a15..621b200e 100644 --- a/FryPot_DosingSystem/View/UserManageView.xaml +++ b/FryPot_DosingSystem/View/UserManageView.xaml @@ -98,31 +98,65 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - - + + - + - - + + @@ -179,7 +213,7 @@ - + @@ -239,15 +273,41 @@ - + + + + - + - + @@ -260,9 +320,17 @@ - + + + + + + + + + @@ -283,40 +351,71 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + - - - + + - - - - + + + + + + + + + + + @@ -379,7 +478,8 @@ - + +