private void AddMovieForm_Load(object sender, EventArgs e) { tbName.Text = MovieName; tbRuntime.Text = Runtime == 0 ? "" : Runtime.ToString(); dtpReleaseDate.Value = ReleaseDate; tbBudget.Text = Budget == 0 ? "" : Budget.ToString(); tbGross.Text = Gross == 0 ? "" : Gross.ToString(); tbTagline.Text = Tagline; rtbPlotSummary.Text = PlotSummary; if (Poster.StartsWith("\\")) { Poster = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + Poster; } try { pbPoster.Image = Image.FromFile(Poster); } catch (FileNotFoundException ex) { pbPoster.Image = Image.FromFile(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\Posters\\default.png"); } var genreItems = lvGenres.Items; foreach (var genre in Genres.ToList()) { foreach (var item in genreItems) { genre genreItem = (genre)(item as ListViewItem).Tag; if (genreItem.id == genre.id) { (item as ListViewItem).Checked = true; } } checkedGenres.Add(genre); } var languageItems = lvLanguages.Items; foreach (var language in Languages.ToList()) { foreach (var item in languageItems) { language languageItem = (language)(item as ListViewItem).Tag; if (languageItem.id == language.id) { (item as ListViewItem).Checked = true; } } checkedLanguages.Add(language); } var actorItems = lvActors.Items; foreach (var actor in MovieActors.ToList()) { foreach (var item in actorItems) { actor actorItem = (actor)(item as ListViewItem).Tag; if (actorItem.id == actor.id) { (item as ListViewItem).Checked = true; } } checkedActors.Add(actor); } var directorItems = lvDirectors.Items; foreach (var director in MovieDirectors.ToList()) { foreach (var item in directorItems) { director directorItem = (director)(item as ListViewItem).Tag; if (directorItem.id == director.id) { (item as ListViewItem).Checked = true; } } checkedDirectors.Add(director); } }
private void btnAddDirector_Click(object sender, EventArgs e) { AddMemberOfCastAndCrewForm addMemberOfCastAndCrew = new AddMemberOfCastAndCrewForm("director"); if (DialogResult.OK == addMemberOfCastAndCrew.ShowDialog()) { try { using (MovieDB context = new MovieDB()) { DateTime?died = addMemberOfCastAndCrew.Dead ? addMemberOfCastAndCrew.Died : (DateTime?)null; var memberOfCastAndCrew = new member_of_cast_and_crew() { first_name = addMemberOfCastAndCrew.FirstName, last_name = addMemberOfCastAndCrew.LastName, birthplace = addMemberOfCastAndCrew.Birthplace, born = addMemberOfCastAndCrew.Born, died = died, bio = addMemberOfCastAndCrew.Bio, image = addMemberOfCastAndCrew.MemberImage, active = 1 }; var director = new director() { member_of_cast_and_crew = memberOfCastAndCrew }; context.directors.Add(director); if (addMemberOfCastAndCrew.DoubleMember) { var actor = new actor() { member_of_cast_and_crew = memberOfCastAndCrew }; context.actors.Add(actor); } context.SaveChanges(); FillDirectorsList(); var directorItems = lvDirectors.Items; foreach (var checkedDirector in MovieDirectors.ToList()) { foreach (var item in directorItems) { director directorItem = (director)(item as ListViewItem).Tag; if (directorItem.id == checkedDirector.id) { (item as ListViewItem).Checked = true; } } } FillActorsList(); var actorItems = lvActors.Items; foreach (var checkedActor in MovieActors.ToList()) { foreach (var item in actorItems) { actor actorItem = (actor)(item as ListViewItem).Tag; if (actorItem.id == checkedActor.id) { (item as ListViewItem).Checked = true; } } } MoviesUcl.Instance.RefreshTableAndFilters(); ActorsUcl.Instance.RefreshTableAndFilters(); DirectorsUcl.Instance.RefreshTableAndFilters(); MessageBox.Show("Director successfully added.", "Success", MessageBoxButtons.OK); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } }