2017-05-16 01:04:42 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using BuechermarktClient.Models;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using MongoDB.Driver;
|
2017-05-18 10:57:50 +00:00
|
|
|
|
using System.Collections.Generic;
|
2017-05-16 01:04:42 +00:00
|
|
|
|
|
|
|
|
|
namespace BuechermarktClient
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaktionslogik für Students.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class Students : Window
|
|
|
|
|
{
|
|
|
|
|
public Thread RefreshThread = null;
|
|
|
|
|
private bool ThreadRunning = true;
|
|
|
|
|
|
2017-05-18 10:57:50 +00:00
|
|
|
|
|
|
|
|
|
public bool Chooser = false;
|
|
|
|
|
|
|
|
|
|
private string _SearchField;
|
|
|
|
|
public string SearchField
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _SearchField;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != _SearchField)
|
|
|
|
|
{
|
|
|
|
|
_SearchField = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Student SelectedItem { get; private set; }
|
|
|
|
|
|
|
|
|
|
public Students() : this(false){ }
|
|
|
|
|
|
|
|
|
|
public Students(bool select)
|
2017-05-16 01:04:42 +00:00
|
|
|
|
{
|
2017-05-18 10:57:50 +00:00
|
|
|
|
DataContext = this;
|
|
|
|
|
Chooser = select;
|
2017-05-16 01:04:42 +00:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
RefreshThread = new Thread(RefreshThreadS);
|
|
|
|
|
RefreshThread.Start();
|
|
|
|
|
RefreshThread.IsBackground = true;
|
|
|
|
|
Closing += Students_Closing;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void Students_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ThreadRunning = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RefreshThreadS()
|
|
|
|
|
{
|
|
|
|
|
while (ThreadRunning)
|
|
|
|
|
{
|
|
|
|
|
LoadList();
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadList()
|
|
|
|
|
{
|
2017-06-27 19:54:13 +00:00
|
|
|
|
List<Models.Student> list = null;
|
|
|
|
|
var not = true;
|
|
|
|
|
while (not)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
list = MainWindow.StudentCollection.FindSync((b) => true).ToList();
|
|
|
|
|
not = false;
|
|
|
|
|
}
|
2017-06-27 19:59:20 +00:00
|
|
|
|
catch (MongoExecutionTimeoutException)
|
2017-06-27 19:54:13 +00:00
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(200);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-18 10:57:50 +00:00
|
|
|
|
var show = new List<Student>();
|
|
|
|
|
if (SearchField != null && SearchField != String.Empty)
|
|
|
|
|
{
|
2017-06-27 19:59:20 +00:00
|
|
|
|
if(SearchField == "%d%")
|
2017-05-18 10:57:50 +00:00
|
|
|
|
{
|
2017-06-27 19:59:20 +00:00
|
|
|
|
foreach (var e in list)
|
2017-05-18 10:57:50 +00:00
|
|
|
|
{
|
2017-06-27 19:59:20 +00:00
|
|
|
|
foreach (var e2 in list)
|
|
|
|
|
{
|
|
|
|
|
if (e.ID == e2.ID) continue;
|
|
|
|
|
if (e.LabelId == e2.LabelId) show.Add(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
foreach (var e in list)
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
if (e.Forname.ToLower().Contains(SearchField.ToLower()) || e.Lastname.ToLower().Contains(SearchField.ToLower()) || e.EMail.ToLower().Contains(SearchField.ToLower()) || e.Form.ToLower().Contains(SearchField.ToLower()) || e.LabelId.ToLower().Contains(SearchField.ToLower()))
|
|
|
|
|
{
|
|
|
|
|
show.Add(e);
|
|
|
|
|
}
|
2017-05-18 10:57:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
show = list;
|
|
|
|
|
}
|
2017-05-16 01:04:42 +00:00
|
|
|
|
Dispatcher.BeginInvoke(new Action(delegate () {
|
2017-05-18 10:57:50 +00:00
|
|
|
|
ViewList.ItemsSource = show;
|
2017-05-16 01:04:42 +00:00
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddNew_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var editWindow = new StudentsEdit(null)
|
|
|
|
|
{
|
|
|
|
|
Owner = this
|
|
|
|
|
};
|
|
|
|
|
editWindow.Show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ListViewItem_PreviewMouseUp(object sender, MouseButtonEventArgs e)
|
|
|
|
|
{
|
2017-05-18 10:57:50 +00:00
|
|
|
|
if (sender is ListViewItem item && item.IsSelected)
|
2017-05-16 01:04:42 +00:00
|
|
|
|
{
|
2017-05-18 10:57:50 +00:00
|
|
|
|
SelectedItem = item.DataContext as Student;
|
|
|
|
|
if (Chooser)
|
|
|
|
|
{
|
|
|
|
|
DialogResult = true;
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
else
|
2017-05-16 01:04:42 +00:00
|
|
|
|
{
|
2017-05-18 10:57:50 +00:00
|
|
|
|
var editWindow = new StudentsEdit(item.DataContext as Student)
|
|
|
|
|
{
|
|
|
|
|
Owner = this
|
|
|
|
|
};
|
|
|
|
|
editWindow.Show();
|
|
|
|
|
}
|
2017-05-16 01:04:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-27 19:54:13 +00:00
|
|
|
|
|
|
|
|
|
private void Search_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadList();
|
|
|
|
|
}
|
2017-05-16 01:04:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|