WpfApp/src/view/FilePage.xaml.cs
2025-10-10 15:58:01 +08:00

154 lines
5.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApp.src.view
{
/// <summary>
/// FilePage.xaml 的交互逻辑
/// </summary>
public partial class FilePage : Page
{
public FilePage()
{
InitializeComponent();
LoadSampleData();
}
private void LoadSampleData()
{
// 清空现有项目
RecordListBox.Items.Clear();
// 添加示例数据
var records = new List<string>
{
"1. GGG[2021-11-17 7:39:50]",
"2. MTU SG2000[2021-12-2 7:41:55]",
"3. JX493ZQ4[2022-1-8 11:22:42]",
"4. JX493ZQ5A[2022-2-15 1:26:38]",
"5. FOTON D01[2022-9-1 9:06:43]",
"6. PUMA2.0[2022-9-15 8:47:59]",
"7. PUMA2.2[2022-9-21 7:50:39]",
"8. SAIC D20[2022-10-10 8:27:46]",
"9. WEICHAI WP2H[2023-3-30 8:46:02]",
"10. JMC PUMA UPG 2.0[2023-7-10 17:07:07]",
"11. BFCEC ISF2.8L F2020 NS6[2023-7-10 17:21:50]",
"12. 12[2023-8-21 14:44:10]",
"13. GME T4[2023-10-2 8:55:38]",
"14. GW EN01[2023-10-4 8:12:50]",
"15. GAC P26 2.0PMI[2023-11-9 7:44:42]",
"16. NU PE2.0 TGDI[2024-5-2 11:07:36]",
"17. M254 E20[2024-7-2 10:08:06]",
"18. NU PE2.0MPI[2024-10-29 10:45:14]"
};
foreach (var record in records)
{
RecordListBox.Items.Add(record);
}
}
private void SearchButton_Click(object sender, RoutedEventArgs e)
{
string searchText = SearchTextBox.Text.Trim();
if (string.IsNullOrEmpty(searchText))
{
LoadSampleData(); // 重新加载所有数据
return;
}
// 过滤数据
RecordListBox.Items.Clear();
var allRecords = new List<string>
{
"1. GGG[2021-11-17 7:39:50]",
"2. MTU SG2000[2021-12-2 7:41:55]",
"3. JX493ZQ4[2022-1-8 11:22:42]",
"4. JX493ZQ5A[2022-2-15 1:26:38]",
"5. FOTON D01[2022-9-1 9:06:43]",
"6. PUMA2.0[2022-9-15 8:47:59]",
"7. PUMA2.2[2022-9-21 7:50:39]",
"8. SAIC D20[2022-10-10 8:27:46]",
"9. WEICHAI WP2H[2023-3-30 8:46:02]",
"10. JMC PUMA UPG 2.0[2023-7-10 17:07:07]",
"11. BFCEC ISF2.8L F2020 NS6[2023-7-10 17:21:50]",
"12. 12[2023-8-21 14:44:10]",
"13. GME T4[2023-10-2 8:55:38]",
"14. GW EN01[2023-10-4 8:12:50]",
"15. GAC P26 2.0PMI[2023-11-9 7:44:42]",
"16. NU PE2.0 TGDI[2024-5-2 11:07:36]",
"17. M254 E20[2024-7-2 10:08:06]",
"18. NU PE2.0MPI[2024-10-29 10:45:14]"
};
var filteredRecords = allRecords.Where(r => r.ToLower().Contains(searchText.ToLower())).ToList();
foreach (var record in filteredRecords)
{
RecordListBox.Items.Add(record);
}
}
private void DeleteButton_Click(object sender, RoutedEventArgs e)
{
if (RecordListBox.SelectedItem != null)
{
var result = MessageBox.Show("确定要删除选中的记录吗?", "确认删除",
MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
RecordListBox.Items.Remove(RecordListBox.SelectedItem);
}
}
else
{
MessageBox.Show("请先选择要删除的记录。", "提示",
MessageBoxButton.OK, MessageBoxImage.Information);
}
}
private void SelectButton_Click(object sender, RoutedEventArgs e)
{
if (RecordListBox.SelectedItem != null)
{
string selectedRecord = RecordListBox.SelectedItem.ToString();
MessageBox.Show($"已选择记录:{selectedRecord}", "选择确认",
MessageBoxButton.OK, MessageBoxImage.Information);
// 这里可以添加实际的选择逻辑,比如返回到主界面或执行其他操作
}
else
{
MessageBox.Show("请先选择一条记录。", "提示",
MessageBoxButton.OK, MessageBoxImage.Information);
}
}
private void CloseButton_Click(object sender, RoutedEventArgs e)
{
// 关闭当前页面或返回上一页
if (NavigationService.CanGoBack)
{
NavigationService.GoBack();
}
else
{
// 如果无法返回,可以关闭窗口或执行其他操作
Window.GetWindow(this)?.Close();
}
}
}
}