TopView.xaml.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 Sorter.UI.ViewModel;
  17. using Aitex.Core.UI.Control;
  18. using Aitex.Core.UI.MVVM;
  19. using Aitex.Core.RT.Event;
  20. using Aitex.Core.UI.Dialog;
  21. using Aitex.Core.WCF;
  22. using Aitex.Sorter.Common;
  23. using MECF.Framework.UI.Core.Applications;
  24. using Aitex.Core.UI.View.Common;
  25. namespace Aitex.Sorter.UI.Views
  26. {
  27. /// <summary>
  28. /// Interaction logic for TopView.xaml
  29. /// </summary>
  30. public partial class TopView : UserControl, ITopView
  31. {
  32. MessageControl _balloonControl;
  33. TopViewModel _vm;
  34. private bool _logoff;
  35. public TopView()
  36. {
  37. InitializeComponent();
  38. _vm = new TopViewModel();
  39. this.DataContext = _vm;
  40. //_vm.TraverseUIElement(gridAll);
  41. _balloonControl = new MessageControl();
  42. this.Loaded += new RoutedEventHandler(TopView_Loaded);
  43. }
  44. void TopView_Loaded(object sender, RoutedEventArgs e)
  45. {
  46. (this.DataContext as TimerViewModelBase).Start();
  47. EventClient.Instance.Service.OnEvent += EV_OnEvent;
  48. }
  49. void EV_OnEvent(EventItem obj)
  50. {
  51. if (_logoff)
  52. return;
  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. }
  99. }));
  100. }
  101. void LogEvent(EventItem obj)
  102. {
  103. if (obj.Type != EventType.EventUI_Notify)
  104. return;
  105. this.comboEvent.Dispatcher.Invoke(new Action(() =>
  106. {
  107. string globalDescription = obj.GlobalDescription_en;
  108. if (string.IsNullOrEmpty(globalDescription))
  109. globalDescription = obj.Description;
  110. string messageStr = string.Format("{0} [{1}]{2}",
  111. obj.OccuringTime.ToString("HH:mm:ss.fff"),
  112. obj.Id.ToString("0000"),
  113. globalDescription);
  114. ComboBoxItem cbI = new ComboBoxItem() { Content = messageStr, ToolTip = messageStr };
  115. Brush brush = Brushes.White;
  116. switch (obj.Level)
  117. {
  118. case EventLevel.Alarm:
  119. brush = System.Windows.Media.Brushes.Pink; //light red
  120. break;
  121. case EventLevel.Information:
  122. brush = System.Windows.Media.Brushes.LightBlue;//light blue
  123. break;
  124. case EventLevel.Warning:
  125. brush = System.Windows.Media.Brushes.Khaki; //light yellow
  126. break;
  127. default:
  128. brush = System.Windows.Media.Brushes.Red;
  129. break;
  130. }
  131. cbI.Background = brush;
  132. comboEvent.Items.Add(cbI);
  133. int maxDisplayMsgNum = 100;
  134. if (comboEvent.Items.Count == maxDisplayMsgNum)
  135. comboEvent.Items.RemoveAt(0);
  136. comboEvent.SelectedIndex = comboEvent.Items.Count - 1;
  137. comboEvent.Background = brush;
  138. }), null);
  139. }
  140. public void SetTitle(string title)
  141. {
  142. txtTitle.Text = title;
  143. }
  144. private void comboEvent_DropDownClosed(object sender, EventArgs e)
  145. {
  146. comboEvent.SelectedIndex = comboEvent.Items.Count - 1;
  147. }
  148. private void btnReset_Click(object sender, RoutedEventArgs e)
  149. {
  150. comboEvent.Background = System.Windows.Media.Brushes.LightBlue;
  151. comboEvent.Items.Clear();
  152. _vm.Reset();
  153. }
  154. private void btnLogoff_Click(object sender, RoutedEventArgs e)
  155. {
  156. _logoff = true;
  157. UiApplication.Instance.Logoff();
  158. }
  159. }
  160. }