Beispiel #1
0
        private void ButtonAdd_Click(object sender, RoutedEventArgs e)
        {
            MainInfoFilm    newMainInfoFilm    = new MainInfoFilm();
            Creators        newCreators        = new Creators();
            BudgetAndFees   newBudgetAndFees   = new BudgetAndFees();
            FilmDescription newFilmDescription = new FilmDescription();
            RentalData      newRentalData      = new RentalData();
            AgeLimit        newAgeLimit        = new AgeLimit();


            newMainInfoFilm.Name              = tbName.Text;
            newMainInfoFilm.CountryCreator    = tbCountryCreator.Text;
            newMainInfoFilm.Operator          = tbOperator.Text;
            newMainInfoFilm.Genres            = tbGenres.Text;
            newMainInfoFilm.idCreators        = newCreators.ID;
            newMainInfoFilm.idFilmDescription = newFilmDescription.ID;
            newMainInfoFilm.idBudgetAndFees   = newBudgetAndFees.ID;
            newMainInfoFilm.idRentalData      = newRentalData.ID;
            newMainInfoFilm.idAgeLimit        = newAgeLimit.ID;
            MemoryStream      stream  = new MemoryStream();
            JpegBitmapEncoder encoder = new JpegBitmapEncoder();

            encoder.Frames.Add(BitmapFrame.Create((BitmapImage)imgLoad.Source));
            encoder.Save(stream);
            newMainInfoFilm.ImageMovie = stream.ToArray();

            var currentType = dbContext.db.AgeLimit.FirstOrDefault(item => item.MPAA == cmbMPAA.Text);

            newMainInfoFilm.ID = currentType.ID;

            newBudgetAndFees.Budget        = Convert.ToInt32(tbBudget.Text);
            newBudgetAndFees.WorldwideFees = Convert.ToInt32(tbWorldwideFees.Text);

            newCreators.Director = tbDirector.Text;
            newCreators.Producer = tbProducer.Text;

            newRentalData.PremiereInRussia = (DateTime)tbPremiereInRussia.SelectedDate;
            newRentalData.PremiereInWorld  = (DateTime)tbPremiereInWorld.SelectedDate;

            newFilmDescription.Description = tbDescription.Text;

            dbContext.db.BudgetAndFees.Add(newBudgetAndFees);

            dbContext.db.Creators.Add(newCreators);
            dbContext.db.AgeLimit.Add(newAgeLimit);
            dbContext.db.RentalData.Add(newRentalData);
            dbContext.db.FilmDescription.Add(newFilmDescription);
            dbContext.db.MainInfoFilm.Add(newMainInfoFilm);

            dbContext.db.SaveChanges();

            MessageBox.Show("Вы успешно добавили данные", "Уведомление", MessageBoxButton.OK, MessageBoxImage.Information);
        }
Beispiel #2
0
        // Issue  movie to customer
        private void btnIssueMovie_Click(object sender, EventArgs e)
        {
            try
            {
                string CustId, MovieId, IssueDate, ReturnDate;

                CustId     = ddlCustomer.SelectedValue.ToString();
                MovieId    = ddlMovie.SelectedValue.ToString();
                IssueDate  = dtIsuue.Value.ToShortDateString();
                ReturnDate = dtReturn.Value.ToShortDateString();

                int totalDays = Convert.ToInt32((DateTime.Parse(ReturnDate) - DateTime.Parse(IssueDate)).TotalDays);

                int RentalCost = GetMovieCost(int.Parse(MovieId)); // Getting rental cost for that movie

                int TotalRent = totalDays * RentalCost;            // Calculated the TotalRent

                if (DateTime.Parse(IssueDate) > DateTime.Parse(ReturnDate))
                {
                    MessageBox.Show("Issue date can not b greater than retun date");
                }
                else
                {
                    RentalData data = new RentalData();
                    data.CustId     = int.Parse(CustId);
                    data.MovieId    = int.Parse(MovieId);
                    data.RentedDate = DateTime.Parse(IssueDate);
                    data.ReturnDate = DateTime.Parse(ReturnDate);
                    data.TotalRent  = TotalRent;

                    if (new RentalMovieAction().RentMovie(data))
                    {
                        // Set Flag to "Rented" when movie goes on rent
                        if (new RentalMovieAction().UpdateMovieFlag(data.MovieId))
                        {
                            BindGridMovies();       //method calling to Bind Grid movies
                            BindGridRentedMovies(); //method calling to Bind Grid for all rental movies
                            BindDDLRentedMovies();  // method calling to Bind comboBox Rented movie
                            MessageBox.Show("Movie rented successfully!");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Failed to rent this movie");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        // Add Movie
        public bool RentMovie(RentalData data)
        {
            SqlCommand cmd = DataConnection.GetConnection().CreateCommand();

            cmd.CommandText = "prcRentMovie"; // stored procedure
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@MovieID", data.MovieId);
            cmd.Parameters.AddWithValue("@CustID", data.CustId);
            cmd.Parameters.AddWithValue("@RentDate", data.RentedDate);
            cmd.Parameters.AddWithValue("@ReturnDate", data.ReturnDate);
            cmd.Parameters.AddWithValue("@TotalRent", data.TotalRent);
            bool ans = cmd.ExecuteNonQuery() > 0;

            cmd.Dispose();
            return(ans);
        }
 public RentalData GetReportData(int id)
 {
     try
     {
         comm.CommandText = "[RentalByID]";
         comm.Parameters.Add("@RentalID", SqlDbType.Int).Value = id;
         comm.CommandType = CommandType.StoredProcedure;
         SqlDataAdapter adp     = new SqlDataAdapter(comm);
         DataTable      dt      = new DataTable();
         RentalData     rentals = new RentalData();
         adp.Fill(rentals.RentalsTable);
         return(rentals);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Beispiel #5
0
 public void RentalTest()
 {
     RentalData obj_Form = new RentalData();
 }