Advertisement
Guest User

Untitled

a guest
Jun 7th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. import psycopg2
  2. from tabulate import tabulate
  3. import sys,os
  4.  
  5. header = print("""
  6. ___ _ _ _____ _ _
  7. | __ \ | | | | | __ \ | | | |
  8. | |__) | __ ___ __| |_ _ ___| |_ | | | | __ _| |_ __ _| |__ __ _ ___ ___ _ __ _ __ ___ __ _ _ __ __ _ _ __ ___ _ __ ___ __ _
  9. | ___/ '__/ _ \ / _` | | | |/ __| __| | | | |/ _` | __/ _` | '_ \ / _` / __|/ _ \ | '_ \| '__/ _ \ / _` | '__/ _` | '_ ` _ \| '_ ` _ \ / _` |
  10. | | | | | (_) | (_| | |_| | (__| |_ | |__| | (_| | || (_| | |_) | (_| \__ \ __/ | |_) | | | (_) | (_| | | | (_| | | | | | | | | | | | (_| |
  11. |_| |_| \___/ \__,_|\__,_|\___|\__| |_____/ \__,_|\__\__,_|_.__/ \__,_|___/\___| | .__/|_| \___/ \__, |_| \__,_|_| |_| |_|_| |_| |_|\__,_| | | __/ | |_| |___/
  12. """)
  13.  
  14.  
  15. #to insert a query do SQL_Queries.sqlread / sqlwrite depending on your usage
  16. def sql_read(query):
  17.  
  18. #ip door dns vervangen wanneer gepushd wordt naar client
  19. conn = psycopg2.connect(database="productdatabase", user="postgres",password="Welkom01",host="172.16.0.2",port="5432")
  20.  
  21. cur = conn.cursor()
  22. cur.execute(query)
  23. column_names = [desc[0] for desc in cur.description]
  24. return( cur.fetchall(),column_names)
  25.  
  26.  
  27. def show_all_product():
  28. query = sql_read(query='select productid, naam, prijs, productbeschrijving, operating_system, aantal_poorten, '
  29. 'serienummer, aantallen, voorraad.locatie,product_type.type_product , product_type.type_nummer, poort_type.poorttype '
  30. 'from product '
  31. 'INNER JOIN product_type ON Product.Product_Typeid = product_type.product_type_id '
  32. 'INNER JOIN poort_type ON Product.poort_typeid = poort_type.poort_type_id '
  33. 'INNER JOIN voorraad ON voorraad_id = voorraad.voorraadid order by productid ASC ;')
  34. print (tabulate (query[0], headers=query[1],tablefmt="psql"))
  35.  
  36. def show_opslag_locatie():
  37. query = sql_read(query='select productid, voorraad.locatie,product.naam, product.aantallen FROM voorraad, product WHERE voorraadid = product.voorraad_id order by locatie ASC')
  38. print (tabulate (query[0], headers=query[1],tablefmt="psql"))
  39.  
  40. def show_fabrikant():
  41. query = sql_read(query='SELECT fabrikant.naam, product.naam from kpl_fabrikantproduct '
  42. 'JOIN product ON kpl_fabrikantproduct.productid = product.productid '
  43. 'JOIN fabrikant ON kpl_fabrikantproduct.fabrikantid = fabrikant.fabrikantid')
  44. print (tabulate (query[0], headers=query[1],tablefmt="psql"))
  45.  
  46. def optie1():
  47. show_all_product()
  48. print ("9: Terug")
  49. print ("0: Afsluiten")
  50. keus = input(">>")
  51. exec_menu(keus)
  52.  
  53.  
  54. def optie2():
  55. show_opslag_locatie()
  56. print ("9: Terug")
  57. print ("0: Afsluiten")
  58. keus = input(">>")
  59. exec_menu(keus)
  60.  
  61. def optie3():
  62. show_fabrikant()
  63. print ("9: Terug")
  64. print ("0: Afsluiten")
  65. keus = input(">>")
  66. exec_menu(keus)
  67.  
  68. def main_menu():
  69. os.system('cls')
  70. header
  71. print("\n")
  72. print('Welkom bij het Product Opvraag Programma')
  73. print('Maak u keuze uit een van de volgende opties:\n'
  74. "\n 1: Laat alle producten zien"
  75. "\n 2: Overzicht van opslaglocaties voor goederen"
  76. "\n 3: Overzicht van fabrikanten en producten"
  77. )
  78. keus = input("Keuze:")
  79. exec_menu(keus)
  80. return
  81.  
  82. def exit():
  83. sys.exit()
  84.  
  85. def exec_menu(keus):
  86. os.system('cls')
  87. if keus == '':
  88. main_menu()
  89. elif keus == '1':
  90. optie1()
  91. elif keus == '2':
  92. optie2()
  93. elif keus == '3':
  94. optie3()
  95. elif keus == '9':
  96. main_menu()
  97. elif keus == '0':
  98. exit()
  99. else:
  100. print ("geen_geldige_keuze\n")
  101. main_menu()
  102. return
  103.  
  104. if __name__ == "__main__":
  105. # Launch main menu
  106. main_menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement