CineBook Projekt hinzugefügt
This commit is contained in:
87
Views/ScreeningEditDialog.xaml.cs
Normal file
87
Views/ScreeningEditDialog.xaml.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using CineBook.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace CineBook.Views;
|
||||
|
||||
public partial class ScreeningEditDialog : Window
|
||||
{
|
||||
public Screening? Result { get; private set; }
|
||||
private readonly List<Movie> _movies;
|
||||
private readonly Screening? _edit;
|
||||
|
||||
public ScreeningEditDialog(List<Movie> movies, Screening? edit = null)
|
||||
{
|
||||
InitializeComponent();
|
||||
_movies = movies;
|
||||
_edit = edit;
|
||||
|
||||
foreach (var m in movies)
|
||||
MovieBox.Items.Add(new ComboBoxItem { Content = m.Title, Tag = m.MovieID, Foreground = System.Windows.Media.Brushes.Gold, FontFamily = new System.Windows.Media.FontFamily("Courier New") });
|
||||
|
||||
if (MovieBox.Items.Count > 0) MovieBox.SelectedIndex = 0;
|
||||
HallBox.SelectedIndex = 0;
|
||||
DatePicker.SelectedDate = DateTime.Today.AddDays(1);
|
||||
|
||||
if (_edit != null)
|
||||
{
|
||||
Title = "Vorführung bearbeiten";
|
||||
// Film vorauswählen
|
||||
for (var i = 0; i < MovieBox.Items.Count; i++)
|
||||
{
|
||||
if (MovieBox.Items[i] is ComboBoxItem ci && (int)ci.Tag == _edit.MovieID)
|
||||
{
|
||||
MovieBox.SelectedIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
DatePicker.SelectedDate = _edit.ScreeningDate;
|
||||
TimeBox.Text = _edit.StartTime.ToString(@"hh\:mm");
|
||||
|
||||
// Hall vorauswählen
|
||||
for (var i = 0; i < HallBox.Items.Count; i++)
|
||||
{
|
||||
if (HallBox.Items[i] is ComboBoxItem hi && (hi.Content?.ToString() ?? "") == _edit.Hall)
|
||||
{
|
||||
HallBox.SelectedIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PriceBox.Text = _edit.PricePerSeat.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (MovieBox.SelectedItem is not ComboBoxItem mi) { ErrorText.Text = "⚠ Film auswählen!"; return; }
|
||||
if (DatePicker.SelectedDate == null) { ErrorText.Text = "⚠ Datum auswählen!"; return; }
|
||||
if (!TimeSpan.TryParse(TimeBox.Text, out var time)) { ErrorText.Text = "⚠ Uhrzeit ungültig (HH:MM)!"; return; }
|
||||
if (HallBox.SelectedItem is not ComboBoxItem hi) { ErrorText.Text = "⚠ Saal auswählen!"; return; }
|
||||
if (!decimal.TryParse(PriceBox.Text.Replace(',', '.'),
|
||||
System.Globalization.NumberStyles.Any,
|
||||
System.Globalization.CultureInfo.InvariantCulture, out var price) || price <= 0)
|
||||
{ ErrorText.Text = "⚠ Ungültiger Preis!"; return; }
|
||||
|
||||
Result = new Screening
|
||||
{
|
||||
ScreeningID = _edit?.ScreeningID ?? 0,
|
||||
MovieID = (int)mi.Tag,
|
||||
ScreeningDate = DatePicker.SelectedDate.Value,
|
||||
StartTime = time,
|
||||
Hall = hi.Content?.ToString() ?? "Saal 1",
|
||||
// Seats werden beim Anlegen im Repository automatisch erzeugt.
|
||||
// Beim Bearbeiten werden TotalSeats/AvailableSeats nicht verändert (damit Buchungen konsistent bleiben).
|
||||
TotalSeats = _edit?.TotalSeats ?? 80,
|
||||
AvailableSeats = _edit?.AvailableSeats ?? 80,
|
||||
PricePerSeat = price
|
||||
};
|
||||
DialogResult = true;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void CancelClick(object sender, RoutedEventArgs e) { DialogResult = false; Close(); }
|
||||
}
|
||||
Reference in New Issue
Block a user