123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538 |
- using Aitex.Core.Common.DeviceData;
- using Aitex.Core.RT.Event;
- using Aitex.Core.UI.Control;
- using Aitex.Core.UI.Dialog;
- using Aitex.Core.UI.MVVM;
- using Aitex.Core.Util;
- using Aitex.Core.WCF;
- using Aitex.Sorter.Common;
- using Aitex.Sorter.UI.ViewModel;
- using Hardcodet.Wpf.TaskbarNotification;
- using MECF.Framework.Common.OperationCenter;
- using MECF.Framework.UI.Core.Accounts;
- using MECF.Framework.UI.Core.Applications;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Windows;
- using System.Windows.Input;
- namespace Sorter.UI.ViewModel
- {
- public class TopViewModel2 : UIViewModelBase
- {
- public string SoftwareVersion
- {
- get;
- set;
- }
- [Subscription(ParamName.RTStatus, SystemStateModule)]
- public int RoutManagerState
- {
- get;
- set;
- }
- public string SystemStatus
- {
- get { return ((RtState)RoutManagerState).ToString(); }
- }
- public string SystemStatusBackground
- {
- get
- {
- switch (RoutManagerState)
- {
- case (int)RtState.Init:
- return "Yellow";
- case (int)RtState.Initializing:
- case (int)RtState.ManualTransfer:
- case (int)RtState.Transfer:
- case (int)RtState.Cycle:
- case (int)RtState.PrepareCycle:
- case (int)RtState.PostCycle:
- case (int)RtState.Reset:
- case (int)RtState.Processing:
- case (int)RtState.PostProcess:
- case (int)RtState.PauseProcess:
- case (int)RtState.SetSpeed:
- return "LawnGreen";
- case (int)RtState.Error:
- case (int)RtState.Maintenance:
- return "Red";
- case (int)RtState.Idle:
- return "Transparent";
- default:
- return "Goldenrod";
- }
- }
- }
- [Subscription("Status", "LP1")]
- public string LoadPort1Status
- {
- get;
- set;
- }
- public string LoadPort1StatusBackground
- {
- get { return GetUnitStatusBackground(LoadPort1Status); }
- }
- [Subscription("Status", "LP2")]
- public string LoadPort2Status
- {
- get;
- set;
- }
- public string LoadPort2StatusBackground
- {
- get { return GetUnitStatusBackground(LoadPort2Status); }
- }
- [Subscription("LoadportState", "LP3")]
- public string LoadPort3Status
- {
- get;
- set;
- }
- public string LoadPort3StatusBackground
- {
- get { return GetUnitStatusBackground(LoadPort3Status); }
- }
- [Subscription("LoadportState", "LP4")]
- public string LoadPort4Status
- {
- get;
- set;
- }
- public string LoadPort4StatusBackground
- {
- get { return GetUnitStatusBackground(LoadPort4Status); }
- }
- [Subscription("Robot.State")]
- public string RobotStatus
- {
- get;
- set;
- }
- public string RobotStatusBackground
- {
- get { return GetUnitStatusBackground(RobotStatus); }
- }
- [Subscription("System.SignalTower.DeviceData")]
- public AITSignalTowerData SignalTower
- {
- get;
- set;
- }
- [Subscription("System.IsOnlineMode")]
- public bool IsOnlineMode { get; set; }
- public string OnlineStatus
- {
- get { return IsOnlineMode ? "Online" : "Offline"; }
- }
- private bool _simulatorMode = false;
- [Subscription("System.ServerStatus")]
- public string ServerStatus
- {
- get; set;
- }
- public R_TRIG _trig = new R_TRIG();
- public bool _clearEventLogEnable;
- [Subscription("System.ClearEventLogEnable")]
- public bool ClearEventLogEnable
- {
- get;
- set;
- //get
- // {
- // return _clearEventLogEnable;
- //}
- //set
- //{
- // _clearEventLogEnable = value;
- // if (value)
- // {
- // _trig.CLK = value;
- // if (_trig.Q)
- // EventLogList.Clear();
- // }
- // else
- // {
- // _trig.RST = true;
- // }
- //}
- }
- [Subscription("CoolingBuffer1.CoolingBuffer1.Status")]
- public string CoolingBuffer1Status
- {
- get; set;
- }
- public string _CoolingBuffer1Status => CoolingBuffer1Status == "Disable" ? "" : CoolingBuffer1Status;
- public string CoolingBuffer1Background
- {
- get { return GetUnitStatusBackground(CoolingBuffer1Status); }
- }
- [Subscription("CoolingBuffer2.CoolingBuffer2.Status")]
- public string CoolingBuffer2Status
- {
- get; set;
- }
- public string _CoolingBuffer2Status => CoolingBuffer2Status == "Disable" ? "" : CoolingBuffer2Status;
- public string CoolingBuffer2Background
- {
- get { return GetUnitStatusBackground(CoolingBuffer2Status); }
- }
- [Subscription("Aligner1.Aligner1.Status")]
- public string Aligner1Status
- {
- get; set;
- }
- public string _Aligner1Status => Aligner1Status == "Disable" ? "" : Aligner1Status;
- public string Aligner1Background
- {
- get { return GetUnitStatusBackground(Aligner1Status); }
- }
- [Subscription("Aligner2.Aligner2.Status")]
- public string Aligner2Status
- {
- get; set;
- }
- public string _Aligner2Status => Aligner2Status == "Disable" ? "" : Aligner2Status;
- public string Aligner2Background
- {
- get { return GetUnitStatusBackground(Aligner2Status); }
- }
- [Subscription("Status", "Flipper")]
- public string FlipperStatus
- {
- get;
- set;
- }
- public string FlipperBackground
- {
- get { return GetUnitStatusBackground(FlipperStatus); }
- }
- public string ServerStatusBackground
- {
- get { return GetServerStatusBackground(ServerStatus); }
- }
- public string GetServerStatusBackground(string status)
- {
- return "Transparent";
- // if (status != null)
- // status = status.Trim().ToLower();
- //switch (status)
- //{
- // case "unknown":
- // return "Yellow";
- // case "idle":
- // return "Transparent";
- // case "busy":
- // return "LawnGreen";
- // default:
- // return "Yellow";
- //}
- }
- public string GetUnitStatusBackground(string status)
- {
- if (status != null)
- status = status.Trim().ToLower();
- switch (status)
- {
- case "unknown":
- return "Yellow";
- case "idle":
- return "Transparent";
- case "busy":
- return "LawnGreen";
- //case "disable":
- // return "DarkOrange";
- default:
- return "Yellow";
- }
- }
- public string TopBackground
- {
- get
- {
- return ServerStatus == "Connected" ? "ForestGreen" : "Yellow";
- }
- }
- public string OnlineStatusBackground
- {
- get
- {
- return IsOnlineMode ? "Transparent" : "Yellow";
- }
- }
- public string TopViewBackground
- {
- get
- {
- return _simulatorMode ? "Goldenrod" : "Transparent";
- }
- }
- public string User
- {
- get
- {
- return AccountClient.Instance.CurrentUser == null ? "" : AccountClient.Instance.CurrentUser.AccountId;
- }
- }
- public string Role
- {
- get
- {
- return AccountClient.Instance.CurrentUser == null ? "" : AccountClient.Instance.CurrentUser.Role;
- }
- }
- #region Moudle Enable Flag
- [Subscription("LP1.IsEnable")]
- public bool LP1Enable { get; set; }
- [Subscription("LP2.IsEnable")]
- public bool LP2Enable { get; set; }
- [Subscription("Aligner1.IsEnable")]
- public bool Aligner1Enable { get; set; }
- [Subscription("Aligner2.IsEnable")]
- public bool Aligner2Enable { get; set; }
- [Subscription("Buffer.IsEnable")]
- public bool BufferEnable { get; set; }
- [Subscription("Buffer1.IsEnable")]
- public bool Buffer1Enable { get; set; }
- [Subscription("Buffer2.IsEnable")]
- public bool Buffer2Enable { get; set; }
- [Subscription("PMA.IsEnable")]
- public bool PMAEnable { get; set; }
- [Subscription("PMB.IsEnable")]
- public bool PMBEnable { get; set; }
- [Subscription("CoolingBuffer1.IsEnable")]
- public bool CoolingBuffer1Enable { get; set; }
- [Subscription("CoolingBuffer2.IsEnable")]
- public bool CoolingBuffer2Enable { get; set; }
- [Subscription("Flipper.IsEnable")]
- public bool FlipperEnable { get; set; }
- #endregion Moudle Enable Flag
- public ICommand SwitchOffBuzzerCommand { get; set; }
- public ICommand ResetCommand { get; set; }
- public ICommand LogoffCommand { get; set; }
- public bool IsEnableOnline
- {
- get { return !IsOnlineMode; }
- }
- public bool IsEnableOffline
- {
- get { return IsOnlineMode; }
- }
- private MessageControl _balloonControl;
- private bool _logoff;
- public ObservableCollection<EventItem> EventLogList { get; set; }
- public TopViewModel2()
- : base("TopViewModel2")
- {
- SwitchOffBuzzerCommand = new DelegateCommand<object>(OnSwitchOffBuzzer);
- ResetCommand = new DelegateCommand<object>(DoReset);
- LogoffCommand = new DelegateCommand<object>(DoLogoff);
- SoftwareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
- InvokePropertyChanged("SoftwareVersion");
- EventLogList = new ObservableCollection<EventItem>();
- _balloonControl = new MessageControl();
- EventClient.Instance.OnEvent += Instance_OnEvent;
- EventClient.Instance.Start();
- }
- private void Instance_OnEvent(EventItem obj)
- {
- if (_logoff)
- return;
- 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;
- }
- }
- private void DoLogoff(object obj)
- {
- _logoff = true;
- UiApplication.Instance.Logoff();
- }
- private void DoReset(object obj)
- {
- InvokeClient.Instance.Service.DoOperation("System.Reset");
- EventLogList.Clear();
- if(LP1Enable) InvokeClient.Instance.Service.DoOperation("LP1.LPReset");
- if(LP2Enable) InvokeClient.Instance.Service.DoOperation("LP2.LPReset");
- }
- public void Reset()
- {
- InvokeClient.Instance.Service.DoOperation(OperationName.ResetAlarm);
- InvokeClient.Instance.Service.DoOperation(OperationName.ResetDevice);
- InvokeClient.Instance.Service.DoOperation(OperationName.ResetRouteManager);
- }
- private void OnSwitchOffBuzzer(object param)
- {
- InvokeClient.Instance.Service.DoOperation("System.SignalTower.SwitchOffBuzzer1");
- InvokeClient.Instance.Service.DoOperation("System.SignalTower.SwitchOffBuzzer2");
- }
- private void PopUIMessage(EventItem obj)
- {
- Application.Current.Dispatcher.Invoke(new Action(() =>
- {
- _balloonControl.SetMessage(MessageType.Info, obj.Description);
- ShowNotifyIcon(2000);
- }));
- }
- private void LogEvent(EventItem obj)
- {
- if (obj.Type != EventType.EventUI_Notify)
- return;
- Application.Current.Dispatcher.Invoke(new Action(() =>
- {
- while (EventLogList.Count > 100)
- {
- EventLogList.RemoveAt(0);
- }
- EventLogList.Add(obj);
- }));
- }
- private void ShowNotifyIcon(int time)
- {
- TaskbarIcon icon = new TaskbarIcon();
- icon.ShowCustomBalloon(_balloonControl, global::System.Windows.Controls.Primitives.PopupAnimation.Slide, time);
- }
- private void PopDialog(EventItem item)
- {
- Application.Current.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;
- }
- }));
- }
- protected override void InvokeBeforeUpdateProperty(Dictionary<string, object> data)
- {
- Application.Current.Dispatcher.Invoke(new Action(() =>
- {
- _trig.CLK = ClearEventLogEnable;
- if (_trig.Q)
- {
- InvokeClient.Instance.Service.DoOperation("System.Reset");
- EventLogList.Clear();
- if(LP1Enable) InvokeClient.Instance.Service.DoOperation("LP1.LPReset");
- if(LP2Enable) InvokeClient.Instance.Service.DoOperation("LP2.LPReset");
- InvokeClient.Instance.Service.DoOperation("System.ClearEventLogEnable");
- }
- }));
- }
- }
- }
|