Skip to content

Commit

Permalink
Edit Address
Browse files Browse the repository at this point in the history
  • Loading branch information
miladbarooni committed Jan 24, 2020
1 parent ed607d1 commit ae94c81
Show file tree
Hide file tree
Showing 3 changed files with 319 additions and 22 deletions.
238 changes: 229 additions & 9 deletions AdminGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def makeMainWindow(self):
def loginPage(self):
def loginVarify():
admin_details = mydb.adminLogin(username_login_entry.get())
self.shop_id = admin_details[0][2]
if (password_login_entry.get() == admin_details[0][1]):
self.dashboardPage()
else:
Expand Down Expand Up @@ -174,13 +175,13 @@ def dashboardPage(self):
self.dashboard_screen.title("Dashboard")
Label(self.dashboard_screen, text="Select Your Choice", bg="blue", width="300", height="2", font=("Calibri", 13)).pack()
Label(text="").pack()
Button(self.dashboard_screen,text="Profile", height="2", width="30", command = self.profilePage).pack()
Label(text="").pack()
Button(self.dashboard_screen,text="Foods (add, delete)", height="2", width="30", command=self.foodsPage).pack()

Button(self.dashboard_screen,text="Show all Foods", height="2", width="30", command=self.showFoods).pack()
Label(text="").pack()
Button(self.dashboard_screen,text="Order", height="2", width="30", command=self.orderPage).pack()
Button(self.dashboard_screen,text="Search", height="2", width="30", command=self.searchFoodOrShop).pack()
Button(self.dashboard_screen,text="Charge your wallet", height="2", width="30", command=self.chargeWallet).pack()
Button(self.dashboard_screen,text="Add food", height="2", width="30", command=self.addFood).pack()
Button(self.dashboard_screen,text="Preparing orders", height="2", width="30", command=self.preparingOrders).pack()
Button(self.dashboard_screen,text="All Compelete orders", height="2", width="30", command=self.allOrders).pack()
Button(self.dashboard_screen,text="Show comments", height="2", width="30", command=self.showComment).pack()

closeButton = Button(self.dashboard_screen, text="Exit", command=self.dashboard_screen.destroy, width="200", height="2")
closeButton.pack()
Expand All @@ -194,13 +195,232 @@ def registerUser(self ,phone_number_entry, password_entry, repeat_password_entry
else:
messagebox.showinfo('Repeat password again', 'your repeated password doesn\'n match your entered password, Try Again')


def showFoods(self):
self.show_food_screen = Tk()
self.show_food_screen.title("Foods")
foods = mydb.showFoodsOfShop(self.shop_id)
print (foods)
Label(self.show_food_screen, text="All foods, double click to delete", bg="red", width="300", height="2", font=("Calibri", 13)).pack()
Label(text="").pack()
tree=Treeview(self.show_food_screen,style="mystyle.Treeview")
tree["columns"]=("one","two","three", "four", "five")
#set tree columns
tree.column("#0", width=150, minwidth=150, stretch=tk.NO)
tree.column("one", width=400, minwidth=200)
tree.column("two", width=80, minwidth=50, stretch=tk.YES)
tree.column("three", width=80, minwidth=50, stretch=tk.YES)
tree.column("four", width=80, minwidth=50, stretch=tk.YES)
tree.column("five", width=80, minwidth=50, stretch=tk.YES)
#set tree's heading
tree.heading("#0", text="Name",anchor=tk.W)
tree.heading("one", text="Price",anchor=tk.W)
tree.heading("two", text="About",anchor=tk.W)
tree.heading("three", text="Category",anchor=tk.W)
tree.heading("four", text="Image",anchor=tk.W)
tree.heading("five", text="Discount",anchor=tk.W)
tree.pack()
for i in range(len(foods)):
tree.insert("", i+1, text=foods[i][3], values=(foods[i][1], foods[i][2], mydb.showCategoryName(foods[i][6]), foods[i][5], str(foods[i][4])))
tree.bind("<Double-1>", partial(self.OnDoubleClickDeleteFood,tree,foods))

def OnDoubleClickDeleteFood(self, tree,foods, event):
item = tree.identify('item',event.x,event.y)
food_name = tree.item(item,"text")
for food in foods:
if food[3] == food_name:
food_id = food[0]
mydb.deleteFood(food_id)


def addFood(self):
print ("add food")

def profilePage(self):
print ("Profile page")
def addNewFood():
mydb.addFood(price_entry.get(), about_entry.get(), name_entry.get(), discount_entry.get(), cat_combo.get()[0], self.shop_id)



self.add_food_screen = Tk()
self.add_food_screen.title("Add a new food")
# mydb.addFood()
#price
Label(self.add_food_screen, text="Add A price for your food").pack()
price_entry = Entry(self.add_food_screen)
price_entry.pack()
#about
Label(self.add_food_screen, text="About your food").pack()
about_entry = Entry(self.add_food_screen)
about_entry.pack()
#Name
Label(self.add_food_screen, text="Choose a name").pack()
name_entry = Entry(self.add_food_screen)
name_entry.pack()
#Discount
Label(self.add_food_screen, text="Enter a discount").pack()
discount_entry = Entry(self.add_food_screen)
discount_entry.pack()
#Categori
Label(self.add_food_screen, text="choose a category").pack()
cat_combo = Combobox(self.add_food_screen)
catogries = mydb.showAllCategory()
self.number_of_catogry = len(catogries)
catogri_list = []
print (catogries)
for i in catogries:
catogri_list.append(str(i[0])+ " "+ i[1])
cat_combo['values']= catogri_list
cat_combo.pack()
Button(self.add_food_screen, text="add new food", command=addNewFood).pack()



def preparingOrders(self):
self.prepare_screen = Tk()
self.prepare_screen.title("Preparing")
all_history = mydb.showActiveOrder(self.shop_id)
print (all_history)
Label(self.prepare_screen, text="All your orders", bg="yellow", width="300", height="2", font=("Calibri", 13)).pack()
Label(text="").pack()
tree=Treeview(self.prepare_screen, style="mystyle.Treeview")
tree["columns"]=("one","two","three", "four")
#set tree columns
tree.column("#0", width=270, minwidth=270, stretch=tk.NO)
tree.column("one", width=150, minwidth=150, stretch=tk.NO)
tree.column("two", width=400, minwidth=200)
tree.column("three", width=80, minwidth=50, stretch=tk.YES)
tree.column("four", width=80, minwidth=50, stretch=tk.YES)
#set tree's heading
tree.heading("#0",text="Order#",anchor=tk.W)
tree.heading("one", text="Total Price",anchor=tk.W)
tree.heading("two", text="Address",anchor=tk.W)
tree.heading("three", text="Status",anchor=tk.W)
tree.heading("four", text="Foods",anchor=tk.W)
invoic_dict = {}
print(all_history)
for history in all_history:
if ((history[0],history[1],history[2], history[4]) in invoic_dict.keys()):
invoic_dict[(history[0],history[1],history[2], history[4])].append(history[3])
else:
invoic_dict[(history[0],history[1],history[2], history[4])] = []
invoic_dict[(history[0],history[1],history[2], history[4])].append(history[3])

# print (type(list(invoic_dict.keys())))
print (invoic_dict)

tree.pack(side=tk.TOP,fill=tk.X)
orders_list = []
for key in invoic_dict.keys():
orders_list.append(key[0])
for i in range(len(list(invoic_dict.keys()))):
order_number = list(invoic_dict.keys())[i][0]
address_id = list(invoic_dict.keys())[i][2]
foods_list = invoic_dict[list(invoic_dict.keys())[i]]
print (foods_list)
tree.insert("", i+1, text="Order#"+str(order_number), values=(list(invoic_dict.keys())[i][1], self.make_address_str(address_id),list(invoic_dict.keys())[i][3] ,self.make_foods_str(foods_list)))
tree.bind("<Double-1>", partial(self.OnDoubleClickChangeStatus,tree))

def OnDoubleClickChangeStatus(self, tree, event):
item = tree.identify('item',event.x,event.y)
status = tree.set(tree.identify_row(event.y))['three']
order_name = tree.item(item,"text")
order_number = int(order_name[order_name.index("#")+1:])
if (status == "Prepration"):
mydb.setStateToSending(order_number)
elif (status=="Sending"):
mydb.setStateToComplete(order_number)

def allOrders(self):
self.all_orders_screen = Tk()
self.all_orders_screen.title("All Orders")
all_history = mydb.showShopHistory(self.shop_id)
print (all_history)
Label(self.all_orders_screen, text="All your orders", bg="yellow", width="300", height="2", font=("Calibri", 13)).pack()
Label(text="").pack()
tree=Treeview(self.all_orders_screen, style="mystyle.Treeview")
tree["columns"]=("one","two","three", "four")
#set tree columns
tree.column("#0", width=270, minwidth=270, stretch=tk.NO)
tree.column("one", width=150, minwidth=150, stretch=tk.NO)
tree.column("two", width=400, minwidth=200)
tree.column("three", width=80, minwidth=50, stretch=tk.YES)
tree.column("four", width=80, minwidth=50, stretch=tk.YES)
#set tree's heading
tree.heading("#0",text="Order#",anchor=tk.W)
tree.heading("one", text="Total Price",anchor=tk.W)
tree.heading("two", text="Address",anchor=tk.W)
tree.heading("three", text="Status",anchor=tk.W)
tree.heading("four", text="Foods",anchor=tk.W)
invoic_dict = {}
print(all_history)
for history in all_history:
if ((history[0],history[1],history[2], history[4]) in invoic_dict.keys()):
invoic_dict[(history[0],history[1],history[2], history[4])].append(history[3])
else:
invoic_dict[(history[0],history[1],history[2], history[4])] = []
invoic_dict[(history[0],history[1],history[2], history[4])].append(history[3])

# print (type(list(invoic_dict.keys())))
# print (invoic_dict)

tree.pack(side=tk.TOP,fill=tk.X)
orders_list = []
for key in invoic_dict.keys():
orders_list.append(key[0])
for i in range(len(list(invoic_dict.keys()))):
order_number = list(invoic_dict.keys())[i][0]
address_id = list(invoic_dict.keys())[i][2]
foods_list = invoic_dict[list(invoic_dict.keys())[i]]
print (foods_list)
tree.insert("", i+1, text="Order#"+str(order_number), values=(list(invoic_dict.keys())[i][1], self.make_address_str(address_id),list(invoic_dict.keys())[i][3] ,self.make_foods_str(foods_list)))

def showComment(self):
self.show_comment_screen = Tk()
self.show_comment_screen.title("comments")
comments = mydb.showAllComments(self.shop_id)
comments = list(dict.fromkeys(comments))
Label(self.show_comment_screen, text="All your Comments", bg="yellow", width="300", height="2", font=("Calibri", 13)).pack()
Label(text="").pack()
tree=Treeview(self.show_comment_screen, style="mystyle.Treeview")
tree["columns"]=("one")
#set tree columns
tree.column("#0", width=270, minwidth=270, stretch=tk.NO)
tree.column("one", width=150, minwidth=150, stretch=tk.NO)

#set tree's heading
tree.heading("#0",text="Comment",anchor=tk.W)
tree.heading("one", text="Rate",anchor=tk.W)


for i in range(len(comments)):
tree.insert("", 1, text=comments[i][4], values=(comments[i][5]))
tree.pack(side=tk.TOP,fill=tk.X)


def make_address_str(self, address_id):
address_info = mydb.showAddress(address_id)
address_info = address_info[0]
address_str = address_info[0] + ", "
# print (address_info)
for i in range(2,6):
address_str += address_info[i] + ", "
# print (address_str)
return address_str

def make_foods_str(self, foods_list):
food_str_dict = {}
for food in foods_list:
food_str = mydb.showFoods([food])[0][3]
if food_str in food_str_dict.keys():
food_str_dict[food_str] += 1
else:
food_str_dict[food_str] = 1

return_str = ""
for food_name in list(food_str_dict.keys()):
return_str += food_name + ": "
return_str += str(food_str_dict[food_name]) + " "
return return_str

root = Tk()
my_gui = Application(root)
root.mainloop()
Loading

0 comments on commit ae94c81

Please sign in to comment.