using Prism.Commands; using Prism.Mvvm; using Prism.Services.Dialogs; using System; using System.Collections.Generic; using System.Linq; using System.Windows; using TeamAAS_VP.Core; using TeamAAS_VP.Interfaces; using TeamAAS_VP.Models; using TeamAAS_VP.Resources.Languages; namespace TeamAAS_VP.ViewModels.Setting { public class AddPlcViewModel : BindableBase, IDialogAware { private PlcInfo _SelectedPlc; public PlcInfo SelectedPlc { get { return _SelectedPlc; } set { SetProperty(ref _SelectedPlc, value); } } private DelegateCommand _ConfirmCommand; public DelegateCommand ConfirmCommand => _ConfirmCommand ?? (_ConfirmCommand = new DelegateCommand(ExecuteConfirmCommand)); void ExecuteConfirmCommand() { if (string.IsNullOrEmpty(SelectedPlc.Name)) { return; } if (!FileHelper.CheckFileName(SelectedPlc.Name)) { MessageBox.Show(Lang.AddCameraVM_message1, "AAS", MessageBoxButton.OK, MessageBoxImage.Error); return; } IDialogParameters parameters = new DialogParameters(); parameters.Add("PLC", SelectedPlc); Tuple rest = new Tuple(false, SelectedPlc); 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("PLC", SelectedPlc); Tuple rest = new Tuple(false, SelectedPlc); RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel, parameters)); } public AddPlcViewModel() { } public string Title { get; set; } = Lang.添加PLC; public event Action RequestClose; public bool CanCloseDialog() { return true; } public void OnDialogClosed() { } public void OnDialogOpened(IDialogParameters parameters) { Title = Lang.增加PLC; SelectedPlc = new PlcInfo() { Id = Guid.NewGuid() }; } } }