From d3c0676a2d840629c607fcd8aa499d3cb78b4ed4 Mon Sep 17 00:00:00 2001 From: sunhonglei Date: Wed, 18 Dec 2024 17:30:56 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat=EF=BC=9A=E5=BC=B9=E5=87=BA=E7=AA=97?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ViewModel/Grading/GradingResultVM.cs | 56 +++++++- Views/Grading/GradingResult.xaml | 201 ++++++++++++++++++++++++++- Views/Grading/GradingResult.xaml.cs | 54 +++++-- 3 files changed, 298 insertions(+), 13 deletions(-) diff --git a/ViewModel/Grading/GradingResultVM.cs b/ViewModel/Grading/GradingResultVM.cs index f2f7b69..6d16a97 100644 --- a/ViewModel/Grading/GradingResultVM.cs +++ b/ViewModel/Grading/GradingResultVM.cs @@ -75,7 +75,7 @@ public class GradingResultVM : BaseViewModel } InitCombobox(); DS = "NA"; - // AutoSave(); + AutoSave(); } #region 画面初始化相关操作 @@ -900,12 +900,14 @@ public class GradingResultVM : BaseViewModel dictionary.Add("TWIST", "扭曲度"); dictionary.Add("CULET_TO_TABLE", "底尖到台面偏心比"); dictionary.Add("round", "圆形"); - return dictionary[id]; + dictionary.Add("", ""); + return dictionary[id??""]; } private string GetGradeName(int order) { // TODO DB没关联 Dictionary dictionary = new(); + dictionary.Add(0, ""); dictionary.Add(1,"极好"); dictionary.Add(2, "很好"); dictionary.Add(3, "好"); @@ -954,7 +956,32 @@ public class GradingResultVM : BaseViewModel SymLevelTotal = string.Empty; } } - + + public RowDetail getSelectData(string testItemId) + { + RowDetail row = new RowDetail(); + row.itemName = GetName(testItemId); + + var data = DtResults.Where(x => x.TestItemId == testItemId).FirstOrDefault(); + row.Avg = data != null ? data.Avg : ""; + row.Dev = data != null ? data.Dev : ""; + row.Max = data != null ? data.Max : ""; + row.Min = data != null ? data.Min : ""; + row.item1 = "1"; + row.item2 = "2"; + row.item3 = "3"; + row.item4 = "4"; + row.item5 = "5"; + row.item6 = "6"; + row.item7 = "7"; + row.item8 = "8"; + row.MaxIndex = 0; + row.MinIndex = 7; + row.CutLevel = data != null ? data.CutLevel : ""; + row.SymLevel = GetGradeName(data != null ? data.SymLevel??0 : 0); + return row; + } + #region 钻石操作相关 //暂略 //部分代码(直接操作控件)需要在xaml.cs里边写 @@ -1015,4 +1042,25 @@ public class DataInfo { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } -} \ No newline at end of file +} + +public class RowDetail +{ + public string? itemName { get; set; } + public string? Avg { get; set; } + public string? Dev { get; set; } + public string? Min { get; set; } + public string? Max { get; set; } + public string? item1 { get; set; } + public string? item2 { get; set; } + public string? item3 { get; set; } + public string? item4 { get; set; } + public string? item5 { get; set; } + public string? item6 { get; set; } + public string? item7 { get; set; } + public string? item8 { get; set; } + public string? CutLevel { get; set; } + public string? SymLevel { get; set; } + public int? MaxIndex { get; set; } + public int? MinIndex { get; set; } +} diff --git a/Views/Grading/GradingResult.xaml b/Views/Grading/GradingResult.xaml index 123c256..7059611 100644 --- a/Views/Grading/GradingResult.xaml +++ b/Views/Grading/GradingResult.xaml @@ -104,7 +104,8 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Views/Grading/GradingResult.xaml.cs b/Views/Grading/GradingResult.xaml.cs index 5c9f887..8009c22 100644 --- a/Views/Grading/GradingResult.xaml.cs +++ b/Views/Grading/GradingResult.xaml.cs @@ -1,14 +1,8 @@ -using System.Windows.Controls; +using System.Windows; +using System.Windows.Controls; using System.Windows.Input; -using System.Windows.Media.Media3D; -using HelixToolkit.Wpf.SharpDX; -using SharpDX; -using SparkClient.Model.Entity; -using SparkClient.Model.Helper; using SparkClient.ViewModel.Grading; using GeometryModel3D = HelixToolkit.Wpf.SharpDX.GeometryModel3D; -using MeshGeometry3D = HelixToolkit.Wpf.SharpDX.MeshGeometry3D; -using PerspectiveCamera = HelixToolkit.Wpf.SharpDX.PerspectiveCamera; namespace SparkClient.Views.Grading; @@ -125,4 +119,48 @@ public partial class GradingResult var d = DataContext as GradingResultVM; d.ChangeSym(null); } + + private void dataGrid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) + { + var dataGrid = sender as DataGrid; + var selectedItem = dataGrid.SelectedItem; + + if (selectedItem != null) + { + // 获取选中行的可视化元素 + var selectedRow = dataGrid.ItemContainerGenerator.ContainerFromItem(selectedItem) as DataGridRow; + if (selectedRow != null) + { + // 获取选中行第一列的坐标 + // 获取选中行第一列的单元格内容 + var firstCell = dataGrid.Columns[0].GetCellContent(selectedRow); + + // 将 firstCell 的边界转换为屏幕坐标系 + var firstCellBounds = firstCell.PointToScreen(new Point(0, 0)); + + // 计算Popup的位置 + var popupPosition = new Point(firstCellBounds.X + firstCell.RenderSize.Width, firstCellBounds.Y + firstCell.RenderSize.Height + 15); + var selectObject = selectedItem as DataInfo; + string testItemId = selectObject.TestItemId; + var d = DataContext as GradingResultVM; + RowDetail rowDetail = d.getSelectData(testItemId); + // 设置Popup的位置 + detailPopup.HorizontalOffset = popupPosition.X; + detailPopup.VerticalOffset = popupPosition.Y; + detailPopup.IsOpen = true; + RowDetail.Items.Clear(); + RowDetail.Items.Add(rowDetail); + } + } + } + + private void Window_MouseDown(object sender, MouseButtonEventArgs e) + { + detailPopup.IsOpen = false; + } + + private void Window_MouseDown(object sender, RoutedEventArgs e) + { + detailPopup.IsOpen = false; + } } \ No newline at end of file From ebfe68ca80b35f03dcbc46bc702375bbf2ac4d7d Mon Sep 17 00:00:00 2001 From: handefeng <1030428966@qq.com> Date: Thu, 19 Dec 2024 09:05:07 +0800 Subject: [PATCH 2/2] =?UTF-8?q?add=EF=BC=9Acheck?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Model/Services/AlgorithmServer.cs | 1 - Model/Services/SOCClientService.cs | 45 +++++++------- Resource/Document/log.txt | 18 ++++++ SparkClient.csproj | 9 +++ ViewModel/Grading/DiamondSelectVM.cs | 89 +++++++++++++++------------- Views/Dialog/MsgDialog.xaml | 45 ++++++++++++++ Views/Dialog/MsgDialog.xaml.cs | 62 +++++++++++++++++++ 7 files changed, 203 insertions(+), 66 deletions(-) create mode 100644 Views/Dialog/MsgDialog.xaml create mode 100644 Views/Dialog/MsgDialog.xaml.cs diff --git a/Model/Services/AlgorithmServer.cs b/Model/Services/AlgorithmServer.cs index 6291805..bf91b48 100644 --- a/Model/Services/AlgorithmServer.cs +++ b/Model/Services/AlgorithmServer.cs @@ -44,7 +44,6 @@ namespace SparkClient.Model.Services string resultJson = Marshal.PtrToStringAnsi(resultPtr); // 释放 DLL 分配的内存 FreeString(resultPtr); - Console.WriteLine("log999999999999999999"+resultJson); // 检查返回的 JSON 字符串是否为空或无效 if (string.IsNullOrEmpty(resultJson)) diff --git a/Model/Services/SOCClientService.cs b/Model/Services/SOCClientService.cs index 614fe58..ebcc0a1 100644 --- a/Model/Services/SOCClientService.cs +++ b/Model/Services/SOCClientService.cs @@ -19,18 +19,6 @@ namespace SparkClient.Model.Services // Log地址 private const string LogFilePath = @"..\..\..\Resource\Document\log.txt"; - private static readonly Dictionary StatusDescriptions = new Dictionary - { - { "S000", "成功" }, - { "S001", "采图正在进行中" }, - { "S002", "缓存图片被清理(读取不够及时)" }, - { "S003", "无法向单片机发送指令" }, - { "S004", "单片机访问超时" }, - { "S005", "单片机返回错误码" }, - { "P001", "未找到切工仪" }, - { "P002", "算法调用失败" } - }; - /// /// 基础URL,用于构建完整的API请求地址。 /// @@ -107,7 +95,13 @@ namespace SparkClient.Model.Services if (status == 200) { byte[] imageBytes = await response.Content.ReadAsByteArrayAsync(); - string fileName = Path.Combine(savePath, $"image_{imageIndex}.bmp"); + + // 获取 Content-Type 头以确定图片格式 + string contentType = response.Content.Headers.ContentType.MediaType; + string fileExtension = GetFileExtension(contentType); + + //string fileName = Path.Combine(savePath, $"image_{imageIndex}.bmp"); + string fileName = Path.Combine(savePath, $"image_{imageIndex}{fileExtension}"); // 图片名称List imageNames.Add(Path.GetFileName(fileName)); // 保存图片 @@ -203,21 +197,26 @@ namespace SparkClient.Model.Services } /// - /// 根据状态码获取相应的描述信息。 - /// 如果状态码在预定义的状态字典中存在,则返回对应的描述信息; - /// 否则返回“未知状态: [状态码]”。 + /// 根据给定的 MIME 类型获取对应的文件扩展名。 /// - /// 状态码。 - /// 状态描述信息。 - private string GetDescription(string status) + /// HTTP 响应中的 Content-Type 头字段,表示内容的 MIME 类型。 + /// 与 MIME 类型对应的文件扩展名。 + /// 当传入的 MIME 类型不受支持时抛出此异常。 + private string GetFileExtension(string contentType) { - if (StatusDescriptions.TryGetValue(status, out string description)) + switch (contentType.ToLower()) { - return description; + case "image/bmp": + return ".bmp"; + case "image/jpg": + return ".jpg"; + case "image/png": + return ".png"; + default: + throw new InvalidOperationException($"Unsupported content type: {contentType}"); } - return "未知状态: " + status; } - + } diff --git a/Resource/Document/log.txt b/Resource/Document/log.txt index 0de3e52..d0a6a0b 100644 --- a/Resource/Document/log.txt +++ b/Resource/Document/log.txt @@ -6,3 +6,21 @@ [2024-12-05 16:51:04.013] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000) [2024-12-05 16:58:31.184] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000) [2024-12-12 13:27:06.264] 发生异常: The process cannot access the file 'image_39.bmp' because it is being used by another process. +[2024-12-18 08:56:09.327] 发生异常: The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing. +[2024-12-18 15:58:22.476] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000) +[2024-12-18 16:12:57.999] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000) +[2024-12-18 16:13:12.680] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000) +[2024-12-18 16:13:20.632] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000) +[2024-12-18 16:13:29.227] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000) +[2024-12-18 16:13:44.433] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000) +[2024-12-18 16:13:59.933] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000) +[2024-12-18 16:14:09.063] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000) +[2024-12-18 17:03:24.758] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000) +[2024-12-18 17:03:50.352] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000) +[2024-12-18 17:06:16.074] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000) +[2024-12-18 17:06:53.906] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000) +[2024-12-18 17:11:04.161] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000) +[2024-12-18 17:13:26.174] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000) +[2024-12-18 17:25:38.182] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000) +[2024-12-19 08:50:34.643] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000) +[2024-12-19 08:54:45.576] 发生异常: 由于目标计算机积极拒绝,无法连接。 (localhost:5000) diff --git a/SparkClient.csproj b/SparkClient.csproj index 4ceff56..d8fe62e 100644 --- a/SparkClient.csproj +++ b/SparkClient.csproj @@ -135,10 +135,19 @@ Designer + + MSBuild:Compile + Wpf + Designer + + + Code + MsgDialog.xaml + diff --git a/ViewModel/Grading/DiamondSelectVM.cs b/ViewModel/Grading/DiamondSelectVM.cs index c718b58..b096eef 100644 --- a/ViewModel/Grading/DiamondSelectVM.cs +++ b/ViewModel/Grading/DiamondSelectVM.cs @@ -115,9 +115,9 @@ public class DiamondSelectVM : BaseViewModel /// public async void StartGrading(object param) { - #if DEBUG - DoStartGrading(param); - #else + // #if DEBUG + // DoStartGrading(param); + // #else LoadingDialog loading = new LoadingDialog(); try { @@ -155,11 +155,33 @@ public class DiamondSelectVM : BaseViewModel parameter.CrownType = value.Split(" ")[1]; parameter.PavType = value.Split(" ")[2]; } - + // 启动soc socResolt = await DoSoc(); + if (socResolt.Status == "P001") + { + // 使用 Dispatcher 将 UI 操作调度到主线程 + Application.Current.Dispatcher.Invoke(() => + { + MsgDialog msgDialog = new MsgDialog(); + msgDialog.ShowDialog(); + }); + loading.Dispatcher.Invoke(() => loading.Close()); + return; + } // 启动算法 parameter = await DoAlgorithm(socResolt, parameter.Shape, parameter.CrownType); + if (parameter.status == "P002" || parameter.status == "P003" || parameter.status == "P004") + { + // 使用 Dispatcher 将 UI 操作调度到主线程 + Application.Current.Dispatcher.Invoke(() => + { + MsgDialog msgDialog = new MsgDialog(); + msgDialog.ShowDialog(); + }); + loading.Dispatcher.Invoke(() => loading.Close()); + return; + } parameter.Standard = "IGI 2024"; parameter.Shape = value.Split(" ")[0]; @@ -194,8 +216,8 @@ public class DiamondSelectVM : BaseViewModel } finally { - } - #endif + } + // #endif } /// @@ -287,35 +309,28 @@ public class DiamondSelectVM : BaseViewModel /// /// 启动切工仪接口。 /// - /// 图片索引 - /// 图片索引 - /// 图片索引 /// 图片的字节数组 private async Task DoSoc() { - // // 光照度 - // string sql = new CutterConfigEntity - // { - // ItemName = null, - // Key = null, - // Value = null - // }.GenerateSelectSQL(new List { "Value" }, new Dictionary { { "Key", "light_level" } }); - // SqliteParameter[] sqliteParameters = [new("@Key", "light_level")]; - // DataTable table = DataBaseHelper.ExecuteQuery(sql,sqliteParameters); - // object lightLevelValue = table.Rows[0][0]; - // if (!int.TryParse(lightLevelValue.ToString(), out int lightLevel)) - // { - // throw new InvalidOperationException("Light level value is not a valid integer."); - // } - // // 初始化SOC客户端服务,传入SOC端的地址和认证Token - // _socClientService = new SOCClientService(); - // // SOC接口 - // string savePath = @"d:\\diamond_images"; - // SocResultEntity resultEntity = await _socClientService.ProcessImageCollectionAsync(lightLevel, savePath); - // // 转换成json - // string jsonResult = JsonConvert.SerializeObject(resultEntity, Formatting.Indented); - - SocResultEntity resultEntity = new SocResultEntity(); + // 光照度 + string sql = new CutterConfigEntity + { + ItemName = null, + Key = null, + Value = null + }.GenerateSelectSQL(new List { "Value" }, new Dictionary { { "Key", "light_level" } }); + SqliteParameter[] sqliteParameters = [new("@Key", "light_level")]; + DataTable table = DataBaseHelper.ExecuteQuery(sql,sqliteParameters); + object lightLevelValue = table.Rows[0][0]; + if (!int.TryParse(lightLevelValue.ToString(), out int lightLevel)) + { + throw new InvalidOperationException("Light level value is not a valid integer."); + } + // 初始化SOC客户端服务,传入SOC端的地址和认证Token + _socClientService = new SOCClientService(); + // SOC接口 + string savePath = @"d:\\diamond_images"; + SocResultEntity resultEntity = await _socClientService.ProcessImageCollectionAsync(lightLevel, savePath); return resultEntity; } @@ -346,19 +361,9 @@ public class DiamondSelectVM : BaseViewModel AlgorithmResultEntity algoResult = _algorithmServer.CallParseJsonAndReturnActions(shape, shape_mode, image_file_base_path, image_files, algo_config); - - // 将 algoResult 序列化为格式化的 JSON 字符串 - string algoJsonResult = JsonConvert.SerializeObject(algoResult, Formatting.Indented); - ShowMessage(algoJsonResult); return Task.FromResult(algoResult); } - - private void ShowMessage(string message) - { - MessageBox.Show(message); - } - } public class ButtonInfo { diff --git a/Views/Dialog/MsgDialog.xaml b/Views/Dialog/MsgDialog.xaml new file mode 100644 index 0000000..b49866a --- /dev/null +++ b/Views/Dialog/MsgDialog.xaml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + +