DeviceManagerViewModel.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System.Collections.ObjectModel;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using UICommon.DataType;
  5. namespace DeviceManagement.ViewModels;
  6. public partial class DeviceManagerViewModel : ObservableObject
  7. {
  8. public DeviceManagerViewModel(DeviceCollection deviceCollection, IDialogService dialogService)
  9. {
  10. this._DeviceCollection = deviceCollection;
  11. this._DialogService = dialogService;
  12. deviceCollection.DeviceList.CollectionChanged += DeviceList_CollectionChanged;
  13. this.DeviceList_CollectionChanged(deviceCollection.DeviceList, null);
  14. }
  15. private void DeviceList_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs? e)
  16. {
  17. if (sender is not ObservableDictionary<Guid, DeviceInfo_VM> deviceList)
  18. return;
  19. this.Devices.Clear();
  20. foreach (DeviceInfo_VM device in deviceList.Values)
  21. {
  22. this.Devices[device.DeviceModel] ??= [];
  23. this.Devices[device.DeviceModel].Add(device);
  24. }
  25. }
  26. private readonly IDialogService _DialogService;
  27. private readonly DeviceCollection _DeviceCollection;
  28. [ObservableProperty]
  29. private ObservableDictionary<DeviceModel, ObservableCollection<DeviceInfo_VM>> _Devices = [];
  30. [RelayCommand]
  31. private void CheckDetail(DeviceInfo_VM deviceInfo)
  32. {
  33. string path = Path.Combine(System.Environment.CurrentDirectory, "Analizer");
  34. try
  35. {
  36. object o = deviceInfo.DeviceModel switch
  37. {
  38. DeviceModel.JetKepler => Process.Start(Path.Combine(path, "Kepler", "KeplerAnalizer.exe")),
  39. DeviceModel.Proxima => Process.Start(Path.Combine(path, "Proxima", "ProximaAnalizer.exe")),
  40. _ => MessageBox.Show("Undefined Type")
  41. };
  42. }
  43. catch
  44. {
  45. }
  46. }
  47. [RelayCommand]
  48. private void Remote(DeviceInfo_VM deviceInfo)
  49. {
  50. //string path = Path.Combine(System.Environment.CurrentDirectory, "Analizer");
  51. try
  52. {
  53. object o = deviceInfo.DeviceModel switch
  54. {
  55. //DeviceModel.JetKepler => Process.Start(Path.Combine(path, "Kepler", "KeplerAnalizer.exe")),
  56. DeviceModel.Proxima => Process.Start(@"E:\TINUI\FurnaceUI.exe"),
  57. _ => MessageBox.Show("Undefined Type")
  58. };
  59. }
  60. catch
  61. {
  62. }
  63. }
  64. [RelayCommand]
  65. private void Delete(DeviceInfo_VM deviceInfo)
  66. {
  67. if (deviceInfo.Guid is null || deviceInfo.Guid == Guid.Empty)
  68. return;
  69. MessageBoxResult result = MessageBox.Show($"确认删除 {deviceInfo.DeviceModel}-{deviceInfo.DeviceName} ?", "确认删除", MessageBoxButton.YesNo, MessageBoxImage.Question);
  70. if (result != MessageBoxResult.Yes)
  71. return;
  72. this._DeviceCollection.DeviceList.Remove(deviceInfo.Guid.Value);
  73. MessageBox.Show($"{deviceInfo.DeviceModel}-{deviceInfo.DeviceName} 已删除");
  74. }
  75. [RelayCommand]
  76. private void Setting(DeviceInfo_VM deviceInfo)
  77. {
  78. IDialogParameters para = new DialogParameters() { { "Device", deviceInfo } };
  79. this._DialogService.Show("EditDevice", para, null);
  80. }
  81. }