197 lines
4.2 KiB
C#
197 lines
4.2 KiB
C#
using _29WxOrderWpf.Commands;
|
|
using _29WxOrderWpf.Services;
|
|
using AllBase.Model.MvvmBaseClasses;
|
|
using AllBase.Util;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Collections.Specialized;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices.ComTypes;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Timers;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
using System.Windows.Threading;
|
|
using Work.KJDServer.API.Models;
|
|
using WPFCommon.Models;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;
|
|
|
|
namespace _29WxOrderWpf.Ctrls.OrderCtrls;
|
|
|
|
/// <summary>
|
|
/// OrderTaskDialogView.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class OrderTaskDialogView : UserControl
|
|
{
|
|
private readonly OrderTaskDialogViewModel _viewModel;
|
|
|
|
public OrderTaskDialogView()
|
|
{
|
|
InitializeComponent();
|
|
this.Loaded += OrderTaskDialogView_Loaded;
|
|
_viewModel = new OrderTaskDialogViewModel();
|
|
DataContext = _viewModel;
|
|
}
|
|
|
|
private async void OrderTaskDialogView_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
_viewModel.LoadTasks();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 任务列表 - ViewModel
|
|
/// </summary>
|
|
public class OrderTaskDialogViewModel : BindableBaseEx, IDisposable
|
|
{
|
|
private DispatcherTimer _timer;
|
|
|
|
private readonly TaskService _taskService;
|
|
|
|
public OrderTaskDialogViewModel()
|
|
: this(TaskService.Instance)
|
|
{
|
|
_timer = new DispatcherTimer();
|
|
_timer.Interval = TimeSpan.FromSeconds(1);
|
|
_timer.Tick += _timer_Tick;
|
|
_timer.Start();
|
|
}
|
|
public OrderTaskDialogViewModel(TaskService taskService)
|
|
{
|
|
_taskService = taskService;
|
|
|
|
|
|
StartDate = _taskService.StartDate;
|
|
EndDate = _taskService.EndDate;
|
|
|
|
|
|
|
|
Tasks = new ObservableCollection<TaskItem>();
|
|
|
|
TasksView = CollectionViewSource.GetDefaultView(Tasks);
|
|
TasksView.Filter = FilterTaskStatus;
|
|
|
|
_taskService.TaskChanged += TaskChanged;
|
|
}
|
|
private async void _timer_Tick(object sender, EventArgs e)
|
|
{
|
|
|
|
RefreshTime = _taskService.ResetCountdown;
|
|
}
|
|
|
|
|
|
public TaskType SelectedTaskType
|
|
{
|
|
get => GetValue<TaskType>();
|
|
set
|
|
{
|
|
SetValue(value);
|
|
TasksView.Refresh();
|
|
}
|
|
}
|
|
|
|
private void TaskChanged(object sender, IEnumerable<TaskItem> data)
|
|
{
|
|
LoadTasks();
|
|
}
|
|
|
|
public void LoadTasks()
|
|
{
|
|
System.Windows.Application.Current.Dispatcher.Invoke(() =>
|
|
{
|
|
Tasks.Clear();
|
|
foreach (var item in TaskService.Instance.Tasks)
|
|
{
|
|
if (!string.IsNullOrEmpty(item.TaskFailReason))
|
|
{
|
|
if (item.TaskFailReason.Contains("任务执行异常"))
|
|
{
|
|
item.Status = 4;
|
|
}
|
|
}
|
|
Tasks.Add(item);
|
|
}
|
|
});
|
|
|
|
|
|
}
|
|
/// <summary>
|
|
/// 过滤
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
private bool FilterTaskStatus(object obj)
|
|
{
|
|
if (obj is not TaskItem task)
|
|
return false;
|
|
|
|
// Status 维度筛选
|
|
bool statusMatch = IsShowAll || task.Status != 2;
|
|
// 如果 IsShowAll=true,表示显示所有状态;否则只显示特定状态
|
|
|
|
// TaskType 维度筛选
|
|
bool typeMatch = SelectedTaskType == TaskType.ALL ? true : SelectedTaskType == task.TaskType;
|
|
bool timeMatch = StartDate <= task.CreateTime && task.CreateTime <= EndDate;
|
|
|
|
// 如果 SelectedTaskType==null,表示显示所有类型;否则只显示特定类型
|
|
return statusMatch && typeMatch && timeMatch;
|
|
}
|
|
|
|
/// <summary>任务列表</summary>
|
|
public ObservableCollection<TaskItem> Tasks { get; }
|
|
|
|
public ICollectionView TasksView { get; }
|
|
|
|
/// <summary>汇总文字(总数/执行中/成功/失败)</summary>
|
|
public string SummaryText
|
|
{
|
|
get => GetValue<string>();
|
|
set => SetValue(value);
|
|
}
|
|
public int RefreshTime
|
|
{
|
|
get => GetValue<int>();
|
|
set => SetValue(value);
|
|
}
|
|
|
|
|
|
public DateTime StartDate
|
|
{
|
|
get => GetValue<DateTime>();
|
|
set => SetValue(value);
|
|
}
|
|
public DateTime EndDate
|
|
{
|
|
get => GetValue<DateTime>();
|
|
set => SetValue(value);
|
|
}
|
|
|
|
public bool IsShowAll
|
|
{
|
|
get => GetValue<bool>();
|
|
set
|
|
{
|
|
SetValue(value);
|
|
TasksView.Refresh();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
{
|
|
_timer.Stop();
|
|
_timer = null;
|
|
}
|
|
}
|