def update_DB(self): conn = create_connection("airline.db") c = conn.cursor() seats_string = json.dumps(self.seats) customer_string = json.dumps(self.customer_list) # update the current flight's info with conn: c.execute("UPDATE FLIGHT SET SCORE=? WHERE NUMBER=?", (self.score, self.number)) c.execute("UPDATE FLIGHT SET SEATS=? WHERE NUMBER=?", (seats_string, self.number)) c.execute("UPDATE FLIGHT SET CUSTOMERS=? WHERE NUMBER=?", (customer_string, self.number)) c.execute("UPDATE FLIGHT SET ACTIVE=? WHERE NUMBER=?", (str(self.active), self.number))
def __init__(self, parent, controller): tk.Frame.__init__(self, parent) conn = create_connection("airline.db") cursor = conn.cursor() f = Flight() # ----Home/Current Flight/Sign Out---- home_button = ttk.Button( self, text="Home", command=lambda: controller.show_frame(ManagerPortal)) home_button.grid(row=0, column=0, pady=5, columnspan=2) sign_out_button = ttk.Button( self, text="Sign Out", command=lambda: controller.show_frame(ManagerSignIn)) sign_out_button.grid(row=0, column=4, pady=5, columnspan=2) # ----Logo and Titles---- load = Image.open("logo.png") load = load.resize((150, 85), Image.ANTIALIAS) render = ImageTk.PhotoImage(load) img = tk.Label(self, image=render) img.image = render img.grid(row=1, column=0, padx=100, columnspan=6) title1 = ttk.Label(self, text="Sunset Chaser Airlines") title1.grid(row=2, column=0, padx=20, pady=2, columnspan=6) title2 = ttk.Label(self, text="Manger Portal") title2.grid(row=3, column=0, padx=20, pady=5, columnspan=6) # ----Display Score---- info1 = ttk.Label(self, text="The Satisfaction Idex reflects") info2 = ttk.Label(self, text="a group of randomly chosen customers") info3 = ttk.Label(self, text="and their satisfaction with the flight.") info1.grid(row=4, column=0, padx=5, columnspan=6) info2.grid(row=5, column=0, padx=5, columnspan=6) info3.grid(row=6, column=0, padx=5, columnspan=6) # get previous flight score flight_num = f.number - 1 with conn: cursor.execute("SELECT * FROM FLIGHT WHERE NUMBER=?", (flight_num, )) rows = cursor.fetchall() score = rows[0][1] score_string = "Flight #" + str(flight_num) + ": " + str(score) score_label = tk.Label(self, text=score_string) score_label.grid(row=7, column=0, pady=15, columnspan=12)
def __init__(self): conn = create_connection("airline.db") c = conn.cursor() # get the current flight's info with conn: c.execute("SELECT * FROM FLIGHT WHERE ACTIVE=?", ("True",)) rows = c.fetchall() self.number = rows[0][0] self.score = rows[0][1] self.seats = json.loads(rows[0][2]) self.active = rows[0][3] self.customer_list = json.loads(rows[0][4]) self.seat_names = ["1A", "1B", "1C", "1D", "1E", "1F", "2A", "2B", "2C", "2D", "2E", "2F", "3A", "3B", "3C", "3D", "3E", "3F", "4A", "4B", "4C", "4D", "4E", "4F", "5A", "5B", "5C", "5D", "5E", "5F", "6A", "6B", "6C", "6D", "6E", "6F", "7A", "7B", "7C", "7D", "7E", "7F", "8A", "8B", "8C", "8D", "8E", "8F", "9A", "9B", "9C", "9D", "9E", "9F", "10A", "10B", "10C", "10D", "10E", "10F", "11A", "11B", "11C", "11D", "11E", "11F", "12A", "12B", "12C", "12D", "12E", "12F", "13A", "13B", "13C", "13D", "13E", "13F", "14A", "14B", "14C", "14D", "14E", "14F", "15A", "15B", "15C", "15D", "15E", "15F", "16A", "16B", "16C", "16D", "16E", "16F", "17A", "17B", "17C", "17D", "17C", "17E", "17F", "18A", "18B", "18C", "18D", "18E", "18F", "19A", "19B", "19C", "19D", "19C", "19E", "19F", "20A", "20B", "20C", "20D", "20E", "20F"] self.left_window_seats = [] self.right_window_seats = [] for i in range(120): # Left window seat if i % 6 == 0: self.left_window_seats.append(i) # Right window seat if (i+1) % 6 == 0: self.right_window_seats.append(i) self.left_aisle_seats = [] self.right_aisle_seats = [] for i in range(120): # Make sure not a window seat if i not in self.left_window_seats: if i not in self.right_window_seats: # Left aisle seat if (i+1) % 3 == 0: self.left_aisle_seats.append(i) # Right aisle seat if i % 3 == 0: self.right_aisle_seats.append(i)
def update_DB(self): conn = create_connection("airline.db") c = conn.cursor() seats_string = json.dumps(self.seats) with conn: c.execute("UPDATE CUSTOMER SET FLIGHT_NUMBER=? WHERE USER=?", (self.flight_num, self.username)) c.execute("UPDATE CUSTOMER SET TRAVEL_TYPE=? WHERE USER=?", (self.type, self.username)) c.execute("UPDATE CUSTOMER SET SEATS=? WHERE USER=?", (seats_string, self.username)) c.execute("UPDATE CUSTOMER SET SATISFACTION=? WHERE USER=?", (self.satisfaction, self.username))
def __init__(self, username, password, auth_code): self.username = username self.password = password self.auth_code = auth_code conn = create_connection("airline.db") c = conn.cursor() # Add To Database insert_string = "INSERT INTO MANAGER (USER, PASSWORD, AUTH_CODE) VALUES (?, ? , ?)" with conn: c.execute(insert_string, [self.username, str(self.password), int(self.auth_code)])
def test_createCustomer(self): Customer("newCustomer", "p@sSw0rD") # check DB now to see that the manager was created conn = create_connection("airline.db") c = conn.cursor() # Check if User/Pass match DB with conn: c.execute("SELECT * FROM CUSTOMER WHERE USER=?", ("newCustomer", )) rows = c.fetchall() username = rows[0][0] password = rows[0][1] self.assertEqual(username, "newCustomer") self.assertEqual(password, "p@sSw0rD")
def create_new_flight(self): self.seats = ['None']*120 self.active = 'True' self.number += 1 self.customer_list = [''] conn = create_connection("airline.db") c = conn.cursor() seats_string = json.dumps(self.seats) customer_string = json.dumps(self.customer_list) # Add To Database insert_string = "INSERT INTO FLIGHT (NUMBER, SCORE, SEATS, ACTIVE, CUSTOMERS) VALUES (?, ? , ?, ?, ?)" with conn: c.execute(insert_string, [self.number, self.score, seats_string, str(self.active), customer_string]) # initiate again self.__init__()
def __init__(self, username, password=""): # If the user is already created we need to pull from the database conn = create_connection("airline.db") c = conn.cursor() exists = False with conn: c.execute("SELECT * FROM CUSTOMER") rows = c.fetchall() for r in rows: if r[0] == username: exists = True self.username = r[0] self.password = r[1] self.flight_num = r[2] self.type = r[3] self.seats = json.loads(r[4]) self.satisfaction = r[5] break if exists is False: self.username = username self.password = password self.flight_num = '' self.type = '' self.seats = [] seats_string = json.dumps(self.seats) self.satisfaction = 0 # Add to DB insert_string = "INSERT INTO CUSTOMER (USER, PASSWORD, FLIGHT_NUMBER, TRAVEL_TYPE, SEATS, SATISFACTION) VALUES (?, ?, ?, ?, ?, ?)" with conn: c.execute(insert_string, [ str(self.username), str(self.password), self.flight_num, str(self.type), seats_string, self.satisfaction ])
def __init__(self, parent, controller): tk.Frame.__init__(self, parent) conn = create_connection("airline.db") cursor = conn.cursor() # ----Logo and Title---- load = Image.open("logo.png") load = load.resize((150, 85), Image.ANTIALIAS) render = ImageTk.PhotoImage(load) img = tk.Label(self, image=render) img.image = render img.grid(row=0, column=0, columnspan=2) title = ttk.Label(self, text="Sunset Chaser Airlines") title.grid(row=1, column=0, pady=10, columnspan=2) # ---- Login ---- def logIn(): user = username1_entry.get() pw = pw_entry.get() # Check if User/Pass match DB with conn: cursor.execute("SELECT * FROM MANAGER") row = cursor.fetchall() for r in row: if r[0] == user: if str(r[1]) == pw: # Navigate To Manager Portal controller.refresh_user(user, "manager") controller.show_frame(ManagerPortal) return # Throw Error If They Do Not Match error1['text'] = "Either the Username or PW is not correct" login = ttk.Label(self, text="Manager Login") login.grid(row=2, column=0, pady=10, columnspan=2) username1_label = ttk.Label(self, text="Username:"******" ") username1_entry.grid(row=3, column=1, padx=10, pady=4) pw_label = ttk.Label(self, text="Password:"******"*") pw_entry.grid(row=4, column=1, padx=10, pady=4) submit1 = ttk.Button(self, text="Submit", command=lambda: logIn()) submit1.grid(row=5, column=0, columnspan=2, pady=5) error1 = ttk.Label(self, text="", foreground="#ff0000") error1.grid(row=6, column=0, columnspan=2, pady=5) # ---- Sign Up ---- def signUp(): user = username2_entry.get() pw1 = pw1_entry.get() pw2 = pw2_entry.get() code = code_entry.get() # Make sure entries are not empty if user != "" and pw1 != "" and code != "": # Check if username is taken or not with conn: cursor.execute("SELECT * FROM MANAGER") row = cursor.fetchall() for r in row: if r[0] == user: error2['text'] = "Username already taken" return # Check That PW Match if pw1 != pw2: error2['text'] = "Passwords do not match" return # Add New Manager to DB Manager(user, pw1, code) # Navigate To Manager Portal controller.refresh_user(user, "manager") controller.show_frame(ManagerPortal) sign_up = ttk.Label(self, text="Need an account? Sign up here") sign_up.grid(row=7, column=0, pady=10, columnspan=2) username2_label = ttk.Label(self, text="Username:"******"Password:"******"*") pw1_entry.grid(row=9, column=1, padx=10, pady=4) pw2_label = ttk.Label(self, text="Re-Enter Password:"******"*") pw2_entry.grid(row=10, column=1, padx=10, pady=4) code_label = ttk.Label(self, text="Security Code:") code_label.grid(row=11, column=0, padx=10, pady=4) code_entry = ttk.Entry(self, width=20, show="*") code_entry.grid(row=11, column=1, padx=10, pady=4) submit2 = ttk.Button(self, text="Submit", command=lambda: signUp()) submit2.grid(row=12, column=0, columnspan=2, pady=5) error2 = ttk.Label(self, text="", foreground="#ff0000") error2.grid(row=13, column=0, columnspan=2, pady=5) # ---- Button Back To Customer Portal ---- manager_button = ttk.Button( self, text="Customer Portal", command=lambda: controller.show_frame(HomePage)) manager_button.grid(row=14, column=0, pady=20, columnspan=2)
def __init__(self, parent, controller): tk.Frame.__init__(self, parent) conn = create_connection("airline.db") cursor = conn.cursor() f = Flight() # ----Home/Current Flight/Sign Out---- home_button = ttk.Button( self, text="Home", command=lambda: controller.show_frame(CustomerPortal)) home_button.grid(row=0, column=0, pady=5) flight_string = "Flight #" + str(f.number) flight_label = ttk.Label(self, text=flight_string) flight_label.grid(row=0, column=1, pady=5) sign_out_button = ttk.Button( self, text="Sign Out", command=lambda: controller.show_frame(HomePage)) sign_out_button.grid(row=0, column=2, pady=5) # ----Logo and Titles---- load = Image.open("logo.png") load = load.resize((150, 85), Image.ANTIALIAS) render = ImageTk.PhotoImage(load) img = tk.Label(self, image=render) img.image = render img.grid(row=1, column=0, padx=100, columnspan=3) title1 = ttk.Label(self, text="Sunset Chaser Airlines") title1.grid(row=2, column=0, padx=20, pady=2, columnspan=3) title2 = ttk.Label(self, text="Customer Portal") title2.grid(row=3, column=0, padx=20, pady=2, columnspan=3) title3 = ttk.Label(self, text="What type of seat(s) do you need?") title3.grid(row=4, column=0, padx=20, pady=2, columnspan=3) # ----Ticket Options---- def travelerType(selection): if selection == 'Business Traveler (1) - Business Select': return "BT-BS" elif selection == 'Business Traveler (1) - Normal Seating': return "BT-N" elif selection == 'Tourist Travelers (2)': return "TT" elif selection == 'Family Travelers (2 adults + 1 child)': return "FT-1" elif selection == 'Family Travelers (2 adults + 2 child)': return "FT-2" elif selection == 'Family Travelers (2 adults + 3 child)': return "FT-3" def updateTraveler(): if ticket_options.get() != '': type = travelerType(ticket_options.get()) with conn: cursor.execute( "UPDATE CUSTOMER SET TRAVEL_TYPE=? WHERE USER=?", (type, controller.USER)) controller.refresh_user(controller.USER, "customer") controller.show_frame(ConfirmSeats) s = tk.StringVar() ticket_options = ttk.Combobox(self, state="readonly", width=27, textvariable=s) ticket_options['values'] = ('Business Traveler (1) - Business Select', 'Business Traveler (1) - Normal Seating', 'Tourist Travelers (2)', 'Family Travelers (2 adults + 1 child)', 'Family Travelers (2 adults + 2 child)', 'Family Travelers (2 adults + 3 child)') ticket_options.grid(row=5, column=0, pady=20, columnspan=3) ticket_options.current(0) submit = ttk.Button(self, text="Submit", command=lambda: updateTraveler()) submit.grid(row=6, column=0, columnspan=3, padx=10)