diff --git a/ViewModel/Grading/GradingResultVM.cs b/ViewModel/Grading/GradingResultVM.cs index 609d2c6..b3e483a 100644 --- a/ViewModel/Grading/GradingResultVM.cs +++ b/ViewModel/Grading/GradingResultVM.cs @@ -283,44 +283,53 @@ public class GradingResultVM : BaseViewModel [Log] private void SaveToCsv() { - 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)) + try + { + 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)) { - - writer.WriteLine(line); + using (var writer = new StreamWriter(filePath, true)) + { + + writer.WriteLine(line); + } } - } - else - { - 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"; - using (var writer = new StreamWriter(filePath, true)) + else { - writer.WriteLine(header); - writer.WriteLine(line); + 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"; + using (var writer = new StreamWriter(filePath, true)) + { + writer.WriteLine(header); + writer.WriteLine(line); + } } } + catch (Exception ex) + { + Logger.Error($"Auto Save Error: {ex.Message}"); + } } private void saveTempDS(string selValue)