Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk #importd tkinter and renames it as tk
- import sqlite3
- import re
- conn = sqlite3.connect('OS_Employee.db')
- LARGE_FONT= ("Verdana", 12)
- class Gui(tk.Tk): #creat Gui class and inherit attributes of tk.TK
- def __init__(self, *args, **kwargs): # the init methodology is going to initialize with the class right away this allows us to pass arguments and keyword arguments
- tk.Tk.__init__(self, *args, **kwargs) #initialize tk within the initialization function
- container = tk.Frame(self) # defines the container to be filled with a bunch of frames to be used later
- container.pack(side="top", fill="both", expand = True) # configure general display
- container.grid_rowconfigure(0, weight=1)
- container.grid_columnconfigure(0, weight=1)
- self.frames = {} #pre defined dictionary
- for F in (HomePage, LoginPage, RegistrationPage, Deliverable1, Display):
- frame = F(container, self)
- self.frames[F] = frame
- frame.grid(row=0, column=0, sticky="nsew") #using grid to place the widget
- self.show_frame(HomePage) #call show_frame to bring the frame we want
- def show_frame(self, cont):
- frame = self.frames[cont]
- frame.tkraise() # this will bring our frame to the top for the user to see
- class HomePage(tk.Frame):
- def __init__(self, parent,controller): #homepage
- tk.Frame.__init__(self,parent)
- self.configure(background="light grey")
- label = tk.Label(self, text="Buisness Solution", font=LARGE_FONT, bg="light grey").pack()
- label1 = tk.Label(self, text="online office supply retailer that ships furniture, tech, pens,\n files, etc. to consumers and corperations nation wide.", font=LARGE_FONT, bg="light grey",bd=1,relief="solid")
- label1.pack(pady=10,padx=10)
- button = tk.Button(self, text="Login", bg="#70ad47", fg="white",
- command=lambda: controller.show_frame(LoginPage))
- button.pack()
- button2 = tk.Button(self, text="New User?", bg="#70ad47", fg="white",
- command=lambda: controller.show_frame(RegistrationPage))
- button2.pack(pady=10)
- class LoginPage(tk.Frame):
- def __init__(self, parent, controller): #LoginPage
- tk.Frame.__init__(self, parent)
- self.controller = controller
- self.configure(background="light grey")
- LPlabel0 = tk.Label(self, text="Enter Email and Password", font=LARGE_FONT, bg="light grey").grid(row=0,column=0)
- LPlabel1 = tk.Label(self, text="Email:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=1,column=0)
- LPlabel2 = tk.Label(self, text="Password:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=2,column=0)
- self.username = tk.Entry(self)
- self.username.grid(row=1,column=1)
- self.password = tk.Entry(self)
- self.password.grid(row=2,column=1)
- self.status = tk.Label(self, fg='red', bg="light grey")
- self.status.grid(row=0,column=1)
- button1 = tk.Button(self, text="Back", bg="dark gray", fg="white",
- command=self.back)
- button1.grid(sticky="W",row=3,column=1,pady=4)
- button2 = tk.Button(self, text="Continue", bg="#70ad47", fg="white", #continue should go to diliverables
- command=self.login) #command=lambda: controller.show_frame(Deliverable1))
- button2.grid(sticky="E",row=3,column=1)
- def back(self):
- self.username.delete(0, 'end')
- self.password.delete(0, 'end')
- self.status.config(text="")
- self.controller.show_frame(HomePage)
- def login(self):
- with conn:
- cur = conn.cursor()
- try:
- # loginTest = False # main condition to loop if email and password not met
- # while not loginTest: # wrong email loopy
- userEmail = self.username.get()
- userEmail = userEmail.lower().replace(" ", "")
- userPassword = self.password.get()
- print("Username: {}, password: {}".format(userEmail, userPassword))
- cur.execute(
- "SELECT COUNT (*) FROM Employee WHERE(Email= '" + userEmail.lower() + "' AND Password= '" + userPassword + "')")
- results = cur.fetchone() # return very first thing it finds that matches
- print(results[0]) # print first thing
- if results[0] == 1:
- print("Login successful")
- loginTest = True
- self.username.delete(0, 'end')
- self.password.delete(0, 'end')
- self.status.config(text="")
- self.controller.show_frame(Deliverable1)
- else:
- print("Login Unsuccessful")
- self.status.config(text="wrong password or user name")
- self.username.delete(0, 'end')
- self.password.delete(0, 'end')
- self.controller.show_frame(LoginPage)
- except Exception as e:
- print(e)
- self.status.config(text="connection failed")
- class RegistrationPage(tk.Frame): #registrationpage
- def __init__(self, parent, controller):
- self.controller = controller
- tk.Frame.__init__(self, parent)
- self.configure(background="light grey")
- label = tk.Label(self, text="Complete the fields below", font=LARGE_FONT, bg="light grey").grid(row=0,column=0)
- label1 = tk.Label(self, text="First Name:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=1,column=0)
- label11 = tk.Label(self, text="Last Name:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=2,column=0)
- label2 = tk.Label(self, text="Employee ID:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=3,column=0)
- label3 = tk.Label(self, text="E-mail:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=4,column=0)
- label5 = tk.Label(self, text="Password:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=5,column=0)
- # label6 = tk.Label(self, text="Confirm PW:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=6,column=0)
- self.firstname = tk.Entry(self)
- self.firstname.grid(row=1,column=1)
- self.lastname = tk.Entry(self)
- self.lastname.grid(row=2,column=1)
- self.id = tk.Entry(self)
- self.id.grid(row=3,column=1)
- self.email = tk.Entry(self)
- self.email.grid(row=4,column=1)
- self.password = tk.Entry(self)
- self.password.grid(row=5,column=1)
- self.status = tk.Label(self, fg='red', bg="light grey")
- self.status.grid(row=0,column=1)
- # self.confirm_pass = tk.Entry(self)
- # self.confirm_pass.grid(row=6,column=1)
- button1 = tk.Button(self, text="Back", bg="dark gray", fg="white",
- command=self.back)
- button1.grid(sticky="w",row=6,column=1,pady=4)
- button2 = tk.Button(self, text="Continue", bg="#70ad47", fg="white",
- command=self.register) # command=lambda: controller.show_frame(LoginPage))
- button2.grid(sticky="E",row=6,column=1)
- def back(self):
- self.firstname.delete(0, "end")
- self.lastname.delete(0, "end")
- self.password.delete(0, "end")
- self.email.delete(0, "end")
- self.id.delete(0, "end")
- self.status.config(text="")
- self.controller.show_frame(HomePage)
- def register(self):
- with conn:
- cur = conn.cursor()
- try:
- if self.id.get():
- EmployeeID = int(self.id.get())
- FirstName = self.firstname.get()
- # while FirstName == "":
- # FirstName = self.firstname.get()
- # FirstName = FirstName.title()
- LastName = self.lastname.get()
- # while LastName == "":
- # LastName = self.lastname.get()
- # LastName = LastName.title()
- Email = self.email.get().lower()
- match = re.match('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$', Email)
- if match is None:
- print('Bad Syntax')
- #raise ValueError('Bad Syntax')
- Password = self.password.get()
- Password = Password.lower()
- cur.execute(
- 'insert into employee values(?,?,?,?,?)',
- (EmployeeID, FirstName, LastName, Email, Password))
- cur.execute(
- 'select * from employee where EmployeeId=?',
- (EmployeeID,))
- results = cur.fetchall()
- print(results)
- self.firstname.delete(0, "end")
- self.lastname.delete(0, "end")
- self.password.delete(0, "end")
- self.email.delete(0, "end")
- self.id.delete(0, "end")
- self.status.config(text="")
- self.controller.show_frame(Deliverable1)
- except Exception as e:
- print(e)
- print("User already exist")
- self.status.config(text="incorrect information")
- class Deliverable1(tk.Frame): #registrationpage
- def __init__(self, parent, controller):
- tk.Frame.__init__(self, parent)
- self.controller = controller
- self.configure(background="light grey")
- label = tk.Label(self, text="Select what to display", font=LARGE_FONT, bg="light grey").grid(row=0,column=0)
- label1 = tk.Label(self, text="10 Most Profitable:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=1,column=0)
- label2 = tk.Label(self, text="10 least profitable:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=2,column=0)
- label3 = tk.Label(self, text="Which State:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=3,column=0)
- label5 = tk.Label(self, text="Which Product:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=4,column=0)
- label6 = tk.Label(self, text="Year:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=5,column=0)
- label7 = tk.Label(self, text="Month:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=6,column=0)
- label8 = tk.Label(self, text="Quarter:", font=LARGE_FONT, bg="light grey").grid(sticky="E",row=7,column=0)
- entry1 = tk.Entry(self).grid(sticky="W",row=6,column=1)
- entry2 = tk.Entry(self).grid(sticky="W",row=7,column=1)
- self.status = tk.Label(self, fg='red', bg="light grey")
- self.status.grid(row=0,column=1)
- v = tk.IntVar()
- tk.Radiobutton(self, variable=v, value=1, bg="light grey").grid(sticky="W",row=2,column=1)
- tk.Radiobutton(self, variable=v, value=2, bg="light grey").grid(sticky="W",row=1,column=1)
- button1 = tk.Button(self, text="Log Out", bg="red", fg="white", #make the back button a logout button?
- command=self.logout) #command=lambda: controller.show_frame(HomePage))
- button1.grid(sticky="w",row=8,column=1,pady=5)
- button2 = tk.Button(self, text="Continue", bg="#70ad47", fg="white", #go to displayproducts in order
- command=lambda: controller.show_frame(Display))
- button2.grid(sticky="E",row=8,column=1)
- self.state = tk.Entry(self)
- self.state.grid(sticky="W",row=3,column=1)
- self.product = tk.Entry(self)
- self.product.grid(sticky="W",row=4,column=1)
- self.year = tk.Entry(self)
- self.year.grid(sticky="W",row=5,column=1)
- def logout(self):
- self.status.config(text="")
- self.controller.show_frame(HomePage)
- class Display(tk.Frame):
- def __init__(self, parent, controller): #homepage
- tk.Frame.__init__(self,parent)
- self.configure(background="light grey")
- label = tk.Label(self, text="Profitable products", font=LARGE_FONT, bg="light grey").pack(pady=10)
- listbox = tk.Listbox(self).pack()
- #for i in range(20):
- #listbox.insert(END, str(i))
- button = tk.Button(self, text="Back", bg="dark grey", fg="white",
- command=lambda: controller.show_frame(Deliverable1))
- button.pack(pady=7)
- app = Gui() #App is the object of the Gui class
- app.mainloop() # then run .mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement