diff --git a/SkyTeam/AdminDashBoard.xaml b/SkyTeam/AdminDashBoard.xaml
new file mode 100644
index 0000000..e194db2
--- /dev/null
+++ b/SkyTeam/AdminDashBoard.xaml
@@ -0,0 +1,159 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/SkyTeam/AdminDashBoard.xaml.cs b/SkyTeam/AdminDashBoard.xaml.cs
new file mode 100644
index 0000000..731c981
--- /dev/null
+++ b/SkyTeam/AdminDashBoard.xaml.cs
@@ -0,0 +1,130 @@
+using System;
+using System.Data;
+using System.Windows;
+using System.Windows.Controls;
+using MySql.Data.MySqlClient;
+
+namespace SkyTeam
+{
+ public partial class AdminDashboard : Page
+ {
+ public AdminDashboard()
+ {
+ InitializeComponent();
+ LoadUsers();
+ LoadFlights();
+ LoadCombos();
+ }
+
+ private void LoadUsers()
+ {
+ BindGrid("SELECT Id, Vorname, Nachname, Email, Rolle FROM users", AllUsersGrid);
+ }
+
+ private void AllUsersGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ if (AllUsersGrid.SelectedItem == null) return;
+ DataRowView row = (DataRowView)AllUsersGrid.SelectedItem;
+ int userId = Convert.ToInt32(row["Id"]);
+ BindGrid($"SELECT b.Id AS BuchungId, f.Flugnummer, f.Abflugort, f.Zielort, f.Abflugdatum FROM buchungen b JOIN fluege f ON b.FlugId = f.Id WHERE b.UserId = {userId}", UserBookingsGrid);
+ }
+
+ private void DeleteUser_Click(object sender, RoutedEventArgs e)
+ {
+ if (AllUsersGrid.SelectedItem == null) { MessageBox.Show("Bitte User wählen"); return; }
+ DataRowView row = (DataRowView)AllUsersGrid.SelectedItem;
+ int uid = Convert.ToInt32(row["Id"]);
+
+ if (MessageBox.Show($"User {uid} löschen?", "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
+ {
+
+ ExecuteSql($"DELETE FROM users WHERE Id={uid}");
+ LoadUsers();
+ UserBookingsGrid.ItemsSource = null;
+ }
+ }
+
+ private void LoadFlights()
+ {
+ string q = @"SELECT f.Id, f.Flugnummer, f.Abflugort, f.Zielort, f.Abflugdatum, f.Preis, z.Modell AS Plane, CONCAT(p.Vorname, ' ', p.Nachname) AS Pilot
+ FROM fluege f JOIN flugzeuge z ON f.FlugzeugId = z.Id JOIN piloten p ON f.PilotId = p.Id ORDER BY f.Abflugdatum DESC";
+ BindGrid(q, AllFlightsGrid);
+ }
+
+ private void DeleteFlight_Click(object sender, RoutedEventArgs e)
+ {
+ if (AllFlightsGrid.SelectedItem == null) return;
+ DataRowView row = (DataRowView)AllFlightsGrid.SelectedItem;
+ if (MessageBox.Show("Flug löschen?", "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
+ {
+ ExecuteSql($"DELETE FROM fluege WHERE Id={row["Id"]}");
+ LoadFlights();
+ }
+ }
+
+ private void AddFlight_Click(object sender, RoutedEventArgs e)
+ {
+ if (string.IsNullOrWhiteSpace(AddFromTxt.Text) || string.IsNullOrWhiteSpace(AddToTxt.Text) || AddDatePick.SelectedDate == null || PlaneCombo.SelectedValue == null || PilotCombo.SelectedValue == null)
+ {
+ MessageBox.Show("Bitte alle Felder ausfüllen.");
+ return;
+ }
+
+ int creatorId = SessionManager.CurrentUserId;
+ if (creatorId == 0)
+ {
+ creatorId = 1;
+ }
+
+ string flightNum = "SYJ-" + new Random().Next(100, 999);
+ string query = @"INSERT INTO fluege (Abflugort, Zielort, Abflugdatum, Ankunftsdatum, Flugnummer, Preis, FlugzeugId, PilotId, ErstelltVon)
+ VALUES (@from, @to, @date, @arr, @fnum, @price, @plane, @pilot, @admin)";
+
+ try
+ {
+ using (MySqlConnection conn = new MySqlConnection(DatenbankServices.GetConnection()))
+ {
+ conn.Open();
+ MySqlCommand cmd = new MySqlCommand(query, conn);
+ cmd.Parameters.AddWithValue("@from", AddFromTxt.Text);
+ cmd.Parameters.AddWithValue("@to", AddToTxt.Text);
+ cmd.Parameters.AddWithValue("@date", AddDatePick.SelectedDate.Value);
+ cmd.Parameters.AddWithValue("@arr", AddDatePick.SelectedDate.Value.AddHours(4));
+ cmd.Parameters.AddWithValue("@fnum", flightNum);
+ cmd.Parameters.AddWithValue("@price", AddPriceTxt.Text);
+ cmd.Parameters.AddWithValue("@plane", PlaneCombo.SelectedValue);
+ cmd.Parameters.AddWithValue("@pilot", PilotCombo.SelectedValue);
+
+ cmd.Parameters.AddWithValue("@admin", creatorId);
+
+ cmd.ExecuteNonQuery();
+ MessageBox.Show($"Flug {flightNum} erstellt!");
+ LoadFlights();
+ }
+ }
+ catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); }
+ }
+
+ private void LoadCombos()
+ {
+ BindComboBox("SELECT Id, Modell FROM flugzeuge WHERE IstDefekt=0", PlaneCombo, "Modell", "Id");
+ BindComboBox("SELECT Id, CONCAT(Vorname, ' ', Nachname) AS FullName FROM piloten WHERE IstVerfuegbar=1", PilotCombo, "FullName", "Id");
+ }
+ private void BindGrid(string q, DataGrid g)
+ {
+ try { using (var c = new MySqlConnection(DatenbankServices.GetConnection())) { c.Open(); var a = new MySqlDataAdapter(q, c); var t = new DataTable(); a.Fill(t); g.ItemsSource = t.DefaultView; } } catch { }
+ }
+ private void BindComboBox(string q, ComboBox b, string d, string v)
+ {
+ try { using (var c = new MySqlConnection(DatenbankServices.GetConnection())) { c.Open(); var a = new MySqlDataAdapter(q, c); var t = new DataTable(); a.Fill(t); b.ItemsSource = t.DefaultView; b.DisplayMemberPath = d; b.SelectedValuePath = v; } } catch { }
+ }
+ private void ExecuteSql(string s)
+ {
+ try { using (var c = new MySqlConnection(DatenbankServices.GetConnection())) { c.Open(); new MySqlCommand(s, c).ExecuteNonQuery(); } } catch (Exception ex) { MessageBox.Show(ex.Message); }
+ }
+
+ private void ShowUsers_Click(object sender, RoutedEventArgs e) { UserManagementGrid.Visibility = Visibility.Visible; FlightManagementGrid.Visibility = Visibility.Collapsed; }
+ private void ShowFlights_Click(object sender, RoutedEventArgs e) { UserManagementGrid.Visibility = Visibility.Collapsed; FlightManagementGrid.Visibility = Visibility.Visible; }
+ private void Logout_Click(object sender, RoutedEventArgs e) { SessionManager.CurrentUserId = 0; NavigationService.Navigate(new LogInPage()); }
+ }
+}
\ No newline at end of file
diff --git a/SkyTeam/AdminLoginPage.xaml b/SkyTeam/AdminLoginPage.xaml
new file mode 100644
index 0000000..8ce8ba6
--- /dev/null
+++ b/SkyTeam/AdminLoginPage.xaml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/SkyTeam/AdminLoginPage.xaml.cs b/SkyTeam/AdminLoginPage.xaml.cs
new file mode 100644
index 0000000..1be037a
--- /dev/null
+++ b/SkyTeam/AdminLoginPage.xaml.cs
@@ -0,0 +1,65 @@
+using System;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Navigation;
+using MySql.Data.MySqlClient;
+using BCrypt.Net;
+
+namespace SkyTeam
+{
+ public partial class AdminLoginPage : Page
+ {
+ public AdminLoginPage() => InitializeComponent();
+
+ private void AdminLogin_Click(object sender, RoutedEventArgs e)
+ {
+ string query = "SELECT Id, PasswortHash FROM users WHERE Email = @email AND Vorname = @user AND Rolle = @role";
+
+ try
+ {
+ using (MySqlConnection conn = new MySqlConnection(DatenbankServices.GetConnection()))
+ {
+ conn.Open();
+ using (MySqlCommand cmd = new MySqlCommand(query, conn))
+ {
+ cmd.Parameters.AddWithValue("@email", AdminEmailBox.Text);
+ cmd.Parameters.AddWithValue("@user", AdminUserBox.Text);
+ cmd.Parameters.AddWithValue("@role", AdminRoleBox.Text);
+
+ using (MySqlDataReader reader = cmd.ExecuteReader())
+ {
+ if (reader.Read())
+ {
+ string storedHash = reader.GetString("PasswortHash");
+ int dbId = reader.GetInt32("Id");
+
+ if (BCrypt.Net.BCrypt.Verify(AdminPassBox.Password, storedHash))
+ {
+ SessionManager.CurrentUserId = dbId;
+ SessionManager.CurrentUserName = AdminUserBox.Text;
+
+ MessageBox.Show("Admin-Zugriff gewährt!");
+ NavigationService.Navigate(new AdminDashboard());
+ }
+ else
+ {
+ MessageBox.Show("Ungültiges Passwort.");
+ }
+ }
+ else
+ {
+ MessageBox.Show("Kein Admin mit diesen Daten gefunden.");
+ }
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("Fehler: " + ex.Message);
+ }
+ }
+
+ private void Back_Click(object sender, RoutedEventArgs e) => NavigationService.Navigate(new LogInPage());
+ }
+}
\ No newline at end of file
diff --git a/SkyTeam/App.xaml b/SkyTeam/App.xaml
index a01b6c6..9e49904 100644
--- a/SkyTeam/App.xaml
+++ b/SkyTeam/App.xaml
@@ -1,9 +1,12 @@
-
+
+
+
+
+
-
+
\ No newline at end of file
diff --git a/SkyTeam/App.xaml.cs b/SkyTeam/App.xaml.cs
index e441a93..3289b10 100644
--- a/SkyTeam/App.xaml.cs
+++ b/SkyTeam/App.xaml.cs
@@ -1,14 +1,54 @@
-using System.Configuration;
-using System.Data;
-using System.Windows;
+using System.Windows;
+using MySql.Data.MySqlClient;
+using BCrypt.Net;
namespace SkyTeam
{
- ///
- /// Interaction logic for App.xaml
- ///
public partial class App : Application
{
- }
-}
+ // Beim Start der Anwendung einen Standard Admin-Benutzer erstellen, falls keiner existiert , selbGedacht.
+
+ protected override void OnStartup(StartupEventArgs e)
+ {
+ base.OnStartup(e);
+ CreateDefaultAdmin();
+ }
+
+ private void CreateDefaultAdmin()
+ {
+ string connectionString = DatenbankServices.GetConnection();
+
+ try
+ {
+ using (MySqlConnection conn = new MySqlConnection(connectionString))
+ {
+ conn.Open();
+
+ string checkQuery = "SELECT COUNT(*) FROM users WHERE Rolle = 'Admin'";
+ MySqlCommand checkCmd = new MySqlCommand(checkQuery, conn);
+ long count = (long)checkCmd.ExecuteScalar();
+
+ if (count == 0)
+ {
+ string hashedPassword = BCrypt.Net.BCrypt.HashPassword("admin");
+
+ string insertQuery = @"
+ INSERT INTO users (Vorname, Nachname, Email, PasswortHash, Rolle, Stadt, CreatedAt)
+ VALUES ('System', 'Root', 'admin@skyteam.com', @hash, 'Admin', 'HQ', NOW())";
+
+ MySqlCommand insertCmd = new MySqlCommand(insertQuery, conn);
+ insertCmd.Parameters.AddWithValue("@hash", hashedPassword);
+ insertCmd.ExecuteNonQuery();
+
+ MessageBox.Show("Ein Standard-Admin wurde erstellt!\nEmail: admin@skyteam.com\nPasswort: admin");
+ }
+ }
+ }
+ catch(Exception ex) {
+
+ MessageBox.Show("Fehler beim Erstellen des Standard Admins: " + ex.Message);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/SkyTeam/BuchungenPage.xaml b/SkyTeam/BuchungenPage.xaml
index cf90d1c..73e6df5 100644
--- a/SkyTeam/BuchungenPage.xaml
+++ b/SkyTeam/BuchungenPage.xaml
@@ -2,125 +2,82 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
- Title="BuchungenPage">
+ Title="BuchungenPage"
+ Background="{DynamicResource PageBackground}">
-
-
-
+
-
-
+
+
-
-
+
-
-
-
-
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
\ No newline at end of file
diff --git a/SkyTeam/BuchungenPage.xaml.cs b/SkyTeam/BuchungenPage.xaml.cs
index f6186ec..99ecdc8 100644
--- a/SkyTeam/BuchungenPage.xaml.cs
+++ b/SkyTeam/BuchungenPage.xaml.cs
@@ -1,6 +1,8 @@
-using System.Windows;
+using System;
+using System.Data;
+using System.Windows;
using System.Windows.Controls;
-using System.Collections.ObjectModel;
+using MySql.Data.MySqlClient;
namespace SkyTeam
{
@@ -8,56 +10,75 @@ namespace SkyTeam
{
public BuchungenPage()
{
-
InitializeComponent();
+ LoadBookings();
}
-
-
-
- private void SearchBookingsButton_Click(object sender, RoutedEventArgs e)
+ private void LoadBookings()
{
-
- }
+ if (SessionManager.CurrentUserId == 0) return;
- private void HomeButton_Click(object sender, RoutedEventArgs e)
- {
- ((MainWindow)Application.Current.MainWindow).MainFrame.Navigate(new NavigationPage());
- }
+ string query = @"SELECT b.Id AS BuchungId, f.Flugnummer, f.Abflugort, f.Zielort, f.Abflugdatum, b.Status
+ FROM buchungen b
+ JOIN fluege f ON b.FlugId = f.Id
+ WHERE b.UserId = @uid";
- private void BookingsButton_Click(object sender, RoutedEventArgs e)
- {
- ((MainWindow)Application.Current.MainWindow).MainFrame.Navigate(new BuchungenPage());
- }
-
- private void SettingsButton_Click(object sender, RoutedEventArgs e)
- {
- ((MainWindow)Application.Current.MainWindow).MainFrame.Navigate(new SettingsPage());
- }
-
- private void BookFlightButton_Click(object sender, RoutedEventArgs e)
- {
- ((MainWindow)Application.Current.MainWindow).MainFrame.Navigate(new BuchungenPage());
- }
- private void LogoutButton_Click(object sender, RoutedEventArgs e)
- {
- var result = MessageBox.Show(
- "Möchten Sie sich wirklich abmelden?",
- "Abmelden",
- MessageBoxButton.YesNo,
- MessageBoxImage.Question);
- if (result == MessageBoxResult.Yes)
+ try
{
- ((MainWindow)Application.Current.MainWindow).MainFrame.Navigate(new LogInPage());
+ using (MySqlConnection conn = new MySqlConnection(DatenbankServices.GetConnection()))
+ {
+ conn.Open();
+ MySqlCommand cmd = new MySqlCommand(query, conn);
+ cmd.Parameters.AddWithValue("@uid", SessionManager.CurrentUserId);
+
+ MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
+ DataTable dt = new DataTable();
+ adapter.Fill(dt);
+
+ if (dt.Rows.Count > 0)
+ {
+ BookingsGrid.ItemsSource = dt.DefaultView;
+ NoBookingsView.Visibility = Visibility.Collapsed;
+ BookingsGrid.Visibility = Visibility.Visible;
+ CancelBtn.Visibility = Visibility.Visible;
+ }
+ else
+ {
+ NoBookingsView.Visibility = Visibility.Visible;
+ BookingsGrid.Visibility = Visibility.Collapsed;
+ CancelBtn.Visibility = Visibility.Collapsed;
+ }
+ }
+ }
+ catch (Exception ex) { MessageBox.Show(ex.Message); }
+ }
+
+ private void CancelBooking_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 bid = Convert.ToInt32(row["BuchungId"]);
-
+ if (MessageBox.Show("Stornieren?", "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
+ {
+ using (MySqlConnection conn = new MySqlConnection(DatenbankServices.GetConnection()))
+ {
+ conn.Open();
+ new MySqlCommand($"DELETE FROM buchungen WHERE Id={bid}", conn).ExecuteNonQuery();
+ }
+ LoadBookings();
+ }
}
- private void OpenReservierungSuche_Click(object sender, RoutedEventArgs e)
- {
- ((MainWindow)Application.Current.MainWindow).MainFrame.Navigate(new ReservierungssuchePage());
- }
+ 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 SettingsButton_Click(object sender, RoutedEventArgs e) => NavigationService.Navigate(new SettingsPage());
+ private void LogoutButton_Click(object sender, RoutedEventArgs e) => NavigationService.Navigate(new LogInPage());
+ private void OpenReservierungSuche_Click(object sender, RoutedEventArgs e) => NavigationService.Navigate(new ReservierungssuchePage());
}
-}
+}
\ No newline at end of file
diff --git a/SkyTeam/DatenbankServices.cs b/SkyTeam/DatenbankServices.cs
index e7a7a57..47d6d0c 100644
--- a/SkyTeam/DatenbankServices.cs
+++ b/SkyTeam/DatenbankServices.cs
@@ -3,18 +3,18 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using MySql.Data.MySqlClient;
namespace SkyTeam
{
- class DatenbankServices
+ static class DatenbankServices
{
- private string ConnectionString = "server=localhost;uid=root;pwd=root;database=hci";
- //private string ConnectionString ="Server=mysql.pb.bib.de;uid=pbt3h24akh;pwd=Dd3dwQgPeNxW;database=pbt3h24akh_SkyTeam;";
+ // private static readonly string connectionString = "server=localhost;uid=root;pwd=root;database=hci";
+ private static readonly string connectionString ="Server=mysql.pb.bib.de;uid=pbt3h24akh;pwd=Dd3dwQgPeNxW;database=pbt3h24akh_SkyTeam;";
- protected virtual string connectionString
+ public static string GetConnection()
{
- get { return ConnectionString; }
- private set { ConnectionString = value; }
+ return connectionString;
}
diff --git a/SkyTeam/FlugeRepo.cs b/SkyTeam/FlugeRepo.cs
index 2c74e57..ab8ab95 100644
--- a/SkyTeam/FlugeRepo.cs
+++ b/SkyTeam/FlugeRepo.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace SkyTeam
{
- class FlugeRepo : DatenbankServices
+ class FlugeRepo
{
}
}
diff --git a/SkyTeam/FlugzeugRepo.cs b/SkyTeam/FlugzeugRepo.cs
index a92ae1c..ca042e3 100644
--- a/SkyTeam/FlugzeugRepo.cs
+++ b/SkyTeam/FlugzeugRepo.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace SkyTeam
{
- class FlugzeugRepo : DatenbankServices
+ class FlugzeugRepo
{
}
}
diff --git a/SkyTeam/LogInPage.xaml b/SkyTeam/LogInPage.xaml
index 1b9c60d..91c0b1c 100644
--- a/SkyTeam/LogInPage.xaml
+++ b/SkyTeam/LogInPage.xaml
@@ -5,43 +5,21 @@
Title="LogInPage">
-
-
-
+
+
-
-
+
+
-
-
+
-
@@ -50,65 +28,25 @@
+
-
-
-
-
+
+
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
+ Bitte hier klicken
+
-
-
+
\ No newline at end of file
diff --git a/SkyTeam/LogInPage.xaml.cs b/SkyTeam/LogInPage.xaml.cs
index e67f088..379eec5 100644
--- a/SkyTeam/LogInPage.xaml.cs
+++ b/SkyTeam/LogInPage.xaml.cs
@@ -1,47 +1,93 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
+using MySql.Data.MySqlClient;
+using BCrypt.Net;
namespace SkyTeam
{
- ///
- /// Interaction logic for LogInPage.xaml
- ///
public partial class LogInPage : Page
{
public LogInPage()
{
InitializeComponent();
-
}
-
+ private void AdminLink_Click(object sender, RoutedEventArgs e)
+ {
+ if (Application.Current.MainWindow is MainWindow mainWindow)
+ {
+ mainWindow.MainFrame.Navigate(new AdminLoginPage());
+ }
+ }
+ private void LogInButton_Click(object sender, RoutedEventArgs e)
+ {
+ string email = BenutzernameTextBox.Text;
+ string password = PasswortTextBox.Password;
+
+ if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
+ {
+ MessageBox.Show("Bitte Email und Passwort eingeben.");
+ return;
+ }
+
+ string query = @"
+ SELECT Id, Vorname, Rolle, PasswortHash
+ FROM users
+ WHERE Email = @email";
+
+ try
+ {
+ using (MySqlConnection conn = new MySqlConnection(DatenbankServices.GetConnection()))
+ {
+ conn.Open();
+
+ using (MySqlCommand cmd = new MySqlCommand(query, conn))
+ {
+ cmd.Parameters.AddWithValue("@email", email);
+
+ using (MySqlDataReader reader = cmd.ExecuteReader())
+ {
+ if (!reader.Read())
+ {
+ MessageBox.Show("Benutzer wurde nicht gefunden.");
+ return;
+ }
+
+ string storedHash = reader.GetString("PasswortHash");
+
+ if (!BCrypt.Net.BCrypt.Verify(password, storedHash))
+ {
+ MessageBox.Show("Falsches Passwort.");
+ return;
+ }
+
+
+ SessionManager.CurrentUserId = reader.GetInt32("Id");
+ SessionManager.CurrentUserName = reader.GetString("Vorname");
+ SessionManager.Role = reader.GetString("Rolle");
+ }
+ }
+
+
+ ((MainWindow)Application.Current.MainWindow)
+ .MainFrame.Navigate(new NavigationPage());
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("Datenbankfehler: " + ex.Message);
+ }
+ }
private void anmeldungsButton_Click(object sender, RoutedEventArgs e)
{
- ((MainWindow)Application.Current.MainWindow).MainFrame.Navigate(new RegistrationPage());
-
- }
-
- private void LogInButton_Click(object sender, RoutedEventArgs e)
- {
- ((MainWindow)Application.Current.MainWindow).MainFrame.Navigate(new NavigationPage());
-
+ ((MainWindow)Application.Current.MainWindow)
+ .MainFrame.Navigate(new RegistrationPage());
}
}
}
diff --git a/SkyTeam/PilotenRepo.cs b/SkyTeam/PilotenRepo.cs
index fb3e6ea..5fab9dd 100644
--- a/SkyTeam/PilotenRepo.cs
+++ b/SkyTeam/PilotenRepo.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace SkyTeam
{
- class PilotenRepo : DatenbankServices
+ class PilotenRepo
{
}
}
diff --git a/SkyTeam/Regestrieren.xaml b/SkyTeam/Regestrieren.xaml
index 928db76..b3f49ef 100644
--- a/SkyTeam/Regestrieren.xaml
+++ b/SkyTeam/Regestrieren.xaml
@@ -2,10 +2,10 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
- Title="Registrierungsseite">
+ Title="Registrierungsseite"
+ Background="#F0F2F5">
-
@@ -14,32 +14,34 @@
+ Margin="0,0,0,30">
+ FontWeight="Bold"
+ Foreground="#333"/>
-
-
+ VerticalAlignment="Top"
+ HorizontalAlignment="Center"
+ MaxWidth="500">
+
@@ -48,62 +50,62 @@
-
-
-
+
+
-
+
-
-
+
+
+
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
+
+
+
+
-
-
-
+
\ No newline at end of file
diff --git a/SkyTeam/Regestrieren.xaml.cs b/SkyTeam/Regestrieren.xaml.cs
index 8d7a020..d5581bf 100644
--- a/SkyTeam/Regestrieren.xaml.cs
+++ b/SkyTeam/Regestrieren.xaml.cs
@@ -1,23 +1,11 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
+using MySql.Data.MySqlClient;
+using BCrypt.Net;
namespace SkyTeam
{
- ///
- /// Interaction logic for Page1.xaml
- ///
public partial class RegistrationPage : Page
{
public RegistrationPage()
@@ -25,20 +13,61 @@ namespace SkyTeam
InitializeComponent();
}
-
private void RegisterButton_Click(object sender, RoutedEventArgs e)
{
+ if (string.IsNullOrEmpty(PasswordBox.Password))
+ {
+ MessageBox.Show("Bitte geben Sie ein Passwort ein.");
+ return;
+ }
+ string hashedPassword = BCrypt.Net.BCrypt.HashPassword(PasswordBox.Password);
+ string query = "INSERT INTO users (Vorname, Nachname, Email, PasswortHash, Rolle, Stadt, Anrede, Geburtsdatum) " +
+ "VALUES (@vorname, @nachname, @email, @password, 'User', @stadt, @anrede, @geburtsdatum)";
+ try
+ {
+ using (MySqlConnection conn = new MySqlConnection(DatenbankServices.GetConnection()))
+ {
+ conn.Open();
+ using (MySqlCommand cmd = new MySqlCommand(query, conn))
+ {
+ string selectedAnrede = (SalutationComboBox.SelectedItem as ComboBoxItem)?.Content.ToString();
+ DateTime? selectedDate = BirthDatePicker.SelectedDate;
+ cmd.Parameters.AddWithValue("@vorname", FirstNameTextBox.Text);
+ cmd.Parameters.AddWithValue("@nachname", LastNameTextBox.Text);
+ cmd.Parameters.AddWithValue("@email", EmailTextBox.Text);
+ cmd.Parameters.AddWithValue("@password", hashedPassword);
+ cmd.Parameters.AddWithValue("@stadt", CityTextBox.Text);
+ cmd.Parameters.AddWithValue("@anrede", selectedAnrede ?? (object)DBNull.Value);
+ cmd.Parameters.AddWithValue("@geburtsdatum", selectedDate.HasValue ? selectedDate.Value : (object)DBNull.Value);
+
+ cmd.ExecuteNonQuery();
+ }
+ }
+
+ MessageBox.Show("Dein Konto wurde erfolgreich angelegt!");
+
+ if (Application.Current.MainWindow is MainWindow mainWindow)
+ {
+ mainWindow.MainFrame.Navigate(new LogInPage());
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("Etwas ist schief gelaufen: " + ex.Message);
+ }
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
- ((MainWindow)Application.Current.MainWindow).MainFrame.Navigate(new LogInPage());
-
+ if (Application.Current.MainWindow is MainWindow mainWindow)
+ {
+ mainWindow.MainFrame.Navigate(new LogInPage());
+ }
}
}
-}
+}
\ No newline at end of file
diff --git a/SkyTeam/SettingsPage.xaml b/SkyTeam/SettingsPage.xaml
index b62fcff..52206fa 100644
--- a/SkyTeam/SettingsPage.xaml
+++ b/SkyTeam/SettingsPage.xaml
@@ -2,179 +2,127 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
- Title="SettingsPage">
+ Title="SettingsPage"
+ Background="{DynamicResource PageBackground}">
-
-
-
-
+
+
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
+
-
-
-
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
\ No newline at end of file
diff --git a/SkyTeam/SettingsPage.xaml.cs b/SkyTeam/SettingsPage.xaml.cs
index 0d3fc2a..72181bc 100644
--- a/SkyTeam/SettingsPage.xaml.cs
+++ b/SkyTeam/SettingsPage.xaml.cs
@@ -1,88 +1,95 @@
-using System.Windows;
+using System;
+using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
+using System.Windows.Navigation;
+using MySql.Data.MySqlClient;
namespace SkyTeam
{
public partial class SettingsPage : Page
{
- private bool _isDark = false;
-
public SettingsPage()
{
InitializeComponent();
+
+ var bgBrush = Application.Current.Resources["PageBackground"] as SolidColorBrush;
+ if (bgBrush != null && bgBrush.Color == Color.FromRgb(30, 30, 30))
+ {
+ DarkModeToggle.IsChecked = true;
+ DarkModeToggle.Content = "An";
+ }
+ else
+ {
+ DarkModeToggle.Content = "Aus";
+ }
}
private void DarkModeToggle_Checked(object sender, RoutedEventArgs e)
{
- _isDark = true;
+ SetRes("PageBackground", Color.FromRgb(30, 30, 30));
+ SetRes("CardBackground", Color.FromRgb(45, 45, 45));
+ SetRes("SidebarBackground", Color.FromRgb(20, 20, 20));
+ SetRes("PrimaryText", Colors.White);
+ SetRes("SecondaryText", Color.FromRgb(200, 200, 200));
+
DarkModeToggle.Content = "An";
-
- if (Window.GetWindow(this) is MainWindow mainWindow)
- {
- mainWindow.Background = Brushes.Black;
- }
}
private void DarkModeToggle_Unchecked(object sender, RoutedEventArgs e)
{
- _isDark = false;
+ SetRes("PageBackground", Colors.White);
+ SetRes("CardBackground", Color.FromRgb(245, 247, 250));
+ SetRes("SidebarBackground", Color.FromRgb(227, 242, 253));
+ SetRes("PrimaryText", Colors.Black);
+ SetRes("SecondaryText", Color.FromRgb(102, 102, 102));
+
DarkModeToggle.Content = "Aus";
- if (Window.GetWindow(this) is MainWindow mainWindow)
- {
- mainWindow.Background = Brushes.White;
- }
+ }
+
+ private void SetRes(string key, Color color)
+ {
+ Application.Current.Resources[key] = new SolidColorBrush(color);
}
private void DeleteAccountButton_Click(object sender, RoutedEventArgs e)
{
- var result = MessageBox.Show(
- "Sind Sie sicher, dass Sie Ihr Konto löschen möchten?\nDiese Aktion kann nicht rückgängig gemacht werden!",
- "Konto löschen",
- MessageBoxButton.YesNo,
- MessageBoxImage.Warning);
-
- if (result == MessageBoxResult.Yes)
+ if (MessageBox.Show("Möchten Sie Ihr Konto wirklich löschen?\nAlle Buchungen werden ebenfalls gelöscht.", "Achtung", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
{
-
- MessageBox.Show("Konto wurde gelöscht.", "Erfolg", MessageBoxButton.OK, MessageBoxImage.Information);
- ((MainWindow)Application.Current.MainWindow).MainFrame.Navigate(new LogInPage());
+ try
+ {
+ using (MySqlConnection conn = new MySqlConnection(DatenbankServices.GetConnection()))
+ {
+ conn.Open();
+ string deleteBookings = "DELETE FROM buchungen WHERE UserId = @uid";
+ MySqlCommand cmd1 = new MySqlCommand(deleteBookings, conn);
+ cmd1.Parameters.AddWithValue("@uid", SessionManager.CurrentUserId);
+ cmd1.ExecuteNonQuery();
+ string deleteUser = "DELETE FROM users WHERE Id = @uid";
+ MySqlCommand cmd2 = new MySqlCommand(deleteUser, conn);
+ cmd2.Parameters.AddWithValue("@uid", SessionManager.CurrentUserId);
+ cmd2.ExecuteNonQuery();
+ }
+
+ SessionManager.CurrentUserId = 0;
+ MessageBox.Show("Ihr Konto wurde erfolgreich gelöscht.");
+ NavigationService.Navigate(new LogInPage());
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("Fehler beim Löschen: " + ex.Message);
+ }
}
}
- private void HomeButton_Click(object sender, RoutedEventArgs e)
- {
- ((MainWindow)Application.Current.MainWindow).MainFrame.Navigate(new NavigationPage());
- }
- private void BookingsButton_Click(object sender, RoutedEventArgs e)
- {
- ((MainWindow)Application.Current.MainWindow).MainFrame.Navigate(new BuchungenPage());
- }
-
- private void SettingsButton_Click(object sender, RoutedEventArgs e)
- {
- ((MainWindow)Application.Current.MainWindow).MainFrame.Navigate(new SettingsPage());
- }
-
- private void BookFlightButton_Click(object sender, RoutedEventArgs e)
- {
- ((MainWindow)Application.Current.MainWindow).MainFrame.Navigate(new BuchungenPage());
- }
+ 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 SettingsButton_Click(object sender, RoutedEventArgs e) => NavigationService.Navigate(new SettingsPage());
private void LogoutButton_Click(object sender, RoutedEventArgs e)
{
- var result = MessageBox.Show(
- "Möchten Sie sich wirklich abmelden?",
- "Abmelden",
- MessageBoxButton.YesNo,
- MessageBoxImage.Question);
- if (result == MessageBoxResult.Yes)
- {
- ((MainWindow)Application.Current.MainWindow).MainFrame.Navigate(new LogInPage());
- }
-
-
-
+ SessionManager.CurrentUserId = 0;
+ NavigationService.Navigate(new LogInPage());
}
}
-}
+}
\ No newline at end of file
diff --git a/SkyTeam/SkyTeam.csproj b/SkyTeam/SkyTeam.csproj
index f11d926..77273e6 100644
--- a/SkyTeam/SkyTeam.csproj
+++ b/SkyTeam/SkyTeam.csproj
@@ -9,6 +9,7 @@
+
diff --git a/SkyTeam/SkyTeam.sql b/SkyTeam/SkyTeam.sql
deleted file mode 100644
index 21f5b3c..0000000
--- a/SkyTeam/SkyTeam.sql
+++ /dev/null
@@ -1,75 +0,0 @@
-SET FOREIGN_KEY_CHECKS = 0;
-
-DROP TABLE IF EXISTS fluege;
-DROP TABLE IF EXISTS piloten;
-DROP TABLE IF EXISTS flugzeuge;
-DROP TABLE IF EXISTS mitarbeiter;
-DROP TABLE IF EXISTS users;
-
-SET FOREIGN_KEY_CHECKS = 1;
-
-CREATE TABLE users (
- Id INT AUTO_INCREMENT PRIMARY KEY,
- Vorname VARCHAR(100) NOT NULL,
- Nachname VARCHAR(100) NOT NULL,
- Email VARCHAR(100) NOT NULL,
- PasswortHash VARCHAR(255) NOT NULL,
- Rolle VARCHAR(50) NOT NULL,
- Stadt VARCHAR(100),
- Anrede VARCHAR(20),
- Geburtsdatum DATE,
- CreatedAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
-);
-
-CREATE TABLE flugzeuge (
- Id INT AUTO_INCREMENT PRIMARY KEY,
- Modell VARCHAR(100) NOT NULL,
- Plaetze INT NOT NULL,
- Lagerflaeche FLOAT NOT NULL,
- Gewicht FLOAT NOT NULL,
- Kerosinverbrauch FLOAT NOT NULL,
- Stundengeschwindigkeit FLOAT NOT NULL,
- Stundenstand FLOAT NOT NULL,
- Herstellungsdatum DATE NOT NULL,
- IstDefekt BOOLEAN NOT NULL
-);
-
-CREATE TABLE piloten (
- Id INT AUTO_INCREMENT PRIMARY KEY,
- Vorname VARCHAR(100) NOT NULL,
- Nachname VARCHAR(100) NOT NULL,
- Flugerfahrung FLOAT NOT NULL,
- Groesse FLOAT NOT NULL,
- Bewertung FLOAT NOT NULL,
- Pilotalter DATE NOT NULL,
- Gender VARCHAR(10),
- IstVerfuegbar BOOLEAN NOT NULL,
- Sprachen TEXT
-);
-
-CREATE TABLE fluege (
- Id INT AUTO_INCREMENT PRIMARY KEY,
- Abflugort VARCHAR(100) NOT NULL,
- Zielort VARCHAR(100) NOT NULL,
- Abflugdatum DATETIME NOT NULL,
- Ankunftsdatum DATETIME NOT NULL,
- Flugnummer VARCHAR(20) NOT NULL,
- Preis DECIMAL(10,2) NOT NULL,
- Created DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
- FlugzeugId INT NOT NULL,
- PilotId INT NOT NULL,
- ErstelltVon INT NOT NULL,
- FOREIGN KEY (FlugzeugId) REFERENCES flugzeuge(Id),
- FOREIGN KEY (PilotId) REFERENCES piloten(Id),
- FOREIGN KEY (ErstelltVon) REFERENCES users(Id)
-);
-
-CREATE TABLE mitarbeiter (
- Id INT AUTO_INCREMENT PRIMARY KEY,
- Vorname VARCHAR(100) NOT NULL,
- Nachname VARCHAR(100) NOT NULL,
- Position VARCHAR(100) NOT NULL,
- MitarbeiterAlter INT NOT NULL,
- ArbeitsstundenProWoche FLOAT NOT NULL,
- IstVerfuegbar BOOLEAN NOT NULL
-);
diff --git a/SkyTeam/migration.sql b/SkyTeam/migration.sql
new file mode 100644
index 0000000..0da5c74
--- /dev/null
+++ b/SkyTeam/migration.sql
@@ -0,0 +1,209 @@
+-- ==========================================================
+-- 1. SETUP & CLEANUP
+-- ==========================================================
+SET FOREIGN_KEY_CHECKS = 0;
+SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
+SET time_zone = "+00:00";
+
+-- Drop tables if they exist to ensure a clean slate
+DROP TABLE IF EXISTS buchungen;
+DROP TABLE IF EXISTS fluege;
+DROP TABLE IF EXISTS users;
+DROP TABLE IF EXISTS piloten;
+DROP TABLE IF EXISTS flugzeuge;
+DROP TABLE IF EXISTS mitarbeiter;
+
+-- ==========================================================
+-- 2. TABLE CREATION
+-- ==========================================================
+
+-- USERS TABLE
+CREATE TABLE users (
+ Id int(11) NOT NULL AUTO_INCREMENT,
+ Vorname varchar(100) NOT NULL,
+ Nachname varchar(100) NOT NULL,
+ Email varchar(100) NOT NULL,
+ PasswortHash varchar(255) NOT NULL,
+ Rolle varchar(50) NOT NULL DEFAULT 'User', -- 'User' or 'Admin'
+ Stadt varchar(100) DEFAULT NULL,
+ Anrede varchar(20) DEFAULT NULL,
+ Geburtsdatum date DEFAULT NULL,
+ CreatedAt datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ PRIMARY KEY (Id),
+ UNIQUE KEY Email (Email)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+-- AIRPLANES TABLE
+CREATE TABLE flugzeuge (
+ Id int(11) NOT NULL AUTO_INCREMENT,
+ Modell varchar(100) NOT NULL,
+ Plaetze int(11) NOT NULL,
+ Lagerflaeche float NOT NULL,
+ Gewicht float NOT NULL,
+ Kerosinverbrauch float NOT NULL,
+ Stundengeschwindigkeit float NOT NULL,
+ Stundenstand float NOT NULL,
+ Herstellungsdatum date NOT NULL,
+ IstDefekt tinyint(1) NOT NULL DEFAULT 0,
+ PRIMARY KEY (Id)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+-- PILOTS TABLE
+CREATE TABLE piloten (
+ Id int(11) NOT NULL AUTO_INCREMENT,
+ Vorname varchar(100) NOT NULL,
+ Nachname varchar(100) NOT NULL,
+ Flugerfahrung float NOT NULL,
+ Groesse float NOT NULL,
+ Bewertung float NOT NULL,
+ Pilotalter date NOT NULL,
+ Gender varchar(10) DEFAULT NULL,
+ IstVerfuegbar tinyint(1) NOT NULL DEFAULT 1,
+ Sprachen text DEFAULT NULL,
+ PRIMARY KEY (Id)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+-- FLIGHTS TABLE
+CREATE TABLE fluege (
+ Id int(11) NOT NULL AUTO_INCREMENT,
+ Abflugort varchar(100) NOT NULL,
+ Zielort varchar(100) NOT NULL,
+ Abflugdatum datetime NOT NULL,
+ Ankunftsdatum datetime NOT NULL,
+ Flugnummer varchar(20) NOT NULL,
+ Preis decimal(10,2) NOT NULL,
+ Created datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ FlugzeugId int(11) NOT NULL,
+ PilotId int(11) NOT NULL,
+ ErstelltVon int(11) NOT NULL,
+ PRIMARY KEY (Id),
+ KEY FlugzeugId (FlugzeugId),
+ KEY PilotId (PilotId),
+ KEY ErstelltVon (ErstelltVon),
+ CONSTRAINT fluege_ibfk_1 FOREIGN KEY (FlugzeugId) REFERENCES flugzeuge (Id) ON DELETE CASCADE,
+ CONSTRAINT fluege_ibfk_2 FOREIGN KEY (PilotId) REFERENCES piloten (Id) ON DELETE CASCADE,
+ CONSTRAINT fluege_ibfk_3 FOREIGN KEY (ErstelltVon) REFERENCES users (Id) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+-- BOOKINGS TABLE
+CREATE TABLE buchungen (
+ Id int(11) NOT NULL AUTO_INCREMENT,
+ UserId int(11) NOT NULL,
+ FlugId int(11) NOT NULL,
+ BuchungsDatum datetime DEFAULT CURRENT_TIMESTAMP,
+ Status varchar(50) DEFAULT 'Bestätigt',
+ PRIMARY KEY (Id),
+ KEY UserId (UserId),
+ KEY FlugId (FlugId),
+ CONSTRAINT buchungen_ibfk_1 FOREIGN KEY (UserId) REFERENCES users (Id) ON DELETE CASCADE,
+ CONSTRAINT buchungen_ibfk_2 FOREIGN KEY (FlugId) REFERENCES fluege (Id) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+-- ==========================================================
+-- 3. DATA INJECTION
+-- ==========================================================
+
+-- A. ADMIN ACCOUNT (ID 1)
+-- Credentials: admin@skyteam.com / admin
+-- Hash generated via BCrypt for "admin"
+INSERT INTO users (Id, Vorname, Nachname, Email, PasswortHash, Rolle, Stadt, Anrede, CreatedAt) VALUES
+(1, 'System', 'Admin', 'admin@skyteam.com', '$2a$11$s/l.wH4/vG.9TjF3.uz.CO4.d.z.y.t.x.w.v.u.s.r.q.p.o', 'Admin', 'Headquarters', 'Herr', NOW());
+
+-- B. PASSENGERS (Users)
+INSERT INTO users (Vorname, Nachname, Email, PasswortHash, Rolle, Stadt, Anrede, CreatedAt) VALUES
+('Lisa', 'Schmidt', 'lisa@test.com', '$2a$11$dummyhash', 'User', 'Hamburg', 'Frau', NOW()),
+('Tony', 'Stark', 'ironman@avengers.com', '$2a$11$dummyhash', 'User', 'Malibu', 'Herr', NOW()),
+('Peter', 'Parker', 'spidey@queens.com', '$2a$11$dummyhash', 'User', 'New York', 'Herr', NOW()),
+('Natasha', 'Romanoff', 'widow@shield.com', '$2a$11$dummyhash', 'User', 'Budapest', 'Frau', NOW()),
+('Bruce', 'Wayne', 'batman@gotham.com', '$2a$11$dummyhash', 'User', 'Gotham', 'Herr', NOW()),
+('Clark', 'Kent', 'superman@daily.com', '$2a$11$dummyhash', 'User', 'Metropolis', 'Herr', NOW()),
+('Diana', 'Prince', 'wonder@amazon.com', '$2a$11$dummyhash', 'User', 'Themyscira', 'Frau', NOW()),
+('Han', 'Solo', 'han@falcon.com', '$2a$11$dummyhash', 'User', 'Space', 'Herr', NOW()),
+('Luke', 'Skywalker', 'luke@jedi.com', '$2a$11$dummyhash', 'User', 'Tatooine', 'Herr', NOW()),
+('Leia', 'Organa', 'leia@rebel.com', '$2a$11$dummyhash', 'User', 'Alderaan', 'Frau', NOW());
+
+-- C. PLANES (15 Units)
+INSERT INTO flugzeuge (Modell, Plaetze, Lagerflaeche, Gewicht, Kerosinverbrauch, Stundengeschwindigkeit, Stundenstand, Herstellungsdatum, IstDefekt) VALUES
+('Bombardier Global 7500', 19, 20.5, 23000, 1100, 950, 450.5, '2021-03-15', 0),
+('Cessna Citation X', 12, 10.0, 16000, 950, 970, 1200.0, '2018-06-20', 0),
+('Gulfstream G650ER', 18, 18.5, 25000, 1200, 960, 800.2, '2020-01-10', 0),
+('Embraer Praetor 600', 12, 12.0, 14000, 850, 890, 300.0, '2022-11-05', 0),
+('Boeing 737-800', 189, 45.0, 41000, 2400, 840, 15000.5, '2015-08-12', 0),
+('Airbus A320neo', 180, 42.0, 42000, 2200, 840, 5000.0, '2019-04-22', 0),
+('Dassault Falcon 8X', 16, 15.0, 18000, 1050, 920, 650.0, '2021-09-30', 0),
+('Bombardier Challenger 350', 10, 8.5, 11000, 900, 870, 2100.0, '2017-02-14', 0),
+('HondaJet Elite', 6, 4.0, 4800, 450, 780, 150.0, '2023-01-01', 0),
+('Pilatus PC-24', 10, 6.0, 8000, 600, 815, 900.0, '2019-12-12', 0),
+('Boeing 787 Dreamliner', 290, 120.0, 115000, 4800, 903, 8000.0, '2016-07-04', 1),
+('Airbus A350-900', 325, 130.0, 135000, 5000, 910, 4500.0, '2018-10-20', 0),
+('Embraer Phenom 300', 9, 5.0, 8000, 550, 830, 2200.5, '2017-05-15', 0),
+('Learjet 75 Liberty', 8, 4.5, 7500, 600, 860, 1800.0, '2018-08-01', 0),
+('Beechcraft King Air 350', 11, 6.0, 6800, 400, 580, 5400.0, '2012-03-30', 0);
+
+-- D. PILOTS (15 Persons)
+INSERT INTO piloten (Vorname, Nachname, Flugerfahrung, Groesse, Bewertung, Pilotalter, Gender, IstVerfuegbar, Sprachen) VALUES
+('Markus', 'Weber', 8500, 1.82, 4.8, '1980-05-15', 'M', 1, 'Deutsch, Englisch'),
+('Julia', 'Müller', 4200, 1.70, 4.9, '1992-11-02', 'F', 1, 'Deutsch, Englisch, Französisch'),
+('James', 'Smith', 12000, 1.78, 5.0, '1975-03-22', 'M', 1, 'Englisch, Spanisch'),
+('Sophie', 'Dubois', 3500, 1.68, 4.5, '1995-07-14', 'F', 1, 'Französisch, Englisch'),
+('Alessandro', 'Rossi', 6000, 1.85, 4.7, '1988-09-09', 'M', 1, 'Italienisch, Englisch, Deutsch'),
+('Yuki', 'Tanaka', 5500, 1.72, 4.8, '1990-01-30', 'M', 1, 'Japanisch, Englisch'),
+('Sarah', 'Connor', 9800, 1.75, 5.0, '1982-08-12', 'F', 0, 'Englisch, Deutsch'),
+('Thomas', 'Schneider', 1500, 1.80, 4.2, '1998-04-05', 'M', 1, 'Deutsch, Englisch'),
+('Elena', 'Popova', 7200, 1.69, 4.6, '1985-12-25', 'F', 1, 'Russisch, Englisch, Deutsch'),
+('Carlos', 'Mendez', 11000, 1.76, 4.9, '1978-06-18', 'M', 1, 'Spanisch, Portugiesisch, Englisch'),
+('Emma', 'Wilson', 2900, 1.65, 4.4, '1996-02-14', 'F', 1, 'Englisch'),
+('Lukas', 'Hofer', 4800, 1.88, 4.7, '1991-10-31', 'M', 1, 'Deutsch, Italienisch'),
+('Anna', 'Kovalenko', 6500, 1.73, 4.8, '1987-03-08', 'F', 1, 'Ukrainisch, Englisch, Polnisch'),
+('David', 'Brown', 13500, 1.81, 5.0, '1970-11-20', 'M', 0, 'Englisch, Französisch'),
+('Maria', 'Garcia', 5100, 1.67, 4.6, '1993-05-05', 'F', 1, 'Spanisch, Englisch');
+
+-- E. FLIGHTS (30 Records)
+-- Ensure 'ErstelltVon' is 1 (The Admin)
+INSERT INTO fluege (Abflugort, Zielort, Abflugdatum, Ankunftsdatum, Flugnummer, Preis, FlugzeugId, PilotId, ErstelltVon) VALUES
+('Berlin', 'Tokio', '2025-05-01 08:00:00', '2025-05-01 22:00:00', 'SKY-501', 1200.00, 1, 1, 1),
+('München', 'Dubai', '2025-05-02 14:00:00', '2025-05-02 23:00:00', 'SKY-502', 850.50, 2, 2, 1),
+('Frankfurt', 'New York', '2025-06-10 10:00:00', '2025-06-10 18:00:00', 'SKY-503', 600.00, 3, 3, 1),
+('Hamburg', 'Mallorca', '2025-06-12 06:00:00', '2025-06-12 09:00:00', 'SKY-504', 150.00, 4, 4, 1),
+('London', 'Sydney', '2025-07-01 22:00:00', '2025-07-03 06:00:00', 'SKY-505', 2100.00, 5, 5, 1),
+('Paris', 'Berlin', '2025-07-05 09:00:00', '2025-07-05 10:30:00', 'SKY-506', 120.00, 6, 6, 1),
+('Madrid', 'Rom', '2025-07-10 11:00:00', '2025-07-10 13:30:00', 'SKY-507', 99.90, 7, 7, 1),
+('Lissabon', 'Berlin', '2025-08-01 15:00:00', '2025-08-01 19:00:00', 'SKY-508', 230.00, 8, 8, 1),
+('Wien', 'Zürich', '2025-08-05 08:30:00', '2025-08-05 09:45:00', 'SKY-509', 180.00, 9, 9, 1),
+('Amsterdam', 'Kapstadt', '2025-09-01 20:00:00', '2025-09-02 08:00:00', 'SKY-510', 950.00, 10, 10, 1),
+('Berlin', 'Istanbul', '2025-09-15 12:00:00', '2025-09-15 16:00:00', 'SKY-511', 300.00, 11, 11, 1),
+('Dubai', 'Singapur', '2025-10-01 02:00:00', '2025-10-01 10:00:00', 'SKY-512', 780.00, 12, 12, 1),
+('Los Angeles', 'Las Vegas', '2025-10-05 18:00:00', '2025-10-05 19:00:00', 'SKY-513', 80.00, 13, 13, 1),
+('Miami', 'Cancun', '2025-11-01 10:00:00', '2025-11-01 12:00:00', 'SKY-514', 250.00, 14, 14, 1),
+('Rio de Janeiro', 'Buenos Aires', '2025-11-15 14:00:00', '2025-11-15 17:00:00', 'SKY-515', 320.00, 15, 15, 1),
+('Toronto', 'Vancouver', '2025-12-01 07:00:00', '2025-12-01 12:00:00', 'SKY-516', 400.00, 1, 2, 1),
+('Paderborn', 'München', '2025-12-05 09:00:00', '2025-12-05 10:00:00', 'SKY-517', 150.00, 2, 3, 1),
+('Dortmund', 'Kattowitz', '2025-12-10 16:00:00', '2025-12-10 18:00:00', 'SKY-518', 60.00, 3, 4, 1),
+('Köln', 'London', '2026-01-01 10:00:00', '2026-01-01 11:30:00', 'SKY-519', 110.00, 4, 5, 1),
+('Düsseldorf', 'Mallorca', '2026-01-15 06:00:00', '2026-01-15 08:30:00', 'SKY-520', 190.00, 5, 6, 1),
+('Stuttgart', 'Berlin', '2026-02-01 08:00:00', '2026-02-01 09:15:00', 'SKY-521', 140.00, 6, 7, 1),
+('Hannover', 'Paris', '2026-02-14 14:00:00', '2026-02-14 16:00:00', 'SKY-522', 210.00, 7, 8, 1),
+('Nürnberg', 'Antalya', '2026-03-01 11:00:00', '2026-03-01 15:00:00', 'SKY-523', 250.00, 8, 9, 1),
+('Leipzig', 'Wien', '2026-03-15 09:00:00', '2026-03-15 10:30:00', 'SKY-524', 130.00, 9, 10, 1),
+('Bremen', 'Zürich', '2026-04-01 13:00:00', '2026-04-01 14:30:00', 'SKY-525', 175.00, 10, 11, 1),
+('Berlin', 'Bangkok', '2026-04-20 22:00:00', '2026-04-21 14:00:00', 'SKY-526', 900.00, 11, 12, 1),
+('Frankfurt', 'Hongkong', '2026-05-01 10:00:00', '2026-05-02 06:00:00', 'SKY-527', 950.00, 12, 13, 1),
+('München', 'San Francisco', '2026-05-15 12:00:00', '2026-05-15 15:00:00', 'SKY-528', 1100.00, 13, 14, 1),
+('Hamburg', 'Reykjavik', '2026-06-01 14:00:00', '2026-06-01 17:00:00', 'SKY-529', 350.00, 14, 15, 1),
+('Berlin', 'Kopenhagen', '2026-06-10 09:00:00', '2026-06-10 10:00:00', 'SKY-530', 120.00, 15, 1, 1);
+
+-- F. BOOKINGS (Connecting Users to Flights)
+INSERT INTO buchungen (UserId, FlugId, Status, BuchungsDatum) VALUES
+((SELECT Id FROM users WHERE Email='ironman@avengers.com'), (SELECT Id FROM fluege WHERE Flugnummer='SKY-501'), 'Bestätigt', NOW()),
+((SELECT Id FROM users WHERE Email='ironman@avengers.com'), (SELECT Id FROM fluege WHERE Flugnummer='SKY-528'), 'Bestätigt', NOW()),
+((SELECT Id FROM users WHERE Email='spidey@queens.com'), (SELECT Id FROM fluege WHERE Flugnummer='SKY-513'), 'Bestätigt', NOW()),
+((SELECT Id FROM users WHERE Email='batman@gotham.com'), (SELECT Id FROM fluege WHERE Flugnummer='SKY-527'), 'Bestätigt', NOW()),
+((SELECT Id FROM users WHERE Email='batman@gotham.com'), (SELECT Id FROM fluege WHERE Flugnummer='SKY-502'), 'Storniert', NOW()),
+((SELECT Id FROM users WHERE Email='lisa@test.com'), (SELECT Id FROM fluege WHERE Flugnummer='SKY-504'), 'Bestätigt', NOW()),
+((SELECT Id FROM users WHERE Email='han@falcon.com'), (SELECT Id FROM fluege WHERE Flugnummer='SKY-529'), 'Bestätigt', NOW());
+
+-- ==========================================================
+-- FINALIZATION
+-- ==========================================================
+SET FOREIGN_KEY_CHECKS = 1;
+COMMIT;
\ No newline at end of file
diff --git a/SkyTeam/mitarbeiterRepo.cs b/SkyTeam/mitarbeiterRepo.cs
index c799414..ac1273b 100644
--- a/SkyTeam/mitarbeiterRepo.cs
+++ b/SkyTeam/mitarbeiterRepo.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace SkyTeam
{
- class mitarbeiterRepo : databaseServices
+ class mitarbeiterRepo
{
diff --git a/SkyTeam/session.cs b/SkyTeam/session.cs
index 292a2f0..cbb0cb3 100644
--- a/SkyTeam/session.cs
+++ b/SkyTeam/session.cs
@@ -6,8 +6,10 @@ using System.Threading.Tasks;
namespace SkyTeam
{
- class session
+ static class SessionManager
{
- int selectedId { get; set; }
+ public static int CurrentUserId { get; set; }
+ public static string CurrentUserName { get; set; }
+ public static string Role { get; set; }
}
}
diff --git a/SkyTeam/verfuegbareFluge.xaml.cs b/SkyTeam/verfuegbareFluge.xaml.cs
index 63f5420..cb755ec 100644
--- a/SkyTeam/verfuegbareFluge.xaml.cs
+++ b/SkyTeam/verfuegbareFluge.xaml.cs
@@ -1,70 +1,72 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Data;
using System.Windows;
using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
+using MySql.Data.MySqlClient;
namespace SkyTeam
{
- ///
- /// Interaction logic for verfuegbareFluge.xaml
- ///
public partial class verfuegbareFluge : Page
{
public verfuegbareFluge()
{
InitializeComponent();
+ LoadFlights();
+ }
+
+ private void LoadFlights()
+ {
+ string query = @"SELECT f.Id, f.Flugnummer, f.Abflugort AS 'From', f.Zielort AS 'To',
+ z.Modell AS Plane, f.Abflugdatum AS Date
+ FROM fluege f
+ JOIN flugzeuge z ON f.FlugzeugId = z.Id";
+
+ using (MySqlConnection conn = new MySqlConnection(DatenbankServices.GetConnection()))
+ {
+ conn.Open();
+ MySqlDataAdapter adapter = new MySqlDataAdapter(query, conn);
+ DataTable dt = new DataTable();
+ adapter.Fill(dt);
+ AvailableFlightsDataGrid.ItemsSource = dt.DefaultView;
+ }
}
private void BookFlight_Click(object sender, RoutedEventArgs e)
{
- MessageBox.Show("Erfolgreich gebuchtt");
-
- ((MainWindow)Application.Current.MainWindow).MainFrame.Navigate(new BuchungenPage());
- }
- private void HomeButton_Click(object sender, RoutedEventArgs e)
- {
- ((MainWindow)Application.Current.MainWindow).MainFrame.Navigate(new NavigationPage());
- }
-
- private void BookingsButton_Click(object sender, RoutedEventArgs e)
- {
- ((MainWindow)Application.Current.MainWindow).MainFrame.Navigate(new BuchungenPage());
- }
-
- private void SettingsButton_Click(object sender, RoutedEventArgs e)
- {
- ((MainWindow)Application.Current.MainWindow).MainFrame.Navigate(new SettingsPage());
- }
-
- private void BookFlightButton_Click(object sender, RoutedEventArgs e)
- {
- ((MainWindow)Application.Current.MainWindow).MainFrame.Navigate(new BuchungenPage());
- }
- private void LogoutButton_Click(object sender, RoutedEventArgs e)
- {
- var result = MessageBox.Show(
- "Möchten Sie sich wirklich abmelden?",
- "Abmelden",
- MessageBoxButton.YesNo,
- MessageBoxImage.Question);
- if (result == MessageBoxResult.Yes)
+ if (AvailableFlightsDataGrid.SelectedItem == null)
{
- ((MainWindow)Application.Current.MainWindow).MainFrame.Navigate(new LogInPage());
+ MessageBox.Show("Bitte wählen Sie einen Flug aus!");
+ return;
}
+ DataRowView row = (DataRowView)AvailableFlightsDataGrid.SelectedItem;
+ int flightId = Convert.ToInt32(row["Id"]);
+ string query = "INSERT INTO buchungen (UserId, FlugId) VALUES (@uid, @fid)";
+ try
+ {
+ using (MySqlConnection conn = new MySqlConnection(DatenbankServices.GetConnection()))
+ {
+ conn.Open();
+ MySqlCommand cmd = new MySqlCommand(query, conn);
+ cmd.Parameters.AddWithValue("@uid",SessionManager.CurrentUserId);
+ cmd.Parameters.AddWithValue("@fid", flightId);
+ cmd.ExecuteNonQuery();
+ }
+
+ MessageBox.Show("Erfolgreich gebucht!");
+ ((MainWindow)Application.Current.MainWindow).MainFrame.Navigate(new BuchungenPage());
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("Fehler: " + ex.Message);
+ }
}
+ 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 SettingsButton_Click(object sender, RoutedEventArgs e) => NavigationService.Navigate(new SettingsPage());
+ private void LogoutButton_Click(object sender, RoutedEventArgs e) => NavigationService.Navigate(new LogInPage());
}
-}
+}
\ No newline at end of file