private void ButtonDelete_Click(object sender, RoutedEventArgs e) { try { MainInfoFilm deleteMainInfoFilm = (MainInfoFilm)ListMain.SelectedItem; if (deleteMainInfoFilm != null) { if (MessageBox.Show("Вы уверены, что хотите удалить элемент?", "Уведомление", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { { dbContext.db.MainInfoFilm.Remove(deleteMainInfoFilm); dbContext.db.SaveChanges(); Page_Loaded(null, null); } } } else { MessageBox.Show("Вы не выбрали ни одного элемента!", "Уведомление", MessageBoxButton.OK, MessageBoxImage.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source, MessageBoxButton.OK, MessageBoxImage.Error); } }
private void ButtonEdit_Click(object sender, RoutedEventArgs e) { MainInfoFilm Save = dbContext.db.MainInfoFilm.FirstOrDefault(item => item.ID == selecteditems.ID); Save.Name = tbName.Text; Save.CountryCreator = tbCountryCreator.Text; Save.Operator = tbOperator.Text; Save.Genres = tbGenres.Text; MemoryStream stream = new MemoryStream(); JpegBitmapEncoder encoder = new JpegBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create((BitmapImage)imgLoad.Source)); encoder.Save(stream); Save.ImageMovie = stream.ToArray(); var edcmbMPAA = dbContext.db.AgeLimit.FirstOrDefault(item => item.MPAA == cmbMPAA.Text); Save.BudgetAndFees.Budget = Convert.ToInt32(tbBudget.Text); Save.BudgetAndFees.WorldwideFees = Convert.ToInt32(tbWorldwideFees.Text); Save.Creators.Director = tbDirector.Text; Save.Creators.Producer = tbProducer.Text; Save.RentalData.PremiereInRussia = tbPremiereInRussia.SelectedDate; Save.RentalData.PremiereInWorld = tbPremiereInWorld.SelectedDate; Save.FilmDescription.Description = tbDescription.Text; dbContext.db.SaveChanges(); MessageBox.Show("Данные успешно изменены!", "Уведомление", MessageBoxButton.OK, MessageBoxImage.Information); NavigationService.GoBack(); }
private void ButtonAdd_Click(object sender, RoutedEventArgs e) { MainInfoFilm newMainInfoFilm = new MainInfoFilm(); Creators newCreators = new Creators(); BudgetAndFees newBudgetAndFees = new BudgetAndFees(); FilmDescription newFilmDescription = new FilmDescription(); RentalData newRentalData = new RentalData(); AgeLimit newAgeLimit = new AgeLimit(); newMainInfoFilm.Name = tbName.Text; newMainInfoFilm.CountryCreator = tbCountryCreator.Text; newMainInfoFilm.Operator = tbOperator.Text; newMainInfoFilm.Genres = tbGenres.Text; newMainInfoFilm.idCreators = newCreators.ID; newMainInfoFilm.idFilmDescription = newFilmDescription.ID; newMainInfoFilm.idBudgetAndFees = newBudgetAndFees.ID; newMainInfoFilm.idRentalData = newRentalData.ID; newMainInfoFilm.idAgeLimit = newAgeLimit.ID; MemoryStream stream = new MemoryStream(); JpegBitmapEncoder encoder = new JpegBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create((BitmapImage)imgLoad.Source)); encoder.Save(stream); newMainInfoFilm.ImageMovie = stream.ToArray(); var currentType = dbContext.db.AgeLimit.FirstOrDefault(item => item.MPAA == cmbMPAA.Text); newMainInfoFilm.ID = currentType.ID; newBudgetAndFees.Budget = Convert.ToInt32(tbBudget.Text); newBudgetAndFees.WorldwideFees = Convert.ToInt32(tbWorldwideFees.Text); newCreators.Director = tbDirector.Text; newCreators.Producer = tbProducer.Text; newRentalData.PremiereInRussia = (DateTime)tbPremiereInRussia.SelectedDate; newRentalData.PremiereInWorld = (DateTime)tbPremiereInWorld.SelectedDate; newFilmDescription.Description = tbDescription.Text; dbContext.db.BudgetAndFees.Add(newBudgetAndFees); dbContext.db.Creators.Add(newCreators); dbContext.db.AgeLimit.Add(newAgeLimit); dbContext.db.RentalData.Add(newRentalData); dbContext.db.FilmDescription.Add(newFilmDescription); dbContext.db.MainInfoFilm.Add(newMainInfoFilm); dbContext.db.SaveChanges(); MessageBox.Show("Вы успешно добавили данные", "Уведомление", MessageBoxButton.OK, MessageBoxImage.Information); }
private void ButtonEdit_Click(object sender, RoutedEventArgs e) { try { MainInfoFilm EditFilm = (MainInfoFilm)ListMain.SelectedItem; if (EditFilm != null) { NavigationService.Navigate(new EditPage(EditFilm)); } else { MessageBox.Show("Вы не выбрали строку которую хотите изменить", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } } catch { } }
private void ListMain_MouseDoubleClick(object sender, MouseButtonEventArgs e) { { try { MainInfoFilm infoGame = (MainInfoFilm)ListMain.SelectedItem; if (infoGame != null) { NavigationService.Navigate(new MoreInfo(infoGame)); } else { throw new Exception("Выберите элемент!"); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source, MessageBoxButton.OK, MessageBoxImage.Error); } } }
public EditPage(MainInfoFilm selecteditems) { InitializeComponent(); this.selecteditems = selecteditems; if (selecteditems.ImageMovie != null) { BitmapImage bitmap = new BitmapImage(); using (MemoryStream stream = new MemoryStream(selecteditems.ImageMovie)) { bitmap.BeginInit(); bitmap.CacheOption = BitmapCacheOption.OnLoad; bitmap.StreamSource = stream; bitmap.EndInit(); } imgLoad.Source = bitmap; } tbName.Text = selecteditems.Name; tbCountryCreator.Text = selecteditems.CountryCreator; tbOperator.Text = selecteditems.Operator; tbGenres.Text = selecteditems.Genres; tbBudget.Text = Convert.ToString(selecteditems.BudgetAndFees.Budget); tbWorldwideFees.Text = Convert.ToString(selecteditems.BudgetAndFees.WorldwideFees); tbDirector.Text = selecteditems.Creators.Director; tbProducer.Text = selecteditems.Creators.Producer; tbPremiereInRussia.SelectedDate = selecteditems.RentalData.PremiereInRussia; tbPremiereInWorld.SelectedDate = selecteditems.RentalData.PremiereInWorld; tbDescription.Text = selecteditems.FilmDescription.Description; cmbMPAA.ItemsSource = dbContext.db.AgeLimit.Select(item => item.MPAA).ToList(); }
public MoreInfo(MainInfoFilm selecteditem) { InitializeComponent(); this.selecteditem = selecteditem; }