123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 |
- using PDF_Master.CustomControl;
- using Prism.Mvvm;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace PDF_Master.Model.HomePageToolsDialogs
- {
- public class HomePageSplitDialogModel : BindableBase
- {
- /// <summary>
- /// 拆分模式
- /// </summary>
- public SplitMode Mode = SplitMode.AveragePages;
- /// <summary>
- /// 页面范围形式
- /// </summary>
- public PageRangeMode PageMode = PageRangeMode.OddPage;
- /// <summary>
- /// 拆分模式份数或者页数
- /// </summary>
- public int GetModeCount = 1;
- /// <summary>
- /// 页面信息
- /// </summary>
- public string PageRange = "";
- private int pageSelectedIndex = 1;
- public int PageSelectedIndex
- {
- get { return pageSelectedIndex; }
- set
- {
- SetProperty(ref pageSelectedIndex, value);
- switch (value)
- {
- case 1:
- PageMode = PageRangeMode.OddPage;
- break;
- case 2:
- PageMode = PageRangeMode.EvenPage;
- break;
- case 3:
- PageMode = PageRangeMode.CustomPage;
- break;
- default:
- break;
- }
- }
- }
- private double pageNum = 1;
- /// <summary>
- /// 平均页数
- /// </summary>
- public double PageNum
- {
- get { return pageNum; }
- set
- {
- SetProperty(ref pageNum, value);
- GetModeCount = (int)value;
- }
- }
- private double filesCount = 1;
- /// <summary>
- /// 平均文件数
- /// </summary>
- public double FilesCount
- {
- get { return filesCount; }
- set
- {
- SetProperty(ref filesCount, value);
- GetModeCount = (int)value;
- }
- }
- private bool isAveragePages = true;
- /// <summary>
- /// 平均按页拆分 是否选中
- /// </summary>
- public bool IsAveragePages
- {
- get { return isAveragePages; }
- set
- {
- SetProperty(ref isAveragePages, value);
- if (value)
- {
- Mode = SplitMode.AveragePages;
- }
- }
- }
- private bool isAveragePDF = false;
- /// <summary>
- /// 平均按PDF拆分 是否选中
- /// </summary>
- public bool IsAveragePDF
- {
- get { return isAveragePDF; }
- set
- {
- SetProperty(ref isAveragePDF, value);
- if (value)
- {
- Mode = SplitMode.AverageFiles;
- }
- }
- }
- private bool isCustomRange = false;
- /// <summary>
- /// 自定义页面范围,是否选中
- /// </summary>
- public bool IsCustomRange
- {
- get { return isCustomRange; }
- set
- {
- SetProperty(ref isCustomRange, value);
- if (value)
- {
- Mode = SplitMode.CustomPageRange;
- }
- else
- {
- PageSelectedIndex = 1;
- }
- }
- }
- private string customPageText;
- /// <summary>
- /// 自定义的输入内容
- /// </summary>
- public string CustomPageText
- {
- get { return customPageText; }
- set
- {
- SetProperty(ref customPageText, value);
- }
- }
- /// <summary>
- /// 文件名标签
- /// </summary>
- private string fileNameLabel = "part";
- public string FileNameLabel
- {
- get { return fileNameLabel; }
- set
- {
- SetProperty(ref fileNameLabel, value);
- RefreshFileName();
- }
- }
- private bool hasLabel = true;
- /// <summary>
- /// 是否含有标签
- /// </summary>
- public bool HasLabel
- {
- get { return hasLabel; }
- set
- {
- SetProperty(ref hasLabel, value);
- RefreshFileName();
- }
- }
- /// <summary>
- /// 文件名与标签分隔符
- /// </summary>
- private string fileNameDeimiter = "-";
- public string FileNameDeimiter
- {
- get { return fileNameDeimiter; }
- set
- {
- SetProperty(ref fileNameDeimiter, value);
- // 拆分 分割符 特殊字符判断
- if (string.IsNullOrEmpty(fileNameDeimiter) == false)
- {
- string pattern = @"[\\\/:*?""<>|.]"; // 定义不允许出现的字符的正则表达式模式
- Regex regex = new Regex(pattern);
- //if (regex.IsMatch(fileName))
- //{
- char[] invalidChars = { '\\', '/', ':', '*', '?', '"', '<', '>', '|', '.' };
- //英文
- if (fileNameDeimiter.IndexOfAny(invalidChars) != -1)
- {
- fileNameDeimiter = string.Empty;
- Console.WriteLine("文件名包含不允许的字符");
- // 进行报错处理的代码逻辑
- AlertsMessage alertsMessage = new AlertsMessage();
- string illegalChars = @"\ /<>:|""?*";
- alertsMessage.ShowDialog($"{App.MainPageLoader.GetString("PageEdite_SplitErroTitle")}", $"{App.MainPageLoader.GetString("PageEdite_SplitErroContent")}{illegalChars}", App.ServiceLoader.GetString("Text_ok"), IconType.Tip);
- }
- }
- RefreshFileName();
- }
- }
- private bool hasDeimiter = true;
- /// <summary>
- /// 是否含有分隔符
- /// </summary>
- public bool HasDeimiter
- {
- get { return hasDeimiter; }
- set
- {
- SetProperty(ref hasDeimiter, value);
- RefreshFileName();
- }
- }
- /// <summary>
- /// 文件名与标签分隔符
- /// </summary>
- public bool FrontFileName = true;
- /// <summary>
- /// 页码 存入页码范围;
- /// </summary>
- public List<int> PageParm = new List<int> { };
- /// <summary>
- /// 文件名;
- /// </summary>
- private string fileName = "";
- public string FileName
- {
- get { return fileName; }
- set
- {
- SetProperty(ref fileName, value);
- }
- }
- private bool isSourceNameFront = true;
- /// <summary>
- /// 原始文档名前置
- /// </summary>
- public bool IsSourceNameFront
- {
- get { return isSourceNameFront; }
- set
- {
- SetProperty(ref isSourceNameFront, value);
- RefreshFileName();
- }
- }
- private string sourceName;
- /// <summary>
- /// 原始文件名
- /// </summary>
- public string SourceFileName
- {
- get { return sourceName; }
- set
- {
- SetProperty(ref sourceName, value);
- RefreshFileName();
- }
- }
- /// <summary>
- /// 刷新文件名
- /// </summary>
- public void RefreshFileName()
- {
- string label = HasLabel ? FileNameLabel : "";
- string deimiter = HasDeimiter ? FileNameDeimiter : "";
- if (isSourceNameFront)
- {
- FileName = SourceFileName + deimiter + label + "1" + ".pdf";
- }
- else
- {
- FileName = label + "1" + deimiter + SourceFileName + ".pdf";
- }
- }
- public enum SplitMode
- {
- /// <summary>
- /// 按页平均拆分
- /// </summary>
- AveragePages,
- /// <summary>
- /// 按文件平均拆分
- /// </summary>
- AverageFiles,
- /// <summary>
- /// 自定义页码范围拆分
- /// </summary>
- CustomPageRange
- }
- public enum PageRangeMode
- {
- /// <summary>
- /// 奇数页
- /// </summary>
- OddPage,
- /// <summary>
- /// 偶数页
- /// </summary>
- EvenPage,
- /// <summary>
- /// 自定义页面范围
- /// </summary>
- CustomPage
- }
- }
- }
|