NoviceGuidDialogViewModel.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. this.RequestClose(new DialogResult(ButtonResult.Ignore));
  159. }
  160. private void InitItemSource()
  161. {
  162. ItemSource = new ObservableCollection<GuidItemModel>();
  163. ItemSource.Add(new GuidItemModel() { ImageSource = "pack://application:,,,/PDF Master;component/Resources/GuidItems/Guid_Office.png", Title = App.HomePageLoader.GetString("GuidTitleP1"), Content = string.Format(App.HomePageLoader.GetString("GuidContentP1"),trialDays) }) ;
  164. ItemSource.Add(new GuidItemModel() { ImageSource = "pack://application:,,,/PDF Master;component/Resources/GuidItems/Guid_Annote.png", Title = App.HomePageLoader.GetString("GuidTitleP2"), Content =App.HomePageLoader.GetString("GuidContentP2") });
  165. ItemSource.Add(new GuidItemModel() { ImageSource = "pack://application:,,,/PDF Master;component/Resources/GuidItems/Guid_Edit.png", Title = App.HomePageLoader.GetString("GuidTitle_Edit"), Content = App.HomePageLoader.GetString("GuidContent_Edit") });
  166. ItemSource.Add(new GuidItemModel() { ImageSource = "pack://application:,,,/PDF Master;component/Resources/GuidItems/Guid_Convert.png", Title = App.HomePageLoader.GetString("GuidTitleP3"), Content = App.HomePageLoader.GetString("GuidContentP3") });
  167. //因填写与签名功能暂时不上,隐藏新手引导宣传页
  168. //ItemSource.Add(new GuidItemModel() { ImageSource = "pack://application:,,,/PDF Master;component/Resources/GuidItems/Guid_FillAndSign.png", Title = App.HomePageLoader.GetString("GuidTitleP4"), Content = App.HomePageLoader.GetString("GuidContentP4") });
  169. ItemSource.Add(new GuidItemModel() { ImageSource = "pack://application:,,,/PDF Master;component/Resources/GuidItems/Guid_SignUp.png", Title = App.HomePageLoader.GetString("GuidTitleP5"), Content = App.HomePageLoader.GetString("GuidContentP5") });
  170. }
  171. /// <summary>
  172. /// 前一页
  173. /// </summary>
  174. private void NextPage()
  175. {
  176. SelectedIndex++;
  177. }
  178. /// <summary>
  179. /// 下一页
  180. /// </summary>
  181. private void PrePage()
  182. {
  183. SelectedIndex--;
  184. }
  185. /// <summary>
  186. /// 注册
  187. /// </summary>
  188. private void SignUp()
  189. {
  190. RequestClose.Invoke(new DialogResult());
  191. Settings.Default.UserDate.TodayRegister = true;
  192. DateTime currentTime = DateTime.Now;
  193. Settings.Default.UserDate.TodayRegisterTime = currentTime.ToString();
  194. Settings.Default.Save();
  195. dialog.ShowDialog(DialogNames.RegisterDialog);
  196. }
  197. /// <summary>
  198. /// 下一次显示
  199. /// </summary>
  200. private void NextTime()
  201. {
  202. //Todo
  203. }
  204. //是否可以执行下一页
  205. private bool CanNextPageExcute()
  206. {
  207. if(SelectedIndex>=ItemSource.Count-1)
  208. {
  209. return false;
  210. }
  211. return true;
  212. }
  213. /// <summary>
  214. /// 是否可以执行上一页
  215. /// </summary>
  216. /// <returns></returns>
  217. private bool CanPrePageExcute()
  218. {
  219. if (SelectedIndex <= 0)
  220. {
  221. return false;
  222. }
  223. return true;
  224. }
  225. public bool CanCloseDialog()
  226. {
  227. return true;
  228. }
  229. public void OnDialogClosed()
  230. {
  231. }
  232. public void OnDialogOpened(IDialogParameters parameters)
  233. {
  234. }
  235. }
  236. }