2017-05-16 01:04:42 +00:00
|
|
|
|
using BuechermarktClient.Models;
|
|
|
|
|
using MongoDB.Driver;
|
2017-06-27 19:54:13 +00:00
|
|
|
|
using MongoDB.Driver.Core.Clusters;
|
2017-05-16 01:04:42 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-05-21 14:23:59 +00:00
|
|
|
|
using System.Diagnostics;
|
2017-05-16 01:04:42 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2017-05-18 10:57:50 +00:00
|
|
|
|
using System.Threading;
|
2017-05-16 01:04:42 +00:00
|
|
|
|
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;
|
2017-05-21 14:23:59 +00:00
|
|
|
|
public const string DatabaseName = "buechermarkt";
|
2017-05-18 10:57:50 +00:00
|
|
|
|
public static string MongoHost = "localhost";
|
2017-06-27 19:54:13 +00:00
|
|
|
|
public static IMongoCollection<BookType> BookTypeCollection
|
|
|
|
|
{
|
|
|
|
|
get {
|
|
|
|
|
var database = Mongo.GetDatabase(DatabaseName);
|
|
|
|
|
return database.GetCollection<BookType>("booktypes");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static IMongoCollection<Book> BookCollection
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var database = Mongo.GetDatabase(DatabaseName);
|
|
|
|
|
return database.GetCollection<Book>("books");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static IMongoCollection<Student> StudentCollection
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var database = Mongo.GetDatabase(DatabaseName);
|
|
|
|
|
return database.GetCollection<Student>("students");
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-16 01:04:42 +00:00
|
|
|
|
|
|
|
|
|
public BookTypes BookTypesWindow = null;
|
|
|
|
|
public Students StudentsWindow = null;
|
2017-05-18 10:57:50 +00:00
|
|
|
|
public Books BooksWindow = null;
|
2017-05-16 01:04:42 +00:00
|
|
|
|
|
|
|
|
|
public MainWindow()
|
|
|
|
|
{
|
2017-05-21 14:23:59 +00:00
|
|
|
|
var s = new GetConnection();
|
|
|
|
|
s.ShowDialog();
|
2017-05-16 01:04:42 +00:00
|
|
|
|
InitializeComponent();
|
2017-05-21 14:23:59 +00:00
|
|
|
|
OnConnectionEstablised();
|
2017-05-16 01:04:42 +00:00
|
|
|
|
//ToDo get server informations
|
2017-05-18 10:57:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-27 19:54:13 +00:00
|
|
|
|
public void ConnectionTester()
|
|
|
|
|
{
|
|
|
|
|
Mongo.Cluster.DescriptionChanged += (object sender, ClusterDescriptionChangedEventArgs e) =>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-21 14:23:59 +00:00
|
|
|
|
public void OnConnectionEstablised()
|
2017-05-18 10:57:50 +00:00
|
|
|
|
{
|
|
|
|
|
Mongo = new MongoClient("mongodb://" + MongoHost + ":27017");
|
2017-06-27 19:54:13 +00:00
|
|
|
|
//Database = Mongo.GetDatabase(DatabaseName);
|
|
|
|
|
//BookTypeCollection =
|
|
|
|
|
//BookCollection = Database.GetCollection<Book>("books");
|
|
|
|
|
//StudentCollection = Database.GetCollection<Student>("students");
|
2017-05-18 10:57:50 +00:00
|
|
|
|
|
|
|
|
|
var t = new Thread(BackupService);
|
|
|
|
|
t.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BackupService()
|
|
|
|
|
{
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
Backup.MakeBackup();
|
2017-06-27 19:54:13 +00:00
|
|
|
|
Thread.Sleep(120000);
|
2017-05-18 10:57:50 +00:00
|
|
|
|
}
|
2017-05-16 01:04:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2017-05-18 10:57:50 +00:00
|
|
|
|
|
|
|
|
|
private void Books_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (BooksWindow == null)
|
|
|
|
|
{
|
|
|
|
|
BooksWindow = new Books()
|
|
|
|
|
{
|
|
|
|
|
Owner = this
|
|
|
|
|
};
|
|
|
|
|
BooksWindow.Show();
|
|
|
|
|
BooksWindow.Closed += BooksWindow_Closes;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
BringWindowOnTop(BooksWindow);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BooksWindow_Closes(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
BooksWindow = null;
|
|
|
|
|
}
|
2017-05-16 01:04:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|