buechermarkt/BuechermarktClient/MainWindow.xaml.cs

111 lines
3.0 KiB
C#
Raw Normal View History

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
{
/// <summary>
/// Interaktionslogik für MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public static MongoClient Mongo;
public static IMongoDatabase Database;
public static IMongoCollection<BookType> BookTypeCollection;
public static IMongoCollection<Book> BookCollection;
public static IMongoCollection<Student> 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<BookType>("booktypes");
BookCollection = Database.GetCollection<Book>("books");
StudentCollection = Database.GetCollection<Student>("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;
}
}
}