/* Function name: saveButton_Click Version: 1 Author: Christopher Sigouin Description: Inputs: Outputs: Return value: N/A Change History: 2015.11.17 Original version by CJS */ private void saveButton_Click(object sender, EventArgs e) { // Check to see if there is an ISBN listed to complete the save if (isbnTextBox.Text == "") { MessageBox.Show("There is nothing to save. Reverting to 'Select Mode'"); } // Create 'Book' object and grab data Book book = new Book(); book.Isbn = isbnTextBox.Text; book.Title = titleTextBox.Text; book.Author = authorTextBox.Text; book.Publisher = publisherTextBox.Text; book.SubjectCode = subjectTextBox.Text; book.ShelfLocation = shelfTextBox.Text; book.Fiction = fictionCheckBox.Checked; Console.Write(bookHandler.Mode); // Change save type based on state of the application switch (bookHandler.Mode) { case BookHandler.Modes.AddMode: Console.Write("\nCurrent Mode: " + bookHandler.Mode + "\n"); bookHandler.Add(book); break; case BookHandler.Modes.EditMode: Console.Write("\nCurrent Mode: " + bookHandler.Mode + "\n"); bookHandler.Update(book); break; } // Reload the ComboBox bookTitleComboBox.Items.Clear(); bookHandler.initializeComboBox(bookTitleComboBox); // Set to default state resetToSelectMode(); // Console check for current mode Console.Write("\nCurrent Mode: " + bookHandler.Mode + "\n"); }
public void Update(Book book) { BookDAO.Update(book); }
public void Add(Book book) { BookDAO.Add(book); }
/* Function name: showBookDetails Version: 1 Author: Christopher Sigouin Description: Pulls the details of the selected book Inputs: String isbn Outputs: Book Return value: N/A Change History: 2015.11.23 Original version by CJS */ public static Book showBookDetails(String isbn) { Book book = new Book(); try { OpenConn(); string query = "select * from " + booksTable + " where " + BookDAO.isbn + " = " + "'" + isbn + "'"; OleDbCommand cmd = new OleDbCommand(query, Conn); OleDbDataReader reader = cmd.ExecuteReader(); // Add each item to an array of type 'ComboBoxItem' Console.Write(query); while (reader.Read()) { book.Isbn = reader.GetString(0); book.Title = reader.GetString(1); book.Author = reader.GetString(2); book.Publisher = reader.GetString(3); book.SubjectCode = reader.GetString(4); book.ShelfLocation = reader.GetString(5); book.Fiction = reader.GetBoolean(6); } // Close connections reader.Close(); Conn.Close(); } catch (Exception ex) { Console.Write("\nBookDAO Exception - showBookDetails - Message:\n" + ex.Message); } return book; }
/* Function name: BuildAddQuery Version: 1 Author: Christopher Sigouin Description: Builds the query for an ADD SQL statement Inputs: Outputs: Return value: N/A Change History: 2015.11.23 Original version by CJS */ private static String BuildAddQuery(Book book) { strTable = "\nInsert into " + booksTable; strFields = " (" + isbn + "," + title + "," + author + "," + publisher + "," + subjectCode + "," + shelfLocation + "," + fiction + ")"; strValues = " Values ( '" + book.Isbn + "' , '" + book.Title + "' , '" + book.Author + "' , '" + book.Publisher + "' , '" + book.SubjectCode + "' , '" + book.ShelfLocation + "' , " + book.Fiction + " )\n"; insertStr = strTable + strFields + strValues; Console.Write("BuildAddQuery SQL => " + insertStr); return insertStr; }
/* Function name: BuildUpdateQuery Version: 1 Author: Christopher Sigouin Description: Builds the query for an UPDATE SQL statement Inputs: Outputs: Return value: N/A Change History: 2015.11.23 Original version by CJS */ private static String BuildUpdateQuery(Book book) { strTable = "\nUpdate " + booksTable; strFields = " Set " + title + "=" + "'" + book.Title + "'" + "," + author + "=" + "'" + book.Author + "'" + "," + publisher + "=" + "'" + book.Publisher + "'" + "," + subjectCode + "=" + "'" + book.SubjectCode + "'" + "," + shelfLocation + "=" + "'" + book.ShelfLocation + "'" + "," + fiction + "=" + "" + book.Fiction + "" + " Where (" + isbn + "='" + book.Isbn + "');\n"; insertStr = strTable + strFields; Console.Write("BuildUpdateQuery SQL => " + insertStr); return insertStr; }
/* Function name: Update Version: 1 Author: Christopher Sigouin Description: Completes the functionality of updating a record in the database Inputs: Outputs: Return value: N/A Change History: 2015.11.23 Original version by CJS */ public static void Update(Book book) { try { String Str = BuildUpdateQuery(book); OpenConn(); OleDbCommand cmd = new OleDbCommand(Str, Conn); cmd.ExecuteNonQuery(); CloseConn(); } catch (Exception ex) { Console.Write("\nBookDAO Exception - Update - Message:\n" + ex.Message); } }
/* Function name: Add Version: 1 Author: Christopher Sigouin Description: Completes the functionality of adding a record to the database Inputs: Outputs: Return value: N/A Change History: 2015.11.23 Original version by CJS */ public static void Add(Book book) { try { String Str = BuildAddQuery(book); OpenConn(); // Str is the SQL. Conn is the connection OleDbCommand cmd = new OleDbCommand(Str, Conn); cmd.ExecuteNonQuery(); CloseConn(); } catch (Exception ex) { Console.Write("\nBookDAO Exception - Add - Message:\n" + ex.Message); } }