using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Shell; using Aitex.Core.Common.DeviceData; using Aitex.Core.RT.IOCore; using Aitex.Core.RT.Log; using Aitex.Core.UI.DeviceControl; using Aitex.Core.Util; using Caliburn.Micro.Core; using FurnaceUI.Models; using FurnaceUI.Views.Recipes; using MECF.Framework.Common.CommonData.DeviceData; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.Device; using MECF.Framework.Common.OperationCenter; using MECF.Framework.UI.Client.CenterViews.Dialogs; using OpenSEMI.ClientBase; namespace FurnaceUI.Views.Maintenances { public class FFUConfigViewModel : FurnaceUIViewModelBase { public bool SetField(ref T field, T value, string propertyName) { if (EqualityComparer.Default.Equals(field, value)) return false; field = value; NotifyOfPropertyChange(propertyName); return true; } [Subscription("System.FFUKeyDict")] public List FFUKeyDict { get; set; } public bool IsPermission { get => this.Permission == 3; } private ObservableCollection _ffuDatas = new ObservableCollection(); public ObservableCollection FFUDataList { get => _ffuDatas; set { _ffuDatas = value; NotifyOfPropertyChange(nameof(FFUDataList)); } } private bool _powerOffVisibility = false; public bool PowerOffVisibility { get => _powerOffVisibility; set => SetField(ref _powerOffVisibility, value, nameof(PowerOffVisibility)); } private bool _powerOnVisibility = true; public bool PowerOnVisibility { get => _powerOnVisibility; set => SetField(ref _powerOnVisibility, value, nameof(PowerOnVisibility)); } protected override void OnActivate() { base.OnActivate(); FFUKeyDict = QueryDataClient.Instance.Service.GetData("System.FFUKeyDict") as List; FFUDataList.Clear(); foreach (var item in FFUKeyDict) { var deviceName = item.Split('.').ToList()[1]; var ffuConfigData = QueryDataClient.Instance.Service.GetConfig($"FFU.{deviceName}.SetSpeed"); FFUDataList.Add(new FFUData() { RTName = deviceName, Value = ffuConfigData.ToString(), }); } } protected override void InvokeAfterUpdateProperty(Dictionary data) { base.InvokeAfterUpdateProperty(data); if (FFUDataList != null && FFUDataList.Count > 0) { var allFfuName = FFUDataList.Select(a => $"PM1.{a.RTName}.DeviceData").ToList(); var allRtData = QueryDataClient.Instance.Service.PollData(allFfuName); foreach (var item in FFUDataList) { var rtItem = allRtData.FirstOrDefault(a => a.Key == $"PM1.{item.RTName}.DeviceData"); if (rtItem.Value == null) continue; item.DisplayName = ((AITFFUData)rtItem.Value).DisplayName; item.ActualValue = ((AITFFUData)rtItem.Value).Feedback; item.IsSwitch = ((AITFFUData)rtItem.Value).IsSwitchOn; } } } public void AllFFUPower(string value) { var setValue = bool.Parse(value); if (setValue) { PowerOnVisibility = false; PowerOffVisibility = true; } else { PowerOnVisibility = true; PowerOffVisibility = false; } InvokeClient.Instance.Service.DoOperation($"PM1.SetAllFFUPower", setValue); } public void SetValueTextChanged(string type, object sender, object item) { try { } catch (Exception ex) { LOG.Write(ex); } } public void Save() { if (!DialogBox.Confirm("Are you sure Determine the speed parameters for FFU")) return; foreach (var item in FFUDataList) { InvokeClient.Instance.Service.DoOperation($"PM1.{item.RTName}.SetCurrectSpeed", item.Value); } (GetView() as Window).Close(); } public void Cancle() { (GetView() as Window).Close(); } public void AllSetClick(object sender) { string stSetValue = ShowNumberKeyboard(sender as Button, "", 1); var values = QueryDataClient.Instance.Service.PollData(FFUKeyDict).Values.Select(a => (a as AITFFUData)).ToList(); foreach (var item in FFUDataList) { var rtData = values.FirstOrDefault(a => a.RTName == item.RTName); if (rtData == null) continue; item.Value = stSetValue; } } private string ShowNumberKeyboard(Control control, string defaultValue, int keepDecimals = -1) { NumberKeyboard numberKeyboard = new NumberKeyboard("", defaultValue); numberKeyboard.KeepDecimals = keepDecimals; var point = control.PointFromScreen(new Point(0, 0)); double wx = SystemParameters.WorkArea.Width; double hy = SystemParameters.WorkArea.Height; if (-point.Y + control.ActualHeight + 5 + numberKeyboard.Height < hy) { numberKeyboard.Top = -point.Y + control.ActualHeight + 5; } else { numberKeyboard.Top = -point.Y - numberKeyboard.Height - 5; } if (-point.X + numberKeyboard.Width < wx) { numberKeyboard.Left = -point.X; } else { numberKeyboard.Left = -point.X - (numberKeyboard.Width - control.ActualWidth); } if ((bool)numberKeyboard.ShowDialog()) return numberKeyboard.ValueString; else return "Cancel"; } } public class FFUData : PropertyChangedBase { private int _no; public int No { get => _no; set { _no = value; NotifyOfPropertyChange(nameof(No)); } } private string _rtName; public string RTName { get => _rtName; set { _rtName = value; NotifyOfPropertyChange(nameof(RTName)); } } private string _displayName; public string DisplayName { get => _displayName; set { _displayName = value; NotifyOfPropertyChange(nameof(DisplayName)); } } private double _lastSetValue; public double LastSetValue { get => _lastSetValue; set { _lastSetValue = value; NotifyOfPropertyChange(nameof(LastSetValue)); } } private double _actualValue; public double ActualValue { get => _actualValue; set { _actualValue = value; NotifyOfPropertyChange(nameof(ActualValue)); } } private string _value; public string Value { get => _value; set { _value = value; NotifyOfPropertyChange(nameof(Value)); } } private bool _isSwitch; public bool IsSwitch { get => _isSwitch; set { _isSwitch = value; NotifyOfPropertyChange(nameof(IsSwitch)); } } private string _maxValue; public string MaxValue { get => _maxValue; set { _maxValue = value; NotifyOfPropertyChange(nameof(MaxValue)); } } private string _minValue; public string MinValue { get => _minValue; set { _minValue = value; NotifyOfPropertyChange(nameof(MinValue)); } } private bool _isSetChanged = true; public bool IsSetChanged { get => _isSetChanged; set { _isSetChanged = value; NotifyOfPropertyChange(nameof(IsSetChanged)); } } } }