Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import psycopg2
- from tabulate import tabulate
- import sys,os
- header = print("""
- ___ _ _ _____ _ _
- | __ \ | | | | | __ \ | | | |
- | |__) | __ ___ __| |_ _ ___| |_ | | | | __ _| |_ __ _| |__ __ _ ___ ___ _ __ _ __ ___ __ _ _ __ __ _ _ __ ___ _ __ ___ __ _
- | ___/ '__/ _ \ / _` | | | |/ __| __| | | | |/ _` | __/ _` | '_ \ / _` / __|/ _ \ | '_ \| '__/ _ \ / _` | '__/ _` | '_ ` _ \| '_ ` _ \ / _` |
- | | | | | (_) | (_| | |_| | (__| |_ | |__| | (_| | || (_| | |_) | (_| \__ \ __/ | |_) | | | (_) | (_| | | | (_| | | | | | | | | | | | (_| |
- |_| |_| \___/ \__,_|\__,_|\___|\__| |_____/ \__,_|\__\__,_|_.__/ \__,_|___/\___| | .__/|_| \___/ \__, |_| \__,_|_| |_| |_|_| |_| |_|\__,_| | | __/ | |_| |___/
- """)
- #to insert a query do SQL_Queries.sqlread / sqlwrite depending on your usage
- def sql_read(query):
- #ip door dns vervangen wanneer gepushd wordt naar client
- conn = psycopg2.connect(database="productdatabase", user="postgres",password="Welkom01",host="172.16.0.2",port="5432")
- cur = conn.cursor()
- cur.execute(query)
- column_names = [desc[0] for desc in cur.description]
- return( cur.fetchall(),column_names)
- def show_all_product():
- query = sql_read(query='select productid, naam, prijs, productbeschrijving, operating_system, aantal_poorten, '
- 'serienummer, aantallen, voorraad.locatie,product_type.type_product , product_type.type_nummer, poort_type.poorttype '
- 'from product '
- 'INNER JOIN product_type ON Product.Product_Typeid = product_type.product_type_id '
- 'INNER JOIN poort_type ON Product.poort_typeid = poort_type.poort_type_id '
- 'INNER JOIN voorraad ON voorraad_id = voorraad.voorraadid order by productid ASC ;')
- print (tabulate (query[0], headers=query[1],tablefmt="psql"))
- def show_opslag_locatie():
- query = sql_read(query='select productid, voorraad.locatie,product.naam, product.aantallen FROM voorraad, product WHERE voorraadid = product.voorraad_id order by locatie ASC')
- print (tabulate (query[0], headers=query[1],tablefmt="psql"))
- def show_fabrikant():
- query = sql_read(query='SELECT fabrikant.naam, product.naam from kpl_fabrikantproduct '
- 'JOIN product ON kpl_fabrikantproduct.productid = product.productid '
- 'JOIN fabrikant ON kpl_fabrikantproduct.fabrikantid = fabrikant.fabrikantid')
- print (tabulate (query[0], headers=query[1],tablefmt="psql"))
- def optie1():
- show_all_product()
- print ("9: Terug")
- print ("0: Afsluiten")
- keus = input(">>")
- exec_menu(keus)
- def optie2():
- show_opslag_locatie()
- print ("9: Terug")
- print ("0: Afsluiten")
- keus = input(">>")
- exec_menu(keus)
- def optie3():
- show_fabrikant()
- print ("9: Terug")
- print ("0: Afsluiten")
- keus = input(">>")
- exec_menu(keus)
- def main_menu():
- os.system('cls')
- header
- print("\n")
- print('Welkom bij het Product Opvraag Programma')
- print('Maak u keuze uit een van de volgende opties:\n'
- "\n 1: Laat alle producten zien"
- "\n 2: Overzicht van opslaglocaties voor goederen"
- "\n 3: Overzicht van fabrikanten en producten"
- )
- keus = input("Keuze:")
- exec_menu(keus)
- return
- def exit():
- sys.exit()
- def exec_menu(keus):
- os.system('cls')
- if keus == '':
- main_menu()
- elif keus == '1':
- optie1()
- elif keus == '2':
- optie2()
- elif keus == '3':
- optie3()
- elif keus == '9':
- main_menu()
- elif keus == '0':
- exit()
- else:
- print ("geen_geldige_keuze\n")
- main_menu()
- return
- if __name__ == "__main__":
- # Launch main menu
- main_menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement