PropertiesDialogViewModel.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. using ComPDFKit.PDFDocument;
  2. using ComPDFKitViewer.PdfViewer;
  3. using PDF_Master.Helper;
  4. using PDF_Master.Model;
  5. using Prism.Mvvm;
  6. using Prism.Services.Dialogs;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Text.RegularExpressions;
  12. using System.Threading.Tasks;
  13. namespace PDF_Master.ViewModels.Dialog
  14. {
  15. public class PropertiesDialogViewModel : BindableBase, IDialogAware
  16. {
  17. public string Title => "";
  18. public event Action<IDialogResult> RequestClose;
  19. private CPDFDocument Document;
  20. private string fileName;
  21. /// <summary>
  22. /// 文件名
  23. /// </summary>
  24. public string FileName
  25. {
  26. get { return fileName; }
  27. set
  28. {
  29. SetProperty(ref fileName, value);
  30. }
  31. }
  32. private string fileSize;
  33. /// <summary>
  34. /// 文件大小
  35. /// </summary>
  36. public string FileSize
  37. {
  38. get { return fileSize; }
  39. set
  40. {
  41. SetProperty(ref fileSize, value);
  42. }
  43. }
  44. private string title;
  45. /// <summary>
  46. /// 文件标题
  47. /// </summary>
  48. public string FileTitle
  49. {
  50. get { return title; }
  51. set
  52. {
  53. SetProperty(ref title, value);
  54. }
  55. }
  56. private string author;
  57. /// <summary>
  58. /// 作者
  59. /// </summary>
  60. public string Author
  61. {
  62. get { return author; }
  63. set
  64. {
  65. SetProperty(ref author, value);
  66. }
  67. }
  68. private string filePath;
  69. /// <summary>
  70. /// 文件路径
  71. /// </summary>
  72. public string FilePath
  73. {
  74. get { return filePath; }
  75. set
  76. {
  77. SetProperty(ref filePath, value);
  78. }
  79. }
  80. private string version;
  81. /// <summary>
  82. /// 版本
  83. /// </summary>
  84. public string Version
  85. {
  86. get { return version; }
  87. set
  88. {
  89. SetProperty(ref version, value);
  90. }
  91. }
  92. private int pageCounr;
  93. /// <summary>
  94. /// 页面大小
  95. /// </summary>
  96. public int PageCount
  97. {
  98. get { return pageCounr; }
  99. set
  100. {
  101. SetProperty(ref pageCounr, value);
  102. }
  103. }
  104. private string creator;
  105. /// <summary>
  106. /// 创建软件名
  107. /// </summary>
  108. public string Creator
  109. {
  110. get { return creator; }
  111. set
  112. {
  113. SetProperty(ref creator, value);
  114. }
  115. }
  116. private string productor;
  117. public string Productor
  118. {
  119. get { return productor; }
  120. set
  121. {
  122. SetProperty(ref productor, value);
  123. }
  124. }
  125. private string createDate;
  126. /// <summary>
  127. /// 创建日期
  128. /// </summary>
  129. public string CreateDate
  130. {
  131. get { return createDate; }
  132. set
  133. {
  134. SetProperty(ref createDate, value);
  135. }
  136. }
  137. private string modifyDate;
  138. /// <summary>
  139. /// 编辑日期
  140. /// </summary>
  141. public string ModifyDate
  142. {
  143. get { return modifyDate; }
  144. set
  145. {
  146. SetProperty(ref modifyDate, value);
  147. }
  148. }
  149. private string isEncrypted;
  150. /// <summary>
  151. /// 是否加密
  152. /// </summary>
  153. public string IsEncrypted
  154. {
  155. get { return isEncrypted; }
  156. set
  157. {
  158. SetProperty(ref isEncrypted, value);
  159. }
  160. }
  161. private string isUnlocked;
  162. /// <summary>
  163. /// 是否加锁
  164. /// </summary>
  165. public string IsUnlocked
  166. {
  167. get { return isUnlocked; }
  168. set
  169. {
  170. SetProperty(ref isUnlocked, value);
  171. }
  172. }
  173. private string allowCopy;
  174. /// <summary>
  175. /// 允许复制
  176. /// </summary>
  177. public string AllowCopy
  178. {
  179. get { return allowCopy; }
  180. set
  181. {
  182. SetProperty(ref allowCopy, value);
  183. }
  184. }
  185. private string allowPrint;
  186. /// <summary>
  187. /// 允许打印
  188. /// </summary>
  189. public string AllowPrint
  190. {
  191. get { return allowPrint; }
  192. set
  193. {
  194. SetProperty(ref allowPrint, value);
  195. }
  196. }
  197. public PropertiesDialogViewModel()
  198. {
  199. }
  200. public bool CanCloseDialog()
  201. {
  202. return true;
  203. }
  204. public void OnDialogClosed()
  205. {
  206. RequestClose.Invoke(new DialogResult());
  207. }
  208. public void OnDialogOpened(IDialogParameters parameters)
  209. {
  210. Document = parameters.GetValue<CPDFDocument>(ParameterNames.PDFDocument);
  211. var info = Document.GetInfo();
  212. FileName = Document.FileName;
  213. FileSize = CommonHelper.GetFileSize(Document.FilePath);
  214. FileTitle = info.Title;
  215. Author = info.Author;
  216. if ((App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).NewFile)
  217. {
  218. //新建文档不显示临时路径
  219. FilePath = "";
  220. }
  221. else
  222. {
  223. FilePath = Document.FilePath;
  224. }
  225. Version = info.Version;
  226. PageCount = Document.PageCount;
  227. Creator = info.Creator;
  228. Productor = info.Producer;
  229. CreateDate = CommonHelper.GetDate(info.CreationDate);
  230. ModifyDate = CommonHelper.GetDate(info.ModificationDate);
  231. string yes = "Yes";
  232. string no = "No";
  233. IsEncrypted = Document.IsEncrypted ? yes : no;
  234. IsUnlocked = Document.IsLocked ? no : yes;
  235. var permissions = Document.GetPermissionsInfo();
  236. AllowCopy = permissions.AllowsCopying? yes : no;
  237. AllowPrint = permissions.AllowsPrinting ? yes : no;
  238. }
  239. }
  240. }