124 lines
3.1 KiB
C#
124 lines
3.1 KiB
C#
using Sinvo.EplanHpD.Plugin.DynaClient;
|
||
using Sinvo.EplanHpD.Plugin.DynaClient.Model;
|
||
using Sinvo.EplanHpD.Plugin.WPFUI.Models;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Diagnostics;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
|
||
{
|
||
public class LoginViewModel: INotifyPropertyChanged
|
||
{
|
||
private readonly DynaServerClient client = DynaServerClient.GetClient();
|
||
public event PropertyChangedEventHandler PropertyChanged;
|
||
public void OnPropertyChanged(string propertyName)
|
||
{
|
||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||
}
|
||
|
||
public LoginViewModel()
|
||
{
|
||
User = new UserLoginModel();
|
||
}
|
||
|
||
private UserLoginModel _user;
|
||
|
||
public UserLoginModel User
|
||
{
|
||
get { return _user; }
|
||
set
|
||
{
|
||
_user = value;
|
||
OnPropertyChanged(nameof(User));
|
||
}
|
||
}
|
||
|
||
|
||
private List<UserGroup> _groups;
|
||
public List<UserGroup> Groups
|
||
{
|
||
get { return _groups; }
|
||
set
|
||
{
|
||
_groups = value;
|
||
OnPropertyChanged(nameof(Groups));
|
||
}
|
||
}
|
||
|
||
private List<UserRole> _roles;
|
||
public List<UserRole> Roles
|
||
{
|
||
get { return _roles; }
|
||
set
|
||
{
|
||
_roles = value;
|
||
OnPropertyChanged(nameof(Roles));
|
||
}
|
||
}
|
||
|
||
private List<string> _servers;
|
||
|
||
public List<string> Servers
|
||
{
|
||
get { return _servers; }
|
||
set
|
||
{
|
||
_servers = value;
|
||
OnPropertyChanged(nameof(Servers));
|
||
}
|
||
}
|
||
|
||
private bool _isRemember;
|
||
|
||
public bool IsRemember
|
||
{
|
||
get { return _isRemember; }
|
||
set
|
||
{
|
||
_isRemember = value;
|
||
OnPropertyChanged(nameof(IsRemember));
|
||
}
|
||
}
|
||
|
||
public async Task<List<UserGroup>> GetUserGroup()
|
||
{
|
||
return await Task.Run(() =>
|
||
{
|
||
var userGroup = client.GetUserGroup(User.UserName);
|
||
Groups = userGroup;
|
||
return userGroup;
|
||
});
|
||
}
|
||
|
||
internal Task GetRolesByCurrentSelect()
|
||
{
|
||
//var client = new DynaServerClient();
|
||
var userRoles = client.GetUserRole(User.UserName,User.UserGroup);
|
||
Roles = userRoles;
|
||
return Task.CompletedTask;
|
||
}
|
||
|
||
internal User Login()
|
||
{
|
||
try
|
||
{
|
||
|
||
//var client = new DynaServerClient();
|
||
// PLM 没有EPLAN的许可,所以只能使用SOLW的类型登录
|
||
var user = client.Login(User.UserName, User.UserPassword, User.UserRole, User.UserGroup, "SOLW");
|
||
#if DEBUG
|
||
//client.LoginOut();
|
||
#endif
|
||
return user;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Debug.WriteLine(ex.ToString());
|
||
return null;
|
||
}
|
||
}
|
||
}
|
||
}
|