Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.71 KB | None | 0 0
  1. import sqlite3
  2. from tkinter import *
  3.  
  4.  
  5.  
  6. def dummy():
  7. connection = sqlite3.connect("phase2.db")
  8.  
  9. cursor = connection.cursor()
  10.  
  11. cursor.execute("SELECT * FROM Supplier")
  12. print("fetchall:")
  13. result = cursor.fetchall()
  14. for r in result:
  15. print(r)
  16.  
  17. def fetch(entries):
  18. for entry in entries:
  19. field = entry[0]
  20. text = entry[1].get()
  21. print('%s: "%s"' % (field, text))
  22.  
  23. def makeform(root, fields):
  24. entries = []
  25. for field in fields:
  26. row = Frame(root)
  27. lab = Label(row, width=15, text=field, anchor='w')
  28. ent = Entry(row)
  29. row.pack(side=TOP, fill=X, padx=5, pady=5)
  30. lab.pack(side=LEFT)
  31. ent.pack(side=LEFT, expand=NO, fill=X)
  32. entries.append((field, ent))
  33. return entries
  34.  
  35. def querycontroller(buttonName):
  36. if (buttonName == "b1"):
  37. query1()
  38. if (buttonName == "b2"):
  39. query2()
  40. if (buttonName == "b3"):
  41. query3()
  42. if (buttonName == "b4"):
  43. query4()
  44. if (buttonName == "b5"):
  45. query5()
  46. if (buttonName == "b6"):
  47. query6()
  48. if (buttonName == "b7"):
  49. query7()
  50. if (buttonName == "b8"):
  51. query8()
  52. if (buttonName == "b9"):
  53. query9()
  54. if (buttonName == "b10"):
  55. query10()
  56. if (buttonName == "b11"):
  57. query11()
  58. if (buttonName == "b12"):
  59. query12()
  60. if (buttonName == "b13"):
  61. query13()
  62. if (buttonName == "b14"):
  63. query14()
  64. if (buttonName == "b15"):
  65. query15()
  66. if (buttonName == "b16"):
  67. query16()
  68. if (buttonName == "b17"):
  69. query17()
  70. if (buttonName == "b18"):
  71. query18()
  72. if (buttonName == "b19"):
  73. query19()
  74. if (buttonName == "b20"):
  75. query20()
  76.  
  77. def query1():
  78. root = Tk()
  79. root.title("Query 1")
  80. customer_fields = ['Customer ID', 'E-Mail', 'Full Name','Billing Address','Shipping Address','Phone Number', 'Total Orders']
  81. ents = makeform(root, customer_fields)
  82. b1 = Button(root, text='Insert Customer',command=(lambda e=ents: q1p(e)))
  83. b1.place(x=0 , y=300)
  84. b2 = Button(root, text='Quit', command=root.quit)
  85. b2.place(x=140, y=300)
  86. root.geometry("400x500")
  87. root.mainloop()
  88.  
  89. def q1p(entries):
  90. id_array = entries[0]
  91. email_array = entries[1]
  92. name_array = entries[2]
  93. bill_array = entries[3]
  94. ship_array = entries[4]
  95. phone_array = entries[5]
  96. orders_array = entries[6]
  97.  
  98. id_value = id_array[1].get()
  99. email_value = email_array[1].get()
  100. name_value = name_array[1].get()
  101. bill_value = bill_array[1].get()
  102. ship_value = ship_array[1].get()
  103. phone_value = phone_array[1].get()
  104. orders_value = orders_array[1].get()
  105.  
  106.  
  107. connection = sqlite3.connect("phase2.db")
  108. cursor = connection.cursor()
  109.  
  110. format_str = """INSERT INTO Customer (Customer_Id, Email, Name, BillingAddress, ShippingAddress, PhoneNumber, TotalOrders)
  111. VALUES ("{id}", "{email}", "{name}", "{bill}", "{ship}", "{phone}", "{orders}");"""
  112.  
  113. sql_command = format_str.format(id=id_value, email=email_value, name=name_value, bill=bill_value, ship=ship_value, phone=phone_value, orders=orders_value)
  114. cursor.execute(sql_command)
  115. connection.commit()
  116.  
  117.  
  118. def query2():
  119. root = Tk()
  120. root.title("Query 2")
  121. cart_fields = ['Cart ID', 'Total Price' , 'Customer ID']
  122. ents = makeform(root, cart_fields)
  123. b1 = Button(root, text='Insert Cart',command=(lambda e=ents: q2p(e)))
  124. b1.place(x=0 , y=300)
  125. b2 = Button(root, text='Quit', command=root.quit)
  126. b2.place(x=140, y=300)
  127. root.geometry("400x500")
  128. root.mainloop()
  129.  
  130. def q2p(entries):
  131. id_array = entries[0]
  132. price_array = entries[1]
  133. cid_array = entries[2]
  134.  
  135.  
  136. id_value = id_array[1].get()
  137. price_value = price_array[1].get()
  138. cid_value = cid_array[1].get()
  139. connection = sqlite3.connect("phase2.db")
  140. cursor = connection.cursor()
  141.  
  142. format_str = """INSERT INTO Cart (Cart_Id, TotalPrice, Customer_Id)
  143. VALUES ("{id}", "{price}", "{cid}");"""
  144.  
  145. sql_command = format_str.format(id=id_value, price=price_value, cid=cid_value)
  146. cursor.execute(sql_command)
  147. connection.commit()
  148.  
  149. def query3():
  150. root = Tk()
  151. root.title("Query 3")
  152. supp_fields = ['Supplier ID', 'Supplier Name' , 'Address', 'Phone Number', 'Total Products', ]
  153. ents = makeform(root, supp_fields)
  154. b1 = Button(root, text='Insert Supplier',command=(lambda e=ents: q3p(e)))
  155. b1.place(x=0 , y=300)
  156. b2 = Button(root, text='Quit', command=root.quit)
  157. b2.place(x=140, y=300)
  158. root.geometry("400x500")
  159. root.mainloop()
  160.  
  161. def q3p(entries):
  162. id_array = entries[0]
  163. name_array = entries[1]
  164. add_array = entries[2]
  165. phone_array = entries[3]
  166. prod_array = entries[4]
  167.  
  168.  
  169. id_value = id_array[1].get()
  170. name_value = name_array[1].get()
  171. add_value = add_array[1].get()
  172. phone_value = phone_array[1].get()
  173. prod_value = prod_array[1].get()
  174.  
  175. connection = sqlite3.connect("phase2.db")
  176. cursor = connection.cursor()
  177.  
  178. format_str = """INSERT INTO Supplier (Supplier_Id, SupplierName, Address, PhoneNumber, TotalProducts)
  179. VALUES ("{id}", "{name}", "{address}", "{phone}", "{products}");"""
  180.  
  181. sql_command = format_str.format(id=id_value, name=name_value, address=add_value, phone=phone_value, products=prod_value)
  182. cursor.execute(sql_command)
  183. connection.commit()
  184.  
  185. def query4():
  186. root = Tk()
  187. root.title("Query 4")
  188. root.mainloop()
  189.  
  190. def query5():
  191. root = Tk()
  192. root.title("Query 5")
  193. root.mainloop()
  194.  
  195. def query6():
  196. root = Tk()
  197. root.title("Query 6")
  198. root.mainloop()
  199.  
  200. def query7():
  201. root = Tk()
  202. root.title("Query 7")
  203. root.mainloop()
  204.  
  205. def query8():
  206. root = Tk()
  207. root.title("Query 8")
  208. root.mainloop()
  209.  
  210. def query9():
  211. root = Tk()
  212. root.title("Query 9")
  213. root.mainloop()
  214.  
  215. def query10():
  216. root = Tk()
  217. root.title("Query 10")
  218. root.mainloop()
  219.  
  220. def query11():
  221. root = Tk()
  222. root.title("Query 11")
  223. root.mainloop()
  224.  
  225. def query12():
  226. root = Tk()
  227. root.title("Query 12")
  228. root.mainloop()
  229.  
  230. def query13():
  231. root = Tk()
  232. root.title("Query 13")
  233. root.mainloop()
  234.  
  235. def query14():
  236. root = Tk()
  237. root.title("Query 14")
  238. root.mainloop()
  239.  
  240. def query15():
  241. root = Tk()
  242. root.title("Query 15")
  243. root.mainloop()
  244.  
  245. def query16():
  246. root = Tk()
  247. root.title("Query 16")
  248. root.mainloop()
  249.  
  250. def query17():
  251. root = Tk()
  252. root.title("Query 17")
  253. root.mainloop()
  254.  
  255. def query18():
  256. root = Tk()
  257. root.title("Query 18")
  258. root.mainloop()
  259.  
  260. def query19():
  261. root = Tk()
  262. root.title("Query 19")
  263. root.mainloop()
  264.  
  265. def query20():
  266. root = Tk()
  267. root.title("Query 20")
  268. root.mainloop()
  269.  
  270. if __name__ == '__main__':
  271. root = Tk()
  272. root.title("E-Commerce Game Shop")
  273. b1 = Button(root, text='Query 1',command=(lambda b="b1": querycontroller(b)))
  274. b1.place(x=0, y=50)
  275.  
  276. b2 = Button(root, text='Query2', command=(lambda b="b2": querycontroller(b)))
  277. b2.place(x=80 , y=50)
  278. b3 = Button(root, text='Query3', command=(lambda b="b3": querycontroller(b)))
  279. b3.place(x=160 , y=50)
  280.  
  281. b4 = Button(root, text='Query4', command=(lambda b="b4": querycontroller(b)))
  282. b4.place(x=240 , y=50)
  283.  
  284. b5 = Button(root, text='Query5', command=(lambda b="b5": querycontroller(b)))
  285. b5.place(x=320 , y=50)
  286.  
  287.  
  288. b6 = Button(root, text='Query6',command=(lambda b="b6": querycontroller(b)))
  289. b6.place(x=0, y=100)
  290.  
  291. b7 = Button(root, text='Query7', command=(lambda b="b7": querycontroller(b)))
  292. b7.place(x=80 , y=100)
  293. b8 = Button(root, text='Query8', command=(lambda b="b8": querycontroller(b)))
  294. b8.place(x=160 , y=100)
  295.  
  296. b9 = Button(root, text='Query9', command=(lambda b="b9": querycontroller(b)))
  297. b9.place(x=240 , y=100)
  298.  
  299. b10 = Button(root, text='Query10', command=(lambda b="b10": querycontroller(b)))
  300. b10.place(x=320 , y=100)
  301.  
  302. b11 = Button(root, text='Query11',command=(lambda b="b11": querycontroller(b)))
  303. b11.place(x=0, y=150)
  304.  
  305. b12 = Button(root, text='Query12', command=(lambda b="b12": querycontroller(b)))
  306. b12.place(x=80 , y=150)
  307. b13 = Button(root, text='Query13', command=(lambda b="b13": querycontroller(b)))
  308. b13.place(x=160 , y=150)
  309.  
  310. b14 = Button(root, text='Query14', command=(lambda b="b14": querycontroller(b)))
  311. b14.place(x=240 , y=150)
  312.  
  313. b15 = Button(root, text='Query15', command=(lambda b="b15": querycontroller(b)))
  314. b15.place(x=320 , y=150)
  315.  
  316. b16 = Button(root, text='Query16',command=(lambda b="b16": querycontroller(b)))
  317. b16.place(x=0, y=200)
  318.  
  319. b17 = Button(root, text='Query17', command=(lambda b="b17": querycontroller(b)))
  320. b17.place(x=80 , y=200)
  321. b18 = Button(root, text='Query18', command=(lambda b="b18": querycontroller(b)))
  322. b18.place(x=160 , y=200)
  323.  
  324. b19 = Button(root, text='Query19', command=(lambda b="b19": querycontroller(b)))
  325. b19.place(x=240 , y=200)
  326.  
  327. b20 = Button(root, text='Query20', command=(lambda b="b20": querycontroller(b)))
  328. b20.place(x=320 , y=200)
  329.  
  330. root.geometry("600x400")
  331. dummy()
  332. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement