SetEncryptionControl.xaml.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System.Collections.Generic;
  2. using System.ComponentModel;
  3. using System.Runtime.CompilerServices;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. namespace Compdfkit_Tools.PDFControl
  7. {
  8. public partial class SetEncryptionControl : UserControl, INotifyPropertyChanged
  9. {
  10. private bool _isUserPasswordEnabled;
  11. public bool IsUserPasswordEnabled
  12. {
  13. get => _isUserPasswordEnabled;
  14. set
  15. {
  16. _isUserPasswordEnabled = value;
  17. OnPropertyChanged();
  18. UpdateValidation();
  19. }
  20. }
  21. private bool _isOwnerPasswordEnabled;
  22. public bool IsOwnerPasswordEnabled
  23. {
  24. get => _isOwnerPasswordEnabled;
  25. set
  26. {
  27. _isOwnerPasswordEnabled = value;
  28. OnPropertyChanged();
  29. UpdateValidation();
  30. }
  31. }
  32. private string _userPassword;
  33. public string UserPassword
  34. {
  35. get => _userPassword;
  36. set
  37. {
  38. _userPassword = value;
  39. OnPropertyChanged();
  40. UpdateValidation();
  41. }
  42. }
  43. private string _ownerPassword;
  44. public string OwnerPassword
  45. {
  46. get => _ownerPassword;
  47. set
  48. {
  49. _ownerPassword = value;
  50. OnPropertyChanged();
  51. UpdateValidation();
  52. }
  53. }
  54. private bool _isAllowPrint = true;
  55. public bool IsAllowPrint
  56. {
  57. get => _isAllowPrint;
  58. set
  59. {
  60. _isAllowPrint = value;
  61. OnPropertyChanged();
  62. }
  63. }
  64. private bool _isAllowCopy = true;
  65. public bool IsAllowCopy
  66. {
  67. get => _isAllowCopy;
  68. set
  69. {
  70. _isAllowCopy = value;
  71. OnPropertyChanged();
  72. }
  73. }
  74. private int _cryptographicLevel;
  75. public int CryptographicLevel
  76. {
  77. get => _cryptographicLevel;
  78. set
  79. {
  80. _cryptographicLevel = value;
  81. OnPropertyChanged();
  82. }
  83. }
  84. public static readonly DependencyProperty IsEnsureProperty =
  85. DependencyProperty.Register(nameof(IsSettingValid), typeof(bool), typeof(SetEncryptionControl), new PropertyMetadata(false));
  86. public bool IsSettingValid
  87. {
  88. get => (bool)GetValue(IsEnsureProperty);
  89. private set => SetValue(IsEnsureProperty, value);
  90. }
  91. public event PropertyChangedEventHandler PropertyChanged;
  92. public SetEncryptionControl()
  93. {
  94. InitializeComponent();
  95. DataContext = this;
  96. }
  97. private void UpdateValidation()
  98. {
  99. if (!IsOwnerPasswordEnabled && !IsUserPasswordEnabled)
  100. {
  101. IsSettingValid = false;
  102. return;
  103. }
  104. bool validUserOption = !IsUserPasswordEnabled || !string.IsNullOrEmpty(UserPassword);
  105. bool validOwnerOption = !IsOwnerPasswordEnabled || !string.IsNullOrEmpty(OwnerPassword);
  106. IsSettingValid = validUserOption && validOwnerOption;
  107. }
  108. protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
  109. {
  110. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  111. }
  112. }
  113. }