RealTimeAlarmWindow.xaml.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. using NEIntelligentControl2.Models.Alarm;
  2. using NEIntelligentControl2.Models.Messages;
  3. using NEIntelligentControl2.Models.Station;
  4. using NEIntelligentControl2.Service.Station;
  5. using NEIntelligentControl2.Service.Windturbine;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Configuration;
  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.Data;
  15. using System.Windows.Documents;
  16. using System.Windows.Input;
  17. using System.Windows.Media;
  18. using System.Windows.Media.Imaging;
  19. using System.Windows.Shapes;
  20. namespace NEIntelligentControl2.Windows.Alarm
  21. {
  22. /// <summary>
  23. /// 实时报警窗口
  24. /// </summary>
  25. public partial class RealTimeAlarmWindow : Window
  26. {
  27. private StationManager _StationManager;
  28. private WEBHelper _WEBHelper;
  29. private InfoManager _InfoManager;
  30. private string _Url;
  31. private StationInfo _CurrentStationInfo;// 场站
  32. private AlarmTypeItem _ClassTypeInfo;// 级别
  33. private AlarmTypeItem _TypeInfo;// 类型
  34. private AlarmTypeItem _STypeInfo;// 子类型
  35. private List<AlarmInfo> _AlarmInfos;
  36. private AlarmTypeInfo _AlarmTypeInfo;
  37. private string _WindturbineId;
  38. public string KeyString { get; set; }
  39. private bool _IsWindturbineFilter;
  40. private bool _IsLoaded;
  41. public RealTimeAlarmWindow(StationManager sm, WEBHelper web, InfoManager im)
  42. {
  43. InitializeComponent();
  44. _StationManager = sm;
  45. _WEBHelper = web;
  46. _InfoManager = im;
  47. Init();
  48. }
  49. private void Init()
  50. {
  51. try
  52. {
  53. #if (DEBUG)
  54. _Url = ConfigurationManager.AppSettings["AlarmPathDebug"];
  55. #else
  56. _Url = ConfigurationManager.AppSettings["AlarmPath"];
  57. #endif
  58. }
  59. catch (Exception ex)
  60. {
  61. Console.WriteLine("读取配置文件[ServicePath]出错!", ex);
  62. }
  63. var ls = _StationManager.GetStationInfos().Where(i=>i.Type!=Models.Station.StationType.Other).ToList();
  64. if (ls == null) return;
  65. _CBStation.ItemsSource = ls;
  66. _AlarmTypeInfo = _InfoManager.GetAlarmTypeInfo();
  67. _CBClass.ItemsSource = _AlarmTypeInfo.RankInfo;
  68. _CBType.ItemsSource = _AlarmTypeInfo.DeviceType;
  69. }
  70. private void ContentControl_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  71. {
  72. switch (((FrameworkElement)sender).Tag)
  73. {
  74. case "close":
  75. this.Close();
  76. break;
  77. case "maximized":
  78. Maximized();
  79. break;
  80. default: return;
  81. }
  82. }
  83. private void Maximized()
  84. {
  85. if (this.WindowState == WindowState.Maximized)
  86. {
  87. this.WindowState = WindowState.Normal;
  88. }
  89. else
  90. {
  91. this.WindowState = WindowState.Maximized;
  92. }
  93. }
  94. public static void ShowWindow()
  95. {
  96. RealTimeAlarmWindow rtw = App.ServiceProvider.GetService(typeof(RealTimeAlarmWindow)) as RealTimeAlarmWindow;
  97. rtw.Owner = Application.Current.MainWindow;
  98. rtw.ShowDialog();
  99. }
  100. /// <summary>
  101. /// 场站
  102. /// </summary>
  103. private void _CBStation_SelectionChanged(object sender, SelectionChangedEventArgs e)
  104. {
  105. if (e.AddedItems.Count <= 0) return;
  106. var v = e.AddedItems[0] as StationInfo;
  107. if (v == null) return;
  108. if (_CurrentStationInfo != null && _CurrentStationInfo.Id == v.Id) return;
  109. _CurrentStationInfo = v;
  110. Task.Run(Search);
  111. }
  112. /// <summary>
  113. /// 级别
  114. /// </summary>
  115. private void _CBClass_SelectionChanged(object sender, SelectionChangedEventArgs e)
  116. {
  117. if (e.AddedItems.Count <= 0) return;
  118. var v = e.AddedItems[0] as AlarmTypeItem;
  119. if (v == null) return;
  120. _ClassTypeInfo = v;
  121. _IsWindturbineFilter = false;
  122. Task.Run(Search);
  123. }
  124. /// <summary>
  125. /// 类型
  126. /// </summary>
  127. private void _CBType_SelectionChanged(object sender, SelectionChangedEventArgs e)
  128. {
  129. if (e.AddedItems.Count <= 0) return;
  130. var v = e.AddedItems[0] as AlarmTypeItem;
  131. if (v == null) return;
  132. _TypeInfo = v;
  133. _CBSType.ItemsSource = v.SubItem;
  134. _CBSType.SelectedIndex = 0;
  135. _IsWindturbineFilter = false;
  136. Task.Run(Search);
  137. }
  138. /// <summary>
  139. /// 子类型
  140. /// </summary>
  141. private void _CBSType_SelectionChanged(object sender, SelectionChangedEventArgs e)
  142. {
  143. if (e.AddedItems.Count <= 0) return;
  144. var v = e.AddedItems[0] as AlarmTypeItem;
  145. if (v == null) return;
  146. _STypeInfo = v;
  147. _IsWindturbineFilter = false;
  148. Task.Run(Search);
  149. }
  150. /// <summary>
  151. /// 风机
  152. /// </summary>
  153. private void _CBWindturbine_SelectionChanged(object sender, SelectionChangedEventArgs e)
  154. {
  155. if (e.AddedItems.Count <= 0) return;
  156. var v = e.AddedItems[0] as string;
  157. if (v == null) return;
  158. _WindturbineId = v;
  159. _IsWindturbineFilter = true;
  160. Task.Run(Search);
  161. }
  162. private void Search()
  163. {
  164. if (!_IsLoaded) return;
  165. try
  166. {
  167. _IBMain.Inof("查询数据...");
  168. var vs = _WEBHelper.HttpGetJSON<List<AlarmInfo>>($"{_Url}/alarm/snap?stationid={_CurrentStationInfo.Id}&isopened=1&windturbineid={(string.IsNullOrWhiteSpace(_WindturbineId) ? "" : _WindturbineId)}" +
  169. $"&category1={GetInfoString(_TypeInfo)}&category2={GetInfoString(_STypeInfo)}&rank={GetInfoString(_ClassTypeInfo)}&keyword={(string.IsNullOrWhiteSpace(KeyString) ? "" : KeyString)}");
  170. _AlarmInfos = vs;
  171. Dispatcher.Invoke(() => ShowData());
  172. }
  173. catch(Exception e)
  174. {
  175. _IBMain.Warning($"查询数据出现错误:{e.Message}");
  176. return;
  177. }
  178. _IBMain.Success();
  179. }
  180. private void ShowData()
  181. {
  182. if (_AlarmInfos == null || _AlarmInfos.Count <= 0)
  183. {
  184. _AlarmInfos = new List<AlarmInfo>();
  185. }
  186. var ids = new HashSet<string>() { "全部" };
  187. foreach (var v in _AlarmInfos)
  188. {
  189. if (!string.IsNullOrWhiteSpace(v.WindturbineId))
  190. {
  191. ids.Add(v.WindturbineId);
  192. }
  193. }
  194. if (!_IsWindturbineFilter)
  195. {
  196. _CBWindturbine.ItemsSource = ids;
  197. }
  198. _DGMain.ItemsSource = _AlarmInfos;
  199. }
  200. private object GetInfoString(AlarmTypeItem ati)
  201. {
  202. if (ati == null) return "";
  203. return ati.Id == "all" ? "" : ati.Id;
  204. }
  205. private void _CBKeyString_LostFocus(object sender, RoutedEventArgs e)
  206. {
  207. KeyString = _CBKeyString.Text;
  208. //Filter();
  209. }
  210. private void Window_Loaded(object sender, RoutedEventArgs e)
  211. {
  212. _IsLoaded = true;
  213. Task.Run(Search);
  214. }
  215. private void Button_Click(object sender, RoutedEventArgs e)
  216. {
  217. switch (((Control)sender).Tag)
  218. {
  219. case "search":
  220. Task.Run(Search);
  221. break;
  222. default:return;
  223. }
  224. }
  225. }
  226. }