mirror of
https://github.com/denglihong2007/CRSim
synced 2026-05-15 08:05:41 +08:00
61 lines
2.5 KiB
C#
61 lines
2.5 KiB
C#
using CRSim.Core.Models;
|
|
using CRSim.Core.Services;
|
|
using CRSim.ScreenSimulator.Models;
|
|
using System.Collections.ObjectModel;
|
|
using System.Windows;
|
|
namespace CRSim.ScreenSimulator.ViewModels.Harbin
|
|
{
|
|
public class PrimaryScreenViewModel : ScreenViewModel
|
|
{
|
|
public ObservableCollection<TrainInfo> LeftScreen { get; private set; } = [];
|
|
public ObservableCollection<TrainInfo> RightScreen { get; private set; } = [];
|
|
public PrimaryScreenViewModel(ITimeService timeService, ISettingsService settingsService)
|
|
: base(timeService, settingsService)
|
|
{
|
|
Text = $"开车前{settingsService.GetSettings().StopCheckInAdvanceDuration.TotalMinutes}分钟停止检票";
|
|
ItemsPerPage = 6;
|
|
PageCount = 2;
|
|
StationType = StationType.Departure;
|
|
timeService.RefreshSecondsElapsed += RefreshDisplay;
|
|
Initialize();
|
|
}
|
|
private async void Initialize()
|
|
{
|
|
await WaitForDataLoadAsync();
|
|
RefreshDisplay(null,null);
|
|
}
|
|
private void RefreshDisplay(object? sender, EventArgs e)
|
|
{
|
|
Application.Current.Dispatcher.Invoke(() =>
|
|
{
|
|
int pageCount = (int)Math.Ceiling((double)TrainInfo.Count / (ItemsPerPage * PageCount));
|
|
LeftScreen.Clear();
|
|
RightScreen.Clear();
|
|
int startIndex = CurrentPageIndex * ItemsPerPage * PageCount;
|
|
var leftItems = TrainInfo.Skip(startIndex).Take(ItemsPerPage).ToList();
|
|
while (leftItems.Count < ItemsPerPage) // Fill up with new object() if not enough items
|
|
{
|
|
leftItems.Add(new TrainInfo());
|
|
}
|
|
foreach (var item in leftItems)
|
|
{
|
|
LeftScreen.Add(item);
|
|
}
|
|
|
|
// Get the slice for the right screen (next 12)
|
|
var rightItems = TrainInfo.Skip(startIndex + ItemsPerPage).Take(ItemsPerPage).ToList();
|
|
while (rightItems.Count < ItemsPerPage) // Fill up with new object() if not enough items
|
|
{
|
|
rightItems.Add(new TrainInfo());
|
|
}
|
|
foreach (var item in rightItems)
|
|
{
|
|
RightScreen.Add(item);
|
|
}
|
|
|
|
CurrentPageIndex = CurrentPageIndex + 1 >= Math.Min(_settings.MaxPages, pageCount) ? 0 : CurrentPageIndex + 1;
|
|
});
|
|
}
|
|
}
|
|
}
|