123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- 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 LR1_05._04
- {
- /// <summary>
- /// Логика взаимодействия для HotelsPage.xaml
- /// </summary>
- public partial class HotelsPage : Page
- {
- public HotelsPage()
- {
- InitializeComponent();
- DGridHotels.ItemsSource = ToursEntities.GetContext().Hotels.ToList();
- }
- private void Button_Click (object sender, RoutedEventArgs e)
- {
-
- }
- private void BtnEdit_Click(object sender, RoutedEventArgs e)
- {
- Manager.MainFrame.Navigate(new AddEditPage((sender as Button).DataContext as Hotel));
- }
- private void BtnAdd_Click(object sender, RoutedEventArgs e)
- {
- Manager.MainFrame.Navigate(new AddEditPage(null));
- }
- private void BtnDelete_Click(object sender, RoutedEventArgs e)
- {
- var hotelsForRemoving = DGridHotels.SelectedItems.Cast<Hotel>().ToList();
-
- if (MessageBox.Show($"Вы точно хотите удалить следующие {hotelsForRemoving.Count()} элементов?", "Внимание",
- MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
- {
- try
- {
- ToursEntities.GetContext().Hotels.RemoveRange(hotelsForRemoving);
- ToursEntities.GetContext().SaveChanges();
- MessageBox.Show("Данные удалены!");
- DGridHotels.ItemsSource = ToursEntities.GetContext().Hotels.ToList();
- }
- catch(Exception ex)
- {
- MessageBox.Show(ex.Message.ToString());
- }
-
- }
- }
- private void Page_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
- {
- if(Visibility == Visibility.Visible)
- {
- ToursEntities.GetContext().ChangeTracker.Entries().ToList().ForEach(p => p.Reload());
- DGridHotels.ItemsSource = ToursEntities.GetContext().Hotels.ToList();
- }
- }
- }
- }
|