TopView.xaml.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using Aitex.Core.UI.View.Frame;
  15. using Hardcodet.Wpf.TaskbarNotification;
  16. using Triton160.UI.ViewModel;
  17. using Aitex.Core.UI.Control;
  18. using Aitex.Core.UI.MVVM;
  19. using Aitex.Core.RT.Event;
  20. using Aitex.Core.RT.Log;
  21. using Aitex.Core.UI.Dialog;
  22. using Aitex.Triton160.Common;
  23. namespace Aitex.Triton160.UI.Views
  24. {
  25. /// <summary>
  26. /// Interaction logic for TopView.xaml
  27. /// </summary>
  28. public partial class TopView : UserControl, ITopView
  29. {
  30. MessageControl _balloonControl;
  31. TopViewModel _vm;
  32. public TopView()
  33. {
  34. InitializeComponent();
  35. _vm = new TopViewModel();
  36. this.DataContext = _vm;
  37. //_vm.TraverseUIElement(gridAll);
  38. _balloonControl = new MessageControl();
  39. this.Loaded += new RoutedEventHandler(TopView_Loaded);
  40. signalTower.BuzzingWarningConfigCallback = () =>
  41. {
  42. //PmWarningSoundConfigWindow dialog = new PmWarningSoundConfigWindow();
  43. //dialog.ShowDialog();
  44. };
  45. }
  46. void TopView_Loaded(object sender, RoutedEventArgs e)
  47. {
  48. (this.DataContext as TimerViewModelBase).Start();
  49. Triton160UiSystem.Instance.EV.OnEvent += EV_OnEvent;
  50. }
  51. void EV_OnEvent(EventItem obj)
  52. {
  53. switch (obj.Type)
  54. {
  55. case EventType.EventUI_Notify:
  56. LogEvent(obj);
  57. break;
  58. case EventType.Dialog_Nofity:
  59. PopDialog(obj);
  60. break;
  61. case EventType.KickOut_Notify:
  62. break;
  63. case EventType.Sound_Notify:
  64. break;
  65. case EventType.UIMessage_Notify:
  66. PopUIMessage(obj);
  67. break;
  68. }
  69. }
  70. void PopUIMessage(EventItem obj)
  71. {
  72. this.Dispatcher.Invoke(new Action(() =>
  73. {
  74. _balloonControl.SetMessage(MessageType.Info, obj.Description);
  75. ShowNotifyIcon(2000);
  76. }));
  77. }
  78. void ShowNotifyIcon(int time)
  79. {
  80. TaskbarIcon icon = new TaskbarIcon();
  81. icon.ShowCustomBalloon(_balloonControl, System.Windows.Controls.Primitives.PopupAnimation.Slide, time);
  82. }
  83. void PopDialog(EventItem item)
  84. {
  85. this.Dispatcher.Invoke(new Action(() =>
  86. {
  87. switch (item.Level)
  88. {
  89. case EventLevel.Alarm:
  90. MessageBoxEx.ShowError(item.Description, item.Explaination);
  91. break;
  92. case EventLevel.Warning:
  93. MessageBoxEx.ShowWarning(item.Description, item.Explaination);
  94. break;
  95. case EventLevel.Information:
  96. MessageBoxEx.ShowInfo(item.Description, item.Explaination);
  97. break;
  98. case EventLevel.InformationNoDelay:
  99. MessageBoxEx.ShowInfoNoDelay(item.Description, item.Explaination);
  100. break;
  101. }
  102. }));
  103. }
  104. void LogEvent(EventItem obj)
  105. {
  106. if (obj.Type != EventType.EventUI_Notify)
  107. return;
  108. this.comboEvent.Dispatcher.Invoke(new Action(() =>
  109. {
  110. string globalDescription = Triton160UiSystem.Instance.Culture == "en-US" ? obj.GlobalDescription_en :
  111. obj.GlobalDescription_zh;
  112. if (string.IsNullOrEmpty(globalDescription))
  113. globalDescription = obj.Description;
  114. string messageStr = string.Format("{0} [{1}]{2}",
  115. obj.OccuringTime.ToString("HH:mm:ss.fff"),
  116. obj.Id.ToString("0000"),
  117. globalDescription);
  118. ComboBoxItem cbI = new ComboBoxItem() { Content = messageStr, ToolTip = messageStr };
  119. Brush brush = Brushes.White;
  120. switch (obj.Level)
  121. {
  122. case EventLevel.Alarm:
  123. brush = System.Windows.Media.Brushes.Pink; //light red
  124. break;
  125. case EventLevel.Information:
  126. brush = System.Windows.Media.Brushes.LightBlue;//light blue
  127. break;
  128. case EventLevel.Warning:
  129. brush = System.Windows.Media.Brushes.Khaki; //light yellow
  130. break;
  131. default:
  132. brush = System.Windows.Media.Brushes.Red;
  133. break;
  134. }
  135. cbI.Background = brush;
  136. comboEvent.Items.Add(cbI);
  137. int maxDisplayMsgNum = 100;
  138. if (comboEvent.Items.Count == maxDisplayMsgNum)
  139. comboEvent.Items.RemoveAt(0);
  140. comboEvent.SelectedIndex = comboEvent.Items.Count - 1;
  141. comboEvent.Background = brush;
  142. }), null);
  143. }
  144. public void SetTitle(string title)
  145. {
  146. txtTitle.Text = title;
  147. }
  148. private void comboEvent_DropDownClosed(object sender, EventArgs e)
  149. {
  150. comboEvent.SelectedIndex = comboEvent.Items.Count - 1;
  151. }
  152. private void btnReset_Click(object sender, RoutedEventArgs e)
  153. {
  154. comboEvent.Background = System.Windows.Media.Brushes.LightBlue;
  155. comboEvent.Items.Clear();
  156. _vm.Reset();
  157. }
  158. private void btnLogoff_Click(object sender, RoutedEventArgs e)
  159. {
  160. Triton160UiSystem.Instance.Logoff();
  161. }
  162. }
  163. }