feat:定级配置画面

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

@ -73,7 +73,7 @@ public class GradingResultVM : BaseViewModel
}
InitCombobox();
DS = "NA";
//AutoSave();
AutoSave();
}
#region 画面初始化相关操作
@ -521,6 +521,12 @@ public class GradingResultVM : BaseViewModel
private string getFilePath()
{
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)){
return defultFilePath;
}
@ -562,7 +568,8 @@ public class GradingResultVM : BaseViewModel
{
// 获取用户选择的文件路径
string filePath = saveFileDialog.FileName;
ExportFile(filePath);
//ExportFile(filePath);
TxtFile(filePath);
}
}
}
@ -577,33 +584,40 @@ public class GradingResultVM : BaseViewModel
));
await Task.Run(async () =>
{
exportDialog.Dispatcher.Invoke(() =>
{
exportDialog.setValue("Txt File(1/4)");
});
TxtFile(filePath);
exportDialog.Dispatcher.Invoke(() =>
int count = saveFileCount();
int index = 1;
if (FileSaveEnabled("Txt")) {
exportDialog.Dispatcher.Invoke(() =>
{
exportDialog.setValue($"Txt File({index++}/{count})");
});
TxtFile(filePath);
}
if (FileSaveEnabled("Excel"))
{
exportDialog.setValue("Excel File(2/4)");
});
ExcelFile(filePath);
exportDialog.Dispatcher.Invoke(() =>
exportDialog.Dispatcher.Invoke(() =>
{
exportDialog.setValue($"Excel File({index++}/{count})");
});
ExcelFile(filePath);
}
if (FileSaveEnabled("Stl"))
{
exportDialog.setValue("STL File(3/4)");
});
await Task.Delay(100);
STLFile(filePath);
exportDialog.Dispatcher.Invoke(() =>
exportDialog.Dispatcher.Invoke(() =>
{
exportDialog.setValue($"STL File({index++}/{count})");
});
await Task.Delay(100);
STLFile(filePath);
}
if (FileSaveEnabled("Dat"))
{
exportDialog.setValue("DAT File(4/4)");
});
await DatFile(filePath);
exportDialog.Dispatcher.Invoke(() =>
{
exportDialog.setValue($"DAT File({index++}/{count})");
});
await DatFile(filePath);
}
exportDialog.Dispatcher.Invoke(() =>
{
exportDialog.setValue("Success");
@ -617,7 +631,28 @@ public class GradingResultVM : BaseViewModel
await Task.Delay(500);
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)
{
string fileName = filePath + ".txt";

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

@ -1,6 +1,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using SparkClient.ViewModel.Grading;
using GeometryModel3D = HelixToolkit.Wpf.SharpDX.GeometryModel3D;
@ -124,46 +125,48 @@ public partial class GradingResult
{
detailPopup.IsOpen = false;
// 获取点击的目标元素
var element = e.OriginalSource as FrameworkElement;
var element = sender as FrameworkElement;
// 检查目标元素是否是 ComboBox
if (element is Border)
{
e.Handled = true;
return;
}
var dataGrid = sender as DataGrid;
var selectedItem = dataGrid.SelectedItem;
var cell = FindVisualParent<DataGridCell>(element);
if (cell == null) return;
if (selectedItem != null)
{
// 获取选中行的可视化元素
var selectedRow = dataGrid.ItemContainerGenerator.ContainerFromItem(selectedItem) as DataGridRow;
if (selectedRow != null)
{
// 获取选中行第一列的坐标
// 获取选中行第一列的单元格内容
var firstCell = dataGrid.Columns[0].GetCellContent(selectedRow);
var row = FindVisualParent<DataGridRow>(cell);
if (row == null) return;
// 将 firstCell 的边界转换为屏幕坐标系
var firstCellBounds = firstCell.PointToScreen(new Point(0, 0));
if (element != null)
{
// 将 firstCell 的边界转换为屏幕坐标系
var firstCellBounds = cell.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);
}
// 计算Popup的位置
var popupPosition = new Point(firstCellBounds.X + cell.RenderSize.Width, firstCellBounds.Y + cell.RenderSize.Height);
var selectObject = row.Item 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 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)
{
detailPopup.IsOpen = false;

Loading…
Cancel
Save