Пример #1
0
        public bool ratingBerekenen(RatingSysteem _Reken)
        {
            Settings      mySettings = new Settings();
            SqlConnection conn       = new SqlConnection(mySettings.ConnectionString);
            SqlCommand    cmd        = new SqlCommand();

            cmd.CommandType = System.Data.CommandType.Text;
            cmd.Connection  = conn;
            cmd.CommandText = "SELECT RatingTotal, RatingAmount FROM Rating WHERE ImgRatingID = @ratingID";
            cmd.Parameters.AddWithValue("@ratingID", _Reken.ratingID);

            try
            {
                conn.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    totaalAantalRating = reader.GetInt32(0);
                    aantalRating       = reader.GetInt32(1);
                }
                totaalAantalRating += userRating;
                aantalRating       += 1;
                nieuwGemRating      = totaalAantalRating / aantalRating;
                reader.Close();
                cmd.Parameters.Clear();
                cmd.CommandText = "UPDATE Rating SET Ratingtotal = @totaalRate, RatingAmount = @aantalRate, RatingAvg = @gemRating WHERE ImgRatingID = @ratingID";
                cmd.Parameters.AddWithValue("@totaalRate", _Reken.totaalAantalRating);
                cmd.Parameters.AddWithValue("@aantalRate", _Reken.aantalRating);
                cmd.Parameters.AddWithValue("@gemRating", _Reken.nieuwGemRating);
                cmd.Parameters.AddWithValue("@ratingID", _Reken.ratingID);
                cmd.ExecuteNonQuery();
                conn.Close();
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
                return(false);
            }
            finally
            {
                if (conn.State == System.Data.ConnectionState.Open)
                {
                    conn.Close();
                }
                conn.Dispose();
                cmd = null;
            }
        }
Пример #2
0
        private void clbRating_Click(object sender, EventArgs e)
        {
            int gegevenCijfer = Convert.ToInt32(clbRating.SelectedItem.ToString());

            clbRating.Visible = false;
            lblRate.Visible   = false;
            RatingSysteem rate = new RatingSysteem();

            rate.RatingID   = ratingID;
            rate.UserRating = gegevenCijfer;


            switch (gegevenCijfer)
            {
            case 1:
                if (rate.ratingBerekenen(rate))
                {
                    lblRateInfo.Visible = true;
                    lblCijfer.Visible   = true;
                    lblCijfer.Text      = Convert.ToString(rate.NeuwGemRating);
                    break;
                }
                else
                {
                    MessageBox.Show("Er is iets mis gegaan");
                    break;
                }

            case 2:
                if (rate.ratingBerekenen(rate))
                {
                    lblRateInfo.Visible = true;
                    lblCijfer.Visible   = true;
                    lblCijfer.Text      = Convert.ToString(rate.NeuwGemRating);
                    break;
                }
                else
                {
                    MessageBox.Show("Er is iets mis gegaan");
                    break;
                }

            case 3:
                if (rate.ratingBerekenen(rate))
                {
                    lblRateInfo.Visible = true;
                    lblCijfer.Visible   = true;
                    lblCijfer.Text      = Convert.ToString(rate.NeuwGemRating);
                    break;
                }
                else
                {
                    MessageBox.Show("Er is iets mis gegaan");
                    break;
                }

            case 4:
                if (rate.ratingBerekenen(rate))
                {
                    lblRateInfo.Visible = true;
                    lblCijfer.Visible   = true;
                    lblCijfer.Text      = Convert.ToString(rate.NeuwGemRating);
                    break;
                }
                else
                {
                    MessageBox.Show("Er is iets mis gegaan");
                    break;
                }

            case 5:
                if (rate.ratingBerekenen(rate))
                {
                    lblRateInfo.Visible = true;
                    lblCijfer.Visible   = true;
                    lblCijfer.Text      = Convert.ToString(rate.NeuwGemRating);
                    break;
                }
                else
                {
                    MessageBox.Show("Er is iets mis gegaan");
                    break;
                }
            }
        }