private void Page_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { if (Visibility == Visibility.Visible) { Tour_FrolovEntities.GetContext().ChangeTracker.Entries().ToList().ForEach(p => p.Reload()); DGridHotels.ItemsSource = Tour_FrolovEntities.GetContext().Hotel.ToList(); } }
public static Tour_FrolovEntities GetContext() { if (_context == null) { _context = new Tour_FrolovEntities(); } return(_context); }
public AddEditPage(Hotel selectedHotel) { InitializeComponent(); if (selectedHotel != null) { _currentHotel = selectedHotel; } DataContext = _currentHotel; Country.ItemsSource = Tour_FrolovEntities.GetContext().Country.ToList(); }
private void BtnEdit_Click_1(object sender, RoutedEventArgs e) { var hotelsForRemoving = DGridHotels.SelectedItems.Cast <Hotel>().ToList(); if (MessageBox.Show($"Вы точно хотите удалить следуещее {hotelsForRemoving.Count()} элементов?", "Внимание", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { try { Tour_FrolovEntities.GetContext().Hotel.RemoveRange(hotelsForRemoving); Tour_FrolovEntities.GetContext().SaveChanges(); MessageBox.Show("Данные удалены"); DGridHotels.ItemsSource = Tour_FrolovEntities.GetContext().Hotel.ToList(); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } } }
private void BtnSave_Click(object sender, RoutedEventArgs e) { StringBuilder errors = new StringBuilder(); if (string.IsNullOrWhiteSpace(_currentHotel.Name)) { errors.AppendLine("Укажите название отеля"); } if (_currentHotel.CountOfStars < 1 || _currentHotel.CountOfStars > 5) { errors.AppendLine("Количество звёзд - число от 1 до 5"); } if (_currentHotel.Country == null) { errors.AppendLine("Выберите страну"); } if (errors.Length > 0) { MessageBox.Show(errors.ToString()); return; } if (_currentHotel.Id == 0) { Tour_FrolovEntities.GetContext().Hotel.Add(_currentHotel); } try { Tour_FrolovEntities.GetContext().SaveChanges(); MessageBox.Show("Информация сохранена!"); Manager.MainFrame.GoBack(); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } }
private void ImportTours() { var fileData = File.ReadAllLines("../../image"); var images = Directory.GetFiles(@"Туры.txt"); foreach (var line in fileData) { var data = line.Split('\t'); var tempTour = new Tour { Name = data[0].Replace("\"", ""), TicketCount = int.Parse(data[2]), Price = decimal.Parse(data[3]), IsActual = (data[4] == "0") ? false : true }; foreach (var tourTape in data[5].Replace("\"", "").Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries)) { var currentType = Tour_FrolovEntities.GetContext().Type.ToList().FirstOrDefault(p => p.Name == tourTape); if (currentType != null) { tempTour.Type.Add(currentType); } } try { tempTour.ImagePreview = File.ReadAllBytes(images.FirstOrDefault(p => p.Contains(tempTour.Name))); } catch (Exception ex) { Console.WriteLine(ex.Message); } Tour_FrolovEntities.GetContext().Tour.Add(tempTour); Tour_FrolovEntities.GetContext().SaveChanges(); } }
public HotelsPage() { InitializeComponent(); DGridHotels.ItemsSource = Tour_FrolovEntities.GetContext().Hotel.ToList(); }