Пример #1
0
class Stock(object):
    
    def __init__(self):
        self.db = Database()

    def increment_stock(self, book_ISBN, increment_amount):
        # Increment the stock in the stock table by the increment_amount
        # Check that the number the user entered > 0 
        if (increment_amount < 0):
            print("Please put in a value that is greater than 0")
            exit()

        query = "Update STOCK_LEVEL set AMOUNT = AMOUNT + %d where BOOK_ID = '%s'" %(increment_amount, book_ISBN)

        try:
            self.db._dbInsert(query)
        except Exception as e:
            print(e)

    def decrement_stock(self, book_ISBN, decrement_amount):
        # Decrement the stock in the stock table by the decrement_amoumt
        # Check that the number the user entered > 0
        if (decrement_amount < 0):
            print("Please put in a value that is greater than 0")
            exit()

        query = "Update STOCK_LEVEL set AMOUNT = AMOUNT - %d where BOOK_ID = '%s'" %(decrement_amount, book_ISBN)

        try:
            self.db._dbInsert(query)
        except Exception as e:
            print(e)
Пример #2
0
class System(object):
    def __init__(self):
        self.db = Database()

    def add_book(self, book_name, book_ISBN, publication_date, price,
                 author_firstname, author_lastname):
        # Add the book to the database
        try:
            query1 = "Insert into BOOK values ('%s', '%s', '%s', %11.2f)" % (
                book_ISBN, book_name, publication_date, price)
            query2 = (
                "Insert into AUTHOR (GIVEN_NAME, LAST_NAME, BOOK_ID) values ('%s', '%s', '%s')"
                % (author_firstname, author_lastname, book_ISBN))
            self.db._dbInsert(query1)
            self.db._dbInsert(query2)
        except Exception as e:
            print(e)

    def delete_book(self, book_ISBN):
        # Remove the book from the database
        query = "Delete from BOOK where ISBN = '%s'" % (book_ISBN)
        try:
            self.db._dbInsert(query)
        except Exception as e:
            print(e)
Пример #3
0
class Tag(object):
    # Each book is associated with a one word tag
    def __init__(self):
        self.db = Database()

    def add_tag(self, book_ISBN, tag):
        # Adds tag to the book
        if not (re.match("\A[\w-]+\Z", tag)):
            print("Tag can only be a single word")
            exit()

        query = "Insert into BOOK_TAG (BOOK_ID, TAG) values ('%s', '%s')" % (
            book_ISBN, tag)
        try:
            self.db._dbInsert(query)
        except Exception as e:
            print(e)

    def remove_tag(self, book_ISBN):
        # Removes the tag from the book
        query = "Delete from BOOK_TAG where BOOK_ID = '%s'" % (book_ISBN)
        try:
            self.db._dbInsert(query)
        except Exception as e:
            print(e)

    def change_tag(self, book_ISBN, tag):
        # Changes the associated tag
        query = "Update BOOK_TAG set TAG = '%s' where BOOK_ID = '%s'" % (
            tag, book_ISBN)
        try:
            self.db._dbInsert(query)
        except Exception as e:
            print(e)