123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using Aitex.Core.UI.View.Frame;
- using Hardcodet.Wpf.TaskbarNotification;
- using Triton160.UI.ViewModel;
- using Aitex.Core.UI.Control;
- using Aitex.Core.UI.MVVM;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Log;
- using Aitex.Core.UI.Dialog;
- using Aitex.Triton160.Common;
- namespace Aitex.Triton160.UI.Views
- {
- /// <summary>
- /// Interaction logic for TopView.xaml
- /// </summary>
- public partial class TopView : UserControl, ITopView
- {
- MessageControl _balloonControl;
- TopViewModel _vm;
- public TopView()
- {
- InitializeComponent();
- _vm = new TopViewModel();
- this.DataContext = _vm;
- //_vm.TraverseUIElement(gridAll);
- _balloonControl = new MessageControl();
- this.Loaded += new RoutedEventHandler(TopView_Loaded);
- signalTower.BuzzingWarningConfigCallback = () =>
- {
- //PmWarningSoundConfigWindow dialog = new PmWarningSoundConfigWindow();
- //dialog.ShowDialog();
- };
- }
- void TopView_Loaded(object sender, RoutedEventArgs e)
- {
- (this.DataContext as TimerViewModelBase).Start();
- Triton160UiSystem.Instance.EV.OnEvent += EV_OnEvent;
- }
- void EV_OnEvent(EventItem obj)
- {
- switch (obj.Type)
- {
- case EventType.EventUI_Notify:
- LogEvent(obj);
- break;
- case EventType.Dialog_Nofity:
- PopDialog(obj);
- break;
- case EventType.KickOut_Notify:
- break;
- case EventType.Sound_Notify:
- break;
- case EventType.UIMessage_Notify:
- PopUIMessage(obj);
- break;
- }
- }
- void PopUIMessage(EventItem obj)
- {
- this.Dispatcher.Invoke(new Action(() =>
- {
- _balloonControl.SetMessage(MessageType.Info, obj.Description);
- ShowNotifyIcon(2000);
- }));
- }
- void ShowNotifyIcon(int time)
- {
- TaskbarIcon icon = new TaskbarIcon();
- icon.ShowCustomBalloon(_balloonControl, System.Windows.Controls.Primitives.PopupAnimation.Slide, time);
- }
- void PopDialog(EventItem item)
- {
- this.Dispatcher.Invoke(new Action(() =>
- {
- switch (item.Level)
- {
- case EventLevel.Alarm:
- MessageBoxEx.ShowError(item.Description, item.Explaination);
- break;
- case EventLevel.Warning:
- MessageBoxEx.ShowWarning(item.Description, item.Explaination);
- break;
- case EventLevel.Information:
- MessageBoxEx.ShowInfo(item.Description, item.Explaination);
- break;
- case EventLevel.InformationNoDelay:
- MessageBoxEx.ShowInfoNoDelay(item.Description, item.Explaination);
- break;
- }
- }));
- }
- void LogEvent(EventItem obj)
- {
- if (obj.Type != EventType.EventUI_Notify)
- return;
- this.comboEvent.Dispatcher.Invoke(new Action(() =>
- {
- string globalDescription = Triton160UiSystem.Instance.Culture == "en-US" ? obj.GlobalDescription_en :
- obj.GlobalDescription_zh;
- if (string.IsNullOrEmpty(globalDescription))
- globalDescription = obj.Description;
- string messageStr = string.Format("{0} [{1}]{2}",
- obj.OccuringTime.ToString("HH:mm:ss.fff"),
- obj.Id.ToString("0000"),
- globalDescription);
- ComboBoxItem cbI = new ComboBoxItem() { Content = messageStr, ToolTip = messageStr };
- Brush brush = Brushes.White;
- switch (obj.Level)
- {
- case EventLevel.Alarm:
- brush = System.Windows.Media.Brushes.Pink; //light red
- break;
- case EventLevel.Information:
- brush = System.Windows.Media.Brushes.LightBlue;//light blue
- break;
- case EventLevel.Warning:
- brush = System.Windows.Media.Brushes.Khaki; //light yellow
- break;
- default:
- brush = System.Windows.Media.Brushes.Red;
- break;
- }
- cbI.Background = brush;
- comboEvent.Items.Add(cbI);
- int maxDisplayMsgNum = 100;
- if (comboEvent.Items.Count == maxDisplayMsgNum)
- comboEvent.Items.RemoveAt(0);
- comboEvent.SelectedIndex = comboEvent.Items.Count - 1;
- comboEvent.Background = brush;
- }), null);
- }
- public void SetTitle(string title)
- {
- txtTitle.Text = title;
- }
- private void comboEvent_DropDownClosed(object sender, EventArgs e)
- {
- comboEvent.SelectedIndex = comboEvent.Items.Count - 1;
- }
- private void btnReset_Click(object sender, RoutedEventArgs e)
- {
- comboEvent.Background = System.Windows.Media.Brushes.LightBlue;
- comboEvent.Items.Clear();
- _vm.Reset();
- }
- private void btnLogoff_Click(object sender, RoutedEventArgs e)
- {
- Triton160UiSystem.Instance.Logoff();
-
- }
- }
- }
|