| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 | 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.Controls;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 OpenSEMI.ClientBase;namespace FurnaceUI.Views.Maintenances{    public class FFUConfigViewModel : FurnaceUIViewModelBase    {        public bool SetField<T>(ref T field, T value, string propertyName)        {            if (EqualityComparer<T>.Default.Equals(field, value)) return false;            field = value;            NotifyOfPropertyChange(propertyName);            return true;        }        [Subscription("System.FFUKeyDict")]        public List<string> FFUKeyDict { get; set; }        private ObservableCollection<FFUData> _ffuDatas = new ObservableCollection<FFUData>();        public ObservableCollection<FFUData> 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));        }        Dictionary<string, FFUData> ffuDictionary = new Dictionary<string, FFUData>();         protected override void OnActivate()        {            base.OnActivate();            FFUKeyDict = QueryDataClient.Instance.Service.GetData("System.FFUKeyDict") as List<string>;            FFUDataList.Clear();            foreach (var item in FFUKeyDict)            {                var deviceName = item.Split('.').ToList()[1];                FFUDataList.Add(new FFUData()                {                    DisplayName = deviceName,                });            }            ffuDictionary = FFUDataList.ToDictionary(a => a.DisplayName);        }        protected override void InvokeAfterUpdateProperty(Dictionary<string, object> data)        {            base.InvokeAfterUpdateProperty(data);            var values = QueryDataClient.Instance.Service.PollData(FFUKeyDict).Values.Select(a => (a as AITFFUData)).ToList();            if (ffuDictionary != null)            {                foreach (var item in values)                {                    if (item==null || !ffuDictionary.TryGetValue(item.DisplayName, out var ffu))                        continue;                    ffu.MaxValue = item.Max.ToString();                    ffu.MinValue = item.Min.ToString();                    ffu.ActualValue = item.Feedback;                    ffu.IsSwitch = item.IsSwitchOn;                    ffu.Value = item.SetPoint.ToString();                    ffu.LastSetValue = item.SetPoint;                }            }        }          async void DelayData(string type, object sender, object item)        {            await WaitForResultsAsync();            if (!string.IsNullOrEmpty(type) && item != null && sender != null)            {                var dataItem = item as FFUData;                string value = ((TextBox)sender).Text;                var setValue = double.Parse(value);                var max = double.Parse(dataItem.MaxValue);                var min = double.Parse(dataItem.MinValue);                if (setValue != dataItem.LastSetValue)                {                    //if (setValue < min || setValue > max)                    //{                    //    DialogBox.ShowWarning($"{dataItem.DisplayName} setValue={setValue}, limit is ({min}, {max})");                    //    return;                    //}                    InvokeClient.Instance.Service.DoOperation($"PM1.{dataItem.DisplayName}.SetCurrectSpeed", value);                }            }        }        private async Task WaitForResultsAsync()        {            // Simulate waiting for results using a delay            // In a real-world scenario, you might wait for an event or a specific condition            await Task.Delay(10);            // Here you can add logic to check if the results are ready            // For example, polling or using a completion source        }        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            {                DelayData(type,sender,item);            }            catch (Exception ex)            {                LOG.Write(ex);            }        }    }    public class FFUData : PropertyChangedBase    {        private int _no;        public int No        {            get => _no;            set            {                _no = value;                NotifyOfPropertyChange(nameof(No));            }        }        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));            }        }    }}
 |