From a3a532091f5c56169f80c72cd5d128efc38a14e0 Mon Sep 17 00:00:00 2001 From: sunhonglei Date: Mon, 10 Mar 2025 15:32:26 +0800 Subject: [PATCH] =?UTF-8?q?csv=20=E5=86=85=E5=AE=B9=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ViewModel/Grading/GradingResultVM.cs | 85 ++++++++++++---------------- 1 file changed, 36 insertions(+), 49 deletions(-) diff --git a/ViewModel/Grading/GradingResultVM.cs b/ViewModel/Grading/GradingResultVM.cs index 5a907b2..d11c16f 100644 --- a/ViewModel/Grading/GradingResultVM.cs +++ b/ViewModel/Grading/GradingResultVM.cs @@ -284,28 +284,29 @@ public class GradingResultVM : BaseViewModel { string strBaseUrl = AppDomain.CurrentDomain.BaseDirectory; string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"csv", "histroy.csv"); + Measurements info = algorithmResult.measurements; + string line = + $"{DiamondCode}," + + $"{Wight}(ct)," + + $"{FormatDouble_A2(info.M1)}(mm)," + + $"{FormatDouble_A2(info.M2)}(mm)," + + $"{FormatDouble_A2(info.M3)}(mm)," + + $"{FormatDouble_P2(info.TABLE)}%," + + $"{FormatDouble_P2(info.CROWN_HEIGHT)}%," + + $"{FormatDouble_P2(info.PAV_DEPTH)}%," + + $"{FormatDouble_P2(info.TOTAL_DEPTH)}%," + + $"{FormatDouble_A2(info.CROWN_ANGLE)}°," + + $"{FormatDouble_A2(info.PAV_ANGLE)}°," + + $"{FormatDouble_A2(info.CULET_SIZE)}(mm)," + + $"{FormatDouble_A2(info.GIRDLE)}%," + + $"{calGirdleName(info)}," + + $"," + + $"," + + $"{GetGradeEnName(GetGradeOrder(CutLevelTotal))}"; if (File.Exists(filePath)) { using (var writer = new StreamWriter(filePath,true)) { - Measurements info = algorithmResult.measurements; - string line = - $"{DiamondCode}," + - $"{Wight}(ct)," + - $"{FormatDouble_A(info.M1)}(mm)," + - $"{FormatDouble_A(info.M2)}(mm)," + - $"{FormatDouble_A(info.M3)}(mm)," + - $"{FormatDouble_P(info.TABLE)}%," + - $"{FormatDouble_P(info.CROWN_HEIGHT)}%," + - $"{FormatDouble_P(info.PAV_DEPTH)}%," + - $"{FormatDouble_P(info.TOTAL_DEPTH)}%," + - $"{FormatDouble_A(info.CROWN_ANGLE)}°," + - $"{FormatDouble_A(info.PAV_ANGLE)}°," + - $"{FormatDouble_A(info.CULET_SIZE)}(mm)," + - $"{FormatDouble_P(info.GIRDLE)}%," + - $"{calGirdleName(info)}," + - $"," + - $"," + - $"{GetGradeEnName(GetGradeOrder(CutLevelTotal))}"; + writer.WriteLine(line); } } @@ -313,25 +314,6 @@ public class GradingResultVM : BaseViewModel { File.Create(filePath).Close(); string header = "Diamond Code,Wight,Measurement1, Measurement2, Measurement3, Table, Crown Height,Pavilion Depth, Total Depth,Crown Angle, Pavilion Angle,Culet Size, Girdle Percent,Girdle Name, POL or Pol/ Sym,SYM,CUT - PROP"; - Measurements info = algorithmResult.measurements; - string line = - $"{DiamondCode}," + - $"{Wight}(ct)," + - $"{FormatDouble_A(info.M1)}(mm)," + - $"{FormatDouble_A(info.M2)}(mm)," + - $"{FormatDouble_A(info.M3)}(mm)," + - $"{FormatDouble_P(info.TABLE)}%," + - $"{FormatDouble_P(info.CROWN_HEIGHT)}%," + - $"{FormatDouble_P(info.PAV_DEPTH)}%," + - $"{FormatDouble_P(info.TOTAL_DEPTH)}%," + - $"{FormatDouble_A(info.CROWN_ANGLE)}°," + - $"{FormatDouble_A(info.PAV_ANGLE)}°," + - $"{FormatDouble_A(info.CULET_SIZE)}(mm)," + - $"{FormatDouble_P(info.GIRDLE)}%," + - $"{calGirdleName(info)}," + - $"," + - $"," + - $"{GetGradeEnName(GetGradeOrder(CutLevelTotal))}"; using (var writer = new StreamWriter(filePath, true)) { writer.WriteLine(header); @@ -1316,17 +1298,17 @@ public class GradingResultVM : BaseViewModel col = 0; dataRow = sheet.CreateRow(row); Measurements info = algorithmResult.measurements; - dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_A(info.M1)}(mm)"); - dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_A(info.M2)}(mm)"); - dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_A(info.M3)}(mm)"); - dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_P(info.TABLE)}%"); - dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_P(info.CROWN_HEIGHT)}%"); - dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_P(info.PAV_DEPTH)}%"); - dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_P(info.TOTAL_DEPTH)}%"); - dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_A(info.CROWN_ANGLE)}°"); - dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_A(info.PAV_ANGLE)}°"); - dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_A(info.CULET_SIZE)}(mm)"); - dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_P(info.GIRDLE)}%"); + dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_A2(info.M1)}(mm)"); + dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_A2(info.M2)}(mm)"); + dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_A2(info.M3)}(mm)"); + dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_P2(info.TABLE)}%"); + dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_P2(info.CROWN_HEIGHT)}%"); + dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_P2(info.PAV_DEPTH)}%"); + dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_P2(info.TOTAL_DEPTH)}%"); + dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_A2(info.CROWN_ANGLE)}°"); + dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_A2(info.PAV_ANGLE)}°"); + dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_A2(info.CULET_SIZE)}(mm)"); + dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_P2(info.GIRDLE)}%"); // 腰部厚度英文 dataRow.CreateCell(col++).SetCellValue($"{calGirdleName(info)}"); dataRow.CreateCell(col++).SetCellValue($""); @@ -1541,6 +1523,11 @@ public class GradingResultVM : BaseViewModel return (Math.Floor(value * 10) / 10).ToString(digitsFormat); } [Log] + private string FormatDouble_A2(double value) + { + return (Math.Floor(value * 100) / 100).ToString("f2"); + } + [Log] private async Task DatFile(string filePath) { //File.Create(filePath + ".dat").Close();