MainForm.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using Aspose.Note;
  2. using Aspose.Note.Saving;
  3. using OneNote2PDF.Utils;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading;
  13. using System.Threading.Tasks;
  14. using System.Windows.Forms;
  15. namespace OneNote2PDF
  16. {
  17. public partial class MainForm : Form
  18. {
  19. App app;
  20. public MainForm()
  21. {
  22. InitializeComponent();
  23. }
  24. private void btnConvert_Click(object sender, EventArgs e)
  25. {
  26. // 判断输入 OneNote 笔记目录是否正确
  27. if (app.inputDir!=null || app.inputDir!="")
  28. {
  29. lbConvertResult.Text = "正在转换中,请稍耐心等待...";
  30. foreach (DirectoryInfo subDirInfo in (new DirectoryInfo(app.inputDir)).GetDirectories())
  31. {
  32. string subDir = Path.Combine(app.outputDir, subDirInfo.Name); //输出目录
  33. if (!Directory.Exists(subDir))
  34. {
  35. Directory.CreateDirectory(subDir);
  36. }
  37. foreach (FileInfo file in subDirInfo.GetFiles())
  38. {
  39. //只有后缀为one的文件才处理
  40. if (file.Name.Substring(file.Name.Length - 3, 3) == "one")
  41. {
  42. // 异步执行
  43. ThreadStart starter = delegate {
  44. OneNoteUtils.One2PDF(file.FullName, Path.Combine(app.outputDir, subDirInfo.Name, file.Name.Substring(0, file.Name.Length - 4) + ".pdf"));
  45. };
  46. new Thread(starter).Start();
  47. }
  48. return;
  49. }
  50. lbConvertResult.Text = "全部转换成功";
  51. }
  52. }
  53. else
  54. {
  55. MessageBox.Show("请先选择正确的 OneNote 笔记目录再执行转换。");
  56. }
  57. }
  58. private void button1_Click(object sender, EventArgs e)
  59. {
  60. folderBrowserDialog1.Description = "请选择文件夹";
  61. if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  62. {
  63. if (string.IsNullOrEmpty(folderBrowserDialog1.SelectedPath))
  64. {
  65. MessageBox.Show(this, "文件夹路径不能为空", "提示");
  66. return;
  67. }
  68. else
  69. {
  70. app.inputDir = folderBrowserDialog1.SelectedPath;
  71. tbInputDir.Text = app.inputDir;
  72. }
  73. }
  74. }
  75. private void MainForm_Load(object sender, EventArgs e)
  76. {
  77. app = App.getInstance();//初始化app对象
  78. tbOutputDir.Text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),"Output");
  79. app.outputDir = tbOutputDir.Text;
  80. }
  81. }
  82. }