Esempio n. 1
0
        public bool extractImage(imgUpload _Extract)
        {
            Settings      mySettings = new Settings();
            SqlConnection conn       = new SqlConnection(mySettings.ConnectionString);
            SqlCommand    cmd        = new SqlCommand();

            cmd.CommandType = CommandType.Text;
            cmd.Connection  = conn;
            cmd.CommandText = "SELECT CategorieID FROM Categorie WHERE CategorieNaam = @Naam";
            cmd.Parameters.AddWithValue("@Naam", _Extract.categorie);


            try
            {
                conn.Open();
                randomCat = Convert.ToInt32(cmd.ExecuteScalar());
                cmd.Parameters.Clear();
                cmd.CommandText = "SELECT img,UserNaam, Rating.ImgRatingID FROM Foto INNER JOIN Users ON Foto.UserID = Users.UserID INNER JOIN Rating ON Rating.ImgRatingID = Foto.ImgRatingID WHERE CategorieID = @CatID ";
                cmd.Parameters.AddWithValue("@CatID", _Extract.randomCat);
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    long   size  = reader.GetBytes(0, 0, null, 0, 0);
                    byte[] image = new byte[size];
                    reader.GetBytes(0, 0, image, 0, (int)size);
                    picture = (Bitmap)((new ImageConverter()).ConvertFrom(image));
                    rGif.Add(picture);
                    userNaam = reader.GetString(1);
                    gifUser.Add(userNaam);
                    ratingID = reader.GetInt32(2);
                    picRating.Add(ratingID);
                }
                conn.Close();
                return(true);
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
                return(false);
            }

            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                cmd = null;
            }
        }
Esempio n. 2
0
        private void btnImgUpload_Click(object sender, EventArgs e)
        {
            imgUpload uploadImg = new imgUpload();

            uploadImg.Naam    = tbNaam.Text.Trim();
            uploadImg.photo   = pbSelectedIMG.Image;
            uploadImg.CatNaam = cbCategorie.Text;
            uploadImg.UserID  = Convert.ToInt32(lblUserID.Text);

            if (uploadImg.AddImage(uploadImg))
            {
                MessageBox.Show("Gif Added Succesfully");
            }
        }
Esempio n. 3
0
        public bool AddImage(imgUpload _Image)
        {
            Settings      mySettings = new Settings();
            SqlConnection conn       = new SqlConnection(mySettings.ConnectionString);
            SqlCommand    cmd        = new SqlCommand();

            cmd.CommandType = CommandType.Text;
            cmd.Connection  = conn;
            cmd.CommandText = "SELECT CategorieID FROM Categorie WHERE CategorieNaam = @Naam";
            cmd.Parameters.AddWithValue("@Naam", _Image.catNaam);


            try
            {
                conn.Open();
                catID = Convert.ToInt32(cmd.ExecuteScalar());
                cmd.Parameters.Clear();
                cmd.CommandText = "INSERT INTO Rating (RatingTotal) OUTPUT INSERTED.ImgRatingID VALUES (@ratingWaarde)";
                cmd.Parameters.AddWithValue("@ratingWaarde", _Image.ratingWaarde);
                ratingID        = Convert.ToInt32(cmd.ExecuteScalar());
                cmd.CommandText = "INSERT INTO Foto (Naam, img,CategorieID, UserID, ImgRatingID) VALUES(@Naam,@img,@CatID,@UserID,@RatingID)";
                cmd.Parameters.AddWithValue("@Naam", _Image.Naam);
                cmd.Parameters.AddWithValue("@img", imageToByteArray(_Image.photo));
                cmd.Parameters.AddWithValue("CatID", _Image.catID);
                cmd.Parameters.AddWithValue("@UserID", _Image.userID);
                cmd.Parameters.AddWithValue("@RatingID", _Image.ratingID);
                cmd.ExecuteNonQuery();
                conn.Close();
                return(true);
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
                return(false);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                cmd = null;
                conn.Dispose();
            }
        }
Esempio n. 4
0
        private void btnExtract_Click(object sender, EventArgs e)
        {
            try
            {
                UncheckAllItems();
                imgUpload extractImg = new imgUpload();
                extractImg.categorie = cbCategorieKies.Text;
                gbRating.Visible     = true;
                lblCijfer.Visible    = false;
                lblRateInfo.Visible  = false;
                lblRate.Visible      = true;
                clbRating.Visible    = true;


                if (cbCategorieKies.Text == "Kies Categorie")
                {
                    MessageBox.Show("Selecteer aub een categorie");
                }
                else
                {
                    if (extractImg.extractImage(extractImg))
                    {
                        Random rnd     = new Random();
                        int    randGif = rnd.Next(0, extractImg.rGif.Count);
                        pbExtract.Image  = extractImg.rGif.ElementAt(randGif);
                        tbImgInfo.Text   = "This picture was uploaded by " + extractImg.gifUser.ElementAt(randGif);
                        gbRating.Visible = true;
                        ratingID         = extractImg.picRating.ElementAt(randGif);
                    }
                }
            }
            catch (ArgumentOutOfRangeException)
            {
                MessageBox.Show("Deze categorie heeft nog geen gifs, u kunt er zelf in toevoegen door er een te uploaden.");
                pbExtract.Image  = null;
                gbRating.Visible = false;
                tbImgInfo.Clear();
            }
        }