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 => string.Format(Lang.自定义视觉处理逻辑0, 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 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("Script"); var path = parameters.GetValue("Path"); Scripting = script; ScriptingFilePath= path; _oldScript= script; } catch (Exception ex) { LogHelper.WriteLogError(ex.Message, ex); } } void ExecuteSaveScriptCommand() { _oldScript = Scripting; } #endregion } }