终端一体化运控平台
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

65 rindas
2.3 KiB

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