fix von viel errors in GUI und logik dahinter
This commit is contained in:
@@ -2,15 +2,25 @@
|
||||
using System.Data;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Navigation;
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
namespace SkyTeam
|
||||
{
|
||||
public partial class verfuegbareFluge : Page
|
||||
{
|
||||
public verfuegbareFluge()
|
||||
private string _fromCity;
|
||||
private string _toCity;
|
||||
private DateTime? _flightDate;
|
||||
|
||||
public verfuegbareFluge(string from = "", string to = "", DateTime? date = null)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_fromCity = from;
|
||||
_toCity = to;
|
||||
_flightDate = date;
|
||||
|
||||
LoadFlights();
|
||||
}
|
||||
|
||||
@@ -19,15 +29,52 @@ namespace SkyTeam
|
||||
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";
|
||||
JOIN flugzeuge z ON f.FlugzeugId = z.Id
|
||||
WHERE 1=1";
|
||||
|
||||
using (MySqlConnection conn = new MySqlConnection(DatenbankServices.GetConnection()))
|
||||
if (!string.IsNullOrWhiteSpace(_fromCity))
|
||||
{
|
||||
conn.Open();
|
||||
MySqlDataAdapter adapter = new MySqlDataAdapter(query, conn);
|
||||
DataTable dt = new DataTable();
|
||||
adapter.Fill(dt);
|
||||
AvailableFlightsDataGrid.ItemsSource = dt.DefaultView;
|
||||
query += " AND f.Abflugort LIKE @from";
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(_toCity))
|
||||
{
|
||||
query += " AND f.Zielort LIKE @to";
|
||||
}
|
||||
if (_flightDate.HasValue)
|
||||
{
|
||||
query += " AND DATE(f.Abflugdatum) = @date";
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using (MySqlConnection conn = new MySqlConnection(DatenbankServices.GetConnection()))
|
||||
{
|
||||
conn.Open();
|
||||
MySqlCommand cmd = new MySqlCommand(query, conn);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(_fromCity))
|
||||
cmd.Parameters.AddWithValue("@from", "%" + _fromCity + "%");
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(_toCity))
|
||||
cmd.Parameters.AddWithValue("@to", "%" + _toCity + "%");
|
||||
|
||||
if (_flightDate.HasValue)
|
||||
cmd.Parameters.AddWithValue("@date", _flightDate.Value.ToString("yyyy-MM-dd"));
|
||||
|
||||
MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
|
||||
DataTable dt = new DataTable();
|
||||
adapter.Fill(dt);
|
||||
AvailableFlightsDataGrid.ItemsSource = dt.DefaultView;
|
||||
|
||||
if (dt.Rows.Count == 0)
|
||||
{
|
||||
MessageBox.Show("Keine Flüge gefunden.");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Fehler beim Laden: " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +89,12 @@ namespace SkyTeam
|
||||
DataRowView row = (DataRowView)AvailableFlightsDataGrid.SelectedItem;
|
||||
int flightId = Convert.ToInt32(row["Id"]);
|
||||
|
||||
if (SessionManager.CurrentUserId == 0)
|
||||
{
|
||||
MessageBox.Show("Fehler: Nicht eingeloggt.");
|
||||
return;
|
||||
}
|
||||
|
||||
string query = "INSERT INTO buchungen (UserId, FlugId) VALUES (@uid, @fid)";
|
||||
|
||||
try
|
||||
@@ -50,13 +103,13 @@ namespace SkyTeam
|
||||
{
|
||||
conn.Open();
|
||||
MySqlCommand cmd = new MySqlCommand(query, conn);
|
||||
cmd.Parameters.AddWithValue("@uid",SessionManager.CurrentUserId);
|
||||
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());
|
||||
NavigationService.Navigate(new BuchungenPage());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user