mirror of
https://github.com/denglihong2007/CRSim
synced 2026-08-12 20:55:38 +08:00
@@ -20,8 +20,8 @@
|
||||
services.AddTransient<DashboardPage>();
|
||||
services.AddTransient<DashboardPageViewModel>();
|
||||
|
||||
services.AddSingleton<SettingsPage>();
|
||||
services.AddSingleton<SettingsPageViewModel>();
|
||||
services.AddTransient<SettingsPage>();
|
||||
services.AddTransient<SettingsPageViewModel>();
|
||||
|
||||
services.AddTransient<DataManagementPage>();
|
||||
services.AddTransient<DataManagementPageViewModel>();
|
||||
|
||||
@@ -6,14 +6,29 @@
|
||||
private string _pageTitle = "设置";
|
||||
[ObservableProperty]
|
||||
private string _appVersion = "";
|
||||
private readonly Settings _settings;
|
||||
private Settings _settings;
|
||||
private readonly ISettingsService _settingsService;
|
||||
private readonly IDatabaseService _databaseService;
|
||||
private readonly IDialogService _dialogService;
|
||||
|
||||
#region 偏好设置
|
||||
[ObservableProperty]
|
||||
public string _timeOffset;
|
||||
[ObservableProperty]
|
||||
public string _departureCheckInAdvanceDuration;
|
||||
[ObservableProperty]
|
||||
public string _passingCheckInAdvanceDuration;
|
||||
[ObservableProperty]
|
||||
public string _stopDisplayUntilDepartureDuration;
|
||||
[ObservableProperty]
|
||||
public string _stopCheckInAdvanceDuration;
|
||||
[ObservableProperty]
|
||||
public string _maxPages;
|
||||
[ObservableProperty]
|
||||
public string _switchPageSeconds;
|
||||
#endregion
|
||||
public SettingsPageViewModel(ISettingsService settingsService, IDatabaseService databaseService, IDialogService dialogService)
|
||||
{
|
||||
_settings = settingsService.GetSettings();
|
||||
LoadSettings(settingsService);
|
||||
_settingsService = settingsService;
|
||||
_databaseService = databaseService;
|
||||
_dialogService = dialogService;
|
||||
@@ -21,107 +36,52 @@
|
||||
AppVersion = $"CRSim v{version}";
|
||||
_dialogService = dialogService;
|
||||
}
|
||||
#region 偏好设置
|
||||
public string TimeOffset
|
||||
|
||||
private void LoadSettings(ISettingsService settingsService)
|
||||
{
|
||||
get => _settings.TimeOffset.TotalMinutes.ToString();
|
||||
set
|
||||
{
|
||||
if (double.TryParse(value, out double minutes))
|
||||
{
|
||||
_settings.TimeOffset = TimeSpan.FromMinutes(minutes);
|
||||
OnPropertyChanged(nameof(TimeOffset));
|
||||
_settingsService.SaveSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
public string DepartureCheckInAdvanceDuration
|
||||
{
|
||||
get => _settings.DepartureCheckInAdvanceDuration.TotalMinutes.ToString();
|
||||
set
|
||||
{
|
||||
if (int.TryParse(value, out int minutes))
|
||||
{
|
||||
_settings.DepartureCheckInAdvanceDuration = TimeSpan.FromMinutes(minutes);
|
||||
OnPropertyChanged(nameof(DepartureCheckInAdvanceDuration));
|
||||
_settingsService.SaveSettings();
|
||||
}
|
||||
}
|
||||
_settings = settingsService.GetSettings();
|
||||
TimeOffset = _settings.TimeOffset.TotalMinutes.ToString();
|
||||
DepartureCheckInAdvanceDuration = _settings.DepartureCheckInAdvanceDuration.TotalMinutes.ToString();
|
||||
PassingCheckInAdvanceDuration = _settings.PassingCheckInAdvanceDuration.TotalMinutes.ToString();
|
||||
StopDisplayUntilDepartureDuration = _settings.StopDisplayUntilDepartureDuration.TotalMinutes.ToString();
|
||||
StopCheckInAdvanceDuration = _settings.StopCheckInAdvanceDuration.TotalMinutes.ToString();
|
||||
MaxPages = _settings.MaxPages.ToString();
|
||||
SwitchPageSeconds = _settings.SwitchPageSeconds.ToString();
|
||||
}
|
||||
|
||||
public string PassingCheckInAdvanceDuration
|
||||
[RelayCommand]
|
||||
public void Unload()
|
||||
{
|
||||
get => _settings.PassingCheckInAdvanceDuration.TotalMinutes.ToString();
|
||||
set
|
||||
if (int.TryParse(_timeOffset,out int i))
|
||||
{
|
||||
if (int.TryParse(value, out int minutes))
|
||||
{
|
||||
_settings.PassingCheckInAdvanceDuration = TimeSpan.FromMinutes(minutes);
|
||||
OnPropertyChanged(nameof(PassingCheckInAdvanceDuration));
|
||||
_settingsService.SaveSettings();
|
||||
}
|
||||
_settings.TimeOffset = TimeSpan.FromMinutes(i);
|
||||
}
|
||||
}
|
||||
|
||||
public string StopDisplayUntilDepartureDuration
|
||||
{
|
||||
get => _settings.StopDisplayUntilDepartureDuration.TotalMinutes.ToString();
|
||||
set
|
||||
if (int.TryParse(DepartureCheckInAdvanceDuration, out int j) && j >= 0)
|
||||
{
|
||||
if (int.TryParse(value, out int minutes))
|
||||
{
|
||||
_settings.StopDisplayUntilDepartureDuration = TimeSpan.FromMinutes(minutes);
|
||||
OnPropertyChanged(nameof(StopDisplayUntilDepartureDuration));
|
||||
_settingsService.SaveSettings();
|
||||
}
|
||||
_settings.DepartureCheckInAdvanceDuration = TimeSpan.FromMinutes(j);
|
||||
}
|
||||
}
|
||||
|
||||
public string StopCheckInAdvanceDuration
|
||||
{
|
||||
get => _settings.StopCheckInAdvanceDuration.TotalMinutes.ToString();
|
||||
set
|
||||
if (int.TryParse(PassingCheckInAdvanceDuration, out int k) && k >= 0)
|
||||
{
|
||||
if (int.TryParse(value, out int minutes))
|
||||
{
|
||||
_settings.StopCheckInAdvanceDuration = TimeSpan.FromMinutes(minutes);
|
||||
OnPropertyChanged(nameof(StopCheckInAdvanceDuration));
|
||||
_settingsService.SaveSettings();
|
||||
}
|
||||
_settings.PassingCheckInAdvanceDuration = TimeSpan.FromMinutes(k);
|
||||
}
|
||||
}
|
||||
|
||||
public string MaxPages
|
||||
{
|
||||
get => _settings.MaxPages.ToString();
|
||||
set
|
||||
if (int.TryParse(StopDisplayUntilDepartureDuration, out int l) && l >= 0)
|
||||
{
|
||||
if (int.TryParse(value, out int maxPages))
|
||||
{
|
||||
_settings.MaxPages = maxPages;
|
||||
OnPropertyChanged(nameof(MaxPages));
|
||||
_settingsService.SaveSettings();
|
||||
}
|
||||
_settings.StopDisplayUntilDepartureDuration = TimeSpan.FromMinutes(l);
|
||||
}
|
||||
}
|
||||
|
||||
public string SwitchPageSeconds
|
||||
{
|
||||
get => _settings.SwitchPageSeconds.ToString();
|
||||
set
|
||||
if (int.TryParse(StopCheckInAdvanceDuration, out int m) && m >= 0)
|
||||
{
|
||||
if (int.TryParse(value, out int switchPageSeconds))
|
||||
{
|
||||
_settings.SwitchPageSeconds = switchPageSeconds;
|
||||
OnPropertyChanged(nameof(SwitchPageSeconds));
|
||||
_settingsService.SaveSettings();
|
||||
}
|
||||
_settings.StopCheckInAdvanceDuration = TimeSpan.FromMinutes(m);
|
||||
}
|
||||
if (int.TryParse(MaxPages, out int n) && n >= 0)
|
||||
{
|
||||
_settings.MaxPages = n;
|
||||
}
|
||||
if (int.TryParse(SwitchPageSeconds, out int o) && o >= 0)
|
||||
{
|
||||
_settings.SwitchPageSeconds = o;
|
||||
}
|
||||
_settingsService.SaveSettings();
|
||||
}
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
protected void OnPropertyChanged(string propertyName) =>
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
#endregion
|
||||
[RelayCommand]
|
||||
public async Task ClearData()
|
||||
{
|
||||
|
||||
@@ -6,12 +6,18 @@
|
||||
xmlns:local="clr-namespace:CRSim.Views"
|
||||
xmlns:controls="clr-namespace:CRSim.Controls"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||
FontFamily="Microsoft YaHei"
|
||||
Title="SettingsPage"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
|
||||
mc:Ignorable="d">
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="Unloaded">
|
||||
<i:InvokeCommandAction Command="{Binding ViewModel.UnloadCommand}" />
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
<Page.Resources>
|
||||
<Style x:Key="LinkTextBlockStyle" TargetType="TextBlock">
|
||||
<Setter Property="Margin" Value="0,4,0,4" />
|
||||
@@ -85,8 +91,8 @@
|
||||
正值为推后时间,负值为提前时间
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
<TextBox Grid.Column="2" Width="72" VerticalAlignment="Center" Text="{Binding ViewModel.TimeOffset, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
FontFamily="Microsoft YaHei" Margin="0,0,8,0" PreviewTextInput="NumberValidationTextBox2">
|
||||
<TextBox Grid.Column="2" Width="72" VerticalAlignment="Center" Text="{Binding ViewModel.TimeOffset, Mode=TwoWay}"
|
||||
FontFamily="Microsoft YaHei" Margin="0,0,8,0">
|
||||
</TextBox>
|
||||
<TextBlock Text="分钟" Style="{StaticResource BodyTextBlockStyle}" VerticalAlignment="Center"
|
||||
Grid.Column="3"/>
|
||||
@@ -128,8 +134,8 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="最大显示页数" Style="{StaticResource BodyTextBlockStyle}" VerticalAlignment="Center"
|
||||
Grid.Column="0"/>
|
||||
<TextBox Grid.Column="2" Width="72" VerticalAlignment="Center" Text="{Binding ViewModel.MaxPages, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
FontFamily="Microsoft YaHei" Margin="0,0,8,0" PreviewTextInput="NumberValidationTextBox">
|
||||
<TextBox Grid.Column="2" Width="72" VerticalAlignment="Center" Text="{Binding ViewModel.MaxPages, Mode=TwoWay}"
|
||||
FontFamily="Microsoft YaHei" Margin="0,0,8,0">
|
||||
</TextBox>
|
||||
<TextBlock Text="页" Style="{StaticResource BodyTextBlockStyle}" VerticalAlignment="Center"
|
||||
Grid.Column="3"/>
|
||||
@@ -145,8 +151,8 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="页面切换时长" Style="{StaticResource BodyTextBlockStyle}" VerticalAlignment="Center"
|
||||
Grid.Column="0"/>
|
||||
<TextBox Grid.Column="2" Width="72" Text="{Binding ViewModel.SwitchPageSeconds, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
FontFamily="Microsoft YaHei" Margin="0,0,8,0" PreviewTextInput="NumberValidationTextBox">
|
||||
<TextBox Grid.Column="2" Width="72" Text="{Binding ViewModel.SwitchPageSeconds, Mode=TwoWay}"
|
||||
FontFamily="Microsoft YaHei" Margin="0,0,8,0">
|
||||
</TextBox>
|
||||
<TextBlock Text="秒" Style="{StaticResource BodyTextBlockStyle}" VerticalAlignment="Center"
|
||||
Grid.Column="3"/>
|
||||
@@ -188,8 +194,8 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="始发车提前检票时长" Style="{StaticResource BodyTextBlockStyle}" VerticalAlignment="Center"
|
||||
Grid.Column="0"/>
|
||||
<TextBox Grid.Column="2" Width="72" Text="{Binding ViewModel.DepartureCheckInAdvanceDuration, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
FontFamily="Microsoft YaHei" Margin="0,0,8,0" PreviewTextInput="NumberValidationTextBox">
|
||||
<TextBox Grid.Column="2" Width="72" Text="{Binding ViewModel.DepartureCheckInAdvanceDuration, Mode=TwoWay}"
|
||||
FontFamily="Microsoft YaHei" Margin="0,0,8,0">
|
||||
</TextBox>
|
||||
<TextBlock Text="分钟" Style="{StaticResource BodyTextBlockStyle}" VerticalAlignment="Center"
|
||||
Grid.Column="3"/>
|
||||
@@ -205,8 +211,8 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="过路车提前检票时长" Style="{StaticResource BodyTextBlockStyle}" VerticalAlignment="Center"
|
||||
Grid.Column="0"/>
|
||||
<TextBox Grid.Column="2" Width="72" Text="{Binding ViewModel.PassingCheckInAdvanceDuration, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
FontFamily="Microsoft YaHei" Margin="0,0,8,0" PreviewTextInput="NumberValidationTextBox">
|
||||
<TextBox Grid.Column="2" Width="72" Text="{Binding ViewModel.PassingCheckInAdvanceDuration, Mode=TwoWay}"
|
||||
FontFamily="Microsoft YaHei" Margin="0,0,8,0">
|
||||
</TextBox>
|
||||
<TextBlock Text="分钟" Style="{StaticResource BodyTextBlockStyle}" VerticalAlignment="Center"
|
||||
Grid.Column="3"/>
|
||||
@@ -222,8 +228,8 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="提前停止检票时长" Style="{StaticResource BodyTextBlockStyle}" VerticalAlignment="Center"
|
||||
Grid.Column="0"/>
|
||||
<TextBox Grid.Column="2" Width="72" Text="{Binding ViewModel.StopCheckInAdvanceDuration, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
FontFamily="Microsoft YaHei" Margin="0,0,8,0" PreviewTextInput="NumberValidationTextBox">
|
||||
<TextBox Grid.Column="2" Width="72" Text="{Binding ViewModel.StopCheckInAdvanceDuration, Mode=TwoWay}"
|
||||
FontFamily="Microsoft YaHei" Margin="0,0,8,0">
|
||||
</TextBox>
|
||||
<TextBlock Text="分钟" Style="{StaticResource BodyTextBlockStyle}" VerticalAlignment="Center"
|
||||
Grid.Column="3"/>
|
||||
@@ -239,8 +245,8 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="显示停检至开点前时长" Style="{StaticResource BodyTextBlockStyle}" VerticalAlignment="Center"
|
||||
Grid.Column="0"/>
|
||||
<TextBox Grid.Column="2" Width="72" Text="{Binding ViewModel.StopDisplayUntilDepartureDuration, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
FontFamily="Microsoft YaHei" Margin="0,0,8,0" PreviewTextInput="NumberValidationTextBox">
|
||||
<TextBox Grid.Column="2" Width="72" Text="{Binding ViewModel.StopDisplayUntilDepartureDuration, Mode=TwoWay}"
|
||||
FontFamily="Microsoft YaHei" Margin="0,0,8,0">
|
||||
</TextBox>
|
||||
<TextBlock Text="分钟" Style="{StaticResource BodyTextBlockStyle}" VerticalAlignment="Center"
|
||||
Grid.Column="3"/>
|
||||
|
||||
@@ -19,15 +19,5 @@ namespace CRSim.Views
|
||||
DataContext = this;
|
||||
InitializeComponent();
|
||||
}
|
||||
private void NumberValidationTextBox(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
Regex regex = new("^[0-9]+$");
|
||||
e.Handled = !regex.IsMatch(e.Text);
|
||||
}
|
||||
private void NumberValidationTextBox2(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
Regex regex = new("^-?[0-9]*$");
|
||||
e.Handled = !regex.IsMatch(e.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user