84 lines
3.4 KiB
C#
84 lines
3.4 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using MySql.Data.MySqlClient;
|
|
|
|
namespace SkyTeam
|
|
{
|
|
public partial class BuchungenPage : Page
|
|
{
|
|
public BuchungenPage()
|
|
{
|
|
InitializeComponent();
|
|
LoadBookings();
|
|
}
|
|
|
|
private void LoadBookings()
|
|
{
|
|
if (SessionManager.CurrentUserId == 0) return;
|
|
|
|
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";
|
|
|
|
try
|
|
{
|
|
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 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());
|
|
}
|
|
} |