Exemplo n.º 1
0
        private void topNAvg_Click(object sender, EventArgs e)
        {
            this.secondBox.Items.Clear();
            int    Nth        = Convert.ToInt32(topN.Text);
            string dbfilename = this.txtDatabase.Text;

            BusinessTier.Business biztier = new BusinessTier.Business(dbfilename);
            BusinessTier.Movie    movie   = biztier.GetMovie(this.movieBox.Text);


            var list = (List <Movie>)biztier.GetTopMoviesByAvgRating(Nth);


            foreach (var i in list)
            {
                secondBox.Items.Add(string.Format("{0}: {1}", i.MovieName, (biztier.GetMovieDetail(i.MovieID).AvgRating)));
            }
        }
Exemplo n.º 2
0
        private void lstMovies_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.txtMovieID.Items.Clear();
            this.movieRating.Items.Clear();
            this.userID.Items.Clear();
            this.occupation.Items.Clear();
            this.secondBox.Items.Clear();

            string dbfilename = this.txtDatabase.Text;

            BusinessTier.Business biztier = new BusinessTier.Business(dbfilename);
            BusinessTier.User     user    = biztier.GetNamedUser(this.lstMovies.Text);
            BusinessTier.Movie    movie   = biztier.GetMovie(this.lstMovies.Text);

            if (user == null)
            {
                this.txtMovieID.Items.Add(string.Format("{0}", movie.MovieID));
                var details = biztier.GetMovieDetail(movie.MovieID);
                this.movieRating.Items.Add(string.Format("{0}", details.AvgRating));


                BusinessTier.MovieDetail detail = biztier.GetMovieDetail(movie.MovieID);

                foreach (BusinessTier.Review i in detail.Reviews)
                {
                    this.secondBox.Items.Add(string.Format("{0}: {1}", i.UserID, i.Rating));
                }
            }

            if (movie == null)
            {
                this.userID.Items.Add(string.Format("{0}", user.UserID));
                this.occupation.Items.Add(string.Format("{0}", user.Occupation));

                BusinessTier.UserDetail detail = biztier.GetUserDetail(user.UserID);
                foreach (BusinessTier.Review i in detail.Reviews)
                {
                    var movieName = biztier.GetMovie(i.MovieID);
                    this.secondBox.Items.Add(string.Format("{0}-> {1}", movieName.MovieName, i.Rating));
                }
            }
        }
Exemplo n.º 3
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            // string username = this.namebox.Text;
            string rate       = this.comboBox1.Text;
            string dbfilename = this.txtDatabase.Text;

            BusinessTier.Business biztier = new BusinessTier.Business(dbfilename);
            BusinessTier.Movie    movie   = biztier.GetMovie(this.movieBox.Text);
            BusinessTier.User     user    = biztier.GetNamedUser(this.namebox.Text);


            if (movie != null && user != null && (Convert.ToInt32(rate)) <= 5 && (Convert.ToInt32(rate)) > 0)
            {
                biztier.AddReview(Convert.ToInt32(movie.MovieID), Convert.ToInt32(user.UserID), Convert.ToInt32(rate));
            }

            else
            {
                MessageBox.Show("invalid input");
            }
        }
Exemplo n.º 4
0
        //
        // GetMovieDetail:
        //
        // Given a MOVIE ID, returns detailed information about this movie --- all
        // the reviews, the total number of reviews, average rating, etc.  If the
        // movie cannot be found, null is returned.
        //
        public MovieDetail GetMovieDetail(int MovieID)
        {
            // SQL Query
            string SQL = string.Format("SELECT MovieID FROM Movies WHERE MovieID = '{0}';", MovieID);

            // Execute Query
            var Q1 = dataTier.ExecuteScalarQuery(SQL);

            if (Q1 == null)
            {
                // SQL Query fails, return null
                return(null);
            }
            else
            {
                List <Review> review_List = new List <Review>();

                // SQL Query
                string SQL2 = string.Format(@"SELECT ROUND(AVG(CAST(Rating AS float)),4) FROM Reviews
                                           Inner Join
                                           (
                                           SELECT MovieID From Movies
	                                       WHERE MovieID = '{0}'
                                           ) AS M
                                           On M.MovieID = Reviews.MovieID", MovieID);

                // Execute Query
                var Q2 = dataTier.ExecuteScalarQuery(SQL2);

                double avg;

                // Check if no average rating is found
                if (Q2.ToString() == "")
                {
                    // Average rating = 0
                    avg = 0;
                }
                else
                {
                    avg = Convert.ToDouble(Q2);
                }

                // SQL Query
                string SQL3 = string.Format(@"SELECT * 
                                           FROM Movies 
                                           WHERE MovieID = '{0}'", MovieID);

                // Execute Query
                var Q3 = dataTier.ExecuteNonScalarQuery(SQL3);
                var t  = Q3.Tables["TABLE"].Rows[0];

                // SQL Query
                string SQL4 = string.Format(@"SELECT COUNT(ReviewID) 
                                           FROM Reviews
                                           WHERE MovieID = '{0}'", MovieID);

                // Execute Query
                var Q4  = dataTier.ExecuteScalarQuery(SQL4);
                int sum = System.Int32.Parse(Q4.ToString());

                Movie m = new Movie(MovieID, t["MovieName"].ToString());

                // SQL Query
                string SQL5 = string.Format(@"SELECT * 
                                           FROM Reviews 
                                           WHERE MovieID = {0}
                                           ORDER BY Rating DESC, UserID ASC", MovieID);

                // Execute Query
                var Q5 = dataTier.ExecuteNonScalarQuery(SQL5);

                Review R;

                // Add to list
                foreach (DataRow rowFour in Q5.Tables["TABLE"].Rows)
                {
                    int review_id = System.Int32.Parse(rowFour["ReviewID"].ToString());
                    int user_id   = System.Int32.Parse(rowFour["UserID"].ToString());
                    int rating    = System.Int32.Parse(rowFour["Rating"].ToString());
                    R = new Review(review_id, MovieID, user_id, rating);
                    review_List.Add(R);
                }

                MovieDetail details = new MovieDetail(m, avg, sum, review_List);

                return(details);
            }
        }
Exemplo n.º 5
0
        private void eachRating_Click(object sender, EventArgs e)
        {
            this.secondBox.Items.Clear();
            string dbfilename = this.txtDatabase.Text;

            BusinessTier.Business biztier = new BusinessTier.Business(dbfilename);
            BusinessTier.User     user    = biztier.GetNamedUser(this.lstMovies.Text);
            BusinessTier.Movie    movie   = biztier.GetMovie(this.lstMovies.Text);



            if (user == null)
            {
                var           bb      = biztier.GetMovieDetail(biztier.GetMovie(Convert.ToInt32(movie.MovieID)).MovieID).Reviews;
                List <Review> ListRev = new List <Review>();
                foreach (var f in bb)
                {
                    ListRev.Add(f);
                }

                int one = 0, two = 0, three = 0, four = 0, five = 0;

                foreach (var b in ListRev)
                {
                    if (b.Rating == 1)
                    {
                        one++;
                    }

                    if (b.Rating == 2)
                    {
                        two++;
                    }

                    if (b.Rating == 3)
                    {
                        three++;
                    }

                    if (b.Rating == 4)
                    {
                        four++;
                    }

                    if (b.Rating == 5)
                    {
                        five++;
                    }
                }

                int totel = one + two + three + four + five;
                secondBox.Items.Add(string.Format("{0}", movie.MovieName));
                secondBox.Items.Add(string.Format(" "));
                secondBox.Items.Add(string.Format("5: {0}", five));
                secondBox.Items.Add(string.Format("4: {0}", four));
                secondBox.Items.Add(string.Format("3: {0}", three));
                secondBox.Items.Add(string.Format("2: {0}", two));
                secondBox.Items.Add(string.Format("1: {0}", one));
                secondBox.Items.Add(string.Format("Totel: {0}", totel));
            }

            else
            {
                MessageBox.Show("Please select a Movie from the movie list");
            }
        }