RecipeStepNaviViewModel.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using DryIoc.FastExpressionCompiler.LightExpression;
  2. using ProximaAnalizer.Data;
  3. using System.Collections.ObjectModel;
  4. using System.Net.NetworkInformation;
  5. using System.Windows;
  6. namespace ProximaAnalizer.ViewModels;
  7. internal partial class RecipeStepNaviViewModel(IEventAggregator eventAggregator, SqlSugarCustom sqlSugar, TraceData traceData) : ObservableObject
  8. {
  9. [ObservableProperty]
  10. private DateTime _SelectedTime = DateTime.Now;
  11. [ObservableProperty]
  12. private Visibility _Masking = Visibility.Hidden;
  13. [ObservableProperty]
  14. private ObservableCollection<ProcessData> _ProcessData = [];
  15. partial void OnSelectedTimeChanged(DateTime value)
  16. {
  17. this.Search();
  18. }
  19. [RelayCommand]
  20. private void Navi(ProcessData process)
  21. {
  22. this.Masking = Visibility.Visible;
  23. traceData.ProcessData = process;
  24. Task.Factory.StartNew(() =>
  25. {
  26. try
  27. {
  28. Thread.Sleep(200);
  29. App.Current.Dispatcher.Invoke(() =>
  30. {
  31. eventAggregator.GetEvent<WindowSwitch>().Page = Pages.MainWindow;
  32. eventAggregator.GetEvent<WindowSwitch>().Publish();
  33. eventAggregator.GetEvent<RefreshRecipeData>().Publish();
  34. });
  35. }
  36. finally
  37. {
  38. this.Masking = Visibility.Collapsed;
  39. }
  40. });
  41. }
  42. [RelayCommand]
  43. private void DayOperator(string para)
  44. {
  45. this.SelectedTime = para switch
  46. {
  47. "+" => this.SelectedTime.AddDays(1),
  48. "-" => this.SelectedTime.AddDays(-1),
  49. _ => this.SelectedTime
  50. };
  51. }
  52. [RelayCommand]
  53. private void Search()
  54. {
  55. if (sqlSugar.Client is null)
  56. return;
  57. this.ProcessData ??= [];
  58. this.ProcessData.Clear();
  59. this.Masking = Visibility.Visible;
  60. Task.Factory.StartNew(() =>
  61. {
  62. try
  63. {
  64. var t = sqlSugar.Client.Queryable<ProcessData>().Where(t =>
  65. t.Process_Begin_Time >= SelectedTime &&
  66. t.Process_Begin_Time < SelectedTime.AddDays(1)).AS("process_data").ToArray();
  67. foreach (var item in t)
  68. {
  69. App.Current.Dispatcher.Invoke(() =>
  70. {
  71. this.ProcessData.Add(item);
  72. });
  73. Thread.Sleep(1);
  74. }
  75. }
  76. finally
  77. {
  78. this.Masking = Visibility.Collapsed;
  79. }
  80. });
  81. }
  82. [RelayCommand]
  83. private void NameSearch(string name)
  84. {
  85. if (sqlSugar.Client is null)
  86. return;
  87. if (string.IsNullOrEmpty(name))
  88. return;
  89. this.ProcessData ??= [];
  90. this.ProcessData.Clear();
  91. this.Masking = Visibility.Visible;
  92. Task.Factory.StartNew(() =>
  93. {
  94. try
  95. {
  96. var t = sqlSugar.Client.Queryable<ProcessData>()
  97. .Where(t => (string.IsNullOrEmpty(t.Recipe_Name) ? string.Empty : t.Recipe_Name).ToLower().Contains(name.ToLower()))
  98. .AS("process_data").ToArray()
  99. .OrderBy(t => t.Process_Begin_Time);
  100. foreach (var item in t)
  101. {
  102. App.Current.Dispatcher.Invoke(() =>
  103. {
  104. this.ProcessData.Add(item);
  105. });
  106. Thread.Sleep(1);
  107. }
  108. }
  109. finally
  110. {
  111. this.Masking = Visibility.Collapsed;
  112. }
  113. });
  114. }
  115. }