DebugRollerHxViewModel.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using Prism.Commands;
  2. using Prism.Events;
  3. using ProjectManagementSystem.Common.Core;
  4. using ProjectManagementSystem.Common.Logger;
  5. using ProjectManagementSystem.Language;
  6. using ProjectManagementSystemView.Infrastructure.Events;
  7. using ProjectManagementSystemView.Infrastructure.Extensions;
  8. using ProjectManagementSystemView.Infrastructure.Models;
  9. using PropertyChanged;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Collections.ObjectModel;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using System.Windows;
  17. namespace ProjectManagementSystemView.ViewModels
  18. {
  19. [AddINotifyPropertyChangedInterface]
  20. public class DebugRollerHxViewModel
  21. {
  22. public bool IsVisible { get; set; }
  23. public byte ActionCode { get; set; }
  24. public VmInfoRollerHx SelectedVmData { get; set; }
  25. public ObservableCollection<VmInfoRollerHx> VmDatas { get; set; } = new ObservableCollection<VmInfoRollerHx>();
  26. public ObservableCollection<byte> ActionCodeCollection { get; set; } = new ObservableCollection<byte>();
  27. public DelegateCommand<object> SendCommand { get; set; }
  28. public DelegateCommand<object> QueryCommand { get; set; }
  29. public DebugRollerHxViewModel(IEventAggregator eventAggregator)
  30. {
  31. ActionCodeCollection.Add(1);
  32. ActionCodeCollection.Add(2);
  33. SendCommand = new DelegateCommand<object>(arg =>
  34. {
  35. RollerHxOpreate(arg);
  36. });
  37. QueryCommand = new DelegateCommand<object>(arg =>
  38. {
  39. DeviceControl.Instance.RollerHxQuery(SelectedVmData?.DeviceId ?? 0);
  40. });
  41. eventAggregator.GetEvent<UpdateViewEvent>().Subscribe(UpdateView);
  42. }
  43. private void UpdateView()
  44. {
  45. if (!IsVisible) return;
  46. var dataList = DeviceControl.Instance.Communication.InfoRollerHxDictionary.Values;
  47. VmDatas.Update(dataList, (s, v) => s.DeviceId == v.DeviceId);
  48. }
  49. private void RollerHxOpreate(object sender)
  50. {
  51. var deviceId = SelectedVmData?.DeviceId ?? 0;
  52. if (deviceId <= 0) return;
  53. if (ActionCode <= 0) return;
  54. string text = $"{sender}? {Langs.DeviceId}:{deviceId} {Langs.ActionCode}:{ActionCode}";
  55. var dialogResult = MessageBox.Show(text, Langs.Prompt, MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.Cancel);
  56. if (dialogResult != MessageBoxResult.OK)
  57. {
  58. return;
  59. }
  60. DeviceControl.Instance.RollerHxOperate(deviceId, ActionCode);
  61. CLog.Instance.TaskLog.WriteInfo(Langs.RollerHxViewManualOperation, $"{Langs.DeviceId}:{deviceId} {Langs.ActionCode}:{ActionCode}");
  62. }
  63. }
  64. }