From 3e9d887a12b0d6f6be2486cc6657c907ce84ccd9 Mon Sep 17 00:00:00 2001
From: "NB-PBG2H23AZH\\bib" <Yongkang.Zhang@edu.bib.de>
Date: Thu, 10 Apr 2025 11:22:48 +0200
Subject: [PATCH] more pdf

---
 PrototypWPFHAG/App.xaml             |   2 +-
 PrototypWPFHAG/SearchWindow.xaml    |   2 +
 PrototypWPFHAG/SearchWindow.xaml.cs | 109 ++++++++++++++++------------
 3 files changed, 65 insertions(+), 48 deletions(-)

diff --git a/PrototypWPFHAG/App.xaml b/PrototypWPFHAG/App.xaml
index 48557f0..7a9034b 100644
--- a/PrototypWPFHAG/App.xaml
+++ b/PrototypWPFHAG/App.xaml
@@ -2,7 +2,7 @@
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:local="clr-namespace:PrototypWPFHAG"
-             StartupUri="MainWindow.xaml">
+             StartupUri="SearchWindow.xaml">
     <Application.Resources>
 		<ResourceDictionary>
 			<ResourceDictionary.MergedDictionaries>
diff --git a/PrototypWPFHAG/SearchWindow.xaml b/PrototypWPFHAG/SearchWindow.xaml
index af178ae..831f24c 100644
--- a/PrototypWPFHAG/SearchWindow.xaml
+++ b/PrototypWPFHAG/SearchWindow.xaml
@@ -50,6 +50,8 @@
                         <Grid Background="Transparent" AllowDrop="True"
                               DragEnter="PdfDropCanvas_DragEnter" Drop="PdfDropCanvas_Drop" Margin="0,0,9,0">
                             <!-- Hinweistext und ggf. Vorschau (zunächst unsichtbar) -->
+                            <Button Grid.Column="0" Content="Wähle PDF aus" Background="LightBlue" Click="ChoosePdfButton_Click" 
+                                        Margin="296,-2,-15,0"/>
                             <TextBlock x:Name="DropHintText" Text="PDF hier rein ziehen" 
                                        Foreground="Gray" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5"/>
                             <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5,30,0,0">
diff --git a/PrototypWPFHAG/SearchWindow.xaml.cs b/PrototypWPFHAG/SearchWindow.xaml.cs
index c419f35..995df79 100644
--- a/PrototypWPFHAG/SearchWindow.xaml.cs
+++ b/PrototypWPFHAG/SearchWindow.xaml.cs
@@ -32,6 +32,7 @@ namespace PrototypWPFHAG
         private readonly PdfServiceClient _pdfServiceClient = new();
         private const string BaseUrl = "http://localhost:8000"; // Microservice-URL
         private string _selectedPdfPath;
+        private List<string> _selectedPdfPaths = new List<string>();
         public SearchWindow()
         {
             InitializeComponent();
@@ -150,6 +151,7 @@ namespace PrototypWPFHAG
             }
         }
 
+        
         private async Task SearchBySimilarityAsync()
         {
             try
@@ -191,18 +193,39 @@ namespace PrototypWPFHAG
             e.Handled = true;
         }
 
+        private void ChoosePdfButton_Click(object sender, RoutedEventArgs e)
+        {
+            var openFileDialog = new Microsoft.Win32.OpenFileDialog
+            {
+                Filter = "PDF Files (*.pdf)|*.pdf",
+                Multiselect = true 
+            };
+
+            if (openFileDialog.ShowDialog() == true)
+            {
+                _selectedPdfPaths.AddRange(openFileDialog.FileNames);
+
+                
+                PdfIcon.Visibility = Visibility.Visible;
+                PdfFileNameText.Text = string.Join(", ", _selectedPdfPaths.Select(System.IO.Path.GetFileName));
+                PdfFileNameText.Visibility = Visibility.Visible;
+                DropHintText.Visibility = Visibility.Collapsed;
+            }
+        }
         private void PdfDropCanvas_Drop(object sender, DragEventArgs e)
         {
             if (e.Data.GetDataPresent(DataFormats.FileDrop))
             {
                 string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
-                _selectedPdfPath = files.FirstOrDefault(f => System.IO.Path.GetExtension(f).Equals(".pdf", StringComparison.OrdinalIgnoreCase));
+                var pdfFiles = files.Where(f => System.IO.Path.GetExtension(f).Equals(".pdf", StringComparison.OrdinalIgnoreCase)).ToList();
 
-                if (_selectedPdfPath != null)
+                if (pdfFiles.Any())
                 {
-                    // Vorschau anzeigen
+                    _selectedPdfPaths.AddRange(pdfFiles);
+
+                    // 更新UI以显示所有文件
                     PdfIcon.Visibility = Visibility.Visible;
-                    PdfFileNameText.Text = System.IO.Path.GetFileName(_selectedPdfPath);
+                    PdfFileNameText.Text = string.Join(", ", _selectedPdfPaths.Select(System.IO.Path.GetFileName));
                     PdfFileNameText.Visibility = Visibility.Visible;
                     DropHintText.Visibility = Visibility.Collapsed;
                 }
@@ -262,7 +285,7 @@ namespace PrototypWPFHAG
 
         private async void UploadButton_Click(object sender, RoutedEventArgs e)
         {
-            if (string.IsNullOrEmpty(_selectedPdfPath))
+            if (!_selectedPdfPaths.Any())
             {
                 MessageBox.Show("Keine PDF ausgewählt!");
                 return;
@@ -275,54 +298,46 @@ namespace PrototypWPFHAG
 
             try
             {
-                using (var httpClient = new HttpClient())
-                using (var fileStream = File.OpenRead(_selectedPdfPath))
+                int totalFiles = _selectedPdfPaths.Count;
+                int currentFile = 0;
+
+                foreach (var pdfPath in _selectedPdfPaths)
                 {
-                    var progress = new Progress<float>(percent =>
+                    currentFile++;
+                    UploadStatusText.Text = $"Upload {currentFile}/{totalFiles}: {System.IO.Path.GetFileName(pdfPath)}";
+
+                    using (var httpClient = new HttpClient())
+                    using (var fileStream = File.OpenRead(pdfPath))
                     {
-                        Dispatcher.Invoke(() =>
+                        var content = new StreamContent(fileStream);
+                        var formData = new MultipartFormDataContent();
+                        formData.Add(content, "file", System.IO.Path.GetFileName(pdfPath));
+
+                        var response = await httpClient.PostAsync($"{BaseUrl}/upload-pdf", formData);
+
+                        if (response.IsSuccessStatusCode)
                         {
-                            UploadProgressBar.Value = percent * 100;
-                            UploadStatusText.Text = $"Upload: {(int)(percent * 100)}%";
-                        });
-                    });
-
-                    var content = new StreamContent(fileStream);
-                    var formData = new MultipartFormDataContent();
-                    formData.Add(content, "file", Path.GetFileName(_selectedPdfPath));
-
-                    // Simulierter Fortschritt
-                    for (int i = 0; i <= 100; i += 10)
-                    {
-                        await Task.Delay(100);
-                        ((IProgress<float>)progress).Report(i / 100f);
-                    }
-
-                    var response = await httpClient.PostAsync($"{BaseUrl}/upload-pdf", formData);
-
-                    if (response.IsSuccessStatusCode)
-                    {
-                        // Erfolgsmeldung anzeigen
-                        UploadStatusText.Text = "Erfolgreich hochgeladen!";
-
-                        // Canvas zurücksetzen
-                        Dispatcher.Invoke(() =>
+                            UploadStatusText.Text = $"Erfolgreich hochgeladen: {System.IO.Path.GetFileName(pdfPath)}";
+                        }
+                        else
                         {
-                            PdfIcon.Visibility = Visibility.Collapsed;
-                            PdfFileNameText.Visibility = Visibility.Collapsed;
-                            DropHintText.Visibility = Visibility.Visible;
-                            _selectedPdfPath = null;
-                        });
-
-                        // Erfolgsmeldung nach 3 Sekunden ausblenden
-                        await Task.Delay(3000);
-                        UploadStatusText.Text = string.Empty;
-                    }
-                    else
-                    {
-                        UploadStatusText.Text = "Fehler beim Upload";
+                            UploadStatusText.Text = $"Fehler beim Upload von {System.IO.Path.GetFileName(pdfPath)}";
+                        }
                     }
                 }
+
+                // Canvas zurücksetzen
+                Dispatcher.Invoke(() =>
+                {
+                    PdfIcon.Visibility = Visibility.Collapsed;
+                    PdfFileNameText.Visibility = Visibility.Collapsed;
+                    DropHintText.Visibility = Visibility.Visible;
+                    _selectedPdfPaths.Clear();
+                });
+
+                // Erfolgsmeldung nach 3 Sekunden ausblenden
+                await Task.Delay(3000);
+                UploadStatusText.Text = string.Empty;
             }
             catch (Exception ex)
             {