2025-08-15 16:34:31 +08:00
|
|
|
|
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;
|
2025-09-04 18:28:02 +08:00
|
|
|
|
using SWS.Commons;
|
|
|
|
|
using SWS.Service;
|
|
|
|
|
using SWS.Model;
|
2025-08-15 16:34:31 +08:00
|
|
|
|
|
|
|
|
|
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<Config>();
|
|
|
|
|
Application.ShowModalWindow(Application.MainWindow.Handle, configView);
|
|
|
|
|
}
|
|
|
|
|
_UserService = GlobalObject.container.Resolve<UserService>();
|
|
|
|
|
_NotificationService = notificationService;
|
|
|
|
|
_Service = Service;
|
|
|
|
|
_configService = configService;
|
|
|
|
|
this.eventAggregator1 = eventAggregator;
|
|
|
|
|
|
2025-09-04 18:28:02 +08:00
|
|
|
|
UserName = _configService.Read(nameof(ConfigIni.UserName));
|
|
|
|
|
sPASSWORD = _configService.Read(nameof(ConfigIni.UserPs));
|
2025-08-15 16:34:31 +08:00
|
|
|
|
if (string.IsNullOrEmpty(sPASSWORD))
|
|
|
|
|
{
|
|
|
|
|
rememberPs = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rememberPs = true;
|
|
|
|
|
}
|
|
|
|
|
if (GlobalObject.userInfo != null && rememberPs)
|
|
|
|
|
{
|
|
|
|
|
sPASSWORD = GlobalObject.userInfo.userPs;
|
|
|
|
|
}
|
2025-09-10 10:57:20 +08:00
|
|
|
|
curServer = "当前服务器: " + _configService.Read("strIPAddress") + ":" + _configService.Read("nPort");
|
2025-08-15 16:34:31 +08:00
|
|
|
|
}
|
|
|
|
|
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("登陆成功!");
|
|
|
|
|
|
2025-09-04 18:28:02 +08:00
|
|
|
|
_configService.Save(nameof(ConfigIni.UserName), UserName);
|
2025-08-15 16:34:31 +08:00
|
|
|
|
if (rememberPs)
|
|
|
|
|
{
|
2025-09-04 18:28:02 +08:00
|
|
|
|
_configService.Save(nameof(ConfigIni.UserPs), Userpass);
|
2025-08-15 16:34:31 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-09-04 18:28:02 +08:00
|
|
|
|
_configService.Save(nameof(ConfigIni.UserPs), "");
|
2025-08-15 16:34:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 拿一些全局的东西
|
|
|
|
|
await _UserService.GetList();
|
|
|
|
|
#endregion
|
|
|
|
|
CloseWindowAction?.Invoke();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Application.ShowAlertDialog(res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|