TaskList.xaml.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace ROGOZ.Pages
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для TaskList.xaml
  19. /// </summary>
  20. public partial class TaskList : Page
  21. {
  22. public TaskList()
  23. {
  24. InitializeComponent();
  25. DGTasks.ItemsSource = user1Entities.GetContext().Task.ToList();
  26. }
  27. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  28. {
  29. NavigationService.Navigate(new AddEditPage(null));
  30. }
  31. private void BtnEdit_Click(object sender, RoutedEventArgs e)
  32. {
  33. NavigationService.Navigate(new AddEditPage((sender as Button).DataContext as Task));
  34. }
  35. private void BtnDelTask_Click(object sender, RoutedEventArgs e)
  36. {
  37. var taskIsForRemoving = DGTasks.SelectedItems.Cast<Task>().ToList();
  38. if (MessageBox.Show($"Вы точно хотите удалить {taskIsForRemoving.Count()} задач?",
  39. "Внимание",MessageBoxButton.YesNo, MessageBoxImage.Question)==MessageBoxResult.Yes)
  40. {
  41. try
  42. {
  43. user1Entities.GetContext().Task.RemoveRange(taskIsForRemoving);
  44. user1Entities.GetContext().SaveChanges();
  45. MessageBox.Show("Данные удалены");
  46. DGTasks.ItemsSource = user1Entities.GetContext().Task.ToList();
  47. }
  48. catch (Exception ex) {MessageBox.Show(ex.Message.ToString());}
  49. }
  50. }
  51. }
  52. }