Exemplo n.º 1
0
 // user properly entered book data - the book can be added
 private void buttonAddBook_Click(object sender, EventArgs e)
 {
     try
     {
         if (!Validation.isNotEmpty(textBoxPublisher.Text))
         {
             validated[2] = true;
         }
         // first we need to check whether everything is valid
         if (validated.Contains(false))
         {
             return;
         }
         database.connect();
         Author a = database.findAuthorByName(textBoxAuthor.Text);
         database.disconnect();
         if (a == null)
         {
             database.connect();
             long id = database.addAuthor(new Author(textBoxAuthor.Text));
             database.disconnect();
             a = new Author(id, textBoxAuthor.Text);
         }
         List <Genre> genres = new List <Genre>();
         foreach (string item in listBoxGenres.Items)
         {
             database.connect();
             Genre genre = database.findGenreByName(item);
             database.disconnect();
             if (genre == null)
             {
                 database.connect();
                 long id = database.addGenre(new Genre(item));
                 database.disconnect();
                 genres.Add(new Genre(id, item));
             }
             else
             {
                 genres.Add(genre);
             }
         }
         Book newBook = new Book(textBoxName.Text, a, textBoxPublisher.Text, genres, dateTimePicker.Value);
         database.connect();
         database.addBook(newBook);
         database.disconnect();
         MessageBox.Show("Book successfully added!", "Message from Database", MessageBoxButtons.OK, MessageBoxIcon.Information);
         initialForm.RefreshData();
         initialForm.Show();
         this.Close();
     }
     catch
     {
         statusLabel.Text = "Error while adding book!";
     }
 }
Exemplo n.º 2
0
 // go back to dashboard
 private void buttonDashboard_Click(object sender, EventArgs e)
 {
     initialForm.RefreshData();
     initialForm.Show();
     this.Close();
 }