CineBook Projekt hinzugefügt
This commit is contained in:
96
Views/MainWindow.xaml.cs
Normal file
96
Views/MainWindow.xaml.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using CineBook.Data;
|
||||
using CineBook.Helpers;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace CineBook.Views;
|
||||
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private readonly Repository _repo;
|
||||
private Button? _activeNavBtn;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
if (!Session.IsLoggedIn)
|
||||
{
|
||||
// Schutz gegen NullReference, falls MainWindow direkt gestartet wird.
|
||||
new LoginWindow().Show();
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
var cs = DbConfig.GetConnectionString();
|
||||
if (string.IsNullOrWhiteSpace(cs))
|
||||
{
|
||||
MessageBox.Show(
|
||||
"DB-Verbindung nicht konfiguriert. Bitte setze 'CINEBOOK_CONNECTION_STRING'.",
|
||||
"Konfiguration fehlt",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
new LoginWindow().Show();
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
var db = new Db(cs);
|
||||
_repo = new Repository(db);
|
||||
|
||||
UserInfoText.Text = $"[ {Session.CurrentUser!.Username.ToUpper()} | {Session.CurrentUser!.Role.ToUpper()} ]";
|
||||
|
||||
if (Session.IsAdmin)
|
||||
BtnAdmin.Visibility = Visibility.Visible;
|
||||
|
||||
SetStats();
|
||||
Navigate("movies", BtnMovies);
|
||||
}
|
||||
|
||||
private void NavClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is Button btn)
|
||||
Navigate(btn.Tag?.ToString() ?? "movies", btn);
|
||||
}
|
||||
|
||||
private void Navigate(string view, Button btn)
|
||||
{
|
||||
if (_activeNavBtn != null)
|
||||
_activeNavBtn.Style = (Style)Resources["NavButton"];
|
||||
btn.Style = (Style)Resources["NavButtonActive"];
|
||||
_activeNavBtn = btn;
|
||||
|
||||
MainContent.Content = view switch
|
||||
{
|
||||
"movies" => new MovieListView(_repo),
|
||||
"screenings" => new ScreeningsView(_repo),
|
||||
"bookings" => new BookingsView(_repo, Session.CurrentUser!),
|
||||
"admin" => new AdminPanelView(_repo),
|
||||
"mine" => new MyBookingsView(_repo, Session.CurrentUser!),
|
||||
_ => new MovieListView(_repo)
|
||||
};
|
||||
}
|
||||
|
||||
private void LogoutClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Session.Logout();
|
||||
new LoginWindow().Show();
|
||||
Close();
|
||||
}
|
||||
|
||||
private void SetStats()
|
||||
{
|
||||
try
|
||||
{
|
||||
var (movies, screenings, bookings, users) = _repo.GetStats();
|
||||
StatsText.Text = $"Filme: {movies} | Vorführungen: {screenings} | Buchungen: {bookings} | Benutzer: {users}";
|
||||
DbStatusText.Text = "● DB VERBUNDEN";
|
||||
DbStatusText.Foreground = System.Windows.Media.Brushes.LimeGreen;
|
||||
}
|
||||
catch
|
||||
{
|
||||
DbStatusText.Text = "● DB NICHT ERREICHBAR";
|
||||
DbStatusText.Foreground = System.Windows.Media.Brushes.Red;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user