终端一体化运控平台
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

72 строки
2.9 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using BPASmartClient.Helper;
  7. using BPASmartClient.DosingSystem.Model;
  8. using Microsoft.Toolkit.Mvvm.ComponentModel;
  9. using Microsoft.Toolkit.Mvvm.Input;
  10. using BPASmartClient.CustomResource.Pages.Model;
  11. namespace BPASmartClient.DosingSystem.ViewModel
  12. {
  13. public class ChangeDeviceNameViewModel : ObservableObject
  14. {
  15. public ChangeDeviceNameViewModel()
  16. {
  17. ActionManage.GetInstance.Register(new Action<object>((o) =>
  18. {
  19. if (o != null && o is string str) IpAddress = str;
  20. }), "ChangeDeviceNameViewOpen");
  21. CancleCommand = new RelayCommand(() => { ActionManage.GetInstance.Send("ChangeDeviceNameViewClose"); });
  22. ConfirmCommand = new RelayCommand(() =>
  23. {
  24. if (string.IsNullOrEmpty(DeviceName))
  25. {
  26. ErrorInfo = "设备名称不能为空";
  27. return;
  28. }
  29. int index = Array.FindIndex(DeviceListViewModel.devices.ToArray(), p => p.IpAddress == IpAddress);
  30. if (index >= 0 && index < DeviceListViewModel.devices.Count)
  31. {
  32. if (DeviceListViewModel.devices.FirstOrDefault(p => p.DeviceName == DeviceName) != null)
  33. ErrorInfo = "设备名称已存在";
  34. else
  35. {
  36. var res = Global.DeviceRawMaterials.FirstOrDefault(p => p.RawMaterialName == DeviceListViewModel.devices.ElementAt(index).DeviceName);
  37. res.RawMaterialName = DeviceName;
  38. DeviceListViewModel.devices.ElementAt(index).DeviceName = DeviceName;
  39. DeviceInquire.GetInstance.GetDevice(IpAddress).SetDeviceName(DeviceName);//设置PLC名称
  40. for (int i = 0; i < Json<LocaPar>.Data.Recipes.Count; i++)
  41. {
  42. for (int m = 0; m < Json<LocaPar>.Data.Recipes.ElementAt(i).RawMaterials.Count; m++)
  43. {
  44. Json<LocaPar>.Data.Recipes.ElementAt(i).RawMaterials.ElementAt(m).RawMaterialName = DeviceName;
  45. }
  46. }
  47. ActionManage.GetInstance.Send("ChangeDeviceNameViewClose");
  48. }
  49. }
  50. });
  51. }
  52. private static string IpAddress = string.Empty;
  53. public RelayCommand ConfirmCommand { get; set; }
  54. public RelayCommand CancleCommand { get; set; }
  55. public string ErrorInfo { get { return _mErrorInfo; } set { _mErrorInfo = value; OnPropertyChanged(); } }
  56. private string _mErrorInfo;
  57. public string DeviceName { get { return _mDeviceName; } set { _mDeviceName = value; OnPropertyChanged(); } }
  58. private string _mDeviceName;
  59. }
  60. }