private void btnReturn_Click(object sender, EventArgs e) { Rental returnMovie = new Rental(); Movie find = new Movie(); int selected = 0; try { selected = dgvRental.CurrentCell.RowIndex; if (current[selected].MediaReturnDate == "") { returnMovie = current[selected]; int findNumber = Convert.ToInt32(returnMovie.MovieNumber); find = MovieCRUD.FindMovie(findNumber); int copies = Convert.ToInt32(find.OnHand) + 1; Rental.ReturnMovie(activeMember, returnMovie, copies); } else { MessageBox.Show("You have aready returned this movie"); } } catch(Exception ex) { MessageBox.Show(ex.Message); Rental.UpdateOnHand(find); current = Rental.GetInfo(activeMember); dgvRental.DataSource = current; } }
public static void AddRental(Movie rent, Member renter) { string connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|Database.mdf;Integrated Security=True;Connect Timeout=30"; SqlCommand objCommand; int rowsAffected; string sqlCommand = "INSERT into RENTAL values (@MovieNumber, @MemberNumber, @MediaCheckOutDate, @MediaExpReturnDate, @MediaReturnDate, @RentalCost)"; using (SqlConnection objConn = new SqlConnection(connectionString)) { objConn.Open(); using (objCommand = new SqlCommand(sqlCommand, objConn)) { DateTime current = DateTime.Now; string turnIn = current.AddDays(5.0).ToString("MM-dd-yyyy"); string checkout = current.ToString("MM-dd-yyyy"); objCommand.Parameters.AddWithValue("@MovieNumber", rent.MovieNumber); objCommand.Parameters.AddWithValue("@MemberNumber", renter.MemberNumber); objCommand.Parameters.AddWithValue("@MediaCheckOutDate", checkout); objCommand.Parameters.AddWithValue("@MediaReturnDate", Convert.DBNull); objCommand.Parameters.AddWithValue("@MediaExpReturnDate", turnIn); objCommand.Parameters.AddWithValue("@RentalCost", rent.RentalCost); rowsAffected = objCommand.ExecuteNonQuery(); if (rowsAffected < 1) { throw new Exception("Error"); } else { throw new Exception("You will recieve your movie tomorrow!"); } } } }
public static void GetBoxArt(Movie movieToFind) { string movieName = movieToFind.MovieTitle; string moviePage = SearchArt(movieName); string boxArt = FindBoxArt(moviePage); MovieCRUD.AddBoxArt(movieName, boxArt); }
private void MoviePage_Load(object sender, EventArgs e) { activeMember = (Member)this.Tag; currentMovie = (Movie)LoadMovie; asfMovie.Movie = currentMovie.Trailer; lblTitle.Text = currentMovie.MovieTitle; lblDate.Text = currentMovie.YearMade; rtbDescription.Text = currentMovie.Description; lblRating.Text = currentMovie.MovieRating; lblGenre.Text = currentMovie.GenreId; lblOnHand.Text = currentMovie.OnHand; }
public static bool AddMovie(Movie addMovie) { //TODO: Briefly Show CRUD //Connect too SQL DATABASE string connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|Database.mdf;Integrated Security=True;Connect Timeout=30";; //Create a command object SqlCommand objCommand; int rowsAffected; //command to execute on database string sqlCommand = "INSERT into Movie (MovieTitle, Description, MovieYearMade, GenreID, MovieRating, MediaType, RentalCost, CopiesOnHand) values (@MovieTitle, @Description, @MovieYearMade, @GenreID, @MovieRating, @MediaType, @RentalCost, @CopiesOnHand)"; using (SqlConnection objConn = new SqlConnection(connectionString)) { //open connection objConn.Open(); //create command object using (objCommand = new SqlCommand(sqlCommand, objConn)) { DateTime currentTime = DateTime.Now; //objCommand.Parameters.AddWithValue("@MovieNumber", addMovie.MovieNumber); objCommand.Parameters.AddWithValue("@MovieTitle", addMovie.MovieTitle); objCommand.Parameters.AddWithValue("@Description", addMovie.Description); objCommand.Parameters.AddWithValue("@MovieYearMade", addMovie.YearMade); objCommand.Parameters.AddWithValue("@GenreID", addMovie.GenreId); objCommand.Parameters.AddWithValue("@MovieRating", addMovie.MovieRating); objCommand.Parameters.AddWithValue("@MediaType", addMovie.MediaType); objCommand.Parameters.AddWithValue("@MovieRetailCost", addMovie.RetailCost); objCommand.Parameters.AddWithValue("@RentalCost", addMovie.RentalCost); objCommand.Parameters.AddWithValue("@CopiesOnHand", addMovie.OnHand); //test how many rows affected rowsAffected = objCommand.ExecuteNonQuery(); if (rowsAffected < 1) { throw new Exception("Incorrect"); } else { throw new Exception("Successfully Added"); } } } }
public static void UpdateMovie(Movie updateMovie) { //Connect too SQL DATABASE string connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|Database.mdf;Integrated Security=True;Connect Timeout=30";; //Create a command object SqlCommand objCommand; int rowsAffected; //command to execute on database string sqlCommand = "UPDATE Movie SET MovieTitle=@MovieTitle, Description=@Description, MovieYearMade=@MovieYearMade, MovieRating=@MovieRating, MediaType=@MediaType, MovieRetailCost=@MovieRetailCost, RentalCost=@RentalCost, CopiesOnHand=@OnHand, trailer=@trailer, image=@image WHERE MovieNumber=@MovieNumber"; using (SqlConnection objConn = new SqlConnection(connectionString)) { //open connection objConn.Open(); //create command object using (objCommand = new SqlCommand(sqlCommand, objConn)) { DateTime currentTime = DateTime.Now; objCommand.Parameters.AddWithValue("@MovieNumber", updateMovie.MovieNumber); objCommand.Parameters.AddWithValue("@MovieTitle", updateMovie.MovieTitle); objCommand.Parameters.AddWithValue("@Description", updateMovie.Description); objCommand.Parameters.AddWithValue("@MovieYearMade", updateMovie.YearMade); objCommand.Parameters.AddWithValue("@MovieRating", updateMovie.MovieRating); objCommand.Parameters.AddWithValue("@MediaType", updateMovie.MediaType); objCommand.Parameters.AddWithValue("@MovieRetailCost", updateMovie.RetailCost); objCommand.Parameters.AddWithValue("@RentalCost", updateMovie.RentalCost); objCommand.Parameters.AddWithValue("@OnHand", updateMovie.OnHand); objCommand.Parameters.AddWithValue("@image", updateMovie.Image); objCommand.Parameters.AddWithValue("@trailer", updateMovie.Trailer); //test how many rows affected rowsAffected = objCommand.ExecuteNonQuery(); if (rowsAffected < 1) { throw new Exception("Incorrect"); } else { throw new Exception("Successfully Updated"); } } } }
public static List<Movie> GetMovieList(string optionalSort) { // connection string string connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|Database.mdf;Integrated Security=True;Connect Timeout=30";; //command object SqlCommand objCommand; //sql string command string command = "SELECT MovieNumber, MovieTitle, Description, MovieYearMade, g.GenreName, MovieRating, MediaType, MovieRetailCost, RentalCost, CopiesOnHand, image, trailer FROM Movie as m inner join GENRE as g on m.GenreID=g.GenreID "+ optionalSort; //sql reader SqlDataReader movieReader = null; //return member List<Movie> lsMovie = new List<Movie>(); using (SqlConnection objConn = new SqlConnection(connectionString)) { //open sesame objConn.Open(); using (objCommand = new SqlCommand(command, objConn)) { using (movieReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)) { while (movieReader.Read()) { Movie objMovie = new Movie(); objMovie.MovieNumber = movieReader["MovieNumber"].ToString(); objMovie.MovieTitle = movieReader["MovieTitle"].ToString(); objMovie.Description = movieReader["Description"].ToString(); objMovie.YearMade = movieReader["MovieYearMade"].ToString(); objMovie.GenreId = movieReader["GenreName"].ToString(); objMovie.MediaType = movieReader["MediaType"].ToString(); objMovie.MovieRating = movieReader["MovieRating"].ToString(); objMovie.RetailCost = movieReader["MovieRetailCost"].ToString(); objMovie.RentalCost = movieReader["RentalCost"].ToString(); objMovie.OnHand = movieReader["CopiesOnHand"].ToString(); objMovie.Image = movieReader["image"].ToString(); objMovie.Trailer = movieReader["trailer"].ToString(); lsMovie.Add(objMovie); } return lsMovie; } } } }
public static Movie FindMovie(int findMovieNumber) { // connection string string connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|Database.mdf;Integrated Security=True;Connect Timeout=30";; //command object SqlCommand objCommand; //sql string command string command = "SELECT MovieNumber, MovieTitle, Description, MovieYearMade, GenreID, MovieRating, MediaType, MovieRetailCost, RentalCost, CopiesOnHand, image, trailer FROM MOVIE where MovieNumber=@MovieNumber"; //sql reader SqlDataReader movieReader = null; //return member Movie objMovie = new Movie(); int movieNumber = 0; using(SqlConnection objConn = new SqlConnection(connectionString)) { //open sesame objConn.Open(); using(objCommand = new SqlCommand(command, objConn)) { objCommand.Parameters.AddWithValue("@MovieNumber", findMovieNumber); using (movieReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)) { while(movieReader.Read()) { movieNumber = Convert.ToInt32(movieReader["MovieNumber"]); if(movieNumber == findMovieNumber) { objMovie.MovieNumber = movieReader["MovieNumber"].ToString(); objMovie.MovieTitle = movieReader["MovieTitle"].ToString(); objMovie.Description = movieReader["Description"].ToString(); objMovie.YearMade = movieReader["MovieYearMade"].ToString(); objMovie.GenreId = movieReader["GenreID"].ToString(); objMovie.MovieRating = movieReader["MovieRating"].ToString(); objMovie.MediaType = movieReader["MediaType"].ToString(); objMovie.RetailCost = movieReader["MovieRetailCost"].ToString(); objMovie.RentalCost = movieReader["RentalCost"].ToString(); objMovie.OnHand = movieReader["CopiesOnHand"].ToString(); objMovie.Image = movieReader["image"].ToString(); objMovie.Trailer = movieReader["trailer"].ToString(); // return objMovie; } } throw new Exception("No movie found"); } } } }
public static void UpdateOnHand(Movie update) { int onHand = Convert.ToInt32(update.OnHand) + 1; int movieNumber = Convert.ToInt32(update.MovieNumber); string connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|Database.mdf;Integrated Security=True;Connect Timeout=30"; SqlCommand objCommand; string command = "UPDATE MOVIE SET CopiesOnHand=@copies WHERE MovieNumber=@MovieNumber"; int rowsAffected; using (SqlConnection objConn = new SqlConnection(connectionString)) { objConn.Open(); using (objCommand = new SqlCommand(command, objConn)) { objCommand.Parameters.AddWithValue("@copies", onHand); objCommand.Parameters.AddWithValue("@MovieNumber", movieNumber); rowsAffected = objCommand.ExecuteNonQuery(); } } }
public static void GetTrailer(Movie find) { string movieName = find.MovieTitle; string moviePage = SearchTrailer(movieName); MovieCRUD.AddTrailer(movieName, moviePage); }
private void btnAddMovie_Click(object sender, EventArgs e) { Movie addMovie = new Movie(); if (TestMovieInput()) { var skip = 0; addMovie.GenreId = Convert.ToString((int)cboGenre.SelectedItem); addMovie.MovieTitle = txtMovieTitle.Text.Trim(); addMovie.YearMade = txtMovieYearMade.Text.Trim(); addMovie.MovieRating = txtMovieRating.Text.Trim(); addMovie.Description = txtMovieDescription.Text.Trim(); addMovie.MediaType = cboMediaType.Text.Trim(); addMovie.RetailCost = txtMovieRetailCost.Text.Trim(); addMovie.RentalCost = txtMovieRentalCost.Text.Trim(); addMovie.OnHand = txtMovieOnHand.Text.Trim(); try { MovieCRUD.AddMovie(addMovie); if (!chkTrailer.Checked) { MovieCRUD.AddTrailer(addMovie.MovieTitle, txtMovieTrailer.Text); skip = 1; } if (!chkImage.Checked) { MovieCRUD.AddBoxArt(addMovie.MovieTitle, txtMovieImage.Text); skip += 2; } } catch (Exception ex) { MessageBox.Show(ex.Message); } //TODO: Show TPL if(skip != 3) { var scrapingTask = new Task(() => { if(skip != 1) { try { Scraper.GetTrailer(addMovie); } catch (Exception ex) { var output = ex.Message; } } if(skip != 2) { try { Scraper.GetBoxArt(addMovie); } catch (Exception ex) { var output = ex.Message; } } }); scrapingTask.Start(); } } }
private void btnFindMovie_Click(object sender, EventArgs e) { string testFind = txtMovieNumber.Text.Trim(); int movieNumberFind = 0; bool change = Int32.TryParse(testFind, out movieNumberFind); Movie findMovie = new Movie(); try { if (change) { findMovie = MovieCRUD.FindMovie(movieNumberFind); cboGenre.Text = findMovie.GenreId; txtMovieRating.Text = findMovie.MovieRating; txtMovieTitle.Text = findMovie.MovieTitle; txtMovieDescription.Text = findMovie.Description; txtMovieOnHand.Text = findMovie.OnHand; txtMovieRentalCost.Text = findMovie.RentalCost; txtMovieRetailCost.Text = findMovie.RetailCost; txtMovieYearMade.Text = findMovie.YearMade; cboMediaType.Text = findMovie.MediaType; txtMovieImage.Text = findMovie.Image; txtMovieTrailer.Text = findMovie.Trailer; } else { MessageBox.Show("Enter a valid number"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }