diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
index 13a0f25..258f544 100644
--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -82,161 +82,35 @@ public partial class MainWindow : Window
#region 菜单点击按钮
- // 在 MainWindow 内部
- ///
- /// 按钮点击触发文件页面
- ///
- ///
- ///
+
private void OnFilePageButtonClick(object sender, RoutedEventArgs e)
{
- FilePage filePage = new FilePage();
- NavigationWindow navWin = new NavigationWindow();
-
- navWin.Width = 810;
- navWin.Height = 600;
- navWin.ResizeMode = ResizeMode.NoResize;
- navWin.Content = filePage;
- navWin.ShowsNavigationUI = false;
- navWin.Title = "记录列表";
-
-
- // ✅ 新增:设定父窗口、样式与居中弹出
- navWin.Owner = Application.Current.MainWindow; // 绑定主窗口
- navWin.WindowStartupLocation = WindowStartupLocation.CenterOwner; // 居中弹出
- navWin.WindowStyle = WindowStyle.ToolWindow;
-
- // ✅ 改这里:Show() 改为 ShowDialog() 实现模态窗口
- navWin.ShowDialog();
+ WindowHelper.ShowPageDialog(new FilePage(), "记录列表", 810, 600);
}
-
- ///
- /// 按钮点击触发配置页面
- ///
- ///
- ///
private void OnConfigPageButtonClick(object sender, RoutedEventArgs e)
{
- ConfigPage configPage = new ConfigPage();
- NavigationWindow navWin = new NavigationWindow();
- navWin.Content = configPage;
- navWin.ShowsNavigationUI = false;
- navWin.Width = 972;
- navWin.Height = 648;
- navWin.Title = "配置";
- navWin.ResizeMode = ResizeMode.NoResize;
-
-
-
- // ✅ 新增:设定父窗口、样式与居中弹出
- navWin.Owner = Application.Current.MainWindow; // 绑定主窗口
- navWin.WindowStartupLocation = WindowStartupLocation.CenterOwner; // 居中弹出
- navWin.WindowStyle = WindowStyle.ToolWindow;
-
- // ✅ 改这里:Show() 改为 ShowDialog() 实现模态窗口
- navWin.ShowDialog();
+ WindowHelper.ShowPageDialog(new ConfigPage(), "配置", 972, 648);
}
- ///
- /// 按钮点击触发标准基准页面
- ///
- ///
- ///
private void OnStandardPageButtonClick(object sender, RoutedEventArgs e)
{
- StandardPage standardPage = new StandardPage();
- NavigationWindow navWin = new NavigationWindow();
- navWin.Width = 972;
- navWin.Height = 648;
- //navWin.ResizeMode = ResizeMode.NoResize;
- navWin.Content = standardPage;
- navWin.ShowsNavigationUI = false;
- navWin.Title = "主标定";
-
-
- // ✅ 新增:设定父窗口、样式与居中弹出
- navWin.Owner = Application.Current.MainWindow; // 绑定主窗口
- navWin.WindowStartupLocation = WindowStartupLocation.CenterOwner; // 居中弹出
- navWin.WindowStyle = WindowStyle.ToolWindow;
-
- // ✅ 改这里:Show() 改为 ShowDialog() 实现模态窗口
- navWin.ShowDialog();
+ WindowHelper.ShowPageDialog(new StandardPage(), "主标定", 972, 648, isResizable: true);
}
- ///
- /// 按钮点击触发Gauge页面
- ///
- ///
- ///
private void OnGaugePageButtonClick(object sender, RoutedEventArgs e)
{
- GaugePage gaugePage = new GaugePage();
- NavigationWindow navWin = new NavigationWindow();
- navWin.Content = gaugePage;
- navWin.ShowsNavigationUI = false;
- navWin.Width = 1080;
- navWin.Height = 720;
- navWin.Title = "Gauge R&&R";
-
- // ✅ 新增:设定父窗口、样式与居中弹出
- navWin.Owner = Application.Current.MainWindow; // 绑定主窗口
- navWin.WindowStartupLocation = WindowStartupLocation.CenterOwner; // 居中弹出
- navWin.WindowStyle = WindowStyle.ToolWindow;
-
- // ✅ 改这里:Show() 改为 ShowDialog() 实现模态窗口
- navWin.ShowDialog();
+ WindowHelper.ShowPageDialog(new GaugePage(), "Gauge R&&R", 1080, 720);
}
-
- ///
- /// 按钮点击触发CgCgk页面
- ///
- ///
- ///
private void OnCgCgkPageButtonClick(object sender, RoutedEventArgs e)
{
- CgCgkPage cgCgkPage = new CgCgkPage();
- NavigationWindow navWin = new NavigationWindow();
- navWin.Content = cgCgkPage;
- navWin.ShowsNavigationUI = false;
- navWin.Title = "CgCgk";
-
-
- // ✅ 新增:设定父窗口、样式与居中弹出
- navWin.Owner = Application.Current.MainWindow; // 绑定主窗口
- navWin.WindowStartupLocation = WindowStartupLocation.CenterOwner; // 居中弹出
- navWin.WindowStyle = WindowStyle.ToolWindow;
-
- // ✅ 改这里:Show() 改为 ShowDialog() 实现模态窗口
- navWin.ShowDialog();
+ WindowHelper.ShowPageDialog(new CgCgkPage(), "CgCgk", 972, 648, isResizable: true);
}
-
- ///
- /// 按钮点击触发系统设置页面
- ///
- ///
- ///
private void OnSysSetPageButtonClick(object sender, RoutedEventArgs e)
{
- SysSetPage sysSetPage = new SysSetPage();
- NavigationWindow navWin = new NavigationWindow();
- navWin.Width = 810;
- navWin.Height = 600;
- navWin.ResizeMode = ResizeMode.NoResize;
- navWin.Content = sysSetPage;
- navWin.ShowsNavigationUI = false;
- navWin.Title = "系统设置";
-
-
- // ✅ 新增:设定父窗口、样式与居中弹出
- navWin.Owner = Application.Current.MainWindow; // 绑定主窗口
- navWin.WindowStartupLocation = WindowStartupLocation.CenterOwner; // 居中弹出
- navWin.WindowStyle = WindowStyle.ToolWindow;
-
- // ✅ 改这里:Show() 改为 ShowDialog() 实现模态窗口
- navWin.ShowDialog();
+ WindowHelper.ShowPageDialog(new SysSetPage(), "系统设置", 810, 600);
}
#endregion
@@ -253,7 +127,6 @@ public partial class MainWindow : Window
}
-
///
/// 测试按钮
///
diff --git a/Utils/ExcelHelper.cs b/Utils/ExcelHelper.cs
new file mode 100644
index 0000000..d795f6f
--- /dev/null
+++ b/Utils/ExcelHelper.cs
@@ -0,0 +1,141 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using unvell.ReoGrid;
+
+namespace WpfApp.Utils
+{
+ ///
+ /// Excel 操作静态工具类(基于 ReoGrid)
+ ///
+ public static class ExcelHelper
+ {
+ private static ReoGridControl reoGridControl;
+ private static Worksheet currentSheet;
+
+ static ExcelHelper()
+ {
+ reoGridControl = new ReoGridControl();
+ }
+
+ ///
+ /// 从模板加载 Excel 文件
+ ///
+ public static void LoadTemplate(string filePath)
+ {
+ if (!File.Exists(filePath))
+ throw new FileNotFoundException($"模板文件不存在: {filePath}");
+
+ reoGridControl.Load(filePath);
+ currentSheet = reoGridControl.CurrentWorksheet;
+ }
+
+ ///
+ /// 切换到指定工作表
+ ///
+ public static void SelectSheet(string sheetName)
+ {
+ if (reoGridControl == null)
+ throw new InvalidOperationException("请先调用 LoadTemplate 方法加载文件。");
+
+ var sheet = reoGridControl.Worksheets[sheetName];
+ if (sheet == null)
+ throw new ArgumentException($"未找到名为 '{sheetName}' 的工作表。");
+
+ currentSheet = sheet;
+ reoGridControl.CurrentWorksheet = sheet;
+ }
+
+ ///
+ /// 获取当前工作表名称
+ ///
+ public static string GetCurrentSheetName()
+ {
+ return currentSheet?.Name ?? string.Empty;
+ }
+
+ ///
+ /// 读取单元格
+ ///
+ public static object ReadCell(string cellName)
+ {
+ return currentSheet?.GetCellData(cellName);
+ }
+
+ ///
+ /// 设置单元格值
+ ///
+ public static void WriteCell(string cellName, object value)
+ {
+ currentSheet?.SetCellData(cellName, value);
+ }
+
+ ///
+ /// 批量写入单元格
+ ///
+ public static void WriteCells(Dictionary cellValues)
+ {
+ foreach (var kv in cellValues)
+ {
+ currentSheet?.SetCellData(kv.Key, kv.Value);
+ }
+ }
+
+ ///
+ /// 在指定行插入数据(从 startColumn 开始)
+ ///
+ public static void InsertRowData(int rowIndex, int startColumn, IList