终端一体化运控平台
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

76 wiersze
3.2 KiB

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