AddHotelWindow.xaml.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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.Shapes;
  14. namespace ПодготовкаКДемо1.Pages
  15. {
  16. /// <summary>
  17. /// Логика взаимодействия для AddHotelWindow.xaml
  18. /// </summary>
  19. public partial class AddHotelWindow : Window
  20. {
  21. Hotel hotel;
  22. bool flag = true;
  23. public AddHotelWindow()
  24. {
  25. InitializeComponent();
  26. hotel = new Hotel();
  27. flag = false;
  28. Contry.DisplayMemberPath = "Name";
  29. Contry.SelectedValuePath = "Code";
  30. Contry.ItemsSource = BaseConnect.BaseModel.Country.ToList();
  31. }
  32. public AddHotelWindow(Hotel hotel)
  33. {
  34. InitializeComponent();
  35. this.hotel = hotel;
  36. DataContext = hotel;
  37. Contry.DisplayMemberPath = "Name";
  38. Contry.SelectedValuePath = "Code";
  39. Contry.ItemsSource = BaseConnect.BaseModel.Country.ToList();
  40. //Contry.SelectedItem = hotel.Country.Code;
  41. Contry.Text = hotel.Country.Name;
  42. }
  43. private void btnSave_Click(object sender, RoutedEventArgs e)
  44. {
  45. if (Name.Text!=""&& Name.Text != ""&& Name.Text != ""&& Contry.SelectedItem!=null)
  46. {
  47. if (flag)
  48. {
  49. BaseConnect.BaseModel.SaveChanges();
  50. MessageBox.Show("Добавлено!");
  51. }
  52. else
  53. {
  54. BaseConnect.BaseModel.Hotel.Add(hotel);
  55. BaseConnect.BaseModel.SaveChanges();
  56. MessageBox.Show("Добавлено!");
  57. }
  58. }
  59. else
  60. {
  61. MessageBox.Show("Не все поля заполненны");
  62. }
  63. }
  64. }
  65. }