fix: Auto Save CSV

master
tongg 7 months ago
parent cf819ee3a8
commit f4b2cfff2d
  1. 3
      Model/Helper/ClientHotKeyManager.cs
  2. 5
      ViewModel/BaseWindow/BaseControlVM.cs
  3. 27
      ViewModel/Grading/GradingResultVM.cs

@ -50,7 +50,8 @@ public sealed class ClientHotKeyManager
}
else
{
throw new InvalidOperationException($"HotKey {hotKey} already registered!");
Logger.Info($"快捷键注册跳过: [ Key = {hotKey.Key.GetName()}, Modifiers = {hotKey.Modifiers.ToSafeAbundantString()}, Handler = {handler.Method.Name}, From = {registrant.GetType().Name}]");
return;
}
}

@ -150,12 +150,13 @@ public class BaseControlVM : BaseViewModel
[Log]
public async void CloseVM(object parameter)
{
if(Content is GradingResultVM)
if(Content is GradingResultVM resultVM)
{
WindowManager.PreviousVM();
WindowManager.mainViewModel.Content = WindowManager.PreviousVM();
await SOCClientService.Service.OpenPump(false);
if(resultVM._isSaveCsv == false)
resultVM.SaveToCsv();
try
{
ClientHotKeyManager.Instance.Unregister(ClientHotKeys.QuickAnewDetectHotKey);

@ -32,6 +32,7 @@ using Brush = System.Drawing.Brush;
using Brushes = System.Drawing.Brushes;
using SparkClient.Model.Attributes;
using SparkClient.Model.Common;
using SparkClient.Model.Extension;
using SparkDotNetCore.DiamondScanner.Entity.Child;
using Exception = System.Exception;
@ -63,6 +64,8 @@ public class GradingResultVM : BaseViewModel
private string _ds;
private RowDetail _selRowDataDetail;
private bool _isEnabled;
public bool _isSaveCsv = false;
/// <summary>
/// 保存按钮状态
/// </summary>
@ -110,10 +113,20 @@ public class GradingResultVM : BaseViewModel
/// 切工等级(整体 画面上部显示)
/// </summary>
public string CutLevelTotal { get { return _cutLevelTotal; } set { _cutLevelTotal = value; OnPropertyChanged(nameof(CutLevelTotal)); } }
/// <summary>
/// 对称性等级(整体 画面上部显示)
/// </summary>
public string SymLevelTotal { get { return _symLevelTotal; } set { _symLevelTotal = value; OnPropertyChanged(nameof(SymLevelTotal)); } }
public string SymLevelTotal
{
get { return _symLevelTotal; }
set
{
_symLevelTotal = value;
OnPropertyChanged(nameof(SymLevelTotal));
if (!value.IsNullOrEmpty()) SaveToCsv();
}
}
/// <summary>
/// 下拉列表DS
/// </summary>
@ -265,6 +278,7 @@ public class GradingResultVM : BaseViewModel
string data = JsonConvert.SerializeObject(result);
ViewportData = new ViewportData(result.DiamondCode, data,colorConfigEntity);
ViewportData.LoadData();
}
[Log]
private void InitDSlist()
@ -277,10 +291,15 @@ public class GradingResultVM : BaseViewModel
DSList.Rows.Add("refer", "refer");
}
[Log]
private void SaveToCsv()
public void SaveToCsv()
{
try
{
if (_isSaveCsv)
{
return;
}
string strBaseUrl = AppDomain.CurrentDomain.BaseDirectory;
string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "csv", "histroy.csv");
var info = algorithmResult.Measurements;
@ -300,7 +319,7 @@ public class GradingResultVM : BaseViewModel
$"{FormatDouble_A2(info.GIRDLE)}%," +
$"{calGirdleName(info)}," +
$"," +
$"," +
$"{GetGradeEnName(GetGradeOrder(SymLevelTotal))}," +
$"{GetGradeEnName(GetGradeOrder(CutLevelTotal))}";
if (File.Exists(filePath))
{
@ -321,6 +340,8 @@ public class GradingResultVM : BaseViewModel
writer.WriteLine(line);
}
}
_isSaveCsv = true;
}
catch (Exception ex)
{

Loading…
Cancel
Save