using BuechermarktClient.Models; using MongoDB.Driver; 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; namespace BuechermarktClient { /// /// Interaktionslogik für MainWindow.xaml /// public partial class MainWindow : Window { public static MongoClient Mongo; public static IMongoDatabase Database; public static IMongoCollection BookTypeCollection; public static IMongoCollection BookCollection; public static IMongoCollection StudentCollection; public BookTypes BookTypesWindow = null; public Students StudentsWindow = null; public MainWindow() { InitializeComponent(); //ToDo get server informations Mongo = new MongoClient("mongodb://localhost:27017"); Database = Mongo.GetDatabase("buechermarkt"); BookTypeCollection = Database.GetCollection("booktypes"); BookCollection = Database.GetCollection("books"); StudentCollection = Database.GetCollection("students"); } private void Window_Loaded(object sender, RoutedEventArgs e) { } private void BookTypes_Click(object sender, RoutedEventArgs e) { if(BookTypesWindow == null) { BookTypesWindow = new BookTypes() { Owner = this }; BookTypesWindow.Show(); BookTypesWindow.Closed += BookTypesWindow_Closed; } else { BringWindowOnTop(BookTypesWindow); } } private void BookTypesWindow_Closed(object sender, EventArgs e) { BookTypesWindow = null; } private void BringWindowOnTop(Window window) { if (!window.IsVisible) { window.Show(); } if (window.WindowState == WindowState.Minimized) { window.WindowState = WindowState.Normal; } window.Activate(); window.Topmost = true; // important window.Topmost = false; // important window.Focus(); // important } private void Students_Click(object sender, RoutedEventArgs e) { if (StudentsWindow == null) { StudentsWindow = new Students() { Owner = this }; StudentsWindow.Show(); StudentsWindow.Closed += StudentsWindow_Closed; } else { BringWindowOnTop(StudentsWindow); } } private void StudentsWindow_Closed(object sender, EventArgs e) { StudentsWindow = null; } } }