Benjamin sisko 4 months ago
parent
commit
acaf6bc8e1
2 changed files with 63 additions and 47 deletions
  1. 2 20
      ArchivesCenter4/backup.xaml
  2. 61 27
      ArchivesCenter4/backup.xaml.cs

+ 2 - 20
ArchivesCenter4/backup.xaml

@@ -16,26 +16,8 @@
 
         <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 x:Name="BDel" Icon="Delete" Label="删除还原点" IsEnabled="False" Click="BDel_Click"/>
+            <AppBarButton x:Name="BAllDel" Icon="SelectAll" Label="清空还原点" Click="BAllDel_Click"/>
             <AppBarButton Icon="Refresh" Label="刷新" Click="AppBarButton_Click"/>
         </CommandBar>
         <ListView x:Name="BackupFilesListView" Grid.Row="1" Margin="48,16,48,0" SelectionChanged="BackupFilesListView_SelectionChanged">

+ 61 - 27
ArchivesCenter4/backup.xaml.cs

@@ -77,37 +77,11 @@ namespace ArchivesCenter4
             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);
@@ -118,12 +92,72 @@ namespace ArchivesCenter4
             if (!Directory.Exists(dataPath))
                 return;
 
-            string fileName = DateTime.Now.ToString("yyyyMMdd_HHmmss_ffffff") + ".zip";
+            string fileName = DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH'.'mm'.'ss'.'fffffff") + ".zip";
             string zipFilePath = Path.Combine(backupsPath, fileName);
 
             ZipFile.CreateFromDirectory(dataPath, zipFilePath);
             LoadBackupFiles();
         }
+
+        private async void BDel_Click(object sender, RoutedEventArgs e)
+        {
+            ContentDialog deleteDialog = new ContentDialog
+            {
+                Title = "确认删除此还原点?",
+                Content = "此操作不可恢复,请谨慎操作!",
+                PrimaryButtonText = "确认",
+                CloseButtonText = "取消",
+                DefaultButton = ContentDialogButton.Primary,
+                XamlRoot=this.XamlRoot
+            };
+
+            // 显示对话框并等待用户操作
+            ContentDialogResult result = await deleteDialog.ShowAsync();
+
+            // 根据用户点击的按钮处理逻辑
+            if (result == ContentDialogResult.Primary)
+            {
+                var selectedItem = BackupFilesListView.SelectedItem as BackupFileInfo;
+                if (selectedItem == null)
+                    return;
+                File.Delete(selectedItem.FullPath);
+                LoadBackupFiles();
+            }
+        }
+
+        private async void BAllDel_Click(object sender, RoutedEventArgs e)
+        {
+            ContentDialog deleteDialog = new ContentDialog
+            {
+                Title = "确认删除全部还原点?",
+                Content = "此操作不可恢复,请谨慎操作!",
+                PrimaryButtonText = "确认",
+                CloseButtonText = "取消",
+                DefaultButton = ContentDialogButton.Primary,
+                XamlRoot = this.XamlRoot
+            };
+
+            // 显示对话框并等待用户操作
+            ContentDialogResult result = await deleteDialog.ShowAsync();
+
+            // 根据用户点击的按钮处理逻辑
+            if (result == ContentDialogResult.Primary)
+            {
+                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();
+            }
+        }
     }
     public class BackupFileInfo
     {