NoviceGuidDialogViewModel.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. using PDF_Master.Model;
  2. using PDF_Master.Model.Dialog;
  3. using PDF_Master.Properties;
  4. using Prism.Commands;
  5. using Prism.Mvvm;
  6. using Prism.Services.Dialogs;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Collections.ObjectModel;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. namespace PDF_Master.ViewModels.Dialog
  15. {
  16. public class NoviceGuidDialogViewModel :BindableBase,IDialogAware
  17. {
  18. public string Title => "";
  19. public event Action<IDialogResult> RequestClose;
  20. private int selectedIndex;
  21. /// <summary>
  22. /// 免费试用天数
  23. /// </summary>
  24. private string trialDays = "7";
  25. /// <summary>
  26. /// 选中索引
  27. /// </summary>
  28. public int SelectedIndex
  29. {
  30. get { return selectedIndex; }
  31. set
  32. {
  33. SetProperty(ref selectedIndex, value);
  34. if(SelectedIndex==ItemSource.Count-1)
  35. {
  36. if (App.IsLogin)
  37. {
  38. StartVisible = Visibility.Visible;
  39. }
  40. else
  41. {
  42. SignUpVisible = Visibility.Visible;
  43. }
  44. }
  45. else
  46. {
  47. SignUpVisible = Visibility.Collapsed;
  48. StartVisible = Visibility.Collapsed;
  49. }
  50. if(SelectedIndex==0)
  51. {
  52. NextTimeVisible = Visibility.Visible;
  53. }
  54. else
  55. {
  56. NextTimeVisible = Visibility.Hidden;
  57. }
  58. }
  59. }
  60. private Visibility signUpVisible = Visibility.Collapsed;
  61. /// <summary>
  62. /// 是否显示SignUp按钮
  63. /// </summary>
  64. public Visibility SignUpVisible
  65. {
  66. get { return signUpVisible; }
  67. set
  68. {
  69. SetProperty(ref signUpVisible, value);
  70. }
  71. }
  72. /// <summary>
  73. /// 开始按钮时否隐藏
  74. /// </summary>
  75. private Visibility startVisible = Visibility.Collapsed;
  76. public Visibility StartVisible
  77. {
  78. get { return startVisible; }
  79. set
  80. {
  81. SetProperty(ref startVisible, value);
  82. }
  83. }
  84. private Visibility nexttimeVisible;
  85. public Visibility NextTimeVisible
  86. {
  87. get { return nexttimeVisible; }
  88. set
  89. {
  90. SetProperty(ref nexttimeVisible, value);
  91. }
  92. }
  93. private string T_btnNextStep;
  94. public string T_BtnNextStep
  95. {
  96. get { return T_btnNextStep; }
  97. set
  98. {
  99. SetProperty(ref T_btnNextStep, value);
  100. }
  101. }
  102. /// <summary>
  103. ///
  104. /// </summary>
  105. private string T_btnStart;
  106. public string T_BtnStart
  107. {
  108. get { return T_btnStart; }
  109. set
  110. {
  111. SetProperty(ref T_btnStart, value);
  112. }
  113. }
  114. private string T_btnNextTime;
  115. public string T_BtnNextTime
  116. {
  117. get { return T_btnNextTime; }
  118. set
  119. {
  120. SetProperty(ref T_btnNextTime, value);
  121. }
  122. }
  123. private string T_btnSignUp;
  124. public string T_BtnSignUp
  125. {
  126. get { return T_btnSignUp; }
  127. set
  128. {
  129. SetProperty(ref T_btnSignUp, value);
  130. }
  131. }
  132. public DelegateCommand NextPageCommand { get; set; }
  133. public DelegateCommand PrePageCommand { get; set; }
  134. public DelegateCommand NextTimeCommand { get; set; }
  135. public DelegateCommand SignUpCommand { get; set; }
  136. public ObservableCollection<GuidItemModel> ItemSource { get; set; }
  137. private IDialogService dialog;
  138. public NoviceGuidDialogViewModel(IDialogService dialogService)
  139. {
  140. dialog = dialogService;
  141. NextPageCommand = new DelegateCommand(NextPage,CanNextPageExcute).ObservesProperty(()=>SelectedIndex);
  142. PrePageCommand = new DelegateCommand(PrePage,CanPrePageExcute).ObservesProperty(()=>SelectedIndex);
  143. SignUpCommand = new DelegateCommand(SignUp);
  144. NextTimeCommand = new DelegateCommand(nexttime);
  145. InitItemSource();
  146. InitString();
  147. }
  148. private void InitString()
  149. {
  150. T_BtnNextStep = App.HomePageLoader.GetString("Guid_AcceptButton");
  151. T_BtnNextTime = App.HomePageLoader.GetString("Guid_LaterButton");
  152. T_BtnSignUp = App.ServiceLoader.GetString("Text_Signup");
  153. T_BtnStart =App.HomePageLoader.GetString("Guid_StartNow");
  154. }
  155. private void nexttime()
  156. {
  157. //忽略,下次再看
  158. //2023.7.17 策略调整,因配图较多,不显示再提示字样
  159. //this.RequestClose(new DialogResult(ButtonResult.Ignore));
  160. }
  161. private void InitItemSource()
  162. {
  163. ItemSource = new ObservableCollection<GuidItemModel>();
  164. //因新手引导配图顺序和功能没有直接关系,因此配图命名按顺序来,方便后面调整顺序或者插入图片后更新资源
  165. ItemSource.Add(new GuidItemModel() { ImageSource = "pack://application:,,,/PDF Master;component/Resources/GuidItems/GuidItem1.png", Title = App.HomePageLoader.GetString("GuidTitleP1"), Content = App.HomePageLoader.GetString("GuidContentP1") }) ;
  166. ItemSource.Add(new GuidItemModel() { ImageSource = "pack://application:,,,/PDF Master;component/Resources/GuidItems/GuidItem2.png", Title = App.HomePageLoader.GetString("GuidTitleP2"), Content =App.HomePageLoader.GetString("GuidContentP2") });
  167. ItemSource.Add(new GuidItemModel() { ImageSource = "pack://application:,,,/PDF Master;component/Resources/GuidItems/GuidItem3.png", Title = App.HomePageLoader.GetString("GuidTitleP3"), Content = App.HomePageLoader.GetString("GuidContentP3") });
  168. ItemSource.Add(new GuidItemModel() { ImageSource = "pack://application:,,,/PDF Master;component/Resources/GuidItems/GuidItem4.png", Title = App.HomePageLoader.GetString("GuidTitleP4"), Content = App.HomePageLoader.GetString("GuidContentP4") });
  169. ItemSource.Add(new GuidItemModel() { ImageSource = "pack://application:,,,/PDF Master;component/Resources/GuidItems/GuidItem5.png", Title = App.HomePageLoader.GetString("GuidTitleP5"), Content = App.HomePageLoader.GetString("GuidContentP5") });
  170. ItemSource.Add(new GuidItemModel() { ImageSource = "pack://application:,,,/PDF Master;component/Resources/GuidItems/GuidItem6.png", Title = App.HomePageLoader.GetString("GuidTitleP6"), Content = App.HomePageLoader.GetString("GuidContentP6") });
  171. }
  172. /// <summary>
  173. /// 前一页
  174. /// </summary>
  175. private void NextPage()
  176. {
  177. SelectedIndex++;
  178. }
  179. /// <summary>
  180. /// 下一页
  181. /// </summary>
  182. private void PrePage()
  183. {
  184. SelectedIndex--;
  185. }
  186. /// <summary>
  187. /// 注册
  188. /// </summary>
  189. private void SignUp()
  190. {
  191. RequestClose.Invoke(new DialogResult());
  192. Settings.Default.UserDate.TodayRegister = true;
  193. DateTime currentTime = DateTime.Now;
  194. Settings.Default.UserDate.TodayRegisterTime = currentTime.ToString();
  195. Settings.Default.Save();
  196. dialog.ShowDialog(DialogNames.RegisterDialog);
  197. }
  198. /// <summary>
  199. /// 下一次显示
  200. /// </summary>
  201. private void NextTime()
  202. {
  203. //Todo
  204. }
  205. //是否可以执行下一页
  206. private bool CanNextPageExcute()
  207. {
  208. if(SelectedIndex>=ItemSource.Count-1)
  209. {
  210. return false;
  211. }
  212. return true;
  213. }
  214. /// <summary>
  215. /// 是否可以执行上一页
  216. /// </summary>
  217. /// <returns></returns>
  218. private bool CanPrePageExcute()
  219. {
  220. if (SelectedIndex <= 0)
  221. {
  222. return false;
  223. }
  224. return true;
  225. }
  226. public bool CanCloseDialog()
  227. {
  228. return true;
  229. }
  230. public void OnDialogClosed()
  231. {
  232. }
  233. public void OnDialogOpened(IDialogParameters parameters)
  234. {
  235. }
  236. }
  237. }