private void btnModify_Click(object sender, EventArgs e) { // create a new Movie object that holds the changes Movie newMovie = new Movie(); newMovie.Id = currentMovie.Id; if (txtTitle.Text.Trim() != "") { newMovie.Title = txtTitle.Text.Trim(); } if (cboFormat.SelectedIndex != 0) { newMovie.Format = cboFormat.Text; } if (cboGenre.SelectedIndex != 0) { newMovie.Genre = cboGenre.Text; } if (cboYear.SelectedIndex != 0) { newMovie.Year = Convert.ToInt16(cboYear.Text); } if (txtSynopsis.Text.Trim() != "") { newMovie.Synopsis = txtSynopsis.Text.Trim(); } // update the database with changes bool modify = false; if (newMovie.Title != null) { modify = MovieDB.Modify(newMovie, currentMovie); } else { MessageBox.Show("Please add the Title of the movie."); newMovie.Title = "\"Empty Title\""; // this is ok because whenever you click btnModify it creates a new movie object so it clears this } // display a confirmation message if (modify == true) { MessageBox.Show(newMovie.Title + " has been modified in the database."); currentMovie = newMovie; // if the database was modified then //assign the value currentMovie //variable to be the newMovie } else { MessageBox.Show(newMovie.Title + " was not modified in the database. " + "Try again."); } }
private void btnAdd_Click(object sender, EventArgs e) { // create a new movie object Movie newMovie = new Movie(); // check to see if the field has a valid value and then store it in its corrisponding variable if (txtTitle.Text.Trim() != "") { newMovie.Title = txtTitle.Text.Trim(); } if (cboFormat.SelectedIndex != 0) { newMovie.Format = cboFormat.Text; } if (cboGenre.SelectedIndex != 0) { newMovie.Genre = cboGenre.Text; } if (cboYear.SelectedIndex != 0) { newMovie.Year = Convert.ToInt16(cboYear.Text); } if (txtSynopsis.Text.Trim() != "") { newMovie.Synopsis = txtSynopsis.Text.Trim(); } // check to see any of the fields have values if so search DB and if no fields have values then let the user know if (!(newMovie.Title == null && newMovie.Format == null && newMovie.Genre == null && newMovie.Year == null && newMovie.Synopsis == null)) { if (newMovie.Title != null) { MovieDB.Add(newMovie); } else { MessageBox.Show("There must be a title name. Please fill in that field."); } } else { MessageBox.Show("All search entries are empty. Please fill in one of them.", "Entry Error"); } }
private void btnSearch_Click(object sender, EventArgs e) { // create a movie object to hold the search data Movie movieSearch = new Movie(); // check to see if the field has a valid value and then store it in its corrisponding variable if (txtTitle.Text.Trim() != "") { movieSearch.Title = txtTitle.Text.Trim(); } if (cboFormat.SelectedIndex != 0) { movieSearch.Format = cboFormat.Text; } if (cboGenre.SelectedIndex != 0) { movieSearch.Genre = cboGenre.Text; } if (cboYear.SelectedIndex != 0) { movieSearch.Year = Convert.ToInt16(cboYear.Text); } if (txtSynopsis.Text.Trim() != "") { movieSearch.Synopsis = txtSynopsis.Text.Trim(); } // check to see any of the fields have values if so search DB and if no fields have values then let the user know if (!(movieSearch.Title == null && movieSearch.Format == null && movieSearch.Genre == null && movieSearch.Year == null && movieSearch.Synopsis == null)) { MovieDB.Search(moviesDataGridView, movieSearch); } else { MessageBox.Show("All search entries are empty. Please fill in one of them.", "Entry Error"); } }