终端一体化运控平台
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

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