internal bool testToRent(RentMovie rentInfo) { bool rent1 = false; rent1 = rentalInfoModel.testToRent(rentInfo); return(rent1); }
internal DataGridView fillRentalHistoryDataGrid(DataGridView rentalHistoryDataGrid) { DataTable dt = new DataTable(); RentMovie rentMovie = new RentMovie(); { string connectionString = ConfigurationManager.ConnectionStrings["MovieRental"].ConnectionString; using (var connection = new SqlConnection(connectionString)) { try { connection.Open(); List <String> data = new List <string>(); SqlCommand cmd = new SqlCommand(@"SELECT RENTAL.CUSTOMER_ID, CUSTOMER_INFO.CUSTOMER_FNAME, CUSTOMER_INFO.CUSTOMER_LNAME, RENTAL.MOVIE_ID, MOVIE_INFO.MOVIE_TITLE, RENTAL.DATE_RENTED, RENTAL.DATE_RETURNED FROM RENTAL, MOVIE_INFO, CUSTOMER_INFO WHERE RENTAL.CUSTOMER_ID = CUSTOMER_INFO.CUSTOMER_ID AND RENTAL.MOVIE_ID = MOVIE_INFO.MOVIE_ID ORDER BY RENTAL.MOVIE_ID, RENTAL.DATE_RENTED DESC" , connection); SqlDataReader reader = cmd.ExecuteReader(); dt.Load(reader); SqlDataAdapter adapter = new SqlDataAdapter(cmd); adapter.Fill(dt); rentalHistoryDataGrid.AutoGenerateColumns = true; rentalHistoryDataGrid.AutoResizeRows(); rentalHistoryDataGrid.AutoResizeColumns(); rentalHistoryDataGrid.DataSource = dt; rentalHistoryDataGrid.DataMember = dt.TableName; reader.Close(); } catch (Exception y) { MessageBox.Show(y.Message); } finally { connection.Close(); } } } return(rentalHistoryDataGrid); }
internal bool testToRent(RentMovie rent) { bool canRent = true; bool movieAllreadyCheckedOut = false; int numberOfRentals = 0; string connectionString = ConfigurationManager.ConnectionStrings["MovieRental"].ConnectionString; string queryString1 = @"SELECT COUNT (*) FROM RENTAL WHERE CUSTOMER_ID = @CUSTOMER_ID AND DATE_RENTED IS NOT NULL AND DATE_RETURNED IS NULL OR DATE_RETURNED LIKE ' '"; string queryString2 = @"SELECT RENTED FROM MOVIE_INFO WHERE MOVIE_ID = @MOVIE_ID"; using (var connection = new SqlConnection(connectionString)) { SqlCommand cmd2 = new SqlCommand(queryString1, connection); SqlCommand cmd3 = new SqlCommand(queryString2, connection); try { connection.Open(); cmd2.Parameters.AddWithValue("@CUSTOMER_ID", rent.customerID); numberOfRentals = (int)cmd2.ExecuteScalar(); if (numberOfRentals >= 3) { canRent = false; } cmd3.Parameters.AddWithValue("@MOVIE_ID", rent.movieID); movieAllreadyCheckedOut = (bool)(cmd3.ExecuteScalar()); if (movieAllreadyCheckedOut == true) { canRent = false; } } catch (Exception e) { MessageBox.Show("Caught this exception: " + e.Message); } finally { connection.Close(); } return(canRent); } }
internal static void returnMovie(RentMovie rentMovie) { string connectionString = ConfigurationManager.ConnectionStrings["MovieRental"].ConnectionString; string queryString = @"UPDATE MOVIE_INFO set RENTED = @RENTED WHERE MOVIE_ID = @MOVIE_ID"; using (var connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand cmd2 = new SqlCommand(queryString, connection); try { bool rented = false; cmd2.Parameters.AddWithValue("@MOVIE_ID", rentMovie.movieID); cmd2.Parameters.AddWithValue("@RENTED", rented); cmd2.ExecuteNonQuery(); } catch { MessageBox.Show("Did not add back to inventory"); } try { string queryString1 = @"UPDATE RENTAL SET DATE_RETURNED = @DATE_RETURNED WHERE MOVIE_ID = @MOVIE_ID AND CUSTOMER_ID = @CUSTOMER_ID"; cmd2 = new SqlCommand(queryString1, connection); cmd2.Parameters.AddWithValue("@DATE_RETURNED", rentMovie.dateReturned); cmd2.Parameters.AddWithValue("@MOVIE_ID", rentMovie.movieID); cmd2.Parameters.AddWithValue("@CUSTOMER_ID", rentMovie.customerID); cmd2.ExecuteNonQuery(); MessageBox.Show("Movie " + rentMovie.movieID + ": " + rentMovie.movieTitle + " was successfully returned."); connection.Close(); } catch (Exception e) { MessageBox.Show(e.Message); connection.Close(); } } }
private void returnMovieBtn_Click(object sender, EventArgs e) { bool allEntered = false; while (allEntered == false) { if (customer_IDTextBox.Text.Equals("") || dateReturnedTextBx.Text.Equals("") || movie_IDTextBox.Text.Equals("")) { MessageBox.Show("You are returning a movie but either the Customer ID, " + "Movie ID or Date Returned fields are blank. Please fill in all fields to continue."); allEntered = false; return; } else { allEntered = true; } } int convertedRentalID = rentalController.convertedText(movie_IDTextBox.Text); int convertedClientID = rentalController.convertedText(customer_IDTextBox.Text); bool ischecked = false; RentMovie rentMovie = new RentMovie() { customerID = convertedClientID, movieID = convertedRentalID, movieTitle = movieTitleTextBx.Text, dateRented = newdateRentedTxtBx.Text, dateReturned = dateReturnedTextBx.Text, rented = ischecked }; rentalController.returnMovie(rentMovie); this.mOVIE_INFOTableAdapter.Fill(this.mOVIESDataSet1.MOVIE_INFO); // TODO: This line of code loads data into the 'mOVIESDataSet.MOVIE_INFO' table. You can move, or remove it, as needed. this.mOVIE_INFOTableAdapter.Fill(this.mOVIESDataSet.MOVIE_INFO); // TODO: This line of code loads data into the 'mOVIESDataSet.RENTAL' table. You can move, or remove it, as needed. this.rENTALTableAdapter.Fill(this.mOVIESDataSet.RENTAL); clearAll(); }
internal void RentMovie(RentMovie rentMovie) { string connectionString = ConfigurationManager.ConnectionStrings["MovieRental"].ConnectionString; string queryString1 = @"UPDATE Movie_INFO set RENTED = @RENTED WHERE MOVIE_ID = @MOVIEID"; string queryString2 = @"INSERT INTO RENTAL (CUSTOMER_ID, MOVIE_ID,DATE_RENTED) VALUES (@CUSTOMERID,@MOVIEID,@DATE_RENTED)"; string queryString3 = @"SELECT MOVIE_TITLE FROM MOVIE_INFO WHERE MOVIE_ID = @MOVIE_ID"; using (var connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand cmd2 = new SqlCommand(queryString1, connection); try { cmd2.Parameters.AddWithValue("@RENTED", rentMovie.rented); cmd2.Parameters.AddWithValue("@MOVIEID", rentMovie.movieID); cmd2.ExecuteNonQuery(); SqlCommand cmd3 = new SqlCommand(queryString2, connection); cmd3.Parameters.AddWithValue("@CUSTOMERID", rentMovie.customerID); cmd3.Parameters.AddWithValue("@MOVIEID", rentMovie.movieID); cmd3.Parameters.AddWithValue("@DATE_RENTED", rentMovie.dateRented); cmd3.ExecuteNonQuery(); SqlCommand cmd4 = new SqlCommand(queryString3, connection); cmd4.Parameters.AddWithValue("@MOVIE_ID", rentMovie.movieID); MessageBox.Show(rentMovie.movieID + ": " + rentMovie.movieTitle + " has been rented by " + rentMovie.customerID); } catch (Exception e) { MessageBox.Show(e.Message); connection.Close(); } finally { connection.Close(); } } }
private void rentBtn_Click_1(object sender, EventArgs e) { bool requiredFieldsFilled = false; while (requiredFieldsFilled == false) { if (movie_IDTextBox.Text.Equals("") || customer_IDTextBox.Text.Equals("")) { MessageBox.Show("You have stated the movie is being checked out. Either the Customer ID or" + "Date Rented fields are blank. Please fill in both fields to continue."); requiredFieldsFilled = false; return; } else { requiredFieldsFilled = true; } } int convertedRentalID = rentalController.convertedText(movie_IDTextBox.Text); int convertedClientID = rentalController.convertedText(customer_IDTextBox.Text); bool ischecked = false; if (rentedChkBx.Checked) { ischecked = true; } RentMovie rentMovie = new RentMovie() { customerID = convertedClientID, movieID = convertedRentalID, movieTitle = movieTitleTextBx.Text, dateRented = newdateRentedTxtBx.Text, rented = ischecked }; bool canRent = false; canRent = rentalController.testToRent(rentMovie); if (canRent == false) { MessageBox.Show("The movie is already rented or the customer " + "already has 3 movies rented. They cannot rent this title."); } else { rentalController.RentMovie(rentMovie); rentedChkBx.Checked = true; } this.mOVIE_INFOTableAdapter.Fill(this.mOVIESDataSet1.MOVIE_INFO); // TODO: This line of code loads data into the 'mOVIESDataSet.MOVIE_INFO' table. You can move, or remove it, as needed. this.mOVIE_INFOTableAdapter.Fill(this.mOVIESDataSet.MOVIE_INFO); // TODO: This line of code loads data into the 'mOVIESDataSet.RENTAL' table. You can move, or remove it, as needed. this.rENTALTableAdapter.Fill(this.mOVIESDataSet.RENTAL); //clearAll(); }
internal void saveFileRentalHistory() { RentMovie rentMovie = new RentMovie(); int rentalID = 0; int customerID = 0; int movieID = 0; string movieTitle = null; string dateRented = null; Object dateReturned = null; string cid = null; string rid = null; string txt = null; SaveFileDialog save = new SaveFileDialog(); save.Title = "Open File"; save.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"; if (save.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string connectionString = ConfigurationManager.ConnectionStrings["MovieRental"].ConnectionString; using (var connection = new SqlConnection(connectionString)) { try { connection.Open(); List <String> data = new List <string>(); SqlCommand cmd = new SqlCommand(@"SELECT RENTAL.RENTAL_ID,RENTAL.CUSTOMER_ID, RENTAL.MOVIE_ID, MOVIE_INFO.MOVIE_TITLE, RENTAL.DATE_RENTED, RENTAL.DATE_RETURNED FROM RENTAL INNER JOIN MOVIE_INFO ON RENTAL.MOVIE_ID = MOVIE_INFO.MOVIE_ID ORDER BY RENTAL.MOVIE_ID, RENTAL.DATE_RENTED DESC", connection); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { rentalID = (int)reader["RENTAL_ID"]; rid = rentalID.ToString(); data.Add(rid); customerID = (int)reader["CUSTOMER_ID"]; cid = customerID.ToString(); data.Add(cid); movieID = (int)reader["MOVIE_ID"]; string mid = movieID.ToString(); data.Add(mid); movieTitle = (string)reader["MOVIE_TITLE"]; data.Add(rentMovie.movieTitle); dateRented = (string)reader["DATE_RENTED"]; data.Add(rentMovie.dateRented); dateReturned = reader["DATE_RETURNED"]; if (dateReturned == null) { dateReturned = DBNull.Value; } data.Add(rentMovie.dateReturned); if (!dateReturned.Equals(DBNull.Value)) { txt += rid + ";" + cid + ";" + mid + ";" + movieTitle + ";" + dateRented + ";" + dateReturned + "\n"; } else { txt += rid + ";" + cid + ";" + mid + ";" + movieTitle + ";" + dateRented + "\n"; } } StreamWriter sw = new StreamWriter(File.Create(save.FileName)); { sw.WriteLine(txt); sw.Dispose(); } reader.Close(); } catch (Exception y) { MessageBox.Show(y.Message); } finally { connection.Close(); } } }//end of if save dialog }
internal void movieList() { RentMovie rentMovie = new RentMovie(); int movieID = 0; string movieTitle = null; string dateRented = null; bool rented = true; string cid = null; string rid = null; string txt = null; SaveFileDialog save = new SaveFileDialog(); save.Title = "Open File"; save.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"; if (save.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string connectionString = ConfigurationManager.ConnectionStrings["MovieRental"].ConnectionString; using (var connection = new SqlConnection(connectionString)) { try { connection.Open(); List <String> data = new List <string>(); SqlCommand cmd = new SqlCommand(@"SELECT * FROM MOVIE_INFO ORDER BY MOVIE_ID", connection); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { movieID = (int)reader["MOVIE_ID"]; string mid = movieID.ToString(); data.Add(mid); movieTitle = (string)reader["MOVIE_TITLE"]; data.Add(rentMovie.movieTitle); rented = (bool)reader["RENTED"]; string rent = rented.ToString(); data.Add(rent); if (!rent.Equals("False")) { txt += mid + ";" + movieTitle + ";" + "0" + "\n"; } else { txt += mid + ";" + movieTitle + ";" + "1" + "\n"; } } StreamWriter sw = new StreamWriter(File.Create(save.FileName)); { sw.WriteLine(txt); sw.Dispose(); } reader.Close(); } catch (Exception y) { MessageBox.Show(y.Message); } finally { connection.Close(); } } }//end of if save dialog }
internal void returnMovie(RentMovie rentMovie) { RentalInfoModel.returnMovie(rentMovie); }
internal void RentMovie(RentMovie rentMovie) { rentalInfoModel.RentMovie(rentMovie); }