实现导出孔数量

This commit is contained in:
2026-05-16 12:07:32 +08:00
parent 51de98bd5b
commit 81a1726557
7 changed files with 291 additions and 93 deletions

View File

@@ -1058,6 +1058,49 @@ M30";
Console.WriteLine($"\n坐标绑定验证结果: {(allMatch ? " " : " ")}");
}
/// <summary>
/// 导出 CAM350 风格孔数报表
/// </summary>
public void ExportDrillUsageReport()
{
if (!HasOriginalFile)
throw new InvalidOperationException("没有原始文件路径,请先加载钻带文件");
if (Tools.Count == 0)
throw new InvalidOperationException("没有可导出的刀具数据,请先加载钻带文件");
string outputFilePath = OriginalFilePath + ".rpt";
ConfirmOverwriteReport(outputFilePath);
string report = DrillUsageReportExporter.GenerateReport(
Tools.ToList(),
FileNameWithoutExtension,
DateTime.Now);
File.WriteAllText(outputFilePath, report, CreateGb2312Encoding());
OpenFileExplorerAndSelectFile(outputFilePath);
}
private static void ConfirmOverwriteReport(string outputFilePath)
{
if (!File.Exists(outputFilePath))
return;
var result = System.Windows.MessageBox.Show(
$"孔数报表文件已存在,是否覆盖?\n\n{outputFilePath}",
"文件已存在",
MessageBoxButton.YesNo,
MessageBoxImage.Question);
if (result != MessageBoxResult.Yes)
throw new OperationCanceledException("用户取消了导出操作");
}
private static Encoding CreateGb2312Encoding()
{
return Encoding.GetEncoding(936);
}
/// <summary>
/// 打开文件资源管理器并选中指定文件
/// </summary>