本次提交主要内容如下: - 新增“排序功能”菜单,支持重排刀序、生成/应用排序种子、按参考钻带重排等多种排序方式,提升刀具顺序管理灵活性。 - 支持用户选择参考钻带文件或排序种子文件,自动重排当前刀具顺序,并提供详细的匹配校验、警告提示和重排前后对比确认。 - 新增生成通用排序种子文件(General_sort.txt)功能,便于批量产品排序。 - 优化界面布局,提升信息展示美观性和空间利用率。 - 增加异常处理和详细注释,提升健壮性和可维护性。 - 新增多个文档,详细说明“使用指定钻带的刀序”功能的实现、使用方法、演示流程及开发过程中的问题修复,便于开发和用户理解。 - 新增两个排序种子文件示例(General_sort.txt、s40024079g0-a2-cs-jp-sort.txt),用于刀具顺序自动重排。 - 其他无实际代码变更的文件未影响功能。 本次改动极大提升了钻带刀具顺序管理的自动化、灵活性和用户体验,适用于多样化的生产场景。
270 lines
9.5 KiB
C#
270 lines
9.5 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Text;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
|
|
namespace DrillTools
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for MainWindow.xaml
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
private MainWindowViewModel ViewModel => (MainWindowViewModel)DataContext;
|
|
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
var viewModel = new MainWindowViewModel();
|
|
DataContext = viewModel;
|
|
InitializeDragDrop();
|
|
|
|
// 设置默认置顶状态
|
|
this.Topmost = viewModel.IsTopmost;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化拖放功能
|
|
/// </summary>
|
|
private void InitializeDragDrop()
|
|
{
|
|
DragDropHelper.EnableDragDrop<ToolItem>(ToolsListView, InsertionIndicator);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 加载示例数据按钮点击事件
|
|
/// </summary>
|
|
private void LoadSampleDataButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
ViewModel.LoadSampleData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 加载钻带文件按钮点击事件
|
|
/// </summary>
|
|
private void LoadDrillTapeButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var openFileDialog = new Microsoft.Win32.OpenFileDialog
|
|
{
|
|
Filter = "钻带文件 (*.txt;*.drl;*.dr2;*.dpin)|*.txt;*.drl;*.dr2;*.dpin|所有文件 (*.*)|*.*",
|
|
Title = "选择钻带文件"
|
|
};
|
|
|
|
if (openFileDialog.ShowDialog() == true)
|
|
{
|
|
try
|
|
{
|
|
// 保存原始文件路径
|
|
ViewModel.OriginalFilePath = openFileDialog.FileName;
|
|
|
|
// 使用 cmd 命令读取加密钻带文件
|
|
var process = new Process
|
|
{
|
|
StartInfo = new ProcessStartInfo
|
|
{
|
|
FileName = "cmd.exe",
|
|
Arguments = $"/c type \"{openFileDialog.FileName}\"",
|
|
RedirectStandardOutput = true,
|
|
UseShellExecute = false,
|
|
CreateNoWindow = true
|
|
}
|
|
};
|
|
|
|
process.Start();
|
|
string drillTapeContent = process.StandardOutput.ReadToEnd();
|
|
process.WaitForExit();
|
|
|
|
ViewModel.LoadToolsFromDrillTape(drillTapeContent);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
System.Windows.MessageBox.Show($"加载钻带文件失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 重排刀序按钮点击事件
|
|
/// </summary>
|
|
private void ReorderToolsButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
string reorderedDrillTape = ViewModel.ReorderAndRenumberTools();
|
|
ViewModel.DrillTapeContent = reorderedDrillTape;
|
|
System.Windows.MessageBox.Show("刀序重排完成", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
catch (OperationCanceledException)
|
|
{
|
|
// 用户取消操作,不显示错误消息
|
|
System.Diagnostics.Debug.WriteLine("用户取消了刀序重排操作");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
System.Windows.MessageBox.Show($"重排刀序失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 应用顺序到钻带按钮点击事件
|
|
/// </summary>
|
|
private void ApplyOrderButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
string reorderedDrillTape = ViewModel.ReorderAndRenumberTools(true);
|
|
ViewModel.DrillTapeContent = reorderedDrillTape;
|
|
System.Windows.MessageBox.Show("刀具顺序已应用到钻带", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
catch (OperationCanceledException)
|
|
{
|
|
// 用户取消操作,不显示错误消息
|
|
System.Diagnostics.Debug.WriteLine("用户取消了保存操作");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
System.Windows.MessageBox.Show($"应用刀具顺序失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 生成排序种子按钮点击事件
|
|
/// </summary>
|
|
private void GenerateSortSeedButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
ViewModel.GenerateGeneralSortSeedFile(ViewModel.Tools);
|
|
System.Windows.MessageBox.Show("通用排序种子文件已生成", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
catch (OperationCanceledException)
|
|
{
|
|
// 用户取消操作,不显示错误消息
|
|
System.Diagnostics.Debug.WriteLine("用户取消了生成排序种子操作");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
System.Windows.MessageBox.Show($"生成排序种子失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 使用指定钻带的刀序按钮点击事件
|
|
/// </summary>
|
|
private void UseReferenceDrillTapeButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
ViewModel.ReorderToolsByReferenceDrillTape();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 使用指定种子的刀序按钮点击事件
|
|
/// </summary>
|
|
private void UseSortSeedButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
ViewModel.ReorderToolsBySortSeedFile();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 测试参考钻带功能按钮点击事件
|
|
/// </summary>
|
|
private void TestReferenceDrillTapeButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
ViewModel.TestReorderByReferenceDrillTape();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 上移按钮点击事件
|
|
/// </summary>
|
|
private void MoveUpButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
ViewModel.MoveSelectedToolUp();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 下移按钮点击事件
|
|
/// </summary>
|
|
private void MoveDownButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
ViewModel.MoveSelectedToolDown();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 置顶按钮点击事件
|
|
/// </summary>
|
|
private void ToggleTopmostButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
ViewModel.ToggleTopmost();
|
|
this.Topmost = ViewModel.IsTopmost;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 刀具列表双击事件
|
|
/// </summary>
|
|
private void ToolsListView_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
|
{
|
|
if (sender is System.Windows.Controls.ListView listView && listView.SelectedItem is ToolItem selectedTool)
|
|
{
|
|
ViewModel.ShowToolDetail(selectedTool);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 拖放文件进入窗口事件
|
|
/// </summary>
|
|
protected override void OnDragEnter(System.Windows.DragEventArgs e)
|
|
{
|
|
if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop))
|
|
{
|
|
e.Effects = System.Windows.DragDropEffects.Copy;
|
|
}
|
|
else
|
|
{
|
|
e.Effects = System.Windows.DragDropEffects.None;
|
|
}
|
|
base.OnDragEnter(e);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 拖放文件到窗口事件
|
|
/// </summary>
|
|
protected override void OnDrop(System.Windows.DragEventArgs e)
|
|
{
|
|
if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop))
|
|
{
|
|
string[] files = (string[])e.Data.GetData(System.Windows.DataFormats.FileDrop);
|
|
if (files.Length > 0)
|
|
{
|
|
try
|
|
{
|
|
// 保存原始文件路径
|
|
ViewModel.OriginalFilePath = files[0];
|
|
|
|
var process = new Process
|
|
{
|
|
StartInfo = new ProcessStartInfo
|
|
{
|
|
FileName = "cmd.exe",
|
|
Arguments = $"/c type \"{files[0]}\"",
|
|
RedirectStandardOutput = true,
|
|
UseShellExecute = false,
|
|
CreateNoWindow = true
|
|
}
|
|
};
|
|
|
|
process.Start();
|
|
string drillTapeContent = process.StandardOutput.ReadToEnd();
|
|
process.WaitForExit();
|
|
|
|
ViewModel.LoadToolsFromDrillTape(drillTapeContent);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
System.Windows.MessageBox.Show($"加载钻带文件失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
}
|
|
base.OnDrop(e);
|
|
}
|
|
}
|
|
} |