WindBlockSmall.xaml.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. using NEIntelligentControl2.Models;
  2. using NEIntelligentControl2.Models.Windturbine;
  3. using NEIntelligentControl2.Service.WebSocket;
  4. using NEIntelligentControl2.Service.Windturbine;
  5. using NEIntelligentControl2.Views.Basic;
  6. using NEIntelligentControl2.Views.Infos;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.Windows.Controls.Primitives;
  15. using System.Windows.Data;
  16. using System.Windows.Documents;
  17. using System.Windows.Input;
  18. using System.Windows.Media;
  19. using System.Windows.Media.Imaging;
  20. using System.Windows.Navigation;
  21. using System.Windows.Shapes;
  22. namespace NEIntelligentControl2.Views.Matrix
  23. {
  24. /// <summary>
  25. /// 风机矩阵块(小)
  26. /// </summary>
  27. public partial class WindBlockSmall : UserControl, IOptional
  28. {
  29. // ----------依赖属性------------
  30. public static DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(WindBlockSmall));
  31. public static DependencyProperty TopValueProperty = DependencyProperty.Register("TopValue", typeof(string), typeof(WindBlockSmall));
  32. public static DependencyProperty MiddleValueProperty = DependencyProperty.Register("MiddleValue", typeof(string), typeof(WindBlockSmall));
  33. public static DependencyProperty BottomValueProperty = DependencyProperty.Register("BottomValue", typeof(string), typeof(WindBlockSmall));
  34. public static DependencyProperty StateProperty = DependencyProperty.Register("State", typeof(int), typeof(WindBlockSmall));
  35. public static DependencyProperty ToolTipValueProperty = DependencyProperty.Register("ToolTipValue", typeof(string), typeof(WindBlockSmall));
  36. public static DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(WindBlockSmall));
  37. /// <summary>
  38. /// 标题
  39. /// </summary>
  40. public string Title { get => GetValue(TitleProperty) as string; set => SetValue(TitleProperty, value); }
  41. /// <summary>
  42. /// 顶部数值
  43. /// </summary>
  44. public string TopValue { get => GetValue(TopValueProperty) as string; set => SetValue(TopValueProperty, value); }
  45. /// <summary>
  46. /// 中间数值
  47. /// </summary>
  48. public string MiddleValue { get => GetValue(MiddleValueProperty) as string; set => SetValue(MiddleValueProperty, value); }
  49. /// <summary>
  50. /// 底部数值
  51. /// </summary>
  52. public string BottomValue { get => GetValue(BottomValueProperty) as string; set => SetValue(BottomValueProperty, value); }
  53. /// <summary>
  54. /// 状态
  55. /// </summary>
  56. public int State
  57. {
  58. get
  59. {
  60. var v = GetValue(StateProperty);
  61. return v == null ? -1 : (int)v;
  62. }
  63. set => SetValue(StateProperty, value);
  64. }
  65. /// <summary>
  66. /// 是否被选中
  67. /// </summary>
  68. public bool IsSelected { get => (bool)GetValue(IsSelectedProperty); set => SetValue(IsSelectedProperty, value); }
  69. /// <summary>
  70. /// 状态改变时间
  71. /// </summary>
  72. public DateTime StateChangedTime { get; set; }
  73. private long _Timestamp { get; set; }// 状态持续时长
  74. /// <summary>
  75. /// 提示消息
  76. /// </summary>
  77. public string ToolTipValue { get => GetValue(ToolTipValueProperty) as string; set => SetValue(ToolTipValueProperty, value); }
  78. /// <summary>
  79. /// 标签
  80. /// </summary>
  81. public string Key { get; set; }
  82. /// <summary>
  83. /// 风机ID
  84. /// </summary>
  85. public string WindturbineId { get; set; }
  86. /// <summary>
  87. /// 被操作时间
  88. /// </summary>
  89. public DateTime OperatedTime { get; set; }
  90. // 鼠标点击事件
  91. public event SelectedEventHandler SelectedChanged;
  92. private WindturbineInfo _WindturbineInfo; // 风机数据
  93. /// <summary>
  94. /// 风机数据
  95. /// </summary>
  96. public WindturbineInfo WindturbineInfo { get => _WindturbineInfo; }
  97. /// <summary>
  98. /// 自定义挂牌信息
  99. /// </summary>
  100. public CustomLockInfo CustomLockInfo { get; internal set; }
  101. private int _PopupInterval = 0;
  102. public WindBlockSmall(WindturbineInfo v)
  103. {
  104. InitializeComponent();
  105. _WindturbineInfo = v;
  106. _PopupInterval = App.GetService<UrlManager>().WindturbineDetailsInterval;
  107. InitToolTip();
  108. }
  109. private void InitToolTip()
  110. {
  111. if (_PopupInterval <= 0) return;
  112. ToolTip tp = new ToolTip();
  113. tp.Opened += ToolTipOpened;
  114. g.ToolTip = tp;
  115. ToolTipService.SetInitialShowDelay(g, _PopupInterval);
  116. }
  117. private void ToolTipOpened(object sender, RoutedEventArgs e)
  118. {
  119. ToolTip tp = sender as ToolTip;
  120. if (tp == null) return;
  121. if (tp.Content == null)
  122. {
  123. var wdv = new WindturbineDetailsView(WindturbineInfo) { ToolTipValue =this.ToolTipValue };
  124. tp.Content = wdv;
  125. }
  126. (tp.Content as WindturbineDetailsView)?.RefreshData();
  127. }
  128. internal void Update(WindturbineInfo ap)
  129. {
  130. _WindturbineInfo = ap;
  131. TopValue = $"{ap.WindSpeed.ToString("F2")} m/s";
  132. MiddleValue = $"{ap.Power.ToString("F2")} kW";
  133. var rs = ap.ModelId.ToLower().Contains("up105") ? ap.RollSpeed * 9.55 : ap.RollSpeed;
  134. BottomValue = $"{rs.ToString("F2")} rpm";
  135. State = (int)ap.Status;
  136. _Timestamp = ap.Ts;
  137. string time = _Timestamp.GetTimeString();
  138. string timespan = _Timestamp.GetTimeSpanString();
  139. ToolTipValue = $"开始时间:{time} 时长:{timespan}分钟";
  140. if (this.CustomLockInfo != null)
  141. {
  142. ToolTipValue += $"\n挂牌:{CustomLockInfo.Value} 挂牌时间:{CustomLockInfo.FollowTime.ToString("yyyy-MM-dd HH:mm:ss")}";
  143. }
  144. else if (_WindturbineInfo.IsLocked)
  145. {
  146. ToolTipValue += $"\n挂牌:{((HungType)_WindturbineInfo.LockValue).GetStringValue()}";
  147. }
  148. var v = (g.ToolTip as ToolTip)?.Content as WindturbineDetailsView;
  149. if (v == null) return;
  150. v.ToolTipValue = ToolTipValue;
  151. }
  152. private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  153. {
  154. var b = Keyboard.Modifiers == ModifierKeys.Shift;
  155. if (SelectedChanged == null)
  156. {
  157. IsSelected = !IsSelected;
  158. }
  159. else
  160. {
  161. SelectedChanged(this, b);
  162. }
  163. if (e.ClickCount <= 1 || _WindturbineInfo == null) return;
  164. Windows.WindturbineInfoWindow.ShowWindow(this.WindturbineInfo);
  165. //WinForms.WindtrubineInfoWindow.ShowWindow(_WindturbineInfo);
  166. //ShowForm.Show(_WindturbineInfo.StationId, _WindturbineInfo.ModelId, _WindturbineInfo.WindturbineId, Title);
  167. }
  168. }
  169. }