PDF-Export für Flugbuchungen hinzugefügt

This commit is contained in:
2026-03-06 10:01:43 +01:00
parent 7603469aae
commit 03c91f7dc9
10 changed files with 107 additions and 2 deletions

View File

@@ -1,8 +1,10 @@
using BCrypt.Net; using BCrypt.Net;
using MySql.Data.MySqlClient; using MySql.Data.MySqlClient;
using PdfSharp.Fonts;
using System.Globalization; using System.Globalization;
using System.Reflection; using System.Reflection;
using System.Windows; using System.Windows;
using static SkyTeam.BuchungenPage;
namespace SkyTeam namespace SkyTeam
{ {
@@ -13,6 +15,7 @@ namespace SkyTeam
{ {
Thread.CurrentThread.CurrentUICulture = new CultureInfo("de"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("de");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("de"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("de");
GlobalFontSettings.FontResolver = new CustomFontResolver();
} }
private void CreateDefaultAdmin() private void CreateDefaultAdmin()

View File

@@ -89,6 +89,7 @@
</DataGrid> </DataGrid>
<Button x:Name="CancelBtn" Visibility="Collapsed" Content="{x:Static properties:Resources.CancelFlightButton}" Background="#D32F2F" Foreground="White" FontWeight="Bold" Width="150" Height="40" HorizontalAlignment="Right" Margin="0,15,0,0" Click="CancelBooking_Click"/> <Button x:Name="CancelBtn" Visibility="Collapsed" Content="{x:Static properties:Resources.CancelFlightButton}" Background="#D32F2F" Foreground="White" FontWeight="Bold" Width="150" Height="40" HorizontalAlignment="Right" Margin="0,15,0,0" Click="CancelBooking_Click"/>
<Button x:Name="CreatePdfBtn" Visibility="Collapsed" Content="{x:Static properties:Resources.CreatePdfButton}" Background="#FF1E88E5" Foreground="White" FontWeight="Bold" Width="150" Height="40" HorizontalAlignment="Right" Margin="0,15,0,0" Click="CreatePdf_Click"/>
</StackPanel> </StackPanel>
</Grid> </Grid>
</Grid> </Grid>

View File

@@ -1,8 +1,13 @@
using System; using MySql.Data.MySqlClient;
using PdfSharp.Drawing;
using PdfSharp.Fonts;
using PdfSharp.Pdf;
using System;
using System.Data; using System.Data;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using MySql.Data.MySqlClient; using static System.Runtime.InteropServices.JavaScript.JSType;
using System.IO;
namespace SkyTeam namespace SkyTeam
{ {
@@ -41,12 +46,14 @@ namespace SkyTeam
NoBookingsView.Visibility = Visibility.Collapsed; NoBookingsView.Visibility = Visibility.Collapsed;
BookingsGrid.Visibility = Visibility.Visible; BookingsGrid.Visibility = Visibility.Visible;
CancelBtn.Visibility = Visibility.Visible; CancelBtn.Visibility = Visibility.Visible;
CreatePdfBtn.Visibility = Visibility.Visible;
} }
else else
{ {
NoBookingsView.Visibility = Visibility.Visible; NoBookingsView.Visibility = Visibility.Visible;
BookingsGrid.Visibility = Visibility.Collapsed; BookingsGrid.Visibility = Visibility.Collapsed;
CancelBtn.Visibility = Visibility.Collapsed; CancelBtn.Visibility = Visibility.Collapsed;
CreatePdfBtn.Visibility = Visibility.Collapsed;
} }
} }
} }
@@ -74,11 +81,81 @@ namespace SkyTeam
LoadBookings(); LoadBookings();
} }
} }
// Idee und Grundlage aus folgendem Video:
// https://www.youtube.com/watch?v=sfeJprlUT7E
// Datum: 05.03.2026
// Anpassung und Implementierung mit Unterstützung von ChatGPT (OpenAI)
public class CustomFontResolver : IFontResolver
{
private readonly string fontPath = "OpenSans-Regular.ttf";
public string DefaultFontName => "OpenSans";
public byte[] GetFont(string faceName)
{
return File.ReadAllBytes(fontPath);
}
public FontResolverInfo ResolveTypeface(string familyName, bool isBold, bool isItalic)
{
return new FontResolverInfo("OpenSans");
}
}
// Feature: PDF-Export für Flugbuchungen hinzugefügt
//Quelle:
//YouTube Tutorial: https://www.youtube.com/watch?v=C-yMypr_TdY
//Datum: 05.03.2026
private void CreatePdf_Click(object sender, RoutedEventArgs e)
{
if (BookingsGrid.SelectedItem == null)
{
MessageBox.Show("Bitte wählen Sie einen Flug aus.");
return;
}
DataRowView row = (DataRowView)BookingsGrid.SelectedItem;
int buchungId = Convert.ToInt32(row["BuchungId"]);
string flugNr = row["Flugnummer"].ToString();
string von = row["Abflugort"].ToString();
string nach = row["Zielort"].ToString();
DateTime datum = Convert.ToDateTime(row["Abflugdatum"]);
string status = row["Status"].ToString();
string logoPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "icon.png");
XImage logo = XImage.FromFile(logoPath);
PdfDocument document = new PdfDocument();
document.Info.Title = "Flugbuchung";
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
XFont titleFont = new XFont("OpenSans", 30);
XFont textFont = new XFont("OpenSans", 20);
gfx.DrawImage(logo, 40, 20, 100, 100);
gfx.DrawString("Flugbuchung", titleFont, XBrushes.Black, new XPoint(200, 80));
gfx.DrawString($"Buchung-ID: {buchungId}", textFont, XBrushes.Black, new XPoint(40, 160));
gfx.DrawString($"Flug-Nr.: {flugNr}", textFont, XBrushes.Black, new XPoint(40, 200));
gfx.DrawString($"Von: {von}", textFont, XBrushes.Black, new XPoint(40, 240));
gfx.DrawString($"Nach: {nach}", textFont, XBrushes.Black, new XPoint(40, 280));
gfx.DrawString($"Datum: {datum:dd.MM.yyyy}", textFont, XBrushes.Black, new XPoint(40, 320));
gfx.DrawString($"Status: {status}", textFont, XBrushes.Black, new XPoint(40, 360));
string filename = $"Flugbuchung_{buchungId}.pdf";
document.Save(filename);
MessageBox.Show($"PDF erfolgreich erstellt: {filename}");
}
private void HomeButton_Click(object sender, RoutedEventArgs e) => NavigationService.Navigate(new NavigationPage()); private void HomeButton_Click(object sender, RoutedEventArgs e) => NavigationService.Navigate(new NavigationPage());
private void BookingsButton_Click(object sender, RoutedEventArgs e) => NavigationService.Navigate(new BuchungenPage()); private void BookingsButton_Click(object sender, RoutedEventArgs e) => NavigationService.Navigate(new BuchungenPage());
private void SettingsButton_Click(object sender, RoutedEventArgs e) => NavigationService.Navigate(new SettingsPage()); private void SettingsButton_Click(object sender, RoutedEventArgs e) => NavigationService.Navigate(new SettingsPage());
private void LogoutButton_Click(object sender, RoutedEventArgs e) => NavigationService.Navigate(new LogInPage()); private void LogoutButton_Click(object sender, RoutedEventArgs e) => NavigationService.Navigate(new LogInPage());
private void OpenReservierungSuche_Click(object sender, RoutedEventArgs e) => NavigationService.Navigate(new ReservierungssuchePage()); private void OpenReservierungSuche_Click(object sender, RoutedEventArgs e) => NavigationService.Navigate(new ReservierungssuchePage());
} }
} }

Binary file not shown.

View File

@@ -222,6 +222,15 @@ namespace SkyTeam {
} }
} }
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die Als PDF exportieren ähnelt.
/// </summary>
public static string CreatePdfButton {
get {
return ResourceManager.GetString("CreatePdfButton", resourceCulture);
}
}
/// <summary> /// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die Passen Sie Ihr Erlebnis an ähnelt. /// Sucht eine lokalisierte Zeichenfolge, die Passen Sie Ihr Erlebnis an ähnelt.
/// </summary> /// </summary>

View File

@@ -285,4 +285,7 @@
<data name="CancelFlightButton" xml:space="preserve"> <data name="CancelFlightButton" xml:space="preserve">
<value>إلغاء الرحلة</value> <value>إلغاء الرحلة</value>
</data> </data>
<data name="CreatePdfButton" xml:space="preserve">
<value>تصدير إلى PDF</value>
</data>
</root> </root>

View File

@@ -285,4 +285,7 @@
<data name="CancelFlightButton" xml:space="preserve"> <data name="CancelFlightButton" xml:space="preserve">
<value>Cancel Flight</value> <value>Cancel Flight</value>
</data> </data>
<data name="CreatePdfButton" xml:space="preserve">
<value>Export as PDF</value>
</data>
</root> </root>

View File

@@ -285,4 +285,7 @@
<data name="CancelFlightButton" xml:space="preserve"> <data name="CancelFlightButton" xml:space="preserve">
<value>Flug stornieren</value> <value>Flug stornieren</value>
</data> </data>
<data name="CreatePdfButton" xml:space="preserve">
<value>Als PDF exportieren</value>
</data>
</root> </root>

View File

@@ -285,4 +285,7 @@
<data name="CancelFlightButton" xml:space="preserve"> <data name="CancelFlightButton" xml:space="preserve">
<value>Скасувати рейс</value> <value>Скасувати рейс</value>
</data> </data>
<data name="CreatePdfButton" xml:space="preserve">
<value>Експортувати у PDF</value>
</data>
</root> </root>

View File

@@ -17,6 +17,9 @@
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" /> <PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="MahApps.Metro.IconPacks" Version="6.2.1" /> <PackageReference Include="MahApps.Metro.IconPacks" Version="6.2.1" />
<PackageReference Include="MySql.Data" Version="9.6.0" /> <PackageReference Include="MySql.Data" Version="9.6.0" />
<PackageReference Include="PDFsharp" Version="6.2.4" />
<PackageReference Include="System.Drawing.Common" Version="10.0.3" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="10.0.3" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>