private void btnUpdate_Click(object sender, EventArgs e) { //Validate the UI if (string.IsNullOrEmpty(txtMovieNumber.Text.Trim())) { MessageBox.Show("Please enter a movie id."); txtMovieNumber.Focus(); return; } if (string.IsNullOrEmpty(txtMovieTitle.Text.Trim())) { MessageBox.Show("Please enter a movie name."); txtMovieNumber.Focus(); return; } Movie objMovie = new Movie(); objMovie.movie_number = txtMovieNumber.Text.Trim(); objMovie.movie_title = txtMovieTitle.Text.Trim(); objMovie.description = txtDescription.Text.Trim(); objMovie.movie_year_made = txtMovieYearMade.Text.Trim(); //Genre genre = GenreDB.GetGenreByName(cbGenre.SelectedItem.ToString()); objMovie.genre_id = genre.ID; objMovie.genre_id = ((Genre)cbGenre.SelectedItem).ID.ToString();//MessageBox.Show(cbGenre.SelectedIndex.ToString()); objMovie.movie_rating = cbRating.Text.Trim(); objMovie.media_type = cbMediaType.Text.Trim(); objMovie.movie_retail_cost = Math.Round(Convert.ToDecimal(txtRetailCost.Text.Trim()), 2); objMovie.copies_on_hand = txtCopiesOnHand.Text.Trim(); objMovie.image = txtImageFilename.Text.Trim(); objMovie.trailer = txtTrailerLink.Text.Trim(); try { bool status = MovieDB.UpdateMovie(objMovie); if (status) //You can use this syntax as well..if (status ==true) { MessageBox.Show("Movie has been updated.", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Movie was not updated in database.", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btn_Update_Click(object sender, EventArgs e) { try { Movie m = GetMovieObjFromUI(); if (m != null) { if (MovieDB.UpdateMovie(m)) { MessageBox.Show("Update Successful."); } else { MessageBox.Show("Update Failed. Make sure all information has been entered."); } } } catch (Exception ex) { MessageBox.Show("There was a technical error during the operation.\n\nMessage:\n" + ex.Message + "\n\nStack Trace:\n" + ex.StackTrace); } }
private void btnUpdate_Click(object sender, EventArgs e) { if (!(validateUI(btnUpdate))) { return; } try { Movie myMovie = new Movie(); myMovie.movie_number = Convert.ToInt32(txtMovieNumber.Text.Trim()); myMovie.movie_title = txtMovieTitle.Text.Trim(); myMovie.description = rtbDescription.Text.Trim(); myMovie.movie_year_made = Convert.ToInt32(txtMovieYearMade.Text.Trim()); myMovie.genre_id = cmbGenre.SelectedIndex; myMovie.movie_rating = cmbMovieRating.Text.Trim(); myMovie.image = txtImage.Text.Trim(); myMovie.rental_duration = cmbRentalDuration.SelectedIndex; myMovie.trailer = txtTrailer.Text.Trim(); bool status = MovieDB.UpdateMovie(myMovie); if (status) //returns true { MessageBox.Show("Movie ID has been updated in the database.", "MeramecNetFlix", MessageBoxButtons.OK, MessageBoxIcon.Information); //Automatically refresh the data grid this.btnBrowse_Click(null, null); } else //returns false { MessageBox.Show("Movie ID was not update in the database.", "MeramecNetFlix", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "MeramecNetFlix", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnUpdate_Click(object sender, EventArgs e) { //Validate the UI foreach (Control control in this.Controls) { if (control.GetType() != dataGridView1.GetType()) { if (string.IsNullOrEmpty(control.Text.Trim())) { MessageBox.Show("Please enter a value for " + control.Name.ToString()); control.Focus(); return; } } } List <Genre> genreList = GenreDB.GetGenres(); int genreid = 0; foreach (Genre genre in genreList) { if (genre.Name == cmbGenre.Text) { genreid = genre.ID; } } Movie objMovie = new Movie(); objMovie.movie_number = Convert.ToInt16(txtMovieNumber.Text); objMovie.movie_title = txtTitle.Text.ToString(); objMovie.Description = txtDescription.Text.ToString(); objMovie.movie_year_made = Convert.ToInt16(txtYear.Text); objMovie.genre_id = genreid; objMovie.movie_rating = cmbRating.Text; objMovie.media_type = cmbMediaType.Text; objMovie.movie_retail_cost = returnDecimal(txtRetailCost.Text); objMovie.movie_rental_cost = returnDecimal(txtRentalCost.Text); objMovie.copies_on_hand = Convert.ToInt16(txtCopies.Text); objMovie.image = txtImage.Text; objMovie.trailer = txtTrailer.Text; try { bool status = MovieDB.UpdateMovie(objMovie); if (status) //You can use this syntax as well..if (status ==true) { Reload_Data(); MessageBox.Show("Movie has been updated.", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Movie was not updated in database.", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void UpdateMovie(Movie movie) { mDb.UpdateMovie(movie); }