using System.Windows;
using System.Windows.Input;
using DI_Electrical.Views;
using Prism.Ioc;
using SWS.Commons;
using SWS.Model;
using SWS.Service;
using Telerik.Windows.Controls;
using Unity;
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
///
/// 设置
///
public ICommand Command_Config { get; set; }
LoginService _Service;
ConfigService _configService;
UserService _UserService;
IContainerProvider containerProvider;
public LoginViewModel(IContainerProvider container)
{
title = "系统登录";
_UserService = container.Resolve();
_Service = container.Resolve();
_configService = container.Resolve();
Command_Config = new DelegateCommand(onConfig);
containerProvider = container;
if (GlobalObject.isConfigIniCreateBySys)
{
var config = container.Resolve();
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("strIPAddress") + ":" + _configService.Read("nPort");
}
public void onConfig(object o)
{
var config = containerProvider.Resolve();
config.ShowDialog();
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))
{
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);
}
}
}
}
}