You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

235 lines
8.6 KiB
C#

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
using SlnMesnac.Business.@base;
using static Microsoft.WindowsAPICodePack.Shell.PropertySystem.SystemProperties.System;
using SlnMesnac.Repository.service;
using SlnMesnac.Repository;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.DependencyInjection;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* T14-GEN3-7895
* SlnMesnac.WPF.ViewModel.IndexPage
* ffdc8ddd-928f-4910-b6ac-d6d6426c39d0
*
* WenJY
*
* 2024-09-05 15:05:57
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.WPF.ViewModel.IndexPage
{
public partial class IndexContentViewModel: ObservableObject
{
private ILogger<IndexContentViewModel> _logger;
private IAirportTaskService _service;
private DispatcherTimer _timer;
public IndexContentViewModel()
{
LogMessages = new ObservableCollection<string>();
_service = App.ServiceProvider.GetService<IAirportTaskService>();
this.Init();
}
private void Init()
{
#region 测试数据
List<AirportTask> AirportTaskItem = _service.GetTaskInfos();
TaskItems = new ObservableCollection<AirportTask>(AirportTaskItem);
// TaskItems = new ObservableCollection<AirportTask>
// {
// new AirportTask { TaskCode = "1", StationName = "1#站台", TaskDetails = "入库P04->C01", Status = "任务状态:执行中" },
// new TaskItem { TaskCode = "2", StationName = "2#站台", TaskDetails = "入库P04->C01", Status = "任务状态:执行中" },
// new TaskItem { TaskCode = "3", StationName = "3#站台", TaskDetails = "入库P04->C01", Status = "任务状态:执行中" },
// new TaskItem { TaskCode = "4", StationName = "4#站台", TaskDetails = "入库P04->C01", Status = "任务状态:执行中" },
// new TaskItem { TaskCode = "5", StationName = "5#站台", TaskDetails = "入库P04->C01", Status = "任务状态:执行中" },
// new TaskItem { TaskCode = "6", StationName = "6#站台", TaskDetails = "入库P04->C01", Status = "任务状态:执行中" },
// };
RefreshLogMessage($"1#站台任务下发站台任务下发站台任务下发站台任务下发站台任务下发站台任务下发");
RefreshLogMessage($"2#站台任务下发");
RefreshLogMessage($"3#站台任务下发");
RefreshLogMessage($"4#站台任务下发");
RefreshLogMessage($"5#站台任务下发");
RefreshLogMessage($"6#站台任务下发");
RefreshLogMessage($"7#站台任务下发");
RefreshLogMessage($"2#站台任务下发");
RefreshLogMessage($"3#站台任务下发");
RefreshLogMessage($"4#站台任务下发");
RefreshLogMessage($"5#站台任务下发");
RefreshLogMessage($"6#站台任务下发");
RefreshLogMessage($"7#站台任务下发");
FlightItems = new ObservableCollection<FlightItem>
{
new FlightItem { flightNumber = "航班号CZ3021", scheduledTime = "计划/变更11:28", destination = "经停/目的:深圳",flightStatus="状态:到达",baggageClaim="转盘1" },
new FlightItem { flightNumber = "航班号CZ3022", scheduledTime = "计划/变更11:28", destination = "经停/目的:深圳",flightStatus="状态:到达",baggageClaim="转盘1" },
new FlightItem { flightNumber = "航班号CZ3023", scheduledTime = "计划/变更11:28", destination = "经停/目的:深圳",flightStatus="状态:到达",baggageClaim="转盘1" },
new FlightItem { flightNumber = "航班号CZ3024", scheduledTime = "计划/变更11:28", destination = "经停/目的:深圳",flightStatus="状态:到达",baggageClaim="转盘1" },
new FlightItem { flightNumber = "航班号CZ3025", scheduledTime = "计划/变更11:28", destination = "经停/目的:深圳",flightStatus="状态:到达",baggageClaim="转盘1" },
new FlightItem { flightNumber = "航班号CZ3026", scheduledTime = "计划/变更11:28", destination = "经停/目的:深圳",flightStatus="状态:到达",baggageClaim="转盘1" },
new FlightItem { flightNumber = "航班号CZ3027", scheduledTime = "计划/变更11:28", destination = "经停/目的:深圳",flightStatus="状态:到达",baggageClaim="转盘1" },
};
#endregion
#region 更新时间显示
_currentDateTime = DateTime.Now;
_timer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(1) // 每秒更新一次
};
_timer.Tick += (s, e) =>
{
CurrentDateTime = DateTime.Now;
};
_timer.Start();
#endregion
}
#region 参数定义
/// <summary>
/// 任务列表
/// </summary>
private ObservableCollection<AirportTask> _taskItems = new ObservableCollection<AirportTask>();
public ObservableCollection<AirportTask> TaskItems
{
get => _taskItems;
set => SetProperty(ref _taskItems, value);
}
/// <summary>
/// 日志信息
/// </summary>
private ObservableCollection<string> _logMessages = new ObservableCollection<string>();
public ObservableCollection<string> LogMessages
{
get => _logMessages;
set => SetProperty(ref _logMessages, value);
}
/// <summary>
/// 日期时间
/// </summary>
private DateTime _currentDateTime;
public DateTime CurrentDateTime
{
get => _currentDateTime;
set
{
if (_currentDateTime != value)
{
SetProperty(ref _currentDateTime, value);
}
}
}
/// <summary>
/// 航班信息
/// </summary>
private ObservableCollection<FlightItem> _flightItems = new ObservableCollection<FlightItem>();
public ObservableCollection<FlightItem> FlightItems
{
get => _flightItems;
set => SetProperty(ref _flightItems, value);
}
#endregion
/// <summary>
/// 刷新日志
/// </summary>
/// <param name="msg"></param>
private void RefreshLogMessage(string msg)
{
App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
LogMessages.Add($"{DateTime.Now}: {msg}");
}));
}
/// <summary>
/// 添加任务
/// </summary>
[RelayCommand]
private void AddTask()
{
MessageBox.Show("添加任务");
}
/// <summary>
/// 处理任务
/// </summary>
/// <param name="taskCode"></param>
[RelayCommand]
private void HandleTask(string taskCode)
{
var info = taskCode;
}
/// <summary>
/// 删除任务
/// </summary>
/// <param name="taskCode"></param>
[RelayCommand]
private void DeleteTask(string taskCode)
{
var info = taskCode;
}
/// <summary>
/// 手动呼叫
/// </summary>
[RelayCommand]
private void ManualCall()
{
MessageBox.Show("手动呼叫");
}
/// <summary>
/// 手动终止
/// </summary>
[RelayCommand]
private void ManualTerminate()
{
MessageBox.Show("手动终止");
}
/// <summary>
/// 复位
/// </summary>
[RelayCommand]
private void Reset()
{
MessageBox.Show("复位");
}
}
}