终端一体化运控平台
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

62 righe
2.1 KiB

  1. using BPASmartClient.Helper;
  2. using FryPot_DosingSystem.Model;
  3. using Microsoft.Toolkit.Mvvm.ComponentModel;
  4. using Microsoft.Toolkit.Mvvm.Input;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace FryPot_DosingSystem.ViewModel
  12. {
  13. internal class DeviceListViewModel : ObservableObject
  14. {
  15. public ObservableCollection<string> DeviceName { get; set; } = new ObservableCollection<string>();
  16. public ObservableCollection<DeviceInfo> devices { get; set; } = new ObservableCollection<DeviceInfo>();
  17. public RelayCommand AddDeviceCommand { get; set; }
  18. public RelayCommand SaveDeviceConfig { get; set; }
  19. public RelayCommand<string> DeleteDevice { get; set; }
  20. public DeviceListViewModel()
  21. {
  22. Json<DeviceManage>.Read();
  23. devices = Json<DeviceManage>.Data.Devices;
  24. DeviceName.Add("滚筒输送线");
  25. DeviceName.Add("炒锅1");
  26. DeviceName.Add("炒锅2");
  27. DeviceName.Add("炒锅3");
  28. DeviceName.Add("炒锅4");
  29. DeviceName.Add("炒锅5");
  30. AddDeviceCommand = new RelayCommand(() =>
  31. {
  32. erp:
  33. string guid = Guid.NewGuid().ToString();
  34. DeviceInfo info = devices.FirstOrDefault(p => p.DeviceNum == guid);
  35. if (info == null)
  36. {
  37. devices.Add(new DeviceInfo() { DeviceNum = guid });
  38. }
  39. else
  40. {
  41. goto erp;
  42. }
  43. });
  44. DeleteDevice = new RelayCommand<string>((str) =>
  45. {
  46. DeviceInfo device = devices.FirstOrDefault(p => p.DeviceNum == str);
  47. if (device != null)
  48. {
  49. devices.Remove(device);
  50. }
  51. });
  52. SaveDeviceConfig = new RelayCommand(() =>
  53. {
  54. Json<DeviceManage>.Data.Devices = devices;
  55. Json<DeviceManage>.Save();
  56. });
  57. }
  58. }
  59. }