From 025878f4f0cb490bd7bf7c35eecfac4cd508cb4e Mon Sep 17 00:00:00 2001 From: denglihong2007 <2639367181@qq.com> Date: Fri, 14 Mar 2025 01:48:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=9D=E5=AD=98=E6=97=B6=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CRSim/CRSim.csproj | 2 +- CRSim/Properties/GlobalUsings.cs | 4 +- CRSim/Services/DialogService.cs | 6 +-- .../StationManagementPageViewModel.cs | 37 ++++++++++++++++--- .../DataManagement/StationManagementPage.xaml | 2 +- .../Windows/Dialogs/LongMessageDialog.xaml | 24 ++++++++++++ .../Windows/Dialogs/LongMessageDialog.xaml.cs | 33 +++++++++++++++++ 7 files changed, 95 insertions(+), 13 deletions(-) create mode 100644 CRSim/Views/Windows/Dialogs/LongMessageDialog.xaml create mode 100644 CRSim/Views/Windows/Dialogs/LongMessageDialog.xaml.cs diff --git a/CRSim/CRSim.csproj b/CRSim/CRSim.csproj index bd9d679..965c8c4 100644 --- a/CRSim/CRSim.csproj +++ b/CRSim/CRSim.csproj @@ -9,7 +9,7 @@ 13.0 CRSim.App Assets\CRSimIcon.ico - 1.2.6.0 + 1.2.7.0 diff --git a/CRSim/Properties/GlobalUsings.cs b/CRSim/Properties/GlobalUsings.cs index 6b10b1b..f1a2595 100644 --- a/CRSim/Properties/GlobalUsings.cs +++ b/CRSim/Properties/GlobalUsings.cs @@ -1,8 +1,10 @@ -锘縢lobal using System.Diagnostics; +锘縢lobal using System.IO; +global using System.Diagnostics; global using System.Globalization; global using System.ComponentModel; global using System.Collections.ObjectModel; global using System.Reflection; +global using System.Text; global using System.Text.Json; global using System.Windows; global using System.Windows.Data; diff --git a/CRSim/Services/DialogService.cs b/CRSim/Services/DialogService.cs index 911d033..2288859 100644 --- a/CRSim/Services/DialogService.cs +++ b/CRSim/Services/DialogService.cs @@ -37,10 +37,8 @@ namespace CRSim.Services } public void ShowMessage(string title, string message) { - var dialog = new MessageDialog(title, message) - { - Owner = _owner - }; + dynamic dialog = message.Length > 25 ? new LongMessageDialog(title, message) : new MessageDialog(title, message); + dialog.Owner = _owner; dialog.ShowDialog(); } diff --git a/CRSim/ViewModels/Pages/DataManagement/StationManagementPageViewModel.cs b/CRSim/ViewModels/Pages/DataManagement/StationManagementPageViewModel.cs index dfcbab3..de2d0b3 100644 --- a/CRSim/ViewModels/Pages/DataManagement/StationManagementPageViewModel.cs +++ b/CRSim/ViewModels/Pages/DataManagement/StationManagementPageViewModel.cs @@ -1,9 +1,3 @@ -using CRSim.Core.Models; -using System.IO; -using System.Linq; -using System.Text; -using static System.Runtime.InteropServices.JavaScript.JSType; - namespace CRSim.ViewModels; public partial class StationManagementPageViewModel : ObservableObject @@ -223,9 +217,40 @@ public partial class StationManagementPageViewModel : ObservableObject [RelayCommand] public async Task SaveChanges() { + if (!(await Validate())) return; _databaseService.UpdateStation(SelectedStation.Name, GenerateStation(SelectedStation.Name,WaitingAreaNames,TicketChecks,StationStops,Platforms)); await _databaseService.SaveData(); } + + private Task Validate() + { + string message = ""; + foreach(var t in TicketChecks) + { + if (!WaitingAreaNames.Contains(t.WaitingAreaName)) + { + message += $"\n检票口 {t.Name} 所在的候车室 {t.WaitingAreaName} 不存在;"; + } + } + foreach(var s in StationStops) + { + if(!Platforms.Any(x=> x.Name == s.Platform)) + { + message += $"\n车次 {s.Number} 所分配的站台 {s.Platform} 不存在;"; + } + foreach(var t in s.TicketChecks) + { + if (!TicketChecks.Any(x => x.Name==t)) + { + message += $"\n车次 {s.Number} 所分配的检票口 {t} 不存在;"; + } + } + } + if (message == "") return Task.FromResult(true); + _dialogService.ShowMessage("保存失败", $"发现 {message.Split("\n").Length-1} 个错误:{message}\n请修复所有错误后再次尝试保存。"); + return Task.FromResult(false); + } + public static Station GenerateStation(string stationName, ObservableCollection waitingAreaNames, ObservableCollection ticketChecks,ObservableCollection stationStops,ObservableCollection platforms) { var station = new Station diff --git a/CRSim/Views/Pages/DataManagement/StationManagementPage.xaml b/CRSim/Views/Pages/DataManagement/StationManagementPage.xaml index f7d59b1..324b849 100644 --- a/CRSim/Views/Pages/DataManagement/StationManagementPage.xaml +++ b/CRSim/Views/Pages/DataManagement/StationManagementPage.xaml @@ -628,7 +628,7 @@ - 璇峰啀娆℃鏌ュ悇璁炬柦閰嶇疆鏄惁姝g‘ + 楠岃瘉骞朵繚瀛樻暟鎹厤缃