123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- using System;
- using System.Collections.Generic;
- using System.Windows;
- using System.Windows.Forms.VisualStyles;
- using System.Windows.Input;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.UI.MVVM;
- using Aitex.Core.Utilities;
- using Aitex.Sorter.Common;
- using Aitex.Sorter.UI.Config;
- using Aitex.Sorter.UI.Views;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.Common.OperationCenter;
- using MECF.Framework.UI.Core.Accounts;
- namespace Aitex.Sorter.UI.ViewModel
- {
- public class UIViewModelBase : SubscriptionViewModelBase
- {
- protected const string SystemDeviceModule = "Device.System";
- protected const string SystemStateModule = "System";
- [IgnorePropertyChange]
- protected SCValue SCLocal
- {
- get;
- set;
- }
- [IgnorePropertyChange]
- private List<Tuple<string, string, string, bool>> _allDataItems = new List<Tuple<string, string, string, bool>>();
- public UIViewModelBase(string vmName)
- : base(vmName)
- {
- SCLocal = new SCValue();
- PollDataFunction = (IEnumerable<string> keys) =>
- {
- return QueryDataClient.Instance.Service.PollData(keys);
- };
- InvokeFunction = (string[] param) =>
- {
- PerformInvokeFunction(param);
- };
- DeviceFunction = (string deviceName, string operationName) =>
- {
- InvokeClient.Instance.Service.DoOperation(OperationName.DeviceOperation.ToString(), deviceName, operationName);
- };
- DeviceControlFunction = (object[] args) =>
- {
- if (args.Length == 2)
- InvokeClient.Instance.Service.DoOperation(OperationName.DeviceOperation.ToString(), args[0], args[1]);
- else if (args.Length == 3)
- InvokeClient.Instance.Service.DoOperation(OperationName.DeviceOperation.ToString(), args[0], args[1], args[2]);
- else if (args.Length == 4)
- InvokeClient.Instance.Service.DoOperation(OperationName.DeviceOperation.ToString(), args[0], args[1], args[2], args[3]);
- };
- _allDataItems = SystemConfigManager.Instance.GetMonitorDataList();
- }
- public virtual bool PerformInvokeFunctionCheck(string[] param)
- {
- if (param != null && (param[0] == "SetAutoMode" || param[0] == "SetManualMode"))
- {
- if (param.Length == 1)
- { return true; }
- if (param.Length == 2 && param[1].ToLower() == "True".ToLower())
- {
- PasswordMsgBox passwordMsgBox = new PasswordMsgBox();
- if (passwordMsgBox.ShowDialog() != true)
- {
- return false;
- }
- }
- }
- return true;
- }
- public override bool PerformInvokeFunction(string[] param)
- {
- if (PerformInvokeFunctionCheck(param))
- {
- if (param.Length == 1)
- {
- if(param[0] == "GonaAbort")
- {
- GonaSorterLogin mainLogin = new GonaSorterLogin();
- if (mainLogin.ShowDialog() == true)
- {
- bool account = AccountClient.Instance.Service.GetAccountInfo(mainLogin.textBoxUserName.Text).ActSuccess;
- if (account)
- InvokeClient.Instance.Service.DoOperation("Abort");
- else
- MessageBox.Show("Do not Support Click Abort");
- }
-
-
- }
- else
- InvokeClient.Instance.Service.DoOperation(param[0]);
- }
- else if (param.Length == 2)
- InvokeClient.Instance.Service.DoOperation(param[0], param[1]);
- else if (param.Length == 3)
- InvokeClient.Instance.Service.DoOperation(param[0], param[1], param[2]);
- }
- return true;
- }
- public virtual void UpdateAllConfig()
- {
- // SCLocal.Update(QueryDataClient.Instance.Service.PollConfig(SCLocal.GetKeys()));
- }
- public Dictionary<string, Tuple<string, string, bool>> GetDataElements(string culture)
- {
- Dictionary<string, Tuple<string, string, bool>> result = new Dictionary<string, Tuple<string, string, bool>>();
- Dictionary<string, Tuple<string, string, string, bool>> all = GetDataElements();
- foreach (var tuple in all)
- {
- result.Add(tuple.Key, Tuple.Create(tuple.Value.Item1, culture == CultureSupported.Chinese ? tuple.Value.Item3 : tuple.Value.Item2, tuple.Value.Item4));
- }
- return result;
- }
- public Dictionary<string, Tuple<string, string, string, bool>> GetDataElements()
- {
- UpdateAllConfig();
- Dictionary<string, Tuple<string, string, string, bool>> dicItems = new Dictionary<string, Tuple<string, string, string, bool>>();
- foreach (var dataItem in _allDataItems)
- {
- dicItems[dataItem.Item1] = dataItem;
- }
- return dicItems;
- }
- void UpdateGasItem(bool enable, string display, string id, string key, Dictionary<string, Tuple<string, string, string, bool>> dicItems)
- {
- if (enable && dicItems.ContainsKey(key))
- {
- dicItems[key] = Tuple.Create(key,
- dicItems[key].Item2.Replace(id, display),
- dicItems[key].Item3.Replace(id, display),
- dicItems[key].Item4);
- }
- else
- {
- dicItems.Remove(key);
- }
- }
- }
- }
|