123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- 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 ROGOZ.Pages
- {
- /// <summary>
- /// Логика взаимодействия для TaskList.xaml
- /// </summary>
- public partial class TaskList : Page
- {
- private user1Entities _context = new user1Entities();
- //private List<string> listUsers = new List<string>();
- public TaskList()
- {
- InitializeComponent();
- CmbStatusSort.ItemsSource = Status.FillStatus();
- //CmbExecutorSort.ItemsSource = user1Entities.GetContext().Executor.ToList();
-
- DGTasks.ItemsSource = user1Entities.GetContext().Task.ToList();
- //foreach (var user in _context.User.ToList())
- //{
- // listUsers.Add(user.getFamilia());
- //}
- //CmbExecutorSort.ItemsSource = listUsers;
- }
- private void BtnAdd_Click(object sender, RoutedEventArgs e)
- {
- NavigationService.Navigate(new AddEditPage(null));
- }
- private void BtnEdit_Click(object sender, RoutedEventArgs e)
- {
- NavigationService.Navigate(new AddEditPage((sender as Button).DataContext as Task));
- }
- private void BtnDelTask_Click(object sender, RoutedEventArgs e)
- {
- var taskIsForRemoving = DGTasks.SelectedItems.Cast<Task>().ToList();
- if (MessageBox.Show($"Вы точно хотите удалить выбранные задачи?",
- "Внимание",MessageBoxButton.YesNo, MessageBoxImage.Question)==MessageBoxResult.Yes)
- {
- try
- {
- user1Entities.GetContext().Task.RemoveRange(taskIsForRemoving);
- user1Entities.GetContext().SaveChanges();
- MessageBox.Show("Данные удалены");
- DGTasks.ItemsSource = user1Entities.GetContext().Task.ToList();
- }
- catch (Exception ex) {MessageBox.Show(ex.Message.ToString());}
- }
- }
- //сортировка по названию
- private void TBoxSearch_TextChanged(object sender, TextChangedEventArgs e)
- {
- UpdateTasks();
- }
- //Очистка фильтров
- private void ClearFilters_Click(object sender, RoutedEventArgs e)
- {
- //CmbExecutorSort.SelectedIndex = -1;
- CmbStatusSort.SelectedIndex = -1;
- TBoxSearch.Clear();
- }
- private void UpdateTasks()
- {
- var searchText = TBoxSearch.Text.ToLower();
- var tasks = user1Entities.GetContext().Task.ToList();
- //сортировка по статусу
- //if (CmbStatusSort.SelectedIndex == -1 || CmbStatusSort.Text == null)
- // DGTasks.ItemsSource = tasks.OrderBy(p => p.Status).ToList();
- //сортировка по поиску
- DGTasks.ItemsSource = tasks.Where(p => p.Title.ToLower().Contains(searchText)
- || p.Executor.User.MiddleName.ToLower().Contains(searchText)).ToList();
- }
- //Сортировка по статусу
- private void CmbStatusSort_LostFocus(object sender, RoutedEventArgs e)
- {
- var tasks = user1Entities.GetContext().Task.ToList();
- if (CmbStatusSort.SelectedIndex != -1 )
- DGTasks.ItemsSource = tasks.Where(p => p.Status == CmbStatusSort.Text).ToList();
- if (CmbStatusSort.SelectedIndex == -1 || CmbStatusSort.Text == null)
- DGTasks.ItemsSource = tasks.OrderBy(p => p.Status).ToList();
- }
- private void CmbStatusSort_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- UpdateTasks();
- }
- }
- }
|