feat: 可重复检票口名

This commit is contained in:
denglihong2007
2025-04-04 03:06:52 +08:00
parent a15b741825
commit c9e198a8d6
9 changed files with 42 additions and 42 deletions

View File

@@ -12,17 +12,6 @@ namespace CRSim.Core.Models
public string Name { get; set; }
public List<WaitingArea> WaitingAreas { get; set; } = [];
[JsonIgnore]
public List<string> TicketChecks
{
get
{
List<string> ticketChecks = [];
ticketChecks.AddRange([.. WaitingAreas.SelectMany(wa => wa.TicketChecks)]);
return ticketChecks;
}
}
public List<TrainStop> TrainStops { get; set; } = [];

View File

@@ -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<string> TicketChecks { get; set; }
public List<string>? 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; }

View File

@@ -36,6 +36,17 @@ namespace CRSim.Core.Services
var data = JsonSerializer.Deserialize<Json>(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,

View File

@@ -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();

View File

@@ -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

View File

@@ -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)

View File

@@ -609,6 +609,11 @@
<TextBlock Text="发时" Opacity="0.7" Style="{StaticResource CaptionTextBlockStyle}"/>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding WaitingArea}">
<DataGridTextColumn.Header>
<TextBlock Text="候车区" Opacity="0.7" Style="{StaticResource CaptionTextBlockStyle}"/>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding TicketChecks,Converter={StaticResource ListToStringConverter}}">
<DataGridTextColumn.Header>
<TextBlock Text="检票口" Opacity="0.7" Style="{StaticResource CaptionTextBlockStyle}"/>

View File

@@ -480,13 +480,6 @@
<TextBlock Focusable="False" FontFamily="{StaticResource SymbolThemeFontFamily}"
FontSize="16" Text="&#xE8B6;" VerticalAlignment="Center"/>
</MenuItem.Header>
<MenuItem Header="联网获取" FontSize="14" IsEnabled="False">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{Binding ViewModel.QuantityImportFromInternetCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</MenuItem>
<MenuItem Header="从Excel表格导入" FontSize="14">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
@@ -613,13 +606,6 @@
<TextBlock Focusable="False" FontFamily="{StaticResource SymbolThemeFontFamily}"
FontSize="16" Text="&#xE8B6;" VerticalAlignment="Center"/>
</MenuItem.Header>
<MenuItem Header="联网获取" FontSize="14" IsEnabled="False">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{Binding ViewModel.PriceImportFromInternetCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</MenuItem>
<MenuItem Header="从Excel表格导入" FontSize="14">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">

View File

@@ -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) &&