示例#1
0
    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.")
示例#2
0
    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')
示例#3
0
文件: login.py 项目: vunhuanh/gourmet
    def callback(self):
        self.givenemail = self.emailbox.get()
        self.givenpassword = self.passwordbox.get()

        db = DBconnection.connecting()
        conn = db.connect()
        query = "SELECT COUNT(*) FROM users u WHERE u.useremail = \'{0}\' AND u.password = \'{1}\'; ".format(
            self.givenemail, self.givenpassword)
        result_set = conn.execute(query)
        conn.close()

        count = []
        for r in result_set:
            count.append(r[0])

        if int(count[0]) == 1:
            setGlobal('useremail', self.givenemail)
            self.emailbox.delete(0, tk.END)
            self.passwordbox.delete(0, tk.END)
            self.controller.show_frame("Homepage")

        else:
            tkMessageBox.showerror("error",
                                   "please recheck your password or email")
示例#4
0
 def logout(self, event):
     setGlobal('useremail', 'None')
     setGlobal('lnb_reserve', 'None')
     setGlobal('lnb_pickup', 'None')
     setGlobal('lnb_event', 'None')
     setGlobal('lnb_review', 'None')
     setGlobal('cartid', 'None')
     setGlobal('pickup_price', '0.0')
     setGlobal('event_price', '0.0')
     setGlobal('total_price', '0.0')
     setGlobal('irow', '4')
     self.controller.show_frame("Mainpage")
示例#5
0
 def userreview(self, event, arg):
     setGlobal('lnb_review', arg)
     self.controller.show_frame("MakeReview")
示例#6
0
 def allreview(self, event, arg):
     setGlobal('lnb_review', arg)
     self.controller.show_frame("AllReviews")
示例#7
0
 def mkres(self, event, arg):
     setGlobal('lnb_reserve', arg)
     self.controller.show_frame("MakeReservation")
示例#8
0
    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))
示例#9
0
 def menu(self, event, arg):
     setGlobal('lnb_pickup', arg)
     self.controller.show_frame("R_menu")