终端一体化运控平台
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

73 řádky
3.0 KiB

  1. using BPASmartClient.CustomResource.Pages.Model;
  2. using BPASmartClient.FoodStationTest.Model;
  3. using BPA.Helper;
  4. using BPA.Helper;
  5. using System;
  6. using System.Linq;
  7. namespace BPASmartClient.FoodStationTest.ViewModel
  8. {
  9. public class ChangeDeviceNameViewModel : NotifyBase
  10. {
  11. public ChangeDeviceNameViewModel()
  12. {
  13. ActionManage.GetInstance.Register(new Action<object>((o) =>
  14. {
  15. if (o != null && o is string str)
  16. IpAddress = str;
  17. }), "ChangeDeviceNameViewOpen");
  18. CancleCommand = new BPARelayCommand(() => { ActionManage.GetInstance.Send("ChangeDeviceNameViewClose"); });
  19. ConfirmCommand = 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<LocalPar>.Data.Recipes.Count; i++)
  40. {
  41. for (int m = 0; m < Json<LocalPar>.Data.Recipes.ElementAt(i).RawMaterials.Count; m++)
  42. {
  43. Json<LocalPar>.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 BPARelayCommand ConfirmCommand { get; set; }
  54. public BPARelayCommand 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. }