From 681bc64930fdc589d9da12d988729946b6e759a9 Mon Sep 17 00:00:00 2001 From: sunhonglei Date: Fri, 10 Jan 2025 16:36:09 +0800 Subject: [PATCH] fix: --- Language/zh_CN.xaml | 2 +- ViewModel/Configuration/AlgorithmConfigVM.cs | 28 ++- ViewModel/Configuration/CutConfigVM.cs | 185 +++++++++++-------- ViewModel/Configuration/LevelConfigVM.cs | 128 ++++++++++--- ViewModel/Configuration/SettingBaseVM.cs | 32 +++- ViewModel/Dialog/StartDialogVM.cs | 3 + ViewModel/Grading/DiamondSelectVM.cs | 8 + ViewModel/Grading/GradingResultVM.cs | 54 +++++- Views/Configuration/LevelConfigPage.xaml | 2 +- 9 files changed, 320 insertions(+), 122 deletions(-) diff --git a/Language/zh_CN.xaml b/Language/zh_CN.xaml index 48a2bf1..28b5279 100644 --- a/Language/zh_CN.xaml +++ b/Language/zh_CN.xaml @@ -198,5 +198,5 @@ CUDA未安装,程序执行中可能会出错 MSVC Runtime未安装,程序执行中可能会出错 文件路径不存在 - + 定级配置文件格式不正 \ No newline at end of file diff --git a/ViewModel/Configuration/AlgorithmConfigVM.cs b/ViewModel/Configuration/AlgorithmConfigVM.cs index a35a5b2..a77416a 100644 --- a/ViewModel/Configuration/AlgorithmConfigVM.cs +++ b/ViewModel/Configuration/AlgorithmConfigVM.cs @@ -39,20 +39,28 @@ public class AlgorithmConfigVM : BaseViewModel /// public void InitAlgorithmData(object param) { - AlgorithmConfigJson = "{}"; - string sql = @"SELECT JSON as json FROM ALGORITHM_CONFIG ORDER BY JSON_ORDER"; - DataTable dataTable = DataBaseHelper.ExecuteQuery(sql); - StringBuilder sb = new StringBuilder(); - if (dataTable != null) + try { - foreach (DataRow row in dataTable.Rows) + AlgorithmConfigJson = "{}"; + string sql = @"SELECT JSON as json FROM ALGORITHM_CONFIG ORDER BY JSON_ORDER"; + DataTable dataTable = DataBaseHelper.ExecuteQuery(sql); + StringBuilder sb = new StringBuilder(); + if (dataTable != null) { - sb.Append(row["json"].ToString()); + foreach (DataRow row in dataTable.Rows) + { + sb.Append(row["json"].ToString()); + } + } + if (sb.Length > 0) + { + AlgorithmConfigJson = JToken.Parse(sb.ToString()).ToString(); } } - if (sb.Length > 0) + catch (Exception ex) { - AlgorithmConfigJson = JToken.Parse(sb.ToString()).ToString(); + new MessageBox().Show($"{MultilingualHelper.getString("ApplicationError")}{ex.Message}"); + Logger.Error($"全局异常捕获:{ex.Message}", ex); } } @@ -118,7 +126,7 @@ public class AlgorithmConfigVM : BaseViewModel catch (Exception ex) { Growl.Error(MultilingualHelper.getString("SaveFail")); - Logger.Error(ex); + Logger.Error($"全局异常捕获:{ex.Message}",ex); } } private void IsEnabledByRole (){ diff --git a/ViewModel/Configuration/CutConfigVM.cs b/ViewModel/Configuration/CutConfigVM.cs index ec59a0d..b61c7d0 100644 --- a/ViewModel/Configuration/CutConfigVM.cs +++ b/ViewModel/Configuration/CutConfigVM.cs @@ -8,11 +8,13 @@ using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolTip; using System.Text.RegularExpressions; using Microsoft.Data.Sqlite; using SparkClient.ViewModel.Configuration.SettingsPages; - +using log4net; +using MessageBox = SparkClient.Views.Dialog.MessageBox; namespace SparkClient.ViewModel.Configuration; public class CutConfigVM: BaseViewModel { + private static readonly ILog Logger = LogManager.GetLogger(typeof(CutConfigVM)); public ICommand AddRowsCommand { get; } public ICommand SaveCutConfigDataCommand { get; } public ICommand DelCutRowCommand { get; } @@ -23,17 +25,26 @@ public class CutConfigVM: BaseViewModel public DataTable CutterInfos { get { return _cutterInfos; } set { _cutterInfos = value; OnPropertyChanged("CutterInfos"); } } private int RowNo = 0; + public CutConfigVM() { - AddRowsCommand = new RelayCommand(AddRows); + try + { + AddRowsCommand = new RelayCommand(AddRows); - SaveCutConfigDataCommand = new RelayCommand(SaveCutConfigData); + SaveCutConfigDataCommand = new RelayCommand(SaveCutConfigData); - DelCutRowCommand = new RelayCommand(DelCutRow); - // 初始化VIEW层参数 - // 初始化VIEW层Command - this.InitCutConfigData(null); - IsEnabledByRole(); + DelCutRowCommand = new RelayCommand(DelCutRow); + // 初始化VIEW层参数 + // 初始化VIEW层Command + this.InitCutConfigData(null); + IsEnabledByRole(); + } + catch (Exception ex) + { + new MessageBox().Show($"{MultilingualHelper.getString("ApplicationError")}{ex.Message}"); + Logger.Error($"全局异常捕获:{ex.Message}", ex); + } } @@ -43,15 +54,23 @@ public class CutConfigVM: BaseViewModel /// public void InitCutConfigData(object param) { - string sql = @"SELECT ITEM_NAME as ItemName , KEY AS Key, VALUE AS Value, GUID FROM CUTTER_CONFIG"; - DataTable dataTable = DataBaseHelper.ExecuteQuery(sql); - if (dataTable!=null) { - dataTable.Columns.Add(new DataColumn("RowNo", typeof(int))); - foreach (DataRow row in dataTable.Rows) - { - row["RowNo"] = RowNo++; + try + { + string sql = @"SELECT ITEM_NAME as ItemName , KEY AS Key, VALUE AS Value, GUID FROM CUTTER_CONFIG"; + DataTable dataTable = DataBaseHelper.ExecuteQuery(sql); + if (dataTable!=null) { + dataTable.Columns.Add(new DataColumn("RowNo", typeof(int))); + foreach (DataRow row in dataTable.Rows) + { + row["RowNo"] = RowNo++; + } + CutterInfos = dataTable; } - CutterInfos = dataTable; + } + catch (Exception ex) + { + new MessageBox().Show($"{MultilingualHelper.getString("ApplicationError")}{ex.Message}"); + Logger.Error($"全局异常捕获:{ex.Message}", ex); } } @@ -61,7 +80,15 @@ public class CutConfigVM: BaseViewModel /// 行数 public void AddRows(object row) { - CutterInfos.Rows.Add("", "", "",Guid.NewGuid(), RowNo++); + try + { + CutterInfos.Rows.Add("", "", "",Guid.NewGuid(), RowNo++); + } + catch (Exception ex) + { + new MessageBox().Show($"{MultilingualHelper.getString("ApplicationError")}{ex.Message}"); + Logger.Error($"全局异常捕获:{ex.Message}", ex); + } } /// @@ -70,79 +97,87 @@ public class CutConfigVM: BaseViewModel /// public void SaveCutConfigData(object param) { - int count = CutterInfos.AsEnumerable().Where(r => r["Key"].ToString() != "").GroupBy(r => new { key = r.Field("Key") }).Count(); - if (count < CutterInfos.AsEnumerable().Where(r => r["Key"].ToString() != "").Count()) - { - Growl.Error("Key有重复数据"); - return; - } - string sql = @"SELECT ITEM_NAME as ItemName , KEY AS Key, VALUE AS Value, GUID FROM CUTTER_CONFIG"; - DataTable dataTable = DataBaseHelper.ExecuteQuery(sql); - int insertCount = 0; - foreach (DataRow row in CutterInfos.Rows) + try { - if (row["Key"].ToString() == "") + int count = CutterInfos.AsEnumerable().Where(r => r["Key"].ToString() != "").GroupBy(r => new { key = r.Field("Key") }).Count(); + if (count < CutterInfos.AsEnumerable().Where(r => r["Key"].ToString() != "").Count()) { - continue; + Growl.Error("Key有重复数据"); + return; } - DataRow? removerow = dataTable.AsEnumerable().Where(r => r["GUID"].ToString() == row["GUID"].ToString()).FirstOrDefault(); - if (removerow != null) + string sql = @"SELECT ITEM_NAME as ItemName , KEY AS Key, VALUE AS Value, GUID FROM CUTTER_CONFIG"; + DataTable dataTable = DataBaseHelper.ExecuteQuery(sql); + int insertCount = 0; + foreach (DataRow row in CutterInfos.Rows) { - CutterConfigEntity entity = new CutterConfigEntity() - { - ItemName = row["ItemName"].ToString() ?? "", - Key = row["Key"].ToString() ?? "", - Value = row["Value"].ToString() ?? "", - GUID = Guid.Parse(row["GUID"].ToString()??"") - }; - sql = entity.GenerateUpdateSQL(); - SqliteParameter[] sqliteParameters = { - new SqliteParameter("@ITEM_NAME", row["ItemName"].ToString()), - new SqliteParameter("@KEY", row["Key"].ToString()), - new SqliteParameter("@VALUE", row["Value"].ToString()), - new SqliteParameter("@GUID", row["GUID"].ToString()), - }; - insertCount += DataBaseHelper.ExecuteNonQuery(sql, sqliteParameters); - dataTable.Rows.Remove(removerow); + if (row["Key"].ToString() == "") + { + continue; + } + DataRow? removerow = dataTable.AsEnumerable().Where(r => r["GUID"].ToString() == row["GUID"].ToString()).FirstOrDefault(); + if (removerow != null) + { + CutterConfigEntity entity = new CutterConfigEntity() + { + ItemName = row["ItemName"].ToString() ?? "", + Key = row["Key"].ToString() ?? "", + Value = row["Value"].ToString() ?? "", + GUID = Guid.Parse(row["GUID"].ToString()??"") + }; + sql = entity.GenerateUpdateSQL(); + SqliteParameter[] sqliteParameters = { + new SqliteParameter("@ITEM_NAME", row["ItemName"].ToString()), + new SqliteParameter("@KEY", row["Key"].ToString()), + new SqliteParameter("@VALUE", row["Value"].ToString()), + new SqliteParameter("@GUID", row["GUID"].ToString()), + }; + insertCount += DataBaseHelper.ExecuteNonQuery(sql, sqliteParameters); + dataTable.Rows.Remove(removerow); + } + else + { + CutterConfigEntity entity = new CutterConfigEntity() + { + ItemName = row["ItemName"].ToString() ?? "", + Key = row["Key"].ToString() ?? "", + Value = row["Value"].ToString() ?? "" + }; + sql = entity.GenerateInsertSQL(); + SqliteParameter[] sqliteParameters = { + new SqliteParameter("@ItemName", row["ItemName"].ToString()), + new SqliteParameter("@Key", row["Key"].ToString()), + new SqliteParameter("@Value", row["Value"].ToString()), + new SqliteParameter("@GUID", row["GUID"].ToString()), + }; + insertCount += DataBaseHelper.ExecuteNonQuery(sql, sqliteParameters); + } } - else + foreach (DataRow row in dataTable.Rows) { + Guid.TryParse(row["GUID"].ToString(), out Guid result); CutterConfigEntity entity = new CutterConfigEntity() { ItemName = row["ItemName"].ToString() ?? "", Key = row["Key"].ToString() ?? "", - Value = row["Value"].ToString() ?? "" - }; - sql = entity.GenerateInsertSQL(); - SqliteParameter[] sqliteParameters = { - new SqliteParameter("@ItemName", row["ItemName"].ToString()), - new SqliteParameter("@Key", row["Key"].ToString()), - new SqliteParameter("@Value", row["Value"].ToString()), - new SqliteParameter("@GUID", row["GUID"].ToString()), + Value = row["Value"].ToString() ?? "", + GUID = result }; - insertCount += DataBaseHelper.ExecuteNonQuery(sql, sqliteParameters); + sql = entity.GenerateDeleteSQL(); + insertCount += DataBaseHelper.ExecuteNonQuery(sql); } - } - foreach (DataRow row in dataTable.Rows) - { - Guid.TryParse(row["GUID"].ToString(), out Guid result); - CutterConfigEntity entity = new CutterConfigEntity() + if (insertCount>=0) { - ItemName = row["ItemName"].ToString() ?? "", - Key = row["Key"].ToString() ?? "", - Value = row["Value"].ToString() ?? "", - GUID = result - }; - sql = entity.GenerateDeleteSQL(); - insertCount += DataBaseHelper.ExecuteNonQuery(sql); - } - if (insertCount>=0) - { - Growl.Info("保存成功"); + Growl.Info("保存成功"); + } + else + { + Growl.Error("保存失败"); + } } - else + catch (Exception ex) { - Growl.Error("保存失败"); + new MessageBox().Show($"{MultilingualHelper.getString("ApplicationError")}{ex.Message}"); + Logger.Error($"全局异常捕获:{ex.Message}", ex); } } private void IsEnabledByRole() diff --git a/ViewModel/Configuration/LevelConfigVM.cs b/ViewModel/Configuration/LevelConfigVM.cs index 1e56e33..8de66e2 100644 --- a/ViewModel/Configuration/LevelConfigVM.cs +++ b/ViewModel/Configuration/LevelConfigVM.cs @@ -16,7 +16,7 @@ namespace SparkClient.ViewModel.Configuration; public class LevelConfigVM : BaseViewModel { - private static readonly ILog Logger = LogManager.GetLogger(typeof(GradingResultVM)); + private static readonly ILog Logger = LogManager.GetLogger(typeof(LevelConfigVM)); public ICommand ChangeShapeModelCommand { get; } public ICommand ChangeInstituteModelCommand { get; } public ICommand LoadLevelConfigCommand { get; } @@ -54,16 +54,24 @@ public class LevelConfigVM : BaseViewModel private string STANDARD_NAME = MultilingualHelper.getString("STANDARD_NAME"); public LevelConfigVM(DataGrid dataGrid) { - if (dataGrid == null) return; - this.dataGrid = dataGrid; - ChangeShapeModelCommand = new RelayCommand(ChangeShapeModel); - ChangeInstituteModelCommand = new RelayCommand(ChangeInstituteModel); - LoadLevelConfigCommand = new RelayCommand(LoadLevelConfig); - DelLevelConfigCommand = new RelayCommand(DelLevelConfig); - SaveLevelConfigCommand = new RelayCommand(SaveLevelConfig); - InitLevelConfig(null); - InitData(); - IsUpdateButtonEnabled = false; + try + { + if (dataGrid == null) return; + this.dataGrid = dataGrid; + ChangeShapeModelCommand = new RelayCommand(ChangeShapeModel); + ChangeInstituteModelCommand = new RelayCommand(ChangeInstituteModel); + LoadLevelConfigCommand = new RelayCommand(LoadLevelConfig); + DelLevelConfigCommand = new RelayCommand(DelLevelConfig); + SaveLevelConfigCommand = new RelayCommand(SaveLevelConfig); + InitLevelConfig(null); + InitData(); + IsUpdateButtonEnabled = false; + } + catch (Exception ex) + { + new MessageBox().Show($"{MultilingualHelper.getString("ApplicationError")}{ex.Message}"); + Logger.Error($"全局异常捕获:{ex.Message}", ex); + } } /// @@ -72,13 +80,24 @@ public class LevelConfigVM : BaseViewModel /// public void InitLevelConfig(object param) { - Save_successful_message = MultilingualHelper.getString("Save_successful_message"); - save_fail_message = MultilingualHelper.getString("save_fail_message"); - no_data_message = MultilingualHelper.getString("no_data_message"); - grade_config_left_top = MultilingualHelper.getString("grade_config_left_top"); - GRADE_NAME = MultilingualHelper.getString("GRADE_NAME"); - STANDARD_NAME = MultilingualHelper.getString("STANDARD_NAME"); + try + { + Save_successful_message = MultilingualHelper.getString("Save_successful_message"); + save_fail_message = MultilingualHelper.getString("save_fail_message"); + no_data_message = MultilingualHelper.getString("no_data_message"); + grade_config_left_top = MultilingualHelper.getString("grade_config_left_top"); + GRADE_NAME = MultilingualHelper.getString("GRADE_NAME"); + STANDARD_NAME = MultilingualHelper.getString("STANDARD_NAME"); + } + catch (Exception ex) + { + new MessageBox().Show($"{MultilingualHelper.getString("ApplicationError")}{ex.Message}"); + Logger.Error($"全局异常捕获:{ex.Message}", ex); + } } + /// + /// 初始化数据(形状列表检索) + /// private void InitData() { dataGrid.Columns.Clear(); @@ -89,13 +108,20 @@ public class LevelConfigVM : BaseViewModel ShapeId = Shapes.AsEnumerable().FirstOrDefault()["SHAPE_ID"].ToString(); } } + /// + /// 初始化数据(规则列表检索) + /// private string setInstitutes(string id) { string insituteSql = $"SELECT RULE_ID,RULE_NAME,RULE_EN_NAME FROM RULE WHERE RULE_ID NOT LIKE '%_TA_%';"; Institutes = DataBaseHelper.ExecuteQuery(insituteSql); return Institutes.AsEnumerable().FirstOrDefault()["RULE_ID"].ToString(); } - + /// + /// 页面数据初始化(检索) + /// + /// + /// private void setDataGrid(string shapeId, string ruleId) { string gradeSql = $"SELECT GRADE_NAME,GRADE_EN_NAME,GRADE_ORDER FROM GRADE WHERE SHAPE_ID = '{shapeId}' AND RULE_ID LIKE '{ruleId}%' GROUP BY GRADE_NAME,GRADE_EN_NAME,GRADE_ORDER ORDER BY GRADE_ORDER;"; @@ -105,23 +131,32 @@ public class LevelConfigVM : BaseViewModel DataTable rowInfos = DataBaseHelper.ExecuteQuery(standardSql); setStandardList(columnInfos, rowInfos); } - + /// + /// 页面数据初始化(页面值设定) + /// + /// + /// private void setStandardList(DataTable gradeList, DataTable standardList) { try { + // 定义单元格样式 Style cellStyle = new Style(typeof(TextBlock)); Setter setSellStyle = new Setter(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center); cellStyle.Setters.Add(setSellStyle); Setter setSellStyle1 = new Setter(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center); cellStyle.Setters.Add(setSellStyle1); + // 清空datagrid中的数据 dataGrid.Columns.Clear(); if (gradeList != null) { + StandardList = new DataTable(); List columns = new List(); + // 循环等级列表,设定datagrid中的列 foreach (DataRow columnInfo in gradeList.Rows) { + // 最高等的情况列放置于中间 if ("1".Equals(columnInfo["GRADE_ORDER"].ToString())) { columns.Add(new DataColumn(columnInfo["GRADE_EN_NAME"].ToString())); @@ -129,6 +164,7 @@ public class LevelConfigVM : BaseViewModel //this.dataGrid.Columns.Add(new DataGridTextColumn() { Header = columnInfo[GRADE_NAME].ToString(), Binding = new Binding(columnInfo["GRADE_EN_NAME"].ToString()),ElementStyle = cellStyle }); this.dataGrid.Columns.Add(GetDataGridColumn(columnInfo[GRADE_NAME].ToString() ?? "", columnInfo["GRADE_EN_NAME"].ToString() ?? "")); } + // 最高等级以外情况的列放置于两侧 else { //this.dataGrid.Columns.Insert(0, new DataGridTextColumn() { Header = columnInfo[GRADE_NAME].ToString(), Binding = new Binding(columnInfo["GRADE_EN_NAME"].ToString() + "_MIN"), ElementStyle = cellStyle }); @@ -141,15 +177,18 @@ public class LevelConfigVM : BaseViewModel columns.Add(new DataColumn(columnInfo["GRADE_EN_NAME"].ToString() + "_MAX" + "_" + 1)); } } + // 在最左侧放置测试项目列 columns.Insert(0, new DataColumn("title")); this.dataGrid.Columns.Insert(0, new DataGridTextColumn() { Header = grade_config_left_top, Binding = new Binding("title"), ElementStyle = cellStyle }); StandardList.Columns.AddRange(columns.ToArray()); - // 以标准名分组表示每一行 + if (standardList != null) { + // 以规则id分组(国标时会有多中规则id的情况) var standardRules = standardList.AsEnumerable().GroupBy(r => r["RULE_ID"].ToString()); foreach (var ruleStandardList in standardRules) { + // 以测试项目名分组表示每一行 var standards = ruleStandardList.AsEnumerable().GroupBy(r => r[STANDARD_NAME].ToString()); foreach (var standard in standards) { @@ -159,6 +198,7 @@ public class LevelConfigVM : BaseViewModel // 每一行单元格内数据 var row = standard.Where(s => s["GRADE_ORDER"].ToString() == columnInfo["GRADE_ORDER"].ToString()).FirstOrDefault(); string value = ""; + // 国标时有空场合,为空时做以下处理 if (row == null) { if ("1".Equals(columnInfo["GRADE_ORDER"].ToString())) @@ -175,10 +215,14 @@ public class LevelConfigVM : BaseViewModel } continue; } + // 把获取的数据按照定级排序放置与单元格中 + // 最高等级放中间,其他的依次往两侧排列 + // 最高等级 if ("1".Equals(row["GRADE_ORDER"].ToString())) { string Min = row["STANDARD_MIN"].ToString(); string Max = row["STANDARD_MAX"].ToString(); + // 最大值并且最小值不为空时 以最小值-最大值显示 if (!string.IsNullOrEmpty(Min) && !string.IsNullOrEmpty(Max)) { value = getFix(row, "MIN_PREFIX") + @@ -187,6 +231,7 @@ public class LevelConfigVM : BaseViewModel + getFix(row, "MIN_SUFFIX") ; } + // 最小值不为空,最大值为空时 显示最小值 else if (!string.IsNullOrEmpty(Min)) { value = getFix(row, "MIN_PREFIX") + @@ -194,6 +239,7 @@ public class LevelConfigVM : BaseViewModel + getFix(row, "MIN_SUFFIX") ; } + // 最大值不为空,最小值为空时 显示最大值 else if (!string.IsNullOrEmpty(Max)) { value = getFix(row, "MIN_PREFIX") + @@ -201,7 +247,7 @@ public class LevelConfigVM : BaseViewModel + getFix(row, "MIN_SUFFIX") ; } - + // 有换行符时 分两行显示 var arr = value.Split("\r\n", 2); rowInfo.Add(arr[0]); if (arr.Length > 1) @@ -213,6 +259,7 @@ public class LevelConfigVM : BaseViewModel rowInfo.Add(""); } } + // 其他等级 依次放两边 else { // 每一行单元格内数据 @@ -290,6 +337,8 @@ public class LevelConfigVM : BaseViewModel if (ruleId != null && !string.IsNullOrEmpty(ruleId)) { string ta = ruleId.Substring(ruleId.Length - 2); + + // 国标场合 按照规则id中涵盖信息不同 对测试项目有不同描述 if (ruleId.StartsWith("GB")) { if ("49".Equals(ta)) @@ -321,6 +370,13 @@ public class LevelConfigVM : BaseViewModel Logger.Error($"全局异常捕获:{ex.Message}", ex); } } + /// + /// 设置单元格内部元素(现在单元格内部元素为两个textblock) + /// + /// + /// + /// + /// private DataGridColumn GetDataGridColumn(string Header,string Binding,int lineCount = 2) { //Style cellStyle = new Style(typeof(TextBlock)); @@ -463,7 +519,7 @@ public class LevelConfigVM : BaseViewModel catch (Exception ex) { DataBaseHelper.rollback(); Logger.Error($"全局异常捕获:{ex.Message}", ex); - Growl.Error(save_fail_message); + new MessageBox().Show($"{MultilingualHelper.getString("ApplicationError")}{ex.Message}"); } } /// @@ -483,9 +539,7 @@ public class LevelConfigVM : BaseViewModel { try { - InstitutesEnabled = false; - ShapesEnabled = false; - IsUpdateButtonEnabled = true; + Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog(); openFileDialog.Filter = "Text files (*.enc)|*.enc|All files (*.*)|*.*"; jsonEntity = null; @@ -495,8 +549,17 @@ public class LevelConfigVM : BaseViewModel string content = ""; if (File.Exists(filename)) { - content = AESHelper.DecryptFile(filename, "000000"); - jsonEntity = JsonConvert.DeserializeObject(content); + try + { + content = AESHelper.DecryptFile(filename, "000000"); + jsonEntity = JsonConvert.DeserializeObject(content); + } + catch (Exception ex) + { + new MessageBox().Show($"{MultilingualHelper.getString("LevelConfigFormatError")}"); + Logger.Error($"全局异常捕获:{ex.Message}", ex); + return; + } } } else @@ -549,6 +612,17 @@ public class LevelConfigVM : BaseViewModel string standardInfosJson = JsonConvert.SerializeObject(jsonEntity.standardInfos); DataTable standardInfos = Common.JsonToDataTable(standardInfosJson); setStandardList(gradeInfos, standardInfos); + InstitutesEnabled = false; + ShapesEnabled = false; + IsUpdateButtonEnabled = true; + } + else + { + new MessageBox().Show($"{MultilingualHelper.getString("LevelConfigFormatError")}"); + InstitutesEnabled = true; + ShapesEnabled = true; + IsUpdateButtonEnabled = false; + return; } } catch (Exception ex) diff --git a/ViewModel/Configuration/SettingBaseVM.cs b/ViewModel/Configuration/SettingBaseVM.cs index fda53ff..1bba0ed 100644 --- a/ViewModel/Configuration/SettingBaseVM.cs +++ b/ViewModel/Configuration/SettingBaseVM.cs @@ -1,11 +1,15 @@ +using log4net; +using SparkClient.Model.Helper; using SparkClient.ViewModel.BaseWindow; using SparkClient.ViewModel.Configuration.SettingsPages; using System.Windows.Input; +using MessageBox = SparkClient.Views.Dialog.MessageBox; namespace SparkClient.ViewModel.Configuration; public class SettingBaseVM : BaseViewModel { + private static readonly ILog Logger = LogManager.GetLogger(typeof(SettingBaseVM)); public SettingsVM CustomSetContent { get; } public ModelColorSetPageVM ModelColorSetContent { get; } @@ -13,17 +17,33 @@ public class SettingBaseVM : BaseViewModel public SettingBaseVM() { - CustomSetContent = new SettingsVM(); - ModelColorSetContent = new ModelColorSetPageVM(); - SaveCommand = new RelayCommand(Save); + try + { + CustomSetContent = new SettingsVM(); + ModelColorSetContent = new ModelColorSetPageVM(); + SaveCommand = new RelayCommand(Save); + } + catch (Exception ex) + { + new MessageBox().Show($"{MultilingualHelper.getString("ApplicationError")}{ex.Message}"); + Logger.Error($"ȫ쳣{ex.Message}", ex); + } } public void Save(object param) { - if(CustomSetContent.SaveUpdate(param)&& - ModelColorSetContent.SaveUpdate(param)) + try + { + if (CustomSetContent.SaveUpdate(param)&& + ModelColorSetContent.SaveUpdate(param)) + { + WindowManager.mainViewModel.Content = WindowManager.PreviousVM(); + } + } + catch (Exception ex) { - WindowManager.mainViewModel.Content = WindowManager.PreviousVM(); + new MessageBox().Show($"{MultilingualHelper.getString("ApplicationError")}{ex.Message}"); + Logger.Error($"ȫ쳣{ex.Message}", ex); } } } \ No newline at end of file diff --git a/ViewModel/Dialog/StartDialogVM.cs b/ViewModel/Dialog/StartDialogVM.cs index 07f13a2..aff6d77 100644 --- a/ViewModel/Dialog/StartDialogVM.cs +++ b/ViewModel/Dialog/StartDialogVM.cs @@ -11,6 +11,9 @@ using System.Windows.Input; namespace SparkClient.ViewModel.Dialog { + /// + /// 开始检测dialog 已作废 + /// internal class StartDialogVM : BaseViewModel { public ICommand SkipCommand { get; } diff --git a/ViewModel/Grading/DiamondSelectVM.cs b/ViewModel/Grading/DiamondSelectVM.cs index 9403e35..de2ab3f 100644 --- a/ViewModel/Grading/DiamondSelectVM.cs +++ b/ViewModel/Grading/DiamondSelectVM.cs @@ -24,6 +24,9 @@ using MessageBox = SparkClient.Views.Dialog.MessageBox; namespace SparkClient.ViewModel.Grading; +/// +/// 钻石选择画面VM +/// public class DiamondSelectVM : BaseViewModel { @@ -68,8 +71,13 @@ public class DiamondSelectVM : BaseViewModel Buttons = tempButtons; } + /// + /// 画面按钮添加 + /// + /// private List GetButtonInfos() { + List buttonInfos = new List(); buttonInfos.Add(new ButtonInfo() { Type = "round", IsEnabled = true, ImageName = "round.png", ButtonName = MultilingualHelper.getString("圆形") }); buttonInfos.Add(new ButtonInfo() { Type = "Hexagon", IsEnabled = false, ImageName = "Hexagon.png", ButtonName = MultilingualHelper.getString("六边形") }); diff --git a/ViewModel/Grading/GradingResultVM.cs b/ViewModel/Grading/GradingResultVM.cs index 2e446d5..66af112 100644 --- a/ViewModel/Grading/GradingResultVM.cs +++ b/ViewModel/Grading/GradingResultVM.cs @@ -25,10 +25,15 @@ using log4net; using SparkClient.ViewModel.Configuration; namespace SparkClient.ViewModel.Grading; - +/// +/// 检测结果画面VM +/// public class GradingResultVM : BaseViewModel { private static readonly ILog Logger = LogManager.GetLogger(typeof(GradingResultVM)); + /// + /// 钻石编码 + /// private string DiamondCode { get; set; } private List _dtResults; // ViewportData @@ -46,23 +51,68 @@ public class GradingResultVM : BaseViewModel private string _ds; private RowDetail _selRowDataDetail; private bool _isEnabled; + /// + /// 保存按钮状态 + /// public bool isSaved = false; + public ICommand SaveFileCommand { get; } public ICommand SaveAsCommand { get; } + /// + /// 左侧计算结果展示数据 + /// public List DtResults { get { return _dtResults; } set { _dtResults = value; OnPropertyChanged(nameof(DtResults)); } } + /// + /// 右侧钻石3D模型展示控件 + /// public ViewportData ViewportData { get { return _viewportData; } set { _viewportData = value; OnPropertyChanged(nameof(ViewportData)); } } + /// + /// 画面上方定级标准 + /// public string Standard { get { return _standard; } set { _standard = value; OnPropertyChanged(nameof(Standard)); } } + /// + /// 形状 + /// public string Shape { get { return _shape; } set { _shape = value; OnPropertyChanged(nameof(Shape)); } } + /// + /// 冠面类型 + /// public string CrownType { get { return _crownType; } set { _crownType = value; OnPropertyChanged(nameof(CrownType)); } } + /// + /// 亭面类型 + /// public string PavType { get { return _pavType; } set { _pavType = value; OnPropertyChanged(nameof(PavType)); } } + /// + /// 画面明细展示数据 + /// public RowDetail SelRowDataDetail { get { return _selRowDataDetail; } set { _selRowDataDetail = value; OnPropertyChanged(nameof(SelRowDataDetail)); } } - + /// + /// 重量 + /// public string Wight { get { return _wight; } set { _wight = value; OnPropertyChanged(nameof(Wight)); } } + /// + /// 切工等级(整体 画面上部显示) + /// public string CutLevelTotal { get { return _cutLevelTotal; } set { _cutLevelTotal = value; OnPropertyChanged(nameof(CutLevelTotal)); } } + /// + /// 对称性等级(整体 画面上部显示) + /// public string SymLevelTotal { get { return _symLevelTotal; } set { _symLevelTotal = value; OnPropertyChanged(nameof(SymLevelTotal)); } } + /// + /// 下拉列表DS + /// public DataTable DSList { get { return _dsList; } set { _dsList = value; OnPropertyChanged(nameof(DSList)); } } + /// + /// 下拉列表DS 选择的值 + /// public string DS { get { return _ds; } set { _ds = value; OnPropertyChanged(nameof(DS)); } } + /// + /// 定级下拉列表 + /// public DataTable GradeList { get { return _gradeList; } set { _gradeList = value; OnPropertyChanged(nameof(GradeList)); } } + /// + /// 活性 + /// public bool IsEnabled { get{ return _isEnabled; } set { _isEnabled = value; OnPropertyChanged(nameof(IsEnabled)); } } private readonly static string digitsFormat = "f1"; diff --git a/Views/Configuration/LevelConfigPage.xaml b/Views/Configuration/LevelConfigPage.xaml index 07b5824..01f100e 100644 --- a/Views/Configuration/LevelConfigPage.xaml +++ b/Views/Configuration/LevelConfigPage.xaml @@ -170,7 +170,7 @@ + ItemsSource="{Binding StandardList}" x:Name="DataGrid1" CanUserSortColumns="False" CanUserResizeColumns="False" CanUserResizeRows="False" CanUserReorderColumns="False">