NoviceGuidDialogViewModel.cs 8.7 KB

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