HomePageSplitDialogModel.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. using PDF_Master.CustomControl;
  2. using Prism.Mvvm;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Text.RegularExpressions;
  8. using System.Threading.Tasks;
  9. namespace PDF_Master.Model.HomePageToolsDialogs
  10. {
  11. public class HomePageSplitDialogModel : BindableBase
  12. {
  13. /// <summary>
  14. /// 拆分模式
  15. /// </summary>
  16. public SplitMode Mode = SplitMode.AveragePages;
  17. /// <summary>
  18. /// 页面范围形式
  19. /// </summary>
  20. public PageRangeMode PageMode = PageRangeMode.OddPage;
  21. /// <summary>
  22. /// 拆分模式份数或者页数
  23. /// </summary>
  24. public int GetModeCount = 1;
  25. /// <summary>
  26. /// 页面信息
  27. /// </summary>
  28. public string PageRange = "";
  29. private int pageSelectedIndex = 1;
  30. public int PageSelectedIndex
  31. {
  32. get { return pageSelectedIndex; }
  33. set
  34. {
  35. SetProperty(ref pageSelectedIndex, value);
  36. switch (value)
  37. {
  38. case 1:
  39. PageMode = PageRangeMode.OddPage;
  40. break;
  41. case 2:
  42. PageMode = PageRangeMode.EvenPage;
  43. break;
  44. case 3:
  45. PageMode = PageRangeMode.CustomPage;
  46. break;
  47. default:
  48. break;
  49. }
  50. }
  51. }
  52. private double pageNum = 1;
  53. /// <summary>
  54. /// 平均页数
  55. /// </summary>
  56. public double PageNum
  57. {
  58. get { return pageNum; }
  59. set
  60. {
  61. SetProperty(ref pageNum, value);
  62. GetModeCount = (int)value;
  63. }
  64. }
  65. private double filesCount = 1;
  66. /// <summary>
  67. /// 平均文件数
  68. /// </summary>
  69. public double FilesCount
  70. {
  71. get { return filesCount; }
  72. set
  73. {
  74. SetProperty(ref filesCount, value);
  75. GetModeCount = (int)value;
  76. }
  77. }
  78. private bool isAveragePages = true;
  79. /// <summary>
  80. /// 平均按页拆分 是否选中
  81. /// </summary>
  82. public bool IsAveragePages
  83. {
  84. get { return isAveragePages; }
  85. set
  86. {
  87. SetProperty(ref isAveragePages, value);
  88. if (value)
  89. {
  90. Mode = SplitMode.AveragePages;
  91. }
  92. }
  93. }
  94. private bool isAveragePDF = false;
  95. /// <summary>
  96. /// 平均按PDF拆分 是否选中
  97. /// </summary>
  98. public bool IsAveragePDF
  99. {
  100. get { return isAveragePDF; }
  101. set
  102. {
  103. SetProperty(ref isAveragePDF, value);
  104. if (value)
  105. {
  106. Mode = SplitMode.AverageFiles;
  107. }
  108. }
  109. }
  110. private bool isCustomRange = false;
  111. /// <summary>
  112. /// 自定义页面范围,是否选中
  113. /// </summary>
  114. public bool IsCustomRange
  115. {
  116. get { return isCustomRange; }
  117. set
  118. {
  119. SetProperty(ref isCustomRange, value);
  120. if (value)
  121. {
  122. Mode = SplitMode.CustomPageRange;
  123. }
  124. else
  125. {
  126. PageSelectedIndex = 1;
  127. }
  128. }
  129. }
  130. private string customPageText;
  131. /// <summary>
  132. /// 自定义的输入内容
  133. /// </summary>
  134. public string CustomPageText
  135. {
  136. get { return customPageText; }
  137. set
  138. {
  139. SetProperty(ref customPageText, value);
  140. }
  141. }
  142. /// <summary>
  143. /// 文件名标签
  144. /// </summary>
  145. private string fileNameLabel = "part";
  146. public string FileNameLabel
  147. {
  148. get { return fileNameLabel; }
  149. set
  150. {
  151. SetProperty(ref fileNameLabel, value);
  152. RefreshFileName();
  153. }
  154. }
  155. private bool hasLabel = true;
  156. /// <summary>
  157. /// 是否含有标签
  158. /// </summary>
  159. public bool HasLabel
  160. {
  161. get { return hasLabel; }
  162. set
  163. {
  164. SetProperty(ref hasLabel, value);
  165. RefreshFileName();
  166. }
  167. }
  168. /// <summary>
  169. /// 文件名与标签分隔符
  170. /// </summary>
  171. private string fileNameDeimiter = "-";
  172. public string FileNameDeimiter
  173. {
  174. get { return fileNameDeimiter; }
  175. set
  176. {
  177. SetProperty(ref fileNameDeimiter, value);
  178. // 拆分 分割符 特殊字符判断
  179. if (string.IsNullOrEmpty(fileNameDeimiter) == false)
  180. {
  181. string pattern = @"[\\\/:*?""<>|.]"; // 定义不允许出现的字符的正则表达式模式
  182. Regex regex = new Regex(pattern);
  183. //if (regex.IsMatch(fileName))
  184. //{
  185. char[] invalidChars = { '\\', '/', ':', '*', '?', '"', '<', '>', '|', '.' };
  186. //英文
  187. if (fileNameDeimiter.IndexOfAny(invalidChars) != -1)
  188. {
  189. fileNameDeimiter = string.Empty;
  190. Console.WriteLine("文件名包含不允许的字符");
  191. // 进行报错处理的代码逻辑
  192. AlertsMessage alertsMessage = new AlertsMessage();
  193. string illegalChars = @"\ /<>:|""?*";
  194. alertsMessage.ShowDialog($"{App.MainPageLoader.GetString("PageEdite_SplitErroTitle")}", $"{App.MainPageLoader.GetString("PageEdite_SplitErroContent")}{illegalChars}", App.ServiceLoader.GetString("Text_ok"), IconType.Tip);
  195. }
  196. }
  197. RefreshFileName();
  198. }
  199. }
  200. private bool hasDeimiter = true;
  201. /// <summary>
  202. /// 是否含有分隔符
  203. /// </summary>
  204. public bool HasDeimiter
  205. {
  206. get { return hasDeimiter; }
  207. set
  208. {
  209. SetProperty(ref hasDeimiter, value);
  210. RefreshFileName();
  211. }
  212. }
  213. /// <summary>
  214. /// 文件名与标签分隔符
  215. /// </summary>
  216. public bool FrontFileName = true;
  217. /// <summary>
  218. /// 页码 存入页码范围;
  219. /// </summary>
  220. public List<int> PageParm = new List<int> { };
  221. /// <summary>
  222. /// 文件名;
  223. /// </summary>
  224. private string fileName = "";
  225. public string FileName
  226. {
  227. get { return fileName; }
  228. set
  229. {
  230. SetProperty(ref fileName, value);
  231. }
  232. }
  233. private bool isSourceNameFront = true;
  234. /// <summary>
  235. /// 原始文档名前置
  236. /// </summary>
  237. public bool IsSourceNameFront
  238. {
  239. get { return isSourceNameFront; }
  240. set
  241. {
  242. SetProperty(ref isSourceNameFront, value);
  243. RefreshFileName();
  244. }
  245. }
  246. private string sourceName;
  247. /// <summary>
  248. /// 原始文件名
  249. /// </summary>
  250. public string SourceFileName
  251. {
  252. get { return sourceName; }
  253. set
  254. {
  255. SetProperty(ref sourceName, value);
  256. RefreshFileName();
  257. }
  258. }
  259. /// <summary>
  260. /// 刷新文件名
  261. /// </summary>
  262. public void RefreshFileName()
  263. {
  264. string label = HasLabel ? FileNameLabel : "";
  265. string deimiter = HasDeimiter ? FileNameDeimiter : "";
  266. if (isSourceNameFront)
  267. {
  268. FileName = SourceFileName + deimiter + label + "1" + ".pdf";
  269. }
  270. else
  271. {
  272. FileName = label + "1" + deimiter + SourceFileName + ".pdf";
  273. }
  274. }
  275. public enum SplitMode
  276. {
  277. /// <summary>
  278. /// 按页平均拆分
  279. /// </summary>
  280. AveragePages,
  281. /// <summary>
  282. /// 按文件平均拆分
  283. /// </summary>
  284. AverageFiles,
  285. /// <summary>
  286. /// 自定义页码范围拆分
  287. /// </summary>
  288. CustomPageRange
  289. }
  290. public enum PageRangeMode
  291. {
  292. /// <summary>
  293. /// 奇数页
  294. /// </summary>
  295. OddPage,
  296. /// <summary>
  297. /// 偶数页
  298. /// </summary>
  299. EvenPage,
  300. /// <summary>
  301. /// 自定义页面范围
  302. /// </summary>
  303. CustomPage
  304. }
  305. }
  306. }