|
@@ -2,6 +2,7 @@
|
|
|
using System.Reflection;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
+using System.Windows.Documents;
|
|
|
using System.Windows.Media.Imaging;
|
|
|
using Microsoft.Win32;
|
|
|
|
|
@@ -17,8 +18,22 @@ namespace ArchivesCenter3
|
|
|
InitializeComponent();
|
|
|
updateinfo();
|
|
|
LoadFileContent();
|
|
|
+ levelitemupdate();
|
|
|
+ tagitemupdate();
|
|
|
+ Birthplaceitemupdate();
|
|
|
+ RelativeStatusitemupdate();
|
|
|
+ Load4Config();
|
|
|
+ MyCalendar.DisplayDate = DateTime.Today;
|
|
|
+ MyCalendar.SelectedDate = DateTime.Today;
|
|
|
Version version = Assembly.GetExecutingAssembly().GetName().Version;
|
|
|
- versionTextBlock.Text = $"版本号:{version.Major}.{version.Minor}.{version.Build}";
|
|
|
+ versionTextBlock.Text = $"版本号:{version.Major}.{version.Minor}.{version.Build}";
|
|
|
+ DateTime tomorrow = DateTime.Today.AddDays(1);
|
|
|
+
|
|
|
+ // 创建一个从明天开始到最大日期的不可选日期范围
|
|
|
+ CalendarDateRange blackoutRange = new CalendarDateRange(tomorrow, DateTime.MaxValue);
|
|
|
+
|
|
|
+ // 将该范围添加到 Calendar 的 BlackoutDates 集合中
|
|
|
+ MyCalendar.BlackoutDates.Add(blackoutRange);
|
|
|
}
|
|
|
|
|
|
private List<string> lines; // 存储文件内容的列表
|
|
@@ -27,7 +42,7 @@ namespace ArchivesCenter3
|
|
|
|
|
|
private void updateinfo()
|
|
|
{
|
|
|
- welcomeText.Text = "欢迎!" + Settings1.Default.Username + " ";
|
|
|
+ welcomeText.Text = "欢迎!" + Settings1.Default.Username;
|
|
|
WelcomeTitle.Text = Settings1.Default.WelcomeTitle;
|
|
|
DatabaseName.Text = Settings1.Default.DatabaseName;
|
|
|
DatabaseSubtitle.Text = Settings1.Default.DatabaseSubtitle;
|
|
@@ -61,6 +76,17 @@ namespace ArchivesCenter3
|
|
|
Settings1.Default.Password = PasswordBox.Text;
|
|
|
Settings1.Default.Save();
|
|
|
updateinfo();
|
|
|
+ string baseDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
|
|
+ string levelConfigPath = Path.Combine(baseDir, "ArchivesCenter", "config", "level.config");
|
|
|
+ string tagConfigPath = Path.Combine(baseDir, "ArchivesCenter", "config", "tag.config");
|
|
|
+ string relativeStatusConfigPath = Path.Combine(baseDir, "ArchivesCenter", "config", "relativeStatus.config");
|
|
|
+ string birthplaceConfigPath = Path.Combine(baseDir, "ArchivesCenter", "config", "birthplace.config");
|
|
|
+
|
|
|
+ // 保存配置文件内容
|
|
|
+ File.WriteAllText(levelConfigPath, LevelConfigBox.Text);
|
|
|
+ File.WriteAllText(tagConfigPath, TagConfigBox.Text);
|
|
|
+ File.WriteAllText(relativeStatusConfigPath, RSConfigBox.Text);
|
|
|
+ File.WriteAllText(birthplaceConfigPath, BPConfigBox.Text);
|
|
|
}
|
|
|
|
|
|
private void TextChanged(object sender, TextChangedEventArgs e)
|
|
@@ -69,6 +95,10 @@ namespace ArchivesCenter3
|
|
|
string.IsNullOrWhiteSpace(DatabaseSubtitleBox.Text) &&
|
|
|
string.IsNullOrWhiteSpace(WelcomeTitleBox.Text) &&
|
|
|
string.IsNullOrWhiteSpace(UsernameBox.Text) &&
|
|
|
+ string.IsNullOrWhiteSpace(LevelConfigBox.Text) &&
|
|
|
+ string.IsNullOrWhiteSpace(TagConfigBox.Text) &&
|
|
|
+ string.IsNullOrWhiteSpace(RSConfigBox.Text) &&
|
|
|
+ string.IsNullOrWhiteSpace(BPConfigBox.Text) &&
|
|
|
string.IsNullOrWhiteSpace(PasswordBox.Text);
|
|
|
settingSaveButton0.IsEnabled = !allTextBoxesEmpty;
|
|
|
settingSaveButton1.IsEnabled = !allTextBoxesEmpty;
|
|
@@ -80,7 +110,7 @@ namespace ArchivesCenter3
|
|
|
// 获取用户文档文件夹路径
|
|
|
string userDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
|
|
// 构建目标文件路径
|
|
|
- string filePath = Path.Combine(userDocumentsPath, "ArchivesCenter", "data", "people", "content.txt");
|
|
|
+ string filePath = Path.Combine(userDocumentsPath, "ArchivesCenter", "data", "people", "content.info");
|
|
|
|
|
|
// 检查文件是否存在
|
|
|
if (File.Exists(filePath))
|
|
@@ -304,7 +334,7 @@ namespace ArchivesCenter3
|
|
|
// 获取用户文档文件夹路径
|
|
|
string userDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
|
|
// 构建目标文件路径
|
|
|
- string filePath = Path.Combine(userDocumentsPath, "ArchivesCenter", "data", "people", "content.txt");
|
|
|
+ string filePath = Path.Combine(userDocumentsPath, "ArchivesCenter", "data", "people", "content.info");
|
|
|
|
|
|
// 确保目标文件夹存在
|
|
|
string directoryPath = Path.GetDirectoryName(filePath);
|
|
@@ -385,7 +415,7 @@ namespace ArchivesCenter3
|
|
|
bitmap.EndInit();
|
|
|
imgPhoto.Source = bitmap;
|
|
|
|
|
|
- // 如果当前行存在,更新文件路径到 content.txt 文件
|
|
|
+ // 如果当前行存在,更新文件路径到 content.info 文件
|
|
|
if (currentIndex >= 0 && currentIndex < lines.Count)
|
|
|
{
|
|
|
string[] parts = lines[currentIndex].Split(new string[] { "**" }, StringSplitOptions.None);
|
|
@@ -408,7 +438,7 @@ namespace ArchivesCenter3
|
|
|
// 获取用户文档文件夹路径
|
|
|
string userDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
|
|
// 构建目标文件路径
|
|
|
- string filePath = Path.Combine(userDocumentsPath, "ArchivesCenter", "data", "people", "content.txt");
|
|
|
+ string filePath = Path.Combine(userDocumentsPath, "ArchivesCenter", "data", "people", "content.info");
|
|
|
|
|
|
// 确保目标文件夹存在
|
|
|
string directoryPath = Path.GetDirectoryName(filePath);
|
|
@@ -430,6 +460,17 @@ namespace ArchivesCenter3
|
|
|
|
|
|
if (result == MessageBoxResult.Yes)
|
|
|
{
|
|
|
+ string[] parts = lines[currentIndex].Split(new string[] { "**" }, StringSplitOptions.None);
|
|
|
+
|
|
|
+ // 检查是否有图片路径,并删除图片文件
|
|
|
+ if (parts.Length > 26 && !string.IsNullOrEmpty(parts[26]))
|
|
|
+ {
|
|
|
+ string photoPath = parts[26];
|
|
|
+ if (File.Exists(photoPath))
|
|
|
+ {
|
|
|
+ File.Delete(photoPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
// 如果当前处于编辑状态,删除当前行
|
|
|
lines.RemoveAt(currentIndex);
|
|
|
// 保存文件内容
|
|
@@ -459,14 +500,14 @@ namespace ArchivesCenter3
|
|
|
string searchContent = pSearchBox.Text.Trim(); // 获取搜索框中的内容
|
|
|
if (string.IsNullOrEmpty(searchContent))
|
|
|
{
|
|
|
- MessageBox.Show("请输入搜索内容!");
|
|
|
+ MessageBox.Show("请输入搜索内容!", "Archives Center", MessageBoxButton.OK, MessageBoxImage.Exclamation);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// 获取用户文档文件夹路径
|
|
|
string userDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
|
|
// 构建目标文件路径
|
|
|
- string filePath = Path.Combine(userDocumentsPath, "ArchivesCenter", "data", "people", "content.txt");
|
|
|
+ string filePath = Path.Combine(userDocumentsPath, "ArchivesCenter", "data", "people", "content.info");
|
|
|
|
|
|
if (File.Exists(filePath))
|
|
|
{
|
|
@@ -519,7 +560,260 @@ namespace ArchivesCenter3
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- MessageBox.Show("未找到数据文件!");
|
|
|
+ MessageBox.Show("未找到数据文件!", "Archives Center", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void LoadLevels_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ levelitemupdate();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void levelitemupdate()
|
|
|
+ {
|
|
|
+ string userDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
|
|
+ string filePath = Path.Combine(userDocumentsPath, "ArchivesCenter", "config", "level.config");
|
|
|
+ string directoryPath = Path.GetDirectoryName(filePath);
|
|
|
+ if (!Directory.Exists(directoryPath))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(directoryPath);
|
|
|
+ }
|
|
|
+ if (!File.Exists(filePath))
|
|
|
+ File.Create(filePath).Close();
|
|
|
+ string[] lines = File.ReadAllLines(filePath);
|
|
|
+ cmbLevel.Items.Clear();
|
|
|
+ foreach (string line in lines)
|
|
|
+ {
|
|
|
+ cmbLevel.Items.Add(line);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void LoadTags_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ tagitemupdate();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void tagitemupdate()
|
|
|
+ {
|
|
|
+ string userDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
|
|
+ string filePath = Path.Combine(userDocumentsPath, "ArchivesCenter", "config", "tag.config");
|
|
|
+ string directoryPath = Path.GetDirectoryName(filePath);
|
|
|
+ if (!Directory.Exists(directoryPath))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(directoryPath);
|
|
|
+ }
|
|
|
+ if (!File.Exists(filePath))
|
|
|
+ File.Create(filePath).Close();
|
|
|
+ string[] lines = File.ReadAllLines(filePath);
|
|
|
+ cmbTag.Items.Clear();
|
|
|
+ foreach (string line in lines)
|
|
|
+ {
|
|
|
+ cmbTag.Items.Add(line);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void LoadBirthplaces_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ Birthplaceitemupdate();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Birthplaceitemupdate()
|
|
|
+ {
|
|
|
+ string userDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
|
|
+ string filePath = Path.Combine(userDocumentsPath, "ArchivesCenter", "config", "birthplace.config");
|
|
|
+ string directoryPath = Path.GetDirectoryName(filePath);
|
|
|
+ if (!Directory.Exists(directoryPath))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(directoryPath);
|
|
|
+ }
|
|
|
+ if (!File.Exists(filePath))
|
|
|
+ File.Create(filePath).Close();
|
|
|
+ string[] lines = File.ReadAllLines(filePath);
|
|
|
+ cmbBirthplace.Items.Clear();
|
|
|
+ foreach (string line in lines)
|
|
|
+ {
|
|
|
+ cmbBirthplace.Items.Add(line);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void LoadRelativeStatuss_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ RelativeStatusitemupdate();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void RelativeStatusitemupdate()
|
|
|
+ {
|
|
|
+ string userDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
|
|
+ string filePath = Path.Combine(userDocumentsPath, "ArchivesCenter", "config", "relativeStatus.config");
|
|
|
+ string directoryPath = Path.GetDirectoryName(filePath);
|
|
|
+ if (!Directory.Exists(directoryPath))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(directoryPath);
|
|
|
+ }
|
|
|
+ if (!File.Exists(filePath))
|
|
|
+ File.Create(filePath).Close();
|
|
|
+ string[] lines = File.ReadAllLines(filePath);
|
|
|
+ cmbRelativeStatus.Items.Clear();
|
|
|
+ foreach (string line in lines)
|
|
|
+ {
|
|
|
+ cmbRelativeStatus.Items.Add(line);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Load4Config()
|
|
|
+ {
|
|
|
+ // 定义配置文件路径
|
|
|
+ string baseDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
|
|
+ string levelConfigPath = Path.Combine(baseDir, "ArchivesCenter", "config", "level.config");
|
|
|
+ string tagConfigPath = Path.Combine(baseDir, "ArchivesCenter", "config", "tag.config");
|
|
|
+ string relativeStatusConfigPath = Path.Combine(baseDir, "ArchivesCenter", "config", "relativeStatus.config");
|
|
|
+ string birthplaceConfigPath = Path.Combine(baseDir, "ArchivesCenter", "config", "birthplace.config");
|
|
|
+
|
|
|
+ // 读取配置文件内容
|
|
|
+ LevelConfigBox.Text = File.Exists(levelConfigPath) ? File.ReadAllText(levelConfigPath) : string.Empty;
|
|
|
+ TagConfigBox.Text = File.Exists(tagConfigPath) ? File.ReadAllText(tagConfigPath) : string.Empty;
|
|
|
+ RSConfigBox.Text = File.Exists(relativeStatusConfigPath) ? File.ReadAllText(relativeStatusConfigPath) : string.Empty;
|
|
|
+ BPConfigBox.Text = File.Exists(birthplaceConfigPath) ? File.ReadAllText(birthplaceConfigPath) : string.Empty;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void MyCalendar_DisplayDateChanged(object sender, SelectionChangedEventArgs e)
|
|
|
+ {
|
|
|
+ // 获取用户文档库路径
|
|
|
+ string userDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
|
|
+ string archivesPath = Path.Combine(userDocumentsPath, "ArchivesCenter", "data", "log");
|
|
|
+
|
|
|
+ // 获取选中的日期
|
|
|
+ DateTime selectedDate = MyCalendar.SelectedDate.Value;
|
|
|
+
|
|
|
+ // 格式化日期为文件夹名称(例如:2025-02-13)
|
|
|
+ string dateFolderName = selectedDate.ToString("yyyy-MM-dd");
|
|
|
+ string dateFolderPath = Path.Combine(archivesPath, dateFolderName);
|
|
|
+
|
|
|
+ // 检查日期文件夹是否存在
|
|
|
+ if (Directory.Exists(dateFolderPath))
|
|
|
+ {
|
|
|
+ // 如果存在,读取content.txt文件
|
|
|
+ string contentFilePath = Path.Combine(dateFolderPath, "content.txt");
|
|
|
+ if (File.Exists(contentFilePath))
|
|
|
+ {
|
|
|
+ // 读取文件内容到RichTextBox
|
|
|
+ string content = File.ReadAllText(contentFilePath);
|
|
|
+ MyRichTextBox.Document.Blocks.Clear();
|
|
|
+ MyRichTextBox.Document.Blocks.Add(new Paragraph(new Run(content)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // 如果不存在,创建文件夹和content.txt文件
|
|
|
+ Directory.CreateDirectory(dateFolderPath);
|
|
|
+ string contentFilePath = Path.Combine(dateFolderPath, "content.txt");
|
|
|
+ File.WriteAllText(contentFilePath, ""); // 创建空文件
|
|
|
+ MyRichTextBox.Document.Blocks.Clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void LogSaveButton_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ // 获取用户文档库路径
|
|
|
+ string userDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
|
|
+ string archivesPath = Path.Combine(userDocumentsPath, "ArchivesCenter", "data", "log");
|
|
|
+
|
|
|
+ // 获取选中的日期
|
|
|
+ DateTime selectedDate = MyCalendar.SelectedDate.Value;
|
|
|
+
|
|
|
+ // 格式化日期为文件夹名称(例如:2025-02-13)
|
|
|
+ string dateFolderName = selectedDate.ToString("yyyy-MM-dd");
|
|
|
+ string dateFolderPath = Path.Combine(archivesPath, dateFolderName);
|
|
|
+
|
|
|
+ // 获取content.txt文件路径
|
|
|
+ string contentFilePath = Path.Combine(dateFolderPath, "content.txt");
|
|
|
+
|
|
|
+ // 获取RichTextBox中的内容
|
|
|
+ TextRange textRange = new TextRange(MyRichTextBox.Document.ContentStart, MyRichTextBox.Document.ContentEnd);
|
|
|
+ string content = textRange.Text;
|
|
|
+
|
|
|
+ // 将内容写入文件
|
|
|
+ File.WriteAllText(contentFilePath, content);
|
|
|
+
|
|
|
+ MessageBox.Show("保存成功!", "Archives Center", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void LogDeleteButton_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ // 获取用户文档库路径
|
|
|
+ string userDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
|
|
+ string archivesPath = Path.Combine(userDocumentsPath, "ArchivesCenter", "data", "log");
|
|
|
+
|
|
|
+ // 获取选中的日期
|
|
|
+ DateTime selectedDate = MyCalendar.SelectedDate.Value;
|
|
|
+
|
|
|
+ // 格式化日期为文件夹名称(例如:2025-02-13)
|
|
|
+ string dateFolderName = selectedDate.ToString("yyyy-MM-dd");
|
|
|
+ string dateFolderPath = Path.Combine(archivesPath, dateFolderName);
|
|
|
+
|
|
|
+ // 检查文件夹是否存在
|
|
|
+ if (Directory.Exists(dateFolderPath))
|
|
|
+ {
|
|
|
+ // 删除文件夹及其内容
|
|
|
+ Directory.Delete(dateFolderPath, true);
|
|
|
+
|
|
|
+ MessageBox.Show("文件夹已删除!", "Archives Center", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MessageBox.Show("该日期文件夹不存在!", "Archives Center", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SearchButton_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ // 获取用户文档库路径
|
|
|
+ string userDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
|
|
+ string archivesPath = Path.Combine(userDocumentsPath, "ArchivesCenter", "Data", "Log");
|
|
|
+
|
|
|
+ // 获取搜索内容
|
|
|
+ string searchText = SearchTextBox.Text.Trim();
|
|
|
+
|
|
|
+ // 清空 DataGrid
|
|
|
+ ResultDataGrid.ItemsSource = null;
|
|
|
+ ResultDataGrid.Items.Clear();
|
|
|
+
|
|
|
+ // 如果搜索内容为空,直接返回
|
|
|
+ if (string.IsNullOrEmpty(searchText))
|
|
|
+ {
|
|
|
+ MessageBox.Show("请输入搜索内容!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 遍历所有日期文件夹
|
|
|
+ try
|
|
|
+ {
|
|
|
+ List<string> matchingDates = new List<string>();
|
|
|
+
|
|
|
+ foreach (var dateFolder in Directory.GetDirectories(archivesPath))
|
|
|
+ {
|
|
|
+ string contentFilePath = Path.Combine(dateFolder, "content.txt");
|
|
|
+
|
|
|
+ // 检查文件是否存在
|
|
|
+ if (File.Exists(contentFilePath))
|
|
|
+ {
|
|
|
+ string content = File.ReadAllText(contentFilePath);
|
|
|
+
|
|
|
+ // 检查内容是否包含搜索文本
|
|
|
+ if (content.Contains(searchText, StringComparison.OrdinalIgnoreCase))
|
|
|
+ {
|
|
|
+ string dateFolderName = Path.GetFileName(dateFolder);
|
|
|
+ matchingDates.Add(dateFolderName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将匹配的日期显示到 DataGrid
|
|
|
+ ResultDataGrid.ItemsSource = matchingDates;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ MessageBox.Show($"搜索失败:{ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
}
|
|
|
}
|
|
|
}
|