|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
-
- using BPA.Helper;
- using FryPot_DosingSystem.Control;
- using FryPot_DosingSystem.Model;
- using FryPot_DosingSystem.View;
- using BPA.Helper;
-
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Forms;
-
- namespace FryPot_DosingSystem.ViewModel
- {
- internal class MainViewModel : NotifyBase
- {
- public ObservableCollection<ActionMenu> menus { get; set; } = new ObservableCollection<ActionMenu>();
-
- public BPARelayCommand Login { get; set; }
- public BPARelayCommand PasswordChange { get; set; }
-
- public BPARelayCommand ExitLogin { get; set; }
- public BPARelayCommand<object> TogglePag { get; set; }
- public bool UserManagement { get { return _mUserManagement; } set { _mUserManagement = value; OnPropertyChanged(); } }
- private bool _mUserManagement;
- /// <summary>
- /// 当前登陆信息
- /// </summary>
- private UserInfo _currentLoginAccount;
- public UserInfo CurrentLoginAccount { get { return _currentLoginAccount; } set { _currentLoginAccount = value; OnPropertyChanged(); } }
- /// <summary>
- /// 不同权限显示不同菜单
- /// </summary>
- public ObservableCollection<ActionMenu> DisplayMenus { get; set; } = new ObservableCollection<ActionMenu>();
- public FrameworkElement MyWindow { get { return _mMyWindow; } set { _mMyWindow = value; OnPropertyChanged(); } }
- private FrameworkElement _mMyWindow;
-
- public string WindowTitleName { get { return _mWindowTitleName; } set { _mWindowTitleName = value; OnPropertyChanged(); } }
- private string _mWindowTitleName;
- /// <summary>
- /// 开机自启
- /// </summary>
- public bool AutoStart { get { return SystemHelper.GetInstance.IsAutoStart(); } set { SystemHelper.GetInstance.AutoStart(value); OnPropertyChanged(); } }
-
- private bool _status;
- /// <summary>
- /// 设备初始化状态
- /// </summary>
- public bool Status
- {
- get { return _status; }
- set
- {
- if (value)
- {
- ActionManage.GetInstance.Send("StartPlcInite");
- }
- else
- {
- ActionManage.GetInstance.Send("EndPlcInite");
- }
- _status = value;
- OnPropertyChanged();
- }
- }
-
- private Authority authority;
- public Authority Authority
- {
- get { return authority; }
- set
- {
- var res = menus.Where(p => Array.FindIndex(p.Authority, au => au == value) >= 0).ToList();
- if (res != null && res.Count > 0)
- {
- DisplayMenus.Clear();
- res.ForEach(p => DisplayMenus.Add(p));
- DoNavChanged(res[0].CommandParameter);
- }
- authority = value;
- }
- }
- public MainViewModel()
- {
- LogViewModel model = LogViewModel.GetInstance;
- // DeviceOperate deviceOperate = DeviceOperate.GetInstance;//开启实时PLC数据读取
- DosingLogicControl logigControl = DosingLogicControl.GetInstance;//开启逻辑控制任务程序
- TogglePag = new BPARelayCommand<object>(DoNavChanged);
- Login = new BPARelayCommand(() =>
- {
- ActionManage.GetInstance.CancelRegister("ContentUpdate");
- ActionManage.GetInstance.Register(new Func<object>(() => { return "注册"; }), "ContentUpdate");
- DoNavChanged("AdministratorLoginView.用户登陆");
- UserManagement = false;
- });
- PasswordChange = new BPARelayCommand(() =>
- {
- ActionManage.GetInstance.CancelRegister("ContentUpdate");
- ActionManage.GetInstance.Register(new Func<object>(() => { return "修改"; }), "ContentUpdate");
- ActionManage.GetInstance.CancelRegister("LoginInfo");
- ActionManage.GetInstance.Register(new Func<object>(() => { return CurrentLoginAccount; }), "LoginInfo");
- DoNavChanged("AdministratorLoginView.密码修改");
- UserManagement = false;
- });
- ExitLogin = new BPARelayCommand(() =>
- {
- //DoNavChanged("LoginView.退出登录");
- CurrentLoginAccount = null;
- Authority = Authority.观察员;
- UserManagement = false;
- });
- LoginInfoConfig.GetInstance.Init();//用户数据初始化
- LoginRegister();
- MenusDefaultInit();
- Authority = Authority.管理员;
- }
-
- private void MenusDefaultInit()
- {
- menus.Add(new ActionMenu() { MenuName = "配方设置", CommandParameter = "RecipeSetView.配方设置", Authority = new Authority[] { Authority.管理员, Authority.技术员 } });
- menus.Add(new ActionMenu() { MenuName = "配方下发", CommandParameter = "RecipeSendDownView.配方下发", Authority = new Authority[] { Authority.管理员, Authority.技术员, Authority.操作员 } });
- menus.Add(new ActionMenu() { MenuName = "设备列表", CommandParameter = "DeviceListVIew.设备列表", Authority = new Authority[] { Authority.管理员, Authority.技术员, Authority.操作员, Authority.观察员 } });
- menus.Add(new ActionMenu() { MenuName = "状态监测", CommandParameter = "HardWareStatusView.状态监测", Authority = new Authority[] { Authority.管理员, Authority.技术员, Authority.操作员, Authority.观察员 } });
- menus.Add(new ActionMenu() { MenuName = "日志信息", CommandParameter = "LogView.日志信息", Authority = new Authority[] { Authority.管理员, Authority.技术员, Authority.操作员, Authority.观察员 } });
- menus.Add(new ActionMenu() { MenuName = "报警记录", CommandParameter = "", Authority = new Authority[] { Authority.管理员, Authority.技术员, Authority.操作员, Authority.观察员 } });
-
- }
-
- public void DoNavChanged(object obj)
- {
- if (obj != null && obj is string stobj)
- {
- var strs = stobj.Split('.');
- if (strs != null && strs.Length == 2)
- {
- Type type = Type.GetType($"FryPot_DosingSystem.View.{strs[0]}");
- var res = type?.GetConstructor(System.Type.EmptyTypes)?.Invoke(null);
- if (res != null && res is FrameworkElement fe) MyWindow = fe;
- WindowTitleName = strs[1];
- }
- }
- }
- /// <summary>
- /// 登陆验证
- /// </summary>
- private void LoginRegister()
- {
- ActionManage.GetInstance.Register(new Func<object, object>((o) =>
- {
- if (o != null && o is string str)
- {
- var strs = str.Split("-=");
- if (strs != null && strs.Length == 3)
- {
- var us = Global.userManager.userInfos.FirstOrDefault(p => p.UserName == strs[0] && p.Password == strs[1] && strs[2] == p.Authority.ToString());
- if (us != null)
- {
- Authority = us.Authority;
- CurrentLoginAccount = us;//记录当前登陆信息
- return string.Empty;
- }
- }
- }
- return "用户名或密码错误";
- }), "LoginDosingSystem");
- }
- }
- }
|