123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- using PP_Ven_MosS.Classes;
- using PP_Ven_MosS.ModelBase;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- namespace PP_Ven_MosS.Pages
- {
- /// <summary>
- /// Логика взаимодействия для MenuAdmin.xaml
- /// </summary>
- 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 Report_Click(object sender, RoutedEventArgs e)
- {
- Button btn = (Button)sender;
- Event evn = DB.Event.FirstOrDefault(x => x.Id_event.ToString() == btn.Uid);
- if (evn != null)
- FrameClass.MainFrame.Navigate(new ReportForEvent(evn));
- }
- private void CBEmpl_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- PP_MininEntities DB = new PP_MininEntities();
- 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());
- }
- private void Otchet_Click(object sender, RoutedEventArgs e)
- {
- FrameClass.MainFrame.Navigate(new Diagram());
- }
- private void DeleteBtn_Click(object sender, RoutedEventArgs e)
- {
- Button btn = (Button)sender;
- Event evn = Database.entities.Event.FirstOrDefault(x => x.Id_event.ToString() == btn.Uid);
- MessageBoxResult mr = MessageBox.Show("Точно ли вы хотите удалить эту запись?", "Удаление", MessageBoxButton.YesNo, MessageBoxImage.Question);
- switch (mr)
- {
- case MessageBoxResult.Yes:
- Database.entities.Event.Remove(evn);
- Database.entities.SaveChanges(); break;
- case MessageBoxResult.No:
- break;
- }
- EventList.ItemsSource = Database.entities.Event.ToList();
- }
- }
- public partial class MenuAdmin : Page
- {
- PP_MininEntities DB = new PP_MininEntities();
- 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<string> { "Фильтр по статусу", "Выполнен", "Не выполнен" };
- CB_Sort_app.ItemsSource = new List<string>() { "Фильтр по дате", "Не сегодня", "Сегодня" };
- 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<string>() { "Фильтр по статусу", "Проведено", "Не проведено" };
- CB_Sort_event.ItemsSource = new List<string>() { "Фильтр по дате", "Не сегодня", "Сегодня" };
- 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<string>();
- CB_Sort_event.ItemsSource = new List<string>();
- CB_Sort_event.SelectedIndex = 0;
- CB_Filter_event.SelectedIndex = 0;
- this.id = id;
- }
- private void Filter()
- {
- List<Applications> 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<Event> 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));
- }
- }
- }
|