123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- using System;
- using System.CodeDom;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Windows;
- using System.Windows.Media;
- using Aitex.Core.Account;
- using Aitex.Core.Common.DeviceData;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.UI.MVVM;
- using System.Windows.Input;
- using Aitex.Core.Util;
- using Aitex.Triton160.Common;
- using Aitex.Triton160.UI;
- using Aitex.Triton160.UI.Config;
- using Aitex.Triton160.UI.ViewModel;
- using Aitex.Triton160.UI.Views;
- namespace Triton160.UI.ViewModel
- {
- class TopViewModel : UIViewModelBase
- {
- public string SoftwareVersion
- {
- get;
- set;
- }
- [Subscription(TritonDevice.EmoSystem, SystemDeviceModule)]
- public AITEmoData EmoState
- {
- get;
- set;
- }
- [Subscription(StateData.PMState, SystemStateModule)]
- public int PMState
- {
- get;
- set;
- }
- [Subscription(TritonDevice.SignalTower, SystemDeviceModule)]
- public AITSignalTowerData SignalTower
- {
- get;
- set;
- }
- public string SystemStatus
- {
- get
- {
- PMState status = (PMState)PMState;
- return status.ToString();
- }
- }
- private bool _simulatorMode = false;
- public string TopViewBackground
- {
- get
- {
- return _simulatorMode ? "Goldenrod" : "Transparent";
- }
- }
- public SolidColorBrush MainContactorColor
- {
- get
- {
- return EmoState != null && EmoState.MainContactorSignal ? Brushes.Lime : Brushes.Gray;
- }
- }
- public SolidColorBrush EmoStopColor
- {
- get
- {
- return EmoState != null && EmoState.StopButtonSignal ? Brushes.Lime : Brushes.Gray;
- }
- }
- public string User
- {
- get
- {
- return Globals.Session["CurrentUser"] == null ? "" : (Globals.Session["CurrentUser"] as Account).AccountId;
- }
- }
- public string Role
- {
- get
- {
- return Globals.Session["CurrentUser"] == null ? "" : (Globals.Session["CurrentUser"] as Account).Role;
- }
- }
- public int _language;
- //public string LanguageButtonDisplay
- //{
- // get
- // {
- // //显示的文字,和实际的语言相反,用于切换
- // return _language == 1 ? "中文" : "EN";
- // }
- //}
- public bool EnableEnButton
- {
- get
- {
- return _language != 1;
- }
- }
- public bool EnableCnButton
- {
- get
- {
- return _language != 2;
- }
- }
- public string LogoSource
- {
- get
- {
- string file = SystemConfigManager.Instance.GetTopviewLogoFile();
- if (string.IsNullOrEmpty(file))
- file = "LogoEmpty.png";
- return "/Core;component/Resources/Main/" + file;
- }
- }
- public ICommand SwitchOffBuzzerCommand
- {
- get;
- private set;
- }
- public ICommand SwitchLanguageCommand
- {
- get;
- private set;
- }
- public FACommunicationState FACommunicationState
- {
- get
- {
- return string.IsNullOrEmpty(HostCommunicationStatus) ? FACommunicationState.Disabled
- : (FACommunicationState)Enum.Parse(typeof(FACommunicationState), HostCommunicationStatus);
- }
- }
- public FAControlState FAControlState
- {
- get
- {
- return string.IsNullOrEmpty(HostControlStatus) ? FAControlState.Unknown
- : (FAControlState)Enum.Parse(typeof(FAControlState), HostControlStatus);
- }
- }
- //Disabled,
- //Enabled,
- //EnabledNotCommunicating,
- //EnabledCommunicating,
- //WaitCRA,
- //WaitDelay,
- //WaitCRFromHost,
- public bool IsEnableEnableButton
- {
- get { return FACommunicationState == FACommunicationState.Disabled; }
- }
- [Subscription("System.ControlStatus")]
- public string HostControlStatus
- {
- get;
- set;
- }
- [Subscription("System.CommunicationStatus")]
- public string HostCommunicationStatus
- {
- get;
- set;
- }
- public string HostControlStatusBackground
- {
- get
- {
- if (FACommunicationState == FACommunicationState.Disabled)
- return "Transparent";
- if (FACommunicationState != FACommunicationState.EnabledCommunicating)
- return "Transparent";
- switch (FAControlState)
- {
- case FAControlState.OnlineLocal:
- case FAControlState.OnlineRemote:
- return "Green";
- case FAControlState.HostOffline:
- //case FAControlState.AttemptOnline:
- case FAControlState.EquipmentOffline:
- case FAControlState.Unknown:
- return "Transparent";
- }
- return "Orange";
- }
- }
- public string HostStatusBackground
- {
- get
- {
- switch (FACommunicationState)
- {
- case FACommunicationState.EnabledCommunicating:
- return "Green";
- case FACommunicationState.Disabled:
- return "Transparent";
- }
- return "Orange";
- }
- }
-
- private bool _isFaEnable;
- public Visibility VisibleHostStatus
- {
- get { return _isFaEnable ? Visibility.Visible : Visibility.Hidden; }
- }
- public string SystemStatusBackground
- {
- get { return GetUnitStatusBackground(SystemStatus); }
- }
- public string GetUnitStatusBackground(string status)
- {
- if (status != null)
- status = status.Trim().ToLower();
- switch (status)
- {
- case "error":
- return "red";
- case "idle":
- return "Transparent";
- case "init":
- return "Orange";
- default:
- return "Green";
- }
- }
- public TopViewModel()
- : base("TopViewModel")
- {
- SwitchOffBuzzerCommand = new DelegateCommand<object>(OnSwitchOffBuzzer);
- SwitchLanguageCommand = new DelegateCommand<object>(OnSwitchOffLanguage);
- SoftwareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
- InvokePropertyChanged("SoftwareVersion");
- }
- public void Reset()
- {
- Triton160UiSystem.Instance.WCF.Invoker.DoOperation(TritonOperation.Reset.ToString());
- }
- void OnSwitchOffBuzzer(object param)
- {
- Triton160UiSystem.Instance.WCF.Invoker.DoOperation(TritonOperation.DeviceOperation.ToString(), new object[] { TritonDevice.SignalTower.ToString(), AITSignalTowerOperation.SwitchOffBuzzer.ToString() });
- Triton160UiSystem.Instance.WCF.Invoker.DoOperation(TritonOperation.BuzzerOFF.ToString());
- }
- void OnSwitchOffLanguage(object param)
- {
- int language = param.ToString().ToLower() == "en" ? 1 : 2;
- Triton160UiSystem.Instance.WCF.Invoker.DoOperation(TritonOperation.SetConfig.ToString(), SCName.System_Language, language);
- }
- protected override void InvokeBeforeUpdateProperty(Dictionary<string, object> data)
- {
- Application.Current.Dispatcher.Invoke(new Action(() =>
- {
- int language = (int)Triton160UiSystem.Instance.WCF.Query.GetConfig(SCName.System_Language);
- if (language != _language)
- {
- _language = language;
- Triton160UiSystem.Instance.SetCulture(_language == 2 ? "zh-CN" : "en-US");
- }
- _simulatorMode = (bool) Triton160UiSystem.Instance.WCF.Query.GetConfig(SCName.System_IsSimulatorMode);
- _isFaEnable = (bool)Triton160UiSystem.Instance.WCF.Query.GetConfig(SCName.System_EnableFa);
- }));
- }
- }
- }
|