AlarmViewModel.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using HardwareData;
  2. namespace HistoryUI.ViewModels;
  3. public partial class AlarmViewModel(Hardwares hardwares, IORM orm) : BaseViewModel<DBWarning>(hardwares, orm)
  4. {
  5. [RelayCommand]
  6. protected override void Query()
  7. {
  8. if (!base.QueryBase(out byte mini8, out byte Channel))
  9. return;
  10. //ChannelData channelData = new();
  11. //channelData.ChannelIndex = 0;
  12. //channelData.Name = "All";
  13. //base.Channels[0] = channelData;
  14. _orm.Query<DBWarning>($"Error-Mini8-{mini8}",
  15. t => t.DateTime >= this.StartTime
  16. && t.DateTime <= this.EndTime &&
  17. t.PV < 1600 && t.PV > 10,
  18. QueryResult);
  19. }
  20. private void QueryResult(List<DBWarning> results)
  21. {
  22. App.Current.Dispatcher?.Invoke(() =>
  23. {
  24. base.Results ??= [];
  25. base.Results?.Clear();
  26. });
  27. Task.Factory.StartNew(() =>
  28. {
  29. results = [.. results.OrderBy(t => t.DateTime)];
  30. for (int i = 1; i <= results.Count; i++)
  31. {
  32. App.Current.Dispatcher?.Invoke(() =>
  33. {
  34. base.Results!.Add(i, results[i - 1]);
  35. });
  36. }
  37. });
  38. }
  39. }