172 lines
6.4 KiB
C#
172 lines
6.4 KiB
C#
using EPLAN.Harness.API;
|
|
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.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;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Windows.Forms;
|
|
using System.Windows.Forms.Integration;
|
|
|
|
namespace Sinvo.EplanHpD.Plugin
|
|
{
|
|
#if Release_WireAndCable || DEBUG
|
|
public class PluginEntry : IHpDPlugin
|
|
#else
|
|
public class PluginEntry
|
|
#endif
|
|
{
|
|
public string Name => "兴禾ProD插件";
|
|
|
|
public string Author => "Sinvo";
|
|
|
|
public string Description => "兴禾EPLAN Harness proD 2.9 Studio插件,提供检查线材资料功能";
|
|
|
|
/// <summary>
|
|
/// 获取DLL版本
|
|
/// </summary>
|
|
public Version Version => Assembly.GetAssembly(this.GetType()).GetName().Version;
|
|
|
|
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;
|
|
|
|
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
|
|
{
|
|
var doc = api.CurrentProject.GetActiveDocument();
|
|
//doc.ID
|
|
//if(doc is FlexReport)
|
|
if (doc is EPLAN.Harness.API.Projects.Documents.Report report)
|
|
{
|
|
var reportId = report.ID;
|
|
var allReports = FlexProject.CurrentProject.GetReports();
|
|
if (allReports.Any(item => item.ID == reportId))
|
|
{
|
|
var flexReport = allReports.Where(item => item.ID == reportId).First();
|
|
if (flexReport != null)
|
|
{
|
|
var isNeedUpdate = FlexReport.IsUpToDate(flexReport);
|
|
if (!isNeedUpdate)
|
|
{
|
|
if (FlexMessageBox.Warning(FlexMessageBox.Buttons.OK_CANCEL,
|
|
"Report",
|
|
"报表数据不是最新的,是否更新?", false) == DialogResult.OK)
|
|
{
|
|
flexReport.UpdateReport();
|
|
isUpdated = true;
|
|
}
|
|
}
|
|
try
|
|
{
|
|
|
|
if (window == null)
|
|
{
|
|
|
|
window = new MainWindow(flexReport);
|
|
ElementHost.EnableModelessKeyboardInterop(window);
|
|
window.Show();
|
|
}
|
|
else
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
window = new MainWindow(flexReport);
|
|
// 解决WPF窗体在WinForm中无法输入的问题
|
|
ElementHost.EnableModelessKeyboardInterop(window);
|
|
window.Show();
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
FlexMessageBox.Error("未找到项目中匹配的报表,请检查是否生成成功或是未保存到项目中!");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
FlexMessageBox.Error("请打开一个报表后再使用!");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
FlexMessageBox.Error(ex.ToString());
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
if (!AppDomainDllLoader.isLoaded)
|
|
{
|
|
//throw new NotImplementedException();
|
|
AppDomainDllLoader.SetLaoder();
|
|
ApplicationExt.InitApplication();
|
|
Consts.InitConfigs();
|
|
}
|
|
}
|
|
|
|
public void Terminate()
|
|
{
|
|
//throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|