123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- 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 Aitex.Sorter.UI.Controls.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
- {
- public class PageSCFA : PageSCValue
- {
- public string HsmsConnectionMode { get; set; }
- public string HsmsLocalIP { get; set; }
- public int HsmsLocalPort { get; set; }
- public string HsmsRemoteIP { get; set; }
- public int HsmsRemotePort { get; set; }
- public int HsmsT3timeout { get; set; }
- public int HsmsT5timeout { get; set; }
- public int HsmsT6timeout { get; set; }
- public int HsmsT7timeout { get; set; }
- public int HsmsT8timeout { get; set; }
- public bool FA_EnableSpooling { get; set; }
- public int FA_FaLinkTestInterval { get; set; }
- public string FA_FaDefaultCommunicationState { get; set; }
- public string FA_FaDefaultControlState { get; set; }
- public string FA_FaDefaultControlSubState { get; set; }
- public string SecsDeviceID { get; set; }
- public PageSCFA()
- {
- UpdateKeys(typeof(PageSCFA).GetProperties());
- }
- }
- class FAViewModel : 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;
- }
- [IgnorePropertyChange]
- public ICommand SetHSMSCommand
- {
- get;
- private set;
- }
- [IgnorePropertyChange]
- public ICommand SetHSMSCommandEx
- {
- get;
- private set;
- }
- public FAViewModel() : base(nameof(FAViewModel))
- {
- ConfigFeedback = new PageSCFA();
- ConfigSetPoint = new PageSCFA();
- SetConfigCommand = new DelegateCommand<object>(SetConfig);
- SetConfig2Command = new DelegateCommand<object>(SetConfig2);
- InitializeCommand = new DelegateCommand<object>(InitializeFa);
- SetHSMSCommand = new DelegateCommand<object>(SetHSMS);
- SetHSMSCommandEx = new DelegateCommand<DependencyObject>(SetHSMSEx);
- UpdateSetHSMS();
- }
- string[] keysisInt = new string[] { "HsmsLocalPort", "HsmsRemotePort", "HsmsT3timeout"
- ,"HsmsT5timeout","HsmsT6timeout","HsmsT7timeout","HsmsT8timeout" };
- private void UpdateSetHSMS()
- {
- var liststr = ConfigFeedback.GetKeys();
- Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
- foreach (var item in liststr)
- {
- object value = QueryDataClient.Instance.Service.GetData("System." + item);
- if (value != null)
- {
- if (keysisInt.Contains(item))
- { keyValuePairs.Add(item, int.Parse(value.ToString())); }
- else
- { keyValuePairs.Add(item, value); }
- }
- }
- ConfigFeedback.Update(keyValuePairs);
- ConfigSetPoint.Update(keyValuePairs);
- InvokeAllPropertyChanged();
- }
- private void SetHSMS(object sender)
- {
- object[] sc = (object[])sender;
- InvokeClient.Instance.Service.DoOperation("FACommand", sc);
- UpdateSetHSMS();
- }
- private void SetHSMSEx(DependencyObject sender)
- {
- // object[] sc = (object[])obj;
- var command = CommandHelper.GetCommandItem(sender);
- var lstParameter = new List<object>(command.Parameters);
- lstParameter.Insert(0, command.CommandName);
- // lstParameter.Insert(1, command.Parameters);
- InvokeClient.Instance.Service.DoOperation("FACommand", lstParameter.ToArray());
- UpdateSetHSMS();
- }
- 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<string, object> data)
- {
- }
- }
- }
|