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

72 lines
2.8 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.DosingSystem.Model;
  8. using Microsoft.Toolkit.Mvvm.ComponentModel;
  9. using Microsoft.Toolkit.Mvvm.Input;
  10. namespace BPASmartClient.DosingSystem.ViewModel
  11. {
  12. public class ChangeDeviceNameViewModel : ObservableObject
  13. {
  14. public ChangeDeviceNameViewModel()
  15. {
  16. ActionManage.GetInstance.Register(new Action<object>((o) =>
  17. {
  18. if (o != null && o is string str) IpAddress = str;
  19. }), "ChangeDeviceNameViewOpen");
  20. CancleCommand = new RelayCommand(() => { ActionManage.GetInstance.Send("ChangeDeviceNameViewClose"); });
  21. ConfirmCommand = new RelayCommand(() =>
  22. {
  23. if (string.IsNullOrEmpty(DeviceName))
  24. {
  25. ErrorInfo = "设备名称不能为空";
  26. return;
  27. }
  28. int index = Array.FindIndex(DeviceListViewModel.devices.ToArray(), p => p.IpAddress == IpAddress);
  29. if (index >= 0 && index < DeviceListViewModel.devices.Count)
  30. {
  31. if (DeviceListViewModel.devices.FirstOrDefault(p => p.DeviceName == DeviceName) != null)
  32. ErrorInfo = "设备名称已存在";
  33. else
  34. {
  35. NewRecipeViewModel.RawMaterialNames.Remove(DeviceListViewModel.devices.ElementAt(index).DeviceName);
  36. NewRecipeViewModel.RawMaterialNames.Add(DeviceName);
  37. DeviceListViewModel.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. private static string IpAddress = string.Empty;
  52. public RelayCommand ConfirmCommand { get; set; }
  53. public RelayCommand CancleCommand { get; set; }
  54. public string ErrorInfo { get { return _mErrorInfo; } set { _mErrorInfo = value; OnPropertyChanged(); } }
  55. private string _mErrorInfo;
  56. public string DeviceName { get { return _mDeviceName; } set { _mDeviceName = value; OnPropertyChanged(); } }
  57. private string _mDeviceName;
  58. }
  59. }