| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Services.Dialogs;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows;
- using System.Windows.Media.Media3D;
- using TeamAAS_VP.Core;
- using TeamAAS_VP.Interfaces;
- using TeamAAS_VP.Models;
- using TeamAAS_VP;
- using TeamAAS_VP.Resources.Languages;
- namespace TeamAAS_VP.ViewModels.Product
- {
- public class VisionScriptPageViewModel : BindableBase, IDialogAware
- {
- string _oldScript = "";
- #region 属性
- public string Title => $"自定义视觉处理逻辑-{ScriptingFilePath}";
- private string _Scripting;
- public string Scripting
- {
- get { return _Scripting; }
- set { SetProperty(ref _Scripting,value); }
- }
- private string _ScriptingFilePath;
- public string ScriptingFilePath
- {
- get { return _ScriptingFilePath; }
- set { SetProperty(ref _ScriptingFilePath, value); }
- }
- #endregion
- #region 命令
- private DelegateCommand _SaveScriptCommand;
- public DelegateCommand SaveScriptCommand =>
- _SaveScriptCommand ?? (_SaveScriptCommand = new DelegateCommand(ExecuteSaveScriptCommand));
-
- #endregion
- #region 事件
- public event Action<IDialogResult> RequestClose;
- #endregion
- public VisionScriptPageViewModel()
- {
- }
- #region 方法
- public bool CanCloseDialog()
- {
- if (!string.Equals(Scripting, _oldScript))
- {
- var res = MessageBox.Show(Lang.是否保存脚本, Lang.保存脚本, MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
- if (res == MessageBoxResult.Yes)
- {
- FileHelper.WriteFile(Scripting,ScriptingFilePath);
- return true;
- }
- else if (res == MessageBoxResult.No)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- else
- {
- return true;
- }
- }
- public void OnDialogClosed()
- {
- }
- public void OnDialogOpened(IDialogParameters parameters)
- {
- try
- {
- var script = parameters.GetValue<string>("Script");
- var path = parameters.GetValue<string>("Path");
- Scripting = script;
- ScriptingFilePath= path;
- _oldScript= script;
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError(ex.Message, ex);
- }
- }
- void ExecuteSaveScriptCommand()
- {
- _oldScript = Scripting;
- }
- #endregion
- }
- }
|