DissolveBottomPosViewModel.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using Prism.Mvvm;
  2. using System.Linq;
  3. using Prism.Events;
  4. using SHJX.Service.Common.Event;
  5. using System.Collections.Generic;
  6. using SHJX.Service.Model.EventArgs;
  7. using SHJX.Service.Model.XmlModules;
  8. using SHJX.Service.Control.Interface;
  9. using System.Collections.ObjectModel;
  10. using SHJX.Service.Model.ControlModules;
  11. using SHJX.Service.Common.Interface;
  12. using SHJX.Service.Common.Constants;
  13. namespace SHJX.Service.Main.ViewModels
  14. {
  15. public class DissolveBottomPosViewModel : BindableBase
  16. {
  17. #region Fields
  18. private readonly ILogService _log;
  19. #endregion
  20. #region Properties
  21. public ObservableCollection<RingProcessBarControl> RingProcessBars { get; set; }
  22. #endregion
  23. public DissolveBottomPosViewModel(ILogService log, IEventAggregator ea, ISampleService service)
  24. {
  25. _log = log;
  26. SamplePosition topPosition = service.GetSamplePosition("DissolveTopPos");
  27. SamplePosition middleposition = service.GetSamplePosition("DissolveMiddlePos");
  28. SamplePosition position = service.GetSamplePosition("DissolveBottomPos");
  29. int startIndex = topPosition.Count + middleposition.Count +1;
  30. RingProcessBars = new ObservableCollection<RingProcessBarControl>();
  31. for (int i = 0; i < position.Count; i++)
  32. {
  33. RingProcessBarControl ringProcess = new()
  34. {
  35. Index = i,
  36. Name = $"{position.Value}{i + startIndex}"
  37. };
  38. RingProcessBars.Add(ringProcess);
  39. }
  40. #region 监听
  41. ea.GetEvent<UpdateElementEvent>().Subscribe(ChangeElement);
  42. ea.GetEvent<UpdateDissolveElementEvent>().Subscribe(ChangeProgress);
  43. #endregion
  44. }
  45. #region Event Methods
  46. public void ChangeElement(List<ElementArgs> args)
  47. {
  48. try
  49. {
  50. foreach (ElementArgs arg in args)
  51. {
  52. RingProcessBarControl control = RingProcessBars.Where(item => item.Name.Equals(arg.Name)).FirstOrDefault();
  53. if (control is null)
  54. {
  55. continue;
  56. }
  57. RingProcessBars[control.Index].CurrentText = !arg.Enable ? string.IsNullOrWhiteSpace(arg.Current) ? string.Empty : arg.Current.Length < 2 ? arg.Current : arg.Current[1..] : string.Empty;
  58. RingProcessBars[control.Index].CenterColor = !arg.Enable ? ColorNames.SentColor : ColorNames.MainColor;
  59. }
  60. }
  61. catch (System.Exception ex)
  62. {
  63. _log.ErrorFormat(ex.ToString());
  64. }
  65. }
  66. public void ChangeProgress(List<HeatingChangeArgs> args)
  67. {
  68. try
  69. {
  70. foreach (HeatingChangeArgs arg in args)
  71. {
  72. RingProcessBarControl control = RingProcessBars.Where(item => item.Name.Equals(arg.Name)).FirstOrDefault();
  73. if (control is null)
  74. {
  75. continue;
  76. }
  77. RingProcessBars[control.Index].RoundVisiable = arg.Dispaly;
  78. RingProcessBars[control.Index].CurrentCycleValue = arg.Progress;
  79. }
  80. }
  81. catch (System.Exception ex)
  82. {
  83. _log.ErrorFormat(ex.ToString());
  84. }
  85. }
  86. #endregion
  87. }
  88. }