终端一体化运控平台
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

127 rader
4.6 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using BPA.Helper;
  7. using System.Collections.ObjectModel;
  8. using BPASmartClient.CustomResource.Pages.Model;
  9. using System.Windows;
  10. using BPA.Helper;
  11. namespace BPASmartClient.CustomResource.Pages.ViewModel
  12. {
  13. public class RecipeCompleteViewModel : NotifyBase
  14. {
  15. public RecipeCompleteViewModel()
  16. {
  17. Sqlite<RecipeCompleteLog>.GetInstance.Save();
  18. SwitchCommand = new BPARelayCommand(() =>
  19. {
  20. if (ButContent == "历史日志")
  21. {
  22. GetHistoryRunLog();
  23. CurrentDataVis = Visibility.Hidden;
  24. HistoryDataVis = Visibility.Visible;
  25. IsVisibility = Visibility.Visible;
  26. ControlButText = "开始查询";
  27. ButContent = "实时日志";
  28. return;
  29. }
  30. if (ButContent == "实时日志")
  31. {
  32. HistoryDataVis = Visibility.Hidden;
  33. CurrentDataVis = Visibility.Visible;
  34. IsVisibility = Visibility.Hidden;
  35. ButContent = "历史日志";
  36. return;
  37. }
  38. });
  39. ControlCommand = new BPARelayCommand(() =>
  40. {
  41. if (ControlButText == "报警复位") return;
  42. if (ControlButText == "开始查询")
  43. {
  44. var lists = Sqlite<RecipeCompleteLog>.GetInstance.GetData();
  45. var res = lists.Where(p => Convert.ToDateTime(p.Date) >= StartDateTime && Convert.ToDateTime(p.Date) <= EndDateTime).ToList();
  46. if (res != null)
  47. {
  48. HistoryRunLog.Clear();
  49. foreach (var item in res)
  50. {
  51. HistoryRunLog.Add(item);
  52. }
  53. }
  54. }
  55. });
  56. }
  57. private void GetHistoryRunLog()
  58. {
  59. var data = Sqlite<RecipeCompleteLog>.GetInstance.GetData();
  60. if (data != null)
  61. {
  62. HistoryRunLog.Clear();
  63. foreach (var item in data)
  64. {
  65. int day = DateTime.Now.Subtract(Convert.ToDateTime(item.Date)).Days;
  66. if (day == 0)
  67. {
  68. HistoryRunLog.Add(item);
  69. }
  70. }
  71. }
  72. }
  73. public BPARelayCommand SwitchCommand { get; set; }
  74. public BPARelayCommand ControlCommand { get; set; }
  75. public Visibility CurrentDataVis { get { return _mCurrentDataVis; } set { _mCurrentDataVis = value; OnPropertyChanged(); } }
  76. private Visibility _mCurrentDataVis = Visibility.Visible;
  77. public Visibility HistoryDataVis { get { return _mHistoryDataVis; } set { _mHistoryDataVis = value; OnPropertyChanged(); } }
  78. private Visibility _mHistoryDataVis = Visibility.Hidden;
  79. /// <summary>
  80. /// 是否显示
  81. /// </summary>
  82. public Visibility IsVisibility { get { return _mIsVisibility; } set { _mIsVisibility = value; OnPropertyChanged(); } }
  83. private Visibility _mIsVisibility = Visibility.Hidden;
  84. /// <summary>
  85. /// 文字显示
  86. /// </summary>
  87. public string ButContent { get { return _mButContent; } set { _mButContent = value; OnPropertyChanged(); } }
  88. private string _mButContent = "历史日志";
  89. /// <summary>
  90. /// 控制按钮文本显示
  91. /// </summary>
  92. public string ControlButText { get { return _mControlButText; } set { _mControlButText = value; OnPropertyChanged(); } }
  93. private string _mControlButText = "报警复位";
  94. /// <summary>
  95. /// 开始时间
  96. /// </summary>
  97. public DateTime StartDateTime { get { return _mStartDateTime; } set { _mStartDateTime = value; OnPropertyChanged(); } }
  98. private DateTime _mStartDateTime = DateTime.Now;
  99. /// <summary>
  100. /// 结束时间
  101. /// </summary>
  102. public DateTime EndDateTime { get { return _mEndDateTime; } set { _mEndDateTime = value; OnPropertyChanged(); } }
  103. private DateTime _mEndDateTime = DateTime.Now;
  104. public ObservableCollection<RecipeCompleteLog> HistoryRunLog { get; set; } = new ObservableCollection<RecipeCompleteLog>();
  105. public ObservableCollection<RecipeCompleteLog> Log { get; set; } = MessageNotify.GetInstance.recipeLogs;
  106. }
  107. }