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
{
///
/// 拆分模式
///
public SplitMode Mode = SplitMode.AveragePages;
///
/// 页面范围形式
///
public PageRangeMode PageMode = PageRangeMode.OddPage;
///
/// 拆分模式份数或者页数
///
public int GetModeCount = 1;
///
/// 页面信息
///
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;
///
/// 平均页数
///
public double PageNum
{
get { return pageNum; }
set
{
SetProperty(ref pageNum, value);
GetModeCount = (int)value;
}
}
private double filesCount = 1;
///
/// 平均文件数
///
public double FilesCount
{
get { return filesCount; }
set
{
SetProperty(ref filesCount, value);
GetModeCount = (int)value;
}
}
private bool isAveragePages = true;
///
/// 平均按页拆分 是否选中
///
public bool IsAveragePages
{
get { return isAveragePages; }
set
{
SetProperty(ref isAveragePages, value);
if (value)
{
Mode = SplitMode.AveragePages;
}
}
}
private bool isAveragePDF = false;
///
/// 平均按PDF拆分 是否选中
///
public bool IsAveragePDF
{
get { return isAveragePDF; }
set
{
SetProperty(ref isAveragePDF, value);
if (value)
{
Mode = SplitMode.AverageFiles;
}
}
}
private bool isCustomRange = false;
///
/// 自定义页面范围,是否选中
///
public bool IsCustomRange
{
get { return isCustomRange; }
set
{
SetProperty(ref isCustomRange, value);
if (value)
{
Mode = SplitMode.CustomPageRange;
}
else
{
PageSelectedIndex = 1;
}
}
}
private string customPageText;
///
/// 自定义的输入内容
///
public string CustomPageText
{
get { return customPageText; }
set
{
SetProperty(ref customPageText, value);
}
}
///
/// 文件名标签
///
private string fileNameLabel = "part";
public string FileNameLabel
{
get { return fileNameLabel; }
set
{
SetProperty(ref fileNameLabel, value);
RefreshFileName();
}
}
private bool hasLabel = true;
///
/// 是否含有标签
///
public bool HasLabel
{
get { return hasLabel; }
set
{
SetProperty(ref hasLabel, value);
RefreshFileName();
}
}
///
/// 文件名与标签分隔符
///
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;
///
/// 是否含有分隔符
///
public bool HasDeimiter
{
get { return hasDeimiter; }
set
{
SetProperty(ref hasDeimiter, value);
RefreshFileName();
}
}
///
/// 文件名与标签分隔符
///
public bool FrontFileName = true;
///
/// 页码 存入页码范围;
///
public List PageParm = new List { };
///
/// 文件名;
///
private string fileName = "";
public string FileName
{
get { return fileName; }
set
{
SetProperty(ref fileName, value);
}
}
private bool isSourceNameFront = true;
///
/// 原始文档名前置
///
public bool IsSourceNameFront
{
get { return isSourceNameFront; }
set
{
SetProperty(ref isSourceNameFront, value);
RefreshFileName();
}
}
private string sourceName;
///
/// 原始文件名
///
public string SourceFileName
{
get { return sourceName; }
set
{
SetProperty(ref sourceName, value);
RefreshFileName();
}
}
///
/// 刷新文件名
///
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
{
///
/// 按页平均拆分
///
AveragePages,
///
/// 按文件平均拆分
///
AverageFiles,
///
/// 自定义页码范围拆分
///
CustomPageRange
}
public enum PageRangeMode
{
///
/// 奇数页
///
OddPage,
///
/// 偶数页
///
EvenPage,
///
/// 自定义页面范围
///
CustomPage
}
}
}