//Add new movie to the database. public bool addMovie(Movie movie, MetroComboBox cmbMovieRating) { //Inserts information to movie. string DDL = "insert into Movie(Movie_Name, Movie_Rating) values('" + movie.getSetMovieName + "','" + movie.getSetMovieRating + "')"; OleDbCommand command = new OleDbCommand(DDL, database.getSetCon()); //Validates the variables first. if (validateName(movie) && validateRating(cmbMovieRating) && validateListing()) { database.runCommand(command); //Executes the SQL statement - adds new movie return true; } //Validation failed else { return false; } }
//Validate movie name. private bool validateName(Movie movie) { //Ensures that it the field isn't empty. if (movie.getSetMovieName != "") { //Checks to see if the length is greater than 50. if(movie.getSetMovieName.Length > 50) { MetroMessageBox.Show(form, "Movie name can only be 50 characters long.", "Invalid Movie Name", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } //Length is less than 50. else { return true; } } //Field is empty else { MetroMessageBox.Show(form, "Please enter the name of the movie", "Invalid Movie Name", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } }
//Deletes a certain row in the grid. public void deleteData(Movie movie, int rowIndex) { //Removes the row from the grid. grid.Rows.RemoveAt(rowIndex); //Deletes a row from the movie database. string DDL = "DELETE FROM movie WHERE movie_id = " + movie.getSetMovieID; OleDbCommand command = new OleDbCommand(DDL, database.getSetCon()); database.runCommand(command); //Execute SQL statement }