using Prism.Commands; using Prism.Mvvm; using Prism.Services.Dialogs; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using TeamAAS_VP.Core; using TeamAAS_VP.Interfaces; using TeamAAS_VP.Models; using TeamAAS_VP.Models.Scanner; namespace TeamAAS_VP.ViewModels.Setting { public class AddScannerViewModel : BindableBase, IDialogAware { private readonly IConfigService _configService; private ScannerInfo _Scanner; /// /// 扫码枪 /// public ScannerInfo Scanner { get { return _Scanner ; } set { SetProperty(ref _Scanner, value); } } private DelegateCommand _ConfirmCommand; public DelegateCommand ConfirmCommand => _ConfirmCommand ?? (_ConfirmCommand = new DelegateCommand(ExecuteConfirmCommand)); void ExecuteConfirmCommand() { if (string.IsNullOrEmpty(Scanner.ScannerName)) { return; } if (!FileHelper.CheckFileName(Scanner.ScannerName)) { string lbuffer1 = System.Windows.Application.Current.Resources["CalibrationHomeViewModel.Info2"] as string; MessageBox.Show($"{lbuffer1}"); return; } IDialogParameters parameters = new DialogParameters(); parameters.Add("Scanner", Scanner); Tuple rest = new Tuple(false, Scanner); RequestClose?.Invoke(new DialogResult(ButtonResult.OK, parameters)); } private DelegateCommand _CancelCommand; public DelegateCommand CancelCommand => _CancelCommand ?? (_CancelCommand = new DelegateCommand(ExecuteCancelCommand)); void ExecuteCancelCommand() { IDialogParameters parameters = new DialogParameters(); parameters.Add("Scanner", Scanner); Tuple rest = new Tuple(false, Scanner); RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel, parameters)); } public AddScannerViewModel() { } public string Title { get; set; } = "添加扫码枪"; public event Action RequestClose; public bool CanCloseDialog() { return true; } public void OnDialogClosed() { } public void OnDialogOpened(IDialogParameters parameters) { Title = System.Windows.Application.Current.Resources["AddRobotViewModel.Info1"] as string; Scanner = new ScannerInfo() { Id = Guid.NewGuid() }; } } }