using Bricscad.ApplicationServices; using SWS.CAD.ViewModels.myViewModelBase; using Telerik.Windows.Controls; using SWS.CAD.CADFunc.Editor; using SWS.CAD.Views; using Unity; using Prism.Events; using SWS.Commons; using SWS.Service; using SWS.Model; namespace SWS.CAD.ViewModels { public class LoginViewModel : DialogBase { #region BINDING private bool _rememberPs; public bool rememberPs { get { return _rememberPs; } set { _rememberPs = value; RaisePropertyChanged(nameof(rememberPs)); } } private string _UserName; public string UserName { get { return _UserName; } set { _UserName = value; RaisePropertyChanged(nameof(UserName)); } } private string _UserPs; private string _curServer; public string curServer { get { return _curServer; } set { _curServer = value; RaisePropertyChanged(nameof(curServer)); } } private string _sPASSWORD; public string sPASSWORD { get { return _sPASSWORD; } set { _sPASSWORD = value; RaisePropertyChanged(nameof(sPASSWORD)); } } #endregion NotificationService _NotificationService; LoginService _Service; ConfigService _configService; UserService _UserService; IEventAggregator eventAggregator1; public LoginViewModel(LoginService Service, ConfigService configService, NotificationService notificationService, IEventAggregator eventAggregator) : base() { title = "用户登录"; if (GlobalObject.isConfigIniCreateBySys) { var configView = GlobalObject.container.Resolve(); Application.ShowModalWindow(Application.MainWindow.Handle, configView); } _UserService = GlobalObject.container.Resolve(); _NotificationService = notificationService; _Service = Service; _configService = configService; this.eventAggregator1 = eventAggregator; UserName = _configService.Read(nameof(ConfigIni.UserName)); sPASSWORD = _configService.Read(nameof(ConfigIni.UserPs)); if (string.IsNullOrEmpty(sPASSWORD)) { rememberPs = false; } else { rememberPs = true; } if (GlobalObject.userInfo != null && rememberPs) { sPASSWORD = GlobalObject.userInfo.userPs; } curServer = "当前服务器: " + _configService.Read("strIPAddress") + ":" + _configService.Read("nPort"); } public override async void ExecuteOKCommandAsync(object obj) { if (obj != null) { } var passBox = obj as RadPasswordBox; var Userpass = passBox.Password; if (string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(Userpass)) { Application.ShowAlertDialog("用户名和密码不能为空!"); } else { IsBusy = true; BusyContent = "登录中..."; var res = await _Service.Login(UserName, Userpass); IsBusy = false; if (string.IsNullOrEmpty(res)) { EditorHelper.WriteInfo("登陆成功!"); _configService.Save(nameof(ConfigIni.UserName), UserName); if (rememberPs) { _configService.Save(nameof(ConfigIni.UserPs), Userpass); } else { _configService.Save(nameof(ConfigIni.UserPs), ""); } #region 拿一些全局的东西 await _UserService.GetList(); #endregion CloseWindowAction?.Invoke(); } else { Application.ShowAlertDialog(res); } } } } }