@ -333,7 +333,7 @@ public class GradingResultVM : BaseViewModel
{
File . Create ( filePath ) . Close ( ) ;
string header = string . Empty ;
if ( "zh-c n" . Equals ( MultilingualHelper . getLangType ( ) ) )
if ( "e n" . Equals ( MultilingualHelper . getLangType ( ) ) )
{
header = "Diamond Code,Wight(ct),Measurement1(mm), Measurement2(mm), Measurement3(mm), Table(%), Crown Height(%),Pavilion Depth(%), Total Depth(%),Crown Angle(°), Pavilion Angle(°),Culet Size(mm), Girdle Percent(%),Girdle Name, POL or Pol/ Sym,SYM,CUT - PROP" ;
}
@ -2275,319 +2275,8 @@ public class GradingResultVM : BaseViewModel
File . Delete ( tempFilePath ) ;
}
}
// try
// {
// // 创建打印文档
// PrintDocument printDocument = new PrintDocument();
// //printDocument.PrintPage += PrintPageHandler;
// // 订阅 PrintPage 事件
// printDocument.PrintPage += PreparePrintData;
/ /
// // 创建自定义打印预览窗体
// CustomPrintPreviewForm customPreviewForm = new CustomPrintPreviewForm(printDocument);
/ /
// // 显示自定义打印预览窗体
//
// MessageBox messageBox = new MessageBox();
// MessageBoxResult boxResult = messageBox.ShowAsk(MultilingualHelper.getString("YesOrNo"));
// if (boxResult == MessageBoxResult.OK)
// {
// // 打开串口
// // if (!_serialPort.IsOpen)
// // {
// // _serialPort.Open();
// // }
/ /
// // 将绘制内容转换为字节数组
// // MemoryStream memoryStream = new MemoryStream();
// // using (Bitmap bitmap = new Bitmap((int)printDocument.DefaultPageSettings.PrintableArea.Width, (int)printDocument.DefaultPageSettings.PrintableArea.Height))
// // {
// // using (var graphics = Graphics.FromImage(bitmap))
// // {
// // // 计算可打印区域的 Rectangle
// // var margins = new Margins(0, 0, 0, 0);
// // var printableArea = new System.Drawing.Rectangle(margins.Left, margins.Top,
// // (int)printDocument.DefaultPageSettings.PrintableArea.Width - margins.Left - margins.Right,
// // (int)printDocument.DefaultPageSettings.PrintableArea.Height - margins.Top - margins.Bottom);
// //
// // // 调用 PreparePrintData 方法绘制内容到 Graphics 对象
// // // 注意这里的第三个参数应该是 Rectangle 类型
// // PreparePrintData(printDocument, new PrintPageEventArgs(graphics, printableArea, printableArea, new PageSettings()));
// // }
// // // 将 Bitmap 保存到 MemoryStream 中
// // bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
// // }
// // byte[] dataToSend = memoryStream.ToArray();
// string? printName = ConfigurationManager.AppSettings["PrintName"];
// string? printWidth = ConfigurationManager.AppSettings["PrintWidth"];
// string? printHeight = ConfigurationManager.AppSettings["PrintHeight"];
/ /
// int pageWidth = 400;
// int pageHeight = 300;
// if (string.IsNullOrWhiteSpace(printName) || string.IsNullOrWhiteSpace(printWidth) ||
// string.IsNullOrWhiteSpace(printHeight) )
// {
// Logger.Info("缺少打印配置。");
// throw new Exception("The printer parameter is invalid");
// }
// int.TryParse(printWidth, out pageWidth);
// int.TryParse(printHeight, out pageHeight);
/ /
// printDocument.PrinterSettings.PrinterName = printName;
// printDocument.DefaultPageSettings.PaperSize = new PaperSize("mm", pageWidth, pageHeight);
// printDocument.PrintController = new System.Drawing.Printing.StandardPrintController();
//
// // DialogResult result = customPreviewForm.ShowDialog();
// printDocument.Print();
// // 发送数据到串口
// //_serialPort.Write(dataToSend, 0, dataToSend.Length);
/ /
// Logger.Info("数据已发送到热敏打印机。");
// }
// }
// catch (Exception ex)
// {
// Logger.Error($"热敏打印发生错误: {ex.Message}");
// Growl.Error(MultilingualHelper.getString("DiamodResultPrintError"));
// }
// finally
// {
// // 关闭串口
// // if (_serialPort.IsOpen)
// // {
// // _serialPort.Close();
// // }
// }
}
// 自定义打印预览窗体类
// public class CustomPrintPreviewForm : Form
// {
// private PrintPreviewControl printPreviewControl;
// private Button confirmButton;
// private Button systemPrintButton; // 新增的系统打印按钮
// private PrintDocument printDocument;
/ /
// public CustomPrintPreviewForm(PrintDocument document)
// {
// this.printDocument = document;
/ /
// // 初始化打印预览控件
// printPreviewControl = new PrintPreviewControl();
// printPreviewControl.Dock = DockStyle.Fill;
// printPreviewControl.Document = printDocument;
/ /
// // 初始化确认按钮
// 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);
// }
/ /
// [Log]
// private void ConfirmButton_Click(object sender, EventArgs e)
// {
// this.DialogResult = DialogResult.OK;
// this.Close();
// }
/ /
// [Log]
// private void SystemPrintButton_Click(object sender, EventArgs e)
// {
// // 创建一个打印对话框
// PrintDialog printDialog = new PrintDialog();
// // 将打印对话框关联到当前的 PrintDocument
// printDialog.Document = printDocument;
/ /
// // 显示打印对话框,如果用户点击了“确定”按钮
// if (printDialog.ShowDialog() == DialogResult.OK)
// {
// // 使用用户在对话框中选择的打印机和设置进行打印
// printDocument.Print();
// }
// }
/ /
// /// <summary>
// /// Required method for Designer support - do not modify
// /// the contents of this method with the code editor.
// /// </summary>
// private void InitializeComponent()
// {
// SuspendLayout();
// //
// // CustomPrintPreviewForm
// //
// ClientSize = new System.Drawing.Size(479, 388);
// ResumeLayout(false);
// }
/ /
/ /
// }
// [Log]
// private void PreparePrintData(object sender, PrintPageEventArgs e)
// {
// int width = e.PageSettings.PaperSize.Width;
//
/ /
// var result = algorithmResult.Measurements;
// int startX = 3;
// int startY = 3;
// var col2X = startX + (width * 0.2f);
// var col3X = col2X + (width * 0.2f);
// var col4X = col3X + (width * 0.2f);
// var col5X = col4X + (width * 0.2f);
// // 设置字体
// Font font = new Font(FontFamily.GenericSerif, 6, FontStyle.Bold);
/ /
// // 设置颜色
// Brush brush = Brushes.Black;
/ /
// // 设置对齐方式
// StringFormat format = new StringFormat();
// format.Alignment = StringAlignment.Center; // 水平居中
// format.LineAlignment = StringAlignment.Center; // 垂直居中
// Brush backgroundBrush = new SolidBrush(System.Drawing.Color.Black); // 背景色为黑色
//
// // 绘制文本
// // 第一行
// float X = startX;
// float Y = startY;
// e.Graphics.DrawString($"{MultilingualHelper.getString("Organization")}:{Standard}", font, brush, new PointF(X, Y));
// e.Graphics.DrawString($"{MultilingualHelper.getString("DiamondResultShape")}:{Shape}", font, brush, new PointF(col2X, Y));
// e.Graphics.DrawString($"{MultilingualHelper.getString("Code")}:{DiamondCode}", font, brush, new PointF(col3X, Y));
// e.Graphics.DrawString($"{MultilingualHelper.getString("Wight")}:{Wight}ct.", font, brush, new PointF(col5X, Y));
/ /
// // 第二行
// X = startX;
// Y += font.Height + 2;
// e.Graphics.DrawString($"{MultilingualHelper.getString("Parameters")}", font, brush, new PointF(X, Y));
/ /
// e.Graphics.DrawString($"{MultilingualHelper.getString("DiamondResultGridAvgValue")}", font, brush, new PointF(col2X, Y));
/ /
// e.Graphics.DrawString($"{MultilingualHelper.getString("Interval")}(Min~Max)", font, brush, new PointF(col3X, Y));
// e.Graphics.DrawString($"{MultilingualHelper.getString("DiamondResultGridCutLevel")}", font, brush, new PointF(col4X, Y));
// e.Graphics.DrawString($"{MultilingualHelper.getString("DiamondResultSymmetryGrade")}", font, brush, new PointF(col5X, Y));
/ /
// // 第三行
// // 直径
// var d = getSelectData("DIAMETER");
// X = startX;
// Y += font.Height + 2;
// e.Graphics.DrawString($"{GetName("DIAMETER")}(mm)", font, brush, new PointF(X, Y));
// X = col2X;
// e.Graphics.DrawString(d.Avg, font, brush, new PointF(X, Y));
// X = col3X;
// e.Graphics.DrawString($"({d.Min}-{d.Max})", font, brush, new PointF(X, Y));
// e.Graphics.DrawString($"-", font, brush, new PointF(col4X, Y));
// e.Graphics.DrawString($"{d.SymLevel}", font, brush, new PointF(col5X, Y));
// // 第四行
// // 全深比
// var o = getSelectData("TOTAL_DEPTH");
// X = startX;
// Y += font.Height + 2;
// e.Graphics.DrawString($"{GetName("TOTAL_DEPTH")}(%)", font, brush, new PointF(X, Y));
// X = col2X;
// e.Graphics.DrawString(o.Avg, font, brush, new PointF(X, Y));
// X = col3X;
// e.Graphics.DrawString($"-", font, brush, new PointF(X, Y));
// e.Graphics.DrawString($"{o.CutLevel}", font, brush, new PointF(col4X, Y));
// e.Graphics.FillRectangle(backgroundBrush, new RectangleF(col5X, Y, 150, font.Height));
// // 第五行
// // 台宽比
// var t = getSelectData("TABLE");
// X = startX;
// Y += font.Height + 2;
// e.Graphics.DrawString($"{GetName("TABLE")}(%)", font, brush, new PointF(X, Y));
// X = col2X;
// e.Graphics.DrawString(t.Avg, font, brush, new PointF(X, Y));
// X = col3X;
// e.Graphics.DrawString($"({t.Min}-{t.Max})", font, brush, new PointF(X, Y));
// e.Graphics.DrawString($"{t.CutLevel}", font, brush, new PointF(col4X, Y));
// e.Graphics.FillRectangle(backgroundBrush, new RectangleF(col5X, Y, 150, font.Height));
// // 第六行
// // 冠角
// var c = getSelectData("CROWN_ANGLE");
// X = startX;
// Y += font.Height + 2;
// e.Graphics.DrawString($"{GetName("CROWN_ANGLE")}(°)", font, brush, new PointF(X, Y));
// X = col2X;
// e.Graphics.DrawString(c.Avg, font, brush, new PointF(X, Y));
// X = col3X;
// e.Graphics.DrawString($"({c.Min}-{c.Max})", font, brush, new PointF(X, Y));
// X += 120;
// e.Graphics.DrawString($"{c.CutLevel}", font, brush, new PointF(col4X, Y));
// e.Graphics.DrawString($"{c.SymLevel}", font, brush, new PointF(col5X, Y));
// // 第七行
// // 冠高比
// var h = getSelectData("CROWN_HEIGHT");
// X = startX;
// Y += font.Height + 2;
// e.Graphics.DrawString($"{GetName("CROWN_HEIGHT")}(%)", font, brush, new PointF(X, Y));
// X = col2X;
// e.Graphics.DrawString(h.Avg, font, brush, new PointF(X, Y));
// X = col3X;
// e.Graphics.DrawString($"({h.Min}-{h.Max})", font, brush, new PointF(X, Y));
// X += 60;
// e.Graphics.DrawString($"{h.CutLevel}", font, brush, new PointF(col4X, Y));
// e.Graphics.DrawString($"{h.SymLevel}", font, brush, new PointF(col5X, Y));
// // 第八行
// // 波谷腰厚
// var g = getSelectData("GIRDLE");
// X = startX;
// Y += font.Height + 2;
// e.Graphics.DrawString($"{GetName("GIRDLE")}(%)", font, brush, new PointF(X, Y));
// X = col2X;
// e.Graphics.DrawString(g.Avg, font, brush, new PointF(X, Y));
// X = col3X;
// e.Graphics.DrawString($"({g.Min}-{g.Max})", font, brush, new PointF(X, Y));
// e.Graphics.DrawString($"{g.CutLevel}", font, brush, new PointF(col4X, Y));
// e.Graphics.DrawString($"{g.SymLevel}", font, brush, new PointF(col5X, Y));
// // 第九行
// // 亭深比
// var p = getSelectData("PAV_DEPTH");
// X = startX;
// Y += font.Height + 2;
// e.Graphics.DrawString($"{GetName("PAV_DEPTH")}(%)", font, brush, new PointF(X, Y));
// X = col2X;
// e.Graphics.DrawString(p.Avg, font, brush, new PointF(X, Y));
// X = col3X;
// e.Graphics.DrawString($"({p.Min}-{p.Max})", font, brush, new PointF(X, Y));
// e.Graphics.DrawString($"{p.CutLevel}", font, brush, new PointF(col4X, Y));
// e.Graphics.DrawString($"{p.SymLevel}", font, brush, new PointF(col5X, Y));
// // 第十行
// X = startX;
// Y += font.Height + 2;
// e.Graphics.FillRectangle(backgroundBrush, new RectangleF(X, Y, col2X - 5, font.Height));
// e.Graphics.DrawString($"{MultilingualHelper.getString("CuttingGrade")}", font, Brushes.White, new PointF(X, Y));
/ /
// X = col2X;
// e.Graphics.DrawString(CutLevelTotal, font, Brushes.Black, new PointF(X, Y));
// // 第十一行
// X = startX;
// Y += font.Height + 2;
// e.Graphics.FillRectangle(backgroundBrush, new RectangleF(X, Y, col2X - 5, font.Height));
// e.Graphics.DrawString($"{MultilingualHelper.getString("SymmetryLevel")}", font, Brushes.White, new PointF(X, Y));
// X = col2X;
// e.Graphics.DrawString(SymLevelTotal, font, Brushes.Black, new PointF(X, Y));
// X = col3X;
// e.Graphics.DrawString($"{MultilingualHelper.getString("DateOfIssue")}: {DateTime.Now:yyyy/M/d}", font, brush, new PointF(X, Y));
/ /
// }
[Log]
private string GenerateTempExcelFile ( )
{
@ -2690,151 +2379,6 @@ public class GradingResultVM : BaseViewModel
ICell cell = row . GetCell ( cellRef . Col ) ? ? row . CreateCell ( cellRef . Col ) ;
cell . SetCellValue ( value ? . ToString ( ) ? ? "" ) ;
}
// [Log]
// private void PrintPageHandler(object sender, PrintPageEventArgs e)
// {
// 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));
/ /
// }
[Log]
private void InitializeSerialPort ( )
{
try
{
string _ serialPortName = "COM1" ; // 根据实际情况设置串口号
int _ baudRate = 9 6 0 0 ; // 根据实际情况设置波特率
_ serialPort = new SerialPort ( _ serialPortName , _ baudRate ) ;
_ serialPort . ReadTimeout = 5 0 0 ;
_ serialPort . WriteTimeout = 5 0 0 ;
}
catch ( UnauthorizedAccessException ex )
{
Logger . Error ( $"无法访问串口: {ex.Message}" ) ;
Growl . Error ( MultilingualHelper . getString ( "DiamodResultPrintError" ) ) ;
}
catch ( IOException ex )
{
Logger . Error ( $"串口操作失败: {ex.Message}" ) ;
Growl . Error ( MultilingualHelper . getString ( "DiamodResultPrintError" ) ) ;
}
catch ( ArgumentOutOfRangeException ex )
{
Logger . Error ( $"参数超出范围: {ex.Message}" ) ;
Growl . Error ( MultilingualHelper . getString ( "DiamodResultPrintError" ) ) ;
}
}
#region 钻石操作相关
//暂略
//部分代码(直接操作控件)需要在xaml.cs里边写
//涉及到计算部分,这里做一个中转
# endregion
}
public class CalGradeInfo {
public int gradeOrder { get ; set ; }
@ -2904,8 +2448,7 @@ public class Name
{
string sql = $"SELECT NAME, EN_NAME FROM NAME WHERE ID = '{id}'" ;
DataTable data = DataBaseHelper . ExecuteQuery ( sql ) ;
var now = MultilingualHelper . getLangType ( ) ;
string nameType = "zn-ch" . Equals ( now ) ? "NAME" : MultilingualHelper . getString ( "NameType" ) ;
string nameType = "zn-ch" . Equals ( MultilingualHelper . getLangType ( ) ) ? "NAME" : MultilingualHelper . getString ( "NameType" ) ;
if ( data . Rows . Count > 0 )
{
return data . Rows [ 0 ] [ nameType ] . ToString ( ) ;