EPLAN_PROD_Plugin/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LoginViewModel.cs

124 lines
3.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
}
}
}
}