终端一体化运控平台
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

76 líneas
3.1 KiB

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