2024-10-24 18:01:26 +08:00
|
|
|
|
using EPLAN.Harness.API;
|
|
|
|
|
using EPLAN.Harness.API.Plugins;
|
|
|
|
|
using EPLAN.Harness.API.Plugins.Core;
|
|
|
|
|
using EPLAN.Harness.Core.Controls;
|
|
|
|
|
using EPLAN.Harness.ProjectCore;
|
2025-04-10 10:19:41 +08:00
|
|
|
|
using Sinvo.EplanHpD.Plugin.DynaClient;
|
|
|
|
|
using Sinvo.EplanHpD.Plugin.Service;
|
2024-10-24 18:01:26 +08:00
|
|
|
|
using Sinvo.EplanHpD.Plugin.WPFUI;
|
2024-12-10 17:02:58 +08:00
|
|
|
|
using Sinvo.EplanHpD.Plugin.WPFUI.Extension;
|
2024-11-15 15:02:16 +08:00
|
|
|
|
using Sinvo.EplanHpD.Plugin.WPFUI.Utils;
|
2025-04-10 10:19:41 +08:00
|
|
|
|
using Sinvo.EplanHpD.Plugin.WPFUI.View;
|
2024-10-24 18:01:26 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Windows.Forms;
|
2024-10-25 15:17:12 +08:00
|
|
|
|
using System.Windows.Forms.Integration;
|
2024-10-24 18:01:26 +08:00
|
|
|
|
|
|
|
|
|
namespace Sinvo.EplanHpD.Plugin
|
|
|
|
|
{
|
2025-02-10 16:14:25 +08:00
|
|
|
|
#if Release_WireAndCable || DEBUG
|
2024-10-24 18:01:26 +08:00
|
|
|
|
public class PluginEntry : IHpDPlugin
|
2025-02-10 11:38:43 +08:00
|
|
|
|
#else
|
|
|
|
|
public class PluginEntry
|
|
|
|
|
#endif
|
2024-10-24 18:01:26 +08:00
|
|
|
|
{
|
|
|
|
|
public string Name => "兴禾ProD插件";
|
|
|
|
|
|
|
|
|
|
public string Author => "Sinvo";
|
|
|
|
|
|
|
|
|
|
public string Description => "兴禾EPLAN Harness proD 2.9 Studio插件,提供检查线材资料功能";
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取DLL版本
|
|
|
|
|
/// </summary>
|
2024-11-07 12:13:19 +08:00
|
|
|
|
public Version Version => Assembly.GetAssembly(this.GetType()).GetName().Version;
|
2024-10-24 18:01:26 +08:00
|
|
|
|
|
|
|
|
|
public System.Drawing.Image ToolbarIcon
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var imageBytes = Resource.Sinvo;
|
|
|
|
|
if (imageBytes != null)
|
|
|
|
|
{
|
|
|
|
|
using (var ms = new MemoryStream(imageBytes))
|
|
|
|
|
{
|
|
|
|
|
return Image.FromStream(ms);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string ToolbarText => "线材资料检查";
|
|
|
|
|
|
|
|
|
|
public string ToolbarTooltip => "线材资料检查";
|
|
|
|
|
|
|
|
|
|
public HpDModule Module => HpDModule.Report;
|
|
|
|
|
|
2024-10-29 10:23:27 +08:00
|
|
|
|
private MainWindow window;
|
2024-10-24 18:01:26 +08:00
|
|
|
|
public void Execute(HpdApi api)
|
|
|
|
|
{
|
2025-04-25 16:25:45 +08:00
|
|
|
|
bool isLogin = PluginServices.IsLogin;
|
|
|
|
|
if (!isLogin)
|
2025-04-24 14:22:46 +08:00
|
|
|
|
{
|
2025-04-25 16:25:45 +08:00
|
|
|
|
var LoginWindow = new LoginWindow();
|
|
|
|
|
if (LoginWindow.ShowDialog() == true)
|
2025-04-10 10:19:41 +08:00
|
|
|
|
{
|
2025-04-25 16:25:45 +08:00
|
|
|
|
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)
|
2024-10-24 18:01:26 +08:00
|
|
|
|
{
|
2025-04-25 16:25:45 +08:00
|
|
|
|
var reportId = report.ID;
|
|
|
|
|
var allReports = FlexProject.CurrentProject.GetReports();
|
|
|
|
|
if (allReports.Any(item => item.ID == reportId))
|
2024-10-24 18:01:26 +08:00
|
|
|
|
{
|
2025-04-25 16:25:45 +08:00
|
|
|
|
var flexReport = allReports.Where(item => item.ID == reportId).First();
|
|
|
|
|
if (flexReport != null)
|
2024-10-24 18:01:26 +08:00
|
|
|
|
{
|
2025-04-25 16:25:45 +08:00
|
|
|
|
var isNeedUpdate = FlexReport.IsUpToDate(flexReport);
|
|
|
|
|
if (!isNeedUpdate)
|
2024-10-24 18:01:26 +08:00
|
|
|
|
{
|
2025-04-25 16:25:45 +08:00
|
|
|
|
if (FlexMessageBox.Warning(FlexMessageBox.Buttons.OK_CANCEL,
|
|
|
|
|
"Report",
|
|
|
|
|
"报表数据不是最新的,是否更新?", false) == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
flexReport.UpdateReport();
|
|
|
|
|
isUpdated = true;
|
|
|
|
|
}
|
2024-10-24 18:01:26 +08:00
|
|
|
|
}
|
2025-04-25 16:25:45 +08:00
|
|
|
|
try
|
2024-10-29 10:23:27 +08:00
|
|
|
|
{
|
|
|
|
|
|
2025-04-25 16:25:45 +08:00
|
|
|
|
if (window == null)
|
2024-10-29 10:23:27 +08:00
|
|
|
|
{
|
2025-04-25 16:25:45 +08:00
|
|
|
|
|
2024-10-29 10:23:27 +08:00
|
|
|
|
window = new MainWindow(flexReport);
|
|
|
|
|
ElementHost.EnableModelessKeyboardInterop(window);
|
|
|
|
|
window.Show();
|
|
|
|
|
}
|
2025-04-25 16:25:45 +08:00
|
|
|
|
else
|
2024-10-29 10:23:27 +08:00
|
|
|
|
{
|
2025-04-25 16:25:45 +08:00
|
|
|
|
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();
|
2024-10-29 10:23:27 +08:00
|
|
|
|
}
|
2025-04-25 16:25:45 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
window = new MainWindow(flexReport);
|
|
|
|
|
// 解决WPF窗体在WinForm中无法输入的问题
|
|
|
|
|
ElementHost.EnableModelessKeyboardInterop(window);
|
2024-10-29 10:23:27 +08:00
|
|
|
|
window.Show();
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-04-25 16:25:45 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FlexMessageBox.Error("未找到项目中匹配的报表,请检查是否生成成功或是未保存到项目中!");
|
2024-10-24 18:01:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-04-25 16:25:45 +08:00
|
|
|
|
FlexMessageBox.Error("请打开一个报表后再使用!");
|
2024-10-24 18:01:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2025-04-25 16:25:45 +08:00
|
|
|
|
catch (Exception ex)
|
2024-10-24 18:01:26 +08:00
|
|
|
|
{
|
2025-04-25 16:25:45 +08:00
|
|
|
|
FlexMessageBox.Error(ex.ToString());
|
2024-10-24 18:01:26 +08:00
|
|
|
|
}
|
2025-04-24 14:22:46 +08:00
|
|
|
|
}
|
2024-10-24 18:01:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Initialize()
|
|
|
|
|
{
|
2025-03-28 16:47:05 +08:00
|
|
|
|
if (!AppDomainDllLoader.isLoaded)
|
|
|
|
|
{
|
|
|
|
|
//throw new NotImplementedException();
|
|
|
|
|
AppDomainDllLoader.SetLaoder();
|
|
|
|
|
ApplicationExt.InitApplication();
|
|
|
|
|
Consts.InitConfigs();
|
|
|
|
|
}
|
2024-10-24 18:01:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Terminate()
|
|
|
|
|
{
|
|
|
|
|
//throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|