VisionScriptPageViewModel.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using Prism.Commands;
  2. using Prism.Mvvm;
  3. using Prism.Services.Dialogs;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Windows;
  8. using System.Windows.Media.Media3D;
  9. using TeamAAS_VP.Core;
  10. using TeamAAS_VP.Interfaces;
  11. using TeamAAS_VP.Models;
  12. using TeamAAS_VP;
  13. using TeamAAS_VP.Resources.Languages;
  14. namespace TeamAAS_VP.ViewModels.Product
  15. {
  16. public class VisionScriptPageViewModel : BindableBase, IDialogAware
  17. {
  18. string _oldScript = "";
  19. #region 属性
  20. public string Title => $"自定义视觉处理逻辑-{ScriptingFilePath}";
  21. private string _Scripting;
  22. public string Scripting
  23. {
  24. get { return _Scripting; }
  25. set { SetProperty(ref _Scripting,value); }
  26. }
  27. private string _ScriptingFilePath;
  28. public string ScriptingFilePath
  29. {
  30. get { return _ScriptingFilePath; }
  31. set { SetProperty(ref _ScriptingFilePath, value); }
  32. }
  33. #endregion
  34. #region 命令
  35. private DelegateCommand _SaveScriptCommand;
  36. public DelegateCommand SaveScriptCommand =>
  37. _SaveScriptCommand ?? (_SaveScriptCommand = new DelegateCommand(ExecuteSaveScriptCommand));
  38. #endregion
  39. #region 事件
  40. public event Action<IDialogResult> RequestClose;
  41. #endregion
  42. public VisionScriptPageViewModel()
  43. {
  44. }
  45. #region 方法
  46. public bool CanCloseDialog()
  47. {
  48. if (!string.Equals(Scripting, _oldScript))
  49. {
  50. var res = MessageBox.Show(Lang.是否保存脚本, Lang.保存脚本, MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
  51. if (res == MessageBoxResult.Yes)
  52. {
  53. FileHelper.WriteFile(Scripting,ScriptingFilePath);
  54. return true;
  55. }
  56. else if (res == MessageBoxResult.No)
  57. {
  58. return true;
  59. }
  60. else
  61. {
  62. return false;
  63. }
  64. }
  65. else
  66. {
  67. return true;
  68. }
  69. }
  70. public void OnDialogClosed()
  71. {
  72. }
  73. public void OnDialogOpened(IDialogParameters parameters)
  74. {
  75. try
  76. {
  77. var script = parameters.GetValue<string>("Script");
  78. var path = parameters.GetValue<string>("Path");
  79. Scripting = script;
  80. ScriptingFilePath= path;
  81. _oldScript= script;
  82. }
  83. catch (Exception ex)
  84. {
  85. LogHelper.WriteLogError(ex.Message, ex);
  86. }
  87. }
  88. void ExecuteSaveScriptCommand()
  89. {
  90. _oldScript = Scripting;
  91. }
  92. #endregion
  93. }
  94. }