123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- using System;
- using System.Runtime.InteropServices;
- using System.Windows;
- using System.Windows.Controls;
- using PDF_Master.CustomControl;
- using PDF_Master.Helper;
- using PDF_Master.Properties;
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Regions;
- using Prism.Services.Dialogs;
- namespace PDF_Master.ViewModels.Dialog.ServiceDialog
- {
- public class UserDialogViewModel : BindableBase, IDialogAware
- {
- private string uuid = ServiceHelper.GetDeviceSerialNumber();
- public IRegionManager Region;
- public string Title => "";
- public event Action<IDialogResult> RequestClose;
- public void Close()
- {
- RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
- }
- public bool CanCloseDialog()
- {
- return true;
- }
- public void OnDialogClosed()
- {
- }
- public void OnDialogOpened(IDialogParameters parameters)
- {
- if (ServiceHelper. IsConnectInternet()==false)
- {
- RegionMan("NOInternetRegion");
- }
- }
- #region 文案
- private string _Text_useracc = "";
- public string Text_useracc
- {
- get { return _Text_useracc; }
- set
- {
- SetProperty(ref _Text_useracc, value);
- }
- }
- private string _Text_admail = "";
- public string Text_admail
- {
- get { return _Text_admail; }
- set
- {
- SetProperty(ref _Text_admail, value);
- }
- }
- private string _Text_logout = "";
- public string Text_logout
- {
- get { return _Text_logout; }
- set
- {
- SetProperty(ref _Text_logout, value);
- }
- }
- private string _Text_no = "";
- public string Text_no
- {
- get { return _Text_no; }
- set
- {
- SetProperty(ref _Text_no, value);
- }
- }
- private string _Text_yes = "";
- public string Text_yes
- {
- get { return _Text_yes; }
- set
- {
- SetProperty(ref _Text_yes, value);
- }
- }
- private string _Text_useroutmsg = "";
- public string Text_useroutmsg
- {
- get { return _Text_useroutmsg; }
- set
- {
- SetProperty(ref _Text_useroutmsg, value);
- }
- }
- private string _Text_userouttol = "";
- public string Text_userouttol
- {
- get { return _Text_userouttol; }
- set
- {
- SetProperty(ref _Text_userouttol, value);
- }
- }
- private void InitString()
- {
- Text_useracc = App.ServiceLoader.GetString("Text_useracc");
- Text_admail = App.ServiceLoader.GetString("Text_admail");
- Text_logout = App.ServiceLoader.GetString("Text_logout");
- Text_userouttol = App.ServiceLoader.GetString("Text_userouttol");
- Text_useroutmsg = App.ServiceLoader.GetString("Text_useroutmsg");
- Text_yes = App.ServiceLoader.GetString("Text_yes");
- Text_no = App.ServiceLoader.GetString("Text_no");
- }
- #endregion
- private string _Useremailchar = Settings.Default.UserDate.Email.Substring(0, 1);
- public string Useremailchar
- {
- get { return _Useremailchar; }
- set
- {
- SetProperty(ref _Useremailchar, value);
- }
- }
- private string _UserEmail = Settings.Default.UserDate.Email;
- public string UserEmail
- {
- get { return _UserEmail; }
- set { _UserEmail = value; }
- }
- private string _UserRegionName;
- public string UserRegionName
- {
- get { return _UserRegionName; }
- set { _UserRegionName = value; }
- }
- public DelegateCommand UserOutCommand { get; set; }
- public DelegateCommand LogOutCommand { get; set; }
- UserDialogViewModel(IRegionManager regionManager, IDialogService dialogService)
- {
- this.Region = regionManager;
- InitString();
- UserRegionName = Guid.NewGuid().ToString();
- UserOutCommand = new DelegateCommand(UserOut);
- LogOutCommand = new DelegateCommand(LogOut);
- UserEmail = Settings.Default.UserDate.Email;
-
- }
- public void UserOut()
- {
- AlertsMessage alertsMessage = new AlertsMessage();
- alertsMessage.ShowDialog(Text_userouttol, Text_useroutmsg, App.ServiceLoader.GetString("Text_yes"), App.ServiceLoader.GetString("Text_no"), IconType.Tip);
- //调整按钮显示位置,cancel按钮表示确认退出
- //目的是尽量引导用户不注销
- if (alertsMessage.result == ContentResult.MiddleCancel)
- {
- RegionMan("UserOutCodeRegion");
- }
- }
- public void LogOut()
- {
- ServiceHelper.Logout(uuid);
- Settings.Default.AppProperties.LoginToken = "";
- Settings.Default.Save();
- App.mainWindowViewModel.UserVis = Visibility.Collapsed;
- App.mainWindowViewModel.RegisterVis = Visibility.Collapsed;
- App.mainWindowViewModel.LoginVis = Visibility.Visible;
- Close();
- }
- public void RegionMan(string name)
- {
- NavigationParameters param = new NavigationParameters();
- param.Add("UserDialogViewModel", this);
- Region.RequestNavigate(UserRegionName, name, e => {
- var r = e.Result;
- }, param);
- }
- }
- }
|