AddScannerViewModel.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using TeamAAS_VP.Core;
  11. using TeamAAS_VP.Interfaces;
  12. using TeamAAS_VP.Models;
  13. using TeamAAS_VP.Models.Scanner;
  14. namespace TeamAAS_VP.ViewModels.Setting
  15. {
  16. public class AddScannerViewModel : BindableBase, IDialogAware
  17. {
  18. private readonly IConfigService _configService;
  19. private ScannerInfo _Scanner;
  20. /// <summary>
  21. /// 扫码枪
  22. /// </summary>
  23. public ScannerInfo Scanner
  24. {
  25. get { return _Scanner ; }
  26. set
  27. {
  28. SetProperty(ref _Scanner, value);
  29. }
  30. }
  31. private DelegateCommand _ConfirmCommand;
  32. public DelegateCommand ConfirmCommand =>
  33. _ConfirmCommand ?? (_ConfirmCommand = new DelegateCommand(ExecuteConfirmCommand));
  34. void ExecuteConfirmCommand()
  35. {
  36. if (string.IsNullOrEmpty(Scanner.ScannerName))
  37. {
  38. return;
  39. }
  40. if (!FileHelper.CheckFileName(Scanner.ScannerName))
  41. {
  42. string lbuffer1 = System.Windows.Application.Current.Resources["CalibrationHomeViewModel.Info2"] as string;
  43. MessageBox.Show($"{lbuffer1}");
  44. return;
  45. }
  46. IDialogParameters parameters = new DialogParameters();
  47. parameters.Add("Scanner", Scanner);
  48. Tuple<bool, ScannerInfo> rest = new Tuple<bool, ScannerInfo>(false, Scanner);
  49. RequestClose?.Invoke(new DialogResult(ButtonResult.OK, parameters));
  50. }
  51. private DelegateCommand _CancelCommand;
  52. public DelegateCommand CancelCommand =>
  53. _CancelCommand ?? (_CancelCommand = new DelegateCommand(ExecuteCancelCommand));
  54. void ExecuteCancelCommand()
  55. {
  56. IDialogParameters parameters = new DialogParameters();
  57. parameters.Add("Scanner", Scanner);
  58. Tuple<bool, ScannerInfo> rest = new Tuple<bool, ScannerInfo>(false, Scanner);
  59. RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel, parameters));
  60. }
  61. public AddScannerViewModel()
  62. {
  63. }
  64. public string Title { get; set; } = "添加扫码枪";
  65. public event Action<IDialogResult> RequestClose;
  66. public bool CanCloseDialog()
  67. {
  68. return true;
  69. }
  70. public void OnDialogClosed()
  71. {
  72. }
  73. public void OnDialogOpened(IDialogParameters parameters)
  74. {
  75. Title = System.Windows.Application.Current.Resources["AddRobotViewModel.Info1"] as string;
  76. Scanner = new ScannerInfo() { Id = Guid.NewGuid() };
  77. }
  78. }
  79. }