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,13 +119,26 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
|
|||
ID = result.ID,
|
||||
Name = result.Name
|
||||
};
|
||||
this.DialogResult = true;
|
||||
|
||||
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();
|
||||
}
|
||||
else
|
||||
{
|
||||
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,21 +59,18 @@ 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)
|
||||
{
|
||||
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()
|
||||
{
|
||||
|
||||
|
|
|
@ -3,10 +3,12 @@ using EPLAN.Harness.API.Plugins;
|
|||
using EPLAN.Harness.API.Plugins.Core;
|
||||
using EPLAN.Harness.Core.Controls;
|
||||
using EPLAN.Harness.ProjectCore;
|
||||
using Sinvo.EplanHpD.Plugin.DynaClient;
|
||||
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,91 +61,96 @@ namespace Sinvo.EplanHpD.Plugin
|
|||
private MainWindow window;
|
||||
public void Execute(HpdApi api)
|
||||
{
|
||||
bool isUpdated = false;
|
||||
try
|
||||
bool isLogin = PluginServices.IsLogin;
|
||||
if (!isLogin)
|
||||
{
|
||||
var doc = api.CurrentProject.GetActiveDocument();
|
||||
//doc.ID
|
||||
//if(doc is FlexReport)
|
||||
if (doc is EPLAN.Harness.API.Projects.Documents.Report report)
|
||||
var LoginWindow = new LoginWindow();
|
||||
if (LoginWindow.ShowDialog() == true)
|
||||
{
|
||||
var reportId = report.ID;
|
||||
var allReports = FlexProject.CurrentProject.GetReports();
|
||||
if (allReports.Any(item => item.ID == reportId))
|
||||
isLogin = PluginServices.IsLogin;
|
||||
}
|
||||
}
|
||||
if (isLogin)
|
||||
{
|
||||
|
||||
bool isUpdated = false;
|
||||
try
|
||||
{
|
||||
var doc = api.CurrentProject.GetActiveDocument();
|
||||
//doc.ID
|
||||
//if(doc is FlexReport)
|
||||
if (doc is EPLAN.Harness.API.Projects.Documents.Report report)
|
||||
{
|
||||
var flexReport = allReports.Where(item => item.ID == reportId).First();
|
||||
if (flexReport != null)
|
||||
var reportId = report.ID;
|
||||
var allReports = FlexProject.CurrentProject.GetReports();
|
||||
if (allReports.Any(item => item.ID == reportId))
|
||||
{
|
||||
var isNeedUpdate = FlexReport.IsUpToDate(flexReport);
|
||||
if (!isNeedUpdate)
|
||||
var flexReport = allReports.Where(item => item.ID == reportId).First();
|
||||
if (flexReport != null)
|
||||
{
|
||||
if (FlexMessageBox.Warning(FlexMessageBox.Buttons.OK_CANCEL,
|
||||
"Report",
|
||||
"报表数据不是最新的,是否更新?", false) == DialogResult.OK)
|
||||
var isNeedUpdate = FlexReport.IsUpToDate(flexReport);
|
||||
if (!isNeedUpdate)
|
||||
{
|
||||
flexReport.UpdateReport();
|
||||
isUpdated = true;
|
||||
}
|
||||
}
|
||||
// 取可见的列
|
||||
//var columns = flexReport.Reporter.Formater.RepColumns;
|
||||
//var datas = flexReport.GetAllReportEntries();
|
||||
//var window = new MainWindow(datas, columns);
|
||||
try
|
||||
{
|
||||
|
||||
if (window == null)
|
||||
{
|
||||
|
||||
window = new MainWindow(flexReport);
|
||||
ElementHost.EnableModelessKeyboardInterop(window);
|
||||
window.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isUpdated)
|
||||
if (FlexMessageBox.Warning(FlexMessageBox.Buttons.OK_CANCEL,
|
||||
"Report",
|
||||
"报表数据不是最新的,是否更新?", false) == DialogResult.OK)
|
||||
{
|
||||
window.Close();
|
||||
flexReport.UpdateReport();
|
||||
isUpdated = true;
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
|
||||
if (window == null)
|
||||
{
|
||||
|
||||
window = new MainWindow(flexReport);
|
||||
ElementHost.EnableModelessKeyboardInterop(window);
|
||||
window.Show();
|
||||
}
|
||||
window.ShowActivated = true;
|
||||
if (window.WindowState == System.Windows.WindowState.Minimized)
|
||||
else
|
||||
{
|
||||
window.WindowState = System.Windows.WindowState.Normal;
|
||||
if (isUpdated)
|
||||
{
|
||||
window.Close();
|
||||
window = new MainWindow(flexReport);
|
||||
ElementHost.EnableModelessKeyboardInterop(window);
|
||||
window.Show();
|
||||
}
|
||||
window.ShowActivated = true;
|
||||
if (window.WindowState == System.Windows.WindowState.Minimized)
|
||||
{
|
||||
window.WindowState = System.Windows.WindowState.Normal;
|
||||
}
|
||||
window.Show();
|
||||
window.Activate();
|
||||
}
|
||||
window.Show();
|
||||
window.Activate();
|
||||
}
|
||||
|
||||
catch (Exception)
|
||||
{
|
||||
window = new MainWindow(flexReport);
|
||||
// 解决WPF窗体在WinForm中无法输入的问题
|
||||
ElementHost.EnableModelessKeyboardInterop(window);
|
||||
window.Show();
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
window = new MainWindow(flexReport);
|
||||
// 解决WPF窗体在WinForm中无法输入的问题
|
||||
ElementHost.EnableModelessKeyboardInterop(window);
|
||||
window.Show();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
FlexMessageBox.Error("未找到项目中匹配的报表,请检查是否生成成功或是未保存到项目中!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FlexMessageBox.Error("未找到项目中匹配的报表,请检查是否生成成功或是未保存到项目中!");
|
||||
FlexMessageBox.Error("请打开一个报表后再使用!");
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
FlexMessageBox.Error("请打开一个报表后再使用!");
|
||||
|
||||
FlexMessageBox.Error(ex.ToString());
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FlexMessageBox.Error(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
|
|
Loading…
Reference in New Issue