From 81a17265573e6fd4d2ffc0327ff57c3f723ac288 Mon Sep 17 00:00:00 2001 From: "Mr.Xia" <1424473282@qq.com> Date: Sat, 16 May 2026 12:07:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=AF=BC=E5=87=BA=E5=AD=94?= =?UTF-8?q?=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.xaml.cs | 4 +- DrillTools.csproj | 4 + DrillUsageReportExporter.cs | 101 ++++++++++++++++ MainWindow.xaml | 8 ++ MainWindow.xaml.cs | 19 +++ MainWindowViewModel.cs | 43 +++++++ demo_drl/s20034192b0-a2-cs.drl | 205 ++++++++++++++++++--------------- 7 files changed, 291 insertions(+), 93 deletions(-) create mode 100644 DrillUsageReportExporter.cs diff --git a/App.xaml.cs b/App.xaml.cs index 1e9e64e..a270fdf 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -2,6 +2,7 @@ using System.Configuration; using System.Data; using System.IO; using System.Linq; +using System.Text; using System.Windows; namespace DrillTools @@ -14,6 +15,7 @@ namespace DrillTools protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); // 运行孔位数据功能测试 //MainWindowViewModel.TestHoleLocationsFunctionality(); @@ -63,4 +65,4 @@ namespace DrillTools return supportedExtensions.Contains(extension); } } -} \ No newline at end of file +} diff --git a/DrillTools.csproj b/DrillTools.csproj index 1139bfd..b417527 100644 --- a/DrillTools.csproj +++ b/DrillTools.csproj @@ -15,4 +15,8 @@ + + + + diff --git a/DrillUsageReportExporter.cs b/DrillUsageReportExporter.cs new file mode 100644 index 0000000..c380ebd --- /dev/null +++ b/DrillUsageReportExporter.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; + +namespace DrillTools +{ + /// + /// 生成 CAM350 风格的钻孔使用报告。 + /// + internal static class DrillUsageReportExporter + { + public static string GenerateReport(IReadOnlyList tools, string layerName, DateTime exportTime) + { + if (tools == null) + throw new ArgumentNullException(nameof(tools)); + + var rows = tools.Select((tool, index) => CreateRow(tool, index + 1)).ToList(); + var report = new StringBuilder(); + + AppendHeader(report, layerName, exportTime); + AppendRows(report, rows); + AppendTotals(report, rows); + + return report.ToString(); + } + + private static ReportRow CreateRow(ToolItem tool, int order) + { + // 当前导出顺序与 Tool Ref 相同;未来如有独立钻孔执行顺序可拆分维护。 + return new ReportRow( + order, + tool.ToolNumber, + FormatDiameter(tool.Diameter), + order, + tool.RegularHoles, + tool.SlotHoles, + tool.TotalHoles); + } + + private static void AppendHeader(StringBuilder report, string layerName, DateTime exportTime) + { + report.AppendLine("Project file name: "); + report.AppendLine($"Date: {FormatDate(exportTime)}"); + report.AppendLine($"Table: DrillTable_1 Layer: {layerName}"); + report.AppendLine("Drill Usage:"); + report.AppendLine("Table # Tool Ref Tool # Size Exp Ord Plated Hits Unplated Hits Total Hits"); + report.AppendLine("======= ======== ====== ==== ======= =========== ============= =========="); + } + + private static void AppendRows(StringBuilder report, IReadOnlyList rows) + { + foreach (var row in rows) + { + report.AppendLine(string.Format( + CultureInfo.InvariantCulture, + "{0,8}{1,10}{2,10}{3,17}{4,16}{5,14}{6,15}{7,12}", + 1, + row.ToolRef, + row.ToolNumber, + row.Size, + row.ExportOrder, + row.PlatedHits, + row.UnplatedHits, + row.TotalHits)); + } + } + + private static void AppendTotals(StringBuilder report, IReadOnlyList rows) + { + report.AppendLine("=========================================================== =========== ============= =========="); + report.AppendLine(string.Format( + CultureInfo.InvariantCulture, + "{0,69}{1,14}{2,15}{3,12}", + "Totals:", + rows.Sum(row => row.PlatedHits), + rows.Sum(row => row.UnplatedHits), + rows.Sum(row => row.TotalHits))); + } + + private static string FormatDate(DateTime value) + { + return $"{value:HH:mm:ss} {value.Year}年{value.Month}月{value.Day}日"; + } + + private static string FormatDiameter(double value) + { + return value.ToString("0.###", CultureInfo.InvariantCulture); + } + + private sealed record ReportRow( + int ToolRef, + int ToolNumber, + string Size, + int ExportOrder, + int PlatedHits, + int UnplatedHits, + int TotalHits); + } +} diff --git a/MainWindow.xaml b/MainWindow.xaml index 35db02b..48ec38a 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -172,6 +172,14 @@ Click="MoveDownButton_Click" Content="↓ 下移" IsEnabled="{Binding CanMoveDown}" /> +