终端一体化运控平台
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.
 
 
 

59 line
2.6 KiB

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