105040 Update 优化登录功能
This commit is contained in:
parent
5bd1f06409
commit
d10a53773e
|
|
@ -10,6 +10,7 @@
|
||||||
Width="320"
|
Width="320"
|
||||||
Height="280"
|
Height="280"
|
||||||
d:DataContext="{d:DesignInstance Type=viewmodel:LoginViewModel}"
|
d:DataContext="{d:DesignInstance Type=viewmodel:LoginViewModel}"
|
||||||
|
Loaded="Window_Loaded"
|
||||||
WindowStartupLocation="CenterScreen"
|
WindowStartupLocation="CenterScreen"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
<Window.Resources>
|
<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 Sinvo.EplanHpD.Plugin.WPFUI.ViewModel;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
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
|
namespace Sinvo.EplanHpD.Plugin.WPFUI.View
|
||||||
{
|
{
|
||||||
|
|
@ -68,22 +61,18 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
|
||||||
|
|
||||||
private async Task LoadData()
|
private async Task LoadData()
|
||||||
{
|
{
|
||||||
//if (viewModel.User != null)
|
var userInfoJson = FormUISettings.Instance.GetValue("UserInfo") as string;
|
||||||
//{
|
var user = JsonConvert.DeserializeObject<UserLoginModel>(userInfoJson);
|
||||||
// viewModel.GetGroup();
|
if (user != null && !string.IsNullOrEmpty(user.UserName))
|
||||||
//}
|
{
|
||||||
//if (viewModel.IsRemember)
|
viewModel.User = user;
|
||||||
//{
|
viewModel.IsRemember = true;
|
||||||
// var groupIndex = viewModel.Groups.IndexOf(viewModel.Groups.FirstOrDefault(x => x.ID == viewModel.User.UserGroupId));
|
_ = this.Dispatcher.BeginInvoke(() =>
|
||||||
// this.groupCbx.SelectedIndex = groupIndex;
|
{
|
||||||
// var roleIndex = viewModel.Roles.IndexOf(viewModel.Roles.FirstOrDefault(x => x.ID == viewModel.User.UserRoleId));
|
this.PasswordTxt.Password = user.UserPassword;
|
||||||
// this.roleCbx.SelectedIndex = roleIndex;
|
LoadGroupAndRole();
|
||||||
//}
|
});
|
||||||
//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;
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loginBtn_Click(object sender, RoutedEventArgs e)
|
private void loginBtn_Click(object sender, RoutedEventArgs e)
|
||||||
|
|
@ -130,13 +119,26 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
|
||||||
ID = result.ID,
|
ID = result.ID,
|
||||||
Name = result.Name
|
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();
|
this.Close();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show("登录失败,请检查用户名和密码是否正确!");
|
MessageBox.Show("登录失败,请检查用户名和密码是否正确!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// if (result)
|
// if (result)
|
||||||
// {
|
// {
|
||||||
// //MessageBox.Show("")
|
// //MessageBox.Show("")
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,10 @@
|
||||||
using Sinvo.EplanHpD.Plugin.DynaClient;
|
using Sinvo.EplanHpD.Plugin.DynaClient;
|
||||||
using Sinvo.EplanHpD.Plugin.DynaClient.Model;
|
using Sinvo.EplanHpD.Plugin.DynaClient.Model;
|
||||||
using Sinvo.EplanHpD.Plugin.Service;
|
|
||||||
using Sinvo.EplanHpD.Plugin.WPFUI.Models;
|
using Sinvo.EplanHpD.Plugin.WPFUI.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Specialized;
|
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
|
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()
|
public async Task<List<UserGroup>> GetUserGroup()
|
||||||
{
|
{
|
||||||
return await Task.Run(() =>
|
return await Task.Run(() =>
|
||||||
|
|
|
||||||
|
|
@ -59,21 +59,18 @@ namespace Sinvo.EplanHpD.Plugin
|
||||||
|
|
||||||
public void Execute(HpdApi api)
|
public void Execute(HpdApi api)
|
||||||
{
|
{
|
||||||
|
bool isLogin = PluginServices.IsLogin;
|
||||||
bool isLogin = false;
|
if (!isLogin)
|
||||||
if (!PluginServices.IsLogin)
|
|
||||||
{
|
{
|
||||||
var LoginWindow = new LoginWindow();
|
var LoginWindow = new LoginWindow();
|
||||||
if(LoginWindow.ShowDialog() == true)
|
if(LoginWindow.ShowDialog() == true)
|
||||||
{
|
{
|
||||||
isLogin = PluginServices.IsLogin;
|
isLogin = PluginServices.IsLogin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new DBHelper().CodeFirst();
|
|
||||||
|
|
||||||
if (isLogin)
|
if (isLogin)
|
||||||
{
|
{
|
||||||
|
new DBHelper().CodeFirst();
|
||||||
var doc = api.CurrentProject.GetActiveDocument();
|
var doc = api.CurrentProject.GetActiveDocument();
|
||||||
if (window == null)
|
if (window == null)
|
||||||
{
|
{
|
||||||
|
|
@ -96,9 +93,7 @@ namespace Sinvo.EplanHpD.Plugin
|
||||||
window.Activate();
|
window.Activate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
if (!AppDomainDllLoader.isLoaded)
|
if (!AppDomainDllLoader.isLoaded)
|
||||||
|
|
@ -106,11 +101,8 @@ namespace Sinvo.EplanHpD.Plugin
|
||||||
AppDomainDllLoader.SetLaoder();
|
AppDomainDllLoader.SetLaoder();
|
||||||
ApplicationExt.InitApplication();
|
ApplicationExt.InitApplication();
|
||||||
Consts.InitConfigs();
|
Consts.InitConfigs();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void Terminate()
|
public void Terminate()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,12 @@ using EPLAN.Harness.API.Plugins;
|
||||||
using EPLAN.Harness.API.Plugins.Core;
|
using EPLAN.Harness.API.Plugins.Core;
|
||||||
using EPLAN.Harness.Core.Controls;
|
using EPLAN.Harness.Core.Controls;
|
||||||
using EPLAN.Harness.ProjectCore;
|
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;
|
||||||
using Sinvo.EplanHpD.Plugin.WPFUI.Extension;
|
using Sinvo.EplanHpD.Plugin.WPFUI.Extension;
|
||||||
using Sinvo.EplanHpD.Plugin.WPFUI.Utils;
|
using Sinvo.EplanHpD.Plugin.WPFUI.Utils;
|
||||||
|
using Sinvo.EplanHpD.Plugin.WPFUI.View;
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
@ -59,91 +61,96 @@ namespace Sinvo.EplanHpD.Plugin
|
||||||
private MainWindow window;
|
private MainWindow window;
|
||||||
public void Execute(HpdApi api)
|
public void Execute(HpdApi api)
|
||||||
{
|
{
|
||||||
bool isUpdated = false;
|
bool isLogin = PluginServices.IsLogin;
|
||||||
try
|
if (!isLogin)
|
||||||
{
|
{
|
||||||
var doc = api.CurrentProject.GetActiveDocument();
|
var LoginWindow = new LoginWindow();
|
||||||
//doc.ID
|
if (LoginWindow.ShowDialog() == true)
|
||||||
//if(doc is FlexReport)
|
|
||||||
if (doc is EPLAN.Harness.API.Projects.Documents.Report report)
|
|
||||||
{
|
{
|
||||||
var reportId = report.ID;
|
isLogin = PluginServices.IsLogin;
|
||||||
var allReports = FlexProject.CurrentProject.GetReports();
|
}
|
||||||
if (allReports.Any(item => item.ID == reportId))
|
}
|
||||||
|
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();
|
var reportId = report.ID;
|
||||||
if (flexReport != null)
|
var allReports = FlexProject.CurrentProject.GetReports();
|
||||||
|
if (allReports.Any(item => item.ID == reportId))
|
||||||
{
|
{
|
||||||
var isNeedUpdate = FlexReport.IsUpToDate(flexReport);
|
var flexReport = allReports.Where(item => item.ID == reportId).First();
|
||||||
if (!isNeedUpdate)
|
if (flexReport != null)
|
||||||
{
|
{
|
||||||
if (FlexMessageBox.Warning(FlexMessageBox.Buttons.OK_CANCEL,
|
var isNeedUpdate = FlexReport.IsUpToDate(flexReport);
|
||||||
"Report",
|
if (!isNeedUpdate)
|
||||||
"报表数据不是最新的,是否更新?", false) == DialogResult.OK)
|
|
||||||
{
|
{
|
||||||
flexReport.UpdateReport();
|
if (FlexMessageBox.Warning(FlexMessageBox.Buttons.OK_CANCEL,
|
||||||
isUpdated = true;
|
"Report",
|
||||||
}
|
"报表数据不是最新的,是否更新?", false) == DialogResult.OK)
|
||||||
}
|
|
||||||
// 取可见的列
|
|
||||||
//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)
|
|
||||||
{
|
{
|
||||||
window.Close();
|
flexReport.UpdateReport();
|
||||||
|
isUpdated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
if (window == null)
|
||||||
|
{
|
||||||
|
|
||||||
window = new MainWindow(flexReport);
|
window = new MainWindow(flexReport);
|
||||||
ElementHost.EnableModelessKeyboardInterop(window);
|
ElementHost.EnableModelessKeyboardInterop(window);
|
||||||
window.Show();
|
window.Show();
|
||||||
}
|
}
|
||||||
window.ShowActivated = true;
|
else
|
||||||
if (window.WindowState == System.Windows.WindowState.Minimized)
|
|
||||||
{
|
{
|
||||||
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)
|
}
|
||||||
{
|
else
|
||||||
window = new MainWindow(flexReport);
|
{
|
||||||
// 解决WPF窗体在WinForm中无法输入的问题
|
FlexMessageBox.Error("未找到项目中匹配的报表,请检查是否生成成功或是未保存到项目中!");
|
||||||
ElementHost.EnableModelessKeyboardInterop(window);
|
|
||||||
window.Show();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
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()
|
public void Initialize()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue