|
|
@@ -1,24 +1,21 @@
|
|
|
|
|
|
using OTS.WinFormsUI.Docking;
|
|
|
-
|
|
|
-using OTSIncAReportApp.OTSRstMgrFunction;
|
|
|
+using OTSCommon.DBOperate.Model;
|
|
|
+using OTSIncAReportApp._1_UI;
|
|
|
using OTSIncAReportApp.OTSRibbon;
|
|
|
+using OTSIncAReportApp.OTSRstMgrFunction;
|
|
|
using OTSIncAReportApp.OTSSampleReportInfo;
|
|
|
-using OTSIncAReportApp.SysMgrTools;
|
|
|
using OTSIncAReportGraph.OTSIncAReportGraphFuncation;
|
|
|
using OTSIncAReprotCharts;
|
|
|
-
|
|
|
using System;
|
|
|
using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Drawing;
|
|
|
using System.IO;
|
|
|
+using System.Linq;
|
|
|
using System.Runtime.InteropServices;
|
|
|
using System.Windows.Forms;
|
|
|
-using OTSCommon.DBOperate.Model;
|
|
|
-using OTSIncAReportApp._1_UI;
|
|
|
using OTSCommon;
|
|
|
-using Language = OTSCommon.Language;
|
|
|
|
|
|
namespace OTSIncAReportApp
|
|
|
{
|
|
|
@@ -198,8 +195,12 @@ namespace OTSIncAReportApp
|
|
|
return Particles;
|
|
|
}
|
|
|
#endregion //--------------------------------------------------------------------------------------------
|
|
|
-
|
|
|
-
|
|
|
+ #region 拖拽提示面板相关字段
|
|
|
+ private Panel dropHintPanel;
|
|
|
+ private PictureBox dropIconBox;
|
|
|
+ private Label dropHintLabel;
|
|
|
+ private Label dropSubLabel;
|
|
|
+ #endregion
|
|
|
#region 窗体初始化及构造函数
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -239,8 +240,9 @@ namespace OTSIncAReportApp
|
|
|
#region 国际化语言
|
|
|
Language lan = new Language(this);
|
|
|
table = lan.GetNameTable(this.Name);
|
|
|
-
|
|
|
#endregion
|
|
|
+ // 初始化拖拽功能
|
|
|
+ InitializeDragDropFeatures();
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -275,10 +277,12 @@ namespace OTSIncAReportApp
|
|
|
/// </summary>
|
|
|
public frmReportApp(string[] str_resultfilepaths)
|
|
|
{
|
|
|
+
|
|
|
m_OutputNlog = new OutputNlog();
|
|
|
m_OutputNlog.Visible = true;
|
|
|
+ Environment.CurrentDirectory = Path.GetDirectoryName(Application.ExecutablePath);
|
|
|
+
|
|
|
|
|
|
-
|
|
|
log = NLog.LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
m_str_resultfilepaths = str_resultfilepaths;
|
|
|
@@ -312,6 +316,8 @@ namespace OTSIncAReportApp
|
|
|
Language lan = new Language(this);
|
|
|
table = lan.GetNameTable(this.Name);
|
|
|
#endregion
|
|
|
+ // 初始化拖拽功能
|
|
|
+ InitializeDragDropFeatures();
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -372,10 +378,31 @@ namespace OTSIncAReportApp
|
|
|
|
|
|
if (m_str_resultfilepaths != null)
|
|
|
{
|
|
|
- //构造函数直接接收传入的测量结果文件,并加载
|
|
|
- for (int i = 0; i < m_str_resultfilepaths.Length; i++)
|
|
|
+ string path = m_str_resultfilepaths[0].Replace("^", " ");
|
|
|
+ if (Path.GetExtension(path) == ".rst")
|
|
|
{
|
|
|
- this.m_RstWindow.AddSampleResult(m_str_resultfilepaths[i].Replace("^", " "));
|
|
|
+ //构造函数直接接收传入的测量结果文件,并加载
|
|
|
+ for (int i = 0; i < m_str_resultfilepaths.Length; i++)
|
|
|
+ {
|
|
|
+ this.m_RstWindow.AddSampleResult(m_str_resultfilepaths[i].Replace("^", " "));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (Path.GetExtension(path) == ".prj")
|
|
|
+ {
|
|
|
+ this.Cursor = Cursors.WaitCursor;
|
|
|
+ string strFilePath = System.IO.Path.GetDirectoryName(path);
|
|
|
+
|
|
|
+ System.IO.DirectoryInfo folder = new System.IO.DirectoryInfo(strFilePath);
|
|
|
+
|
|
|
+ foreach (System.IO.DirectoryInfo directory in folder.GetDirectories())
|
|
|
+ {
|
|
|
+ foreach (System.IO.FileInfo file in directory.GetFiles("*.rst"))
|
|
|
+ {
|
|
|
+ this.m_RstWindow.AddSampleResult(file.FullName);
|
|
|
+ this.m_StandardLibrary.DataRefresh();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.Cursor = Cursors.Default;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1348,6 +1375,267 @@ namespace OTSIncAReportApp
|
|
|
{
|
|
|
OpenProFile();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void frmReportApp_DragDrop(object sender, DragEventArgs e)
|
|
|
+ {
|
|
|
+ // 隐藏拖拽提示面板
|
|
|
+ HideDropHintPanel();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
|
|
+ {
|
|
|
+ string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
|
|
+ // 过滤出有效的文件
|
|
|
+ var validFiles = files.Where(f =>
|
|
|
+ Path.GetExtension(f)?.ToLower() == ".prj" ||
|
|
|
+ Path.GetExtension(f)?.ToLower() == ".rst").ToList();
|
|
|
+
|
|
|
+ if (!validFiles.Any())
|
|
|
+ {
|
|
|
+ MessageBox.Show("未找到有效的 .prj 或 .rst 文件", "提示",
|
|
|
+ MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.Cursor = Cursors.WaitCursor;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ProcessDroppedFiles(validFiles);
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ this.Cursor = Cursors.Default;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ this.Cursor = Cursors.Default;
|
|
|
+ log.Error($"处理拖拽文件时发生错误: {ex.Message}", ex);
|
|
|
+ MessageBox.Show($"处理文件时发生错误: {ex.Message}", "错误",
|
|
|
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void frmReportApp_DragEnter(object sender, DragEventArgs e)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ // 检查拖放的数据是否包含文件
|
|
|
+ if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
|
|
+ {
|
|
|
+ // 获取拖放的文件
|
|
|
+ string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
|
|
+ // 检查是否有有效的.prj文件
|
|
|
+ bool hasValidFile = files.Any(f =>
|
|
|
+ !string.IsNullOrEmpty(Path.GetExtension(f)) &&
|
|
|
+ (Path.GetExtension(f).ToLower() == ".prj"|| Path.GetExtension(f).ToLower() == ".rst"));
|
|
|
+ if (hasValidFile)
|
|
|
+ {
|
|
|
+ // 显示拖拽提示面板
|
|
|
+ ShowDropHintPanel();
|
|
|
+ // 显示复制光标
|
|
|
+ e.Effect = DragDropEffects.Copy;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ log?.Warn($"DragEnter处理异常: {ex.Message}");
|
|
|
+ }
|
|
|
+ // 隐藏拖拽提示面板并设置无效文件类型
|
|
|
+ HideDropHintPanel();
|
|
|
+ e.Effect = DragDropEffects.None;
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 初始化拖拽提示面板
|
|
|
+ /// </summary>
|
|
|
+ private void InitializeDropHintPanel()
|
|
|
+ {
|
|
|
+ // 创建主面板
|
|
|
+ dropHintPanel = new Panel();
|
|
|
+ dropHintPanel.Name = "dropHintPanel";
|
|
|
+ dropHintPanel.BackColor = Color.FromArgb(200, Color.RoyalBlue);
|
|
|
+ dropHintPanel.Dock = DockStyle.Fill;
|
|
|
+ dropHintPanel.Visible = false;
|
|
|
+ dropHintPanel.BorderStyle = BorderStyle.None;
|
|
|
+ // 创建主提示文本
|
|
|
+ dropHintLabel = new Label();
|
|
|
+ dropHintLabel.Text = "拖拽 .prj 或 .rst文件到此处打开项目";
|
|
|
+ dropHintLabel.AutoSize = false;
|
|
|
+ dropHintLabel.TextAlign = ContentAlignment.MiddleCenter;
|
|
|
+ dropHintLabel.Font = new Font(this.Font.FontFamily, 18, FontStyle.Bold);
|
|
|
+ dropHintLabel.ForeColor = Color.White;
|
|
|
+ dropHintLabel.Dock = DockStyle.Fill;
|
|
|
+ dropHintLabel.BackColor = Color.Transparent;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 创建辅助说明文本
|
|
|
+ dropSubLabel = new Label();
|
|
|
+ dropSubLabel.Text = "松开鼠标按键即可打开项目";
|
|
|
+ dropSubLabel.AutoSize = false;
|
|
|
+ dropSubLabel.TextAlign = ContentAlignment.MiddleCenter;
|
|
|
+ dropSubLabel.Font = new Font(this.Font.FontFamily, 12, FontStyle.Regular);
|
|
|
+ dropSubLabel.ForeColor = Color.LightGray;
|
|
|
+ dropSubLabel.Dock = DockStyle.Bottom;
|
|
|
+ dropSubLabel.Height = 30;
|
|
|
+ dropSubLabel.BackColor = Color.Transparent;
|
|
|
+
|
|
|
+ // 组装控件
|
|
|
+ dropHintPanel.Controls.Add(dropIconBox);
|
|
|
+ dropHintPanel.Controls.Add(dropHintLabel);
|
|
|
+ dropHintPanel.Controls.Add(dropSubLabel);
|
|
|
+
|
|
|
+ // 将面板添加到窗体中并置于顶层
|
|
|
+ this.Controls.Add(dropHintPanel);
|
|
|
+ dropHintPanel.BringToFront();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 显示拖拽提示面板
|
|
|
+ /// </summary>
|
|
|
+ private void ShowDropHintPanel()
|
|
|
+ {
|
|
|
+ if (dropHintPanel == null) return;
|
|
|
+
|
|
|
+ dropHintPanel.Visible = true;
|
|
|
+ dropHintPanel.BringToFront();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 隐藏拖拽提示面板
|
|
|
+ /// </summary>
|
|
|
+ private void HideDropHintPanel()
|
|
|
+ {
|
|
|
+ if (dropHintPanel == null) return;
|
|
|
+
|
|
|
+ dropHintPanel.Visible = false;
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 初始化拖拽功能
|
|
|
+ /// </summary>
|
|
|
+ private void InitializeDragDropFeatures()
|
|
|
+ {
|
|
|
+ this.AllowDrop = true;
|
|
|
+ InitializeDropHintPanel();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void frmReportApp_DragOver(object sender, DragEventArgs e)
|
|
|
+ {
|
|
|
+ if (dropHintPanel != null && dropHintPanel.Visible)
|
|
|
+ {
|
|
|
+ e.Effect = DragDropEffects.Copy;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ e.Effect = DragDropEffects.None;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void frmReportApp_DragLeave(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ HideDropHintPanel();
|
|
|
+ }
|
|
|
+ private void ProcessDroppedFiles(List<string> files)
|
|
|
+ {
|
|
|
+ bool processed = false;
|
|
|
+
|
|
|
+ foreach (string filePath in files)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string extension = Path.GetExtension(filePath).ToLower();
|
|
|
+
|
|
|
+ if (extension == ".prj")
|
|
|
+ {
|
|
|
+ ProcessProjectFile(filePath);
|
|
|
+ processed = true;
|
|
|
+ break; // 只处理第一个项目文件
|
|
|
+ }
|
|
|
+ else if (extension == ".rst")
|
|
|
+ {
|
|
|
+ log.Info($"开始加载结果文件: {filePath}");
|
|
|
+ this.m_RstWindow.AddSampleResult(filePath);
|
|
|
+ this.m_StandardLibrary.DataRefresh();
|
|
|
+ processed = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ log.Error($"处理文件 {filePath} 时发生错误: {ex.Message}", ex);
|
|
|
+ MessageBox.Show($"处理文件 {filePath} 时发生错误: {ex.Message}", "错误",
|
|
|
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!processed && files.Any())
|
|
|
+ {
|
|
|
+ MessageBox.Show("未能成功处理任何文件", "提示",
|
|
|
+ MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ProcessProjectFile(string projectFilePath)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string directoryPath = Path.GetDirectoryName(projectFilePath);
|
|
|
+ DirectoryInfo folder = new DirectoryInfo(directoryPath);
|
|
|
+
|
|
|
+ int loadedCount = 0;
|
|
|
+ foreach (System.IO.DirectoryInfo directory in folder.GetDirectories())
|
|
|
+ {
|
|
|
+ foreach (System.IO.FileInfo file in directory.GetFiles("*.rst"))
|
|
|
+ {
|
|
|
+ this.m_RstWindow.AddSampleResult(file.FullName);
|
|
|
+ loadedCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (loadedCount > 0)
|
|
|
+ {
|
|
|
+ this.m_StandardLibrary.DataRefresh();
|
|
|
+ log.Info($"从项目文件加载了 {loadedCount} 个结果文件");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ log.Warn("项目文件夹中未找到 .rst 文件");
|
|
|
+ MessageBox.Show("项目文件夹中未找到 .rst 文件", "提示",
|
|
|
+ MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ throw new Exception($"处理项目文件时出错: {ex.Message}", ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|