终端一体化运控平台
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

75 行
3.1 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. ActionManage.GetInstance.Send("ChangeDeviceNameViewClose");
  50. }
  51. }
  52. }
  53. });
  54. }
  55. private static string IpAddress = string.Empty;
  56. public RelayCommand ConfirmCommand { get; set; }
  57. public RelayCommand CancleCommand { get; set; }
  58. public string ErrorInfo { get { return _mErrorInfo; } set { _mErrorInfo = value; OnPropertyChanged(); } }
  59. private string _mErrorInfo;
  60. public string DeviceName { get { return _mDeviceName; } set { _mDeviceName = value; OnPropertyChanged(); } }
  61. private string _mDeviceName;
  62. }
  63. }