实现导出孔数量

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

@@ -2,6 +2,7 @@ using System.Configuration;
using System.Data; using System.Data;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using System.Windows; using System.Windows;
namespace DrillTools namespace DrillTools
@@ -14,6 +15,7 @@ namespace DrillTools
protected override void OnStartup(StartupEventArgs e) protected override void OnStartup(StartupEventArgs e)
{ {
base.OnStartup(e); base.OnStartup(e);
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
// 运行孔位数据功能测试 // 运行孔位数据功能测试
//MainWindowViewModel.TestHoleLocationsFunctionality(); //MainWindowViewModel.TestHoleLocationsFunctionality();
@@ -63,4 +65,4 @@ namespace DrillTools
return supportedExtensions.Contains(extension); return supportedExtensions.Contains(extension);
} }
} }
} }

View File

@@ -15,4 +15,8 @@
<Content Include="favicon.ico" /> <Content Include="favicon.ico" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<PackageReference Include="System.Text.Encoding.CodePages" Version="6.0.0" />
</ItemGroup>
</Project> </Project>

101
DrillUsageReportExporter.cs Normal file
View File

@@ -0,0 +1,101 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
namespace DrillTools
{
/// <summary>
/// 生成 CAM350 风格的钻孔使用报告。
/// </summary>
internal static class DrillUsageReportExporter
{
public static string GenerateReport(IReadOnlyList<ToolItem> 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<ReportRow> 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<ReportRow> 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);
}
}

View File

@@ -172,6 +172,14 @@
Click="MoveDownButton_Click" Click="MoveDownButton_Click"
Content="↓ 下移" Content="↓ 下移"
IsEnabled="{Binding CanMoveDown}" /> IsEnabled="{Binding CanMoveDown}" />
<Button
Name="ExportDrillUsageReportButton"
Width="90"
Height="35"
Margin="15,0,5,0"
Click="ExportDrillUsageReportButton_Click"
Content="导出孔数"
IsEnabled="{Binding HasOriginalFile}" />
</StackPanel> </StackPanel>
</Grid> </Grid>
</GroupBox> </GroupBox>

View File

@@ -198,6 +198,25 @@ namespace DrillTools
} }
} }
/// <summary>
/// 导出孔数报表按钮点击事件
/// </summary>
private void ExportDrillUsageReportButton_Click(object sender, RoutedEventArgs e)
{
try
{
ViewModel.ExportDrillUsageReport();
}
catch (OperationCanceledException)
{
return;
}
catch (Exception ex)
{
System.Windows.MessageBox.Show($"导出孔数报表失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
/// <summary> /// <summary>
/// 生成排序种子按钮点击事件 /// 生成排序种子按钮点击事件
/// </summary> /// </summary>

View File

@@ -1058,6 +1058,49 @@ M30";
Console.WriteLine($"\n坐标绑定验证结果: {(allMatch ? " " : " ")}"); 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>
/// 打开文件资源管理器并选中指定文件 /// 打开文件资源管理器并选中指定文件
/// </summary> /// </summary>

View File

@@ -2,33 +2,32 @@ M48
;600V参数-镀膜-EA-260417 ;600V参数-镀膜-EA-260417
T01C0.749H01200Z+0.000S062.00F098.0U1000.0 T01C0.749H01200Z+0.000S062.00F098.0U1000.0
T02C3.175H00200Z-0.305S020.00F035.0U0700.0 T02C3.175H00200Z-0.305S020.00F035.0U0700.0
T03C0.300H01500Z+0.400S155.00F114.0U1000.0 T03C0.500H01200Z+0.254S110.00F102.0U1000.0
T04C0.500H01200Z+0.254S110.00F102.0U1000.0 T04C0.650H01200Z+0.200S065.00F098.0U1000.0
T05C0.650H01200Z+0.200S065.00F098.0U1000.0 T05C0.800H01200Z+0.000S060.00F087.0U1000.0
T06C0.800H01200Z+0.000S060.00F087.0U1000.0 T06C0.950H01200Z+0.000S056.00F087.0U1000.0
T07C0.950H01200Z+0.000S056.00F087.0U1000.0 T07C1.100H01200Z+0.000S055.00F087.0U1000.0
T08C1.100H01200Z+0.000S055.00F087.0U1000.0 T08C1.150H01200Z+0.000S050.00F087.0U1000.0
T09C1.150H01200Z+0.000S050.00F087.0U1000.0 T09C1.200H01200Z+0.000S050.00F087.0U1000.0
T10C1.200H01200Z+0.000S050.00F087.0U1000.0 T10C1.250H01200Z+0.000S045.00F059.0U1000.0
T11C1.250H01200Z+0.000S045.00F059.0U1000.0 T11C1.350H01200Z+0.000S045.00F059.0U1000.0
T12C1.350H01200Z+0.000S045.00F059.0U1000.0 T12C1.450H01200Z+0.000S045.00F059.0U1000.0
T13C1.450H01200Z+0.000S045.00F059.0U1000.0 T13C1.500H01200Z+0.000S030.00F047.0U1000.0
T14C1.500H01200Z+0.000S030.00F047.0U1000.0 T14C1.550H01200Z+0.000S030.00F047.0U1000.0
T15C1.550H01200Z+0.000S030.00F047.0U1000.0 T15C1.650H01200Z-0.201S028.00F047.0U1000.0
T16C1.650H01200Z-0.201S028.00F047.0U1000.0 T16C1.700H01200Z-0.201S028.00F047.0U1000.0
T17C1.700H01200Z-0.201S028.00F047.0U1000.0 T17C1.750H01200Z-0.201S028.00F047.0U1000.0
T18C1.750H01200Z-0.201S028.00F047.0U1000.0 T18C2.000H01200Z-0.201S025.00F035.0U1000.0
T19C2.000H01200Z-0.201S025.00F035.0U1000.0 T19C2.600H00800Z-0.254S022.00F031.0U0600.0
T20C2.600H00800Z-0.254S022.00F031.0U0600.0 T20C3.100H00500Z-0.305S020.00F028.0U0600.0
T21C3.100H00500Z-0.305S020.00F028.0U0600.0 T21C3.250H00500Z-0.305S020.00F028.0U0600.0
T22C3.250H00500Z-0.305S020.00F028.0U0600.0 T22C3.600H00500Z-0.305S020.00F028.0U0600.0
T23C3.600H00500Z-0.305S020.00F028.0U0600.0 T23C4.600H00500Z-0.305S020.00F024.0U0600.0
T24C4.600H00500Z-0.305S020.00F024.0U0600.0 T24C1.056H01500Z+0.000S062.00F012.0U1000.0
T25C1.056H01500Z+0.000S062.00F012.0U1000.0 T25C1.101H02000Z+0.000S055.00F025.0U1000.0
T26C1.101H02000Z+0.000S055.00F025.0U1000.0 T26C4.601H00500Z-0.305S020.00F020.0U0700.0
T27C4.601H00500Z-0.305S020.00F020.0U0700.0 T27C1.053H15000Z+0.000S055.00F060.0U1000.0
T28C1.053H15000Z+0.000S055.00F060.0U1000.0 T28C0.499H05000Z+0.254S110.00F102.0U1000.0
T29C0.499H05000Z+0.254S110.00F102.0U1000.0
% %
T01 T01
X205206Y302500 X205206Y302500
@@ -79,20 +78,6 @@ X206000Y002000
X206000Y016950 X206000Y016950
X206034Y401022 X206034Y401022
T03 T03
X174250Y188300
X187750Y188300
X174250Y378300
X187750Y378300
X187750Y568300
X174250Y568300
X-174250Y413100
X-187750Y413100
X-174250Y223100
X-187750Y223100
X-187750Y033100
X-174250Y033100
X206034Y405759
T04
X079121Y360219 X079121Y360219
X080121Y360219 X080121Y360219
X080121Y359219 X080121Y359219
@@ -10281,8 +10266,8 @@ X072266Y428636
X070639Y423477 X070639Y423477
X065967Y417723 X065967Y417723
X071333Y414125 X071333Y414125
X206034Y409159 X206034Y405653
T05 T04
X-191600Y104201 X-191600Y104201
X-191600Y107701 X-191600Y107701
X-191600Y111201 X-191600Y111201
@@ -10379,20 +10364,32 @@ X-191600Y484201
X-191600Y301201 X-191600Y301201
X-191600Y297701 X-191600Y297701
X-191600Y294201 X-191600Y294201
X206034Y412734 X206034Y409228
T06 T05
X-174250Y033875
X-174250Y032325
X-188000Y014000 X-188000Y014000
X-193000Y014000 X-193000Y014000
X-198000Y014000 X-198000Y014000
X-205000Y008585 X-205000Y008585
X-187750Y032325
X-187750Y033875
X-193800Y097388 X-193800Y097388
X-193800Y099013 X-193800Y099013
X-193800Y116388 X-193800Y116388
X-193800Y118013 X-193800Y118013
X-187750Y222325
X-187750Y223875
X-174250Y222325
X-174250Y223875
X-193800Y287388 X-193800Y287388
X-193800Y289013 X-193800Y289013
X-193800Y306388 X-193800Y306388
X-193800Y308013 X-193800Y308013
X-187750Y412325
X-187750Y413875
X-174250Y412325
X-174250Y413875
X-193800Y477388 X-193800Y477388
X-193800Y479013 X-193800Y479013
X-193800Y496388 X-193800Y496388
@@ -10542,14 +10539,26 @@ X188000Y591000
X193000Y591000 X193000Y591000
X198000Y591000 X198000Y591000
X205000Y596728 X205000Y596728
X187750Y569075
X187750Y567525
X174250Y569075
X174250Y567525
X193800Y504012 X193800Y504012
X193800Y502387 X193800Y502387
X193800Y485012 X193800Y485012
X193800Y483387 X193800Y483387
X187750Y379075
X187750Y377525
X174250Y379075
X174250Y377525
X193800Y314012 X193800Y314012
X193800Y312387 X193800Y312387
X193800Y295012 X193800Y295012
X193800Y293387 X193800Y293387
X187750Y189075
X187750Y187525
X174250Y189075
X174250Y187525
X193800Y124012 X193800Y124012
X193800Y122387 X193800Y122387
X193800Y105012 X193800Y105012
@@ -10558,8 +10567,8 @@ X205000Y008585
X198000Y014000 X198000Y014000
X193000Y014000 X193000Y014000
X188000Y014000 X188000Y014000
X206034Y416459 X206034Y412953
T07 T06
X-183500Y224831 X-183500Y224831
X-181000Y224831 X-181000Y224831
X-178500Y224831 X-178500Y224831
@@ -10794,8 +10803,8 @@ X-011401Y180901
X-178500Y034831 X-178500Y034831
X-181000Y034831 X-181000Y034831
X-183500Y034831 X-183500Y034831
X206034Y420334 X206034Y416828
T08 T07
X-052212Y327360 X-052212Y327360
X-052212Y329390 X-052212Y329390
X-059832Y328375 X-059832Y328375
@@ -10814,8 +10823,8 @@ X-052212Y137360
X052212Y084040 X052212Y084040
X052212Y082010 X052212Y082010
X059832Y083025 X059832Y083025
X206034Y424359 X206034Y420853
T09 T08
X-118478Y421219 X-118478Y421219
X-115978Y421219 X-115978Y421219
X-031969Y435047 X-031969Y435047
@@ -10852,8 +10861,8 @@ X031969Y163853
X031969Y166353 X031969Y166353
X115978Y180181 X115978Y180181
X118478Y180181 X118478Y180181
X206034Y428484 X206034Y424978
T10 T09
X-193575Y036204 X-193575Y036204
X-191850Y037200 X-191850Y037200
X-193575Y038196 X-193575Y038196
@@ -10896,8 +10905,8 @@ X191850Y031200
X193575Y030204 X193575Y030204
X193575Y032196 X193575Y032196
X193575Y183204 X193575Y183204
X206034Y432659 X206034Y429153
T11 T10
X031717Y551648 X031717Y551648
X031717Y556648 X031717Y556648
X039362Y558219 X039362Y558219
@@ -11288,8 +11297,8 @@ X-076282Y488531
X-073782Y488531 X-073782Y488531
X-071282Y488531 X-071282Y488531
X-068782Y488531 X-068782Y488531
X206034Y436884 X206034Y433378
T12 T11
X156618Y176016 X156618Y176016
X169118Y166016 X169118Y166016
X169118Y176016 X169118Y176016
@@ -11320,8 +11329,8 @@ X-169118Y045384
X-156618Y045384 X-156618Y045384
X-160764Y032731 X-160764Y032731
X-155765Y032731 X-155765Y032731
X206034Y441184 X206034Y437678
T13 T12
X133441Y541819 X133441Y541819
X140941Y541819 X140941Y541819
X129397Y519263 X129397Y519263
@@ -11400,8 +11409,8 @@ X-164625Y574258
X-157025Y574258 X-157025Y574258
X-149526Y573077 X-149526Y573077
X-141926Y573077 X-141926Y573077
X206034Y445584 X206034Y442078
T14 T13
X-082500Y575288 X-082500Y575288
X-078550Y495650 X-078550Y495650
X-080961Y489180 X-080961Y489180
@@ -11714,8 +11723,8 @@ X-186300Y409400
X-186800Y455191 X-186800Y455191
X-193800Y473200 X-193800Y473200
X-195870Y576447 X-195870Y576447
X206034Y450059 X206034Y446553
T15 T14
X113333Y075194 X113333Y075194
X120833Y075194 X120833Y075194
X129433Y075194 X129433Y075194
@@ -11896,8 +11905,8 @@ X-179118Y042884
X-171618Y042884 X-171618Y042884
X-156618Y042884 X-156618Y042884
X-156618Y055384 X-156618Y055384
X206034Y454584 X206034Y451078
T16 T15
X-079621Y239141 X-079621Y239141
X-079621Y244221 X-079621Y244221
X-079621Y249301 X-079621Y249301
@@ -11964,8 +11973,8 @@ X-105021Y059301
X-105021Y054221 X-105021Y054221
X-105021Y049141 X-105021Y049141
X-105021Y044061 X-105021Y044061
X206034Y459184 X206034Y455678
T17 T16
X105795Y455028 X105795Y455028
X105795Y458829 X105795Y458829
X105795Y462628 X105795Y462628
@@ -12368,8 +12377,8 @@ X-036269Y564953
X-036269Y559953 X-036269Y559953
X-029539Y564953 X-029539Y564953
X-029539Y559953 X-029539Y559953
X206034Y463859 X206034Y460353
T18 T17
X-169500Y487701 X-169500Y487701
X-169500Y495701 X-169500Y495701
X-174500Y495701 X-174500Y495701
@@ -12442,8 +12451,8 @@ X-021774Y434873
X-021774Y429873 X-021774Y429873
X021774Y361527 X021774Y361527
X021774Y356527 X021774Y356527
X206034Y468584 X206034Y465078
T19 T18
X081700Y487119 X081700Y487119
X-081700Y494280 X-081700Y494280
X-081700Y304280 X-081700Y304280
@@ -12451,7 +12460,7 @@ X-081700Y114280
X081700Y107119 X081700Y107119
X081700Y297119 X081700Y297119
X064610Y596091 X064610Y596091
T20 T19
X-190000Y401100 X-190000Y401100
X-190000Y211100 X-190000Y211100
X-190000Y021100 X-190000Y021100
@@ -12459,11 +12468,27 @@ X190000Y021100
X190000Y211100 X190000Y211100
X190000Y401100 X190000Y401100
X069910Y596091 X069910Y596091
T21 T20
X-193000Y391500 X193000Y201500
X-133000Y391500 X187750Y188300
X-073000Y391500 X174250Y188300
X167000Y201500
X107000Y201500
X047000Y201500
X-013000Y201500
X-073000Y201500
X-187750Y033100
X-174250Y033100
X-133000Y201500
X-174250Y223100
X-193000Y201500
X-187750Y223100
X-013000Y391500 X-013000Y391500
X-073000Y391500
X-133000Y391500
X-174250Y413100
X-193000Y391500
X-187750Y413100
X-193000Y581500 X-193000Y581500
X-133000Y581500 X-133000Y581500
X-073000Y581500 X-073000Y581500
@@ -12471,21 +12496,17 @@ X-013000Y581500
X047000Y581500 X047000Y581500
X107000Y581500 X107000Y581500
X167000Y581500 X167000Y581500
X174250Y568300
X193000Y581500 X193000Y581500
X187750Y568300
X047000Y391500 X047000Y391500
X107000Y391500 X107000Y391500
X167000Y391500 X167000Y391500
X174250Y378300
X193000Y391500 X193000Y391500
X193000Y201500 X187750Y378300
X167000Y201500
X107000Y201500
X047000Y201500
X-013000Y201500
X-073000Y201500
X-133000Y201500
X-193000Y201500
X075760Y596091 X075760Y596091
T22 T21
X-193800Y497200 X-193800Y497200
X-193800Y478200 X-193800Y478200
X-193800Y307200 X-193800Y307200
@@ -12499,7 +12520,7 @@ X193800Y313200
X193800Y484200 X193800Y484200
X193800Y503200 X193800Y503200
X081935Y596091 X081935Y596091
T23 T22
X-190000Y580000 X-190000Y580000
X-190000Y390000 X-190000Y390000
X-190000Y200000 X-190000Y200000
@@ -12507,7 +12528,7 @@ X190000Y200000
X190000Y390000 X190000Y390000
X190000Y580000 X190000Y580000
X088360Y596091 X088360Y596091
T24 T23
X-193000Y570200 X-193000Y570200
X-193000Y417200 X-193000Y417200
X-193000Y380200 X-193000Y380200
@@ -12521,7 +12542,7 @@ X193000Y374200
X193000Y411200 X193000Y411200
X193000Y564200 X193000Y564200
X095460Y596091 X095460Y596091
T25 T24
X-141775Y557837G85X-142775Y557837 X-141775Y557837G85X-142775Y557837
X-148675Y560377G85X-149675Y560377 X-148675Y560377G85X-149675Y560377
X-156875Y559017G85X-157875Y559017 X-156875Y559017G85X-157875Y559017
@@ -12559,7 +12580,7 @@ X156875Y422382G85X157875Y422382
X148675Y421023G85X149675Y421023 X148675Y421023G85X149675Y421023
X141775Y423563G85X142775Y423563 X141775Y423563G85X142775Y423563
X101288Y596091 X101288Y596091
T26 T25
X-183167Y433266G85X-187217Y433266 X-183167Y433266G85X-187217Y433266
X-183167Y243266G85X-187217Y243266 X-183167Y243266G85X-187217Y243266
X-183167Y053266G85X-187217Y053266 X-183167Y053266G85X-187217Y053266
@@ -12567,7 +12588,7 @@ X183167Y168133G85X187217Y168133
X183167Y358133G85X187217Y358133 X183167Y358133G85X187217Y358133
X183167Y548133G85X187217Y548133 X183167Y548133G85X187217Y548133
X105367Y596091 X105367Y596091
T27 T26
X-015982Y028183G85X-018260Y030268 X-015982Y028183G85X-018260Y030268
X015982Y193217G85X018260Y191132 X015982Y193217G85X018260Y191132
X-015982Y218183G85X-018260Y220268 X-015982Y218183G85X-018260Y220268
@@ -12575,7 +12596,7 @@ X015982Y383217G85X018260Y381132
X-015982Y408183G85X-018260Y410268 X-015982Y408183G85X-018260Y410268
X015982Y573217G85X018260Y571132 X015982Y573217G85X018260Y571132
X111218Y596091 X111218Y596091
T28 T27
X-141775Y557837G85X-142775Y557837 X-141775Y557837G85X-142775Y557837
X-148675Y560377G85X-149675Y560377 X-148675Y560377G85X-149675Y560377
X-156875Y559017G85X-157875Y559017 X-156875Y559017G85X-157875Y559017
@@ -12613,7 +12634,7 @@ X156875Y422382G85X157875Y422382
X148675Y421023G85X149675Y421023 X148675Y421023G85X149675Y421023
X141775Y423563G85X142775Y423563 X141775Y423563G85X142775Y423563
X117045Y596091 X117045Y596091
T29 T28
M97,B*,$S $N M97,B*,$S $N
X-142000Y011000 X-142000Y011000
M30 M30