Exemple #1
0
        private void buttonIzmijeniDK_Click(object sender, EventArgs e)
        {
            MySqlConnection connection = DBConnection.getConnection();
            MySqlCommand    command    = new MySqlCommand();

            String query = "select autorID, naziv, opis, cijena, zanr from knjiga where id=@idParam";
            string naziv, opis, zanr;
            double cijena;
            int    autorID;

            try
            {
                command.CommandText = query;
                command.Connection  = connection;

                command.Parameters.Add("idParam", MySqlDbType.Int32);
                command.Parameters["idParam"].Value = id;

                MySqlDataReader reader = command.ExecuteReader();

                reader.Read();

                naziv   = reader["naziv"].ToString();
                opis    = reader["opis"].ToString();
                zanr    = reader["zanr"].ToString();
                autorID = Int32.Parse(reader["autorID"].ToString());
                cijena  = Double.Parse(reader["cijena"].ToString());

                reader.Close();

                if (textBoxNazivDK.Text != "")
                {
                    naziv = textBoxNazivDK.Text;
                }
                if (textBoxOpisDK.Text != "")
                {
                    opis = textBoxOpisDK.Text;
                }
                if (textBoxZanrDK.Text != "")
                {
                    zanr = textBoxZanrDK.Text;
                }
                if (textBoxCijenaDK.Text != "")
                {
                    cijena = Double.Parse(textBoxCijenaDK.Text);
                }
                if (comboBoxAutorDK.Text != "")
                {
                    string[] arr     = comboBoxAutorDK.Text.Split(' ');
                    string   ime     = arr[0];
                    string   prezime = arr[1];
                    autorID = Autor.nadjiID(ime, prezime);
                }

                Knjiga knjiga = new Knjiga(autorID, naziv, opis, cijena, zanr);
                knjiga.IzmjenaKnjige(this.id);
                this.Close();
            }
            catch (Exception err)
            {
            }
        }
        private void buttonIzmijeniDA_Click(object sender, EventArgs e)
        {
            MySqlConnection connection = DBConnection.getConnection();
            MySqlCommand    command    = new MySqlCommand();

            String query = "select ime, prezime, biografija from autor where id=@idParam";
            string ime, prezime, biografija;

            try
            {
                command.CommandText = query;
                command.Connection  = connection;

                command.Parameters.Add("idParam", MySqlDbType.Int32);
                command.Parameters["idParam"].Value = id;

                MySqlDataReader reader = command.ExecuteReader();

                reader.Read();

                ime        = reader["ime"].ToString();
                prezime    = reader["prezime"].ToString();
                biografija = reader["biografija"].ToString();

                reader.Close();

                String destPath1 = "../../Autori/" + ime + "" + prezime + ".jpg";

                int changed = 0;

                if (textBoxImeDA.Text != "")
                {
                    ime     = textBoxImeDA.Text;
                    changed = 1;
                }
                if (textBoxPrezimeDA.Text != "")
                {
                    prezime = textBoxPrezimeDA.Text;
                    changed = 1;
                }
                if (textBoxBiografijaDA.Text != "")
                {
                    biografija = textBoxBiografijaDA.Text;
                }

                if (changed == 1)
                {
                    if (File.Exists(destPath1))
                    {
                        String destPath2 = "../../Autori/" + ime + "" + prezime + ".jpg";
                        File.Copy(destPath1, destPath2, true);
                        File.Delete(destPath1);
                    }
                }

                Autor autor = new Autor(ime, prezime, biografija);
                autor.IzmjenaAutora(this.id);
                this.Close();
            }
            catch (Exception err)
            {
            }
        }