using Prism.Commands;
using Prism.Ioc;
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.Models;
using TeamAAS_VP.Resources.Languages;
using TouchSocket.Core;
namespace TeamAAS_VP.ViewModels.Setting
{
public class AddRobotViewModel : BindableBase, IDialogAware
{
IContainerProvider _container;
private Management _management;
public Management management
{
get { return _management; }
set { SetProperty(ref _management, value); }
}
private RobotInfo _Robot;
///
/// 选中的机器人
///
public RobotInfo Robot
{
get { return _Robot; }
set { SetProperty(ref _Robot, value); }
}
private PlcInfo _SelectedPlc;
public PlcInfo SelectedPlc
{
get { return _SelectedPlc; }
set
{
SetProperty(ref _SelectedPlc, value);
if (value != null)
{
Robot.PLC = value.Id;
}
else
{
Robot.PLC = Guid.Empty;
}
}
}
private DelegateCommand _ConfirmCommand;
public DelegateCommand ConfirmCommand =>
_ConfirmCommand ?? (_ConfirmCommand = new DelegateCommand(ExecuteConfirmCommand));
void ExecuteConfirmCommand()
{
if (string.IsNullOrEmpty(Robot.RobotName))
{
return;
}
if (!FileHelper.CheckFileName(Robot.RobotName))
{
MessageBox.Show(Lang.AddCameraVM_message1, "AAS", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
IDialogParameters parameters = new DialogParameters();
parameters.Add("Robot", Robot);
Tuple rest = new Tuple(false, Robot);
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("Robot", Robot);
Tuple rest = new Tuple(false, Robot);
RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel, parameters));
}
public AddRobotViewModel(IContainerProvider container)
{
_container = container;
management = _container.Resolve();
}
public string Title { get; set; } = "添加机器人";
public event Action RequestClose;
public bool CanCloseDialog()
{
return true;
}
public void OnDialogClosed()
{
}
public void OnDialogOpened(IDialogParameters parameters)
{
Title = Lang.增加机器人;
Robot = new RobotInfo() { Id = Guid.NewGuid() };
}
}
}