feat:定级配置画面

master
sunhonglei 7 months ago
parent e38900ed4f
commit e033ca1108
  1. 61
      ViewModel/Grading/GradingResultVM.cs
  2. 20
      Views/Grading/GradingResult.xaml
  3. 47
      Views/Grading/GradingResult.xaml.cs

@ -73,7 +73,7 @@ public class GradingResultVM : BaseViewModel
} }
InitCombobox(); InitCombobox();
DS = "NA"; DS = "NA";
//AutoSave(); AutoSave();
} }
#region 画面初始化相关操作 #region 画面初始化相关操作
@ -521,6 +521,12 @@ public class GradingResultVM : BaseViewModel
private string getFilePath() private string getFilePath()
{ {
string defultFilePath = "D://DTest//"; string defultFilePath = "D://DTest//";
string sql = $"SELECT SETTING_P FROM SETTING WHERE SETTING_ID = 'FilePath'";
DataTable data = DataBaseHelper.ExecuteQuery(sql);
if (data!= null && data.Rows.Count>0)
{
defultFilePath = data.Rows[0]["SETTING_P"].ToString();
}
if( File.Exists(defultFilePath)){ if( File.Exists(defultFilePath)){
return defultFilePath; return defultFilePath;
} }
@ -562,7 +568,8 @@ public class GradingResultVM : BaseViewModel
{ {
// 获取用户选择的文件路径 // 获取用户选择的文件路径
string filePath = saveFileDialog.FileName; string filePath = saveFileDialog.FileName;
ExportFile(filePath); //ExportFile(filePath);
TxtFile(filePath);
} }
} }
} }
@ -577,33 +584,40 @@ public class GradingResultVM : BaseViewModel
)); ));
await Task.Run(async () => await Task.Run(async () =>
{ {
int count = saveFileCount();
int index = 1;
if (FileSaveEnabled("Txt")) {
exportDialog.Dispatcher.Invoke(() => exportDialog.Dispatcher.Invoke(() =>
{ {
exportDialog.setValue("Txt File(1/4)"); exportDialog.setValue($"Txt File({index++}/{count})");
}); });
TxtFile(filePath); TxtFile(filePath);
}
if (FileSaveEnabled("Excel"))
{
exportDialog.Dispatcher.Invoke(() => exportDialog.Dispatcher.Invoke(() =>
{ {
exportDialog.setValue("Excel File(2/4)"); exportDialog.setValue($"Excel File({index++}/{count})");
}); });
ExcelFile(filePath); ExcelFile(filePath);
}
if (FileSaveEnabled("Stl"))
{
exportDialog.Dispatcher.Invoke(() => exportDialog.Dispatcher.Invoke(() =>
{ {
exportDialog.setValue("STL File(3/4)"); exportDialog.setValue($"STL File({index++}/{count})");
}); });
await Task.Delay(100); await Task.Delay(100);
STLFile(filePath); STLFile(filePath);
}
if (FileSaveEnabled("Dat"))
{
exportDialog.Dispatcher.Invoke(() => exportDialog.Dispatcher.Invoke(() =>
{ {
exportDialog.setValue("DAT File(4/4)"); exportDialog.setValue($"DAT File({index++}/{count})");
}); });
await DatFile(filePath); await DatFile(filePath);
}
exportDialog.Dispatcher.Invoke(() => exportDialog.Dispatcher.Invoke(() =>
{ {
exportDialog.setValue("Success"); exportDialog.setValue("Success");
@ -617,7 +631,28 @@ public class GradingResultVM : BaseViewModel
await Task.Delay(500); await Task.Delay(500);
exportDialog.Close(); exportDialog.Close();
} }
private bool FileSaveEnabled(string Key)
{
bool result = false;
string sql = $"SELECT SETTING_P FROM SETTING WHERE SETTING_ID = '{Key}FileChecked'";
DataTable data = DataBaseHelper.ExecuteQuery(sql);
if (data != null && data.Rows.Count>0)
{
bool.TryParse(data.Rows[0]["SETTING_P"].ToString(),out result);
}
return result;
}
private int saveFileCount()
{
int result = 0;
string sql = $"SELECT SETTING_P FROM SETTING WHERE SETTING_ID LIKE '%FileChecked'";
DataTable data = DataBaseHelper.ExecuteQuery(sql);
if (data != null)
{
result = data.Rows.Count;
}
return result;
}
private void TxtFile(string filePath) private void TxtFile(string filePath)
{ {
string fileName = filePath + ".txt"; string fileName = filePath + ".txt";

@ -105,7 +105,7 @@
<Border Grid.Row="1" Grid.Column="0"> <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"> CanUserSortColumns ="False">
<DataGrid.ColumnHeaderStyle> <DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader"> <Style TargetType="DataGridColumnHeader">
<Setter Property="MinWidth" Value="120"/> <Setter Property="MinWidth" Value="120"/>
@ -134,15 +134,15 @@
</Style> </Style>
</DataGrid.Resources> </DataGrid.Resources>
<DataGrid.Columns> <DataGrid.Columns>
<DataGridTextColumn Width="*" IsReadOnly="True" Header="" Binding="{Binding TestItemName}" ElementStyle="{StaticResource CenteredTextBlockStyle}"> <DataGridTemplateColumn Width="*" IsReadOnly="True" Header="">
<DataGridTextColumn.CellStyle> <DataGridTemplateColumn.CellTemplate>
<Style TargetType="DataGridCell"> <DataTemplate>
<Setter Property="Background" Value="#ededed"/> <Border MouseLeftButtonDown="dataGrid_MouseLeftButtonUp" Background="AliceBlue">
<Setter Property="BorderThickness" Value="1,1,1,1"/> <TextBlock Text="{Binding TestItemName}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Setter Property="BorderBrush" Value="#BBBBBB"/> </Border>
</Style> </DataTemplate>
</DataGridTextColumn.CellStyle> </DataGridTemplateColumn.CellTemplate>
</DataGridTextColumn> </DataGridTemplateColumn>
<DataGridTextColumn Width="*" IsReadOnly="True" Header="{DynamicResource resAvg}" Binding="{Binding Avg}" ElementStyle="{StaticResource CenteredTextBlockStyle}"/> <DataGridTextColumn Width="*" IsReadOnly="True" Header="{DynamicResource resAvg}" Binding="{Binding Avg}" ElementStyle="{StaticResource CenteredTextBlockStyle}"/>
<DataGridTextColumn Width="*" IsReadOnly="True" Header="{DynamicResource resDev}" Binding="{Binding Dev}" ElementStyle="{StaticResource CenteredTextBlockStyle}"/> <DataGridTextColumn Width="*" IsReadOnly="True" Header="{DynamicResource resDev}" Binding="{Binding Dev}" ElementStyle="{StaticResource CenteredTextBlockStyle}"/>
<DataGridTextColumn Width="*" IsReadOnly="True" Header="{DynamicResource resMin}" Binding="{Binding Min}" ElementStyle="{StaticResource CenteredTextBlockStyle}"/> <DataGridTextColumn Width="*" IsReadOnly="True" Header="{DynamicResource resMin}" Binding="{Binding Min}" ElementStyle="{StaticResource CenteredTextBlockStyle}"/>

@ -1,6 +1,7 @@
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media;
using SparkClient.ViewModel.Grading; using SparkClient.ViewModel.Grading;
using GeometryModel3D = HelixToolkit.Wpf.SharpDX.GeometryModel3D; using GeometryModel3D = HelixToolkit.Wpf.SharpDX.GeometryModel3D;
@ -124,33 +125,22 @@ public partial class GradingResult
{ {
detailPopup.IsOpen = false; detailPopup.IsOpen = false;
// 获取点击的目标元素 // 获取点击的目标元素
var element = e.OriginalSource as FrameworkElement; var element = sender as FrameworkElement;
// 检查目标元素是否是 ComboBox var cell = FindVisualParent<DataGridCell>(element);
if (element is Border) if (cell == null) return;
{
e.Handled = true;
return;
}
var dataGrid = sender as DataGrid;
var selectedItem = dataGrid.SelectedItem;
if (selectedItem != null) var row = FindVisualParent<DataGridRow>(cell);
{ if (row == null) return;
// 获取选中行的可视化元素
var selectedRow = dataGrid.ItemContainerGenerator.ContainerFromItem(selectedItem) as DataGridRow;
if (selectedRow != null)
{
// 获取选中行第一列的坐标
// 获取选中行第一列的单元格内容
var firstCell = dataGrid.Columns[0].GetCellContent(selectedRow);
if (element != null)
{
// 将 firstCell 的边界转换为屏幕坐标系 // 将 firstCell 的边界转换为屏幕坐标系
var firstCellBounds = firstCell.PointToScreen(new Point(0, 0)); var firstCellBounds = cell.PointToScreen(new Point(0, 0));
// 计算Popup的位置 // 计算Popup的位置
var popupPosition = new Point(firstCellBounds.X + firstCell.RenderSize.Width, firstCellBounds.Y + firstCell.RenderSize.Height + 15); var popupPosition = new Point(firstCellBounds.X + cell.RenderSize.Width, firstCellBounds.Y + cell.RenderSize.Height);
var selectObject = selectedItem as DataInfo; var selectObject = row.Item as DataInfo;
string testItemId = selectObject.TestItemId; string testItemId = selectObject.TestItemId;
var d = DataContext as GradingResultVM; var d = DataContext as GradingResultVM;
RowDetail rowDetail = d.getSelectData(testItemId); RowDetail rowDetail = d.getSelectData(testItemId);
@ -162,8 +152,21 @@ public partial class GradingResult
RowDetail.Items.Add(rowDetail); RowDetail.Items.Add(rowDetail);
} }
} }
} // 辅助方法:查找父元素
private T FindVisualParent<T>(DependencyObject child) where T : DependencyObject
{
var parentObject = VisualTreeHelper.GetParent(child);
if (parentObject == null) return null;
if (parentObject is T parent)
{
return parent;
}
else
{
return FindVisualParent<T>(parentObject);
}
}
private void Window_MouseDown(object sender, MouseButtonEventArgs e) private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{ {
detailPopup.IsOpen = false; detailPopup.IsOpen = false;

Loading…
Cancel
Save