EquipmentSettingWindowViewModel.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using Prism.Mvvm;
  2. using System.Linq;
  3. using Prism.Events;
  4. using Panuon.UI.Silver;
  5. using SHJX.Service.Common.Event;
  6. using SHJX.Service.Common.Interface;
  7. using System.Collections.ObjectModel;
  8. using SHJX.Service.Model.CRUDModules;
  9. using SHJX.Service.Control.Interface;
  10. namespace SHJX.Service.Shell.ViewModels.Setting
  11. {
  12. public class EquipmentSettingWindowViewModel : BindableBase
  13. {
  14. #region Field
  15. private readonly ILogService _log;
  16. private readonly IEventAggregator _ea;
  17. private readonly ISettingService _service;
  18. #endregion
  19. #region Property
  20. public ObservableCollection<MotorSpeed> MotorSpeeds { get; set; }
  21. public ObservableCollection<LiquidVolume> LiquidVolumes { get; set; }
  22. public ObservableCollection<LiquidTotal> LiquidTotals { get; set; }
  23. #endregion
  24. public EquipmentSettingWindowViewModel(IEventAggregator ea, ILogService log, ISettingService service)
  25. {
  26. _ea = ea;
  27. _log = log;
  28. _service = service;
  29. LiquidVolumes = new ObservableCollection<LiquidVolume>(_service.GetData<LiquidVolume>());
  30. MotorSpeeds = new ObservableCollection<MotorSpeed>(_service.GetData<MotorSpeed>());
  31. LiquidTotals=new ObservableCollection<LiquidTotal>(_service.GetData<LiquidTotal>());
  32. _ea.GetEvent<UpdateSettingEvent>().Subscribe(UpdateSetting);
  33. _ea.GetEvent<SettingClosingEvent>().Subscribe(() =>
  34. {
  35. _ea.GetEvent<UpdateSettingEvent>().Unsubscribe(UpdateSetting);
  36. });
  37. }
  38. #region Method
  39. public void UpdateSetting()
  40. {
  41. var ret = _service.UpdateSetting(LiquidVolumes.ToList());
  42. ret = ret && _service.UpdateSetting(MotorSpeeds.ToList());
  43. ret = ret && _service.UpdateSetting(LiquidTotals.ToList());
  44. Notice.Show($"设备相关设置更新{(ret ? "成功" : "失败")}", "Info", 3, Panuon.UI.Silver.MessageBoxIcon.Info);
  45. }
  46. #endregion
  47. }
  48. }