예제 #1
0
        /* Displays Average Rating and Movie ID in text boxes right of listbox */
        private void getAvgRating_movieID()
        {
            int index = this.listBox1.SelectedIndex;

            BusinessTier.Business btier = new BusinessTier.Business(this.textBox1.Text);

            // test connection to database
            if (!btier.TestConnection())
            {
                MessageBox.Show("Can't connect to the database!");
                return;
            }

            // Get ID and Average rating for the movie
            BusinessTier.Movie movie = btier.GetMovie(this.listBox1.Items[index].ToString());

            if (movie == null)
            {
                MessageBox.Show("Movie could not be found!");
            }
            else
            {
                // Movie exists, display ID and AVG rating
                BusinessTier.MovieDetail m = btier.GetMovieDetail(movie.MovieID);
                this.textBox2.Text = movie.MovieID.ToString();
                this.textBox3.Text = m.AvgRating.ToString();
            }

            // Done
            this.textBox7.Text = this.listBox1.Items[index].ToString();
        }
예제 #2
0
        // When selecting a movie in the list, retrieve its id and average rating
        private void listBox_movies_SelectedIndexChanged(object sender, EventArgs e)
        {
            string movieName = this.listBox_movies.Text;

            this.textBox_movieID.Clear();
            this.textBox_avgRating.Clear();

            string filename = this.textBox_filename.Text;

            if (!fileExists(filename))
            {
                return;
            }

            BusinessTier.Business biztier = new BusinessTier.Business(filename);
            BusinessTier.Movie    movie   = biztier.GetMovie(movieName);

            if (movie == null)
            {
                MessageBox.Show("ERROR: Movie not found!");
                return;
            }

            this.textBox_movieID.Text = movie.MovieID.ToString();
            BusinessTier.MovieDetail movieDetails = biztier.GetMovieDetail(movie.MovieID);

            if (movieDetails == null)
            {
                MessageBox.Show("ERROR: MovieID possibly corrupted!");
                return;
            }

            this.textBox_avgRating.Text = movieDetails.AvgRating.ToString();
        }
예제 #3
0
        //-----------------------------------------------------------------------------------------------------------------------------------------
        private void Reviews_Click(object sender, EventArgs e)//Movie Reviews
        {
            //textBox11: Movie Input
            //listBox1: Diplay reviews
            listBox1.Items.Clear();                 // Clear display

            string dbfilename = this.textBox3.Text; //get DB name from text box: //where the database is located

            BusinessTier.Business biztier = new BusinessTier.Business(dbfilename);

            string movie = this.textBox11.Text;     //get user’s input from where they are clicking

            BusinessTier.Movie movieObj = biztier.GetMovie(movie);

            if (movieObj == null)
            {
                MessageBox.Show("Invalid Movie");
                return;
            }

            BusinessTier.MovieDetail details = biztier.GetMovieDetail(movieObj.MovieID); // from Object browser

            listBox1.Items.Add(movie);
            listBox1.Items.Add(" ");

            foreach (var x in details.Reviews)
            {
                listBox1.Items.Add(x.UserID + ": " + x.Rating);
            }

            textBox11.Clear(); //Clear textbox
        }
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e) //movie List
        {
            string dbfilename = this.textBox1.Text;

            this.textBox2.Clear();
            this.textBox3.Clear();
            this.textBox6.Clear();
            this.textBox6.Text = this.listBox1.Text;

            BusinessTier.Business biztier = new BusinessTier.Business(dbfilename); //open object
            string moviename = this.listBox1.Text;

            BusinessTier.Movie movie = biztier.GetMovie(moviename); //obtain movie object

            if (movie == null)
            {
                MessageBox.Show("Error 404!");
            }

            else
            {
                if (!fileExists(dbfilename))
                {
                    return;
                }
                this.textBox2.Text = movie.MovieID.ToString();
                BusinessTier.MovieDetail details = biztier.GetMovieDetail(Convert.ToInt32(this.textBox2.Text));
                string rating = details.AvgRating.ToString();
                double result = Convert.ToDouble(rating);
                this.textBox3.Text = Convert.ToString(Math.Round(result, 1));
            }
        }
예제 #5
0
        private void userReviewsBUTTON_Click(object sender, EventArgs e)
        {
            this.displayLISTBOX.Items.Clear();
            //this.typeMovieNameTEXTBOX.Text = " ";

            string filename = this.filenameTEXTBOX.Text;

            BusinessTier.Business biztier = new BusinessTier.Business(filename);

            var user = biztier.GetNamedUser(this.typeUserNameTEXTBOX.Text);

            if (user == null)
            {
                MessageBox.Show("Wrong user name!");
            }
            else
            {
                displayLISTBOX.Items.Add(this.typeUserNameTEXTBOX.Text);
                displayLISTBOX.Items.Add(" ");

                BusinessTier.UserDetail userDetail = biztier.GetUserDetail(user.UserID);

                foreach (var review in userDetail.Reviews)
                {
                    BusinessTier.Movie movie = biztier.GetMovie(review.MovieID);
                    displayLISTBOX.Items.Add(movie.MovieName + " -> " + review.Rating);
                }
            }
        }
예제 #6
0
        //---------------------------------------------------------------------------------------------------------------------------


        //---------------------------------------------------------------------------------------------------------------------------
        //
        // Get User Reviews
        //
        private void button4_Click(object sender, EventArgs e)
        {
            // Clear list box
            this.lstUserReviews.Items.Clear();

            // Wait for user to select a user
            if (this.lstUsers.SelectedIndex < 0)
            {
                MessageBox.Show("Please select a user...");
                return;
            }

            // Get user name
            string username = this.lstUsers.Text;

            // Check if user is not found, display error message
            if (username == null)
            {
                MessageBox.Show("User not found");
                return;
            }


            int userID = System.Int32.Parse(this.txtUserID.Text);

            this.lstUserReviews.Items.Add(username);
            this.lstUserReviews.Items.Add("");



            BusinessTier.Business biztier = new BusinessTier.Business(this.txtDatabase.Text);

            BusinessTier.UserDetail details = biztier.GetUserDetail(userID);

            // No reviews
            if (details == null)
            {
                MessageBox.Show("No Reviews");
                return;
            }

            var reviews = details.Reviews;

            // Display movie name and rating
            foreach (var review in reviews)
            {
                BusinessTier.Movie movie = biztier.GetMovie(review.MovieID);

                string line = string.Format("{0} -> {1}", movie.MovieName, review.Rating);
                this.lstUserReviews.Items.Add(line);
            }
        }
예제 #7
0
        private void button4_Click(object sender, EventArgs e)// insert Review
        {
            //textBox6: User
            //textBox7: Movie
            //textBox8: Rating
            //addReview(int,int,int);

            string dbfilename = this.textBox3.Text;   //get DB name from text box: //where the database is located

            BusinessTier.Business biztier = new BusinessTier.Business(dbfilename);


            string username = this.textBox6.Text;   //get user input from user
            string movie    = this.textBox7.Text;   //get movie input from user
            string rating   = this.textBox8.Text;   //get rating input from user

            BusinessTier.Movie movieObj = biztier.GetMovie(movie);
            BusinessTier.User  userObj  = biztier.GetNamedUser(username);

            if (userObj == null)
            {
                MessageBox.Show("Invalid Username");
                return;
            }
            else if (movieObj == null)
            {
                MessageBox.Show("Invalid Movie");
                return;
            }
            else if (Convert.ToInt32(rating) < 1 || Convert.ToInt32(rating) > 5)
            {
                MessageBox.Show("Rating must be 1 <= 5");
                return;
            }
            else
            {
                var x = biztier.AddReview(movieObj.MovieID, userObj.UserID, Convert.ToInt32(rating));

                if (x == null)
                {
                    MessageBox.Show("fail");
                }
            }


            this.textBox6.Clear();
            this.textBox7.Clear();
            this.textBox8.Clear();
        }
        //
        // 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)
        {
            // MOVIE OBJECT ----------------------------------------------------------------------------
            BusinessTier.Movie Movie = GetMovie(MovieID);
            // -----------------------------------------------------------------------------------------

            // AVG RATING ------------------------------------------------------------------------------
            double avgRating;
            string sql   = string.Format(@"SELECT AVG(CAST(Rating as float)) FROM Reviews WHERE MovieID = {0};", MovieID);
            object query = dataTier.ExecuteScalarQuery(sql);

            if (query.ToString() != "")
            {
                avgRating = Convert.ToDouble(query.ToString());
            }
            else
            {
                avgRating = 0.0;
            }
            // -----------------------------------------------------------------------------------------

            // NUM OF REVIEWS --------------------------------------------------------------------------
            sql   = string.Format(@"SELECT Count(MovieID) FROM Reviews WHERE MovieID = {0};", MovieID);
            query = dataTier.ExecuteScalarQuery(sql);
            int numReviews = Convert.ToInt32(query.ToString());
            // -----------------------------------------------------------------------------------------

            // BUILDING LIST OF REVIEWS ----------------------------------------------------------------
            List <Review> reviews = new List <Review>();

            // HARVESTS ALL DATA WE NEED EXCEPT MOVIEID (ALREADY HAVE)
            sql = string.Format(@"SELECT DISTINCT ReviewID, Rating, UserID FROM Reviews WHERE MovieID = {0} ORDER BY Rating DESC, ReviewID ASC;", MovieID);
            DataSet reviewsSet = dataTier.ExecuteNonScalarQuery(sql);

            foreach (DataRow row in reviewsSet.Tables["TABLE"].Rows)
            {
                reviews.Add(new BusinessTier.Review(Convert.ToInt32(row["ReviewID"]),
                                                    MovieID,
                                                    Convert.ToInt32(row["UserID"]),
                                                    Convert.ToInt32(row["Rating"])));
            }
            // -----------------------------------------------------------------------------------------


            BusinessTier.MovieDetail MovieDetail = new BusinessTier.MovieDetail(Movie, avgRating, numReviews, reviews);

            return(MovieDetail);
        }
예제 #9
0
        //--------------------------------------------------------------------------------------------------------------------------------------------------------------
        // GetMovie: Retrieves Movie object based on MOVIE ID; returns null if movie is not found.
        public Movie GetMovie(int MovieID)
        {
            string sql    = string.Format(@"Select MovieName from Movies where MovieID = {0} ;", MovieID);//search for MovieName with MovieID
            Object result = dataTier.ExecuteScalarQuery(sql);

            if (result == null)
            {
                return(null);
            }
            else
            {
                string             displayResult = Convert.ToString(result);
                BusinessTier.Movie test          = new BusinessTier.Movie(MovieID, displayResult);
                return(test);
            }
        }
        //
        // GetMovie:
        //
        // Retrieves Movie object based on MOVIE ID; returns null if movie is not
        // found.
        //
        public Movie GetMovie(int MovieID)
        {
            string sql = string.Format(@"SELECT MovieName FROM Movies WHERE MovieID = {0};", MovieID);

            object query = dataTier.ExecuteScalarQuery(sql); // Query returns object with MovieName

            if (query == null)
            {
                return(null);
            }

            string MovieName = query.ToString();                                   // Turns object to string

            BusinessTier.Movie Movie = new BusinessTier.Movie(MovieID, MovieName); // Creates new Movie object needed to return

            return(Movie);
        }
예제 #11
0
        //
        // Get Movie Name:  from id...
        //
        private void cmdGetMovieName_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();

            int id = Convert.ToInt32(txtMovieID.Text);  //converts string to integer

            BusinessTier.Movie m = businesstier.GetMovie(id);

            if (m == null)
            {
                listBox1.Items.Add("Movie not found...");
            }
            else
            {
                listBox1.Items.Add(m.MovieName);
            }
        }
예제 #12
0
        /* Displays all of the users reviews in a listbox */
        public void getAllUserReviews()
        {
            int index = this.listBox1.SelectedIndex;

            BusinessTier.Business btier = new BusinessTier.Business(this.textBox1.Text);

            // test connection to database
            if (!btier.TestConnection())
            {
                MessageBox.Show("Can't connect to the database!");
                return;
            }

            // Get user if the user exists
            BusinessTier.User user = btier.GetNamedUser(this.listBox1.Items[index].ToString());

            if (user == null)
            {
                MessageBox.Show("User does not exist!");
                return;
            }
            else
            {
                // Get all of the users reviews
                this.listBox2.Items.Clear();
                BusinessTier.UserDetail userDetails = btier.GetUserDetail(user.UserID);

                if (userDetails.NumReviews == 0)
                {
                    this.listBox2.Items.Add("No Reviews");
                }
                else
                {
                    // For all reviews, get movie name + rating and insert
                    this.listBox2.Items.Add(user.UserName);
                    this.listBox2.Items.Add("");

                    foreach (BusinessTier.Review U in userDetails.Reviews)
                    {
                        BusinessTier.Movie m = btier.GetMovie(U.MovieID);
                        this.listBox2.Items.Add(m.MovieName + "->" + U.Rating);
                    }
                }
            }
        }
        //
        // GetMovie:
        //
        // Retrieves Movie object based on MOVIE NAME; returns null if movie is not
        // found.
        //
        public Movie GetMovie(string MovieName)
        {
            string sql = string.Format(@"SELECT MovieID FROM Movies WHERE MovieName = '{0}';", MovieName.Replace("'", "''"));

            object query = dataTier.ExecuteScalarQuery(sql);

            if (query == null)
            {
                return(null);
            }

            string MovieID = query.ToString();

            MovieName.Replace("''", "'");
            BusinessTier.Movie Movie = new BusinessTier.Movie(Int32.Parse(MovieID), MovieName);

            return(Movie);
        }
예제 #14
0
        //-----------------------------------------------------------------------------------------------------------------------------------------
        private void button5_Click(object sender, EventArgs e)// Top N Movies
        {
            //get top movies by N + ratings
            //textBox9 is N

            listBox2.Items.Clear();// clear display

            var test = this.textBox9.Text;

            if (test == null)//no number added check
            {
                MessageBox.Show("Please insert a number");
                return;
            }

            string dbfilename = this.textBox3.Text;   //get DB name from text box: //where the database is located

            BusinessTier.Business biztier = new BusinessTier.Business(dbfilename);

            //string username = this.listBox2.Text;     //get user’s input from where they are clicking
            //BusinessTier.User user = biztier.GetNamedUser(username); //obtain user object

            int number = Convert.ToInt32(this.textBox9.Text);//invalid number check

            if (number < 0)
            {
                MessageBox.Show("Invalid number!");
                return;
            }

            var topMovies = biztier.GetTopMoviesByAvgRating(Convert.ToInt32(this.textBox9.Text));

            foreach (var x in topMovies)
            {
                BusinessTier.Movie       movie  = biztier.GetMovie(x.MovieName);
                BusinessTier.MovieDetail movie2 = biztier.GetMovieDetail(movie.MovieID);

                var review = movie2.AvgRating;

                listBox2.Items.Add(x.MovieName + ":" + review);
            }

            this.textBox9.Clear();
        }
예제 #15
0
        /* Inserts a rating into the database */
        private void insert_movieRating_Click(object sender, EventArgs e)
        {
            // Check that a movie was selected
            if (string.IsNullOrWhiteSpace(this.textBox7.Text))
            {
                MessageBox.Show("Please select a Movie from the list!");
                return;
            }

            // Check that a Username was selected
            if (string.IsNullOrWhiteSpace(this.textBox4.Text))
            {
                MessageBox.Show("Please select a Username from the list!");
                return;
            }

            // Check that Rating is valid
            int    rating      = 0;
            string s           = this.textBox5.Text;
            bool   validRating = int.TryParse(s, out rating);

            if (!(validRating && (rating <= 5) && (rating >= 1)))
            {
                MessageBox.Show("Please enter a rating between 1 and 5!");
                return;
            }

            // test connection to database
            BusinessTier.Business btier = new BusinessTier.Business(this.textBox1.Text);

            if (!btier.TestConnection())
            {
                MessageBox.Show("Can't connect to the database!");
                return;
            }

            // Get movie ID and user ID
            BusinessTier.Movie M = btier.GetMovie(this.textBox7.Text);
            BusinessTier.User  U = btier.GetNamedUser(this.textBox4.Text);

            // Insert review
            btier.AddReview(M.MovieID, U.UserID, rating);
            MessageBox.Show("Review was succesfully inserted!");
        }
예제 #16
0
        //-----------------------------------------------------------------------------------------------------------------------------------------
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //ListBox1: User's selection
            //textBox1: ID
            //textBox2: Average rating

            string dbfilename = this.textBox3.Text;   //get DB name from text box: //where the database is located

            BusinessTier.Business biztier = new BusinessTier.Business(dbfilename);

            string moviename = this.listBox1.Text;                                   //get user’s input from where they are clicking

            BusinessTier.Movie movie = biztier.GetMovie(moviename);                  //  obtain movie object:

            BusinessTier.MovieDetail movie2 = biztier.GetMovieDetail(movie.MovieID); // from Object browser

            this.textBox1.Text = "" + movie.MovieID;

            this.textBox2.Text = "" + movie2.AvgRating; //from Object browser
        }
예제 #17
0
        private void InsertReview_Click(object sender, EventArgs e)
        {
            if (!fileExists(filename))
            {
                return;
            }
            if (!connectionTest(filename))
            {
                return;
            }
            if (this.ListDisplay.SelectedIndex < 0)
            {
                MessageBox.Show("Please select a movie...");
                return;
            }
            if (this.ListDisplay2.SelectedIndex < 0)
            {
                MessageBox.Show("Please select a user...");
                return;
            }
            if (this.RatingBox.SelectedIndex < 0)
            {
                MessageBox.Show("Please select a rating...");
                return;
            }

            filename = this.txtFilename.Text;
            BusinessTier.Business biztier = new BusinessTier.Business(filename);

            string movieId = MovieIdBox.Text;      // MovieNameBox.Text;
            string userId  = userIdBox.Text;
            string rating  = RatingBox.Text;

            BusinessTier.Movie movie = biztier.GetMovie(Convert.ToInt32(movieId));
            BusinessTier.User  user  = biztier.GetUser(Convert.ToInt32(userId));

            if (movie == null)
            {
                MessageBox.Show(String.Format("ID: {0} not found..!", movieId)); return;
            }
            else if (user == null)
            {
                MessageBox.Show(String.Format("ID: {0} not found..!", userId)); return;
            }

            int rate = Convert.ToInt32(rating);

            if (rate < 1 || rate > 5)
            {
                MessageBox.Show("Rating is not in range..!"); return;
            }

            var result = biztier.AddReview(movie.MovieID, user.UserID, rate);

            if (result == null)
            {
                MessageBox.Show("Insert failed...");
            }
            else
            {
                MessageBox.Show(String.Format("Insert Success with new Review ID: {0}", result.ReviewID.ToString()));
            }
        }
예제 #18
0
        private void eachRating_Click(object sender, EventArgs e)//each rating
        {
            //listBox1: Display results
            //textBox12: movie Input
            listBox1.Items.Clear();                 // clear the display

            string dbfilename = this.textBox3.Text; //get DB name from text box: //where the database is located

            BusinessTier.Business biztier = new BusinessTier.Business(dbfilename);

            string movie = this.textBox12.Text;     //get user’s input from where they are clicking

            BusinessTier.Movie movieObj = biztier.GetMovie(movie);


            if (movieObj == null)
            {
                MessageBox.Show("Invalid Movie");
                return;
            }

            BusinessTier.MovieDetail details = biztier.GetMovieDetail(movieObj.MovieID); // from Object browser


            listBox1.Items.Add(movie);
            listBox1.Items.Add(" ");

            int x5 = 0;
            int x4 = 0;
            int x3 = 0;
            int x2 = 0;
            int x1 = 0;
            int x0 = 0;

            foreach (var x in details.Reviews)
            {
                if (x.Rating == 5)
                {
                    x5 = x5 + 1;
                }
                else if (x.Rating == 4)
                {
                    x4 = x4 + 1;
                }
                else if (x.Rating == 3)
                {
                    x3 = x3 + 1;
                }
                else if (x.Rating == 2)
                {
                    x2 = x2 + 1;
                }
                else
                {
                    x1 = x1 + 1;
                }

                x0 = x0 + 1; //total
            }

            listBox1.Items.Add("5: " + x5);
            listBox1.Items.Add("4: " + x4);
            listBox1.Items.Add("3: " + x3);
            listBox1.Items.Add("2: " + x2);
            listBox1.Items.Add("1: " + x1);
            listBox1.Items.Add(" ");
            listBox1.Items.Add("Total: " + x0);

            textBox12.Clear();//clear textbox
        }
예제 #19
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            String dbfilename = this.textBox1.Text;

            /* if (!fileExists(filename))
             *   return;*/

            this.Cursor = Cursors.WaitCursor;

            //clearForm();

            /*SqlConnection db;
             * String version = "MSSQLLocalDB";
             * //filename = "CrimeDB.mdf";
             * String connectionInfo = String.Format(@"Data Source=(LocalDB)\{0};AttachDbFilename=|DataDirectory|\{1};Integrated Security=True;", version, filename);
             * db = new SqlConnection(connectionInfo);
             * db.Open();
             * string Name = this.listBox1.Text;
             * Name = Name.Replace("'", "''");
             * string sql = string.Format(@"SELECT MovieID FROM Movies where Movies.MovieName= '{0}';", Name);
             * SqlCommand cmd = new SqlCommand();
             * cmd.Connection = db;
             * SqlDataAdapter adapter = new SqlDataAdapter(cmd);
             * DataSet ds = new DataSet();
             *
             * cmd.CommandText = sql;
             * object result = cmd.ExecuteScalar();*/
            BusinessTier.Business biztier = new BusinessTier.Business(dbfilename);
            if (!biztier.TestConnection())
            {
                return;
            }
            //if (textBox5.Text.Length == 0) return;
            //int movieID = Convert.ToInt32(textBox5.Text);

            string Name = this.listBox1.Text;

            BusinessTier.Movie details = biztier.GetMovie(Name);

            //var reviews = details.Reviews;


            int id = Convert.ToInt32(details.MovieID);

            textBox5.Text = Convert.ToString(id);

            /*sql = string.Format(@"SELECT Rating FROM Reviews, Movies where Movies.MovieName= '{0}' And Movies.MovieID= Reviews.MovieID;", Name);
             *
             * cmd = new SqlCommand();
             * cmd.Connection = db;
             * adapter = new SqlDataAdapter(cmd);
             * ds = new DataSet();
             *
             * cmd.CommandText = sql;
             * adapter.Fill(ds);
             * List<Double> numbers = new List<double>();
             * foreach (DataRow row in ds.Tables["TABLE"].Rows)
             * {
             *  Double rate = Convert.ToDouble(row["Rating"]);
             *  numbers.Add(rate);
             *  //movienames = string.Format("{0}", (string)(row["MovieName"]));
             *  //listBox1.Items.Add(movienames);
             * }
             * if (numbers.Count == 0)
             * {
             *  this.Cursor = Cursors.Default;
             *
             *  return;
             * }*/

            BusinessTier.MovieDetail movieDetail = biztier.GetMovieDetail(id);


            Double average = movieDetail.AvgRating;

            textBox2.Text = average.ToString();
            //db.Close();

            getmoviereviews();

            this.Cursor = Cursors.Default;

            /*int UN= 233;
             *
             * BusinessTier.Business biztier = new BusinessTier.Business(filename);
             * BusinessTier.Movie m = biztier.GetMovie(UN);
             *
             * textBox16.Text = m.MovieName;*/
        }
예제 #20
0
        private void listLISTBOX_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (LIST_STATUS != 3)
            {
                this.displayLISTBOX.Items.Clear();
            }

            string filename = this.filenameTEXTBOX.Text;

            BusinessTier.Business biztier = new BusinessTier.Business(filename);

            if (LIST_STATUS == 1)           // movie button
            {
                if (this.listLISTBOX != null)
                {
                    // movie name
                    var movie = biztier.GetMovie(this.listLISTBOX.Text);
                    movieIdTEXTBOX.Text = movie.MovieID.ToString();
                    //typeMovieNameTEXTBOX.Text = movie.MovieName.ToString();
                    typeMovieNameTEXTBOX.Text = "";
                    typeUserNameTEXTBOX.Text  = "";

                    // avg rating
                    var movie2 = biztier.GetMovieDetail(movie.MovieID);
                    avgRatingTEXTBOX.Text = movie2.AvgRating.ToString();


                    displayLISTBOX.Items.Add(this.listLISTBOX.Text);
                    displayLISTBOX.Items.Add(" ");

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

                    foreach (var review in movieDetail.Reviews)
                    {
                        displayLISTBOX.Items.Add(review.UserID + ": " + review.Rating);
                    }
                }
            }
            else if (LIST_STATUS == 2)      // user button
            {
                if (this.listLISTBOX != null)
                {
                    // user id
                    var user = biztier.GetNamedUser(this.listLISTBOX.Text);
                    userIdTEXTBOX.Text = user.UserID.ToString();
                    //typeUserNameTEXTBOX.Text = user.UserName.ToString();
                    typeMovieNameTEXTBOX.Text = "";
                    typeUserNameTEXTBOX.Text  = "";

                    // occupation
                    occupationTEXTBOX.Text = user.Occupation.ToString();


                    displayLISTBOX.Items.Add(this.listLISTBOX.Text);
                    displayLISTBOX.Items.Add(" ");

                    BusinessTier.UserDetail userDetail = biztier.GetUserDetail(user.UserID);

                    foreach (var review in userDetail.Reviews)
                    {
                        BusinessTier.Movie movie = biztier.GetMovie(review.MovieID);
                        displayLISTBOX.Items.Add(movie.MovieName + " -> " + review.Rating);
                    }
                }
            }
            else if (LIST_STATUS == 3)
            {
                insertReviewMovieTEXTBOX.Text = this.listLISTBOX.Text;
            }
        }
예제 #21
0
        /* When the user clicks a movie name in the listbox, a different listbox
         * displays all of its ratings, a third listbox displays statistics about the ratings */
        private void getAllMovieRatings()
        {
            int index = this.listBox1.SelectedIndex;

            BusinessTier.Business btier = new BusinessTier.Business(this.textBox1.Text);

            // test connection to database
            if (!btier.TestConnection())
            {
                MessageBox.Show("Can't connect to the database!");
                return;
            }

            // Get the movie and all of it's ratings
            BusinessTier.Movie movie = btier.GetMovie(this.listBox1.Items[index].ToString());

            if (movie == null)
            {
                MessageBox.Show("Movie does not exist!");
                return;
            }
            else
            {
                // Display ratings and count ratings
                int[] ratings = new int[] { 0, 0, 0, 0, 0, 0 };
                this.listBox2.Items.Clear();
                BusinessTier.MovieDetail movieDetails = btier.GetMovieDetail(movie.MovieID);

                if (movieDetails.NumReviews == 0)
                {
                    this.listBox2.Items.Add("No Reviews");
                }
                else
                {
                    // For all reviews, get User ID + Rating and insert
                    this.listBox2.Items.Add(movie.MovieName);
                    this.listBox2.Items.Add("");

                    foreach (BusinessTier.Review R in movieDetails.Reviews)
                    {
                        this.listBox2.Items.Add(R.UserID + ": " + R.Rating);
                        countRating(ref ratings, R.Rating);
                    }
                }

                // Display the rating counts
                int ratingsTotal = 0;
                this.listBox3.Items.Clear();
                this.listBox3.Items.Add(movie.MovieName);
                this.listBox3.Items.Add("");

                for (int i = 1; i <= 5; ++i)
                {
                    this.listBox3.Items.Add(i + ":" + ratings[i]);
                    ratingsTotal += ratings[i];
                }

                this.listBox3.Items.Add("");
                this.listBox3.Items.Add("Total: " + ratingsTotal);
            }
        }