using PDF_Master.CustomControl; using PDF_Master.Helper; using PDF_Master.Model; using Prism.Commands; using Prism.Mvvm; using Prism.Services.Dialogs; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PDF_Master.ViewModels.Dialog.Redaction { public class PageMarkDialogViewModel : BindableBase, IDialogAware { public string Title => ""; public event Action RequestClose; public DelegateCommand OkCommand { get; set; } public DelegateCommand CancelCommand { get; set; } public DelegateCommand CheckedCommand { get; set; } /// /// 当前页 /// public int CurrentPageIndex { get; set; } private string pagecount = "/1"; /// /// 页面总数 /// public string PageCount { get { return pagecount; } set { SetProperty(ref pagecount, value); } } /// /// 页码集合 /// public List PageList = new List(); /// /// 文档页面总数 /// public int pageCount = 0; private string custompage; /// /// 自定义页面 /// public string CustomPage { get { return custompage; } set { SetProperty(ref custompage, value); if(!string.IsNullOrEmpty(value)) { CheckCustomPage(); } } } public PageMarkDialogViewModel() { OkCommand = new DelegateCommand(ok); CancelCommand = new DelegateCommand(cancel); CheckedCommand = new DelegateCommand(check); } private void cancel() { RequestClose.Invoke(new DialogResult(ButtonResult.Cancel)); } private void ok() { DialogParameters valuePairs = new DialogParameters(); valuePairs.Add(ParameterNames.PageList, PageList); RequestClose.Invoke(new DialogResult(ButtonResult.OK, valuePairs)); } private void CheckCustomPage() { var result = CommonHelper.GetPagesInRange(ref PageList,CustomPage,pageCount,new char[]{ ','},new char[] { '-'}); if(!result) { AlertsMessage alertsMessage = new AlertsMessage(); alertsMessage.ShowDialog("","页码错误","ok"); CustomPage = ""; return; } } private void check(string args) { switch (args) { case "Odd": PageList = new List(); for (int i = 1; i <=pageCount; i++) { if (i % 2 != 0) { PageList.Add(i-1); } } break; case "Even": PageList = new List(); for (int i = 1; i <= pageCount; i++) { if (i % 2 == 0) { PageList.Add(i - 1); } } break; case "All": PageList = new List(); for(int i=0;i(); PageList.Add(CurrentPageIndex); break; } } public bool CanCloseDialog() { return true; } public void OnDialogClosed() { } public void OnDialogOpened(IDialogParameters parameters) { int page = parameters.GetValue(ParameterNames.PageCount); if(page>0) { PageCount = "/ " + page; pageCount = page; } PageList = new List(); for (int i = 0; i < pageCount; i++) { PageList.Add(i); } CurrentPageIndex = parameters.GetValue(ParameterNames.CurrentPageIndex); } } }