WindturbineRealTimeAlarm.xaml.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using NEIntelligentControl2.Models.Alarm;
  2. using NEIntelligentControl2.Models.Messages;
  3. using NEIntelligentControl2.Models.Windturbine;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Configuration;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Navigation;
  18. using System.Windows.Shapes;
  19. namespace NEIntelligentControl2.Views.Alarm
  20. {
  21. /// <summary>
  22. /// 风机实时报警
  23. /// </summary>
  24. public partial class WindturbineRealTimeAlarm : UserControl
  25. {
  26. private string _Url;
  27. private WEBHelper _WEBHelper;
  28. public WindturbineInfo WindturbineInfo { get; set; }
  29. public WindturbineRealTimeAlarm()
  30. {
  31. InitializeComponent();
  32. _WEBHelper = App.ServiceProvider.GetService(typeof(WEBHelper)) as WEBHelper;
  33. try
  34. {
  35. #if (DEBUG)
  36. _Url = ConfigurationManager.AppSettings["AlarmPathDebug"];
  37. #else
  38. _Url = ConfigurationManager.AppSettings["AlarmPath"];
  39. #endif
  40. }
  41. catch (Exception ex)
  42. {
  43. Console.WriteLine("读取配置文件[ServicePath]出错!", ex);
  44. }
  45. }
  46. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  47. {
  48. if (_DGMain.ItemsSource != null) return;
  49. Task.Run(() =>
  50. {
  51. try
  52. {
  53. _IBMain.Inof("查询数据...");
  54. var vs = _WEBHelper.HttpGetJSON<List<AlarmInfo>>($"{_Url}/alarm/snap?stationid={WindturbineInfo.StationId}&category1=windturbine&windturbineid={WindturbineInfo.WindturbineId}&isopened=1");
  55. DateTime dt = DateTime.Now;
  56. var ls = vs.Where(x => (dt - x.LastUpdateTime.Value).TotalDays <= 3).ToList();
  57. Dispatcher.Invoke(() =>
  58. {
  59. _DGMain.ItemsSource = ls;
  60. });
  61. _IBMain.Success();
  62. }
  63. catch (Exception ex)
  64. {
  65. _IBMain.Warning($"查询数据出现错误:{ex.Message}");
  66. return;
  67. }
  68. });
  69. }
  70. }
  71. }