Example #1
0
        public static int PromeniFotografiju1(Fotografija f)
        {
            using (SqlConnection konekcija = new SqlConnection(Konekcija.cnnFotografija))
            {
                using (SqlCommand komanda = new SqlCommand("PromeniFotografiju1", konekcija))
                {
                    komanda.CommandType = CommandType.StoredProcedure;

                    try
                    {
                        komanda.Parameters.AddWithValue("@FotografijaId", f.FotografijaId);
                        komanda.Parameters.AddWithValue("@Naziv", f.Naziv);
                        komanda.Parameters.AddWithValue("@Datum", f.Datum);
                        komanda.Parameters.AddWithValue("@Opis", f.Opis);

                        konekcija.Open();

                        komanda.ExecuteNonQuery();
                        return(0);
                    }
                    catch (Exception)
                    {
                        return(-1);
                    }
                }
            }
        }
Example #2
0
        //PROMENI
        private void Promeni(int promeniSliku = 0)
        {
            if (indeks < 0)
            {
                return;
            }

            if (!Validacija())
            {
                return;
            }

            Border b = WrapPanel1.Children[indeks] as Border;

            Fotografija selFotografija = b.Tag as Fotografija;

            selFotografija.Naziv = TextBoxNaziv.Text;
            selFotografija.Datum = DatePicker1.SelectedDate.Value;
            selFotografija.Opis  = TextBoxOpis.Text;

            if (promeniSliku == 0)
            {
                int rez = FotografijaDal.PromeniFotografiju1(selFotografija);

                if (rez == 0)
                {
                    SelektujBroder(b);
                    MessageBox.Show("Podaci promenjeni");
                    DozvoliIzmenu(false);
                }
            }

            if (promeniSliku == 1)
            {
                Uri         adresa = new Uri(odabranaSlika, UriKind.Absolute);
                BitmapImage bmp    = SlikaHelper.KreirajBitMapu(adresa);
                selFotografija.BinarniPodaci = SlikaHelper.KreirajNizBajtova(bmp);

                int rez = FotografijaDal.PromeniFotografiju2(selFotografija);

                if (rez == 0)
                {
                    PrikaziFotografije();
                    Border b1 = WrapPanel1.Children[indeks] as Border;
                    SelektujBroder(b1);

                    DozvoliIzmenu(false);
                    MessageBox.Show("Podaci promenjeni");
                }
                else
                {
                    MessageBox.Show("Greska pri promeni");
                }
            }
        }
Example #3
0
        //UBACI
        private void Ubaci()
        {
            if (!Validacija())
            {
                DozvoliIzmenu(true);
                return;
            }

            if (string.IsNullOrWhiteSpace(odabranaSlika))
            {
                MessageBox.Show("Odaberi sliku");
                return;
            }

            Fotografija f = new Fotografija();

            f.Naziv = TextBoxNaziv.Text;
            f.Datum = DatePicker1.SelectedDate.Value;
            f.Opis  = TextBoxOpis.Text;

            Uri         adresa = new Uri(odabranaSlika, UriKind.Absolute);
            BitmapImage bmp    = SlikaHelper.KreirajBitMapu(adresa);

            f.BinarniPodaci = SlikaHelper.KreirajNizBajtova(bmp);

            int rez = FotografijaDal.UbaciFotografiju(f);

            if (rez == 0)
            {
                PrikaziFotografije();
                odabranaSlika = "";
                indeks        = WrapPanel1.Children.Count - 1;
                Border b = WrapPanel1.Children[indeks] as Border;

                SelektujBroder(b);
                DozvoliIzmenu(false);
                MessageBox.Show("Slika sacuvana");
            }
            else
            {
                MessageBox.Show("Greska pri cuvanju");
            }
        }
Example #4
0
        private void Img2_MouseDown(object sender, MouseButtonEventArgs e)
        {
            odabranaSlika = "";
            ResetujBordere();
            Image  img       = (Image)sender;
            Border selBorder = img.Parent as Border;

            SelektujBroder(selBorder);
            Fotografija selektovanaFotografija = selBorder.Tag as Fotografija;

            TextBoxNaziv.Text        = selektovanaFotografija.Naziv;
            TextBoxOpis.Text         = selektovanaFotografija.Opis;
            DatePicker1.SelectedDate = selektovanaFotografija.Datum;

            BitmapImage bmp = SlikaHelper.KreirajBitMapuIzMemorije(selektovanaFotografija.BinarniPodaci);

            Image1.Source = bmp;
            indeks        = WrapPanel1.Children.IndexOf(selBorder);
        }
Example #5
0
        private void ButtonObrisi_Click(object sender, RoutedEventArgs e)
        {
            if (indeks > -1)
            {
                Border b = WrapPanel1.Children[indeks] as Border;

                Fotografija f = b.Tag as Fotografija;

                int rez = FotografijaDal.ObrisiFotografiju(f.FotografijaId);

                if (rez == 0)
                {
                    PrikaziFotografije();
                    Resetuj();
                    ResetujBordere();
                    DozvoliIzmenu(false);
                    MessageBox.Show("Podaci obrisani");
                }
                else
                {
                    MessageBox.Show("Greska pri brisanju podataka");
                }
            }
        }
Example #6
0
        public static List <Fotografija> VratiFotografije()
        {
            List <Fotografija> listaFotografija = new List <Fotografija>();

            using (SqlConnection konekcija = new SqlConnection(Konekcija.cnnFotografija))
            {
                using (SqlCommand komanda = new SqlCommand("PrikaziFotografije", konekcija))
                {
                    komanda.CommandType = CommandType.StoredProcedure;
                    try
                    {
                        konekcija.Open();
                        using (SqlDataReader dr = komanda.ExecuteReader())
                        {
                            while (dr.Read())
                            {
                                Fotografija f = new Fotografija
                                {
                                    FotografijaId = dr.GetInt32(0),
                                    Naziv         = dr.GetString(1),
                                    BinarniPodaci = (byte[])dr[2],
                                    Datum         = dr.GetDateTime(3),
                                    Opis          = dr.GetString(4)
                                };
                                listaFotografija.Add(f);
                            }
                        }
                        return(listaFotografija);
                    }
                    catch (Exception)
                    {
                        return(null);
                    }
                }
            }
        }