From c9e198a8d61a1ef1742f2f39cc3ad0527c2a0b1c Mon Sep 17 00:00:00 2001 From: denglihong2007 <2639367181@qq.com> Date: Fri, 4 Apr 2025 03:06:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=AF=E9=87=8D=E5=A4=8D=E6=A3=80?= =?UTF-8?q?=E7=A5=A8=E5=8F=A3=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CRSim.Core/Models/Station.cs | 11 ----------- CRSim.Core/Models/TrainStop.cs | 14 ++++++++------ CRSim.Core/Services/DatabaseService.cs | 12 ++++++++++++ .../ViewModels/Windows/ScreenViewModel.cs | 4 ++-- .../StationManagementPageViewModel.cs | 9 +++++---- .../Simulation/ScreenSimulationPageViewModel.cs | 7 +++++-- .../DataManagement/StationManagementPage.xaml | 5 +++++ .../DataManagement/TrainNumberManagementPage.xaml | 14 -------------- .../Views/Windows/Dialogs/TrainStopDialog.xaml.cs | 8 +++++--- 9 files changed, 42 insertions(+), 42 deletions(-) diff --git a/CRSim.Core/Models/Station.cs b/CRSim.Core/Models/Station.cs index 847885f..bbf5fd1 100644 --- a/CRSim.Core/Models/Station.cs +++ b/CRSim.Core/Models/Station.cs @@ -12,17 +12,6 @@ namespace CRSim.Core.Models public string Name { get; set; } public List WaitingAreas { get; set; } = []; - - [JsonIgnore] - public List TicketChecks - { - get - { - List ticketChecks = []; - ticketChecks.AddRange([.. WaitingAreas.SelectMany(wa => wa.TicketChecks)]); - return ticketChecks; - } - } public List TrainStops { get; set; } = []; diff --git a/CRSim.Core/Models/TrainStop.cs b/CRSim.Core/Models/TrainStop.cs index c0f6f43..b85d22b 100644 --- a/CRSim.Core/Models/TrainStop.cs +++ b/CRSim.Core/Models/TrainStop.cs @@ -5,9 +5,9 @@ namespace CRSim.Core.Models { public class TrainStop { - public string Number { get; set; } + public string? Number { get; set; } - public string Station { get; set; } + public string? Station { get; set; } [JsonConverter(typeof(TimeSpanJsonConverter))] public TimeSpan? ArrivalTime { get; set; } @@ -15,13 +15,15 @@ namespace CRSim.Core.Models [JsonConverter(typeof(TimeSpanJsonConverter))] public TimeSpan? DepartureTime { get; set; } - public List TicketChecks { get; set; } + public List? TicketChecks { get; set; } - public string Origin { get; set; } + public string? WaitingArea { get; set; } - public string Terminal { get; set; } + public string? Origin { get; set; } - public string Platform { get; set; } + public string? Terminal { get; set; } + + public string? Platform { get; set; } public string? Landmark { get; set; } diff --git a/CRSim.Core/Services/DatabaseService.cs b/CRSim.Core/Services/DatabaseService.cs index 751b925..96d4ece 100644 --- a/CRSim.Core/Services/DatabaseService.cs +++ b/CRSim.Core/Services/DatabaseService.cs @@ -36,6 +36,17 @@ namespace CRSim.Core.Services var data = JsonSerializer.Deserialize(json); _stations = data.Stations; _trainNumbers = data.TrainNumbers; + + foreach (var station in _stations) + { + foreach(var trainStop in station.TrainStops) + { + if (trainStop.WaitingArea == null) + { + trainStop.WaitingArea = station.WaitingAreas.Where(x => x.TicketChecks.Contains(trainStop.TicketChecks[0])).FirstOrDefault().Name; + } + } + }// 修复旧版本的数据 } catch { @@ -191,6 +202,7 @@ namespace CRSim.Core.Services TicketChecks = [.. ticketCheck.Split('|')], ArrivalTime = arrivalTime, DepartureTime = departureTime, + WaitingArea = waitingAreaName, 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.ScreenSimulator/ViewModels/Windows/ScreenViewModel.cs b/CRSim.ScreenSimulator/ViewModels/Windows/ScreenViewModel.cs index 138d961..1fcd884 100644 --- a/CRSim.ScreenSimulator/ViewModels/Windows/ScreenViewModel.cs +++ b/CRSim.ScreenSimulator/ViewModels/Windows/ScreenViewModel.cs @@ -82,7 +82,7 @@ namespace CRSim.ScreenSimulator.ViewModels { ThisStation = station; ThisPlatform = platform; - ThisTicketCheck = ticketCheck; + ThisTicketCheck = ticketCheck.Split(" - ")[1];//重复检票口名称的临时解决方案 var trains = station.TrainStops; foreach (var trainNumber in trains) { @@ -91,7 +91,7 @@ namespace CRSim.ScreenSimulator.ViewModels (StationType == StationType.Both || trainNumber.StationType == StationType.Both || StationType == trainNumber.StationType) && - (ticketCheck == string.Empty || trainNumber.TicketChecks.Contains(ticketCheck)) && + (ticketCheck == string.Empty || (trainNumber.WaitingArea==ticketCheck.Split(" - ")[0] && trainNumber.TicketChecks.Contains(ticketCheck.Split(" - ")[1]))) &&//重复检票口名称的临时解决方案 (platform == string.Empty || trainNumber.Platform == platform)) { var now = _timeService.GetDateTimeNow(); diff --git a/CRSim/ViewModels/Pages/DataManagement/StationManagementPageViewModel.cs b/CRSim/ViewModels/Pages/DataManagement/StationManagementPageViewModel.cs index 66ecde4..2f91daf 100644 --- a/CRSim/ViewModels/Pages/DataManagement/StationManagementPageViewModel.cs +++ b/CRSim/ViewModels/Pages/DataManagement/StationManagementPageViewModel.cs @@ -167,7 +167,7 @@ public partial class StationManagementPageViewModel : ObservableObject { foreach (string ticketCheck in ticketChecks) { - if (TicketChecks.Select(x => x.Name).Contains(ticketCheck)) + if (TicketChecks.Where(x => x.WaitingAreaName == waitingAreaName).Select(x => x.Name).Contains(ticketCheck)) { _dialogService.ShowMessage("添加失败", $"编号 {ticketCheck} 检票口已存在。"); return; @@ -417,7 +417,7 @@ public partial class StationManagementPageViewModel : ObservableObject [RelayCommand] public void AddTrainStop() { - var newTrainStop = _dialogService.GetInputTrainStop([.. TicketChecks.Select(x => x.Name)], [.. Platforms.Select(x => x.Name)]); + var newTrainStop = _dialogService.GetInputTrainStop([.. TicketChecks.Select(x => $"{x.WaitingAreaName} - {x.Name}")], [.. Platforms.Select(x => x.Name)]); if (newTrainStop != null) { if (TrainStops.Any(x => x.Number == newTrainStop.Number)) @@ -447,7 +447,7 @@ public partial class StationManagementPageViewModel : ObservableObject { if (_selectedTrainStop is TrainStop selectedTrainStop) { - var newTrainStop = _dialogService.GetInputTrainStop([.. TicketChecks.Select(x => x.Name)], [.. Platforms.Select(x => x.Name)], selectedTrainStop); + var newTrainStop = _dialogService.GetInputTrainStop([.. TicketChecks.Select(x => $"{x.WaitingAreaName} - {x.Name}")], [.. Platforms.Select(x => x.Name)], selectedTrainStop); if (newTrainStop != null) { TrainStops[TrainStops.IndexOf(selectedTrainStop)] = newTrainStop; @@ -495,11 +495,12 @@ public partial class StationManagementPageViewModel : ObservableObject } private TrainStop RandomTrainStopProperties(TrainStop t) { - 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; + t.Platform = Platforms[new Random().Next(Platforms.Count)].Name; t.TicketChecks = [.. TicketChecks.Where(x => x.Name == t.Platform + "A" || x.Name == t.Platform + "B").Select(x => x.Name)]; if (t.TicketChecks.Count == 0) t.TicketChecks = [TicketChecks[new Random().Next(TicketChecks.Count)].Name]; + t.WaitingArea = TicketChecks.Where(x => x.Name == t.TicketChecks[0]).ToList()[new Random().Next(TicketChecks.Where(x => x.Name == t.TicketChecks[0]).ToList().Count)].WaitingAreaName; return t; } #endregion diff --git a/CRSim/ViewModels/Pages/Simulation/ScreenSimulationPageViewModel.cs b/CRSim/ViewModels/Pages/Simulation/ScreenSimulationPageViewModel.cs index 9415026..2eb25b0 100644 --- a/CRSim/ViewModels/Pages/Simulation/ScreenSimulationPageViewModel.cs +++ b/CRSim/ViewModels/Pages/Simulation/ScreenSimulationPageViewModel.cs @@ -109,9 +109,12 @@ public partial class ScreenSimulationPageViewModel : ObservableObject SelectedTicketCheck = ""; SelectedLoaction = 0; TicketChecks.Clear(); - foreach(string ticketCheck in station.TicketChecks) + foreach (var waitingArea in station.WaitingAreas) { - TicketChecks.Add(ticketCheck); + foreach (string ticketCheck in waitingArea.TicketChecks) + { + TicketChecks.Add($"{waitingArea.Name} - {ticketCheck}");//重复检票口名称的临时解决方案 + } } Platforms.Clear(); foreach (var platform in station.Platforms) diff --git a/CRSim/Views/Pages/DataManagement/StationManagementPage.xaml b/CRSim/Views/Pages/DataManagement/StationManagementPage.xaml index 629f4e8..3d0f7fd 100644 --- a/CRSim/Views/Pages/DataManagement/StationManagementPage.xaml +++ b/CRSim/Views/Pages/DataManagement/StationManagementPage.xaml @@ -609,6 +609,11 @@ + + + + + diff --git a/CRSim/Views/Pages/DataManagement/TrainNumberManagementPage.xaml b/CRSim/Views/Pages/DataManagement/TrainNumberManagementPage.xaml index 4898075..9156159 100644 --- a/CRSim/Views/Pages/DataManagement/TrainNumberManagementPage.xaml +++ b/CRSim/Views/Pages/DataManagement/TrainNumberManagementPage.xaml @@ -480,13 +480,6 @@ - - - - - - - @@ -613,13 +606,6 @@ - - - - - - - diff --git a/CRSim/Views/Windows/Dialogs/TrainStopDialog.xaml.cs b/CRSim/Views/Windows/Dialogs/TrainStopDialog.xaml.cs index 338c8ca..1507f3a 100644 --- a/CRSim/Views/Windows/Dialogs/TrainStopDialog.xaml.cs +++ b/CRSim/Views/Windows/Dialogs/TrainStopDialog.xaml.cs @@ -124,10 +124,11 @@ namespace CRSim.Views Origin = DepartureTextBox.Text, ArrivalTime = StartHour.IsEnabled ? TimeSpan.Parse($"{StartHour.Text}:{StartMinute.Text}") : null, DepartureTime = EndHour.IsEnabled ? TimeSpan.Parse($"{EndHour.Text}:{EndMinute.Text}") : null, - TicketChecks = [.. TicketChecksList.Where(x => x.Checked).Select(x => x.TicketCheck)], + WaitingArea = TicketChecksList.Where(x => x.Checked).FirstOrDefault().TicketCheck.Split(" - ")[0], + TicketChecks = [.. TicketChecksList.Where(x => x.Checked).Select(x => x.TicketCheck.Split(" - ")[1])], Platform = (string)PlatformComboBox.SelectedItem, Length = int.Parse(LengthTextBox.Text), - Landmark = (string)LandmarkComboBox.SelectedItem == "无" ? null: (string)LandmarkComboBox.SelectedItem, + Landmark = (string)LandmarkComboBox.SelectedItem == "无" ? null : (string)LandmarkComboBox.SelectedItem, }; DialogResult = true; Close(); @@ -192,7 +193,8 @@ namespace CRSim.Views (!EndMinute.IsEnabled || ValidateTime(EndMinute.Text, 60)); AccentButton.IsEnabled = - (!TicketChecksCheckList.IsEnabled || TicketChecksList.Any(x => x.Checked)) && + (!TicketChecksCheckList.IsEnabled || + (TicketChecksList.Any(x => x.Checked) && TicketChecksList.Where(x=>x.Checked).Select(x=>x.TicketCheck.Split(" - ")[0]).Distinct().Count() <= 1)) && areTextBoxesFilled && !string.IsNullOrWhiteSpace(NumberTextBox.Text) && !string.IsNullOrWhiteSpace(ArrivalTextBox.Text) &&