From 007f91bb411579a0f99599a3f9a604d7c6b6d107 Mon Sep 17 00:00:00 2001 From: Tongg Date: Wed, 22 Jan 2025 17:29:44 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=203D=E6=A8=A1=E5=9E=8B=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Resource/Images/UserControl/03-8-3.png | Bin 0 -> 2906 bytes SparkClient.csproj | 2 ++ Views/UserControl/Viewport3D.xaml | 4 +++ Views/UserControl/Viewport3D.xaml.cs | 12 ++++++++- .../ViewportData/Helper/UnityHelper.cs | 18 ++++++++++++++ .../ViewportData/Helper/ViewportHelperPro.cs | 1 + .../ViewportData/Helper/ViewportManager.cs | 23 ++++++++++++++++++ 7 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 Resource/Images/UserControl/03-8-3.png create mode 100644 Views/UserControl/ViewportData/Helper/UnityHelper.cs diff --git a/Resource/Images/UserControl/03-8-3.png b/Resource/Images/UserControl/03-8-3.png new file mode 100644 index 0000000000000000000000000000000000000000..b2c78f5634a9f268e6fa38811a387a2355707909 GIT binary patch literal 2906 zcmbVO2UHW;8pfxh3+UqrBCbMWsEVnCkPHcE0s>+L5fOCZkTN7=%A`R;(6yi-(w1Xe zs%v?I0tyI<;DQFQ21KKxh?PBPEEGjWUFA&>Iqp0A+Riz5?wxzT`+t8wlODD_aGJ&U z7G`E<(}IKi!;#t9G^Uy(??+}o|BOuE$%3MlW@eT)rZK@RztG;yZ1P+vB1#p-UIy@B z368^uxgbs>ks)X^GrFHf#^H%T6`BhQASnaW-_V3XLwp8iwHKSfma#w~6r@#vE49lb zcv=yU#>e>iqUjm{5g-9o9JEFvmMQ@a12ZZYK-Q*hJO(`qQHdCs#U?^@6gv#ff)yaz z3rE57h-5FcHw{Omc#>(fg=i9iNW~MVc%mnkNCC(MfJ8!%Js5;d!H);R{g;e!AzuuP zP^FRqc)VJz#;HAVutI<*(r7e1frKZKum}RHOp>ZN8mv_5^i_gCsN^XinF@lXXp=+^ z7fw(yFo>pKOpwUN#Y&Z9ZbBS}*KlNbB934(X%xukjpJkq3h^j8pN9vuq@gE2f*Rt8;9Dk~dL^4jHR0Sj=W{f%HPtnSVBpHYg2bFMwf(Hg9 zB5FFBtdRjM1;|msiU=4Me+^XFSC!E$mMJhawEJpE%7@j;`QO|D{W&U-fguq{URVMV zOCm%Ny#OyVK&E*Rr~rZR1}80^o$ApXHY5Fa3OK+u~)2C-Cct~Zv$C6lpSZ>l#ooyyd)ZxC37&IwxmMaV&3`@A|Eb-;<&olifpfZb$`YrkD|r`E zS4OXJ$hrDRVHM}J%1OB=9cuto3&GuTgg!HbYyh4*=ga>7t2RrdaQM z!$q+GXSiSI;#t@cXVciZbs)$p{Z0q;tg~mH81czlr>P0Bp~sy`=pqlzSdf;pbLP#Y zI@>4u`pdZ*>j%eow%>Bna&M%!`3(9LM)w+bc7%*%l$vu%*i92*>&LUI4}7rcd!Axd z-m+);%8?4gjpqQH;l5$MO`-r7X<-!lcz&{%^6^E ztVQ&S4OS1XTdeaN_K+@otvcg#)q%P{UB1BXLfRBCpw_`}_E`)1nqK4PRdZZhI<_Xi zCMUwX%1duO?j?o7trL-;XRNLHn-41Su?PuhrO(xyF%1Ww*pGx1(tcUh>tJ0kxY-(8 zp>3M}{KSF!lMRMs*~Z9-vKnu`YgN(klDv|&$&?yL*f{%ydcCHjWoiF!QC7QWC z%(-`-N-1ow?OEJiH1j4<(U`@fdmNqDy(6IRh~Cf^gF*G5#P1X797zM@`(7Pybj7E$ zvd<R#nNMB!?LxWK25Sy3nhi$dOLu;N+Lbb4h-NdQ5 zJofNQ<|REfE9I#bb*{&8TT%6a`eg;Dd=1Cte?Q`K+jG-B%}2gy1TU^x>esLXH}^uE z`T#rX3SfP$^xo9jb(eKsqFdad15w`W@`AgS%gTb4 zduYmsK2dhuIu}Uy*%&h=M;B9fOmCQIn7TU&*gU7Q!bW$^lLg#rD<*|D9eQ*7{Ok@&O9R-Mrs%D9=zRb_K3m9GK_Sz+pHDB->dYng7*bc0sNXJ!t*CxznA9U0D};NGe? zHVhJ$d%RY$GmG;>cFZ_-Hc%#qKh}_h!sZO7oAF^_*NX;(<;P&_lJLNfe!lCw%Pm2t zn+xywE_G%eiry90xf<$G1pM~C>i5dSZL3b>uKPlJc}RD;+Fq~ScX7uv_wK`Q^mlen z2JyXRFDItTZ5p#1;>%h;qE9f_w$igQuFyYqihJx{(Ry3@{NdJ9RTX-}221B$A!yVV zW{R%R@A>Xy`=QDs9|MJ{`$Q=l(@qvAM;A=Lzg;cN(QZ3gy8d*-{%e=YKIL0Kn@1_d zX0@LU?s6Llf60RJpN}y1qzz`gZ=BzjIx;cgj@X4|eyH5^_Zu9r-2WIeZp%LbqaLQf literal 0 HcmV?d00001 diff --git a/SparkClient.csproj b/SparkClient.csproj index 62c3379..cbedd23 100644 --- a/SparkClient.csproj +++ b/SparkClient.csproj @@ -189,6 +189,8 @@ + + diff --git a/Views/UserControl/Viewport3D.xaml b/Views/UserControl/Viewport3D.xaml index 2c2ccfc..532b5eb 100644 --- a/Views/UserControl/Viewport3D.xaml +++ b/Views/UserControl/Viewport3D.xaml @@ -45,6 +45,10 @@ x:Name="BtnFcuntion3View" Click="BtnFunction_OnClick"> + diff --git a/Views/UserControl/Viewport3D.xaml.cs b/Views/UserControl/Viewport3D.xaml.cs index 45df875..797a4f2 100644 --- a/Views/UserControl/Viewport3D.xaml.cs +++ b/Views/UserControl/Viewport3D.xaml.cs @@ -42,7 +42,12 @@ public partial class Viewport3D private void Viewport3D_OnLoaded(object sender, RoutedEventArgs e) { ViewportManager.SetViewport3D(Viewport3Dx); + ViewportManager.SetViewport(this); ViewportManager.LoadModelByEntities(new List()); + #if DEBUG + #else + BtnShow3DView.Visibility = Visibility.Hidden; + #endif //选项初始化 显示-后端-管理类 一致 ViewportRightMenuSelectFaceFrame.IsEnabled = ViewportRightMenuSelectFace.IsChecked ; @@ -174,7 +179,9 @@ public partial class Viewport3D { var directionName = ((Button)sender).Name.ToString(); var directionValue = (int) TbCustomizeRevolve.Value; - + + + switch (directionName) { case "BtnFcuntion1View": @@ -210,6 +217,9 @@ public partial class Viewport3D await Task.Delay(7000); ViewportManager.DoubleClickSelect = !false; break; + case "BtnShow3DView": + + break; } diff --git a/Views/UserControl/ViewportData/Helper/UnityHelper.cs b/Views/UserControl/ViewportData/Helper/UnityHelper.cs new file mode 100644 index 0000000..10dc8fd --- /dev/null +++ b/Views/UserControl/ViewportData/Helper/UnityHelper.cs @@ -0,0 +1,18 @@ +namespace SparkClient.Views.UserControl.ViewportData.Helper; + +public class UnityHelper +{ + private static string _image_path = AppDomain.CurrentDomain.BaseDirectory + "/temp/image/"; + + /*** + * 1、根据模型信息和钻石编码生成签名作为stl文件名(导出:ViewportHelperPro.ExportModelsToStl(null, path+filename)) + * 2、判断同名STL文件是否存在 存在跳到 7 + * 3、 清理temp下,image、stl两个目录 + * 4、导出模型stl文件,记录完整的路径paramA + * 5、执行导出命令 xx.exe --model=_stl_path+paramA --output=_image_path --type=0/1 0:心图(0.png) 1:箭图(1.png) + * 6、等待命令结束 + * 7、判断图片文件是否存在 --->>不存在:提示生成失败,请重试, --->>不存在并且从2过来的,跳到1 + * 8、展示图片弹窗,并注以说明:心箭图为模拟渲染,实际请以切工镜观测为准。 + * 9、关闭 + */ +} \ No newline at end of file diff --git a/Views/UserControl/ViewportData/Helper/ViewportHelperPro.cs b/Views/UserControl/ViewportData/Helper/ViewportHelperPro.cs index c6466b8..5984b47 100644 --- a/Views/UserControl/ViewportData/Helper/ViewportHelperPro.cs +++ b/Views/UserControl/ViewportData/Helper/ViewportHelperPro.cs @@ -899,6 +899,7 @@ public class ViewportHelperPro /// 旋转时间 秒 public static void RotateModel(Vector3D axis, bool hasLine = true, int speed = 7, int to = 360) { + ViewportManager.GetViewport().ViewportRightMenuShowModelFaceByType.IsChecked = false; ViewportManager.ClearDicModels(); ViewportManager.DoubleClickSelect = false; diff --git a/Views/UserControl/ViewportData/Helper/ViewportManager.cs b/Views/UserControl/ViewportData/Helper/ViewportManager.cs index 8efb773..d9ac7b4 100644 --- a/Views/UserControl/ViewportData/Helper/ViewportManager.cs +++ b/Views/UserControl/ViewportData/Helper/ViewportManager.cs @@ -63,6 +63,8 @@ public class ViewportManager /// 网格线(圈) /// public static LineGeometryModel3D MainModelCircleLine_P = new LineGeometryModel3D(); + + /// /// 腰垂直线 /// @@ -88,6 +90,9 @@ public class ViewportManager /// 模型控件对象映射 /// private static Viewport3DX _viewport; + + //模型 + private static Viewport3D _viewport3D = null; public static void SetViewport3D(Viewport3DX viewport3D) { if (_viewport != null) @@ -105,6 +110,24 @@ public class ViewportManager throw new Exception("Viewport is not set"); return _viewport; + } + public static void SetViewport(Viewport3D viewport3D) + { + if (_viewport != null) + { + ClearDicModels(); + _viewport.Items.Clear(); + + } + + _viewport3D = viewport3D; + } + public static Viewport3D GetViewport() + { + if (_viewport3D == null) + throw new Exception("Viewport is not set"); + return _viewport3D; + } #region 模型选中交互管理 //是否双击选中 From e97cc45ee464320acc88660459325adfa0dc707d Mon Sep 17 00:00:00 2001 From: handefeng <1030428966@qq.com> Date: Thu, 23 Jan 2025 16:27:20 +0800 Subject: [PATCH 2/2] =?UTF-8?q?add:=E7=83=AD=E6=95=8F=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SparkClient.csproj | 1 + SparkClient.sln.DotSettings.user | 5 + ViewModel/Grading/GradingResultVM.cs | 364 ++++++++++++++++++--------- Views/Grading/GradingResult.xaml | 20 ++ 4 files changed, 265 insertions(+), 125 deletions(-) diff --git a/SparkClient.csproj b/SparkClient.csproj index 62c3379..76c0cdc 100644 --- a/SparkClient.csproj +++ b/SparkClient.csproj @@ -24,6 +24,7 @@ + diff --git a/SparkClient.sln.DotSettings.user b/SparkClient.sln.DotSettings.user index 4910ea3..79d18e2 100644 --- a/SparkClient.sln.DotSettings.user +++ b/SparkClient.sln.DotSettings.user @@ -12,6 +12,7 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded @@ -31,9 +32,11 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded @@ -50,11 +53,13 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded diff --git a/ViewModel/Grading/GradingResultVM.cs b/ViewModel/Grading/GradingResultVM.cs index 986bda2..f3cd760 100644 --- a/ViewModel/Grading/GradingResultVM.cs +++ b/ViewModel/Grading/GradingResultVM.cs @@ -1,6 +1,7 @@ using System.ComponentModel; using System.Data; using System.IO; +using System.IO.Ports; using System.Reflection; using System.Windows.Forms; using System.Windows.Input; @@ -12,27 +13,16 @@ using SaveFileDialog = Microsoft.Win32.SaveFileDialog; using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using SparkClient.Views.Dialog; -using NPOI.HPSF; using Application = System.Windows.Application; using MessageBox = SparkClient.Views.Dialog.MessageBox; using System.Windows; -using SharpDX; using SparkClient.Views.UserControl.ViewportData.Entity; using SparkClient.ViewModel.Configuration.SettingsPages; using SparkClient.Views.UserControl.ViewportData.Helper; -using System.Diagnostics.Metrics; using log4net; -using SparkClient.ViewModel.Configuration; using System.Drawing.Printing; using System.Drawing; -using RectangleF = System.Drawing.RectangleF; -using FontFamily = System.Drawing.FontFamily; -using FontStyle = System.Drawing.FontStyle; -using NPOI.SS.Formula.Functions; -using System.Windows.Media; -using Brush = System.Drawing.Brush; -using Brushes = System.Drawing.Brushes; - +using HandyControl.Controls; namespace SparkClient.ViewModel.Grading; /// /// 检测结果画面VM @@ -67,6 +57,10 @@ public class GradingResultVM : BaseViewModel public ICommand SaveFileCommand { get; } public ICommand SaveAsCommand { get; } + // 热敏标签打印 + public ICommand ThermalPrintCommand { get; } + private SerialPort _serialPort; + /// /// 左侧计算结果展示数据 /// @@ -167,6 +161,10 @@ public class GradingResultVM : BaseViewModel { SaveAsCommand = new RelayCommand(SaveAs); SaveFileCommand = new RelayCommand(SaveFile); + // 热敏标签打印 + ThermalPrintCommand = new RelayCommand(ExecuteThermalPrint); + // 初始化 SerialPort + InitializeSerialPort(); if (result != null) { @@ -1672,131 +1670,247 @@ public class GradingResultVM : BaseViewModel DataBaseHelper.ExecuteNonQuery(sql); } #endregion + + + // 执行热敏打印的方法 + private void ExecuteThermalPrint(object parameter) + { + try + { + // 准备要打印的数据 + string printData = PreparePrintData(); + + // 创建打印文档 + PrintDocument printDocument = new PrintDocument(); + + // 确保 PrintPage 事件处理程序正确实现 + printDocument.PrintPage += (sender, e) => + { + // 设置打印字体和格式 + Font printFont = new Font("Courier", 10); + SolidBrush drawBrush = new SolidBrush(System.Drawing.Color.Black); + float yPos = 0f; + int linesPerPage = 0; - public void PrintLabel() + // 逐行打印数据 + using (StringReader sr = new StringReader(printData)) + { + string line; + while ((line = sr.ReadLine()) != null) + { + yPos = e.MarginBounds.Top + (linesPerPage * printFont.GetHeight(e.Graphics)); + e.Graphics.DrawString(line, printFont, drawBrush, e.MarginBounds.Left, yPos); + linesPerPage++; + } + } + + // 表示已完成打印,不需要额外的页面 + e.HasMorePages = false; + }; + + // 创建自定义打印预览窗体 + CustomPrintPreviewForm customPreviewForm = new CustomPrintPreviewForm(printDocument); + + // 显示自定义打印预览窗体 + DialogResult result = customPreviewForm.ShowDialog(); + + if (result == DialogResult.OK) + { + // 打开串口 + if (!_serialPort.IsOpen) + { + _serialPort.Open(); + } + + // 将数据转换为字节数组 + byte[] dataToSend = System.Text.Encoding.UTF8.GetBytes(printData); + + // 发送数据到串口 + _serialPort.Write(dataToSend, 0, dataToSend.Length); + + Logger.Info("数据已发送到热敏打印机。"); + } + } + catch (Exception ex) + { + Logger.Error($"热敏打印发生错误: {ex.Message}"); + Growl.Error("热敏打印发生错误"); + } + finally + { + // 关闭串口 + if (_serialPort.IsOpen) + { + _serialPort.Close(); + } + } + } + + // 自定义打印预览窗体类 + public class CustomPrintPreviewForm : Form { - PrintDocument printDoc = new PrintDocument(); - printDoc.PrintPage += new PrintPageEventHandler(PrintPageHandler); - printDoc.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("Custom", 550, 300); + private PrintPreviewControl printPreviewControl; + private Button confirmButton; + private Button systemPrintButton; // 新增的系统打印按钮 + private PrintDocument printDocument; + + public CustomPrintPreviewForm(PrintDocument document) + { + this.printDocument = document; - PrintDialog printDialog = new PrintDialog(); - printDialog.Document = printDoc; + // 初始化打印预览控件 + printPreviewControl = new PrintPreviewControl(); + printPreviewControl.Dock = DockStyle.Fill; + printPreviewControl.Document = printDocument; - if (printDialog.ShowDialog() == DialogResult.OK) + // 初始化确认按钮 + confirmButton = new Button(); + confirmButton.Text = "确认打印"; + confirmButton.Dock = DockStyle.Bottom; + confirmButton.Click += ConfirmButton_Click; + + // 初始化系统打印按钮 + systemPrintButton = new Button(); + systemPrintButton.Text = "系统打印"; + systemPrintButton.Dock = DockStyle.Bottom; + systemPrintButton.Click += SystemPrintButton_Click; + + // 将控件添加到窗体 + this.Controls.Add(printPreviewControl); + this.Controls.Add(confirmButton); + this.Controls.Add(systemPrintButton); + + // 设置窗体属性 + this.Size = new System.Drawing.Size(800, 600); + } + + private void ConfirmButton_Click(object sender, EventArgs e) { - printDoc.Print(); + this.DialogResult = DialogResult.OK; + this.Close(); + } + + private void SystemPrintButton_Click(object sender, EventArgs e) + { + // 创建一个打印对话框 + PrintDialog printDialog = new PrintDialog(); + // 将打印对话框关联到当前的 PrintDocument + printDialog.Document = printDocument; + + // 显示打印对话框,如果用户点击了“确定”按钮 + if (printDialog.ShowDialog() == DialogResult.OK) + { + // 使用用户在对话框中选择的打印机和设置进行打印 + printDocument.Print(); + } } } + // 准备要打印的数据 - private void PrintPageHandler(object sender, PrintPageEventArgs e) + private string PreparePrintData() { var result = algorithmResult.measurements; - int startX = 10; - int startY = 10; - var col2X = startX + 90; - var col3X = col2X + 70; - // 设置字体 - Font font = new Font(FontFamily.GenericSerif, 12, FontStyle.Bold); - - // 设置颜色 - Brush brush = Brushes.Black; - - // 设置对齐方式 - StringFormat format = new StringFormat(); - format.Alignment = StringAlignment.Center; // 水平居中 - format.LineAlignment = StringAlignment.Center; // 垂直居中 - - // 绘制文本 - // 第一行 - int X = startX; - int Y = startY; - e.Graphics.DrawString(Standard, font, brush, new PointF(X, Y)); - X += 70; - e.Graphics.DrawString(Shape, font, brush, new PointF(X, Y)); - X += 50; - e.Graphics.DrawString($"ID:{DiamondCode}", font, brush, new PointF(X, Y)); - X += 100; - e.Graphics.DrawString($"Weight:{Wight}ct.", font, brush, new PointF(X, Y)); - X += 120; - Brush backgroundBrush = new SolidBrush(System.Drawing.Color.Black); // 背景色为黄色 - e.Graphics.FillRectangle(backgroundBrush, new RectangleF(X, Y, 200, font.Height)); - e.Graphics.DrawString(CutLevelTotal, font, Brushes.White, new PointF(X, Y)); - - // 第二行 - X = startX; - Y += font.Height; - e.Graphics.DrawString("Diameter", font, brush, new PointF(X, Y)); - - e.Graphics.DrawString($"{FormatDouble_D(result.DIAMETER)}mm", font, brush, new PointF(col2X, Y)); - - e.Graphics.DrawString($"({FormatDouble_D(result.M1)}mm-{FormatDouble_D(result.M2)}mm)", font, brush, new PointF(col3X, Y)); - e.Graphics.DrawString($"0.3%", font, brush, new PointF(310, Y)); - e.Graphics.FillRectangle(backgroundBrush, new RectangleF(350, Y, 200, font.Height)); - e.Graphics.DrawString(SymLevelTotal, font, Brushes.White, new PointF(X, Y)); - - // 第三行 - X = startX; - Y += font.Height; - e.Graphics.DrawString("Total Dep.", font, brush, new PointF(X, Y)); - X = col2X; - e.Graphics.DrawString($"{FormatDouble_D(result.DIAMETER * result.TOTAL_DEPTH)}mm", font, brush, new PointF(X, Y)); - X = col3X; - e.Graphics.DrawString($"{FormatDouble_P(result.TOTAL_DEPTH)}%", font, brush, new PointF(X, Y)); - e.Graphics.DrawString($"{DtResults.Where(X=> "TOTAL_DEPTH".Equals(X.TestItemId)).Select(X=>X.CutLevel).FirstOrDefault()}", font, brush, new PointF(480, Y)); - // 第四行 - X = startX; - Y += font.Height; - e.Graphics.DrawString("Table", font, brush, new PointF(X, Y)); - X = col2X; - e.Graphics.DrawString($"{FormatDouble_D(result.DIAMETER * result.TABLE)}mm", font, brush, new PointF(X, Y)); - X = col3X; - e.Graphics.DrawString($"{FormatDouble_P(result.TABLE)}%", font, brush, new PointF(X, Y)); - e.Graphics.DrawString($"{DtResults.Where(X => "TABLE".Equals(X.TestItemId)).Select(X => X.CutLevel).FirstOrDefault()}", font, brush, new PointF(480, Y)); - // 第五行 - X = startX; - Y += font.Height; - e.Graphics.DrawString("Crown", font, brush, new PointF(X, Y)); - X = col2X; - e.Graphics.DrawString($"{FormatDouble_A(result.CROWN_ANGLE)}°", font, brush, new PointF(X, Y)); - X = col3X; - e.Graphics.DrawString($"({FormatDouble_A(result.CROWN_ANGLE_MIN)}°-{FormatDouble_A(result.CROWN_ANGLE_MAX)}°)", font, brush, new PointF(X, Y)); - X += 120; - e.Graphics.DrawString($"({FormatDouble_A(result.CROWN_HEIGHT)}%)", font, brush, new PointF(X, Y)); - e.Graphics.DrawString($"{DtResults.Where(X => "CROWN_ANGLE".Equals(X.TestItemId)).Select(X => X.CutLevel).FirstOrDefault()}", font, brush, new PointF(410, Y)); - e.Graphics.DrawString($"{DtResults.Where(X => "CROWN_HEIGHT".Equals(X.TestItemId)).Select(X => X.CutLevel).FirstOrDefault()}", font, brush, new PointF(480, Y)); - // 第六行 - X = startX; - Y += font.Height; - e.Graphics.DrawString("Pavil.", font, brush, new PointF(X, Y)); - X = col2X; - e.Graphics.DrawString($"{FormatDouble_A(result.PAV_ANGLE)}°", font, brush, new PointF(X, Y)); - X = col3X; - e.Graphics.DrawString($"({FormatDouble_A(result.PAV_ANGLE_MIN)}°-{FormatDouble_A(result.PAV_ANGLE_MAX)}°)", font, brush, new PointF(X, Y)); - X += 120; - e.Graphics.DrawString($"({FormatDouble_A(result.PAV_DEPTH)}%)", font, brush, new PointF(X, Y)); - e.Graphics.DrawString($"{DtResults.Where(X => "PAV_ANGLE".Equals(X.TestItemId)).Select(X => X.CutLevel).FirstOrDefault()}", font, brush, new PointF(410, Y)); - e.Graphics.DrawString($"{DtResults.Where(X => "PAV_DEPTH".Equals(X.TestItemId)).Select(X => X.CutLevel).FirstOrDefault()}", font, brush, new PointF(480, Y)); - // 第七行 - X = startX; - Y += font.Height; - e.Graphics.DrawString("Culet", font, brush, new PointF(X, Y)); - X = col2X; - e.Graphics.DrawString($"{FormatDouble_P(result.CULET)}%", font, brush, new PointF(X, Y)); - X = col3X; - e.Graphics.DrawString($"Twist", font, brush, new PointF(X, Y)); - X += 60; - e.Graphics.DrawString($"({FormatDouble_A(result.TWIST_MIN)}°-{FormatDouble_A(result.TWIST_MAX)}°)", font, brush, new PointF(X, Y)); - // 第八行 - X = startX; - Y += font.Height; - e.Graphics.DrawString("Girdle 16M", font, brush, new PointF(X, Y)); - X = col2X; - e.Graphics.DrawString($"{FormatDouble_D(result.GIRDLE_VALLEY)}", font, brush, new PointF(X, Y)); - X = col3X; - e.Graphics.DrawString($"({FormatDouble_P(result.GIRDLE_VALLEY_MIN)}%-{FormatDouble_P(result.GIRDLE_VALLEY_MAX)}%)", font, brush, new PointF(X, Y)); - e.Graphics.DrawString($"{DtResults.Where(X => "GIRDLE".Equals(X.TestItemId)).Select(X => X.CutLevel).FirstOrDefault()}", font, brush, new PointF(480, Y)); + // 定义每个字段的目标宽度,确保每个字段有足够的空间 + int paramWidth = 20; // 参数列宽度 + int avgWidth = 15; // 平均值列宽度 + int rangeWidth = 50; // 区间列宽度 + int cutGradeWidth = 15; // 切工等级列宽度 + int symGradeWidth = 15; // 对称性等级列宽度 + + // 格式化数值,确保数值位数一致 + string formatNumber = "{0,8:F2}"; // 数值占8个字符宽度,保留两位小数 + + // 使用固定宽度填充每个字段,确保整齐 + string data = $"{string.Format(formatNumber, "机构:IGI").PadRight(paramWidth)}" + + $"{string.Format(formatNumber, "形状:圆形").PadRight(avgWidth)}" + + $"{string.Format(formatNumber, $"编码:{DiamondCode}").PadRight(rangeWidth)}" + + $"{string.Format(formatNumber, $"重量: {Wight}ct.").PadRight(paramWidth)}" + "\n"; + + data += $"{string.Format(formatNumber, "参数").PadRight(paramWidth)}" + + $"{string.Format(formatNumber, "平均值").PadRight(avgWidth)}" + + $"{string.Format(formatNumber, "区间(Min/Max)").PadRight(rangeWidth)}" + + $"{string.Format(formatNumber, "切工等级").PadRight(cutGradeWidth)}" + + $"{string.Format(formatNumber, "对称性等级").PadRight(symGradeWidth)}" + "\n"; + + // 使用 PadRight 对齐每列,确保每一列内容在宽度内对齐 + data += $"{string.Format(formatNumber, "直径(mm)").PadRight(paramWidth)}" + + $"{string.Format(formatNumber, result.DIAMETER).PadRight(avgWidth)}" + + $"{string.Format($"({formatNumber}-{formatNumber})", result.M1, result.M2).PadRight(rangeWidth)}" + + $"{string.Format(formatNumber, "完美").PadRight(cutGradeWidth)}" + + $"{string.Format(formatNumber, "很好").PadRight(symGradeWidth)}" + "\n"; + + data += $"{string.Format(formatNumber, "全深比(%)").PadRight(paramWidth)}" + + $"{string.Format(formatNumber, result.TOTAL_DEPTH * 100).PadRight(avgWidth)}" + + $"{string.Format(formatNumber, "-").PadRight(rangeWidth)}" + + $"{string.Format(formatNumber, CutLevelTotal).PadRight(cutGradeWidth)}" + + $"{string.Format(formatNumber, "-").PadRight(symGradeWidth)}" + "\n"; + + data += $"{string.Format(formatNumber, "台宽比(%)").PadRight(paramWidth)}" + + $"{string.Format(formatNumber, result.TABLE * 100).PadRight(avgWidth)}" + + $"{string.Format($"({formatNumber}-{formatNumber})", result.TABLE * 100 - 0.7, result.TABLE * 100 + 0.3).PadRight(rangeWidth)}" + + $"{string.Format(formatNumber, "极好").PadRight(cutGradeWidth)}" + + $"{string.Format(formatNumber, "-").PadRight(symGradeWidth)}" + "\n"; + + data += $"{string.Format(formatNumber, "冠角(°)").PadRight(paramWidth)}" + + $"{string.Format(formatNumber, result.CROWN_ANGLE).PadRight(avgWidth)}" + + $"{string.Format($"({formatNumber}-{formatNumber})", result.CROWN_ANGLE_MIN, result.CROWN_ANGLE_MAX).PadRight(rangeWidth)}" + + $"{string.Format(formatNumber, "一般 - 差").PadRight(cutGradeWidth)}" + + $"{string.Format(formatNumber, "好").PadRight(symGradeWidth)}" + "\n"; + + data += $"{string.Format(formatNumber, "冠高比(%)").PadRight(paramWidth)}" + + $"{string.Format(formatNumber, result.CROWN_HEIGHT).PadRight(avgWidth)}" + + $"{string.Format(formatNumber, "-").PadRight(rangeWidth)}" + + $"{string.Format(formatNumber, "完美").PadRight(cutGradeWidth)}" + + $"{string.Format(formatNumber, "很好").PadRight(symGradeWidth)}" + "\n"; + + data += $"{string.Format(formatNumber, "波谷腰厚(%)").PadRight(paramWidth)}" + + $"{string.Format(formatNumber, result.GIRDLE_VALLEY).PadRight(avgWidth)}" + + $"{string.Format($"({formatNumber}-{formatNumber})", result.GIRDLE_VALLEY_MIN, result.GIRDLE_VALLEY_MAX).PadRight(rangeWidth)}" + + $"{string.Format(formatNumber, "极好").PadRight(cutGradeWidth)}" + + $"{string.Format(formatNumber, "-").PadRight(symGradeWidth)}" + "\n"; + + data += $"{string.Format(formatNumber, "亭深比(%)").PadRight(paramWidth)}" + + $"{string.Format(formatNumber, result.PAV_DEPTH).PadRight(avgWidth)}" + + $"{string.Format($"({formatNumber}-{formatNumber})", result.PAV_DEPTH - 0.3, result.PAV_DEPTH + 0.3).PadRight(rangeWidth)}" + + $"{string.Format(formatNumber, "极好").PadRight(cutGradeWidth)}" + + $"{string.Format(formatNumber, "极好").PadRight(symGradeWidth)}" + "\n"; + + data += $"{string.Format(formatNumber, "综合切工等级: 一般 - 差").PadRight(paramWidth + avgWidth + rangeWidth)}" + + $"{string.Format(formatNumber, "综合对称等级: 好").PadRight(cutGradeWidth)}" + + $"{string.Format(formatNumber, $"签发日期: {DateTime.Now:yyyy/M/d}").PadRight(symGradeWidth)}" + "\n"; + + return data; + } + + private void InitializeSerialPort() + { + try + { + string _serialPortName = "COM1"; // 根据实际情况设置串口号 + int _baudRate = 9600; // 根据实际情况设置波特率 + + _serialPort = new SerialPort(_serialPortName, _baudRate); + _serialPort.ReadTimeout = 500; + _serialPort.WriteTimeout = 500; + } + catch (UnauthorizedAccessException ex) + { + Logger.Error($"无法访问串口: {ex.Message}"); + Growl.Error("热敏打印发生错误"); + } + catch (IOException ex) + { + Logger.Error($"串口操作失败: {ex.Message}"); + Growl.Error("热敏打印发生错误"); + } + catch (ArgumentOutOfRangeException ex) + { + Logger.Error($"参数超出范围: {ex.Message}"); + Growl.Error("热敏打印发生错误"); + } } + #region 钻石操作相关 //暂略 //部分代码(直接操作控件)需要在xaml.cs里边写 diff --git a/Views/Grading/GradingResult.xaml b/Views/Grading/GradingResult.xaml index 12dc145..cd66d0c 100644 --- a/Views/Grading/GradingResult.xaml +++ b/Views/Grading/GradingResult.xaml @@ -139,6 +139,26 @@ Margin="10 0 0 0" FontSize="16" Width="80" BorderBrush="Black" BorderThickness="0" Height="30"/> + +