Beispiel #1
0
        // Insert Movie
        public bool InsertRentedMovie(RentedMoviesData data)
        {
            SqlCommand cmd = DataBaseConnection.OpenConnection().CreateCommand();

            cmd.CommandText = "RentThisMovie";
            cmd.CommandType = CommandType.StoredProcedure; // store procedure
            cmd.Parameters.AddWithValue("@MovieID", data.MovieId);
            cmd.Parameters.AddWithValue("@CustID", data.CustId);
            cmd.Parameters.AddWithValue("@RentDate", data.RentDate);
            cmd.Parameters.AddWithValue("@ReturnDate", data.ReturnDate);
            cmd.Parameters.AddWithValue("@TotalRent", data.TotalRentAmount);

            bool ans = cmd.ExecuteNonQuery() > 0;

            cmd.Dispose();
            return(ans);
        }
Beispiel #2
0
        //Issue movie to selected customer
        private void BtnIssueMovie_Click(object sender, EventArgs e)
        {
            try
            {
                string CustId, MovieId, IssueDate, ReturnDate;
                int    totalDays = 0;
                int    temp      = 0;
                int    TotalRent = 0;
                CustId     = DropDownSelectCustomer.SelectedValue.ToString();
                MovieId    = DropDownMovie.SelectedValue.ToString();
                IssueDate  = dtIsuue.Value.ToShortDateString();
                ReturnDate = dtReturn.Value.ToShortDateString();

                if (CustId == "" || CustId == "0" || CustId == null)
                {
                    MessageBox.Show("Please select customer");
                }
                else if (MovieId.Equals("") || MovieId == "0" || MovieId == null)
                {
                    MessageBox.Show("Please select movie");
                }

                else if (DateTime.Parse(IssueDate) > DateTime.Parse(ReturnDate))
                {
                    MessageBox.Show("Issue date can not be greater than retun date", "Alert");
                }
                else if (IssueDate == ReturnDate)
                {
                    totalDays = 1;
                    temp      = new Movies().CalculateMovieCost(int.Parse(MovieId)); // Getting rent amount for that movie

                    TotalRent = totalDays * temp;                                    // Calculate the Total Rent of issue movie
                }
                else
                {
                    totalDays = new CalculateDays().TotalDays(IssueDate, ReturnDate);

                    temp = new Movies().CalculateMovieCost(int.Parse(MovieId)); // Getting rent amount for that movie

                    TotalRent = totalDays * temp;                               // Calculate the Total Rent of issue movie
                }

                RentedMoviesData rmdata = new RentedMoviesData
                {
                    MovieId         = int.Parse(MovieId),
                    CustId          = int.Parse(CustId),
                    RentDate        = IssueDate,
                    ReturnDate      = ReturnDate,
                    TotalRentAmount = TotalRent
                };

                if (new RentedMOvies().InsertRentedMovie(rmdata))
                {
                    TabControlSystem.SelectedTab = TabControlSystem.TabPages["RentedMovies"];
                    RentedMovieGridData();
                    MessageBox.Show("Movie rented successfully!");
                }
                else
                {
                    MessageBox.Show("Failed to rent this movie!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }