From 3027c288c3fa9937be4a37238599025256772072 Mon Sep 17 00:00:00 2001 From: hsc Date: Fri, 21 Nov 2025 11:46:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=A7=86=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BOB/App.xaml.cs | 2 + BOB/BOB.csproj | 1 + BOB/Singleton/Devices.cs | 46 ++-- BOB/Singleton/StepRunning.cs | 2 +- BOB/SystemConfig.cs | 2 + BOB/ViewModels/CommandTreeViewModel.cs | 1 + BOB/ViewModels/DataViewModel.cs | 48 ++++ BOB/ViewModels/MainViewModel.cs | 46 +--- BOB/ViewModels/MonitorViewModel.cs | 353 +++++++++++++++++++++++++ BOB/ViewModels/ShellViewModel.cs | 34 ++- BOB/Views/DataView.xaml | 60 +++++ BOB/Views/DataView.xaml.cs | 28 ++ BOB/Views/MonitorView.xaml | 139 ++++++++++ BOB/Views/MonitorView.xaml.cs | 28 ++ BOB/Views/ShellView.xaml | 17 +- DeviceCommand/Device/E36233A.cs | 46 ++-- DeviceCommand/Device/EAEL9080.cs | 60 ++--- DeviceCommand/Device/IOBoard.cs | 4 +- DeviceCommand/Device/IT6724C.cs | 48 ++-- DeviceCommand/Device/IT6724CReverse.cs | 102 ++----- DeviceCommand/Device/LQ7500-D.cs | 38 ++- DeviceCommand/Device/PSB11000.cs | 166 ++---------- DeviceCommand/Device/SQ0030G1D.cs | 49 ++-- DeviceCommand/Device/WS-68030-380T.cs | 135 +++------- DeviceCommand/DeviceCommand.csproj | 2 + Logger/LoggingInterceptor.cs | 9 +- 26 files changed, 962 insertions(+), 504 deletions(-) create mode 100644 BOB/ViewModels/DataViewModel.cs create mode 100644 BOB/ViewModels/MonitorViewModel.cs create mode 100644 BOB/Views/DataView.xaml create mode 100644 BOB/Views/DataView.xaml.cs create mode 100644 BOB/Views/MonitorView.xaml create mode 100644 BOB/Views/MonitorView.xaml.cs diff --git a/BOB/App.xaml.cs b/BOB/App.xaml.cs index 1fb808a..5fd252b 100644 --- a/BOB/App.xaml.cs +++ b/BOB/App.xaml.cs @@ -50,6 +50,8 @@ namespace BOB { //注册视图 containerRegistry.RegisterForNavigation("MainView"); + containerRegistry.RegisterForNavigation("MonitorView"); + containerRegistry.RegisterForNavigation("DataView"); //注册弹窗 containerRegistry.RegisterDialog("MessageBox"); containerRegistry.RegisterDialog("ParameterSetting"); diff --git a/BOB/BOB.csproj b/BOB/BOB.csproj index ee993ec..3f9f277 100644 --- a/BOB/BOB.csproj +++ b/BOB/BOB.csproj @@ -39,6 +39,7 @@ + diff --git a/BOB/Singleton/Devices.cs b/BOB/Singleton/Devices.cs index ac5b903..2634301 100644 --- a/BOB/Singleton/Devices.cs +++ b/BOB/Singleton/Devices.cs @@ -32,7 +32,10 @@ namespace BOB.Singleton private ITcp SQ0030G1DTDevice { get; set; } private IModbusDevice ZXKSTDevice { get; set; } - public Devices(List deviceList) + public Devices() + { + } + public void Init(List deviceList) { foreach (var device in deviceList) { @@ -43,10 +46,10 @@ namespace BOB.Singleton case "DeviceCommand.Device.E36233A": if (device.CommunicationConfig is TcpConfig tcp1) { - E36233ADevice = _proxyGen.CreateInterfaceProxyWithTarget( - new E36233A(tcp1.IPAddress, tcp1.Port, tcp1.ReadTimeout, tcp1.WriteTimeout), - _loggingInterceptor - ); + E36233ADevice = _proxyGen.CreateClassProxyWithTarget( + new E36233A(tcp1.IPAddress, tcp1.Port, tcp1.ReadTimeout, tcp1.WriteTimeout), + _loggingInterceptor + ); DeviceDic["E36233A"] = E36233ADevice; } else throw new InvalidOperationException("E36233A 必须使用 TcpConfig"); @@ -55,10 +58,10 @@ namespace BOB.Singleton case "DeviceCommand.Device.IT6724C": if (device.CommunicationConfig is SerialPortConfig sp1) { - IT6724CDevice = _proxyGen.CreateInterfaceProxyWithTarget( - new IT6724C(sp1.COMPort, sp1.BaudRate, sp1.DataBit, sp1.StopBit, sp1.ParityBit, sp1.ReadTimeout, sp1.WriteTimeout), - _loggingInterceptor - ); + IT6724CDevice = _proxyGen.CreateClassProxyWithTarget( + new IT6724C(sp1.COMPort, sp1.BaudRate, sp1.DataBit, sp1.StopBit, sp1.ParityBit, sp1.ReadTimeout, sp1.WriteTimeout), + _loggingInterceptor + ); DeviceDic["IT6724C"] = IT6724CDevice; } else throw new InvalidOperationException("IT6724C 必须使用 SerialPortConfig"); @@ -67,19 +70,19 @@ namespace BOB.Singleton case "DeviceCommand.Device.IT6724CReverse": if (device.CommunicationConfig is SerialPortConfig sp3) { - IT6724CReverseDevice = _proxyGen.CreateInterfaceProxyWithTarget( - new IT6724C(sp3.COMPort, sp3.BaudRate, sp3.DataBit, sp3.StopBit, sp3.ParityBit, sp3.ReadTimeout, sp3.WriteTimeout), - _loggingInterceptor - ); + IT6724CReverseDevice = _proxyGen.CreateClassProxyWithTarget( + new IT6724C(sp3.COMPort, sp3.BaudRate, sp3.DataBit, sp3.StopBit, sp3.ParityBit, sp3.ReadTimeout, sp3.WriteTimeout), + _loggingInterceptor + ); DeviceDic["IT6724CReverse"] = IT6724CReverseDevice; } - else throw new InvalidOperationException("IT6724C 必须使用 SerialPortConfig"); + else throw new InvalidOperationException("IT6724CReverse 必须使用 SerialPortConfig"); break; case "DeviceCommand.Device.LQ7500_D": if (device.CommunicationConfig is SerialPortConfig sp2) { - LQ7500_DDevice = _proxyGen.CreateInterfaceProxyWithTarget( + LQ7500_DDevice = _proxyGen.CreateClassProxyWithTarget( new LQ7500_D(sp2.COMPort, sp2.BaudRate, sp2.DataBit, sp2.StopBit, sp2.ParityBit, sp2.ReadTimeout, sp2.WriteTimeout), _loggingInterceptor ); @@ -91,7 +94,7 @@ namespace BOB.Singleton case "DeviceCommand.Device.EAEL9080": if (device.CommunicationConfig is TcpConfig tcp2) { - EAEL9080Device = _proxyGen.CreateInterfaceProxyWithTarget( + EAEL9080Device = _proxyGen.CreateClassProxyWithTarget( new EAEL9080(tcp2.IPAddress, tcp2.Port, tcp2.ReadTimeout, tcp2.WriteTimeout), _loggingInterceptor ); @@ -103,7 +106,7 @@ namespace BOB.Singleton case "DeviceCommand.Device.IOBoard": if (device.CommunicationConfig is TcpConfig tcp3) { - IOBoardevice = _proxyGen.CreateInterfaceProxyWithTarget( + IOBoardevice = _proxyGen.CreateClassProxyWithTarget( new IOBoard(tcp3.IPAddress, tcp3.Port, tcp3.ReadTimeout, tcp3.WriteTimeout), _loggingInterceptor ); @@ -115,7 +118,7 @@ namespace BOB.Singleton case "DeviceCommand.Device.PSB11000": if (device.CommunicationConfig is TcpConfig tcp4) { - PSB11000Device = _proxyGen.CreateInterfaceProxyWithTarget( + PSB11000Device = _proxyGen.CreateClassProxyWithTarget( new PSB11000(tcp4.IPAddress, tcp4.Port, tcp4.ReadTimeout, tcp4.WriteTimeout), _loggingInterceptor ); @@ -127,7 +130,7 @@ namespace BOB.Singleton case "DeviceCommand.Device.WS_68030_380T": if (device.CommunicationConfig is TcpConfig tcp5) { - WS_68030_380TDevice = _proxyGen.CreateInterfaceProxyWithTarget( + WS_68030_380TDevice = _proxyGen.CreateClassProxyWithTarget( new WS_68030_380T(tcp5.IPAddress, tcp5.Port, tcp5.ReadTimeout, tcp5.WriteTimeout), _loggingInterceptor ); @@ -139,7 +142,7 @@ namespace BOB.Singleton case "DeviceCommand.Device.SQ0030G1D": if (device.CommunicationConfig is TcpConfig tcp7) { - SQ0030G1DTDevice = _proxyGen.CreateInterfaceProxyWithTarget( + SQ0030G1DTDevice = _proxyGen.CreateClassProxyWithTarget( new SQ0030G1D(tcp7.IPAddress, tcp7.Port, tcp7.ReadTimeout, tcp7.WriteTimeout), _loggingInterceptor ); @@ -151,7 +154,7 @@ namespace BOB.Singleton case "DeviceCommand.Device.ZXKS": if (device.CommunicationConfig is TcpConfig tcp6) { - ZXKSTDevice = _proxyGen.CreateInterfaceProxyWithTarget( + ZXKSTDevice = _proxyGen.CreateClassProxyWithTarget( new ZXKS(tcp6.IPAddress, tcp6.Port, tcp6.ReadTimeout, tcp6.WriteTimeout), _loggingInterceptor ); @@ -163,6 +166,7 @@ namespace BOB.Singleton default: throw new NotSupportedException($"未知设备类型:{device.DeviceType}"); } + } } diff --git a/BOB/Singleton/StepRunning.cs b/BOB/Singleton/StepRunning.cs index f223bc3..7a9a335 100644 --- a/BOB/Singleton/StepRunning.cs +++ b/BOB/Singleton/StepRunning.cs @@ -40,7 +40,7 @@ namespace BOB { _globalVariables = containerProvider.Resolve(); _eventAggregator = eventAggregator; - + _devices = containerProvider.Resolve(); } public async Task ExecuteSteps(ProgramModel program, int depth = 0, CancellationToken cancellationToken = default) { diff --git a/BOB/SystemConfig.cs b/BOB/SystemConfig.cs index 39947f3..5f1a6ab 100644 --- a/BOB/SystemConfig.cs +++ b/BOB/SystemConfig.cs @@ -32,6 +32,8 @@ namespace BOB [JsonIgnore] public string SystemPath { get; set; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "BOB"); public string Title { get; set; } = ""; + public int SaveDay { get; set; } + public string DBSavePath { get; set; } = ""; public int PerformanceLevel { get; set; } = 50; diff --git a/BOB/ViewModels/CommandTreeViewModel.cs b/BOB/ViewModels/CommandTreeViewModel.cs index 342fa45..194516c 100644 --- a/BOB/ViewModels/CommandTreeViewModel.cs +++ b/BOB/ViewModels/CommandTreeViewModel.cs @@ -273,6 +273,7 @@ namespace BOB.ViewModels var types = assembly.GetTypes().Where(t => t.IsPublic && !t.IsNested && + (t.IsClass || t.IsValueType) && (!t.IsAbstract || t.IsSealed) && t.GetCustomAttribute() != null); diff --git a/BOB/ViewModels/DataViewModel.cs b/BOB/ViewModels/DataViewModel.cs new file mode 100644 index 0000000..3783d67 --- /dev/null +++ b/BOB/ViewModels/DataViewModel.cs @@ -0,0 +1,48 @@ +using BOB.Singleton; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BOB.ViewModels +{ + public class DataViewModel : BindableBase, INavigationAware + { + #region 属性 + + + #endregion + #region 命令 + + + #endregion + private IEventAggregator _eventAggregator; + private IDialogService _dialogService; + private Devices _devices { get; set; } + public DataViewModel(IEventAggregator eventAggregator, IDialogService dialogService, IContainerProvider containerProvider) + { + _dialogService = dialogService; + _eventAggregator = eventAggregator; + _devices = containerProvider.Resolve(); + + } + #region 导航 + public void OnNavigatedTo(NavigationContext navigationContext) + { + + } + + public bool IsNavigationTarget(NavigationContext navigationContext) + { + return true; + } + + public void OnNavigatedFrom(NavigationContext navigationContext) + { + + } + #endregion + } + +} diff --git a/BOB/ViewModels/MainViewModel.cs b/BOB/ViewModels/MainViewModel.cs index 1f3b4fe..56e8486 100644 --- a/BOB/ViewModels/MainViewModel.cs +++ b/BOB/ViewModels/MainViewModel.cs @@ -15,14 +15,13 @@ using System.Windows.Input; namespace BOB.ViewModels { - public class MainViewModel : BindableBase,INavigationAware,IDialogAware + public class MainViewModel : BindableBase,INavigationAware { #region 属性 #endregion #region 命令 - public ICommand testcommand { get; set; } #endregion @@ -35,26 +34,15 @@ namespace BOB.ViewModels _dialogService = dialogService; _eventAggregator = eventAggregator; _devices=containerProvider.Resolve(); - testcommand = new DelegateCommand(test); } - private void test() - { - //_eventAggregator.GetEvent().Publish(true); - //var parameters = new DialogParameters - //{ - // { "Title", "提示" }, - // { "Message", "操作成功!" }, - // { "Icon", "info" }, - // { "ShowOk", true } - //}; - //_dialogService.ShowDialog("MessageBox",parameters); - } + private async Task InitializeDevicesAsync() { try { + _devices.Init(SystemConfig.Instance.DeviceList); await _devices.ConnectAllDevicesAsync(); } catch (Exception ex) @@ -67,12 +55,19 @@ namespace BOB.ViewModels } } #region 导航 + private bool _isInitialized = false; + public void OnNavigatedTo(NavigationContext navigationContext) { - _eventAggregator.GetEvent().Publish(true); - _=InitializeDevicesAsync(); + if (!_isInitialized) + { + _eventAggregator.GetEvent().Publish(true); + _ = InitializeDevicesAsync(); + _isInitialized = true; + } } + public bool IsNavigationTarget(NavigationContext navigationContext) { return true; @@ -84,21 +79,6 @@ namespace BOB.ViewModels } #endregion - #region 弹窗 - public bool CanCloseDialog() - { - return true; - } - - public void OnDialogClosed() - { - - } - - public void OnDialogOpened(IDialogParameters parameters) - { - - } - #endregion + } } diff --git a/BOB/ViewModels/MonitorViewModel.cs b/BOB/ViewModels/MonitorViewModel.cs new file mode 100644 index 0000000..88779fc --- /dev/null +++ b/BOB/ViewModels/MonitorViewModel.cs @@ -0,0 +1,353 @@ +using BOB.Singleton; +using Common.PubEvents; +using Logger; +using Microsoft.Win32; +using OxyPlot; +using OxyPlot.Legends; +using OxyPlot.Series; +using Prism.Dialogs; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; +using System.Windows.Threading; + +namespace BOB.ViewModels +{ + public class MonitorViewModel : BindableBase, INavigationAware + { + #region 属性 + private PlotModel _CurveModel=new(); + + public PlotModel CurveModel + { + get => _CurveModel; + set => SetProperty(ref _CurveModel, value); + } + private List _signalSeries = new List(); + + public List SignalSeries + { + get => _signalSeries; + set => SetProperty(ref _signalSeries, value); + } + private Dictionary _SeriesDic = new (); + + public Dictionary SeriesDic + { + get => _SeriesDic; + set => SetProperty(ref _SeriesDic, value); + } + private string _FilePath; + + public string FilePath + { + get => _FilePath; + set => SetProperty(ref _FilePath, value); + } + private string _SelectCurve; + + public string SelectCurve + { + get => _SelectCurve; + set => SetProperty(ref _SelectCurve, value); + } + private string _SelectDeleteCurve; + + public string SelectDeleteCurve + { + get => _SelectDeleteCurve; + set => SetProperty(ref _SelectDeleteCurve, value); + } + private string _SelectedSaveDays; + + public string SelectedSaveDays + { + get => _SelectedSaveDays; + set => SetProperty(ref _SelectedSaveDays, value); + } + private ObservableCollection _CurSingleList=new(); + + public ObservableCollection CurSingleList + { + get => _CurSingleList; + set => SetProperty(ref _CurSingleList, value); + } + private ObservableCollection _DeviceSingleList = new(); + + public ObservableCollection DeviceSingleList + { + get => _DeviceSingleList; + set => SetProperty(ref _DeviceSingleList, value); + } + + + #endregion + #region 命令 + public ICommand ResetViewCommand { get; set; } + public ICommand AddSignalCommand { get; set; } + public ICommand RemoveSignalCommand { get; set; } + public ICommand ChanegPathCommand { get; set; } + public ICommand SaveCommand { get; set; } + + #endregion + private IEventAggregator _eventAggregator; + private IDialogService _dialogService; + private static Random _random = new Random(); + private Devices _devices { get; set; } + public MonitorViewModel(IEventAggregator eventAggregator, IDialogService dialogService, IContainerProvider containerProvider ) + { + _dialogService = dialogService; + _eventAggregator = eventAggregator; + _devices = containerProvider.Resolve(); + ResetViewCommand = new DelegateCommand(ResetView); + AddSignalCommand = new DelegateCommand(AddSignal); + RemoveSignalCommand = new DelegateCommand(RemoveSignal); + ChanegPathCommand = new DelegateCommand(ChanegPath); + SaveCommand = new DelegateCommand(Save); + InitData(); + + // 初始化模拟量曲线 + InitializeSimulatedSignals(); + + // 设置定时器定时更新模拟数据 + _timer = new DispatcherTimer + { + Interval = TimeSpan.FromSeconds(0.5) // 每1秒更新一次 + }; + _timer.Tick += (s, e) => UpdateSimulatedData(); + _timer.Start(); + } + + private void InitData() + { + SelectedSaveDays=SystemConfig.Instance.SaveDay.ToString(); + FilePath= SystemConfig.Instance.DBSavePath; + } + + + + #region 模拟量 + + private DispatcherTimer _timer; + private double _time = 0; + + private void InitializeSimulatedSignals() + { + CurveModel.Legends.Add(new Legend + { + LegendPosition= LegendPosition.TopLeft, + IsLegendVisible=true + }); + // 模拟四个信号的初始化 + + // 模拟量1:正弦波 + var sineSignal = new LineSeries + { + Title = "正弦波信号", + MarkerType = MarkerType.Circle, + StrokeThickness = 2, + Color = OxyColors.Red + }; + _signalSeries.Add(sineSignal); + SeriesDic.Add(sineSignal.Title, sineSignal); + + // 模拟量2:线性增长 + var linearSignal = new LineSeries + { + Title = "线性增长信号", + MarkerType = MarkerType.Square, + StrokeThickness = 2, + Color = OxyColors.Green + }; + _signalSeries.Add(linearSignal); + SeriesDic.Add(linearSignal.Title, linearSignal); + + // 模拟量3:随机波动 + var randomSignal = new LineSeries + { + Title = "随机波动信号", + MarkerType = MarkerType.Triangle, + StrokeThickness = 2, + Color = OxyColors.Blue + }; + _signalSeries.Add(randomSignal); + SeriesDic.Add(randomSignal.Title, randomSignal); + + // 模拟量4:指数衰减 + var exponentialSignal = new LineSeries + { + Title = "指数衰减信号", + MarkerType = MarkerType.Diamond, + StrokeThickness = 2, + Color = OxyColors.Orange + }; + _signalSeries.Add(exponentialSignal); + SeriesDic.Add(exponentialSignal.Title, exponentialSignal); + + // 将模拟量曲线添加到图表中 + foreach (var signal in _signalSeries) + { + CurveModel.Series.Add(signal); + } + } + private void UpdateSimulatedData() + { + // 更新模拟量的值并添加新的数据点 + + // 模拟量1:正弦波 + var sineSignal = _signalSeries[0]; + sineSignal.Points.Add(new DataPoint(_time, Math.Sin(_time))); + if (sineSignal.Points.Count > 1000) sineSignal.Points.RemoveAt(0); // 保持最多100个点 + + // 模拟量2:线性增长 + var linearSignal = _signalSeries[1]; + linearSignal.Points.Add(new DataPoint(_time, _time)); + if (linearSignal.Points.Count > 1000) linearSignal.Points.RemoveAt(0); // 保持最多100个点 + + // 模拟量3:随机波动 + var randomSignal = _signalSeries[2]; + var randomValue = 10 * (2 * new Random().NextDouble() - 1); // 随机波动范围 [-10, 10] + randomSignal.Points.Add(new DataPoint(_time, randomValue)); + if (randomSignal.Points.Count > 1000) randomSignal.Points.RemoveAt(0); // 保持最多100个点 + + // 模拟量4:指数衰减 + var exponentialSignal = _signalSeries[3]; + exponentialSignal.Points.Add(new DataPoint(_time, Math.Exp(-0.1 * _time))); + if (exponentialSignal.Points.Count > 1000) exponentialSignal.Points.RemoveAt(0); // 保持最多100个点 + + // 更新图表 + CurveModel.InvalidatePlot(true); + + // 时间前进 + _time += 0.5; // 每次增加0.1秒 + } + #endregion + private OxyColor GetRandomColor() + { + // 生成随机的红色、绿色、蓝色分量,范围是 0 到 255 + byte r = (byte)_random.Next(0, 256); + byte g = (byte)_random.Next(0, 256); + byte b = (byte)_random.Next(0, 256); + + // 返回一个随机的颜色 + return OxyColor.FromRgb(r, g, b); + } + + private void AddSignal() + { + try + { + if (_SeriesDic.ContainsKey(SelectCurve)) + { + return; + } + else + { + // 开启资源 + + var sineSignal = new LineSeries + { + Title = SelectCurve, + MarkerType = MarkerType.Circle, + StrokeThickness = 2, + Color = GetRandomColor() + }; + CurveModel.Series.Add(sineSignal); + SeriesDic.Add(SelectCurve, sineSignal); + CurSingleList.Add(SelectCurve); + CurveModel.InvalidatePlot(true); + } + } + catch (Exception ex) + { + LoggerHelper.ErrorWithNotify("添加曲线失败", ex.StackTrace); + } + } + private void RemoveSignal() + { + try + { + if (_SeriesDic.ContainsKey(SelectDeleteCurve)) + { + var signalToRemove = _SeriesDic[SelectDeleteCurve]; + _SeriesDic.Remove(SelectDeleteCurve); + CurveModel.Series.Remove(signalToRemove); + CurSingleList.Remove(SelectDeleteCurve); + CurveModel.InvalidatePlot(true); + + // 释放资源 + } + } + catch (Exception ex) + { + LoggerHelper.ErrorWithNotify("删除曲线失败",ex.StackTrace); + } + } + private void Save() + { + SelectedSaveDays = SelectedSaveDays ?? "30"; + if (int.TryParse(SelectedSaveDays, out int saveDays)) + { + if (saveDays > 0 && saveDays <= 30) + { + Console.WriteLine($"保存天数: {saveDays}"); + } + else + { + //_dialogService.ShowDialog("请输入1到30之间的有效天数。", "无效输入"); + } + } + else + { + //_dialogService.ShowDialog("请输入有效的数字。", "无效输入"); + } + } + + + public void ChanegPath() + { + var openFileDialog = new OpenFileDialog + { + CheckFileExists = false, + CheckPathExists = true, + FileName = "Folder", + ValidateNames = false, + Filter = "All files (*.*)|*.*" + }; + openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); + if (openFileDialog.ShowDialog() == true) + { + FilePath = System.IO.Path.GetDirectoryName(openFileDialog.FileName); + SystemConfig.Instance.DBSavePath = FilePath; + SystemConfig.Instance.SaveToFile(); + } + + } + + private void ResetView() + { + CurveModel.ResetAllAxes(); + CurveModel.InvalidatePlot(true); + } + #region 导航 + public void OnNavigatedTo(NavigationContext navigationContext) + { + + } + + public bool IsNavigationTarget(NavigationContext navigationContext) + { + return true; + } + + public void OnNavigatedFrom(NavigationContext navigationContext) + { + + } + #endregion + } +} diff --git a/BOB/ViewModels/ShellViewModel.cs b/BOB/ViewModels/ShellViewModel.cs index 95154e0..75f9e55 100644 --- a/BOB/ViewModels/ShellViewModel.cs +++ b/BOB/ViewModels/ShellViewModel.cs @@ -94,19 +94,21 @@ namespace BOB.ViewModels public ICommand NewCommand { get; set; } public ICommand SetDefaultCommand { get; set; } public ICommand LoadCommand { get; set; } - public ICommand NavigateOneCommand { get; set; } + public ICommand NavigateCommand { get; set; } #endregion private IEventAggregator _eventAggregator; private GlobalVariables _globalVariables; private IContainerProvider _containerProvider; + private IRegionManager _regionManager; private StepRunning _stepRunning; private Task? currentExecutionTask; - public ShellViewModel(IEventAggregator eventAggregator, IContainerProvider containerProvider,GlobalVariables globalVariables, StepRunning stepRunning) + public ShellViewModel(IEventAggregator eventAggregator, IContainerProvider containerProvider,GlobalVariables globalVariables, StepRunning stepRunning,IRegionManager regionManager) { _eventAggregator = eventAggregator; _containerProvider = containerProvider; _globalVariables = globalVariables; + _regionManager = regionManager; _stepRunning =stepRunning; LeftDrawerOpenCommand = new DelegateCommand(LeftDrawerOpen); MinimizeCommand = new DelegateCommand(MinimizeWindow); @@ -122,9 +124,34 @@ namespace BOB.ViewModels SaveCommand = new DelegateCommand(Save); SetDefaultCommand = new DelegateCommand(SetDefault); LoadCommand = new DelegateCommand(Load); + NavigateCommand = new DelegateCommand(Navigate); _eventAggregator.GetEvent().Subscribe(UpdateRunIcon); } - + + private void Navigate(string content) + { + switch (content) + { + case "程序界面": + _regionManager.RequestNavigate("ShellViewManager", "MainView"); + break; + + case "监控界面": + _regionManager.RequestNavigate("ShellViewManager", "MonitorView"); + break; + + case "数据管理": + _regionManager.RequestNavigate("ShellViewManager", "DataView"); + break; + + case "更新信息": + + break; + + default: + break; + } + } private void UpdateRunIcon(string obj) { @@ -138,7 +165,6 @@ namespace BOB.ViewModels private void Load() { SystemConfig.Instance.LoadFromFile(); - _containerProvider.Resolve((typeof(List), SystemConfig.Instance.DeviceList)); if (SystemConfig.Instance.DefaultSubProgramFilePath != null) { if (File.Exists(SystemConfig.Instance.DefaultSubProgramFilePath)) diff --git a/BOB/Views/DataView.xaml b/BOB/Views/DataView.xaml new file mode 100644 index 0000000..f6e133b --- /dev/null +++ b/BOB/Views/DataView.xaml @@ -0,0 +1,60 @@ + + + + + + + + + + + + +