HomePageConverterExcelViewModel.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using ComPDFKit_Conversion.Options;
  2. using PDF_Master.Model;
  3. using PDF_Master.Model.Dialog.ConverterDialogs;
  4. using PDF_Master.Model.EditTools.Watermark;
  5. using Prism.Commands;
  6. using Prism.Mvvm;
  7. using Prism.Regions;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Windows.Controls;
  12. namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageConverter
  13. {
  14. public class HomePageConverterExcelViewModel : BindableBase, INavigationAware
  15. {
  16. #region 参数和属性
  17. public HomePageConverterDialogViewModel homePageConverterDialogViewModel { get; set; }
  18. private int _anyContentSelectIndex;
  19. public int AnyContentSelectIndex
  20. {
  21. get { return _anyContentSelectIndex; }
  22. set
  23. {
  24. SetProperty(ref _anyContentSelectIndex, value);
  25. AnyContent(_anyContentSelectIndex);
  26. }
  27. }
  28. private int _onlyTableSelectIndex;
  29. public int OnlyTableSelectIndex
  30. {
  31. get { return _onlyTableSelectIndex; }
  32. set
  33. {
  34. SetProperty(ref _onlyTableSelectIndex, value);
  35. OnlyTable(_onlyTableSelectIndex);
  36. }
  37. }
  38. #endregion
  39. #region 委托声明
  40. public DelegateCommand<string> RadioButtonCommand { get; set; }
  41. #endregion
  42. public HomePageConverterExcelViewModel()
  43. {
  44. RadioButtonCommand = new DelegateCommand<string>(radiobutton);
  45. }
  46. #region 逻辑函数
  47. private void radiobutton(string e)
  48. {
  49. string radioButton = e;
  50. if (radioButton != null)
  51. {
  52. switch (radioButton)
  53. {
  54. case "AnyContentRadioBtn":
  55. AnyContent(AnyContentSelectIndex);
  56. break;
  57. case "OnlyTableRadioBtn":
  58. OnlyTable(OnlyTableSelectIndex);
  59. break;
  60. case "OnlyTextRadioBtn":
  61. homePageConverterDialogViewModel.ConverterExcelModel.Options.WorksheetOpts = WorksheetOptions.ForTheDocument;
  62. homePageConverterDialogViewModel.ConverterExcelModel.Options.ContentOpts = ContentOptions.OnlyText;
  63. break;
  64. default:
  65. break;
  66. }
  67. }
  68. }
  69. private void AnyContent(int SelectedIndex) {
  70. switch (SelectedIndex)
  71. {
  72. case 0:
  73. homePageConverterDialogViewModel.ConverterExcelModel.Options.WorksheetOpts = WorksheetOptions.ForEachPage;
  74. homePageConverterDialogViewModel.ConverterExcelModel.Options.ContentOpts = ContentOptions.AllContent;
  75. break;
  76. case 1:
  77. homePageConverterDialogViewModel.ConverterExcelModel.Options.WorksheetOpts = WorksheetOptions.ForTheDocument;
  78. homePageConverterDialogViewModel.ConverterExcelModel.Options.ContentOpts = ContentOptions.AllContent;
  79. break;
  80. default:
  81. break;
  82. }
  83. }
  84. private void OnlyTable(int SelectedIndex)
  85. {
  86. homePageConverterDialogViewModel.ConverterExcelModel.Options.ContentOpts = ContentOptions.OnlyTable;
  87. switch (SelectedIndex)
  88. {
  89. case 0:
  90. homePageConverterDialogViewModel.ConverterExcelModel.Options.WorksheetOpts = WorksheetOptions.ForEachTable;
  91. break;
  92. case 1:
  93. homePageConverterDialogViewModel.ConverterExcelModel.Options.WorksheetOpts = WorksheetOptions.ForEachPage;
  94. break;
  95. case 2:
  96. homePageConverterDialogViewModel.ConverterExcelModel.Options.WorksheetOpts = WorksheetOptions.ForEachPage;
  97. break;
  98. default:
  99. break;
  100. }
  101. }
  102. #endregion
  103. #region 构架行为
  104. public void OnNavigatedTo(NavigationContext navigationContext)
  105. {
  106. var homePageConverterVM = navigationContext.Parameters[ParameterNames.ViewContentViewModel] as HomePageConverterDialogViewModel;
  107. if (homePageConverterVM != null)
  108. {
  109. homePageConverterDialogViewModel = homePageConverterVM;
  110. OnlyTableSelectIndex = 0;
  111. AnyContentSelectIndex = 0;
  112. homePageConverterDialogViewModel.ConverterExcelModel.excelOptions = homePageConverterDialogViewModel.ConverterExcelModel.ExcelOptions();
  113. }
  114. }
  115. public bool IsNavigationTarget(NavigationContext navigationContext)
  116. {
  117. return true;
  118. }
  119. public void OnNavigatedFrom(NavigationContext navigationContext)
  120. {
  121. }
  122. #endregion
  123. }
  124. }