using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Windows; using System.Windows.Input; using Aitex.Core.Common; using Aitex.Core.RT.Event; using Aitex.Core.RT.SCCore; using Aitex.Core.UI.Dialog; using Aitex.Core.UI.MVVM; using Aitex.Core.UI.View.Common; using Aitex.Core.Util; using Aitex.Core.Utilities; using Aitex.Sorter.Common; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.OperationCenter; using MessageBox = Xceed.Wpf.Toolkit.MessageBox; using PageSCValue = MECF.Framework.UI.Core.View.Common.PageSCValue; namespace Aitex.Sorter.UI.ViewModel { class TerminalMessageViewModel : UIViewModelBase { #region subscrib [Subscription(ParamName.IsSpoolingEnable, ChamberSetString.System)] public bool IsSpoolingEnable { get; set; } [Subscription(ParamName.SpoolingState, ChamberSetString.System)] public string SpoolingState { get; set; } [Subscription(ParamName.SpoolingActual, ChamberSetString.System)] public string SpoolingActual { get; set; } [Subscription(ParamName.SpoolingTotal, ChamberSetString.System)] public string SpoolingTotal { get; set; } [Subscription(ParamName.SpoolingFullTime, ChamberSetString.System)] public string SpoolingFullTime { get; set; } [Subscription(ParamName.SpoolingStartTime, ChamberSetString.System)] public string SpoolingStartTime { get; set; } [Subscription(ParamName.ControlStatus, ChamberSetString.System)] public string HostControlStatus { get; set; } [Subscription(ParamName.CommunicationStatus, ChamberSetString.System)] public string HostCommunicationStatus { get; set; } #endregion #region logic 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; } } public bool IsEnableDisableButton { get { return FACommunicationState != FACommunicationState.Disabled; } } //Unknown, //EquipmentOffline, //AttemptOnline, //HostOffline, //OnlineLocal, //OnlineRemote, public bool IsEnableOnlineButton { get { return FAControlState == FAControlState.Unknown || FAControlState == FAControlState.EquipmentOffline; } } public bool IsEnableOfflineButton { get { return FAControlState == FAControlState.Unknown || FAControlState != FAControlState.EquipmentOffline; } } public bool IsEnableLocalButton { get { return FAControlState == FAControlState.OnlineRemote; } } public bool IsEnableRemoteButton { get { return FAControlState == FAControlState.OnlineLocal; } } public bool IsEnableSpoolingEnableButton { get { return !IsSpoolingEnable;//SpoolingState == FASpoolingState.Inactive.ToString(); } } public bool IsEnableSpoolingDisableButton { get { return IsSpoolingEnable;// SpoolingState == FASpoolingState.Active.ToString(); } } #endregion [IgnorePropertyChange] public PageSCFA ConfigFeedback { get; set; } [IgnorePropertyChange] public PageSCFA ConfigSetPoint { get; set; } [IgnorePropertyChange] public ICommand SetConfigCommand { get; private set; } [IgnorePropertyChange] public ICommand SetConfig2Command { get; private set; } [IgnorePropertyChange] public ICommand InitializeCommand { get; private set; } public TerminalMessageViewModel():base(nameof(TerminalMessageViewModel)) { ConfigFeedback = new PageSCFA(); ConfigSetPoint = new PageSCFA(); SetConfigCommand = new DelegateCommand(SetConfig); SetConfig2Command = new DelegateCommand(SetConfig2); InitializeCommand = new DelegateCommand(InitializeFa); } private void InitializeFa(object obj) { if (MessageBox.Show("Are you sure you want to re-initialize FA connection?", "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { InvokeClient.Instance.Service.DoOperation("Fa.Initialize"); } } void SetConfig(object param) { object[] sc = (object[])param; InvokeClient.Instance.Service.DoOperation("System.SetConfig", sc[0].ToString(), sc[1].ToString()); UpdateConfig(); } void SetConfig2(object param) { string id = (string)param; string key = id.Replace("Fa.", "Fa_"); PropertyInfo[] property = typeof(PageSCFA).GetProperties(); foreach (PropertyInfo prop in property) { if (prop.Name == key) { InvokeClient.Instance.Service.DoOperation("System.SetConfig", id, prop.GetValue(ConfigSetPoint, null).ToString()); break; } } UpdateConfig(); } public void UpdateConfig() { ConfigFeedback.Update(QueryDataClient.Instance.Service.PollConfig(ConfigFeedback.GetKeys())); ConfigSetPoint.Update(QueryDataClient.Instance.Service.PollConfig(ConfigSetPoint.GetKeys())); InvokeAllPropertyChanged(); } protected override void InvokeBeforeUpdateProperty(Dictionary data) { } } }