92 lines
2.8 KiB
C#
92 lines
2.8 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using System;
|
|
using System.Windows;
|
|
|
|
namespace HME_MoistureLossMeter.ViewModels
|
|
{
|
|
public partial class MainViewModel : ViewModelBase
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
[ObservableProperty]
|
|
private object _currentView;
|
|
|
|
[ObservableProperty]
|
|
private string _currentViewName = "测试画面";
|
|
|
|
[ObservableProperty]
|
|
private bool _isConnected;
|
|
|
|
[ObservableProperty]
|
|
private string _connectionStatus = "未连接";
|
|
|
|
[ObservableProperty]
|
|
private bool _isTesting;
|
|
|
|
[ObservableProperty]
|
|
private DateTime _currentTime = DateTime.Now;
|
|
|
|
public TestViewModel TestViewModel { get; }
|
|
public ManualControlViewModel ManualControlViewModel { get; }
|
|
public RecordViewModel RecordViewModel { get; }
|
|
public ReportViewModel ReportViewModel { get; }
|
|
|
|
public MainViewModel(IServiceProvider serviceProvider,
|
|
TestViewModel testViewModel,
|
|
ManualControlViewModel manualControlViewModel,
|
|
RecordViewModel recordViewModel,
|
|
ReportViewModel reportViewModel)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
TestViewModel = testViewModel;
|
|
ManualControlViewModel = manualControlViewModel;
|
|
RecordViewModel = recordViewModel;
|
|
ReportViewModel = reportViewModel;
|
|
|
|
CurrentView = TestViewModel;
|
|
CurrentViewName = "测试画面";
|
|
|
|
var timer = new System.Timers.Timer(1000);
|
|
timer.Elapsed += (s, e) => CurrentTime = DateTime.Now;
|
|
timer.Start();
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void NavigateToTest()
|
|
{
|
|
CurrentView = TestViewModel;
|
|
CurrentViewName = "测试画面";
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void NavigateToManual()
|
|
{
|
|
CurrentView = ManualControlViewModel;
|
|
CurrentViewName = "手动控制";
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void NavigateToRecord()
|
|
{
|
|
CurrentView = RecordViewModel;
|
|
CurrentViewName = "记录画面";
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void NavigateToReport()
|
|
{
|
|
CurrentView = ReportViewModel;
|
|
CurrentViewName = "报表";
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void ExitApplication()
|
|
{
|
|
var result = MessageBox.Show("确定要退出程序吗?", "确认退出",
|
|
MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
if (result == MessageBoxResult.Yes)
|
|
Application.Current.Shutdown();
|
|
}
|
|
}
|
|
} |