using PP_Ven_MosS.Classes;
using PP_Ven_MosS.ModelBase;
using PP_Ven_MosS.Pages;
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 PP_Ven_MosS
{
///
/// Логика взаимодействия для ApplicationsListUser.xaml
///
public partial class ApplicationsListUser : Page
{
public ApplicationsListUser()
{
InitializeComponent();
ApplicationList.ItemsSource = Classes.Database.entities.Applications.Where(x => x.Id_user == UserID.userid).ToList();
CB_Filter_app.ItemsSource = new List { "Фильтр по статусу", "Выполнен", "Не выполнен" };
CB_Sort_app.ItemsSource = new List() { "Фильтр по дате", "Не сегодня", "Сегодня" };
CB_Sort_app.SelectedIndex = 0;
CB_Filter_app.SelectedIndex = 0;
CB_Filter_event.ItemsSource = new List() { "Фильтр по статусу", "Проведено", "Не проведено" };
CB_Sort_event.ItemsSource = new List() { "Фильтр по дате", "Не сегодня", "Сегодня" };
CB_Sort_event.SelectedIndex = 0;
CB_Filter_event.SelectedIndex = 0;
}
private void CreateApp_Click(object sender, RoutedEventArgs e)
{
FrameClass.MainFrame.Navigate(new CreateApplication());
}
private void CreateEv_Click(object sender, RoutedEventArgs e)
{
FrameClass.MainFrame.Navigate(new CreateEvent());
}
private void Exit_Click(object sender, RoutedEventArgs e)
{
FrameClass.MainFrame.Navigate(new Avtorization());
}
private void Filter()
{
List applications = Classes.Database.entities.Applications.Where(x => x.Id_user == UserID.userid).ToList();
if (CB_Sort_app.SelectedIndex != 0)
{
switch (CB_Sort_app.SelectedIndex)
{
case 1:
applications = applications.Where(x => x.Date_app < DateTime.Today).OrderBy(x => x.Date_app).ToList();
break;
case 2:
applications = applications.Where(x => x.Date_app == DateTime.Today).OrderBy(x => x.Date_app).ToList();
break;
}
}
if (CB_Filter_app.SelectedIndex != 0)
{
switch (CB_Filter_app.SelectedIndex)
{
case 1:
applications = applications.Where(x => x.Id_status_app == 1).ToList();
break;
case 2:
applications = applications.Where(x => x.Id_status_app == 2).ToList();
break;
}
}
if (!string.IsNullOrEmpty(TB_Search_app.Text))
{
applications = applications.Where(x => x.Description.ToUpper().Contains(TB_Search_app.Text.ToUpper())).ToList();
}
ApplicationList.ItemsSource = applications;
//Мероприятия
List events = Database.entities.Event.ToList();
if (CB_Sort_event.SelectedIndex != 0)
{
switch (CB_Sort_event.SelectedIndex)
{
case 1:
events = events.Where(x => x.Date_event < DateTime.Today).OrderBy(x => x.Date_event).ToList();
break;
case 2:
events = events.Where(x => x.Date_event == DateTime.Today).OrderBy(x => x.Date_event).ToList();
break;
}
}
if (CB_Filter_event.SelectedIndex != 0)
{
switch (CB_Filter_event.SelectedIndex)
{
case 1:
events = events.Where(x => x.Id_status_event == 1).ToList();
break;
case 2:
events = events.Where(x => x.Id_status_event == 2).ToList();
break;
}
}
if (!string.IsNullOrEmpty(TB_Search_event.Text))
{
events = events.Where(x => x.Title_event.ToUpper().Contains(TB_Search_event.Text.ToUpper())).ToList();
}
EventList.ItemsSource = events;
}
private void SortFilterChanged(object sender, SelectionChangedEventArgs e)
{
Filter();
}
private void SearchChanged(object sender, TextChangedEventArgs e)
{
Filter();
}
private void TB_Search_event_TextChanged(object sender, TextChangedEventArgs e)
{
Filter();
}
private void CB_Sort_event_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Filter();
}
private void CB_Filter_event_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Filter();
}
}
}