OtherManualWindowViewModel.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using Prism.Mvvm;
  2. using System.Linq;
  3. using SHJX.Service.Control.Interface;
  4. using SHJX.Service.Model.Dao;
  5. using System.Collections.ObjectModel;
  6. using Prism.Commands;
  7. using SHJX.Service.Control.Extends;
  8. using Prism.Events;
  9. using SHJX.Service.Common.Event;
  10. using SHJX.Service.Model.EventArgs;
  11. using SHJX.Service.Common.Constants;
  12. namespace SHJX.Service.Shell.ViewModels.Manual
  13. {
  14. public class OtherManualWindowViewModel : BindableBase
  15. {
  16. #region Fields
  17. private readonly IManualService _service;
  18. private readonly IEventAggregator _ea;
  19. #endregion
  20. #region Perproties
  21. private string _waveKeyItem;
  22. public string WaveKeyItem
  23. {
  24. get => _waveKeyItem;
  25. set => SetProperty(ref _waveKeyItem, value);
  26. }
  27. private double _currentKValue;
  28. public double CurrentKValue
  29. {
  30. get => _currentKValue;
  31. set => SetProperty(ref _currentKValue, value);
  32. }
  33. public ObservableCollection<string> Wavekeys { get; set; }
  34. #endregion
  35. public OtherManualWindowViewModel(IManualService service, IEventAggregator ea)
  36. {
  37. _ea = ea;
  38. _service = service;
  39. Wavekeys = new ObservableCollection<string>((from wavekey in _service.GetData<Wavekey>().ToList() orderby wavekey.WaveKey descending select wavekey.WaveKey).ToList());
  40. }
  41. #region Command
  42. private DelegateCommand _loadedCommand;
  43. public DelegateCommand LoadedCommand => _loadedCommand ??= new DelegateCommand(ExecuteLoadedCommand);
  44. private DelegateCommand _selectionChangedCommand;
  45. public DelegateCommand SelectionChangedCommand => _selectionChangedCommand ??= new DelegateCommand(ExecuteSelectionChangedCommand);
  46. private DelegateCommand _adjustCommand;
  47. public DelegateCommand AdjustCommand => _adjustCommand ??= new DelegateCommand(ExecuteAdjustCommand);
  48. #endregion
  49. #region Execute
  50. private void ExecuteLoadedCommand()
  51. {
  52. ChangeCurrentKValue();
  53. }
  54. private void ExecuteSelectionChangedCommand()
  55. {
  56. ChangeCurrentKValue();
  57. }
  58. private void ChangeCurrentKValue()
  59. {
  60. CurrentKValue = CalculationResult.CalculateType(WaveKeyItem, TaskTypeName.CALIBRATION_ZH, (arg) => 10 / arg);
  61. }
  62. private void ExecuteAdjustCommand()
  63. {
  64. AdjustResultArgs args = new()
  65. {
  66. Key = WaveKeyItem,
  67. Value = CurrentKValue
  68. };
  69. _ea.GetEvent<AdjustResultEvent>().Publish(args);
  70. }
  71. #endregion
  72. }
  73. }