private void btnAdd_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();
            objMovie.genre_id          = ((Genre)cbGenre.SelectedItem).ID.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.AddMovie(objMovie);
                if (status) //You can use this syntax as well..if (status ==true)
                {
                    MessageBox.Show("Movie added to the database.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Movie was not added to database.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!(validateUI(btnAdd)))
            {
                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.AddMovie(myMovie);
                if (status) //returns true
                {
                    MessageBox.Show("Movie added to the database.", "MeramecNetFlix", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //Automatically refresh the data grid
                    this.btnBrowse_Click(null, null);
                }
                else //returns false
                {
                    MessageBox.Show("Movie was not added to the database.", "MeramecNetFlix", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //Automatically refresh the data grid
                    this.btnBrowse_Click(null, null);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "MeramecNetFlix", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 private void btn_Add_Click(object sender, EventArgs e)
 {
     try
     {
         Movie m = GetMovieObjFromUI();
         if (m != null)
         {
             if (MovieDB.AddMovie(m))
             {
                 MessageBox.Show("Add Successful.");
             }
             else
             {
                 MessageBox.Show("Add 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);
     }
 }
Beispiel #4
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            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.Trim())
                {
                    genreid = genre.ID;
                }
            }



            Movie objMovie = new Movie();

            objMovie.movie_number      = Convert.ToInt32(txtMovieNumber.Text);
            objMovie.movie_title       = txtTitle.Text.ToString();
            objMovie.Description       = txtDescription.Text.ToString();
            objMovie.movie_year_made   = Convert.ToInt32(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.ToInt32(txtCopies.Text);
            objMovie.image             = txtImage.Text;
            objMovie.trailer           = txtTrailer.Text;

            //if(lblPicture.Text != string.Empty)
            //{
            //    objMember.photo = lblPicture.Text;
            //}


            try
            {
                bool status = MovieDB.AddMovie(objMovie);
                if (status) //You can use this syntax as well..if (status ==true)
                {
                    Reload_Data();
                    MessageBox.Show("Movieadded to the database.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Movie was not added to database.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 public void AddMovie(Movie movie)
 {
     mDb.AddMovie(movie);
 }