def add2cart(self, event, arg1, arg2, arg3, arg4, arg5): #arg1=attendees, arg2=licensenb, arg3=event, arg4=date, arg5=price cartid_global = getGlobal('cartid') if cartid_global == 'None': #Connect to the db db = DBconnection.connecting() conn = db.connect() #create a new cart id query = "INSERT INTO cart VALUES (default);" conn.execute(query) query = "SELECT cartid FROM cart ORDER BY cartid DESC LIMIT 1;" cartid = conn.execute(query) for c in cartid: realid = c[0] conn.close() else: realid = cartid_global #insert new records into pickup_order i = 0 invalid_count = 0 event_price = float(getGlobal('event_price')) #Connect to the db db = DBconnection.connecting() conn = db.connect() for entry in arg1: num = entry.get() if int(num) > 0: licensenb = arg2[i] event = arg3[i] date = arg4[i] price = arg5[i] event_price += float(num) * price query = "INSERT INTO event_order VALUES (\'{0}\', \'{1}\', \'{2}\', \'{3}\', \'{4}\')".format( realid, licensenb, event, date, num) conn.execute(query) i += 1 else: i += 1 invalid_count += 1 continue conn.close() #When all the quantities user entered are invalid if invalid_count == i: tkMessageBox.showerror( "error", "You did not select anything. Please check your selections again." ) setGlobal('cartid', str(realid)) setGlobal('event_price', str(event_price)) tkMessageBox.showinfo("Message", "Added to cart successfully.")
def display(self, event): # Header #get the global variable from config.ini laterrr useremail = getGlobal('useremail') self.title = tk.Label(self, text="GOURMET") self.title.grid(row=1, column=1) msg = "Welcome, " msg += useremail self.desc = tk.Label(self, text=msg) self.desc.grid(row=2, column=1) # Logout self.logout_btn = tk.Button(self, text="Logout") self.logout_btn.bind('<Button-1>', self.logout) self.logout_btn.grid(row=0, column=0) # Cart self.cart_btn = tk.Button(self, text="My cart") self.cart_btn.bind('<Button-1>', self.cart) self.cart_btn.grid(row=2, column=0) # Buttons for all actions user can take self.points_btn = tk.Button(self, text="View my points") self.points_btn.bind('<Button-1>', self.points) self.points_btn.grid(row=3, column=1, sticky=tk.W) self.u_resr_btn = tk.Button(self, text="View my upcoming reservations") self.u_resr_btn.bind('<Button-1>', self.u_resr) self.u_resr_btn.grid(row=4, column=1, sticky=tk.W) self.u_pickup_btn = tk.Button(self, text="View my upcoming pickup orders") self.u_pickup_btn.bind('<Button-1>', self.u_pickup) self.u_pickup_btn.grid(row=5, column=1, sticky=tk.W) self.u_event_btn = tk.Button(self, text="View my upcoming events") self.u_event_btn.bind('<Button-1>', self.u_event) self.u_event_btn.grid(row=6, column=1, sticky=tk.W) self.resr_btn = tk.Button(self, text="Make a reservation") self.resr_btn.bind('<Button-1>', self.resr) self.resr_btn.grid(row=7, column=1, sticky=tk.W) self.pickup_btn = tk.Button(self, text="Make a food pickup order") self.pickup_btn.bind('<Button-1>', self.pickup) self.pickup_btn.grid(row=8, column=1, sticky=tk.W) self.event_btn = tk.Button(self, text="Purchase tickets for an event") self.event_btn.bind('<Button-1>', self.event) self.event_btn.grid(row=9, column=1, sticky=tk.W) self.review_btn = tk.Button(self, text="Review a restaurant") self.review_btn.bind('<Button-1>', self.review) self.review_btn.grid(row=10, column=1, sticky=tk.W)
def display(self, event): # Header self.hp_btn = tk.Button(self, text="Homepage") self.hp_btn.bind('<Button-1>', self.homepage) self.hp_btn.grid(row=0, column=0) self.desc = tk.Label(self, text="All reviews for this restaurant", wraplength=300) self.desc.grid(row=1, column=1) # Get restaurant license number from global variable licensenb = getGlobal('lnb_review') # Connect to DB and select user's points db = DBconnection.connecting() conn = db.connect() query = "SELECT reviewdate, rating, comment FROM review WHERE licensenb=\'{0}\';".format( licensenb) result_set = conn.execute(query) conn.close() #Putting all data from review table to arrays date, rating and comment date = [] rating = [] comment = [] for r in result_set: date.append(r[0]) rating.append(r[1]) comment.append(r[2]) #Print column names self.date = tk.Label(self, text="Date") self.date.grid(row=3, column=0) self.rating = tk.Label(self, text="Rating") self.rating.grid(row=3, column=1) self.comment = tk.Label(self, text="Comment") self.comment.grid(row=3, column=2) #Display data put in arrays date, rating and comment irow = 4 i = 0 for r in date: self.date = tk.Label(self, text=date[i]) self.date.grid(row=irow, column=0) self.rating = tk.Label(self, text=rating[i]) self.rating.grid(row=irow, column=1) self.comment = tk.Label(self, text=comment[i], wraplength=300) self.comment.grid(row=irow, column=2) i += 1 irow += 1
def on_button(self): rating = int(self.entry.get()) if (rating < 1) or (rating > 5): tkMessageBox.showerror("error", "Please enter a valid rating.") return lines = self.text.get("1.0", tk.END).splitlines() comment = "" for line in lines: comment += line comment += " " # Get restaurant license number from global variable useremail = getGlobal('useremail') licensenb = getGlobal('lnb_review') date = getGlobal("date") # Connect to DB and select user's points db = DBconnection.connecting() conn = db.connect() query_select = "SELECT * FROM review WHERE useremail=\'{0}\' AND licensenb=\'{1}\';".format( useremail, licensenb) try: print "Did not find it" query = "INSERT INTO review VALUES (\'{0}\', \'{1}\', \'{2}\', \'{3}\', \'{4}\');".format( useremail, licensenb, comment, rating, date) conn.execute(query) print "great" except (Exception): query = "UPDATE review SET comment = \'{0}\', rating = \'{1}\', reviewdate = \'{2}\' WHERE useremail = \'{3}\' AND licensenb = \'{4}\';".format( comment, rating, date, useremail, licensenb) conn.execute(query) print "noooo" finally: conn.close()
def display(self, event): # Header self.hp_btn = tk.Button(self, text="Homepage") self.hp_btn.bind('<Button-1>', self.homepage) self.hp_btn.grid(row=0, column=0) self.desc = tk.Label( self, text="You have upcoming events from the following restaurants", wraplength=300) self.desc.grid(row=1, column=1) #get the global variable from config.ini later useremail = getGlobal('useremail') # Connect to DB and get info db = DBconnection.connecting() conn = db.connect() query = "SELECT restaurantname, eventname, eventdate FROM (SELECT * FROM transaction WHERE useremail = '{0}') as t JOIN (SELECT * FROM event_order WHERE eventdate > now()) as e ON t.cartid = e.cartid JOIN (SELECT licenseNB, restaurantname FROM restaurant) as res ON e.licenseNB = res.licenseNB ORDER BY eventdate;".format( useremail) result_set = conn.execute(query) conn.close() restau = [] event = [] date = [] for r in result_set: restau.append(r[0]) event.append(r[1]) date.append(r[2]) # Print relevant info self.name = tk.Label(self, text="Restaurant") self.name.grid(row=3, column=0) self.event = tk.Label(self, text="Event") self.event.grid(row=3, column=1) self.time = tk.Label(self, text="Date (y-m-d)") self.time.grid(row=3, column=2) irow = 4 i = 0 for r in restau: self.res = tk.Label(self, text=restau[i]) self.res.grid(row=irow, column=0) self.event = tk.Label(self, text=event[i]) self.event.grid(row=irow, column=1) self.time = tk.Label(self, text=date[i]) self.time.grid(row=irow, column=2) i += 1 irow += 1
def display(self, event): # Header self.hp_btn = tk.Button(self, text="Homepage") self.hp_btn.bind('<Button-1>', self.homepage) self.hp_btn.grid(row=0, column=0) self.payment_complete = tk.Label( self, text="Payment completed! Thank you so much!.") self.payment_complete.grid(row=1, column=1) total_price = float(getGlobal('pickup_price')) + float( getGlobal('event_price')) setGlobal('total_price', str(total_price)) useremail = getGlobal('useremail') cartid = getGlobal('cartid') date = getGlobal('date') db = DBconnection.connecting() conn = db.connect() query = "INSERT INTO transaction VALUES (\'{0}\', \'{1}\', \'{2}\', \'{3}\');".format( useremail, cartid, total_price, date) conn.execute(query) points_gained = int(total_price) query = "UPDATE users SET points = points + \'{0}\' WHERE useremail = \'{1}\';".format( points_gained, useremail) conn.execute(query) conn.close() self.total_price = tk.Label(self, text="Your made a payment of $" + str(total_price) + ".") self.total_price.grid(row=2, column=1) setGlobal('cartid', 'None')
def display(self, event): # Header self.hp_btn = tk.Button(self, text="Homepage") self.hp_btn.bind('<Button-1>', self.homepage) self.hp_btn.grid(row=0, column=0) self.desc = tk.Label( self, text= "You have upcoming reservations from the following restaurants:", wraplength=300) self.desc.grid(row=1, column=1) #get the global variable from config.ini later useremail = getGlobal('useremail') # Connect to DB and get info db = DBconnection.connecting() conn = db.connect() query = "SELECT restaurantname, r.time FROM (SELECT * FROM user_books WHERE useremail = '{0}') as u JOIN (SELECT * FROM reservation WHERE time > now()) as r ON u.reservationid = r.reservationid JOIN (SELECT * FROM reservation_contains) as rc ON r.reservationid = rc.reservationid JOIN (SELECT licenseNB, restaurantname FROM restaurant) as res ON rc.licenseNB = res.licenseNB ORDER BY r.time;".format( useremail) result_set = conn.execute(query) conn.close() restau = [] time = [] for r in result_set: restau.append(r[0]) time.append(r[1]) # Print relevant info self.name = tk.Label(self, text="Restaurant") self.name.grid(row=3, column=1) self.time = tk.Label(self, text="Time (y-m-d h:s)") self.time.grid(row=3, column=2) irow = 4 i = 0 for r in restau: self.res = tk.Label(self, text=restau[i]) self.res.grid(row=irow, column=1) self.time = tk.Label(self, text=time[i]) self.time.grid(row=irow, column=2) i += 1 irow += 1
def points(self, event): # Get user email from session variable useremail = getGlobal('useremail') # Connect to DB and select user's points db = DBconnection.connecting() conn = db.connect() query = "SELECT points FROM users WHERE useremail='{0}';".format( useremail) result_set = conn.execute(query) conn.close() for r in result_set: nbpoints = r[0] strpoints = "You have " strpoints += str(nbpoints) strpoints += " points" self.point = tk.Label(self, text=strpoints) self.point.grid(row=3, column=2)
def display(self, event): # Header self.hp_btn = tk.Button(self, text="Homepage") self.hp_btn.bind('<Button-1>', self.homepage) self.hp_btn.grid(row=0, column=0) self.desc = tk.Label( self, text= "You have upcoming food pickups from the following restaurants:", wraplength=300) self.desc.grid(row=1, column=1) #get the global variable from config.ini later useremail = getGlobal('useremail') # Connect to DB and get info db = DBconnection.connecting() conn = db.connect() query = "SELECT restaurantname FROM (SELECT * FROM transaction WHERE useremail = '{0}' AND transactiondate = current_date) as t JOIN (SELECT * FROM pickup_order) as p ON t.cartid = p.cartid JOIN (SELECT licenseNB, restaurantname FROM restaurant) as res ON p.licenseNB = res.licenseNB;".format( useremail) result_set = conn.execute(query) conn.close() restau = [] for r in result_set: restau.append(r[0]) # Print relevant info irow = 3 i = 0 for r in restau: self.resr = tk.Label(self, text=restau[i]) self.resr.grid(row=irow, column=1) i += 1 irow += 1
def submitReservation(self, event): #Get user input self.u_time = self.time2.get() self.u_date = self.date2.get() self.u_quantity = self.quantity.get() licensenb = getGlobal('lnb_reserve') useremail = getGlobal('useremail') date = getGlobal('date') if (validate_date(self.u_date) == False): tkMessageBox.showerror( "error", "Invalid date format. Expected format is YYYY-MM-DD") elif (validate_time(self.u_time) == False): tkMessageBox.showerror( "error", "Invalid time format. Expected format is HH:MM") elif (int(self.u_quantity) < 1): tkMessageBox.showerror("error", "Number of attendees must be at least 1.") else: db = DBconnection.connecting() conn = db.connect() query = "SELECT r_table.licensenb, r_table.tableid, r_table.capacity FROM r_table, (SELECT licensenb, tableid FROM r_table EXCEPT SELECT reservation_contains.licensenb, reservation_contains.tableid FROM reservation, reservation_contains WHERE reservation.reservationid = reservation_contains.reservationid AND reservation.time::date = '{0}') AS e WHERE r_table.licensenb = e.licensenb AND r_table.tableid = e.tableid AND r_table.licensenb = '{1}' ORDER BY r_table.tableid;".format( self.u_date, licensenb) result_set = conn.execute(query) conn.close() db = DBconnection.connecting() conn = db.connect() query = "SELECT licensenb FROM restaurant WHERE restaurant.licensenb = '{0}' AND (restaurant.openinghours < '{1}' OR restaurant.closinghours > '{2}');".format( licensenb, self.u_time, self.u_time) result_set2 = conn.execute(query) conn.close() licenseNB = [] tables = [] capty = [] for r in result_set: licenseNB.append(r[0]) print(r[0]) tables.append(r[1]) print(r[1]) capty.append(r[2]) print(r[2]) licenseNB2 = [] for r2 in result_set2: licenseNB2.append(r2[0]) #get total seats available across all tables total_seats = 0 for c in capty: total_seats += c # print("total seats avail: ") # print(total_seats) # print("total quant input: " + self.u_quantity) timestamp = self.u_date + " " + self.u_time if (int(self.u_quantity) > total_seats): tkMessageBox.showerror( "error", "There aren't enough seats to accomodate the number of diners mentioned. Reservation failed." ) #Checking if time input falls between opening hours and closing hours for the restaurant elif (not licenseNB2): tkMessageBox.showerror( "error", "Invalid time provided. Please consult restaurant opening and closing hours." ) elif (self.u_date < date): tkMessageBox.showerror( "error", "Invalid date provided. Reservation failed.") #Verifying date format # elif(validate(self.u_date)): # print("Wrong date format") else: print(useremail) db = DBconnection.connecting() conn = db.connect() conn.autocommit = True query = "SELECT reservationid FROM reservation ORDER BY reservationid DESC LIMIT 1;" rid = conn.execute(query) conn.close() for r in rid: real_rid = r[0] + 1 # db = DBconnection.connecting() # conn = db.connect() # conn.autocommit = True # query2 = "SELECT * FROM make_reservation('{0}',{1},'{2}','{3}',{4});".format(useremail,real_rid,licensenb,timestamp,self.u_quantity) # result3 = conn.execute(query2) # conn.close() # for e in result3: # wreck = e[0] db = DBconnection.connecting() conn = db.connect() conn.autocommit = True query = "INSERT INTO reservation VALUES({0},'{1}',{2});".format( real_rid, timestamp, self.u_quantity) conn.execute(query) conn.close() db = DBconnection.connecting() conn = db.connect() conn.autocommit = True query = "INSERT INTO user_books VALUES('{0}',{1});".format( useremail, real_rid) conn.execute(query) conn.close() peopleLeft = int(self.u_quantity) i = 0 while (peopleLeft > 0): print(tables[i]) db = DBconnection.connecting() conn = db.connect() conn.autocommit = True query = "INSERT INTO reservation_contains VALUES({0},'{1}',{2});".format( real_rid, licensenb, tables[i]) conn.execute(query) conn.close() peopleLeft = peopleLeft - capty[i] i = i + 1 tkMessageBox.showinfo("Reservation successful", "Reservation was successful!") db = DBconnection.connecting() conn = db.connect() conn.autocommit = True query = "UPDATE users SET points = points + 100 WHERE useremail = '{0}';".format( useremail) conn.execute(query) conn.close()
def display(self, event): # Header self.hp_btn = tk.Button(self, text="Homepage") self.hp_btn.bind('<Button-1>', self.homepage) self.hp_btn.grid(row=0, column=0) self.desc = tk.Label(self, text="Current items in your cart") self.desc.grid(row=1, column=1) # Checkout self.hp_btn = tk.Button(self, text="Checkout") self.hp_btn.bind('<Button-1>', self.checkout) self.hp_btn.grid(row=2, column=0) cartid_global = getGlobal('cartid') current_date = getGlobal('date') #When the user hasn't put anything in the cart if cartid_global == 'None': print "Is None" self.controller.show_frame("Empty_Cart") else: print "Not None" self.type = tk.Label(self, text="Order type") self.type.grid(row=3, column=0) self.res = tk.Label(self, text="Restaurant") self.res.grid(row=3, column=1) self.name = tk.Label(self, text="Name") self.name.grid(row=3, column=2) self.date = tk.Label(self, text="Date") self.date.grid(row=3, column=3) self.qty = tk.Label(self, text="Quantity") self.qty.grid(row=3, column=4) self.price = tk.Label(self, text="Price") self.price.grid(row=3, column=5) #Arrays for storing pickup order and event order info ordertype = [] licensenb = [] restau = [] itemname = [] date = [] quantity = [] price = [] # Connect to DB and get all pickup_order records db = DBconnection.connecting() conn = db.connect() query = "SELECT licensenb, foodname, quantity FROM pickup_order WHERE cartid = \'{0}\'".format( cartid_global) result_set_pickup = conn.execute(query) conn.close() for r in result_set_pickup: ordertype.append('Pickup') licensenb.append(r[0]) itemname.append(r[1]) date.append(current_date) quantity.append(r[2]) # Connect to DB and get all event_order records db = DBconnection.connecting() conn = db.connect() query = "SELECT licensenb, eventname, eventdate, eventattendees FROM event_order WHERE cartid = \'{0}\'".format( cartid_global) result_set_event = conn.execute(query) conn.close() for r in result_set_event: ordertype.append('Event') licensenb.append(r[0]) itemname.append(r[1]) date.append(r[2]) quantity.append(r[3]) #Get the restaurant names and price for each pickup and event record i = 0 db = DBconnection.connecting() conn = db.connect() for r in licensenb: this_licensenb = licensenb[i] this_item = itemname[i] #Get restaurant name, same for event and pickup query_restau = "SELECT restaurantname FROM restaurant WHERE licensenb = \'{0}\'".format( this_licensenb) result_set_restau = conn.execute(query_restau) for r in result_set_restau: restau.append(r[0]) if ordertype[i] == 'Pickup': #Get price for each pickup record query_price = "SELECT foodprice FROM food_menu WHERE licensenb = \'{0}\' AND foodname = \'{1}\'".format( this_licensenb, this_item) result_set_price = conn.execute(query_price) for r in result_set_price: price.append(r[0]) elif ordertype[i] == 'Event': #Get price for each pickup record query_price = "SELECT eventprice FROM r_event WHERE licensenb = \'{0}\' AND eventname = \'{1}\'".format( this_licensenb, this_item) result_set_price = conn.execute(query_price) for r in result_set_price: price.append(r[0]) else: print "It must be wrong if it's not Pickup or Event :(" i += 1 conn.close() # Display cart contents irow = int(getGlobal('irow')) i = 0 for r in itemname: self.ordertype = tk.Label(self, text=ordertype[i]) self.ordertype.grid(row=irow, column=0) self.restau = tk.Label(self, text=restau[i]) self.restau.grid(row=irow, column=1) self.itemname = tk.Label(self, text=itemname[i]) self.itemname.grid(row=irow, column=2) self.date = tk.Label(self, text=date[i]) self.date.grid(row=irow, column=3) self.quantity = tk.Label(self, text=quantity[i]) self.quantity.grid(row=irow, column=4) self.price = tk.Label(self, text=price[i]) self.price.grid(row=irow, column=5) i += 1 irow += 1 setGlobal('irow', str(irow))
def getlnb(self): return getGlobal('lnb_pickup')
def display(self, event): self.canvas = tk.Canvas(self, bd=0, highlightthickness=0) self.canvas.grid(row=0, column=0) self.vsbar = tk.Scrollbar(self, orient="vertical", command=self.canvas.yview) self.vsbar.grid(row=0, column=1, sticky='ns') self.canvas.configure(yscrollcommand=self.vsbar.set) # create a frame inside the canvas which will be scrolled with it self.interior = tk.Frame(self.canvas) self.canvas.create_window((0, 0), window=self.interior, anchor='nw') self.interior.bind("<Configure>", self.resize) self.interior.grid_columnconfigure(0, minsize=150) self.interior.grid_columnconfigure(1, minsize=150) self.interior.grid_columnconfigure(2, minsize=150) self.hp_btn = tk.Button(self.interior, text="Homepage") self.hp_btn.bind('<Button-1>', self.homepage) self.hp_btn.grid(row=0, column=0) self.display_btn = tk.Button(self.interior, text="Display") self.display_btn.bind('<Button-1>', self.display) self.display_btn.grid(row=1, column=0) self.desc = tk.Label(self.interior, text="Menu") self.desc.grid(row=1, column=1) # Get queried restaurant licensenb lnb_pickup = getGlobal('lnb_pickup') # Connect to DB and get info db = DBconnection.connecting() conn = db.connect() query = "SELECT foodname, foodprice FROM food_menu WHERE licensenb='{0}';".format( lnb_pickup) result_set = conn.execute(query) conn.close() food = [] price = [] quantities = [] for r in result_set: food.append(r[0]) price.append(r[1]) # Print relevant info self.cart = tk.Button( self.interior, text="Add to cart", ) self.cart.bind('<Button-1>', lambda event, arg1=quantities, arg2=food, arg3=price: self.add2cart(event, arg1, arg2, arg3)) self.cart.grid(row=3, column=0) self.fd = tk.Label(self.interior, text="Food") self.fd.grid(row=3, column=1) self.pc = tk.Label(self.interior, text="Price") self.pc.grid(row=3, column=2) self.qty = tk.Label(self.interior, text="Quantity") self.qty.grid(row=3, column=3) irow = 4 i = 0 for r in food: self.food = tk.Label(self.interior, text=food[i]) self.food.grid(row=irow, column=1) self.price = tk.Label(self.interior, text=price[i]) self.price.grid(row=irow, column=2) self.quantity = tk.Entry(self.interior, width=10) self.quantity.insert(0, "0") self.quantity.grid(row=irow, column=3) quantities.append(self.quantity) i += 1 irow += 1