@@ -38,10 +38,10 @@ namespace BPASmartClient.CustomResource.Pages.Model | |||||
private void AddData() | 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() {Id= IdProcess(), Permission = Permission.管理员, UserName = "admin", Password = "admin" }); ; | |||||
Global.userManager.userInfos.Add(new UserInfo() { Id = IdProcess(), Permission = Permission.操作员, UserName = "czy", Password = "123456" }); | |||||
Global.userManager.userInfos.Add(new UserInfo() { Id = IdProcess(), Permission = Permission.观察员, UserName = "gcy", Password = "654321" }); | |||||
Global.userManager.userInfos.Add(new UserInfo() { Id = IdProcess(), Permission = Permission.技术员, UserName = "jsy", Password = "88888888" }); | |||||
SaveUser(); | SaveUser(); | ||||
} | } | ||||
@@ -49,5 +49,23 @@ namespace BPASmartClient.CustomResource.Pages.Model | |||||
{ | { | ||||
File.WriteAllText("up.hbl", JsonConvert.SerializeObject(Global.userManager).AESEncrypt()); | File.WriteAllText("up.hbl", JsonConvert.SerializeObject(Global.userManager).AESEncrypt()); | ||||
} | } | ||||
public string IdProcess() | |||||
{ | |||||
erp: | |||||
string id= Guid.NewGuid().ToString(); | |||||
if (Global.userManager.userInfos.Count > 0) | |||||
{ | |||||
var res=Global.userManager.userInfos.FirstOrDefault(p => p.Id == id); | |||||
if (res != null) | |||||
{ | |||||
goto erp; | |||||
} | |||||
else | |||||
{ | |||||
return id; | |||||
} | |||||
} | |||||
return id; | |||||
} | |||||
} | } | ||||
} | } |
@@ -10,7 +10,9 @@ namespace BPASmartClient.CustomResource.Pages.Model | |||||
{ | { | ||||
public class UserInfo:ObservableObject | public class UserInfo:ObservableObject | ||||
{ | { | ||||
public Permission Permission { get { return _permission; } set { if (value is Permission per) { _permission = value; } else { _permission =(Permission) Enum.Parse(typeof(Permission), value.ToString()); } OnPropertyChanged(); } } | |||||
public string Id { get { return _id; } set { _id = value;OnPropertyChanged(); } } | |||||
private string _id; | |||||
public Permission Permission { get { return _permission; } set { _permission = value; OnPropertyChanged(); } } | |||||
private Permission _permission; | private Permission _permission; | ||||
public string UserName { get { return _userName; } set { _userName = value;OnPropertyChanged(); } } | public string UserName { get { return _userName; } set { _userName = value;OnPropertyChanged(); } } | ||||
private string _userName; | private string _userName; | ||||
@@ -478,7 +478,7 @@ | |||||
</DataGridTemplateColumn.Header> | </DataGridTemplateColumn.Header> | ||||
<DataGridTemplateColumn.CellTemplate> | <DataGridTemplateColumn.CellTemplate> | ||||
<DataTemplate> | <DataTemplate> | ||||
<ComboBox Style="{StaticResource ComboBoxStyle1}" SelectedValue="{Binding Permission}" SelectionChanged="ComboBox_SelectionChanged" ItemsSource="{Binding DataContext.Authorities, RelativeSource={RelativeSource AncestorType=DataGrid, Mode=FindAncestor}}" Foreground="SkyBlue" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="16"> | |||||
<ComboBox Style="{StaticResource ComboBoxStyle1}" Text="{Binding Permission}" Tag="{Binding Id}" SelectedItem="{Binding Permission}" SelectionChanged="ComboBox_SelectionChanged" ItemsSource="{Binding DataContext.Authorities, RelativeSource={RelativeSource AncestorType=DataGrid, Mode=FindAncestor}}" Foreground="SkyBlue" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="16"> | |||||
<ComboBox.ItemContainerStyle> | <ComboBox.ItemContainerStyle> | ||||
<Style TargetType="{x:Type ComboBoxItem}"> | <Style TargetType="{x:Type ComboBoxItem}"> | ||||
@@ -1,5 +1,11 @@ | |||||
using System; | |||||
using BPA.Message; | |||||
using BPASmartClient.CustomResource.Pages.Enums; | |||||
using BPASmartClient.CustomResource.Pages.Model; | |||||
using FryPot_DosingSystem.ViewModel; | |||||
using Newtonsoft.Json; | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.IO; | |||||
using System.Linq; | using System.Linq; | ||||
using System.Text; | using System.Text; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
@@ -27,8 +33,16 @@ namespace FryPot_DosingSystem.View | |||||
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) | private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) | ||||
{ | { | ||||
var a= (sender as ComboBox).SelectedValue; | |||||
var b= (sender as ComboBox).Text; | |||||
ComboBox cbo = sender as ComboBox; | |||||
var id = cbo.Tag; | |||||
var per = cbo.SelectedItem; | |||||
var a = UserManageViewModel.GetInstance.usersInfo.FirstOrDefault(p=>p.Id==id); | |||||
if (a != null && per != null) | |||||
{ | |||||
a.Permission = (Permission)Enum.Parse(typeof(Permission), per.ToString()); | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -17,18 +17,19 @@ namespace FryPot_DosingSystem.ViewModel | |||||
{ | { | ||||
internal class UserManageViewModel : ObservableObject | internal class UserManageViewModel : ObservableObject | ||||
{ | { | ||||
private static UserManageViewModel _instance; | |||||
public static UserManageViewModel GetInstance=>_instance??= new UserManageViewModel(); | |||||
public ObservableCollection<UserInfo> usersInfo { get; set; } = new ObservableCollection<UserInfo>(); | public ObservableCollection<UserInfo> usersInfo { get; set; } = new ObservableCollection<UserInfo>(); | ||||
public List<Permission> Authorities { get; set; } = new List<Permission>() { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }; | |||||
//public string selecttext { get; set; } = "123"; | |||||
//public List<Permission> Authorities { get; set; } = new List<Permission>() { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }; | |||||
public List<string> Authorities { get; set; } = new List<string>(); | |||||
public RelayCommand<string> SaveCommand { get; set; } | public RelayCommand<string> SaveCommand { get; set; } | ||||
public RelayCommand<string> DeleteCommand { get; set; } | public RelayCommand<string> DeleteCommand { get; set; } | ||||
public UserManageViewModel() | public UserManageViewModel() | ||||
{ | { | ||||
var userManager = JsonConvert.DeserializeObject<UserManager>(File.ReadAllText("up.hbl").AESDecrypt()); | var userManager = JsonConvert.DeserializeObject<UserManager>(File.ReadAllText("up.hbl").AESDecrypt()); | ||||
usersInfo = userManager.userInfos; | usersInfo = userManager.userInfos; | ||||
// AddAuthorities(); | |||||
AddAuthorities(); | |||||
SaveCommand = new RelayCommand<string>((str) => | SaveCommand = new RelayCommand<string>((str) => | ||||
{ | { | ||||
@@ -41,9 +42,15 @@ namespace FryPot_DosingSystem.ViewModel | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
var res = usersInfo.FirstOrDefault(p => p.UserName == str); | |||||
if (res.Id == null || res.Id == string.Empty) | |||||
{ | |||||
res.Id = IdProcess(); | |||||
} | |||||
Global.userManager.userInfos = usersInfo; | Global.userManager.userInfos = usersInfo; | ||||
File.WriteAllText("up.hbl", JsonConvert.SerializeObject(Global.userManager).AESEncrypt()); | File.WriteAllText("up.hbl", JsonConvert.SerializeObject(Global.userManager).AESEncrypt()); | ||||
MessageBox.Show("保存成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information); | MessageBox.Show("保存成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information); | ||||
} | } | ||||
} | } | ||||
@@ -69,17 +76,34 @@ namespace FryPot_DosingSystem.ViewModel | |||||
}); | }); | ||||
} | } | ||||
//private void AddAuthorities() | |||||
//{ | |||||
// foreach (Permission aut in System.Enum.GetValues(typeof(Permission))) | |||||
// { | |||||
// Authorities.Add(aut.ToString()); | |||||
// } | |||||
public string IdProcess() | |||||
{ | |||||
erp: | |||||
string id = Guid.NewGuid().ToString(); | |||||
if (usersInfo.Count > 0) | |||||
{ | |||||
var res = usersInfo.FirstOrDefault(p => p.Id == id); | |||||
if (res != null) | |||||
{ | |||||
goto erp; | |||||
} | |||||
else | |||||
{ | |||||
return id; | |||||
} | |||||
} | |||||
return id; | |||||
} | |||||
//} | |||||
private void AddAuthorities() | |||||
{ | |||||
foreach (Permission aut in System.Enum.GetValues(typeof(Permission))) | |||||
{ | |||||
Authorities.Add(aut.ToString()); | |||||
} | |||||
} | |||||
} | } | ||||
} | } |