Услуги.xaml.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 Khaustov_ProbniyDE
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для Услуги.xaml
  19. /// </summary>
  20. public partial class Услуги : Page
  21. {
  22. public Услуги()
  23. {
  24. InitializeComponent();
  25. DGridУслуги.ItemsSource = Хаустов_ПробныйДЭEntities.GetContext().Service.ToList();
  26. }
  27. private void BtnEdit_Click(object sender, RoutedEventArgs e)
  28. {
  29. Switcher.MainFrame.Navigate(new AddEditPage((sender as Button).DataContext as Service));
  30. }
  31. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  32. {
  33. Switcher.MainFrame.Navigate(new AddEditPage(null));
  34. }
  35. private void BtnDelete_Click(object sender, RoutedEventArgs e)
  36. {
  37. var ServiceForRemoving = DGridУслуги.SelectedItems.Cast<Service>().ToList();
  38. if (MessageBox.Show($"Вы точно хотите удалить следующие {ServiceForRemoving.Count()} элементов?", "Внимание", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  39. {
  40. try
  41. {
  42. Хаустов_ПробныйДЭEntities.GetContext().Service.RemoveRange(ServiceForRemoving);
  43. Хаустов_ПробныйДЭEntities.GetContext().SaveChanges();
  44. MessageBox.Show("Данные удалены");
  45. DGridУслуги.ItemsSource = Хаустов_ПробныйДЭEntities.GetContext().Service.ToList();
  46. }
  47. catch (Exception ex)
  48. {
  49. MessageBox.Show(ex.Message.ToString());
  50. }
  51. }
  52. }
  53. }
  54. }