|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- using BPASmartClient.CustomResource.Pages.Model;
- using BPASmartClient.CustomResource.Pages.View;
- using BPA.Helper;
- using BPASmartClient.Model;
- using BPA.Helper;
-
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
-
- namespace BPASmartClient.CustomResource.Pages.ViewModel
- {
- public class UserConfigViewModel:NotifyBase
- {
- /// <summary>
- /// 页面列表集合
- /// </summary>
- public ObservableCollection<UserTreeViewModel> pageTreeViewModels { get; set; } = new ObservableCollection<UserTreeViewModel>();
- /// <summary>
- /// 已选择页面
- /// </summary>
- public ObservableCollection<UserTreeViewModel> SelectePage { get; set; } = new ObservableCollection<UserTreeViewModel>();
- /// <summary>
- /// 本地原料集合
- /// </summary>
- public ObservableCollection<RawMaterialModel> LoaclMaterails { get; set; } = Json<LocaMaterial>.Data.LocalMaterails;
- /// <summary>
- /// 设备原料集合
- /// </summary>
- public ObservableCollection<RawMaterialModel> DeviceMaterails { get; set; } = Global.DeviceRawMaterials;
- /// <summary>
- /// 用户本地原料权限
- /// </summary>
- public ObservableCollection<RawMaterialModel> UserLoaclMaterails { get; set; } = new ObservableCollection<RawMaterialModel>();
- /// <summary>
- /// 用户设备原料权限
- /// </summary>
- public ObservableCollection<RawMaterialModel> UserDeviceMaterails { get; set; } = new ObservableCollection<RawMaterialModel>();
-
- /// <summary>
- /// 切换本地和设备原料权限
- /// </summary>
- public bool IsChecked { get { return _isChecked; } set { _isChecked = value;OnPropertyChanged(); } }
- private bool _isChecked = true;
-
- /// <summary>
- /// 用户名
- /// </summary>
- public string UserName { get { return _username; } set { _username = value; OnPropertyChanged(); } }
- private string _username;
- /// <summary>
- /// 本地原料权限显示
- /// </summary>
- public Visibility VisibilityLocal { get { return _visibilityLocal; } set { _visibilityLocal = value; OnPropertyChanged(); } }
- private Visibility _visibilityLocal = Visibility.Visible;
- /// <summary>
- /// 设备原料权限显示
- /// </summary>
- public Visibility VisibilityDevice { get { return _visibilityDevice; } set { _visibilityDevice = value; OnPropertyChanged(); } }
- private Visibility _visibilityDevice = Visibility.Collapsed;
-
- public BPARelayCommand<object> AddUserPageCommand { get; set; }
-
- public BPARelayCommand<object> DeleteUserPageCommand { get; set; }
-
- public BPARelayCommand<object> DeleteAllCommand { get; set; }
-
- public BPARelayCommand<object> AddAllCommand { get; set; }
-
- public BPARelayCommand<object> ChangeMaterailPageCommand { get; set; }
-
- public BPARelayCommand SaveCommand { get; set; }
-
- public BPARelayCommand CancelCommand { get; set; }
-
- public BPARelayCommand<object> AddLoaclMaterialCommand { get; set; }
-
- public BPARelayCommand<object> DeleteLoaclMaterialCommand { get; set; }
-
- public BPARelayCommand<object> AddDeviceMaterialCommand { get; set; }
-
- public BPARelayCommand<object> DeleteDeviceMaterialCommand { get; set; }
-
-
- private void AddUserPage(object o)
- {
- if (o == null) return;
- if(o is string name)
- {
- var s = SelectePage.FirstOrDefault(x => x.Name == name);
- if (!SelectePage.Contains(s))
- {
- foreach (UserTreeViewModel item in pageTreeViewModels)
- {
- var res = item.TreeViewItems.FirstOrDefault(P => P.Name == name);
- if(res != null)
- {
- SelectePage.Add(res);
- return;
- }
- }
- }
- }
- }
-
- private void DeleteUserPage(object o)
- {
- if (o == null) return;
- if (o is string name)
- {
- var res = SelectePage.FirstOrDefault(p=>p.Name == name);
- SelectePage.Remove(res);
- }
- }
-
- private void ChangeMaterailPage(object o)
- {
-
- if (o == null) return;
- if (o is string type)
- {
- if(type == "Local") {IsChecked = true;VisibilityLocal = Visibility.Visible; VisibilityDevice = Visibility.Collapsed; }
- else {IsChecked = false; VisibilityDevice = Visibility.Visible;VisibilityLocal = Visibility.Collapsed; }
-
- }
- }
-
- private void AddLoaclMaterial(object o)
- {
-
- if (o == null) return;
- if (o is string materail)
- {
- var res = LoaclMaterails.FirstOrDefault(p=>p.RawMaterialName == materail);
- if(UserLoaclMaterails.FirstOrDefault(p=>p.RawMaterialName == materail)==null) UserLoaclMaterails.Add(res);
- }
- }
-
- private void DeleteLoaclMaterial(object o)
- {
- if (o == null) return;
- if (o is string materail)
- {
- var res = UserLoaclMaterails.FirstOrDefault(p => p.RawMaterialName == materail);
- UserLoaclMaterails.Remove(res);
- }
- }
-
- private void AddDeviceMaterial(object o)
- {
- if (o == null) return;
- if (o is string materail)
- {
- var res = DeviceMaterails.FirstOrDefault(p => p.RawMaterialName == materail);
- if(UserDeviceMaterails.FirstOrDefault(p=>p.DeviceIp == res.DeviceIp) == null)
- {
- UserDeviceMaterails.Add(res);
- }
- }
- }
-
- private void DeleteDeviceMaterial(object o)
- {
- if (o == null) return;
- if (o is string materail)
- {
- var res = UserDeviceMaterails.FirstOrDefault(p => p.RawMaterialName == materail);
- UserDeviceMaterails.Remove(res);
- }
- }
-
- private void AddAll(object o)
- {
- if (o == null) return;
- if (o.ToString() == "page")
- {
- SelectePage.Clear();
- foreach (UserTreeViewModel item in pageTreeViewModels)
- {
- foreach (var res in item.TreeViewItems)
- {
- SelectePage.Add(res);
- }
- }
-
- }
- else if (o.ToString() == "local")
- {
- UserLoaclMaterails.Clear();
- foreach (RawMaterialModel item in LoaclMaterails)
- {
- UserLoaclMaterails.Add(item);
- }
- }
- else if (o.ToString() == "device")
- {
- UserDeviceMaterails.Clear();
- foreach (RawMaterialModel item in DeviceMaterails)
- {
- UserDeviceMaterails.Add(item);
- }
- }
- }
-
- private void DeleteAll(object o)
- {
- if (o == null) return;
- if(o.ToString() == "page")
- {
- SelectePage.Clear();
-
- }
- else if(o.ToString() == "local")
- {
- UserLoaclMaterails.Clear();
- }
- else if(o.ToString() == "device")
- {
- UserDeviceMaterails.Clear();
- }
- }
-
-
-
- public UserConfigViewModel()
- {
- AddUserPageCommand = new BPARelayCommand<object>(AddUserPage);
-
- DeleteUserPageCommand = new BPARelayCommand<object>(DeleteUserPage);
-
- DeleteAllCommand = new BPARelayCommand<object>(DeleteAll);
-
-
- AddAllCommand = new BPARelayCommand<object>(AddAll);
-
-
- ChangeMaterailPageCommand = new BPARelayCommand<object>(ChangeMaterailPage);
-
- SaveCommand = new BPARelayCommand(() =>
- {
- var res = Global.userManager.userInfos.FirstOrDefault(p => p.UserName == Global.changeUserInfo.UserName && p.Password == Global.changeUserInfo.Password);
- if(res != null)
- {
- res.userTreeViewModels = new List<UserTreeViewModel>();
- res.userTreeViewModels.AddRange(SelectePage);
- res.locaRawMaterials = new List<RawMaterialModel>();
- res.locaRawMaterials.AddRange(UserLoaclMaterails);
- res.devRawMaterials = new List<RawMaterialModel>();
- res.devRawMaterials.AddRange(UserDeviceMaterails);
- Config.GetInstance.SaveUser();
- }
- Global.changeUserInfo = null;
- ActionManage.GetInstance.Send("UserConfigViewConfirm");
- });
-
- CancelCommand = new BPARelayCommand(() =>
- {
- Global.changeUserInfo = null;
- ActionManage.GetInstance.Send("UserConfigViewCancel");
- });
-
- AddLoaclMaterialCommand = new BPARelayCommand<object>(AddLoaclMaterial);
-
- DeleteLoaclMaterialCommand = new BPARelayCommand<object>(DeleteLoaclMaterial);
-
- AddDeviceMaterialCommand = new BPARelayCommand<object>(AddDeviceMaterial);
-
- DeleteDeviceMaterialCommand = new BPARelayCommand<object>(DeleteDeviceMaterial);
-
-
- foreach (var item in MenuManage.GetInstance.menuModels)
- {
- List<UserTreeViewModel> list = new List<UserTreeViewModel>();
- foreach(var res in item.subMenumodels)
- {
- list.Add(new UserTreeViewModel { Name = res.SubMenuName});
- }
- pageTreeViewModels.Add(new UserTreeViewModel
- {
- Name = item.MainMenuName,
- TreeViewItems = list
- });
- }
- //用户已拥有权限
- if(Global.changeUserInfo != null)
- {
- UserName = Global.changeUserInfo.UserName;
- if (Global.changeUserInfo.userTreeViewModels != null)
- {
- if(Global.changeUserInfo.userTreeViewModels.Count > 0)
- {
- foreach(UserTreeViewModel item in Global.changeUserInfo.userTreeViewModels)
- {
- SelectePage.Add(item);
- }
- }
-
- if(Global.changeUserInfo.locaRawMaterials.Count>0)
- {
- foreach(RawMaterialModel model in Global.changeUserInfo.locaRawMaterials)
- {
- UserLoaclMaterails.Add(model);
- }
- }
-
- if (Global.changeUserInfo.devRawMaterials.Count > 0)
- {
- foreach (RawMaterialModel model in Global.changeUserInfo.devRawMaterials)
- {
- UserDeviceMaterails.Add(model);
- }
- }
- }
- }
-
-
-
-
-
-
-
-
- }
-
- }
- }
|