终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

65 lines
2.3 KiB

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