SetEncryptionControl.xaml.cs 3.1 KB

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