Benjamin sisko 2 months ago
parent
commit
46a495af0e

+ 1 - 4
ArchivesCenter4 (Package)/ArchivesCenter4 (Package).wapproj

@@ -64,13 +64,10 @@
     </ProjectReference>
   </ItemGroup>
   <ItemGroup>
-    <PackageReference Include="CommunityToolkit.WinUI.Controls.Primitives" Version="8.1.240916" />
-    <PackageReference Include="CommunityToolkit.WinUI.Controls.Segmented" Version="8.1.240916" />
-    <PackageReference Include="CommunityToolkit.WinUI.Controls.SettingsControls" Version="8.1.240916" />
-    <PackageReference Include="CommunityToolkit.WinUI.Controls.Sizers" Version="8.1.240916" />
     <PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1742" />
     <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.250205002" />
     <PackageReference Include="System.Configuration.ConfigurationManager" Version="9.0.2" />
+    <PackageReference Include="System.Private.Uri" Version="4.3.2" />
   </ItemGroup>
   <Import Project="$(WapProjPath)\Microsoft.DesktopBridge.targets" />
 </Project>

+ 12 - 0
ArchivesCenter4/App.config

@@ -25,6 +25,18 @@
             <setting name="welcomeTitle" serializeAs="String">
                 <value />
             </setting>
+            <setting name="level" serializeAs="String">
+                <value />
+            </setting>
+            <setting name="tag" serializeAs="String">
+                <value />
+            </setting>
+            <setting name="rS" serializeAs="String">
+                <value />
+            </setting>
+            <setting name="bP" serializeAs="String">
+                <value />
+            </setting>
         </ArchivesCenter4.Settings>
     </userSettings>
 </configuration>

+ 1 - 4
ArchivesCenter4/ArchivesCenter4.csproj

@@ -35,13 +35,10 @@
   </ItemGroup>
 
   <ItemGroup>
-    <PackageReference Include="CommunityToolkit.WinUI.Controls.Primitives" Version="8.1.240916" />
-    <PackageReference Include="CommunityToolkit.WinUI.Controls.Segmented" Version="8.1.240916" />
-    <PackageReference Include="CommunityToolkit.WinUI.Controls.SettingsControls" Version="8.1.240916" />
-    <PackageReference Include="CommunityToolkit.WinUI.Controls.Sizers" Version="8.1.240916" />
     <PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1742" />
     <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.250205002" />
     <PackageReference Include="System.Configuration.ConfigurationManager" Version="9.0.2" />
+    <PackageReference Include="System.Private.Uri" Version="4.3.2" />
   </ItemGroup>
 
   <ItemGroup>

+ 48 - 0
ArchivesCenter4/Settings.Designer.cs

@@ -94,5 +94,53 @@ namespace ArchivesCenter4 {
                 this["welcomeTitle"] = value;
             }
         }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("")]
+        public string level {
+            get {
+                return ((string)(this["level"]));
+            }
+            set {
+                this["level"] = value;
+            }
+        }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("")]
+        public string tag {
+            get {
+                return ((string)(this["tag"]));
+            }
+            set {
+                this["tag"] = value;
+            }
+        }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("")]
+        public string rS {
+            get {
+                return ((string)(this["rS"]));
+            }
+            set {
+                this["rS"] = value;
+            }
+        }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("")]
+        public string bP {
+            get {
+                return ((string)(this["bP"]));
+            }
+            set {
+                this["bP"] = value;
+            }
+        }
     }
 }

+ 12 - 0
ArchivesCenter4/Settings.settings

@@ -20,5 +20,17 @@
     <Setting Name="welcomeTitle" Type="System.String" Scope="User">
       <Value Profile="(Default)" />
     </Setting>
+    <Setting Name="level" Type="System.String" Scope="User">
+      <Value Profile="(Default)" />
+    </Setting>
+    <Setting Name="tag" Type="System.String" Scope="User">
+      <Value Profile="(Default)" />
+    </Setting>
+    <Setting Name="rS" Type="System.String" Scope="User">
+      <Value Profile="(Default)" />
+    </Setting>
+    <Setting Name="bP" Type="System.String" Scope="User">
+      <Value Profile="(Default)" />
+    </Setting>
   </Settings>
 </SettingsFile>

+ 39 - 2
ArchivesCenter4/backup.xaml

@@ -6,10 +6,47 @@
     xmlns:local="using:ArchivesCenter4"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
-    mc:Ignorable="d"
-    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
+    mc:Ignorable="d">
 
     <Grid>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="auto"/>
+            <RowDefinition Height="*"/>
+        </Grid.RowDefinitions>
 
+        <CommandBar Grid.Row="0" Background="Transparent" IsOpen="False" Margin="48,16,48,0" DefaultLabelPosition="Right">
+            <AppBarButton Icon="NewFolder" Label="新建还原点" Click="AppBarButton_Click_2"/>
+            <AppBarButton x:Name="BDel" Icon="Delete" Label="删除还原点" IsEnabled="False">
+                <AppBarButton.Flyout>
+                    <Flyout>
+                        <StackPanel>
+                            <TextBlock Style="{ThemeResource BaseTextBlockStyle}" Text="确认删除此还原点?" Margin="0,0,0,12" />
+                            <Button Click="AppBarButton_Click_1" Content="确认" />
+                        </StackPanel>
+                    </Flyout>
+                </AppBarButton.Flyout>
+            </AppBarButton>
+            <AppBarButton x:Name="BAllDel" Icon="SelectAll" Label="清空还原点">
+                <AppBarButton.Flyout>
+                    <Flyout>
+                        <StackPanel>
+                            <TextBlock Style="{ThemeResource BaseTextBlockStyle}" Text="确认删除全部还原点?" Margin="0,0,0,12" />
+                            <Button Click="Button_Click" Content="确认" />
+                        </StackPanel>
+                    </Flyout>
+                </AppBarButton.Flyout>
+            </AppBarButton>
+            <AppBarButton Icon="Refresh" Label="刷新" Click="AppBarButton_Click"/>
+        </CommandBar>
+        <ListView x:Name="BackupFilesListView" Grid.Row="1" Margin="48,16,48,0" SelectionChanged="BackupFilesListView_SelectionChanged">
+            <ListView.ItemTemplate>
+                <DataTemplate>
+                    <StackPanel>
+                        <TextBlock Text="{Binding FileName}" Style="{StaticResource BodyTextBlockStyle}"/>
+                        <TextBlock Text="{Binding FileSize}" Style="{StaticResource CaptionTextBlockStyle}"/>
+                    </StackPanel>
+                </DataTemplate>
+            </ListView.ItemTemplate>
+        </ListView>
     </Grid>
 </Page>

+ 104 - 0
ArchivesCenter4/backup.xaml.cs

@@ -12,6 +12,9 @@ using Microsoft.UI.Xaml.Data;
 using Microsoft.UI.Xaml.Input;
 using Microsoft.UI.Xaml.Media;
 using Microsoft.UI.Xaml.Navigation;
+using System.Collections.ObjectModel;
+using Windows.Storage;
+using System.IO.Compression;
 
 // To learn more about WinUI, the WinUI project structure,
 // and more about our project templates, see: http://aka.ms/winui-project-info.
@@ -26,6 +29,107 @@ namespace ArchivesCenter4
         public backup()
         {
             this.InitializeComponent();
+            LoadBackupFiles();
+        }
+
+        private void LoadBackupFiles()
+        {
+            // 获取用户文档库路径
+            string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
+            string backupsPath = Path.Combine(documentsPath, "ArchivesCenter4", "backups");
+            if (!Directory.Exists(backupsPath))
+                Directory.CreateDirectory(backupsPath);
+
+            // 获取所有压缩包文件并创建 BackupFileInfo 对象
+            var backupFiles = new List<BackupFileInfo>();
+            if (Directory.Exists(backupsPath))
+            {
+                backupFiles = Directory.GetFiles(backupsPath, "*.zip")
+                                       .Select(filePath => new BackupFileInfo
+                                       {
+                                           FileName = Path.GetFileNameWithoutExtension(filePath),
+                                           FileSize = GetFileSize(filePath),
+                                           FullPath = filePath
+                                       })
+                                       .ToList();
+            }
+
+            // 绑定到 ListView
+            BackupFilesListView.ItemsSource = backupFiles;
+        }
+
+        private string GetFileSize(string filePath)
+        {
+            var fileInfo = new FileInfo(filePath);
+            long sizeInBytes = fileInfo.Length;
+
+            // 将文件大小转换为合适的单位
+            if (sizeInBytes >= 1024 * 1024)
+                return $"{sizeInBytes / (1024 * 1024):0.##} MB";
+            else if (sizeInBytes >= 1024)
+                return $"{sizeInBytes / 1024:0.##} KB";
+            else
+                return $"{sizeInBytes} bytes";
+        }
+
+        private void AppBarButton_Click(object sender, RoutedEventArgs e)
+        {
+            LoadBackupFiles();
+        }
+
+        private void AppBarButton_Click_1(object sender, RoutedEventArgs e)
+        {
+            var selectedItem = BackupFilesListView.SelectedItem as BackupFileInfo;
+            if (selectedItem == null)
+                return;
+            File.Delete(selectedItem.FullPath);
+            LoadBackupFiles();
+        }
+
+        private void BackupFilesListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            BDel.IsEnabled = BackupFilesListView.SelectedItem != null;
+        }
+
+        private void Button_Click(object sender, RoutedEventArgs e)
+        {
+            string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
+            string backupsPath = Path.Combine(documentsPath, "ArchivesCenter4", "backups");
+
+            if (!Directory.Exists(backupsPath))
+                return;
+            var zipFiles = Directory.GetFiles(backupsPath, "*.zip");
+            if (zipFiles.Length == 0)
+                return;
+            foreach (var file in zipFiles)
+            {
+                File.Delete(file);
+            }
+            LoadBackupFiles();
+        }
+
+        private void AppBarButton_Click_2(object sender, RoutedEventArgs e)
+        {
+            string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
+            string dataPath = Path.Combine(documentsPath, "ArchivesCenter4", "data");
+            string backupsPath = Path.Combine(documentsPath, "ArchivesCenter4", "backups");
+
+            // 检查 data 文件夹是否存在
+            if (!Directory.Exists(dataPath))
+                return;
+
+            string fileName = DateTime.Now.ToString("yyyyMMdd_HHmmss_ffffff") + ".zip";
+            string zipFilePath = Path.Combine(backupsPath, fileName);
+
+            ZipFile.CreateFromDirectory(dataPath, zipFilePath);
+            LoadBackupFiles();
         }
     }
+    public class BackupFileInfo
+    {
+        public string FileName { get; set; }
+        public string FileSize { get; set; }
+        public string FullPath { get; set; }
+    }
 }
+

+ 2 - 3
ArchivesCenter4/people.xaml

@@ -21,7 +21,7 @@
                         <RowDefinition Height="auto"/>
                         <RowDefinition Height="*"/>
                     </Grid.RowDefinitions>
-                    <CommandBar Grid.ColumnSpan="100" Grid.Row="0" Background="Transparent" IsOpen="False" DefaultLabelPosition="Right">
+                    <CommandBar Grid.ColumnSpan="100" Grid.Row="0" Background="Transparent" IsOpen="False" DefaultLabelPosition="Right" Margin="48,16,16,0">
                         <AppBarButton Icon="NewWindow" Label="新建"/>
                         <AppBarButton Icon="Edit" Label="编辑" IsEnabled="False"/>
                         <AppBarButton Icon="Contact2" Label="更改照片" IsEnabled="False"/>
@@ -30,7 +30,7 @@
                         <AppBarButton Icon="Next" Label="下一个" IsEnabled="False"/>
                         <AppBarSeparator/>
                         <AppBarButton Icon="Delete" Label="删除" IsEnabled="False"/>
-                        <AppBarButton Icon="Refresh" Label="刷新"/>
+                        <AppBarButton Icon="Refresh" Label="刷新" Click="AppBarButton_Click_1"/>
                     </CommandBar>
                     <Grid Grid.Row="1">
                         <Grid.RowDefinitions>
@@ -56,7 +56,6 @@
                                 <RowDefinition Height="auto"/>
                             </Grid.RowDefinitions>
 
-
                             <Grid Grid.Row="0" Grid.Column="0" Background="{ThemeResource CardBackgroundFillColorDefaultBrush}" Margin="48,36,48,16" BorderThickness="1" CornerRadius="{StaticResource ControlCornerRadius}" BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}">
                                 <Grid.RowDefinitions>
                                     <RowDefinition Height="auto"/>

+ 5 - 0
ArchivesCenter4/people.xaml.cs

@@ -32,5 +32,10 @@ namespace ArchivesCenter4
         {
 
         }
+
+        private void AppBarButton_Click_1(object sender, RoutedEventArgs e)
+        {
+
+        }
     }
 }

+ 8 - 18
ArchivesCenter4/setting.xaml

@@ -6,7 +6,6 @@
     xmlns:local="using:ArchivesCenter4"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
-    xmlns:toolkit="using:CommunityToolkit.WinUI.Controls"
     mc:Ignorable="d">
 
     <Grid>
@@ -92,55 +91,46 @@
                         <ColumnDefinition Width="auto"/>
                         <ColumnDefinition Width="*"/>
                     </Grid.ColumnDefinitions>
-                    <toolkit:SettingsCard Description="Select which app theme to display" Header="App theme">
-                        <toolkit:SettingsCard.HeaderIcon>
-                            <FontIcon Glyph="&#xE790;" />
-                        </toolkit:SettingsCard.HeaderIcon>
-                        <ComboBox
-        x:Name="themeMode"
-        AutomationProperties.AutomationId="themeModeComboBox"
-        SelectionChanged="themeMode_SelectionChanged">
-                            <ComboBoxItem Content="Light" Tag="Light" />
-                            <ComboBoxItem Content="Dark" Tag="Dark" />
-                            <ComboBoxItem Content="Use system setting" Tag="Default" />
-                        </ComboBox>
-                    </toolkit:SettingsCard>
                     <TextBlock Grid.Column="0" Text="欢迎标题" Margin="16,16,12,16" HorizontalAlignment="Center" VerticalAlignment="Center" Style="{StaticResource BodyTextBlockStyle}"/>
                     <TextBox x:Name="SwelcomeTitleBox" Grid.Column="1" Margin="0,16,16,16" VerticalAlignment="Center" HorizontalAlignment="Right" Width="200" TextChanged="SwelcomeTitleBox_TextChanged"/>
                 </Grid>
 
                 <TextBlock Grid.Row="9" Text="候选项" HorizontalAlignment="Left" Style="{StaticResource BodyStrongTextBlockStyle}" Margin="36,0,0,8"/>
+                
                 <Grid Grid.Row="10" Background="{ThemeResource CardBackgroundFillColorDefaultBrush}" Margin="36,0,36,16" BorderThickness="1" CornerRadius="{StaticResource ControlCornerRadius}" BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}">
                     <Grid.ColumnDefinitions>
                         <ColumnDefinition Width="auto"/>
                         <ColumnDefinition Width="*"/>
                     </Grid.ColumnDefinitions>
                     <TextBlock Grid.Column="0" Text="“级别”候选项" Margin="16,16,12,16" HorizontalAlignment="Center" VerticalAlignment="Center" Style="{StaticResource BodyTextBlockStyle}"/>
-                    <TextBox x:Name="SlevelBox" Grid.Column="1" Margin="0,16,16,16" TextWrapping="Wrap" AcceptsReturn="True" HorizontalAlignment="Right" Width="400"/>
+                    <TextBox x:Name="SlevelBox" Grid.Column="1" Margin="0,16,16,16" TextWrapping="Wrap" AcceptsReturn="True" HorizontalAlignment="Right" Width="400" TextChanged="SlevelBox_TextChanged"/>
                 </Grid>
+                
                 <Grid Grid.Row="11" Background="{ThemeResource CardBackgroundFillColorDefaultBrush}" Margin="36,0,36,16" BorderThickness="1" CornerRadius="{StaticResource ControlCornerRadius}" BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}">
                     <Grid.ColumnDefinitions>
                         <ColumnDefinition Width="auto"/>
                         <ColumnDefinition Width="*"/>
                     </Grid.ColumnDefinitions>
                     <TextBlock Grid.Column="0" Text="“标签”候选项" Margin="16,16,12,16" HorizontalAlignment="Center" VerticalAlignment="Center" Style="{StaticResource BodyTextBlockStyle}"/>
-                    <TextBox x:Name="StagBox" Grid.Column="1" Margin="0,16,16,16" TextWrapping="Wrap" AcceptsReturn="True" HorizontalAlignment="Right" Width="400"/>
+                    <TextBox x:Name="StagBox" Grid.Column="1" Margin="0,16,16,16" TextWrapping="Wrap" AcceptsReturn="True" HorizontalAlignment="Right" Width="400" TextChanged="StagBox_TextChanged"/>
                 </Grid>
+                
                 <Grid Grid.Row="12" Background="{ThemeResource CardBackgroundFillColorDefaultBrush}" Margin="36,0,36,16" BorderThickness="1" CornerRadius="{StaticResource ControlCornerRadius}" BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}">
                     <Grid.ColumnDefinitions>
                         <ColumnDefinition Width="auto"/>
                         <ColumnDefinition Width="*"/>
                     </Grid.ColumnDefinitions>
                     <TextBlock Grid.Column="0" Text="“相对关系”候选项" Margin="16,16,12,16" HorizontalAlignment="Center" VerticalAlignment="Center" Style="{StaticResource BodyTextBlockStyle}"/>
-                    <TextBox x:Name="SrSBox" Grid.Column="1" Margin="0,16,16,16" TextWrapping="Wrap" AcceptsReturn="True" HorizontalAlignment="Right" Width="400"/>
+                    <TextBox x:Name="SrSBox" Grid.Column="1" Margin="0,16,16,16" TextWrapping="Wrap" AcceptsReturn="True" HorizontalAlignment="Right" Width="400" TextChanged="SrSBox_TextChanged"/>
                 </Grid>
+                
                 <Grid Grid.Row="13" Background="{ThemeResource CardBackgroundFillColorDefaultBrush}" Margin="36,0,36,16" BorderThickness="1" CornerRadius="{StaticResource ControlCornerRadius}" BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}">
                     <Grid.ColumnDefinitions>
                         <ColumnDefinition Width="auto"/>
                         <ColumnDefinition Width="*"/>
                     </Grid.ColumnDefinitions>
                     <TextBlock Grid.Column="0" Text="“籍贯”候选项" Margin="16,16,12,16" HorizontalAlignment="Center" VerticalAlignment="Center" Style="{StaticResource BodyTextBlockStyle}"/>
-                    <TextBox x:Name="SbPBox" Grid.Column="1" Margin="0,16,16,16" TextWrapping="Wrap" AcceptsReturn="True" HorizontalAlignment="Right" Width="400"/>
+                    <TextBox x:Name="SbPBox" Grid.Column="1" Margin="0,16,16,16" TextWrapping="Wrap" AcceptsReturn="True" HorizontalAlignment="Right" Width="400" TextChanged="SbPBox_TextChanged"/>
                 </Grid>
             </Grid>
         </ScrollViewer>

+ 28 - 0
ArchivesCenter4/setting.xaml.cs

@@ -32,6 +32,10 @@ namespace ArchivesCenter4
             SdbSubTitleBox.Text = Settings.Default.dbSubName;
             SdbPSWDBox.Password = Settings.Default.dbPassword;
             SwelcomeTitleBox.Text = Settings.Default.welcomeTitle;
+            SlevelBox.Text = Settings.Default.level.Replace("/*/", "\r\n");
+            StagBox.Text = Settings.Default.tag.Replace("/*/", "\r\n");
+            SrSBox.Text = Settings.Default.rS.Replace("/*/", "\r\n");
+            SbPBox.Text = Settings.Default.bP.Replace("/*/", "\r\n");
         }
 
         private void SuserNameBox_TextChanged(object sender, TextChangedEventArgs e)
@@ -69,5 +73,29 @@ namespace ArchivesCenter4
             Settings.Default.welcomeTitle = SwelcomeTitleBox.Text;
             Settings.Default.Save();
         }
+
+        private void SlevelBox_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            Settings.Default.level = SlevelBox.Text.Replace("\r\n", "/*/");
+            Settings.Default.Save();
+        }
+
+        private void StagBox_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            Settings.Default.tag = StagBox.Text.Replace("\r\n", "/*/");
+            Settings.Default.Save();
+        }
+
+        private void SrSBox_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            Settings.Default.rS = SrSBox.Text.Replace("\r\n", "/*/");
+            Settings.Default.Save();
+        }
+
+        private void SbPBox_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            Settings.Default.bP = SbPBox.Text.Replace("\r\n", "/*/");
+            Settings.Default.Save();
+        }
     }
 }