using PP_Ven_MosS.Classes;
using PP_Ven_MosS.ModelBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
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.Pages
{
///
/// Логика взаимодействия для MenuAdmin.xaml
///
public partial class MenuAdmin
{
User user = new User();
private string evtype;
public string EventType
{
get { return evtype; }
set { evtype = value; }
}
private string apptype;
public string ApplicType
{
get { return apptype; }
set { apptype = value; }
}
private string employee;
public string Employee
{
get { return employee; }
set { employee = value; }
}
private void CBEmpl_Loaded(object sender, RoutedEventArgs e)
{
ComboBox cb = (ComboBox)sender;
cb.ItemsSource = DB.User.ToList().Where(x => x.Id_role == 2);
cb.DisplayMemberPath = "Surname";
cb.SelectedValuePath = "Id_user";
int appId = int.Parse(cb.Uid);
Applications ap = DB.Applications.FirstOrDefault(x => x.Id_application == appId);
if (ap.Id_employee != null)
{
cb.SelectedValue = Convert.ToInt32(ap.Id_employee);
EmployeeID.employeeid = Convert.ToInt32(cb.SelectedValue);
}
}
private void CBEmpl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
PP_MininEntities2 DB = new PP_MininEntities2();
ComboBox cb = (ComboBox)sender;
cb.DisplayMemberPath = "Surname";
cb.SelectedValuePath = "Id_user";
if(cb.Uid != null) {
int appId = int.Parse(cb.Uid);
Applications ap = DB.Applications.FirstOrDefault(x => x.Id_application == appId);
if (cb.SelectedItem != null)
{
if (ap != null)
{
ap.Id_employee = Convert.ToInt32(cb.SelectedValue);
DB.SaveChanges();
}
}
}
}
private void Users_Click(object sender, RoutedEventArgs e)
{
FrameClass.MainFrame.Navigate(new Acount());
}
}
public partial class MenuAdmin : Page
{
PP_MininEntities2 DB = new PP_MininEntities2();
int id;
public MenuAdmin()
{
InitializeComponent();
ApplicationList.ItemsSource = DB.Applications.ToList();
Applications appl = DB.Applications.Where(x => x.Id_status_app == id).FirstOrDefault();
CB_Filter_app.ItemsSource = new List { "Фильтр по статусу", "Выполнен", "Не выполнен" };
CB_Sort_app.ItemsSource = new List() { "Фильтр по дате", "Не сегодня", "Сегодня" };
CB_Sort_app.SelectedIndex = 0;
CB_Filter_app.SelectedIndex = 0;
EventList.ItemsSource = DB.Event.ToList();
Event evnt = DB.Event.Where(x => x.Id_event == id).FirstOrDefault();
CB_Filter_event.ItemsSource = new List() { "Фильтр по статусу", "Проведено", "Не проведено" };
CB_Sort_event.ItemsSource = new List() { "Фильтр по дате", "Не сегодня", "Сегодня" };
CB_Sort_event.SelectedIndex = 0;
CB_Filter_event.SelectedIndex = 0;
}
public MenuAdmin(int id)
{
InitializeComponent();
ApplicationList.ItemsSource = DB.Applications.ToList();
Applications appl = DB.Applications.Where(x => x.Id_application == id).FirstOrDefault();
CB_Filter_app.ItemsSource = DB.Applications.ToList();
CB_Sort_app.ItemsSource = DB.Applications.ToList();
CB_Sort_app.SelectedIndex = 0;
CB_Filter_app.SelectedIndex = 0;
this.id = id;
EventList.ItemsSource = DB.Event.ToList();
Event evnt = DB.Event.Where(x => x.Id_event == id).FirstOrDefault();
CB_Filter_event.ItemsSource = new List();
CB_Sort_event.ItemsSource = new List();
CB_Sort_event.SelectedIndex = 0;
CB_Filter_event.SelectedIndex = 0;
this.id = id;
}
private void Filter()
{
List applications = DB.Applications.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 = DB.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();
}
private void Exit_Click(object sender, RoutedEventArgs e)
{
FrameClass.MainFrame.Navigate(new Avtorization());
}
private void Profile_Click(object sender, RoutedEventArgs e)
{
FrameClass.MainFrame.Navigate(new Profile(user));
}
}
}