Merge remote-tracking branch 'origin/master'

# Conflicts:
#	Language/en_US.xaml
master
Tongg 5 months ago
commit 72a736b4e9
  1. 2
      App.xaml.cs
  2. 2
      Language/zh_CN.xaml
  3. 4
      LoginWindow.xaml.cs
  4. 2
      Model/Entity/ApiEntity/StatusCodes.cs
  5. 3
      Model/Entity/JsonEntity.cs
  6. 137
      Model/Services/AlgorithmServer.cs
  7. 4
      SparkClient.csproj
  8. 1
      SparkClient.sln.DotSettings.user
  9. BIN
      SparkDB.db
  10. 6
      ViewModel/BaseWindow/BaseControlVM.cs
  11. 2
      ViewModel/Configuration/AlgorithmConfigVM.cs
  12. 2
      ViewModel/Configuration/CutConfigVM.cs
  13. 90
      ViewModel/Configuration/SettingsPages/ModelColorSetPageVM.cs
  14. 67
      ViewModel/Configuration/SettingsPages/SettingsVM.cs
  15. 96
      ViewModel/Grading/DiamondSelectVM.cs
  16. 8
      ViewModel/Grading/GradingResultVM.cs

@ -25,7 +25,7 @@ public partial class App : Application
//打开数据库连接 //打开数据库连接
//读取数据库多语言配置 //读取数据库多语言配置
DataBaseHelper.CreateConnection(); DataBaseHelper.CreateConnection();
string LanguageId = Settings.SelectValueByName("LanguageId"); string LanguageId = Settings.SelectValueById("LanguageId");
if (LanguageId.Length == 0) if (LanguageId.Length == 0)
{ {
LanguageId = "zh-cn"; LanguageId = "zh-cn";

@ -191,7 +191,7 @@
<sys:String x:Key="JsonParseFailure">P004:JSON解析失败</sys:String> <sys:String x:Key="JsonParseFailure">P004:JSON解析失败</sys:String>
<sys:String x:Key="Recheck">P021:检测到钻石需进行清洁</sys:String> <sys:String x:Key="Recheck">P021:检测到钻石需进行清洁</sys:String>
<sys:String x:Key="NoDiamond">P011:未检测到钻石</sys:String> <sys:String x:Key="NoDiamond">P011:未检测到钻石</sys:String>
<sys:String x:Key="OpenOfTheHatch">请检查切工仪设备舱门是否关闭</sys:String> <sys:String x:Key="OpenOfTheHatch">S007:请检查切工仪设备舱门是否关闭</sys:String>
<sys:String x:Key="ApplicationError">应用程序出现错误:</sys:String> <sys:String x:Key="ApplicationError">应用程序出现错误:</sys:String>

@ -15,8 +15,8 @@ public partial class LoginWindow : Window
{ {
InitializeComponent(); InitializeComponent();
WindowStartupLocation = WindowStartupLocation.CenterScreen; WindowStartupLocation = WindowStartupLocation.CenterScreen;
AccountTextBox.Text = Settings.SelectValueByName("SAVE_ACCOUNT"); AccountTextBox.Text = Settings.SelectValueById("SAVE_ACCOUNT");
PasswordBox.Password = Settings.SelectValueByName("SAVE_PASSWORD"); PasswordBox.Password = Settings.SelectValueById("SAVE_PASSWORD");
checkCUDA(); checkCUDA();
// 检测MSVCRuntime是否安装 // 检测MSVCRuntime是否安装
checkMSVCRuntime(); checkMSVCRuntime();

@ -5,6 +5,8 @@
/// </summary> /// </summary>
public static class StatusCodes public static class StatusCodes
{ {
// 成功
public const string Ok = "ok";
// 成功 // 成功
public const string Success = "S000"; public const string Success = "S000";

@ -10,6 +10,9 @@ using System.Windows.Shapes;
namespace EncryptFileTool.Entity namespace EncryptFileTool.Entity
{ {
/// <summary>
/// 定级配置导入数据
/// </summary>
public class JsonEntity public class JsonEntity
{ {
public string SHAPE_ID { get; set; } public string SHAPE_ID { get; set; }

@ -43,6 +43,11 @@ namespace SparkClient.Model.Services
//图片根目录 //图片根目录
string? image_file_base_path = ConfigurationManager.AppSettings["ImageFileBasePath"]; string? image_file_base_path = ConfigurationManager.AppSettings["ImageFileBasePath"];
// 获取 log4net 日志文件所在的目录
string? log4NetLogDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
// 构建C++ DLL 日志文件路径
string algorithm_log_path = Path.Combine(log4NetLogDirectory, "logs");
// 将所有变量拼接成一个 JSON 对象 // 将所有变量拼接成一个 JSON 对象
JObject jsonData = new JObject( JObject jsonData = new JObject(
new JProperty("shape", shape), new JProperty("shape", shape),
@ -50,13 +55,12 @@ namespace SparkClient.Model.Services
new JProperty("image_file_base_path", image_file_base_path), new JProperty("image_file_base_path", image_file_base_path),
new JProperty("image_files", JToken.Parse(image_files)), new JProperty("image_files", JToken.Parse(image_files)),
new JProperty("half_circle", half_circle), new JProperty("half_circle", half_circle),
new JProperty("algorithm_log_path", algorithm_log_path),
new JProperty("algo_config", JObject.Parse(algo_config)) new JProperty("algo_config", JObject.Parse(algo_config))
); );
string jsonDataString = jsonData.ToString(); string jsonDataString = jsonData.ToString();
// 调用 C++ DLL 函数解析 JSON // 调用 C++ DLL 函数解析 JSON
IntPtr resultPtr = DetectDiamond(jsonDataString); IntPtr resultPtr = DetectDiamond(jsonDataString);
string resultJson = Marshal.PtrToStringAnsi(resultPtr); string resultJson = Marshal.PtrToStringAnsi(resultPtr);
// 释放 DLL 分配的内存 // 释放 DLL 分配的内存
FreeString(resultPtr); FreeString(resultPtr);
@ -71,7 +75,6 @@ namespace SparkClient.Model.Services
measurements = new Measurements() measurements = new Measurements()
}; };
} }
// 反序列化 JSON 字符串为 AlgorithmResultEntity 对象 // 反序列化 JSON 字符串为 AlgorithmResultEntity 对象
var result = JsonConvert.DeserializeObject<AlgorithmResultEntity>(resultJson); var result = JsonConvert.DeserializeObject<AlgorithmResultEntity>(resultJson);
@ -85,13 +88,55 @@ namespace SparkClient.Model.Services
measurements = new Measurements() measurements = new Measurements()
}; };
} }
// 记录算法失败的状态
Logger.Error($"Algorithm failed with status: {result.status}");
// 记录算法失败的错误信息
Logger.Error($"Algorithm failed with errorMsg: {result.error_msg}");
// 处理 C++ DLL 日志文件
//ProcessDllLog();
// 算法调用失败时,保存图片到历史记录文件夹 // 算法调用失败时,保存图片到历史记录文件夹
if (result.status == StatusCodes.AlgorithmFailed) // if (result.status == StatusCodes.AlgorithmFailed)
// {
// HandleAlgorithmFailure(image_files);
// }
return result;
}
catch (Exception ex)
{ {
// 记录日志或处理异常
Logger.Error($"Error in CallParseJsonAndReturnActions: {ex.Message}");
Logger.Error($"Stack Trace: {ex.StackTrace}");
// 如果有 InnerException,打印出来
if (ex.InnerException != null)
{
Logger.Error($"Inner Exception: {ex.InnerException.Message}");
Logger.Error($"Inner Stack Trace: {ex.InnerException.StackTrace}");
}
// 返回一个默认的 AlgorithmResultEntity 对象表示解析失败
return new AlgorithmResultEntity
{
facets = new List<Facet>(),
measurements = new Measurements()
};
}
}
/// <summary>
/// 处理算法调用失败时的逻辑,包括保存图片到历史记录文件夹
/// </summary>
/// <param name="image_files">图片文件路径的 JSON 字符串</param>
private void HandleAlgorithmFailure(string image_files)
{
// 从配置文件中读取 imageHistoryPath // 从配置文件中读取 imageHistoryPath
// 定义历史记录文件夹路径 // 定义历史记录文件夹路径
string? imageHistoryPath = ConfigurationManager.AppSettings["ImageHistoryPath"]; string? imageHistoryPath = ConfigurationManager.AppSettings["ImageHistoryPath"];
if (string.IsNullOrEmpty(imageHistoryPath))
{
Logger.Error("ImageHistoryPath is not configured in AppSettings.");
return;
}
// 生成时间戳,格式为 yyyyMMddHHmmss // 生成时间戳,格式为 yyyyMMddHHmmss
string timestamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"); string timestamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
// 组合新的文件夹路径 // 组合新的文件夹路径
@ -99,7 +144,7 @@ namespace SparkClient.Model.Services
// 检查 D 盘内存空间 // 检查 D 盘内存空间
DriveInfo dDrive = new DriveInfo("D"); DriveInfo dDrive = new DriveInfo("D");
long requiredSpace = 10L * 1024 * 1024 * 1024; // 10GB long requiredSpace = 1000L * 1024 * 1024 * 1024; // 10GB
if (dDrive.TotalFreeSpace < requiredSpace) if (dDrive.TotalFreeSpace < requiredSpace)
{ {
// 如果 D 盘空间不足 10GB,删除最早创建的10个文件夹 // 如果 D 盘空间不足 10GB,删除最早创建的10个文件夹
@ -130,6 +175,11 @@ namespace SparkClient.Model.Services
string[] imageFiles = imageFilesArray.Select(token => token.ToString()).ToArray(); string[] imageFiles = imageFilesArray.Select(token => token.ToString()).ToArray();
string? imageBasePath = ConfigurationManager.AppSettings["ImageFileBasePath"]; // 图片根目录 string? imageBasePath = ConfigurationManager.AppSettings["ImageFileBasePath"]; // 图片根目录
if (string.IsNullOrEmpty(imageBasePath))
{
Logger.Error("ImageFileBasePath is not configured in AppSettings.");
return;
}
foreach (string imageFile in imageFiles) foreach (string imageFile in imageFiles)
{ {
@ -149,28 +199,73 @@ namespace SparkClient.Model.Services
Logger.Error($"Error parsing image_files JSON: {ex.Message}"); Logger.Error($"Error parsing image_files JSON: {ex.Message}");
Logger.Error($"Stack Trace: {ex.StackTrace}"); Logger.Error($"Stack Trace: {ex.StackTrace}");
} }
catch (Exception ex)
{
// 记录其他异常
Logger.Error($"Error saving images: {ex.Message}");
Logger.Error($"Stack Trace: {ex.StackTrace}");
}
} }
/// <summary>
return result; /// 处理 C++ DLL 的日志文件,将其复制到 log4net 日志目录下的 logs 文件夹,并记录其内容到日志中
/// </summary>
private void ProcessDllLog()
{
try
{
// 获取系统临时目录路径(TMP 或 TEMP 环境变量)
string? tempDirectory = Environment.GetEnvironmentVariable("TMP") ?? Environment.GetEnvironmentVariable("TEMP");
if (tempDirectory != null)
{
// 构建搜索模式
string searchPattern = "*diamond_cut_inspector*";
// 获取所有匹配的文件
string[] logFiles = Directory.GetFiles(tempDirectory, searchPattern, SearchOption.TopDirectoryOnly);
if (logFiles.Length > 0)
{
// 找到最新的日志文件
string latestLogFile = logFiles.OrderByDescending(file => new FileInfo(file).LastWriteTime).First();
// 获取 log4net 日志文件所在的目录
string log4netLogDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
if (log4netLogDirectory != null)
{
// 构建 logs 目录路径
string logsDirectory = Path.Combine(log4netLogDirectory, "logs");
// 确保 logs 目录存在
Directory.CreateDirectory(logsDirectory);
// 构建目标文件路径
string targetFilePath = Path.Combine(logsDirectory, Path.GetFileName(latestLogFile));
// 复制最新日志文件到 logs 目录
File.Copy(latestLogFile, targetFilePath, true);
// 读取复制后的日志文件的内容
string dllLogContent = File.ReadAllText(targetFilePath);
// 记录 C++ DLL 日志文件的内容到日志中
Logger.Error("C++ DLL Log Content:");
Logger.Error(dllLogContent);
} }
catch (Exception ex) else
{ {
// 记录日志或处理异常 Logger.Error("Unable to determine the log4net log directory.");
Logger.Error($"Error in CallParseJsonAndReturnActions: {ex.Message}"); }
Logger.Error($"Stack Trace: {ex.StackTrace}"); }
// 如果有 InnerException,打印出来 else
if (ex.InnerException != null)
{ {
Logger.Error($"Inner Exception: {ex.InnerException.Message}"); // 如果没有找到匹配的日志文件,记录错误信息
Logger.Error($"Inner Stack Trace: {ex.InnerException.StackTrace}"); Logger.Error("No C++ DLL log files found matching the pattern '*diamond_cut_inspector*.log'.");
} }
// 返回一个默认的 AlgorithmResultEntity 对象表示解析失败 }
return new AlgorithmResultEntity else
{ {
facets = new List<Facet>(), // 如果无法获取临时目录路径,记录错误信息
measurements = new Measurements() Logger.Error("Unable to determine the temporary directory path.");
}; }
}
catch (Exception ex)
{
// 记录读取或复制日志文件时的异常
Logger.Error($"Error processing C++ DLL log file: {ex.Message}");
Logger.Error($"Stack Trace: {ex.StackTrace}");
} }
} }
} }

@ -52,9 +52,9 @@
<None Remove="Resource\Images\UIResource\round_P8-P8.png" /> <None Remove="Resource\Images\UIResource\round_P8-P8.png" />
<None Remove="Resource\Images\UIResource\round_select.png" /> <None Remove="Resource\Images\UIResource\round_select.png" />
<None Remove="Resource\Images\ze-add-o 1%403x.png" /> <None Remove="Resource\Images\ze-add-o 1%403x.png" />
<Resource Include="ffmpeg.exe"> <Content Include="ffmpeg.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource> </Content>
<None Remove="Resource\Images\homebg.png" /> <None Remove="Resource\Images\homebg.png" />
<Resource Include="Resource\Images\UIResource\Cushion.png" /> <Resource Include="Resource\Images\UIResource\Cushion.png" />
<Resource Include="Resource\Images\UIResource\Cushion_select.png" /> <Resource Include="Resource\Images\UIResource\Cushion_select.png" />

@ -57,6 +57,7 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ATriggerAction_002Ecs_002Fl_003AC_0021_003FUsers_003Ftongg_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F95b2fd5cb826a0d61aff88f87b258644cfe6df15959e521eb9d6cc8da70dc52_003FTriggerAction_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ATriggerAction_002Ecs_002Fl_003AC_0021_003FUsers_003Ftongg_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F95b2fd5cb826a0d61aff88f87b258644cfe6df15959e521eb9d6cc8da70dc52_003FTriggerAction_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AUIElement_002Ecs_002Fl_003AC_0021_003FUsers_003Ftongg_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fbfd90ad81939493b96034353abcd1045825908_003F4b_003F18f975e4_003FUIElement_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AUIElement_002Ecs_002Fl_003AC_0021_003FUsers_003Ftongg_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fbfd90ad81939493b96034353abcd1045825908_003F4b_003F18f975e4_003FUIElement_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AUndoStack_002Ecs_002Fl_003AC_0021_003FUsers_003Ftongg_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F85eb3e3af2ef415e8072243864dec55a97e00_003F18_003F3f9ef08f_003FUndoStack_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AUndoStack_002Ecs_002Fl_003AC_0021_003FUsers_003Ftongg_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F85eb3e3af2ef415e8072243864dec55a97e00_003F18_003F3f9ef08f_003FUndoStack_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AUnsafeNativeMethodsCLR_002Ecs_002Fl_003AC_0021_003FUsers_003FAdministrator_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F2e8b8aa5d488ba9b46d9ca2a747d6895994b3519f2f231f4e3d1af87b86320_003FUnsafeNativeMethodsCLR_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AUnwrapPromise_00601_002Ecs_002Fl_003AC_0021_003FUsers_003FAdministrator_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F211e6f3b24fa438a92f1815153647ce2c8f908_003F9d_003F0ea6b8e2_003FUnwrapPromise_00601_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AUnwrapPromise_00601_002Ecs_002Fl_003AC_0021_003FUsers_003FAdministrator_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F211e6f3b24fa438a92f1815153647ce2c8f908_003F9d_003F0ea6b8e2_003FUnwrapPromise_00601_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AWindow_002Ecs_002Fl_003AC_0021_003FUsers_003FAdministrator_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fd0db11e55b76dc7f234163f6cee32b297b8ddb591fb0b5cbad1b46ed17343e18_003FWindow_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AWindow_002Ecs_002Fl_003AC_0021_003FUsers_003FAdministrator_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fd0db11e55b76dc7f234163f6cee32b297b8ddb591fb0b5cbad1b46ed17343e18_003FWindow_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AWindow_002Ecs_002Fl_003AC_0021_003FUsers_003Ftongg_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fd0db11e55b76dc7f234163f6cee32b297b8ddb591fb0b5cbad1b46ed17343e18_003FWindow_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AWindow_002Ecs_002Fl_003AC_0021_003FUsers_003Ftongg_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fd0db11e55b76dc7f234163f6cee32b297b8ddb591fb0b5cbad1b46ed17343e18_003FWindow_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>

Binary file not shown.

@ -64,6 +64,11 @@ public class BaseControlVM : BaseViewModel
{ {
if(Content is GradingResultVM) if(Content is GradingResultVM)
{ {
bool isSaved = (Content as GradingResultVM).isSaved;
if (isSaved) {
WindowManager.mainViewModel.Content = WindowManager.PreviousVM();
}
else {
MessageBox message = new MessageBox(); MessageBox message = new MessageBox();
MessageBoxResult result = message.ShowAsk(MultilingualHelper.getString("DiamodResultCloseConfirm")); MessageBoxResult result = message.ShowAsk(MultilingualHelper.getString("DiamodResultCloseConfirm"));
if (MessageBoxResult.OK.Equals(result)) if (MessageBoxResult.OK.Equals(result))
@ -71,6 +76,7 @@ public class BaseControlVM : BaseViewModel
WindowManager.mainViewModel.Content = WindowManager.PreviousVM(); WindowManager.mainViewModel.Content = WindowManager.PreviousVM();
} }
} }
}
else else
{ {
WindowManager.mainViewModel.Content = WindowManager.PreviousVM(); WindowManager.mainViewModel.Content = WindowManager.PreviousVM();

@ -122,7 +122,7 @@ public class AlgorithmConfigVM : BaseViewModel
} }
} }
private void IsEnabledByRole (){ private void IsEnabledByRole (){
string PERMISSIONS = Settings.SelectValueByName("PERMISSIONS"); string PERMISSIONS = Settings.SelectValueById("PERMISSIONS");
if ("admin".Equals(PERMISSIONS)) if ("admin".Equals(PERMISSIONS))
{ {
IsEnabled = true; IsEnabled = true;

@ -147,7 +147,7 @@ public class CutConfigVM: BaseViewModel
} }
private void IsEnabledByRole() private void IsEnabledByRole()
{ {
string PERMISSIONS = Settings.SelectValueByName("PERMISSIONS"); string PERMISSIONS = Settings.SelectValueById("PERMISSIONS");
if ("admin".Equals(PERMISSIONS)) if ("admin".Equals(PERMISSIONS))
{ {
IsEnabled = true; IsEnabled = true;

@ -1,9 +1,14 @@
using log4net;
using SparkClient.Model.Helper; using SparkClient.Model.Helper;
using SparkClient.ViewModel.Grading;
namespace SparkClient.ViewModel.Configuration.SettingsPages; namespace SparkClient.ViewModel.Configuration.SettingsPages;
/// <summary>
/// 系统配置中颜色配置页面VM
/// </summary>
public class ModelColorSetPageVM : BaseViewModel public class ModelColorSetPageVM : BaseViewModel
{ {
private static readonly ILog Logger = LogManager.GetLogger(typeof(ModelColorSetPageVM));
private string _FACET_COLOR; private string _FACET_COLOR;
private string _BORDER_COLOR; private string _BORDER_COLOR;
private string _SELECTED_FACET_COLOR; private string _SELECTED_FACET_COLOR;
@ -21,22 +26,73 @@ public class ModelColorSetPageVM : BaseViewModel
private string _PAVILION_MAIN_FACET_COLOR; private string _PAVILION_MAIN_FACET_COLOR;
private string _LOWER_GIRDLE_FACET_COLOR; private string _LOWER_GIRDLE_FACET_COLOR;
private string _CULET_COLOR; private string _CULET_COLOR;
/// <summary>
/// 面部颜色
/// </summary>
public string FACET_COLOR { get { return _FACET_COLOR; } set { _FACET_COLOR = value; OnPropertyChanged(nameof(FACET_COLOR)); } } public string FACET_COLOR { get { return _FACET_COLOR; } set { _FACET_COLOR = value; OnPropertyChanged(nameof(FACET_COLOR)); } }
/// <summary>
/// 边框颜色
/// </summary>
public string BORDER_COLOR { get { return _BORDER_COLOR; } set { _BORDER_COLOR = value; OnPropertyChanged(nameof(BORDER_COLOR)); } } public string BORDER_COLOR { get { return _BORDER_COLOR; } set { _BORDER_COLOR = value; OnPropertyChanged(nameof(BORDER_COLOR)); } }
/// <summary>
/// 选中面颜色
/// </summary>
public string SELECTED_FACET_COLOR { get { return _SELECTED_FACET_COLOR; } set { _SELECTED_FACET_COLOR = value; OnPropertyChanged(nameof(SELECTED_FACET_COLOR)); } } public string SELECTED_FACET_COLOR { get { return _SELECTED_FACET_COLOR; } set { _SELECTED_FACET_COLOR = value; OnPropertyChanged(nameof(SELECTED_FACET_COLOR)); } }
/// <summary>
/// 选中面边框颜色
/// </summary>
public string SELECTED_BORDER_COLOR { get { return _SELECTED_BORDER_COLOR; } set { _SELECTED_BORDER_COLOR = value; OnPropertyChanged(nameof(SELECTED_BORDER_COLOR)); } } public string SELECTED_BORDER_COLOR { get { return _SELECTED_BORDER_COLOR; } set { _SELECTED_BORDER_COLOR = value; OnPropertyChanged(nameof(SELECTED_BORDER_COLOR)); } }
/// <summary>
/// 选中面同类面颜色
/// </summary>
public string SELECTED_TYPE_COLOR { get { return _SELECTED_TYPE_COLOR; } set { _SELECTED_TYPE_COLOR = value; OnPropertyChanged(nameof(SELECTED_TYPE_COLOR)); } } public string SELECTED_TYPE_COLOR { get { return _SELECTED_TYPE_COLOR; } set { _SELECTED_TYPE_COLOR = value; OnPropertyChanged(nameof(SELECTED_TYPE_COLOR)); } }
/// <summary>
/// 选中面文字信息颜色
/// </summary>
public string SELECTED_FONT_COLOR { get { return _SELECTED_FONT_COLOR; } set { _SELECTED_FONT_COLOR = value; OnPropertyChanged(nameof(SELECTED_FONT_COLOR)); } } public string SELECTED_FONT_COLOR { get { return _SELECTED_FONT_COLOR; } set { _SELECTED_FONT_COLOR = value; OnPropertyChanged(nameof(SELECTED_FONT_COLOR)); } }
/// <summary>
/// 标识线条颜色
/// </summary>
public string RULER_COLOR { get { return _RULER_COLOR; } set { _RULER_COLOR = value; OnPropertyChanged(nameof(RULER_COLOR)); } } public string RULER_COLOR { get { return _RULER_COLOR; } set { _RULER_COLOR = value; OnPropertyChanged(nameof(RULER_COLOR)); } }
/// <summary>
/// 正方向标记颜色
/// </summary>
public string ARROW_COLOR { get { return _ARROW_COLOR; } set { _ARROW_COLOR = value; OnPropertyChanged(nameof(ARROW_COLOR)); } } public string ARROW_COLOR { get { return _ARROW_COLOR; } set { _ARROW_COLOR = value; OnPropertyChanged(nameof(ARROW_COLOR)); } }
/// <summary>
/// 瑕疵面颜色
/// </summary>
public string BLEMISH_FACET_COLOR { get { return _BLEMISH_FACET_COLOR; } set { _BLEMISH_FACET_COLOR = value; OnPropertyChanged(nameof(BLEMISH_FACET_COLOR)); } } public string BLEMISH_FACET_COLOR { get { return _BLEMISH_FACET_COLOR; } set { _BLEMISH_FACET_COLOR = value; OnPropertyChanged(nameof(BLEMISH_FACET_COLOR)); } }
/// <summary>
/// 台面颜色
/// </summary>
public string TABLE_FACET_COLOR { get { return _TABLE_FACET_COLOR; } set { _TABLE_FACET_COLOR = value; OnPropertyChanged(nameof(TABLE_FACET_COLOR)); } } public string TABLE_FACET_COLOR { get { return _TABLE_FACET_COLOR; } set { _TABLE_FACET_COLOR = value; OnPropertyChanged(nameof(TABLE_FACET_COLOR)); } }
/// <summary>
/// 风筝面颜色
/// </summary>
public string UPPER_MAIN_FACET_COLOR { get { return _UPPER_MAIN_FACET_COLOR; } set { _UPPER_MAIN_FACET_COLOR = value; OnPropertyChanged(nameof(UPPER_MAIN_FACET_COLOR)); } } public string UPPER_MAIN_FACET_COLOR { get { return _UPPER_MAIN_FACET_COLOR; } set { _UPPER_MAIN_FACET_COLOR = value; OnPropertyChanged(nameof(UPPER_MAIN_FACET_COLOR)); } }
/// <summary>
/// 星刻面颜色
/// </summary>
public string STAR_FACET_COLOR { get { return _STAR_FACET_COLOR; } set { _STAR_FACET_COLOR = value; OnPropertyChanged(nameof(STAR_FACET_COLOR)); } } public string STAR_FACET_COLOR { get { return _STAR_FACET_COLOR; } set { _STAR_FACET_COLOR = value; OnPropertyChanged(nameof(STAR_FACET_COLOR)); } }
/// <summary>
/// 上腰面颜色
/// </summary>
public string UPPER_GIRDLE_FACET_COLOR { get { return _UPPER_GIRDLE_FACET_COLOR; } set { _UPPER_GIRDLE_FACET_COLOR = value; OnPropertyChanged(nameof(UPPER_GIRDLE_FACET_COLOR)); } } public string UPPER_GIRDLE_FACET_COLOR { get { return _UPPER_GIRDLE_FACET_COLOR; } set { _UPPER_GIRDLE_FACET_COLOR = value; OnPropertyChanged(nameof(UPPER_GIRDLE_FACET_COLOR)); } }
/// <summary>
/// 腰面颜色
/// </summary>
public string GIRDLE_FACET_COLOR { get { return _GIRDLE_FACET_COLOR; } set { _GIRDLE_FACET_COLOR = value; OnPropertyChanged(nameof(GIRDLE_FACET_COLOR)); } } public string GIRDLE_FACET_COLOR { get { return _GIRDLE_FACET_COLOR; } set { _GIRDLE_FACET_COLOR = value; OnPropertyChanged(nameof(GIRDLE_FACET_COLOR)); } }
/// <summary>
/// 亭部主刻面颜色
/// </summary>
public string PAVILION_MAIN_FACET_COLOR { get { return _PAVILION_MAIN_FACET_COLOR; } set { _PAVILION_MAIN_FACET_COLOR = value; OnPropertyChanged(nameof(PAVILION_MAIN_FACET_COLOR)); } } public string PAVILION_MAIN_FACET_COLOR { get { return _PAVILION_MAIN_FACET_COLOR; } set { _PAVILION_MAIN_FACET_COLOR = value; OnPropertyChanged(nameof(PAVILION_MAIN_FACET_COLOR)); } }
/// <summary>
/// 下腰面颜色
/// </summary>
public string LOWER_GIRDLE_FACET_COLOR { get { return _LOWER_GIRDLE_FACET_COLOR; } set { _LOWER_GIRDLE_FACET_COLOR = value; OnPropertyChanged(nameof(LOWER_GIRDLE_FACET_COLOR)); } } public string LOWER_GIRDLE_FACET_COLOR { get { return _LOWER_GIRDLE_FACET_COLOR; } set { _LOWER_GIRDLE_FACET_COLOR = value; OnPropertyChanged(nameof(LOWER_GIRDLE_FACET_COLOR)); } }
/// <summary>
/// 底面颜色
/// </summary>
public string CULET_COLOR { get { return _CULET_COLOR; } set { _CULET_COLOR = value; OnPropertyChanged(nameof(CULET_COLOR)); } } public string CULET_COLOR { get { return _CULET_COLOR; } set { _CULET_COLOR = value; OnPropertyChanged(nameof(CULET_COLOR)); } }
private Dictionary<string, string> colors; private Dictionary<string, string> colors;
@ -44,8 +100,12 @@ public class ModelColorSetPageVM : BaseViewModel
{ {
InitSetting(); InitSetting();
} }
/// <summary>
/// 页面初始化参数赋值
/// </summary>
private void InitSetting() private void InitSetting()
{
try
{ {
colors = new Dictionary<string, string>(); colors = new Dictionary<string, string>();
colors.Add("FACET_COLOR", "面部颜色"); colors.Add("FACET_COLOR", "面部颜色");
@ -66,14 +126,24 @@ public class ModelColorSetPageVM : BaseViewModel
colors.Add("LOWER_GIRDLE_FACET_COLOR", "下腰面颜色"); colors.Add("LOWER_GIRDLE_FACET_COLOR", "下腰面颜色");
colors.Add("CULET_COLOR", "底面颜色"); colors.Add("CULET_COLOR", "底面颜色");
foreach (var color in colors) foreach (var color in colors)
{ {
setColor(color.Key); setColor(color.Key);
} }
} }
catch (Exception ex)
{
Logger.Error($"全局异常捕获:{ex.Message}", ex);
}
}
/// <summary>
/// 颜色数据更新
/// </summary>
/// <param name="param"></param>
/// <returns></returns>
public bool SaveUpdate(object param) public bool SaveUpdate(object param)
{
try
{ {
DataBaseHelper.BeginTransaction(); DataBaseHelper.BeginTransaction();
foreach (var color in colors) foreach (var color in colors)
@ -83,6 +153,12 @@ public class ModelColorSetPageVM : BaseViewModel
DataBaseHelper.commit(); DataBaseHelper.commit();
return true; return true;
} }
catch (Exception ex)
{
Logger.Error($"全局异常捕获:{ex.Message}", ex);
return false;
}
}
private void updateDataBase(string SETTING_ID) private void updateDataBase(string SETTING_ID)
{ {
Type type = this.GetType(); Type type = this.GetType();
@ -94,9 +170,13 @@ public class ModelColorSetPageVM : BaseViewModel
}; };
colorData.insert(); colorData.insert();
} }
/// <summary>
/// 画面中颜色属性赋值
/// </summary>
/// <param name="SETTING_ID"></param>
private void setColor(string SETTING_ID) private void setColor(string SETTING_ID)
{ {
var value = Settings.SelectValueByName(SETTING_ID); var value = Settings.SelectValueById(SETTING_ID);
if (value == null || string.IsNullOrEmpty(value)) if (value == null || string.IsNullOrEmpty(value))
{ {
value = "#FF000000"; value = "#FF000000";

@ -1,4 +1,5 @@
using HandyControl.Controls; using HandyControl.Controls;
using log4net;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using SparkClient.Model.Entity.Base; using SparkClient.Model.Entity.Base;
using SparkClient.Model.Helper; using SparkClient.Model.Helper;
@ -17,6 +18,7 @@ namespace SparkClient.ViewModel.Configuration.SettingsPages
{ {
public class SettingsVM : BaseViewModel public class SettingsVM : BaseViewModel
{ {
private static readonly ILog Logger = LogManager.GetLogger(typeof(ModelColorSetPageVM));
public ICommand SelectFileCommand { get; } public ICommand SelectFileCommand { get; }
public string _languageId; public string _languageId;
@ -47,36 +49,51 @@ namespace SparkClient.ViewModel.Configuration.SettingsPages
public DataTable Rules { get { return _rules; } set { _rules = value; OnPropertyChanged(nameof(Rules)); } } public DataTable Rules { get { return _rules; } set { _rules = value; OnPropertyChanged(nameof(Rules)); } }
public SettingsVM() public SettingsVM()
{ {
try {
SelectFileCommand = new RelayCommand(SelectFile); SelectFileCommand = new RelayCommand(SelectFile);
InitSetting(); InitSetting();
} }
catch (Exception ex)
{
Logger.Error($"全局异常捕获:{ex.Message}", ex);
}
}
private void InitSetting() private void InitSetting()
{
try
{ {
Languages = new DataTable(); Languages = new DataTable();
Languages.Columns.Add("Key"); Languages.Columns.Add("Key");
Languages.Columns.Add("Value"); Languages.Columns.Add("Value");
Languages.Rows.Add("中文", "zh-cn"); Languages.Rows.Add("中文", "zh-cn");
Languages.Rows.Add("English", "en"); Languages.Rows.Add("English", "en");
LanguageId = Settings.SelectValueByName("LanguageId"); LanguageId = Settings.SelectValueById("LanguageId");
if (LanguageId.Length == 0) if (LanguageId.Length == 0)
{ {
LanguageId = "zh-cn"; LanguageId = "zh-cn";
} }
bool.TryParse( Settings.SelectValueByName("TxtFileChecked"), out bool TxtFileChecked); bool.TryParse( Settings.SelectValueById("TxtFileChecked"), out bool TxtFileChecked);
this.TxtFileChecked = TxtFileChecked; this.TxtFileChecked = TxtFileChecked;
bool.TryParse(Settings.SelectValueByName("StlFileChecked"), out bool StlFileChecked); bool.TryParse(Settings.SelectValueById("StlFileChecked"), out bool StlFileChecked);
this.StlFileChecked = StlFileChecked; this.StlFileChecked = StlFileChecked;
bool.TryParse(Settings.SelectValueByName("ExcelFileChecked"), out bool ExcelFileChecked); bool.TryParse(Settings.SelectValueById("ExcelFileChecked"), out bool ExcelFileChecked);
this.ExcelFileChecked = ExcelFileChecked; this.ExcelFileChecked = ExcelFileChecked;
bool.TryParse(Settings.SelectValueByName("DatFileChecked"), out bool DatFileChecked); bool.TryParse(Settings.SelectValueById("DatFileChecked"), out bool DatFileChecked);
this.DatFileChecked = DatFileChecked; this.DatFileChecked = DatFileChecked;
FilePath = Settings.SelectValueByName("FilePath"); FilePath = Settings.SelectValueById("FilePath");
RuleId = Settings.SelectValueByName("RuleId"); RuleId = Settings.SelectValueById("RuleId");
selectRules(); selectRules();
} }
catch (Exception ex)
{
Logger.Error($"全局异常捕获:{ex.Message}", ex);
}
}
private void selectRules() private void selectRules()
{
try
{ {
Rules = new DataTable(); Rules = new DataTable();
Rules.Columns.Add("Key"); Rules.Columns.Add("Key");
@ -87,9 +104,16 @@ namespace SparkClient.ViewModel.Configuration.SettingsPages
{ {
Rules.Rows.Add(row[MultilingualHelper.getString("RULE_NAME")].ToString(), row["RULE_ID"].ToString()); Rules.Rows.Add(row[MultilingualHelper.getString("RULE_NAME")].ToString(), row["RULE_ID"].ToString());
} }
}
catch (Exception ex)
{
Logger.Error($"全局异常捕获:{ex.Message}", ex);
}
//Rules.Rows.Add("IGI 2023", "IGI2023"); //Rules.Rows.Add("IGI 2023", "IGI2023");
} }
public bool SaveUpdate(object param) public bool SaveUpdate(object param)
{
try
{ {
if (!Directory.Exists(FilePath)) if (!Directory.Exists(FilePath))
{ {
@ -102,7 +126,15 @@ namespace SparkClient.ViewModel.Configuration.SettingsPages
Growl.InfoGlobal(MultilingualHelper.getString("Save_successful_message")); Growl.InfoGlobal(MultilingualHelper.getString("Save_successful_message"));
return true; return true;
} }
catch (Exception ex)
{
Logger.Error($"全局异常捕获:{ex.Message}", ex);
return false;
}
}
private void updateDataBase() private void updateDataBase()
{
try
{ {
// 语言设置登录 // 语言设置登录
Settings LanguageData = new Settings() Settings LanguageData = new Settings()
@ -161,6 +193,11 @@ namespace SparkClient.ViewModel.Configuration.SettingsPages
}; };
RuleData.insert(); RuleData.insert();
} }
catch (Exception ex)
{
Logger.Error($"全局异常捕获:{ex.Message}", ex);
}
}
public void SelectFile(object param) public void SelectFile(object param)
{ {
using (var folderBrowserDlg = new FolderBrowserDialog()) using (var folderBrowserDlg = new FolderBrowserDialog())
@ -182,6 +219,9 @@ namespace SparkClient.ViewModel.Configuration.SettingsPages
} }
} }
} }
/// <summary>
/// 设定表实体
/// </summary>
public class Settings public class Settings
{ {
private static string TABLE_NAME = "SETTING"; private static string TABLE_NAME = "SETTING";
@ -203,7 +243,10 @@ namespace SparkClient.ViewModel.Configuration.SettingsPages
/// </summary> /// </summary>
[DbField("SETTING_P")] [DbField("SETTING_P")]
public required string Value { get; set; } public required string Value { get; set; }
/// <summary>
/// 设定表DB登录
/// </summary>
/// <returns>更新数量</returns>
public int insert() public int insert()
{ {
string sql = $"SELECT * FROM {TABLE_NAME} WHERE SETTING_ID = '{Key}';"; string sql = $"SELECT * FROM {TABLE_NAME} WHERE SETTING_ID = '{Key}';";
@ -219,8 +262,12 @@ namespace SparkClient.ViewModel.Configuration.SettingsPages
return DataBaseHelper.ExecuteNonQuery(insertSql); return DataBaseHelper.ExecuteNonQuery(insertSql);
} }
} }
/// <summary>
public static string SelectValueByName(string Id) /// 设定表值检索
/// </summary>
/// <param name="Id"></param>
/// <returns>value</returns>
public static string SelectValueById(string Id)
{ {
string sql = $"SELECT * FROM {TABLE_NAME} WHERE SETTING_ID = '{Id}';"; string sql = $"SELECT * FROM {TABLE_NAME} WHERE SETTING_ID = '{Id}';";
DataTable db = DataBaseHelper.ExecuteQuery(sql); DataTable db = DataBaseHelper.ExecuteQuery(sql);

@ -1,3 +1,4 @@
using System.Configuration;
using Newtonsoft.Json; using Newtonsoft.Json;
using SparkClient.Model.Entity.ApiEntity; using SparkClient.Model.Entity.ApiEntity;
using SparkClient.Model.Helper; using SparkClient.Model.Helper;
@ -15,6 +16,8 @@ using SparkClient.Model.Services;
using System.Text; using System.Text;
using System.IO; using System.IO;
using System.Windows.Media; using System.Windows.Media;
using log4net;
using Newtonsoft.Json.Linq;
using SparkClient.Model.Common; using SparkClient.Model.Common;
using Color = System.Windows.Media.Color; using Color = System.Windows.Media.Color;
using MessageBox = SparkClient.Views.Dialog.MessageBox; using MessageBox = SparkClient.Views.Dialog.MessageBox;
@ -170,7 +173,6 @@ public class DiamondSelectVM : BaseViewModel
parameter.CrownType = value.Split(" ")[1]; parameter.CrownType = value.Split(" ")[1];
parameter.PavType = value.Split(" ")[2]; parameter.PavType = value.Split(" ")[2];
} }
// 初始化SOC客户端服务,传入SOC端的地址和认证Token // 初始化SOC客户端服务,传入SOC端的地址和认证Token
_socClientService = new SOCClientService(); _socClientService = new SOCClientService();
// 启动soc // 启动soc
@ -207,6 +209,10 @@ public class DiamondSelectVM : BaseViewModel
string image_files = JsonConvert.SerializeObject(socResolt.Images, Formatting.Indented); string image_files = JsonConvert.SerializeObject(socResolt.Images, Formatting.Indented);
//string image_files =$"[ \"image_0.bmp\", \"image_1.bmp\", \"image_2.bmp\", \"image_3.bmp\", \"image_4.bmp\", \"image_5.bmp\", \"image_6.bmp\", \"image_7.bmp\", \"image_8.bmp\", \"image_9.bmp\", \"image_10.bmp\", \"image_11.bmp\", \"image_12.bmp\", \"image_13.bmp\", \"image_14.bmp\", \"image_15.bmp\", \"image_16.bmp\", \"image_17.bmp\", \"image_18.bmp\", \"image_19.bmp\", \"image_20.bmp\", \"image_21.bmp\", \"image_22.bmp\", \"image_23.bmp\", \"image_24.bmp\", \"image_25.bmp\", \"image_26.bmp\", \"image_27.bmp\", \"image_28.bmp\", \"image_29.bmp\", \"image_30.bmp\", \"image_31.bmp\", \"image_32.bmp\", \"image_33.bmp\", \"image_34.bmp\", \"image_35.bmp\", \"image_36.bmp\", \"image_37.bmp\", \"image_38.bmp\", \"image_39.bmp\", \"image_40.bmp\", \"image_41.bmp\", \"image_42.bmp\", \"image_43.bmp\", \"image_44.bmp\", \"image_45.bmp\", \"image_46.bmp\", \"image_47.bmp\", \"image_48.bmp\", \"image_49.bmp\", \"image_50.bmp\", \"image_51.bmp\", \"image_52.bmp\", \"image_53.bmp\", \"image_54.bmp\", \"image_55.bmp\", \"image_56.bmp\", \"image_57.bmp\", \"image_58.bmp\", \"image_59.bmp\", \"image_60.bmp\", \"image_61.bmp\", \"image_62.bmp\", \"image_63.bmp\", \"image_64.bmp\", \"image_65.bmp\", \"image_66.bmp\", \"image_67.bmp\", \"image_68.bmp\", \"image_69.bmp\", \"image_70.bmp\", \"image_71.bmp\", \"image_72.bmp\", \"image_73.bmp\", \"image_74.bmp\", \"image_75.bmp\", \"image_76.bmp\", \"image_77.bmp\", \"image_78.bmp\", \"image_79.bmp\", \"image_80.bmp\", \"image_81.bmp\", \"image_82.bmp\", \"image_83.bmp\", \"image_84.bmp\", \"image_85.bmp\", \"image_86.bmp\", \"image_87.bmp\", \"image_88.bmp\", \"image_89.bmp\", \"image_90.bmp\", \"image_91.bmp\", \"image_92.bmp\", \"image_93.bmp\", \"image_94.bmp\", \"image_95.bmp\", \"image_96.bmp\", \"image_97.bmp\", \"image_98.bmp\", \"image_99.bmp\"]" ; //string image_files =$"[ \"image_0.bmp\", \"image_1.bmp\", \"image_2.bmp\", \"image_3.bmp\", \"image_4.bmp\", \"image_5.bmp\", \"image_6.bmp\", \"image_7.bmp\", \"image_8.bmp\", \"image_9.bmp\", \"image_10.bmp\", \"image_11.bmp\", \"image_12.bmp\", \"image_13.bmp\", \"image_14.bmp\", \"image_15.bmp\", \"image_16.bmp\", \"image_17.bmp\", \"image_18.bmp\", \"image_19.bmp\", \"image_20.bmp\", \"image_21.bmp\", \"image_22.bmp\", \"image_23.bmp\", \"image_24.bmp\", \"image_25.bmp\", \"image_26.bmp\", \"image_27.bmp\", \"image_28.bmp\", \"image_29.bmp\", \"image_30.bmp\", \"image_31.bmp\", \"image_32.bmp\", \"image_33.bmp\", \"image_34.bmp\", \"image_35.bmp\", \"image_36.bmp\", \"image_37.bmp\", \"image_38.bmp\", \"image_39.bmp\", \"image_40.bmp\", \"image_41.bmp\", \"image_42.bmp\", \"image_43.bmp\", \"image_44.bmp\", \"image_45.bmp\", \"image_46.bmp\", \"image_47.bmp\", \"image_48.bmp\", \"image_49.bmp\", \"image_50.bmp\", \"image_51.bmp\", \"image_52.bmp\", \"image_53.bmp\", \"image_54.bmp\", \"image_55.bmp\", \"image_56.bmp\", \"image_57.bmp\", \"image_58.bmp\", \"image_59.bmp\", \"image_60.bmp\", \"image_61.bmp\", \"image_62.bmp\", \"image_63.bmp\", \"image_64.bmp\", \"image_65.bmp\", \"image_66.bmp\", \"image_67.bmp\", \"image_68.bmp\", \"image_69.bmp\", \"image_70.bmp\", \"image_71.bmp\", \"image_72.bmp\", \"image_73.bmp\", \"image_74.bmp\", \"image_75.bmp\", \"image_76.bmp\", \"image_77.bmp\", \"image_78.bmp\", \"image_79.bmp\", \"image_80.bmp\", \"image_81.bmp\", \"image_82.bmp\", \"image_83.bmp\", \"image_84.bmp\", \"image_85.bmp\", \"image_86.bmp\", \"image_87.bmp\", \"image_88.bmp\", \"image_89.bmp\", \"image_90.bmp\", \"image_91.bmp\", \"image_92.bmp\", \"image_93.bmp\", \"image_94.bmp\", \"image_95.bmp\", \"image_96.bmp\", \"image_97.bmp\", \"image_98.bmp\", \"image_99.bmp\"]" ;
// 保存图片到历史记录文件夹
HandleAlgorithmFailure(image_files);
// 启动算法 // 启动算法
parameter = _algorithmServer.CallParseJsonAndReturnActions(parameter.Shape, parameter.CrownType, image_files); parameter = _algorithmServer.CallParseJsonAndReturnActions(parameter.Shape, parameter.CrownType, image_files);
//机器号 //机器号
@ -365,6 +371,94 @@ public class DiamondSelectVM : BaseViewModel
await Task.Delay(5); await Task.Delay(5);
loading.Close(); loading.Close();
} }
}
/// <summary>
/// 处理算法调用失败时的逻辑,包括保存图片到历史记录文件夹
/// </summary>
/// <param name="image_files">图片文件路径的 JSON 字符串</param>
///
private static readonly ILog Logger = LogManager.GetLogger(typeof(AlgorithmServer));
private void HandleAlgorithmFailure(string image_files)
{
// 从配置文件中读取 imageHistoryPath
// 定义历史记录文件夹路径
string? imageHistoryPath = ConfigurationManager.AppSettings["ImageHistoryPath"];
if (string.IsNullOrEmpty(imageHistoryPath))
{
Logger.Error("ImageHistoryPath is not configured in AppSettings.");
return;
}
// 生成时间戳,格式为 yyyyMMddHHmmss
string timestamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
// 组合新的文件夹路径
string newFolderPath = Path.Combine(imageHistoryPath, $"image-{timestamp}");
// 检查 D 盘内存空间
DriveInfo dDrive = new DriveInfo("D");
long requiredSpace = 10L * 1024 * 1024 * 1024; // 10GB
if (dDrive.TotalFreeSpace < requiredSpace)
{
// 如果 D 盘空间不足 10GB,删除最早创建的10个文件夹
DirectoryInfo historyDir = new DirectoryInfo(imageHistoryPath); // 获取历史记录文件夹的信息
DirectoryInfo[] subDirs = historyDir.GetDirectories(); // 获取历史记录文件夹中的所有子文件夹
if (subDirs.Length > 0)
{
// 按创建时间排序子文件夹
var orderedSubDirs = subDirs.OrderBy(d => d.CreationTime).ToList();
int foldersToDelete = Math.Min(10, orderedSubDirs.Count);
// 删除最早的 10 个文件夹,如果不够 10 个则全删掉
for (int i = 0; i < foldersToDelete; i++)
{
orderedSubDirs[i].Delete(true);
}
}
}
// 创建新文件夹
Directory.CreateDirectory(newFolderPath);
// 保存图片到新文件夹
try
{
// 解析 image_files JSON 数组
JArray imageFilesArray = JArray.Parse(image_files);
string[] imageFiles = imageFilesArray.Select(token => token.ToString()).ToArray();
string? imageBasePath = ConfigurationManager.AppSettings["ImageFileBasePath"]; // 图片根目录
if (string.IsNullOrEmpty(imageBasePath))
{
Logger.Error("ImageFileBasePath is not configured in AppSettings.");
return;
}
foreach (string imageFile in imageFiles)
{
// 获取文件名
string fileName = Path.GetFileName(imageFile);
// 构建完整的源文件路径
string sourcePath = Path.Combine(imageBasePath, imageFile);
// 组合目标路径
string destinationPath = Path.Combine(newFolderPath, fileName);
// 复制文件到目标路径,如果目标文件已存在则覆盖
File.Copy(sourcePath, destinationPath, true);
}
}
catch (JsonException ex)
{
// 记录日志或处理异常
Logger.Error($"Error parsing image_files JSON: {ex.Message}");
Logger.Error($"Stack Trace: {ex.StackTrace}");
}
catch (Exception ex)
{
// 记录其他异常
Logger.Error($"Error saving images: {ex.Message}");
Logger.Error($"Stack Trace: {ex.StackTrace}");
}
} }
/// <summary> /// <summary>
/// 跳转至检测结果 /// 跳转至检测结果

@ -46,6 +46,7 @@ public class GradingResultVM : BaseViewModel
private string _ds; private string _ds;
private RowDetail _selRowDataDetail; private RowDetail _selRowDataDetail;
private bool _isEnabled; private bool _isEnabled;
public bool isSaved = false;
public ICommand SaveFileCommand { get; } public ICommand SaveFileCommand { get; }
public ICommand SaveAsCommand { get; } public ICommand SaveAsCommand { get; }
public List<DataInfo> DtResults { get { return _dtResults; } set { _dtResults = value; OnPropertyChanged(nameof(DtResults)); } } public List<DataInfo> DtResults { get { return _dtResults; } set { _dtResults = value; OnPropertyChanged(nameof(DtResults)); } }
@ -87,7 +88,7 @@ public class GradingResultVM : BaseViewModel
algorithmResult = result as AlgorithmResultEntity?? new AlgorithmResultEntity(); algorithmResult = result as AlgorithmResultEntity?? new AlgorithmResultEntity();
InitView(algorithmResult); InitView(algorithmResult);
machine = algorithmResult.DeviceId; machine = algorithmResult.DeviceId;
username = Settings.SelectValueByName("PERMISSIONS"); username = Settings.SelectValueById("PERMISSIONS");
if (ruleId.StartsWith("IGI")) if (ruleId.StartsWith("IGI"))
{ {
IsEnabled = true; IsEnabled = true;
@ -139,7 +140,7 @@ public class GradingResultVM : BaseViewModel
Type type = colorConfigEntity.GetType(); Type type = colorConfigEntity.GetType();
foreach (var property in colorProperty) foreach (var property in colorProperty)
{ {
var value = Settings.SelectValueByName(property.Key); var value = Settings.SelectValueById(property.Key);
PropertyInfo? p = type.GetProperty(property.Value); PropertyInfo? p = type.GetProperty(property.Value);
if (p != null && !string.IsNullOrEmpty(value)) if (p != null && !string.IsNullOrEmpty(value))
{ {
@ -196,7 +197,7 @@ public class GradingResultVM : BaseViewModel
} }
private string getRuleId() private string getRuleId()
{ {
return Settings.SelectValueByName("RuleId"); return Settings.SelectValueById("RuleId");
} }
#endregion #endregion
/// <summary> /// <summary>
@ -662,6 +663,7 @@ public class GradingResultVM : BaseViewModel
string fullPath = Path.Combine(getFilePath(), this.DiamondCode); string fullPath = Path.Combine(getFilePath(), this.DiamondCode);
ExportFile(fullPath); ExportFile(fullPath);
SaveTestResult(SaveStatus.Save); SaveTestResult(SaveStatus.Save);
isSaved = true;
} }
private string getFilePath() private string getFilePath()
{ {

Loading…
Cancel
Save