2025-08-15 16:34:31 +08:00

160 lines
4.8 KiB
C#

using Bricscad.ApplicationServices;
using Bricscad.Windows;
using Bricscad.EditorInput;
using SWS.CAD.Services;
using SWS.CAD.ViewModels.myViewModelBase;
using System;
using System.Windows.Input;
using Teigha.Runtime;
using Telerik.Windows.Controls;
using System.IO;
using SWS.CAD.CADFunc.Editor;
using SWS.CAD.Views;
using System.ComponentModel;
using Unity;
using Prism.Events;
using SWS.CAD.Event;
using System.Diagnostics;
using SWS.CAD.Models.NoEntity;
using SWS.CAD.Helper;
using Teigha.GraphicsInterface;
using System.Linq;
using Prism.Dialogs;
using SWS.CAD.Models;
using Teigha.GraphicsSystem;
using System.Collections.Generic;
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;
UserName = _configService.Read(nameof(SWS.CAD.Models.NoEntity.ConfigIni.UserName));
sPASSWORD = _configService.Read(nameof(SWS.CAD.Models.NoEntity.ConfigIni.UserPs));
if (string.IsNullOrEmpty(sPASSWORD))
{
rememberPs = false;
}
else
{
rememberPs = true;
}
if (GlobalObject.userInfo != null && rememberPs)
{
sPASSWORD = GlobalObject.userInfo.userPs;
}
curServer = "当前服务器: " + _configService.Read(nameof(ConfigIni.Address)) + ":" + _configService.Read(nameof(ConfigIni.Port));
}
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(SWS.CAD.Models.NoEntity.ConfigIni.UserName), UserName);
if (rememberPs)
{
_configService.Save(nameof(SWS.CAD.Models.NoEntity.ConfigIni.UserPs), Userpass);
}
else
{
_configService.Save(nameof(SWS.CAD.Models.NoEntity.ConfigIni.UserPs), "");
}
#region 西
await _UserService.GetList();
#endregion
CloseWindowAction?.Invoke();
}
else
{
Application.ShowAlertDialog(res);
}
}
}
}
}