123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- 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 RepeatMarkDialogViewModel : BindableBase, IDialogAware
- {
- public string Title => "";
- public event Action<IDialogResult> RequestClose;
- public DelegateCommand OkCommand { get; set; }
- public DelegateCommand CancelCommand { get; set; }
- public DelegateCommand<string> CheckedCommand { get; set; }
- private int pageCount;
- /// <summary>
- /// 最大页码
- /// </summary>
- public int PageCount
- {
- get { return pageCount; }
- set
- {
- SetProperty(ref pageCount, value);
- }
- }
- private string inputString;
- public string InputString
- {
- get { return inputString; }
- set
- {
- SetProperty(ref inputString, value);
- if (!string.IsNullOrEmpty(value))
- {
- CheckCustomPage();
- }
- }
- }
- public List<int> PageList = new List<int>();
- public RepeatMarkDialogViewModel()
- {
- OkCommand = new DelegateCommand(ok);
- CancelCommand = new DelegateCommand(cancel);
- CheckedCommand = new DelegateCommand<string>(check);
- }
- private void check(string args)
- {
- switch (args)
- {
- case "Odd":
- PageList = new List<int>();
- for (int i = 1; i <= pageCount; i++)
- {
- if (i % 2 != 0)
- {
- PageList.Add(i - 1);
- }
- }
- break;
- case "Even":
- PageList = new List<int>();
- for (int i = 1; i <= pageCount; i++)
- {
- if (i % 2 == 0)
- {
- PageList.Add(i - 1);
- }
- }
- break;
- case "All":
- PageList = new List<int>();
- for (int i = 0; i < pageCount; i++)
- {
- PageList.Add(i);
- }
- break;
- case "Custom":
- if (!string.IsNullOrEmpty(InputString))
- {
- CheckCustomPage();
- }
- break;
- default:
- break;
- }
- }
- private void CheckCustomPage()
- {
- var result = CommonHelper.GetPagesInRange(ref PageList, InputString, pageCount, new char[] { ',' }, new char[] { '-' });
- if (!result)
- {
- AlertsMessage alertsMessage = new AlertsMessage();
- alertsMessage.ShowDialog("", "页码错误", "ok");
- InputString = "";
- return;
- }
- }
- private void ok()
- {
- DialogParameters valuePairs = new DialogParameters();
- valuePairs.Add(ParameterNames.PageList,PageList);
- RequestClose.Invoke(new DialogResult(ButtonResult.OK,valuePairs));
- }
- private void cancel()
- {
- RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
- }
- public bool CanCloseDialog()
- {
- return true;
- }
- public void OnDialogClosed()
- {
-
- }
- public void OnDialogOpened(IDialogParameters parameters)
- {
- PageCount = parameters.GetValue<int>(ParameterNames.PageCount);
- PageList = new List<int>();
- for (int i = 0; i < pageCount; i++)
- {
- PageList.Add(i);
- }
- }
- }
- }
|