/// <summary>
        /// Adds a new rating and comment to the database for the selected movie.
        /// </summary>
        private void AddRating()
        {
            //Variable Declarations.
            LimelightBusiness business = new LimelightBusiness(repository);

            try
            {
                //Insert the new movie review.
                business.AddRating((int)cmbRating.SelectedValue, (int)lstMovieList.SelectedValue, txtComment.Text);

                //Refresh the list of movies.
                movies = business.GetAllMovies();
            }
            catch (Exception ex)
            {
                //Handle the exception.
                ApplicationUtilities.CatchExceptions(ex);
                return;
            }

            //Re-display the movie information on the form.
            DisplayMovieInfo();

            cmbRating.SelectedIndex = 0;
            txtComment.Text         = "";
        }
        /// <summary>
        /// Fills the ratings combobox with the various rating levels.
        /// </summary>
        private void FillRatingsList()
        {
            //Variable Declarations.
            DataSet           movieRatings;
            LimelightBusiness business = new LimelightBusiness(repository);

            //Get the movie titles from the database.
            try
            {
                movieRatings = business.GetAllRatingTitles();
            }
            catch (Exception ex)
            {
                ApplicationUtilities.CatchExceptions(ex);
                return;
            }

            //Add the genre titles to the ratings combobox.
            DataRow emptyDataRow = movieRatings.Tables[0].NewRow();

            emptyDataRow[0] = 0;
            emptyDataRow[1] = "Select A Rating";
            movieRatings.Tables[0].Rows.InsertAt(emptyDataRow, 0);


            cmbRating.DataSource    = movieRatings.Tables[0];
            cmbRating.ValueMember   = "RatingID";
            cmbRating.DisplayMember = "RatingTitle";
        }
        private void ViewRecords_Load(object sender, EventArgs e)
        {
            //Variable Declarations.
            LimelightBusiness business = new LimelightBusiness(repository);

            //Fill the list of movies and reviews.
            try
            {
                movies = business.GetAllMovies();
            }
            catch (Exception ex)
            {
                ApplicationUtilities.CatchExceptions(ex);
                return;
            }

            //Fill the movie titles listbox.
            FillMovieList();
            lstMovieList.SelectedIndex = -1;

            //Fill the ratings combobox.
            FillRatingsList();

            //Clear the controls on the form.
            ResetForm();
        }
        /// <summary>
        /// Deletes the selected movie from the database.
        /// </summary>
        private void DeleteAMovie()
        {
            //Variable Declarations.
            LimelightBusiness business = new LimelightBusiness(repository);

            try
            {
                //Delete the selected movie.
                business.DeleteMovie((int)lstMovieList.SelectedValue);
            }
            catch (Exception ex)
            {
                //Handle the exception.
                ApplicationUtilities.CatchExceptions(ex);
            }
        }
        private void btnSaveMovie_Click(object sender, EventArgs e)
        {
            try
            {
                //Save the new movie to the data source.
                AddNewMovie();

                //Reset the form.
                ResetForm();
            }
            catch (Exception ex)
            {
                //Handle the exception.
                ApplicationUtilities.CatchExceptions(ex);
            }
        }
        private void btnUpdateMovie_Click(object sender, EventArgs e)
        {
            try
            {
                //Update the movie information.
                UpdateMovieInfo();
            }
            catch (Exception ex)
            {
                //Handle an exceptions thrown.
                ApplicationUtilities.CatchExceptions(ex);
                return;
            }

            //Fill the movie titles listbox.
            FillMovieList();

            //Reset the form.
            ResetForm();
            lstMovieList.SelectedIndex = -1;
        }
        /// <summary>
        /// Fills the movie listbox with a list of titles for all movies in the database.
        /// </summary>
        private void FillMovieList()
        {
            //Variable Declarations.
            DataSet           movieTitles;
            LimelightBusiness business = new LimelightBusiness(repository);

            //Get the movie titles from the database.
            try
            {
                movieTitles = business.GetAllMovieTitles();
            }
            catch (Exception ex)
            {
                ApplicationUtilities.CatchExceptions(ex);
                return;
            }

            //Fill the movie listbox with the movie titles.
            lstMovieList.DataSource    = movieTitles.Tables[0];
            lstMovieList.ValueMember   = "MovieID";
            lstMovieList.DisplayMember = "Title";
        }
        private void Search_Load(object sender, EventArgs e)
        {
            //Variable Declarations.
            LimelightBusiness business = new LimelightBusiness(repository);

            //Fill the list of movies and reviews.
            try
            {
                movies = business.GetAllMovies();
            }
            catch (Exception ex)
            {
                ApplicationUtilities.CatchExceptions(ex);
                return;
            }

            //Fill the genres combobox.
            FillGenreList();

            //Clear the controls on the form.
            ResetForm();
        }
        private void btnChoosePoster_Click(object sender, EventArgs e)
        {
            //Code found at:
            //  Site Name: stackoverflow.com
            //  URL: http://stackoverflow.com/questions/24449988/how-to-get-file-path-from-openfiledialog-and-folderbrowserdialog

            //Variable Declarations.
            string imagePath = "";

            //Create and display an open file dialog box.
            //OpenFileDialog choofdlog = new OpenFileDialog();
            //choofdlog.Filter = "Image Files | *.jpg; *.png; *.bmp";

            ////Get the path of the file selected.
            //if (choofdlog.ShowDialog() == DialogResult.OK)
            //{
            //    //label1.Text = choofdlog.FileName;
            //    //pbMoviePoster.Image = choofdlog.FileName;

            //    pbMoviePoster.ImageLocation = choofdlog.FileName;
            //}

            //pbMoviePoster.ImageLocation = ApplicationUtilities.ChooseImageFile();

            try
            {
                //pbMoviePoster.ImageLocation = ApplicationUtilities.ChooseImageFile();
                imagePath = ApplicationUtilities.ChooseImageFile();
                if (imagePath != "")
                {
                    pbMoviePoster.ImageLocation = imagePath;
                }
            }
            catch (Exception ex)
            {
                ApplicationUtilities.CatchExceptions(ex);
            }
        }
        private void btnSearchMovie_Click(object sender, EventArgs e)
        {
            //Variable Declarations.
            LimelightBusiness business = new LimelightBusiness(repository);
            List <Movie>      results  = new List <Movie>();

            //Validate the title if it is being used as a search criteria.
            if (chkSearchTitle.Checked == true)
            {
                try
                {
                    business.ValidateSearchTitle(txtSearchTitle.Text);
                }
                catch (Exception ex)
                {
                    //Handle an exceptions thrown.
                    ApplicationUtilities.CatchExceptions(ex);
                    return;
                }
            }

            //Validate the release date range if it is being used as a search criteria.
            if (chkSearchReleaseDate.Checked == true)
            {
                try
                {
                    business.ValidateSearchDates(dtpSearchDateFrom.Value, dtpSearchDateTo.Value);
                }
                catch (Exception ex)
                {
                    //Handle an exceptions thrown.
                    ApplicationUtilities.CatchExceptions(ex);
                    return;
                }
            }

            //Validate the release date range if it is being used as a search criteria.
            if (chkSearchGenre.Checked == true)
            {
                try
                {
                    business.ValidateSearchGenre(cmbGenre.Text);
                }
                catch (Exception ex)
                {
                    //Handle an exceptions thrown.
                    ApplicationUtilities.CatchExceptions(ex);
                    return;
                }
            }

            //Search for the movies.
            //xxx();

            //Search for the movies with that match the entered criteria.
            results = SortMovies(SearchForMovies());

            //Add the movie titles from the search result to the movie list box.
            lstMovieList.Items.Clear();
            foreach (Movie movie in results)
            {
                lstMovieList.Items.Add(movie.Title);
            }
        }