终端一体化运控平台
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

ChangeDeviceNameViewModel.cs 3.0 KiB

2 yıl önce
2 yıl önce
2 yıl önce
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 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. }