AddExistedCertificationControl.xaml.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using ComPDFKit.DigitalSign;
  2. using Compdfkit_Tools.Helper;
  3. using System;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. namespace Compdfkit_Tools.PDFControl
  7. {
  8. public partial class AddExistedCertificationControl : UserControl
  9. {
  10. public event EventHandler SaveEvent;
  11. public event EventHandler CancelEvent;
  12. public event EventHandler<CertificateAccess> FillSignatureEvent;
  13. public AddExistedCertificationControl()
  14. {
  15. InitializeComponent();
  16. }
  17. private void CancelBtn_Click(object sender, System.Windows.RoutedEventArgs e)
  18. {
  19. CancelEvent?.Invoke(this, EventArgs.Empty);
  20. }
  21. private void DoneBtn_Click(object sender, System.Windows.RoutedEventArgs e)
  22. {
  23. if (FileNameTxt.Text == string.Empty)
  24. {
  25. ErrorTipsText.Text = "Please select a file.";
  26. return;
  27. }
  28. if (PasswordBoxTxt.Password == string.Empty)
  29. {
  30. ErrorTipsText.Text = "Please input password.";
  31. return;
  32. }
  33. if (!CPDFPKCS12CertHelper.CheckPKCS12Password(FileNameTxt.Text, PasswordBoxTxt.Password))
  34. {
  35. ErrorTipsText.Text = "Password is incorrect.";
  36. return;
  37. }
  38. FillSignatureEvent?.Invoke(sender, new CertificateAccess { filePath = FileNameTxt.Text, password = PasswordBoxTxt.Password });
  39. }
  40. private void SelectFileBtn_Click(object sender, System.Windows.RoutedEventArgs e)
  41. {
  42. string filePath = CommonHelper.GetExistedPathOrEmpty("PFX Files(*.pfx) | *.pfx");
  43. if (filePath != string.Empty)
  44. {
  45. FileNameTxt.Text = filePath;
  46. }
  47. }
  48. }
  49. }