|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- 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.Media;
- using BPASmartClient.CustomResource.Pages.Model;
- using BPASmartClient.Helper;
- using BPASmartClient.Model;
- using Microsoft.Toolkit.Mvvm.ComponentModel;
- using Microsoft.Toolkit.Mvvm.Input;
-
- namespace BPASmartClient.CustomResource.Pages.ViewModel
- {
- public class MainViewModel : ObservableObject
- {
- public MainViewModel()
- {
- NavChangedCommand = new RelayCommand<object>(DoNavChanged);
- BPA.Helper.MessageLog.GetInstance.NotifyShow = new Action<string>((o) =>
- {
- Application.Current?.Dispatcher?.Invoke(() =>
- {
- //ff20aefe
- var temp = new MessageModel()
- {
- LogInfo = o,
- Forground = new SolidColorBrush(Color.FromArgb(255, 32, 174, 254))
- };
- if (DebugLogViewModel.MessageModels.Count > 0)
- DebugLogViewModel.MessageModels.Insert(0, temp);
- else
- DebugLogViewModel.MessageModels.Add(temp);
- });
- });
- BPA.Helper.MessageLog.GetInstance.NotifyShowEx = new Action<string>((o) =>
- {
- Application.Current?.Dispatcher?.Invoke(() =>
- {
- //FFF53F62
- var temp = new MessageModel()
- {
- LogInfo = o,
- Forground = new SolidColorBrush(Color.FromArgb(255, 245, 63, 98))
- };
- if (DebugLogViewModel.MessageModels.Count > 0)
- DebugLogViewModel.MessageModels.Insert(0, temp);
- else
- DebugLogViewModel.MessageModels.Add(temp);
- });
-
-
- });
- menuModels = MenuManage.GetInstance.menuModels;
- PermissionChange();
- ActionManage.GetInstance.Register(new Action(() =>
- {
- PermissionChange();
- }), "PermissionChange");
- }
-
- private void PermissionChange()
- {
- int MainIndex = Array.FindIndex(menuModels.ToArray(), P => P.MainMenuVisibility == Visibility.Visible);
- if (MainIndex >= 0 && MainIndex < menuModels.Count)
- {
- int SubIndex; SubIndex = Array.FindIndex(menuModels.ElementAt(MainIndex).subMenumodels.ToArray(), p => p.SubMenuVisibility == Visibility.Visible);
- if (SubIndex >= 0 && SubIndex < menuModels.ElementAt(MainIndex).subMenumodels.Count)
- {
- //DoNavChanged(menuModels.ElementAt(MainIndex).subMenumodels.ElementAt(SubIndex).ToggleWindowPath);
- DoNavChanged(menuModels.ElementAt(MainIndex).subMenumodels.ElementAt(SubIndex));
- }
- }
- }
-
- public ObservableCollection<MenuModel> menuModels { get; set; }
-
- private void DoNavChanged(object obj)
- {
- if (obj != null && obj is SubMenumodel menumodel)
- {
- DisplayName = menumodel.SubMenuName;
- var end = menumodel.AssemblyName.Substring(menumodel.AssemblyName.Length - 1);
- var start = menumodel.ToggleWindowPath.Substring(0, 1);
- bool isAddPoint = end != "." && start != ".";
- string point = isAddPoint ? "." : "";
- Type type = Assembly.Load(menumodel.AssemblyName)?.GetType($"{menumodel.AssemblyName}{point}{menumodel.ToggleWindowPath}");
- ConstructorInfo cti = type?.GetConstructor(System.Type.EmptyTypes);
- if (type?.BaseType.Name == "Window") ((Window)cti?.Invoke(null)).ShowDialog();
- else if (type?.BaseType.Name == "UserControl")
- {
- MainContent = null;
- MainContent = (FrameworkElement)cti?.Invoke(null);
- MainContent?.GetType()?.GetProperty("Name").SetValue(MainContent, menumodel.SubMenuName);
- }
- }
- }
- 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();
- }
- }
- /// <summary>
- /// 开机自启
- /// </summary>
- public bool AutoStart { get { return SystemHelper.GetInstance.IsAutoStart(); } set { SystemHelper.GetInstance.AutoStart(value); OnPropertyChanged(); } }
- public RelayCommand<object> NavChangedCommand { get; set; }
-
- public FrameworkElement MainContent { get { return _mMainContent; } set { _mMainContent = value; OnPropertyChanged(); } }
- private FrameworkElement _mMainContent;
-
- public string DisplayName { get { return _mDisplayName; } set { _mDisplayName = value; OnPropertyChanged(); } }
- private string _mDisplayName;
-
-
-
- }
- }
|