WindturbineDetailsView.xaml.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using NEIntelligentControl2.Models.Windturbine;
  2. using NEIntelligentControl2.Models.WinForms;
  3. using NEIntelligentControl2.Service.Windturbine;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Navigation;
  17. using System.Windows.Shapes;
  18. namespace NEIntelligentControl2.Views.Infos
  19. {
  20. /// <summary>
  21. /// 风机详情弹窗视图
  22. /// </summary>
  23. public partial class WindturbineDetailsView : UserControl
  24. {
  25. private IList<UniformCodeInfo> UniformCodeInfos;
  26. private WindturbineInfo info;
  27. private List<WindturbineDetailsCard> _Cards;
  28. private DateTime _DataRefreshTime;
  29. private InfoManager _InfoManager;
  30. private string[] _UniformCodes;
  31. public string ToolTipValue { get => tbcontent.Text; internal set => tbcontent.Text = value; }
  32. public WindturbineDetailsView(WindturbineInfo windturbineInfo)
  33. {
  34. InitializeComponent();
  35. info = windturbineInfo;
  36. tbtitle.Text = windturbineInfo.WindturbineId;
  37. _Cards = new List<WindturbineDetailsCard>();
  38. _InfoManager = App.GetService<InfoManager>();
  39. Init();
  40. }
  41. /// <summary>
  42. /// 刷新数据
  43. /// </summary>
  44. internal void RefreshData()
  45. {
  46. if ((DateTime.Now - _DataRefreshTime).TotalSeconds < 5) return;
  47. Task.Run(() =>
  48. {
  49. try
  50. {
  51. var vs = _InfoManager.GetPointDatas(info.WindturbineId, _UniformCodes);
  52. Dispatcher.Invoke(() =>
  53. {
  54. foreach(var v in _Cards)
  55. {
  56. v.RefreshData(vs);
  57. }
  58. });
  59. }
  60. catch { }
  61. });
  62. _DataRefreshTime = DateTime.Now;
  63. }
  64. private void Init()
  65. {
  66. UniformCodeInfos = App.GetService<InfoManager>().GetUniformCode(info.StationId, info.ModelId);
  67. var gp = UniformCodeInfos.GroupBy(u => u.PartName);
  68. foreach(var v in gp)
  69. {
  70. WindturbineDetailsCard windturbineDetailsCard = new WindturbineDetailsCard() { CardTitle = v.Key, Items = v.ToList(), Info = info };
  71. _Cards.Add(windturbineDetailsCard);
  72. sp.Children.Add(windturbineDetailsCard);
  73. }
  74. _UniformCodes = UniformCodeInfos.Select(u => u.UniformCode).ToArray();
  75. }
  76. }
  77. }