TaskList.xaml.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using Esoft.Pages;
  2. using Esoft;
  3. using Microsoft.Office.Interop.Word;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Navigation;
  17. using System.Windows.Shapes;
  18. namespace Esoft.Pages
  19. {
  20. /// <summary>
  21. /// Логика взаимодействия для TaskList.xaml
  22. /// </summary>
  23. public partial class TaskList : System.Windows.Controls.Page
  24. {
  25. private user6Entities _context = new user6Entities();
  26. //private List<string> listUsers = new List<string>();
  27. public TaskList()
  28. {
  29. InitializeComponent();
  30. CmbStatusSort.ItemsSource = Status.FillStatus();
  31. //CmbExecutorSort.ItemsSource = user6Entities.GetContext().Executor.ToList();
  32. DGTasks.ItemsSource = user6Entities.GetContext().Task.ToList();
  33. //foreach (var user in _context.User.ToList())
  34. //{
  35. // listUsers.Add(user.getFamilia());
  36. //}
  37. //CmbExecutorSort.ItemsSource = listUsers;
  38. }
  39. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  40. {
  41. NavigationService.Navigate(new AddEditPage(null));
  42. }
  43. private void BtnEdit_Click(object sender, RoutedEventArgs e)
  44. {
  45. NavigationService.Navigate(new AddEditPage((sender as Button).DataContext as Task));
  46. }
  47. private void BtnDelTask_Click(object sender, RoutedEventArgs e)
  48. {
  49. var taskIsForRemoving = DGTasks.SelectedItems.Cast<Task>().ToList();
  50. if (MessageBox.Show($"Вы точно хотите удалить выбранные задачи?",
  51. "Внимание", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  52. {
  53. try
  54. {
  55. user6Entities.GetContext().Task.RemoveRange(taskIsForRemoving);
  56. user6Entities.GetContext().SaveChanges();
  57. MessageBox.Show("Данные удалены");
  58. DGTasks.ItemsSource = user6Entities.GetContext().Task.ToList();
  59. }
  60. catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); }
  61. }
  62. }
  63. //сортировка по названию
  64. private void TBoxSearch_TextChanged(object sender, TextChangedEventArgs e)
  65. {
  66. UpdateTasks();
  67. }
  68. //Очистка фильтров
  69. private void ClearFilters_Click(object sender, RoutedEventArgs e)
  70. {
  71. //CmbExecutorSort.SelectedIndex = -1;
  72. CmbStatusSort.SelectedIndex = -1;
  73. TBoxSearch.Clear();
  74. }
  75. private void UpdateTasks()
  76. {
  77. var searchText = TBoxSearch.Text.ToLower();
  78. var tasks = user6Entities.GetContext().Task.ToList();
  79. //сортировка по статусу
  80. //if (CmbStatusSort.SelectedIndex == -1 || CmbStatusSort.Text == null)
  81. // DGTasks.ItemsSource = tasks.OrderBy(p => p.Status).ToList();
  82. //сортировка по поиску
  83. DGTasks.ItemsSource = tasks.Where(p => p.Title.ToLower().Contains(searchText)
  84. || p.Executor.User.MiddleName.ToLower().Contains(searchText)).ToList();
  85. }
  86. //Сортировка по статусу
  87. private void CmbStatusSort_LostFocus(object sender, RoutedEventArgs e)
  88. {
  89. var tasks = user6Entities.GetContext().Task.ToList();
  90. if (CmbStatusSort.SelectedIndex != -1)
  91. DGTasks.ItemsSource = tasks.Where(p => p.Status == CmbStatusSort.Text).ToList();
  92. if (CmbStatusSort.SelectedIndex == -1 || CmbStatusSort.Text == null)
  93. DGTasks.ItemsSource = tasks.OrderBy(p => p.Status).ToList();
  94. }
  95. private void CmbStatusSort_SelectionChanged(object sender, SelectionChangedEventArgs e)
  96. {
  97. UpdateTasks();
  98. }
  99. }
  100. }