AddPlcViewModel.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using Prism.Commands;
  2. using Prism.Mvvm;
  3. using Prism.Services.Dialogs;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Windows;
  8. using TeamAAS_VP.Core;
  9. using TeamAAS_VP.Interfaces;
  10. using TeamAAS_VP.Models;
  11. using TeamAAS_VP.Resources.Languages;
  12. namespace TeamAAS_VP.ViewModels.Setting
  13. {
  14. public class AddPlcViewModel : BindableBase, IDialogAware
  15. {
  16. private PlcInfo _SelectedPlc;
  17. public PlcInfo SelectedPlc
  18. {
  19. get { return _SelectedPlc; }
  20. set { SetProperty(ref _SelectedPlc, value); }
  21. }
  22. private DelegateCommand _ConfirmCommand;
  23. public DelegateCommand ConfirmCommand =>
  24. _ConfirmCommand ?? (_ConfirmCommand = new DelegateCommand(ExecuteConfirmCommand));
  25. void ExecuteConfirmCommand()
  26. {
  27. if (string.IsNullOrEmpty(SelectedPlc.Name))
  28. {
  29. return;
  30. }
  31. if (!FileHelper.CheckFileName(SelectedPlc.Name))
  32. {
  33. MessageBox.Show(Lang.AddCameraVM_message1, "AAS", MessageBoxButton.OK, MessageBoxImage.Error);
  34. return;
  35. }
  36. IDialogParameters parameters = new DialogParameters();
  37. parameters.Add("PLC", SelectedPlc);
  38. Tuple<bool, PlcInfo> rest = new Tuple<bool, PlcInfo>(false, SelectedPlc);
  39. RequestClose?.Invoke(new DialogResult(ButtonResult.OK, parameters));
  40. }
  41. private DelegateCommand _CancelCommand;
  42. public DelegateCommand CancelCommand =>
  43. _CancelCommand ?? (_CancelCommand = new DelegateCommand(ExecuteCancelCommand));
  44. void ExecuteCancelCommand()
  45. {
  46. IDialogParameters parameters = new DialogParameters();
  47. parameters.Add("PLC", SelectedPlc);
  48. Tuple<bool, PlcInfo> rest = new Tuple<bool, PlcInfo>(false, SelectedPlc);
  49. RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel, parameters));
  50. }
  51. public AddPlcViewModel()
  52. {
  53. }
  54. public string Title { get; set; } = "添加PLC";
  55. public event Action<IDialogResult> RequestClose;
  56. public bool CanCloseDialog()
  57. {
  58. return true;
  59. }
  60. public void OnDialogClosed()
  61. {
  62. }
  63. public void OnDialogOpened(IDialogParameters parameters)
  64. {
  65. Title = Lang.增加PLC;
  66. SelectedPlc = new PlcInfo() { Id = Guid.NewGuid() };
  67. }
  68. }
  69. }