def addToCart(self, cart): try: sql="insert into cart(foodId,foodQuantity,customerEmail) values(%d,%d,'%s')" i= c.execute(sql % (cart.getFoodId(),cart.getFoodQuantity(),cart.getCustomerEmail())) database.commit() print("food added to cart",i,"rows affected") except Exception as ex: print(ex)
def deleteCustInfo(self, customerId): try: sql = "delete from customer where CustomerId=%d" i = c.execute(sql % (customerId)) database.commit() if i is 0: print("id doesnt exist") else: print("data deleted", i, "rows affected") except Exception as ex: print(ex)
def addFood(self, food): try: sql = "insert into food (FoodName,FoodType,FoodCategory,FoodDescription,FoodPrice) values('%s','%s','%s','%s',%d)" i = c.execute(sql % (food.getFoodName(), food.getFoodType(), food.getFoodCategory(), food.getFoodDescription(), food.getFoodPrice())) database.commit() print("food Info added ", i, "rows affected") except Exception as ex: print(ex)
def deleteFood(self, foodId): try: sql = "delete from food where foodId=%d" i = c.execute(sql % (foodId)) database.commit() if i == 0: print("id doesnt exist") else: print("data deleted", i, "rows affected") except Exception as ex: print(ex)
def deleteCartByEmail(self, customerEmail): try: sql = "delete from cart where customerEmail='%s'" i = c.execute(sql % (customerEmail)) database.commit() if i is 0: print("email doesnt exist") else: print("data deleted", i, "rows affected") except Exception as ex: print(ex)
def deleteCartById(self, cartId): try: sql = "delete from cart where cartId=%d" i = c.execute(sql % (cartId)) database.commit() if i is 0: print("id doesnt exist") else: print("data deleted", i, "rows affected") except Exception as ex: print(ex)
def updateCart(self, cart): try: sql = "update cart set foodId=%d,foodQuantity=%d,customerEmail='%s' where cartId=%d" i = c.execute(sql % (cart.getFoodId(),cart.getFoodQuantity(),cart.getCustomerEmail(),cart.getcartId())) database.commit() if i == 0: print("ID doesnt exist") else: print("value updated", i, "rows affected") except Exception as ex: print(ex)
def addCustInfo(self, customer): try: sql = "insert into customer(customerName,customerEmail,customerPassword,customerContact,customerAddress) values('%s','%s','%s',%d,'%s')" i = c.execute( sql % (customer.getCustomerName(), customer.getCustomerEmail(), customer.getCustomerPassword(), customer.getCustomerContact(), customer.getCustomerAddress())) database.commit() print("customer Info added ", i, "rows affected") except Exception as ex: print(ex)
def updateFood(self, food): try: sql = "update food set FoodName='%s',FoodType='%s',FoodCategory='%s',FoodDescription='%s',FoodPrice=%d where foodId=%d" i = c.execute(sql % (food.getFoodName(), food.getFoodType(), food.getFoodCategory(), food.getFoodDescription(), food.getFoodPrice(), food.getFoodId())) database.commit() if i == 0: print("ID doesnt exist") else: print("value updated", i, "rows affected") except Exception as ex: print(ex)
def updateCustInfo(self, customer): try: sql = "update customer set CustomerName='%s',CustomerEmail='%s',CustomerPassword='******',CustomerContact=%d,CustomerAddress='%s' where CustomerId=%d" i = c.execute( sql % (customer.getCustomerName(), customer.getCustomerEmail(), customer.getCustomerPassword(), customer.getCustomerContact(), customer.getCustomerAddress(), customer.getCustomerId())) database.commit() if i == 0: print("ID doesnt exist") else: print("value updated", i, "rows affected") except Exception as ex: print(ex)
def searchFood(self, foodId): try: sql = "select * from food where foodId=%d" i = c.execute(sql % (foodId)) data = c.fetchone() food = Food(data[1], data[2], data[3], data[4], data[5]) database.commit() if i == 0: print("food Id doesn't exist") else: print("data search", i, "rows added") except Exception as ex: print(ex) return food
def searchBymail(self, customerEmail): customer = None try: sql = 'select * from customer where CustomerEmail like "%' "{}" '%"'.format( customerEmail) i = c.execute(sql) data = c.fetchone() customer = Customer(data[1], data[2], data[3], data[4], data[5]) database.commit() if i is 0: print(" Id doesn't exist") else: print("data search", i, "rows added") except Exception as ex: print(ex) return customer
def searchCustInfo(self, customerId): customer = None try: sql = "select * from customer where CustomerId=%d" i = c.execute(sql % (customerId)) data = c.fetchone() customer = Customer(data[1], data[2], data[3], data[4], data[5]) database.commit() if i is 0: print(" Id doesn't exist") else: print("data search", i, "rows added") except Exception as ex: print(ex) return customer
def showCart(self, customerEmail): cartlist = [] try: sql = "select cartId, FoodName, FoodPrice, foodQuantity from cart inner join food on cart.foodId=food.foodId where customerEmail='%s'" i = c.execute(sql % (customerEmail)) data = c.fetchall() for result in data: cart = Cart(result[0], None, customerEmail, result[1], result[2], result[3]) cartlist.append(cart) database.commit() if i == 0: print("cart data doesn't exist") else: pass except Exception as ex: print(ex) return cartlist
def getAllData(self): foodlist = [] try: sql = "select * from food" i = c.execute(sql) data = c.fetchall() for result in data: food = Food(result[1], result[2], result[3], result[4], result[5]) foodlist.append(food) database.commit() if i == 0: print("menu data doesn't exist") else: pass except Exception as ex: print(ex) return foodlist
def searchbyName(self, foodName): foodlist = [] try: sql = 'select * from food where foodName like "%' "{}" '%"'.format( foodName) i = c.execute(sql) data = c.fetchall() for result in data: food = Food(result[1], result[2], result[3], result[4], result[5]) foodlist.append(food) database.commit() if i == 0: print("Food doesn't exist") else: print("data search", i, "rows added") except Exception as ex: print(ex) return foodlist