def rentBook(isbn, usuario,cantidad):
     try:
         conection=connect("invated","invated")
         con=conection.return_conection()
         cursor=con.cursor()
         
         usuario_id=rented_books_controller.searchIdUser(usuario)
         print("---------------------------------------------Usuario ID rented book controller:", type(usuario_id))
         book_to_rent=(isbn, usuario_id, cantidad)
         verify_stock=rented_books_controller.func_verify_stock(isbn, cantidad)
         print(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++rented book controller verify stock:",verify_stock)
        
         if not(verify_stock ==0):
             update_books_dict={'cantidad':verify_stock,'isbn':isbn}
             
             statement_update="update libros set cantidad=:cantidad where ISBN=:isbn"
             cursor.execute(statement_update, update_books_dict)
             con.commit()
             statement_insert_rent="insert into libros_pedido(id_pedido,ISBN, usuario_id, cantidad) values(seq_id_libros_pedido.nextval,:0,:1,:2)"
             cursor.execute(statement_insert_rent, book_to_rent) 
             con.commit() 
     
     
         return rented_books_controller.return_books(usuario_id)    
     except Exception as ex:
         return None
         print("-------------------------------------Exception rentBook: "+str(ex))
 def func_verify_stock(isbn,quantity):
     try:
         print("-----------------------------------------------------------Entering to func_Verify_Stock")
         conection=connect("invated","invated")
         con=conection.return_conection()
         cursor=con.cursor()
     
         returnFunctionValue=cursor.callfunc("func_verify_stock", cx_Oracle.NUMBER, [str(isbn), int(quantity)])
         con.commit()
         return returnFunctionValue
     except Exception as ex:
         print("-------------------------------------------Exception func_verify_stock: ", str(ex))
         return None
Exemplo n.º 3
0
    def create_user(usuario, clave):
        try:
            connection = connect("invated", "invated")
            con = connection.return_conection()
            cur = con.cursor()
            cur = con.cursor()
            user = {'usuario': usuario, 'clave': clave}

            statement = "INSERT INTO usuario(id_usuario,usuario, clave) values(sec_usuario_id.nextval,:usuario,:clave)"
            cur.execute(statement, user)
            con.commit()
            return "User " + usuario + " Created Succesfully"
        except Exception as ex:
            print("create user Exception:" + str(ex))
            return "Error:" + str(ex)
 def return_books(id_user):
     try:
         print("------------------------------------------return_book id_user:"******"invated","invated")
         con=connection.return_conection()
         cursor=con.cursor()
         user={"id_usuario":id_user}
         stmt_foundBoks="select nombre, libros_pedido.cantidad, usuario from libros, usuario, libros_pedido where libros_pedido.isbn=libros.isbn and libros_pedido.usuario_id=usuario.id_usuario and usuario_id=:id_usuario"
         cursor.execute(stmt_foundBoks,user)
         con.commit()
         books_user=cursor.fetchall()
         return books_user
     except Exception as ex:
         print("------------------------------------------Exception return_books:",str(ex))
         return None
 def searchIdUser(usuario):
     conection=connect("invated","invated")
     con=conection.return_conection()
     cursor=con.cursor()
               
     usuario_dictionary={'usuario':usuario}
     
     statement_user="******"   
             
     cursor.execute(statement_user,usuario_dictionary)
     con.commit()
     usuario=cursor.fetchone()
     print("   ---------------------------------------------------------------------rented books controller-User returned",usuario)
     usuario_id=usuario[0]
     return usuario_id
Exemplo n.º 6
0
    def return_a_book(isbn):
        try:
            connection = connect("invated", "invated")
            con = connection.return_conection()
            cur = con.cursor()
            isbn_dic = {"isbn": isbn}
            statement_search_book = "select * from libros where ISBN=:isbn"
            cur.execute(statement_search_book, isbn_dic)

            book_found = cur.fetchone()

            print("-------------------------------BOOK found: ", book_found)
            return book_found

        except Exception as ex:
            print("---------------------------RETURN ONE BOOK:" + str(ex))
Exemplo n.º 7
0
    def return_books():
        try:
            connection = connect("invated", "invated")
            con = connection.return_conection()
            cur = con.cursor()
            statement_books = "select * from libros"
            cur.execute(statement_books)
            con.commit()
            all_books = []
            for row_book in cur:
                aux_book = book(row_book[0], row_book[1], row_book[2])
                all_books.append(aux_book)

            return all_books

        except Exception as ex:
            print("----------------------Exception Return Books: " + str(ex))
Exemplo n.º 8
0
    def start_session(usuario, clave):
        try:
            connection = connect("invated", "invated")
            con = connection.return_conection()
            cur = con.cursor()
            user = {'usuario': usuario, 'clave': clave}
            statement = "select * from usuario where usuario=:usuario and clave=:clave"
            cur.execute(statement, user)
            con.commit()
            users = []
            for result in cur:
                print("--------------------------------------------- Result: ",
                      result)
                myUser = {
                    'id_usuario': result[0],
                    'usuario': result[1],
                    'clave': result[2],
                    'fecha': result[3]
                }
                print('-------------------Usuario.fecha:', type(result[3]))
                users.append(myUser)

            print('---------------------------------------------- Users: ',
                  users)
            if len(users) == 1:
                print('-----------------------Users[Usuario][fecha]',
                      users[0]['fecha'])
                if users[0]['usuario'] == usuario and users[0][
                        'clave'] == clave:

                    return users[0]
                else:
                    return None
            else:
                return None

        except Exception as ex:
            print('Exception Start Session:', ex)