终端一体化运控平台
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ChangeDeviceNameViewModel.cs 2.9 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. using BPASmartClient.CustomResource.Pages.Model;
  11. namespace BPASmartClient.DosingSystem.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(DeviceListViewModel.devices.ToArray(), p => p.IpAddress == IpAddress);
  30. if (index >= 0 && index < DeviceListViewModel.devices.Count)
  31. {
  32. if (DeviceListViewModel.devices.FirstOrDefault(p => p.DeviceName == DeviceName) != null)
  33. ErrorInfo = "设备名称已存在";
  34. else
  35. {
  36. var res = Global.DeviceRawMaterials.FirstOrDefault(p => p.RawMaterialName == DeviceListViewModel.devices.ElementAt(index).DeviceName);
  37. res.RawMaterialName = DeviceName;
  38. DeviceListViewModel.devices.ElementAt(index).DeviceName = DeviceName;
  39. DeviceInquire.GetInstance.GetDevice(IpAddress).SetDeviceName(DeviceName);//设置PLC名称
  40. for (int i = 0; i < Json<LocaPar>.Data.Recipes.Count; i++)
  41. {
  42. for (int m = 0; m < Json<LocaPar>.Data.Recipes.ElementAt(i).RawMaterials.Count; m++)
  43. {
  44. Json<LocaPar>.Data.Recipes.ElementAt(i).RawMaterials.ElementAt(m).RawMaterialName = DeviceName;
  45. }
  46. }
  47. ActionManage.GetInstance.Send("ChangeDeviceNameViewClose");
  48. }
  49. }
  50. });
  51. }
  52. private static string IpAddress = string.Empty;
  53. public RelayCommand ConfirmCommand { get; set; }
  54. public RelayCommand 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. }