2017-05-16 01:04:42 +00:00
|
|
|
|
using BuechermarktClient.Models;
|
|
|
|
|
using MongoDB.Driver;
|
2017-06-27 19:54:13 +00:00
|
|
|
|
using System;
|
2017-05-16 01:04:42 +00:00
|
|
|
|
using System.ComponentModel;
|
2017-06-27 19:54:13 +00:00
|
|
|
|
using System.Threading;
|
2017-05-16 01:04:42 +00:00
|
|
|
|
using System.Windows;
|
|
|
|
|
|
|
|
|
|
namespace BuechermarktClient
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaktionslogik für BookTypesEdit.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class StudentsEdit : Window, INotifyPropertyChanged
|
|
|
|
|
{
|
|
|
|
|
private bool New = false;
|
|
|
|
|
private Student Student = null;
|
|
|
|
|
public string Forname
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Student.Forname;
|
|
|
|
|
}
|
|
|
|
|
set {
|
|
|
|
|
if(value != Student.Forname)
|
|
|
|
|
{
|
|
|
|
|
Student.Forname = value;
|
|
|
|
|
OnPropertyChanged("Forname");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Lastname
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Student.Lastname;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != Student.Lastname)
|
|
|
|
|
{
|
|
|
|
|
Student.Lastname = value;
|
|
|
|
|
OnPropertyChanged("Lastname");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string EMail
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Student.EMail;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != Student.EMail)
|
|
|
|
|
{
|
|
|
|
|
Student.EMail = value;
|
|
|
|
|
OnPropertyChanged("EMail");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string PhoneNumber
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Student.PhoneNumber;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != Student.PhoneNumber)
|
|
|
|
|
{
|
|
|
|
|
Student.PhoneNumber = value;
|
|
|
|
|
OnPropertyChanged("PhoneNumber");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-28 20:01:27 +00:00
|
|
|
|
public string ID
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Student.ID.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-16 01:04:42 +00:00
|
|
|
|
public string LabelId
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Student.LabelId;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != Student.LabelId)
|
|
|
|
|
{
|
|
|
|
|
Student.LabelId = value;
|
|
|
|
|
OnPropertyChanged("LabelId");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Form
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Student.Form;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != Student.Form)
|
|
|
|
|
{
|
|
|
|
|
Student.Form = value;
|
|
|
|
|
OnPropertyChanged("Form");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
|
protected void OnPropertyChanged(string propertyName)
|
|
|
|
|
{
|
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public StudentsEdit(Student student)
|
|
|
|
|
{
|
|
|
|
|
DataContext = this;
|
|
|
|
|
if(student == null)
|
|
|
|
|
{
|
|
|
|
|
Student = new Student();
|
|
|
|
|
New = true;
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
Student = student;
|
|
|
|
|
}
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Save_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2017-06-27 19:54:13 +00:00
|
|
|
|
while (true)
|
2017-05-16 01:04:42 +00:00
|
|
|
|
{
|
2017-06-27 19:54:13 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (New)
|
|
|
|
|
{
|
|
|
|
|
MainWindow.StudentCollection.InsertOne(Student);
|
|
|
|
|
Student = new Student();
|
|
|
|
|
Forname = "";
|
|
|
|
|
Lastname = "";
|
|
|
|
|
EMail = "";
|
|
|
|
|
PhoneNumber = "";
|
|
|
|
|
LabelId = "";
|
|
|
|
|
Form = "";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MainWindow.StudentCollection.FindOneAndUpdate(s => s.ID == Student.ID, Builders<Student>.Update
|
|
|
|
|
.Set(s => s.Forname, Student.Forname)
|
|
|
|
|
.Set(s => s.Lastname, Student.Lastname)
|
|
|
|
|
.Set(s => s.EMail, Student.EMail)
|
|
|
|
|
.Set(s => s.PhoneNumber, Student.PhoneNumber)
|
|
|
|
|
.Set(s => s.LabelId, Student.LabelId)
|
|
|
|
|
.Set(s => s.Form, Student.Form));
|
2017-05-18 10:57:50 +00:00
|
|
|
|
|
2017-06-27 19:54:13 +00:00
|
|
|
|
Close();
|
|
|
|
|
}
|
2017-06-27 19:59:20 +00:00
|
|
|
|
return;
|
|
|
|
|
} catch (MongoExecutionTimeoutException)
|
2017-06-27 19:54:13 +00:00
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(100);
|
|
|
|
|
}
|
2017-05-16 01:04:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Delete_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2017-06-27 19:54:13 +00:00
|
|
|
|
while (true)
|
2017-05-16 01:04:42 +00:00
|
|
|
|
{
|
2017-06-27 19:54:13 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (Student.ID != null)
|
|
|
|
|
{
|
|
|
|
|
MainWindow.StudentCollection.DeleteOne(bt => bt.ID == Student.ID);
|
|
|
|
|
}
|
|
|
|
|
Close();
|
2017-06-27 19:59:20 +00:00
|
|
|
|
return;
|
2017-06-27 19:54:13 +00:00
|
|
|
|
}
|
2017-06-27 19:59:20 +00:00
|
|
|
|
catch (MongoExecutionTimeoutException)
|
2017-06-27 19:54:13 +00:00
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(100);
|
|
|
|
|
}
|
2017-05-16 01:04:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|