using Prism.Commands; using Prism.Events; using Prism.Ioc; using Prism.Mvvm; using Prism.Regions; 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; namespace TeamAAS_VP.ViewModels.Calibration { public class CalibrationResultViewModel : BindableBase { IRegionManager _regionManager; IRegionNavigationService _regionNavigationService; IContainerProvider _container; IDialogService _dialogService; IEventAggregator _eventAggregator; #region 属性 private CalibrationInfo _SelectCalibration; public CalibrationInfo SelectCalibration { get { return _SelectCalibration; } set { SetProperty(ref _SelectCalibration, value); } } private CalibrationResult _Result; public CalibrationResult Result { get { return _Result; } set { SetProperty(ref _Result, value); } } private CalibrationTestResult _TestResult; public CalibrationTestResult TestResult { get { return _TestResult; } set { SetProperty(ref _TestResult, value); } } #endregion #region 命令 private DelegateCommand _LoadedCommand; public DelegateCommand LoadedCommand => _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand)); private DelegateCommand _NextCommand; public DelegateCommand NextCommand => _NextCommand ?? (_NextCommand = new DelegateCommand(ExecuteNextCommand)); private DelegateCommand _BackCommand; public DelegateCommand BackCommand => _BackCommand ?? (_BackCommand = new DelegateCommand(ExecuteBackCommand)); #endregion #region 事件 #endregion public CalibrationResultViewModel(IRegionManager regionManager, IEventAggregator ea, IRegionNavigationService regionNavigationService, IContainerProvider container, IDialogService dialogService) { _regionManager = regionManager; _regionNavigationService = regionNavigationService; _container = container; _dialogService = dialogService; _eventAggregator = ea; SelectCalibration = _container.Resolve().SelectCalibration; _container.Resolve().PropertyChanged += CalibrationEditVisionViewModel_PropertyChanged; } #region 方法 void ExecuteLoadedCommand() { if (_container.Resolve().CurrentUser.userPart == Enums.UserPart.Operator) { IsAllowEdit = false; } else { IsAllowEdit = true; } try { SelectCalibration = _container.Resolve().SelectCalibration; Result = SelectCalibration.CalibrationResult; TestResult = SelectCalibration.CalibrationTestResult; } catch (Exception ex) { LogHelper.WriteLogError("相机校准-校准结果界面加载时出错!", ex); MessageBox.Show(ex.Message); } } /// /// 下一步 /// void ExecuteNextCommand() { _container.Resolve().SaveCalibration(SelectCalibration); _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationHome"); } /// /// 上一步 /// void ExecuteBackCommand() { _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationVerification"); } private void CalibrationEditVisionViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { //if (e.PropertyName == "SelectCalibration") //{ // SelectCalibration = _container.Resolve().SelectCalibration; //} } #endregion private bool _IsAllowEdit = false; public bool IsAllowEdit { get { return _IsAllowEdit; } set { SetProperty(ref _IsAllowEdit, value); } } private void LoginChange(Models.User user) { if (user.userPart == Enums.UserPart.Operator) { IsAllowEdit = false; } else { IsAllowEdit = true; } } } }