| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- using Prism.Commands;
- using Prism.Ioc;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows.Media;
- using Team.FFFeederService;
- using Team.FFFeederService.Interfaces;
- using TeamAAS_VP.Controls;
- using TeamAAS_VP.Core;
- using TeamAAS_VP.Interfaces;
- namespace TeamAAS_VP.ViewModels.DebugMod
- {
- public class VisionSolutionViewModel : BindableBase, IConfirmNavigationRequest
- {
- IContainerProvider _container;
- ISystemDatabaseService _systemDatabaseService;
- private ImageSource _CurrentImage;
- public ImageSource CurrentImage
- {
- get { return _CurrentImage; }
- set { SetProperty(ref _CurrentImage, value); }
- }
- private FocusAnalyzerViewModel _FocusAnalyzerViewModel;
- public FocusAnalyzerViewModel FocusAnalyzerViewModel
- {
- get { return _FocusAnalyzerViewModel; }
- set { SetProperty(ref _FocusAnalyzerViewModel, value); }
- }
- //选择图片
- private DelegateCommand _SelectImageCommand;
- public DelegateCommand SelectImageCommand =>
- _SelectImageCommand ?? (_SelectImageCommand = new DelegateCommand(ExecuteSelectImageCommand));
-
- private DelegateCommand _LoadedCommand;
- public DelegateCommand LoadedCommand =>
- _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
- public VisionSolutionViewModel(IContainerProvider container, ISystemDatabaseService systemDatabaseService)
- {
- _container = container;
- _systemDatabaseService = systemDatabaseService;
- }
- void ExecuteLoadedCommand()
- {
- try
- {
- if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
- {
- IsAllowEdit = false;
- }
- else
- {
- IsAllowEdit = true;
- }
- }
- catch (Exception)
- {
- }
- }
- /// <summary>
- /// 选择一张图像
- /// </summary>
- void ExecuteSelectImageCommand()
- {
- //打开文件对话框,选择一张图片
- Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();
- openFileDialog.Filter = "Image files (*.png;*.jpg;*.jpeg;*.bmp)|*.png;*.jpg;*.jpeg;*.bmp|All files (*.*)|*.*";
- openFileDialog.Multiselect = true;
- bool? result = openFileDialog.ShowDialog();
- if (result.HasValue)
- {
- if (openFileDialog.FileNames.Length > 0)
- {
- //加载第一张图片
- string filePath = openFileDialog.FileNames[0];
- try
- {
- System.Windows.Media.Imaging.BitmapImage bitmap = new System.Windows.Media.Imaging.BitmapImage();
- bitmap.BeginInit();
- bitmap.UriSource = new Uri(filePath, UriKind.Absolute);
- bitmap.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
- bitmap.EndInit();
- FocusAnalyzerViewModel.CurrentImage = bitmap;
- }
- catch (Exception ex)
- {
- //显示错误信息
- System.Windows.MessageBox.Show("加载图片失败:" + ex.Message);
- }
- }
- }
- }
- #region 继承
- /// <summary>
- /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
- /// </summary>
- /// <param name="navigationContext"></param>
- /// <param name="continuationCallback"></param>
- public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
- {
- continuationCallback(true);
- }
- /// <summary>
- /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
- /// </summary>
- /// <param name="navigationContext"></param>
- /// <exception cref="NotImplementedException"></exception>
- public async void OnNavigatedTo(NavigationContext navigationContext)
- {
- if (FocusAnalyzerViewModel==null)
- {
- FocusAnalyzerViewModel = new FocusAnalyzerViewModel();
- }
- }
- /// <summary>
- /// 是否允许导航到此视图模型。
- /// </summary>
- /// <param name="navigationContext"></param>
- /// <returns></returns>
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- /// <summary>
- /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
- /// </summary>
- /// <param name="navigationContext"></param>
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- }
- #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;
- }
- }
- }
- }
|