From c13d35cd60c7f43ea961112d83b9c61220b0663a Mon Sep 17 00:00:00 2001 From: denglihong2007 <2639367181@qq.com> Date: Sun, 9 Mar 2025 01:16:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=88=97=E8=BD=A6?= =?UTF-8?q?=E3=80=81=E7=AB=99=E5=8F=B0=E9=95=BF=E5=BA=A6=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E4=BC=98=E5=8C=96=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Converters/TimeOnlyJsonConverter.cs | 9 +- CRSim.Core/Models/Platform.cs | 14 ++ CRSim.Core/Models/Station.cs | 2 +- CRSim.Core/Models/StationStop.cs | 2 + CRSim.Core/Services/DatabaseService.cs | 7 +- CRSim/Converters/NumberToStringConverter.cs | 8 +- CRSim/Models/TrainInfo.cs | 1 + CRSim/Services/DialogService.cs | 14 ++ CRSim/Services/IDialogService.cs | 1 + .../StationManagementPageViewModel.cs | 46 ++-- .../ScreenSimulationPageViewModel.cs | 16 +- CRSim/ViewModels/Windows/ScreenViewModel.cs | 2 + .../DataManagement/StationManagementPage.xaml | 208 ++++++------------ CRSim/Views/Pages/SettingsPage.xaml | 105 +++++++-- CRSim/Views/Pages/SettingsPage.xaml.cs | 20 ++ .../Simulation/ScreenSimulationPage.xaml | 21 +- .../Views/Windows/Dialogs/ConfirmDialog.xaml | 8 +- CRSim/Views/Windows/Dialogs/InputDialog.xaml | 4 +- .../Views/Windows/Dialogs/MessageDialog.xaml | 8 +- .../Views/Windows/Dialogs/PlatformDialog.xaml | 44 ++++ .../Windows/Dialogs/PlatformDialog.xaml.cs | 72 ++++++ .../Windows/Dialogs/StationStopDialog.xaml | 43 ++-- .../Windows/Dialogs/StationStopDialog.xaml.cs | 11 +- .../Windows/Dialogs/TicketCheckDialog.xaml | 8 +- .../Windows/Dialogs/TrainStopDialog.xaml | 9 +- .../PrimaryTicketCheckScreenView.xaml | 2 +- 26 files changed, 412 insertions(+), 273 deletions(-) create mode 100644 CRSim.Core/Models/Platform.cs create mode 100644 CRSim/Views/Windows/Dialogs/PlatformDialog.xaml create mode 100644 CRSim/Views/Windows/Dialogs/PlatformDialog.xaml.cs diff --git a/CRSim.Core/Converters/TimeOnlyJsonConverter.cs b/CRSim.Core/Converters/TimeOnlyJsonConverter.cs index 67085d6..ed379fa 100644 --- a/CRSim.Core/Converters/TimeOnlyJsonConverter.cs +++ b/CRSim.Core/Converters/TimeOnlyJsonConverter.cs @@ -1,10 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using System.Text.Json; -using System.Threading.Tasks; +using CRSim.Core.Services; namespace CRSim.Core.Converters { @@ -12,6 +8,7 @@ namespace CRSim.Core.Converters { private const string TimeFormat = "HH:mm:ss"; + public override DateTime? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { if (reader.TokenType == JsonTokenType.String) diff --git a/CRSim.Core/Models/Platform.cs b/CRSim.Core/Models/Platform.cs new file mode 100644 index 0000000..f80716a --- /dev/null +++ b/CRSim.Core/Models/Platform.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CRSim.Core.Models +{ + public class Platform + { + public string Name { get; set; } + public int Length { get; set; } + } +} diff --git a/CRSim.Core/Models/Station.cs b/CRSim.Core/Models/Station.cs index 417ef8a..4f4c992 100644 --- a/CRSim.Core/Models/Station.cs +++ b/CRSim.Core/Models/Station.cs @@ -26,6 +26,6 @@ namespace CRSim.Core.Models public List StationStops { get; set; } = []; - public List Platforms { get; set; } = []; + public List Platforms { get; set; } = []; } } diff --git a/CRSim.Core/Models/StationStop.cs b/CRSim.Core/Models/StationStop.cs index 1ec520c..0d3a553 100644 --- a/CRSim.Core/Models/StationStop.cs +++ b/CRSim.Core/Models/StationStop.cs @@ -27,5 +27,7 @@ namespace CRSim.Core.Models public string Platform { get; set; } public string? Landmark { get; set; } + + public int Length { get; set; } } } diff --git a/CRSim.Core/Services/DatabaseService.cs b/CRSim.Core/Services/DatabaseService.cs index 6fb142b..6764dfe 100644 --- a/CRSim.Core/Services/DatabaseService.cs +++ b/CRSim.Core/Services/DatabaseService.cs @@ -133,11 +133,13 @@ namespace CRSim.Core.Services var platform = string.IsNullOrWhiteSpace(data[5]) ? "未知" : data[5]; var ticketCheck = string.IsNullOrWhiteSpace(data[4]) ? string.Empty : data[4]; - if (!station.Platforms.Contains(platform)) + var existingPlatform = station.Platforms.FirstOrDefault(x => x.Name == platform); + if (existingPlatform == null) { - station.Platforms.Add(platform); + station.Platforms.Add(new Platform { Name = platform, Length = 20 }); } + var waitingArea = station.WaitingAreas.FirstOrDefault(x => x.Name == waitingAreaName); if (waitingArea == null) { @@ -181,6 +183,7 @@ namespace CRSim.Core.Services ArrivalTime = arrivalTime, DepartureTime = departureTime, Platform = platform, + Length = data[0].StartsWith('G') || data[0].StartsWith('D') || data[0].StartsWith('C') ? Math.Abs(data[0].GetHashCode()) % 3 == 0 ? 8 : 16 : 18, Landmark = data[8] + "色" ?? null, }); } diff --git a/CRSim/Converters/NumberToStringConverter.cs b/CRSim/Converters/NumberToStringConverter.cs index 0a8224f..42194be 100644 --- a/CRSim/Converters/NumberToStringConverter.cs +++ b/CRSim/Converters/NumberToStringConverter.cs @@ -10,15 +10,15 @@ namespace CRSim.Converters { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - if(value is string number) + if(value is int l) { - if(number.StartsWith('G')|| number.StartsWith('D')|| number.StartsWith('C')) + if (l % 2 == 0) { - return Math.Abs(number.GetHashCode()) % 3 == 0 ? "1-8" : "9-16"; + return (new List { $"1-{l / 2}", $"{l / 2 + 1}-{l}" })[l.GetHashCode() % 2]; } else { - return Math.Abs(number.GetHashCode()) % 2 == 0 ? "1-9" : "10-18"; + return (new List { $"1-{(l + 1) / 2}", $"{(l + 1) / 2}-{l}" })[l.GetHashCode() % 2]; } } return value; diff --git a/CRSim/Models/TrainInfo.cs b/CRSim/Models/TrainInfo.cs index 5660fa0..2506a82 100644 --- a/CRSim/Models/TrainInfo.cs +++ b/CRSim/Models/TrainInfo.cs @@ -12,5 +12,6 @@ public string Platform { get; set; } public TimeSpan State { get; set; } public string? Landmark { get; set; } + public int Length { get; set; } } } diff --git a/CRSim/Services/DialogService.cs b/CRSim/Services/DialogService.cs index e4f7b8f..911d033 100644 --- a/CRSim/Services/DialogService.cs +++ b/CRSim/Services/DialogService.cs @@ -145,5 +145,19 @@ namespace CRSim.Services } return null; } + + public List? GetInputPlatform() + { + var dialog = new PlatformDialog() + { + Owner = _owner + }; + bool? result = dialog.ShowDialog(); + if (result == true) + { + return dialog.GeneratedPlatforms; + } + return null; + } } } diff --git a/CRSim/Services/IDialogService.cs b/CRSim/Services/IDialogService.cs index 91ebfe6..2dc5c03 100644 --- a/CRSim/Services/IDialogService.cs +++ b/CRSim/Services/IDialogService.cs @@ -11,6 +11,7 @@ TrainStop? GetInputTrainStop(TrainStop trainStop); StationStop? GetInputStationStop(List ticketChecks, List platforms); StationStop? GetInputStationStop(List ticketChecks, List platforms, StationStop stationStop); + List? GetInputPlatform(); (string, List) GetInputTicketCheck(List waitingAreaNames); void SetOwner(Window owner); } diff --git a/CRSim/ViewModels/Pages/DataManagement/StationManagementPageViewModel.cs b/CRSim/ViewModels/Pages/DataManagement/StationManagementPageViewModel.cs index 45bbc84..dfcbab3 100644 --- a/CRSim/ViewModels/Pages/DataManagement/StationManagementPageViewModel.cs +++ b/CRSim/ViewModels/Pages/DataManagement/StationManagementPageViewModel.cs @@ -2,6 +2,7 @@ using CRSim.Core.Models; using System.IO; using System.Linq; using System.Text; +using static System.Runtime.InteropServices.JavaScript.JSType; namespace CRSim.ViewModels; @@ -28,7 +29,7 @@ public partial class StationManagementPageViewModel : ObservableObject private Station _selectedStation = new(); public ObservableCollection WaitingAreaNames { get; private set; } = []; - public ObservableCollection Platforms { get; private set; } = []; + public ObservableCollection Platforms { get; private set; } = []; public ObservableCollection TicketChecks { get; private set; } = []; @@ -75,7 +76,7 @@ public partial class StationManagementPageViewModel : ObservableObject { StationStops.Add(stationStop); } - foreach(string platform in SelectedStation.Platforms) + foreach(var platform in SelectedStation.Platforms) { Platforms.Add(platform); } @@ -151,29 +152,14 @@ public partial class StationManagementPageViewModel : ObservableObject [RelayCommand] public void AddPlatform() { - string? platform = _dialogService.GetInput("վ̨"); - if (platform != null) + var platforms = _dialogService.GetInputPlatform(); + if (platforms != null) { - string[] platforms = platform.Split('-'); - if (platforms.Length == 2 && int.TryParse(platforms[0],out int startindex) && int.TryParse(platforms[1], out int endindex)) + foreach (var platform in platforms) { - var startIndex = Math.Min(startindex, endindex); - var endIndex = Math.Max(startindex, endindex); - for(int i = startIndex; i < endIndex + 1; i++) + if (Platforms.Any(x=>x.Name==platform.Name)) { - if (Platforms.Contains(i.ToString())) - { - _dialogService.ShowMessage("ʧ", $" {i} վ̨Ѵڡ"); - return; - } - Platforms.Add(i.ToString()); - } - } - else - { - if (Platforms.Contains(platform)) - { - _dialogService.ShowMessage("ʧ", $" {platform} վ̨Ѵڡ"); + _dialogService.ShowMessage("ʧ", $" {platform.Name} վ̨Ѵڡ"); return; } Platforms.Add(platform); @@ -184,9 +170,9 @@ public partial class StationManagementPageViewModel : ObservableObject [RelayCommand] public void DeletePlatform(object selectedPlatform) { - if (selectedPlatform is string n) + if (selectedPlatform is Platform p) { - Platforms.Remove(n); + Platforms.Remove(p); } } [RelayCommand] @@ -240,7 +226,7 @@ public partial class StationManagementPageViewModel : ObservableObject _databaseService.UpdateStation(SelectedStation.Name, GenerateStation(SelectedStation.Name,WaitingAreaNames,TicketChecks,StationStops,Platforms)); await _databaseService.SaveData(); } - public static Station GenerateStation(string stationName, ObservableCollection waitingAreaNames, ObservableCollection ticketChecks,ObservableCollection stationStops,ObservableCollection platforms) + public static Station GenerateStation(string stationName, ObservableCollection waitingAreaNames, ObservableCollection ticketChecks,ObservableCollection stationStops,ObservableCollection platforms) { var station = new Station { @@ -336,7 +322,8 @@ public partial class StationManagementPageViewModel : ObservableObject ArrivalTime = arrivalTime, DepartureTime = departureTime, TicketChecks = [TicketChecks[new Random().Next(TicketChecks.Count)].Name], - Platform = Platforms[new Random().Next(Platforms.Count)], + Platform = Platforms[new Random().Next(Platforms.Count)].Name, + Length = firstColumn.StartsWith('G') || firstColumn.StartsWith('D') || firstColumn.StartsWith('C') ? Math.Abs(firstColumn.GetHashCode()) % 3 == 0 ? 8 : 16 : 18, Landmark = new[] { "ɫ", "ɫ", "ɫ", "ɫ", "ɫ", "ɫ", "ɫ",null}[new Random().Next(8)] }); } @@ -366,7 +353,7 @@ public partial class StationManagementPageViewModel : ObservableObject [RelayCommand] public void AddStationStop() { - var newStationStop = _dialogService.GetInputStationStop([.. TicketChecks.Select(x => x.Name)], [.. Platforms]); + var newStationStop = _dialogService.GetInputStationStop([.. TicketChecks.Select(x => x.Name)], [.. Platforms.Select(x => x.Name)]); if (newStationStop != null) { if (StationStops.Any(x => x.Number == newStationStop.Number)) @@ -396,7 +383,7 @@ public partial class StationManagementPageViewModel : ObservableObject { if (_selectedStationStop is StationStop selectedStationStop) { - var newStationStop = _dialogService.GetInputStationStop([.. TicketChecks.Select(x => x.Name)], [.. Platforms], selectedStationStop); + var newStationStop = _dialogService.GetInputStationStop([.. TicketChecks.Select(x => x.Name)], [.. Platforms.Select(x => x.Name)], selectedStationStop); if (newStationStop != null) { StationStops[StationStops.IndexOf(selectedStationStop)] = newStationStop; @@ -431,8 +418,9 @@ public partial class StationManagementPageViewModel : ObservableObject foreach (StationStop t in stops) { t.TicketChecks = [TicketChecks[new Random().Next(TicketChecks.Count)].Name]; - t.Platform = Platforms[new Random().Next(Platforms.Count)]; + t.Platform = Platforms[new Random().Next(Platforms.Count)].Name; t.Landmark = new[] { "ɫ", "ɫ", "ɫ", "ɫ", "ɫ", "ɫ", "ɫ", null }[new Random().Next(8)]; + t.Length = t.Number.StartsWith('G') || t.Number.StartsWith('D') || t.Number.StartsWith('C') ? Math.Abs(t.Number.GetHashCode()) % 3 == 0 ? 8 : 16 : 18; StationStops.Add(t); } } diff --git a/CRSim/ViewModels/Pages/Simulation/ScreenSimulationPageViewModel.cs b/CRSim/ViewModels/Pages/Simulation/ScreenSimulationPageViewModel.cs index 8f16155..ac9e62f 100644 --- a/CRSim/ViewModels/Pages/Simulation/ScreenSimulationPageViewModel.cs +++ b/CRSim/ViewModels/Pages/Simulation/ScreenSimulationPageViewModel.cs @@ -35,11 +35,11 @@ public partial class ScreenSimulationPageViewModel : ObservableObject public string SelectedTicketCheck = ""; - public string SelectedPlatform = ""; + public string SelectedPlatformName = ""; public ObservableCollection StationNames { get; private set; } = []; public ObservableCollection TicketChecks { get; private set; } = []; - public ObservableCollection Platforms { get; private set; } = []; + public ObservableCollection Platforms { get; private set; } = []; [ObservableProperty] private bool _isStartSimulationAvailable = false; @@ -65,7 +65,7 @@ public partial class ScreenSimulationPageViewModel : ObservableObject IsStartSimulationAvailable = selectedStyle!=null && (!StationNeeded || !string.IsNullOrWhiteSpace(SelectedStationName))&& (!TicketCheckNeeded || !string.IsNullOrWhiteSpace(SelectedTicketCheck)) && - (!PlatformNeeded || !string.IsNullOrWhiteSpace(SelectedPlatform)); + (!PlatformNeeded || !string.IsNullOrWhiteSpace(SelectedPlatformName)); } [RelayCommand] @@ -89,13 +89,15 @@ public partial class ScreenSimulationPageViewModel : ObservableObject if(s is string station) { SelectedStationName = station; + SelectedPlatformName = ""; + SelectedTicketCheck = ""; TicketChecks.Clear(); foreach(string ticketCheck in _databaseService.GetStationByName(SelectedStationName).TicketChecks) { TicketChecks.Add(ticketCheck); } Platforms.Clear(); - foreach (string platform in _databaseService.GetStationByName(SelectedStationName).Platforms) + foreach (var platform in _databaseService.GetStationByName(SelectedStationName).Platforms) { Platforms.Add(platform); } @@ -114,9 +116,9 @@ public partial class ScreenSimulationPageViewModel : ObservableObject [RelayCommand] public void SelectPlatform(object s) { - if (s is string platform) + if (s is Platform platform) { - SelectedPlatform = platform; + SelectedPlatformName = platform.Name; } CheckCanStart(); } @@ -132,7 +134,7 @@ public partial class ScreenSimulationPageViewModel : ObservableObject Window.ViewModel.LoadData(_databaseService.GetStationByName(SelectedStationName), TicketCheckNeeded ? SelectedTicketCheck : string.Empty, - PlatformNeeded ? SelectedPlatform : string.Empty); + PlatformNeeded ? SelectedPlatformName : string.Empty); Window.Show(); } } diff --git a/CRSim/ViewModels/Windows/ScreenViewModel.cs b/CRSim/ViewModels/Windows/ScreenViewModel.cs index 5001f1b..0598b3c 100644 --- a/CRSim/ViewModels/Windows/ScreenViewModel.cs +++ b/CRSim/ViewModels/Windows/ScreenViewModel.cs @@ -58,6 +58,7 @@ namespace CRSim.ViewModels var trains = station.StationStops; foreach (var trainNumber in trains) { + if (trainNumber != null && trainNumber.DepartureTime != null && (ticketCheck==string.Empty || trainNumber.TicketChecks.Contains(ticketCheck)) && (platform == string.Empty || trainNumber.Platform==platform)) { TrainInfo.Add(new TrainInfo @@ -70,6 +71,7 @@ namespace CRSim.ViewModels TicketChecks = trainNumber.TicketChecks, WaitingArea = station.WaitingAreas.Where(x => x.TicketChecks.Intersect(trainNumber.TicketChecks).ToList().Count!=0).FirstOrDefault().Name, Platform = trainNumber.Platform, + Length =trainNumber.Length, Landmark = trainNumber.Landmark, State = TimeSpan.Zero }); diff --git a/CRSim/Views/Pages/DataManagement/StationManagementPage.xaml b/CRSim/Views/Pages/DataManagement/StationManagementPage.xaml index 34d2f3d..f7d59b1 100644 --- a/CRSim/Views/Pages/DataManagement/StationManagementPage.xaml +++ b/CRSim/Views/Pages/DataManagement/StationManagementPage.xaml @@ -11,12 +11,47 @@ Title="StationManagementPage" d:DesignHeight="450" d:DesignWidth="800" + FontFamily="Microsoft YaHei" Foreground="{DynamicResource TextFillColorPrimaryBrush}" mc:Ignorable="d" - FontFamily="Microsoft YaHei"> + > + + + + + + + + + + + + + + + + @@ -84,8 +119,8 @@ - + @@ -143,6 +178,7 @@ + @@ -160,10 +196,14 @@ Style="{StaticResource BodyTextBlockStyle}"/> - + + @@ -234,10 +274,8 @@ - + @@ -245,36 +283,6 @@ - - - - - - - @@ -349,10 +357,8 @@ - + @@ -365,36 +371,6 @@ - - - - - - - @@ -468,47 +444,20 @@ - + - + + + + + + - - - - - - - @@ -610,16 +559,19 @@ - + + + + + + @@ -656,39 +608,7 @@ - - - - - - - - - @@ -711,7 +631,7 @@ 请再次检查各设施配置是否正确 + + + + + + + + + CommunityToolkit.Mvvm + + + Microsoft.Extensions.DependencyInjection + + + Microsoft.Extensions.Hosting + + + + + + + + + + + + + + + + diff --git a/CRSim/Views/Pages/SettingsPage.xaml.cs b/CRSim/Views/Pages/SettingsPage.xaml.cs index 85f7df6..ed490a3 100644 --- a/CRSim/Views/Pages/SettingsPage.xaml.cs +++ b/CRSim/Views/Pages/SettingsPage.xaml.cs @@ -19,5 +19,25 @@ namespace CRSim.Views DataContext = this; InitializeComponent(); } + + private void Open_ToolkitInformation(object sender, RoutedEventArgs e) + { + Process.Start(new ProcessStartInfo("https://www.nuget.org/packages/CommunityToolkit.Mvvm/") { UseShellExecute = true }); + } + + private void Open_DIInformation(object sender, RoutedEventArgs e) + { + Process.Start(new ProcessStartInfo("https://www.nuget.org/packages/Microsoft.Extensions.DependencyInjection/") { UseShellExecute = true }); + } + + private void Open_HostingInformation(object sender, RoutedEventArgs e) + { + Process.Start(new ProcessStartInfo("https://www.nuget.org/packages/Microsoft.Extensions.Hosting") { UseShellExecute = true }); + } + + private void Open_Issues(object sender, RoutedEventArgs e) + { + Process.Start(new ProcessStartInfo("https://github.com/denglihong2007/CRSim/issues/new") { UseShellExecute = true }); + } } } diff --git a/CRSim/Views/Pages/Simulation/ScreenSimulationPage.xaml b/CRSim/Views/Pages/Simulation/ScreenSimulationPage.xaml index 568bf0f..089f0b2 100644 --- a/CRSim/Views/Pages/Simulation/ScreenSimulationPage.xaml +++ b/CRSim/Views/Pages/Simulation/ScreenSimulationPage.xaml @@ -12,6 +12,7 @@ d:DesignHeight="450" d:DesignWidth="800" Foreground="{DynamicResource TextFillColorPrimaryBrush}" + FontFamily="Microsoft YaHei" mc:Ignorable="d"> @@ -96,8 +97,7 @@ - + - + - + - - + + + + 留空即为默认 + + + @@ -179,7 +182,7 @@ 按下Esc以关闭窗口