private void Button_Click(object sender, RoutedEventArgs e) { if (!string.IsNullOrEmpty(tbTitle.Text)) { movie = new Movy { Title = tbTitle.Text.Trim(), Year = Convert.ToInt32(tbYear.Text.Trim()), Country = tbCountry.Text.Trim(), MovieSerial = Convert.ToInt32(tbSerial.Text.Trim()), ImdbScore = Convert.ToDecimal(tbIMDB.Text.Trim()) }; this.Close(); } else { MessageBox.Show("You must enter a movie's name"); } }
private void Button_Click(object sender, RoutedEventArgs e) { if (isFilled() == true) { using (MoviesDBEntities ctx = new MoviesDBEntities()) { try { var theActor = (from m in ctx.Actors where m.FirstName == tbActorFN.Text.Trim() && m.LastName == tbActorLN.Text.Trim() select m).First(); Actor = theActor; } catch (Exception) { AddActor window = new AddActor(); window.tbFN.Text = tbActorFN.Text; window.tbLN.Text = tbActorLN.Text; window.tbFN.IsEnabled = false; window.tbLN.IsEnabled = false; window.ShowDialog(); if (window.actor != null) { ctx.Actors.Add(window.actor); ctx.SaveChanges(); } var aActor = (from m in ctx.Actors where m.FirstName == window.tbFN.Text.Trim() select m).First(); Actor = aActor; } try { var theActress = (from m in ctx.Actresses where m.FirstName == tbActressFN.Text.Trim() && m.LastName == tbActressLN.Text.Trim() select m).First(); Actress = theActress; } catch (Exception) { AddActress window = new AddActress(); window.tbFN.Text = tbActressFN.Text; window.tbLN.Text = tbActressLN.Text; window.tbFN.IsEnabled = false; window.tbLN.IsEnabled = false; window.ShowDialog(); if (window.actress != null) { ctx.Actresses.Add(window.actress); ctx.SaveChanges(); } var aActress = (from m in ctx.Actresses where m.FirstName == window.tbFN.Text.Trim() select m).First(); Actress = aActress; } try { var theDirector = (from m in ctx.Directors where m.FirstName == tbDirectorFN.Text.Trim() && m.FirstName == tbDirectorFN.Text.Trim() select m).First(); Director = theDirector; } catch (Exception) { AddDirector window = new AddDirector(); window.tbFN.Text = tbDirectorFN.Text; window.tbLN.Text = tbDirectorLN.Text; window.tbFN.IsEnabled = false; window.tbLN.IsEnabled = false; window.ShowDialog(); if (window.director != null) { ctx.Directors.Add(window.director); ctx.SaveChanges(); } var aDirector = (from m in ctx.Directors where m.FirstName == window.tbFN.Text.Trim() select m).First(); Director = aDirector; } try { var theMovie = (from m in ctx.Movies where m.Title == tbMovie.Text.Trim() select m).First(); Movie = theMovie; } catch (Exception) { AddMovie window = new AddMovie(); window.tbTitle.Text = tbMovie.Text; window.tbTitle.IsEnabled = false; window.ShowDialog(); if (window.movie != null) { ctx.Movies.Add(window.movie); ctx.SaveChanges(); } var aMovie = (from m in ctx.Movies where m.Title == window.tbTitle.Text.Trim() select m).First(); Movie = aMovie; } try { GoldenGlobe = new GoldenGlobe { ActressId_Id = Actress.Id, ActorId_Id = Actor.Id, DirectorId_Id = Director.Id, MovieId_MovieSerial = Movie.MovieSerial, Year = Convert.ToInt32(tbYear.Text.Trim()) }; } catch (FormatException) { MessageBox.Show("Invalid Input."); this.Close(); } ctx.SaveChanges(); this.Close(); } } else { MessageBox.Show("Fill all...."); } }
private void Button_Click(object sender, RoutedEventArgs e) { if ((bool)rbActor.IsChecked) { using (MoviesDBEntities ctx = new MoviesDBEntities()) { try { var theActor = (from m in ctx.Actors where m.FirstName == tbFN.Text.Trim() && m.LastName == tbLN.Text.Trim() select m).First(); Actor = theActor; } catch (Exception) { AddActor window = new AddActor(); window.tbFN.Text = tbFN.Text; window.tbLN.Text = tbLN.Text; window.tbFN.IsEnabled = false; window.tbLN.IsEnabled = false; window.ShowDialog(); if (window.actor != null) { ctx.Actors.Add(window.actor); ctx.SaveChanges(); } var theActor = (from m in ctx.Actors where m.FirstName == window.tbFN.Text.Trim() && m.LastName == window.tbLN.Text.Trim() select m).First(); Actor = theActor; } try { var theMovie = (from m in ctx.Movies where m.Title == tbAM.Text.Trim() select m).First(); Movie = theMovie; } catch (Exception) { MessageBox.Show("Your movie doesn't exist"); this.Close(); } Movie.Actors.Add(Actor); Actor.Movies.Add(Movie); ctx.SaveChanges(); this.Close(); } } else if ((bool)rbActress.IsChecked) { using (MoviesDBEntities ctx = new MoviesDBEntities()) { try { var theActress = (from m in ctx.Actresses where m.FirstName == tbFN.Text.Trim() && m.LastName == tbLN.Text.Trim() select m).First(); Actress = theActress; } catch (Exception) { AddActress window = new AddActress(); window.tbFN.Text = tbFN.Text; window.tbLN.Text = tbLN.Text; window.tbFN.IsEnabled = false; window.tbLN.IsEnabled = false; window.ShowDialog(); if (window.actress != null) { ctx.Actresses.Add(window.actress); ctx.SaveChanges(); } var theActress = (from m in ctx.Actresses where m.FirstName == window.tbFN.Text.Trim() && m.LastName == window.tbLN.Text.Trim() select m).First(); Actress = theActress; } try { var theMovie = (from m in ctx.Movies where m.Title == tbAM.Text.Trim() select m).First(); Movie = theMovie; } catch (Exception) { MessageBox.Show("Your movie doesn't exist"); this.Close(); } Movie.Actresses.Add(Actress); Actress.Movies.Add(Movie); ctx.SaveChanges(); this.Close(); } } else if ((bool)rbDirector.IsChecked) { using (MoviesDBEntities ctx = new MoviesDBEntities()) { try { var theDirector = (from m in ctx.Directors where m.FirstName == tbFN.Text.Trim() && m.LastName == tbLN.Text.Trim() select m).First(); Director = theDirector; } catch (Exception) { AddDirector window = new AddDirector(); window.tbFN.Text = tbFN.Text; window.tbLN.Text = tbLN.Text; window.tbFN.IsEnabled = false; window.tbLN.IsEnabled = false; window.ShowDialog(); if (window.director != null) { ctx.Directors.Add(window.director); ctx.SaveChanges(); } var theDirector = (from m in ctx.Directors where m.FirstName == window.tbFN.Text.Trim() && m.LastName == window.tbLN.Text.Trim() select m).First(); Director = theDirector; } try { var theMovie = (from m in ctx.Movies where m.Title == tbAM.Text.Trim() select m).First(); Movie = theMovie; } catch (Exception) { MessageBox.Show("Your movie doesn't exist"); this.Close(); } Movie.Director = Director; Director.Movies.Add(Movie); ctx.SaveChanges(); this.Close(); } } }
private void Button_Click(object sender, RoutedEventArgs e) { using (MoviesDBEntities ctx = new MoviesDBEntities()) { try { var movies = (from m in ctx.Movies where m.Title == tbAM.Text select m).First(); Movie = movies; } catch (Exception) { AddMovie window = new AddMovie(); window.ShowDialog(); window.tbTitle.Text = tbAM.Text; window.tbTitle.IsEnabled = false; var movies = (from m in ctx.Movies where m.Title == window.tbTitle.Text select m).First(); Movie = movies; } if ((bool)rbActor.IsChecked) { try { var actor = (from m in ctx.Actors where m.FirstName == tbFN.Text && m.LastName == tbLN.Text select m).First(); actor.Movies.Add(Movie); Movie.Actors.Add(actor); ctx.SaveChanges(); this.Close(); } catch (Exception) { MessageBox.Show("Actor dosen't exist."); this.Close(); } } else if ((bool)rbActress.IsChecked) { try { var actress = (from m in ctx.Actresses where m.FirstName == tbFN.Text && m.LastName == tbLN.Text select m).First(); actress.Movies.Add(Movie); Movie.Actresses.Add(actress); ctx.SaveChanges(); this.Close(); } catch (Exception) { MessageBox.Show("Actress dosen't exist."); this.Close(); } } else if ((bool)rbDirector.IsChecked) { try { var director = (from m in ctx.Directors where m.FirstName == tbFN.Text && m.LastName == tbLN.Text select m).First(); director.Movies.Add(Movie); Movie.Director = director; ctx.SaveChanges(); this.Close(); } catch (Exception) { MessageBox.Show("Director dosen't exist."); this.Close(); } } } }