using Prism.Mvvm; using System.Linq; using SHJX.Service.Control.Interface; using SHJX.Service.Model.Dao; using System.Collections.ObjectModel; using Prism.Commands; using SHJX.Service.Control.Extends; using Prism.Events; using SHJX.Service.Common.Event; using SHJX.Service.Model.EventArgs; using SHJX.Service.Common.Constants; namespace SHJX.Service.Shell.ViewModels.Manual { public class OtherManualWindowViewModel : BindableBase { #region Fields private readonly IManualService _service; private readonly IEventAggregator _ea; #endregion #region Perproties private string _waveKeyItem; public string WaveKeyItem { get => _waveKeyItem; set => SetProperty(ref _waveKeyItem, value); } private double _currentKValue; public double CurrentKValue { get => _currentKValue; set => SetProperty(ref _currentKValue, value); } public ObservableCollection Wavekeys { get; set; } #endregion public OtherManualWindowViewModel(IManualService service, IEventAggregator ea) { _ea = ea; _service = service; Wavekeys = new ObservableCollection((from wavekey in _service.GetData().ToList() orderby wavekey.WaveKey descending select wavekey.WaveKey).ToList()); } #region Command private DelegateCommand _loadedCommand; public DelegateCommand LoadedCommand => _loadedCommand ??= new DelegateCommand(ExecuteLoadedCommand); private DelegateCommand _selectionChangedCommand; public DelegateCommand SelectionChangedCommand => _selectionChangedCommand ??= new DelegateCommand(ExecuteSelectionChangedCommand); private DelegateCommand _adjustCommand; public DelegateCommand AdjustCommand => _adjustCommand ??= new DelegateCommand(ExecuteAdjustCommand); #endregion #region Execute private void ExecuteLoadedCommand() { ChangeCurrentKValue(); } private void ExecuteSelectionChangedCommand() { ChangeCurrentKValue(); } private void ChangeCurrentKValue() { CurrentKValue = CalculationResult.CalculateType(WaveKeyItem, TaskTypeName.CALIBRATION_ZH, (arg) => 10 / arg); } private void ExecuteAdjustCommand() { AdjustResultArgs args = new() { Key = WaveKeyItem, Value = CurrentKValue }; _ea.GetEvent().Publish(args); } #endregion } }