105040 Update 优化登录功能
This commit is contained in:
parent
5bd1f06409
commit
d10a53773e
|
@ -10,6 +10,7 @@
|
|||
Width="320"
|
||||
Height="280"
|
||||
d:DataContext="{d:DesignInstance Type=viewmodel:LoginViewModel}"
|
||||
Loaded="Window_Loaded"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
mc:Ignorable="d">
|
||||
<Window.Resources>
|
||||
|
|
|
@ -1,18 +1,11 @@
|
|||
using Sinvo.EplanHpD.Plugin.Service;
|
||||
using EPLAN.Harness.Core.Settings;
|
||||
using Newtonsoft.Json;
|
||||
using Sinvo.EplanHpD.Plugin.Service;
|
||||
using Sinvo.EplanHpD.Plugin.WPFUI.Models;
|
||||
using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace Sinvo.EplanHpD.Plugin.WPFUI.View
|
||||
{
|
||||
|
@ -68,22 +61,18 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
|
|||
|
||||
private async Task LoadData()
|
||||
{
|
||||
//if (viewModel.User != null)
|
||||
//{
|
||||
// viewModel.GetGroup();
|
||||
//}
|
||||
//if (viewModel.IsRemember)
|
||||
//{
|
||||
// var groupIndex = viewModel.Groups.IndexOf(viewModel.Groups.FirstOrDefault(x => x.ID == viewModel.User.UserGroupId));
|
||||
// this.groupCbx.SelectedIndex = groupIndex;
|
||||
// var roleIndex = viewModel.Roles.IndexOf(viewModel.Roles.FirstOrDefault(x => x.ID == viewModel.User.UserRoleId));
|
||||
// this.roleCbx.SelectedIndex = roleIndex;
|
||||
//}
|
||||
//if (EplSession.Current.Config != null)
|
||||
//{
|
||||
// var serverIndex = viewModel.Servers.IndexOf(viewModel.Servers.FirstOrDefault(x => x.ServerUrl == EplSession.Current.Config.CurrentServer.ServerUrl));
|
||||
// this.serverCbx.SelectedIndex = serverIndex;
|
||||
//}
|
||||
var userInfoJson = FormUISettings.Instance.GetValue("UserInfo") as string;
|
||||
var user = JsonConvert.DeserializeObject<UserLoginModel>(userInfoJson);
|
||||
if (user != null && !string.IsNullOrEmpty(user.UserName))
|
||||
{
|
||||
viewModel.User = user;
|
||||
viewModel.IsRemember = true;
|
||||
_ = this.Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
this.PasswordTxt.Password = user.UserPassword;
|
||||
LoadGroupAndRole();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void loginBtn_Click(object sender, RoutedEventArgs e)
|
||||
|
@ -130,6 +119,17 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
|
|||
ID = result.ID,
|
||||
Name = result.Name
|
||||
};
|
||||
|
||||
if (viewModel.IsRemember)
|
||||
{
|
||||
FormUISettings.Instance.SetValue("UserInfo", JsonConvert.SerializeObject(viewModel.User));
|
||||
FormUISettings.Instance.SaveSingleton();
|
||||
}
|
||||
else
|
||||
{
|
||||
FormUISettings.Instance.SetValue("UserInfo", "{}");
|
||||
FormUISettings.Instance.SaveSingleton();
|
||||
}
|
||||
this.DialogResult = true;
|
||||
this.Close();
|
||||
}
|
||||
|
@ -137,6 +137,8 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
|
|||
{
|
||||
MessageBox.Show("登录失败,请检查用户名和密码是否正确!");
|
||||
}
|
||||
|
||||
|
||||
// if (result)
|
||||
// {
|
||||
// //MessageBox.Show("")
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
using Sinvo.EplanHpD.Plugin.DynaClient;
|
||||
using Sinvo.EplanHpD.Plugin.DynaClient.Model;
|
||||
using Sinvo.EplanHpD.Plugin.Service;
|
||||
using Sinvo.EplanHpD.Plugin.WPFUI.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
|
||||
|
@ -75,6 +70,18 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
|
|||
}
|
||||
}
|
||||
|
||||
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(() =>
|
||||
|
|
|
@ -59,9 +59,8 @@ namespace Sinvo.EplanHpD.Plugin
|
|||
|
||||
public void Execute(HpdApi api)
|
||||
{
|
||||
|
||||
bool isLogin = false;
|
||||
if (!PluginServices.IsLogin)
|
||||
bool isLogin = PluginServices.IsLogin;
|
||||
if (!isLogin)
|
||||
{
|
||||
var LoginWindow = new LoginWindow();
|
||||
if(LoginWindow.ShowDialog() == true)
|
||||
|
@ -69,11 +68,9 @@ namespace Sinvo.EplanHpD.Plugin
|
|||
isLogin = PluginServices.IsLogin;
|
||||
}
|
||||
}
|
||||
|
||||
new DBHelper().CodeFirst();
|
||||
|
||||
if (isLogin)
|
||||
{
|
||||
new DBHelper().CodeFirst();
|
||||
var doc = api.CurrentProject.GetActiveDocument();
|
||||
if (window == null)
|
||||
{
|
||||
|
@ -96,9 +93,7 @@ namespace Sinvo.EplanHpD.Plugin
|
|||
window.Activate();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
if (!AppDomainDllLoader.isLoaded)
|
||||
|
@ -106,11 +101,8 @@ namespace Sinvo.EplanHpD.Plugin
|
|||
AppDomainDllLoader.SetLaoder();
|
||||
ApplicationExt.InitApplication();
|
||||
Consts.InitConfigs();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Terminate()
|
||||
{
|
||||
|
||||
|
|
|
@ -4,9 +4,11 @@ using EPLAN.Harness.API.Plugins.Core;
|
|||
using EPLAN.Harness.Core.Controls;
|
||||
using EPLAN.Harness.ProjectCore;
|
||||
using Sinvo.EplanHpD.Plugin.DynaClient;
|
||||
using Sinvo.EplanHpD.Plugin.Service;
|
||||
using Sinvo.EplanHpD.Plugin.WPFUI;
|
||||
using Sinvo.EplanHpD.Plugin.WPFUI.Extension;
|
||||
using Sinvo.EplanHpD.Plugin.WPFUI.Utils;
|
||||
using Sinvo.EplanHpD.Plugin.WPFUI.View;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
|
@ -59,6 +61,18 @@ namespace Sinvo.EplanHpD.Plugin
|
|||
private MainWindow window;
|
||||
public void Execute(HpdApi api)
|
||||
{
|
||||
bool isLogin = PluginServices.IsLogin;
|
||||
if (!isLogin)
|
||||
{
|
||||
var LoginWindow = new LoginWindow();
|
||||
if (LoginWindow.ShowDialog() == true)
|
||||
{
|
||||
isLogin = PluginServices.IsLogin;
|
||||
}
|
||||
}
|
||||
if (isLogin)
|
||||
{
|
||||
|
||||
bool isUpdated = false;
|
||||
try
|
||||
{
|
||||
|
@ -85,10 +99,6 @@ namespace Sinvo.EplanHpD.Plugin
|
|||
isUpdated = true;
|
||||
}
|
||||
}
|
||||
// 取可见的列
|
||||
//var columns = flexReport.Reporter.Formater.RepColumns;
|
||||
//var datas = flexReport.GetAllReportEntries();
|
||||
//var window = new MainWindow(datas, columns);
|
||||
try
|
||||
{
|
||||
|
||||
|
@ -116,7 +126,6 @@ namespace Sinvo.EplanHpD.Plugin
|
|||
window.Show();
|
||||
window.Activate();
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
@ -125,8 +134,6 @@ namespace Sinvo.EplanHpD.Plugin
|
|||
ElementHost.EnableModelessKeyboardInterop(window);
|
||||
window.Show();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -137,7 +144,6 @@ namespace Sinvo.EplanHpD.Plugin
|
|||
else
|
||||
{
|
||||
FlexMessageBox.Error("请打开一个报表后再使用!");
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -145,6 +151,7 @@ namespace Sinvo.EplanHpD.Plugin
|
|||
FlexMessageBox.Error(ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue