pgHotels.xaml.cs 1.6 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 WpfApp1
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для pgHotels.xaml
  19. /// </summary>
  20. public partial class pgHotels : Page
  21. {
  22. List<Hotel> hotels;
  23. public pgHotels()
  24. {
  25. InitializeComponent();
  26. BaseConnect.BaseModel = new ToursEntities();
  27. hotels = BaseConnect.BaseModel.Hotel.ToList();
  28. dgHotels.ItemsSource = hotels;
  29. }
  30. private void Button_Click(object sender, RoutedEventArgs e)
  31. {
  32. Button btn = (Button)sender;
  33. int id = Convert.ToInt32(btn.Uid);
  34. LoadPages.frmMain.Navigate(new pgUpdateHotel(id));
  35. }
  36. private void btnDelHotel_Click(object sender, RoutedEventArgs e)
  37. {
  38. foreach(Hotel hotel in dgHotels.SelectedItems)
  39. {
  40. BaseConnect.BaseModel.Hotel.Remove(hotel);
  41. BaseConnect.BaseModel.SaveChanges();
  42. }
  43. BaseConnect.BaseModel = new ToursEntities();
  44. hotels = BaseConnect.BaseModel.Hotel.ToList();
  45. dgHotels.ItemsSource = hotels;
  46. }
  47. private void btnAddHotel_Click(object sender, RoutedEventArgs e)
  48. {
  49. LoadPages.frmMain.Navigate(new pgAddHotel());
  50. }
  51. }
  52. }