153 lines
4.5 KiB
C#
153 lines
4.5 KiB
C#
using System.Threading;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
using DI_Electrical.Helper;
|
|
using DI_Electrical.Model;
|
|
using DI_Electrical.Services;
|
|
using DI_Electrical.Views;
|
|
using Prism.Events;
|
|
using Prism.Ioc;
|
|
using Prism.Mvvm;
|
|
using Prism.Services.Dialogs;
|
|
using Telerik.Windows.Controls;
|
|
using Unity;
|
|
using DialogParameters = Prism.Services.Dialogs.DialogParameters;
|
|
|
|
namespace DI_Electrical.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
|
|
/// <summary>
|
|
/// 设置
|
|
/// </summary>
|
|
public ICommand Command_Config { get; set; }
|
|
LoginService _Service;
|
|
ConfigService _configService;
|
|
UserService _UserService;
|
|
IContainerProvider containerProvider;
|
|
public LoginViewModel(IContainerProvider container)
|
|
{
|
|
title = "系统登录";
|
|
_UserService = container.Resolve<UserService>();
|
|
_Service = container.Resolve<LoginService>();
|
|
_configService = container.Resolve<ConfigService>();
|
|
Command_Config = new DelegateCommand(onConfig);
|
|
containerProvider = container;
|
|
if (GlobalObject.isConfigIniCreateBySys)
|
|
{
|
|
var config= container.Resolve<Config>();
|
|
config.ShowDialog();
|
|
}
|
|
|
|
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(nameof(ConfigIni.Address)) + ":" + _configService.Read(nameof(ConfigIni.Port));
|
|
|
|
}
|
|
public void onConfig(object o)
|
|
{
|
|
var config = containerProvider.Resolve<Config>();
|
|
config.ShowDialog();
|
|
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))
|
|
{
|
|
MessageBox.Show("用户名和密码不能为空!");
|
|
}
|
|
else
|
|
{
|
|
IsBusy = true; BusyContent = "登录中...";
|
|
var res = await _Service.Login(UserName, Userpass);
|
|
IsBusy = false;
|
|
if (string.IsNullOrEmpty(res))
|
|
{
|
|
_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
|
|
{
|
|
MessageBox.Show(res);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|