AddRobotViewModel.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using Prism.Commands;
  2. using Prism.Ioc;
  3. using Prism.Mvvm;
  4. using Prism.Services.Dialogs;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Windows;
  9. using TeamAAS_VP.Core;
  10. using TeamAAS_VP.Models;
  11. using TeamAAS_VP.Resources.Languages;
  12. using TouchSocket.Core;
  13. namespace TeamAAS_VP.ViewModels.Setting
  14. {
  15. public class AddRobotViewModel : BindableBase, IDialogAware
  16. {
  17. IContainerProvider _container;
  18. private Management _management;
  19. public Management management
  20. {
  21. get { return _management; }
  22. set { SetProperty(ref _management, value); }
  23. }
  24. private RobotInfo _Robot;
  25. /// <summary>
  26. /// 选中的机器人
  27. /// </summary>
  28. public RobotInfo Robot
  29. {
  30. get { return _Robot; }
  31. set { SetProperty(ref _Robot, value); }
  32. }
  33. private PlcInfo _SelectedPlc;
  34. public PlcInfo SelectedPlc
  35. {
  36. get { return _SelectedPlc; }
  37. set
  38. {
  39. SetProperty(ref _SelectedPlc, value);
  40. if (value != null)
  41. {
  42. Robot.PLC = value.Id;
  43. }
  44. else
  45. {
  46. Robot.PLC = Guid.Empty;
  47. }
  48. }
  49. }
  50. private DelegateCommand _ConfirmCommand;
  51. public DelegateCommand ConfirmCommand =>
  52. _ConfirmCommand ?? (_ConfirmCommand = new DelegateCommand(ExecuteConfirmCommand));
  53. void ExecuteConfirmCommand()
  54. {
  55. if (string.IsNullOrEmpty(Robot.RobotName))
  56. {
  57. return;
  58. }
  59. if (!FileHelper.CheckFileName(Robot.RobotName))
  60. {
  61. MessageBox.Show(Lang.AddCameraVM_message1, "AAS", MessageBoxButton.OK, MessageBoxImage.Error);
  62. return;
  63. }
  64. IDialogParameters parameters = new DialogParameters();
  65. parameters.Add("Robot", Robot);
  66. Tuple<bool, RobotInfo> rest = new Tuple<bool, RobotInfo>(false, Robot);
  67. RequestClose?.Invoke(new DialogResult(ButtonResult.OK, parameters));
  68. }
  69. private DelegateCommand _CancelCommand;
  70. public DelegateCommand CancelCommand =>
  71. _CancelCommand ?? (_CancelCommand = new DelegateCommand(ExecuteCancelCommand));
  72. void ExecuteCancelCommand()
  73. {
  74. IDialogParameters parameters = new DialogParameters();
  75. parameters.Add("Robot", Robot);
  76. Tuple<bool, RobotInfo> rest = new Tuple<bool, RobotInfo>(false, Robot);
  77. RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel, parameters));
  78. }
  79. public AddRobotViewModel(IContainerProvider container)
  80. {
  81. _container = container;
  82. management = _container.Resolve<Management>();
  83. }
  84. public string Title { get; set; } = "添加机器人";
  85. public event Action<IDialogResult> RequestClose;
  86. public bool CanCloseDialog()
  87. {
  88. return true;
  89. }
  90. public void OnDialogClosed()
  91. {
  92. }
  93. public void OnDialogOpened(IDialogParameters parameters)
  94. {
  95. Title = Lang.增加机器人;
  96. Robot = new RobotInfo() { Id = Guid.NewGuid() };
  97. }
  98. }
  99. }