예제 #1
0
        }//txtInsertBox

        //
        // Instert Review :
        //
        private void addReview_Click(object sender, EventArgs e)
        {
            if (this.txtInsertBox.Text == "")
            {
                MessageBox.Show("Please select a Movie name , User Name and enter Review..");
                return;
            }
            if (this.lstMovies.SelectedIndex < 0)
            {
                MessageBox.Show("Please select a movie...");
                return;
            }
            if (this.lstUserName.SelectedIndex < 0)
            {
                MessageBox.Show("Please select a UserName...");
                return;
            }


            int input = System.Int32.Parse(this.txtInsertBox.Text);

            if (input < 0 || input > 5)
            {
                MessageBox.Show("Please enter Rating between 1 to 5...");
                return;
            }


            int movieid = System.Int32.Parse(this.textMovieID.Text);
            int userid  = System.Int32.Parse(this.txtUserID.Text);


            BusinessTier.Business biztier = new BusinessTier.Business(this.txtDatabase.Text);
            BusinessTier.Review   review  = biztier.AddReview(movieid, userid, input);

            MessageBox.Show("Review is added...");


            //this.lstReviews.Items.Add(review.UserID.ToString());
            //this.lstReview1.Items.Add(review.MovieID.ToString());
        }//end of the insert review event:
예제 #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            string dbfilename = this.textBox1.Text;

            BusinessTier.Business biztier = new BusinessTier.Business(dbfilename);
            if (!biztier.TestConnection())
            {
                return;
            }
            if (textBox5.Text.Length == 0)
            {
                return;
            }

            int movieID = Convert.ToInt32(textBox5.Text);

            if (textBox6.Text.Length == 0)
            {
                return;
            }

            int userID = Convert.ToInt32(textBox6.Text);

            if (comboBox1.Text.Length == 0)
            {
                return;
            }

            int rating = Convert.ToInt32(comboBox1.Text);

            BusinessTier.Review review = biztier.AddReview(movieID, userID, rating);

            if (review == null)
            {
                MessageBox.Show("Failed");
            }
            else
            {
                MessageBox.Show("Success");
            }
        }
예제 #3
0
        private void button6_Click(object sender, EventArgs e)
        {
            String dbfilename = this.dbname.Text; // get DB name from text box:

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

            if (biztier.TestConnection())
            {
                int mid, uid, rating;
                if (this.listBox1.SelectedIndex < 0)
                {
                    MessageBox.Show("Please select a movie");
                    return;
                }
                else
                {
                    mid = Convert.ToInt32(this.textBox9.Text);
                }
                if (this.listBox2.SelectedIndex < 0)
                {
                    MessageBox.Show("Please select a user");
                    return;
                }
                else
                {
                    uid = Convert.ToInt32(this.textBox1.Text);
                }
                if (this.textBox6.Text.Length == 0)
                {
                    MessageBox.Show("Please enter a rating");
                    return;
                }
                else
                {
                    rating = Convert.ToInt32(this.textBox6.Text);
                }

                if (rating < 1 || rating > 5)
                {
                    MessageBox.Show("Rating must range from 1-5");
                    return;
                }
                else
                {
                    BusinessTier.Review newreview = biztier.AddReview(mid, uid, rating);
                    if (newreview != null)
                    {
                        MessageBox.Show("Success!");
                        return;
                    }
                    else
                    {
                        MessageBox.Show("Failed to add review");
                        return;
                    }
                }
            }
            else
            {
                MessageBox.Show("Connection could not be established");
                return;
            }
        }
예제 #4
0
        private void insertReviewBUTTON_Click(object sender, EventArgs e)
        {
            string insertMovie  = insertReviewMovieTEXTBOX.Text;
            string insertUser   = insertReviewUserTEXTBOX.Text;
            string insertRating = insertReviewRatingTEXTBOX.Text;
            int    insertRate;

            bool m = false;
            bool u = false;
            bool r = false;

            if (int.TryParse(insertReviewRatingTEXTBOX.Text, out insertRate))
            {
                if (insertRate >= 1 && insertRate <= 5)
                {
                    r = true;
                }
            }
            else
            {
                MessageBox.Show("Input ERROR");
            }

            // Check to make sure database filename in text box actually exists:
            string filename = this.filenameTEXTBOX.Text;

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

            // check movie name exist
            string        version, connectionInfo;
            SqlConnection db;

            version        = "MSSQLLocalDB";
            connectionInfo = String.Format(@"Data Source=(LocalDB)\{0};AttachDbFilename=|DataDirectory|\{1};Integrated Security=True;", version, filename);

            db = new SqlConnection(connectionInfo);
            db.Open();

            string sql = string.Format(@"SELECT MovieName FROM Movies ORDER BY MovieName ASC;");

            SqlCommand cmd = new SqlCommand();

            cmd.Connection = db;
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataSet        ds      = new DataSet();

            cmd.CommandText = sql;
            adapter.Fill(ds);

            db.Close();

            foreach (DataRow row in ds.Tables["TABLE"].Rows)
            {
                string msg = string.Format("{0}", Convert.ToString(row["MovieName"]));

                if (msg == insertMovie)
                {
                    m = true;
                }
            }

            // check user exist
            SqlConnection db2;

            version        = "MSSQLLocalDB";
            connectionInfo = String.Format(@"Data Source=(LocalDB)\{0};AttachDbFilename=|DataDirectory|\{1};Integrated Security=True;", version, filename);

            db2 = new SqlConnection(connectionInfo);
            db2.Open();

            string sql2 = string.Format(@"SELECT UserName FROM Users ORDER BY UserName ASC;");

            SqlCommand cmd2 = new SqlCommand();

            cmd2.Connection = db2;
            SqlDataAdapter adapter2 = new SqlDataAdapter(cmd2);
            DataSet        ds2      = new DataSet();

            cmd2.CommandText = sql2;
            adapter2.Fill(ds2);

            db2.Close();

            foreach (DataRow row in ds2.Tables["TABLE"].Rows)
            {
                string msg = string.Format("{0}", Convert.ToString(row["UserName"]));

                if (msg == insertUser)
                {
                    u = true;
                }
            }

            // insert if valid
            if (m && u && r)
            {
                BusinessTier.Business biztier = new BusinessTier.Business(filename);

                var insUser = biztier.GetNamedUser(insertUser);
                int userID  = insUser.UserID;

                var insMovie = biztier.GetMovie(insertMovie);
                int movieID  = insMovie.MovieID;

                BusinessTier.Review newReview = biztier.AddReview(movieID, userID, insertRate);

                if (newReview != null)
                {
                    MessageBox.Show("Insert Successful");
                }
                else
                {
                    MessageBox.Show("Fail inserting");
                }
            }
            else
            {
                MessageBox.Show("Input ERROR");
            }
        }