Merge remote-tracking branch 'origin/master'

# Conflicts:
#	SparkClient.csproj
master
Tongg 7 months ago
commit a010ceacfb
  1. 1
      Model/Services/AlgorithmServer.cs
  2. 45
      Model/Services/SOCClientService.cs
  3. 18
      Resource/Document/log.txt
  4. 17
      SparkClient.csproj
  5. 89
      ViewModel/Grading/DiamondSelectVM.cs
  6. 56
      ViewModel/Grading/GradingResultVM.cs
  7. 45
      Views/Dialog/MsgDialog.xaml
  8. 62
      Views/Dialog/MsgDialog.xaml.cs
  9. 201
      Views/Grading/GradingResult.xaml
  10. 54
      Views/Grading/GradingResult.xaml.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))

@ -19,18 +19,6 @@ namespace SparkClient.Model.Services
// Log地址
private const string LogFilePath = @"..\..\..\Resource\Document\log.txt";
private static readonly Dictionary<string, string> StatusDescriptions = new Dictionary<string, string>
{
{ "S000", "成功" },
{ "S001", "采图正在进行中" },
{ "S002", "缓存图片被清理(读取不够及时)" },
{ "S003", "无法向单片机发送指令" },
{ "S004", "单片机访问超时" },
{ "S005", "单片机返回错误码" },
{ "P001", "未找到切工仪" },
{ "P002", "算法调用失败" }
};
/// <summary>
/// 基础URL,用于构建完整的API请求地址。
/// </summary>
@ -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
}
/// <summary>
/// 根据状态码获取相应的描述信息。
/// 如果状态码在预定义的状态字典中存在,则返回对应的描述信息;
/// 否则返回“未知状态: [状态码]”。
/// 根据给定的 MIME 类型获取对应的文件扩展名。
/// </summary>
/// <param name="status">状态码。</param>
/// <returns>状态描述信息。</returns>
private string GetDescription(string status)
/// <param name="contentType">HTTP 响应中的 Content-Type 头字段,表示内容的 MIME 类型。</param>
/// <returns>与 MIME 类型对应的文件扩展名。</returns>
/// <exception cref="InvalidOperationException">当传入的 MIME 类型不受支持时抛出此异常。</exception>
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;
}
}

@ -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)

@ -140,10 +140,27 @@
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="Views\Configuration\SettingPages\CustomSettingPage.xaml">
<Page Update="Views\Dialog\MsgDialog.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Remove="Resource\Images\Temp\**" />
<Compile Update="Views\Dialog\MsgDialog.xaml.cs">
<SubType>Code</SubType>
<DependentUpon>MsgDialog.xaml</DependentUpon>
</Compile>
<Compile Update="Views\Dialog\MsgDialog.xaml.cs">
<SubType>Code</SubType>
<DependentUpon>MsgDialog.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>

@ -115,9 +115,9 @@ public class DiamondSelectVM : BaseViewModel
/// <param name="param"></param>
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
}
/// <summary>
@ -287,35 +309,28 @@ public class DiamondSelectVM : BaseViewModel
/// <summary>
/// 启动切工仪接口。
/// </summary>
/// <param name="index">图片索引</param>
/// <param name="index">图片索引</param>
/// <param name="index">图片索引</param>
/// <returns>图片的字节数组</returns>
private async Task<SocResultEntity> DoSoc()
{
// // 光照度
// string sql = new CutterConfigEntity
// {
// ItemName = null,
// Key = null,
// Value = null
// }.GenerateSelectSQL(new List<string> { "Value" }, new Dictionary<string, object> { { "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<string> { "Value" }, new Dictionary<string, object> { { "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
{

@ -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<int, string> 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));
}
}
}
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; }
}

@ -0,0 +1,45 @@
<Window x:Class="SparkClient.Views.Dialog.MsgDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None" AllowsTransparency="True"
Background="Transparent" ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
MouseLeftButtonDown="Window_MouseLeftButtonDown">
<!-- 窗口圆角和背景 -->
<Border CornerRadius="20" Background="White" Width="400" Height="250">
<Grid Margin="20">
<!-- 布局定义 -->
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- 右上角关闭按钮 -->
<Button Background="Transparent" BorderBrush="Transparent" Click="CloseButton_Click">
<Viewbox Stretch="Uniform"/>
</Button>
<!-- 标题 -->
<TextBlock Grid.Row="0" Text="XXXXXXXXXXXXXX"
FontSize="16" FontWeight="Bold" Foreground="Black"
HorizontalAlignment="Center" Margin="0,70" />
<!-- 按钮区域 -->
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,10,0,0">
<!-- 确定按钮 -->
<Button Content="{DynamicResource ok}" HorizontalAlignment="Center" Width="80" Height="35" Margin="10,0"
Background="#4DA3FF" Foreground="White" FontSize="14"
BorderBrush="Transparent" Click="Skip_Click" />
</StackPanel>
<Path Data="{StaticResource CloseGeometry}"
Fill="Azure"
Stroke="Black"
StrokeThickness="1"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="335,7,0,0"
Width="30" />
</Grid>
</Border>
</Window>

@ -0,0 +1,62 @@
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
namespace SparkClient.Views.Dialog
{
/// <summary>
/// MsgDialog.xaml 的交互逻辑
/// </summary>
public partial class MsgDialog : Window
{
public MsgDialog()
{
InitializeComponent();
this.Loaded += (s, e) => ApplyCornerRadiusClip();
this.SizeChanged += (s, e) => ApplyCornerRadiusClip();
}
/// <summary>
/// 关闭按钮点击事件
/// </summary>
private void CloseButton_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
/// <summary>
/// 跳过按钮点击事件
/// </summary>
private void Skip_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
/// <summary>
/// 窗口圆角裁剪
/// </summary>
private void ApplyCornerRadiusClip()
{
if (this.ActualWidth > 0 && this.ActualHeight > 0)
{
this.Clip = new RectangleGeometry
{
Rect = new Rect(0, 0, this.ActualWidth, this.ActualHeight),
RadiusX = 20,
RadiusY = 20
};
}
}
/// <summary>
/// 支持窗口拖动
/// </summary>
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
this.DragMove();
}
}
}
}

@ -104,7 +104,8 @@
</Border>
<Border Grid.Row="1" Grid.Column="0">
<DataGrid HeadersVisibility="Column" AutoGenerateColumns="False" ItemsSource="{Binding DtResults,Mode=TwoWay}" CanUserResizeColumns="False" CanUserResizeRows="False">
<DataGrid HeadersVisibility="Column" AutoGenerateColumns="False" ItemsSource="{Binding DtResults,Mode=TwoWay}" CanUserResizeColumns="False" CanUserResizeRows="False"
MouseLeftButtonUp="dataGrid_MouseLeftButtonUp">
<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="MinWidth" Value="120"/>
@ -155,9 +156,207 @@
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="TestItemId" Binding="{Binding TestItemId}" Visibility="Hidden"/>
</DataGrid.Columns>
</DataGrid>
</Border>
<Popup x:Name="detailPopup" IsOpen="False" Placement="Absolute" Width="1200">
<Grid Background="#ededed">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="117*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<DataGrid x:Name="RowDetail" CanUserResizeColumns="False" CanUserResizeRows="False">
<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="Background" Value="Transparent"/>
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.Resources>
<Style x:Key="CenteredTextBlockStyle" TargetType="TextBlock">
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="FontWeight" Value="Normal" />
</Style>
<Style x:Key="OtherCellkStyle" TargetType="DataGridCell">
<Setter Property="Background" Value="#bbbbbb"/>
<Setter Property="BorderBrush" Value="#ededed"/>
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn Width="2*" Header="" Binding="{Binding itemName}" ElementStyle="{StaticResource CenteredTextBlockStyle}">
<DataGridTextColumn.CellStyle >
<Style TargetType="DataGridCell">
<Setter Property="Background" Value="#ededed"/>
<Setter Property="BorderBrush" Value="#ededed"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<DataGridTextColumn Width="*" Header="{DynamicResource resAvg}" Binding="{Binding Avg}" ElementStyle="{StaticResource CenteredTextBlockStyle}" CellStyle="{StaticResource OtherCellkStyle}"/>
<DataGridTextColumn Width="*" Header="{DynamicResource resDev}" Binding="{Binding Dev}" ElementStyle="{StaticResource CenteredTextBlockStyle}" CellStyle="{StaticResource OtherCellkStyle}"/>
<DataGridTextColumn Width="*" Header="{DynamicResource resMin}" Binding="{Binding Min}" ElementStyle="{StaticResource CenteredTextBlockStyle}"/>
<DataGridTextColumn Width="*" Header="{DynamicResource resMax}" Binding="{Binding Max}" ElementStyle="{StaticResource CenteredTextBlockStyle}"/>
<DataGridTextColumn Width="*" Header="1" Binding="{Binding item1}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="FontWeight" Value="Normal" />
<Style.Triggers>
<DataTrigger Binding="{Binding MaxIndex}" Value="0">
<Setter Property="FontWeight" Value="Bold" />
</DataTrigger>
<DataTrigger Binding="{Binding MinIndex}" Value="0">
<Setter Property="FontWeight" Value="Bold" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Width="*" Header="2" Binding="{Binding item2}" >
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="FontWeight" Value="Normal" />
<Style.Triggers>
<DataTrigger Binding="{Binding MaxIndex}" Value="1">
<Setter Property="FontWeight" Value="Bold" />
</DataTrigger>
<DataTrigger Binding="{Binding MinIndex}" Value="1">
<Setter Property="FontWeight" Value="Bold" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Width="*" Header="3" Binding="{Binding item3}" >
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="FontWeight" Value="Normal" />
<Style.Triggers>
<DataTrigger Binding="{Binding MaxIndex}" Value="2">
<Setter Property="FontWeight" Value="Bold" />
</DataTrigger>
<DataTrigger Binding="{Binding MinIndex}" Value="2">
<Setter Property="FontWeight" Value="Bold" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Width="*" Header="4" Binding="{Binding item4}" >
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="FontWeight" Value="Normal" />
<Style.Triggers>
<DataTrigger Binding="{Binding MaxIndex}" Value="3">
<Setter Property="FontWeight" Value="Bold" />
</DataTrigger>
<DataTrigger Binding="{Binding MinIndex}" Value="3">
<Setter Property="FontWeight" Value="Bold" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Width="*" Header="5" Binding="{Binding item5}" >
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="FontWeight" Value="Normal" />
<Style.Triggers>
<DataTrigger Binding="{Binding MaxIndex}" Value="4">
<Setter Property="FontWeight" Value="Bold" />
</DataTrigger>
<DataTrigger Binding="{Binding MinIndex}" Value="4">
<Setter Property="FontWeight" Value="Bold" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Width="*" Header="6" Binding="{Binding item6}" >
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="FontWeight" Value="Normal" />
<Style.Triggers>
<DataTrigger Binding="{Binding MaxIndex}" Value="5">
<Setter Property="FontWeight" Value="Bold" />
</DataTrigger>
<DataTrigger Binding="{Binding MinIndex}" Value="5">
<Setter Property="FontWeight" Value="Bold" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Width="*" Header="7" Binding="{Binding item7}" >
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="FontWeight" Value="Normal" />
<Style.Triggers>
<DataTrigger Binding="{Binding MaxIndex}" Value="6">
<Setter Property="FontWeight" Value="Bold" />
</DataTrigger>
<DataTrigger Binding="{Binding MinIndex}" Value="6">
<Setter Property="FontWeight" Value="Bold" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Width="*" Header="8" Binding="{Binding item8}" >
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="FontWeight" Value="Normal" />
<Style.Triggers>
<DataTrigger Binding="{Binding MaxIndex}" Value="7">
<Setter Property="FontWeight" Value="Bold" />
</DataTrigger>
<DataTrigger Binding="{Binding MinIndex}" Value="7">
<Setter Property="FontWeight" Value="Bold" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Width="*" Header="{DynamicResource CutLevel}" Binding="{Binding CutLevel}" ElementStyle="{StaticResource CenteredTextBlockStyle}" CellStyle="{StaticResource OtherCellkStyle}"/>
<DataGridTextColumn Width="*" Header="{DynamicResource resLevel}" Binding="{Binding SymLevel}" ElementStyle="{StaticResource CenteredTextBlockStyle}" CellStyle="{StaticResource OtherCellkStyle}"/>
</DataGrid.Columns>
</DataGrid>
<Button Grid.Column="1" Click="Window_MouseDown" VerticalAlignment="Top" Background="Transparent">
<Path Data="{StaticResource CloseGeometry}"
Fill="Black"
Stroke="Black"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Margin="0 0 0 0"
Width="10" />
</Button>
</Grid>
</Popup>
<GridSplitter Grid.Row="1" Grid.Column="1" Width="3" HorizontalAlignment="Stretch"></GridSplitter>
<Border Grid.Row="1" Grid.Column="2" Background="White">
<Grid>

@ -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;
}
}
Loading…
Cancel
Save