-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserInterface.py
More file actions
111 lines (99 loc) · 3.88 KB
/
UserInterface.py
File metadata and controls
111 lines (99 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#This file is for User Interface
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 16 10:52:06 2024
@author: inder
"""
#UserInterface
from Database import LibraryDatabase
import sys
class CommandLineInterface:
def __init__(self):
print("Welcome to Inderjit's library sytem version 1.0.")
self.db = LibraryDatabase("library.db")
self.mainMenu()
def mainMenu(self):
print("What would you like to do?")
print("")
print("1:Checkout/Return Book 2:Manage Books 3:User Information 4:Close Program")
try:
userInput = int(input())
if 0 < userInput < 5:
switcher = {
1: self.checkingReturning,
2: self.manageBooks,
3: self.userInformation,
4: self.termination
}
switcher.get(userInput)()
else:
print("This is not a vaild option try a number from 1-4.")
self.mainMenu()
except ValueError:
print("This is not a vaild option try a number from 1-4.")
self.mainMenu()
#this will allow the user to checkout and return book
def checkingReturning(self):
print("1:Checkout Book 2:Return Book 3:Return to Main Menu")
try:
userInput = int(input())
if 0 < userInput < 4:
switcher = {
1: self.db.checkout,
2: self.db.returnBook,
3: self.mainMenu
}
switcher.get(userInput)()
self.mainMenu()
else:
print("This is not a valid option try a number from 1-3.")
self.checkingReturning()
except ValueError:
print("This is not a valid option try a number from 1-3.")
self.checkingReturning()
#this will allow the user to manage the books,
def manageBooks(self):
print("1:Insert New Book 2:Find Book 3: Update Book Information 4:Delete Book 5: Return to main menu")
try:
userInput = int(input())
if 0 < userInput < 6:
switcher = {
1: self.db.insert,
2: self.db.select,
3: self.db.update,
4: self.db.delete,
5: self.mainMenu
}
switcher.get(userInput)()
self.mainMenu()
else:
print("This is not a valid option try a number from 1-5.")
self.manageBooks()
except ValueError:
print("This is not a valid option try a number from 1-5.")
self.manageBooks()
#This will allow the user to manage the borrowers
def userInformation(self):
print("1:Look Up User Information 2:Add New User 3: Delete User 4: Update User Information 5: Return to main menu")
try:
userInput = int(input())
if 0 < userInput < 6:
switcher = {
1: self.db.findUserInformation,
2: self.db.addUser,
3: self.db.deleteUser,
4: self.db.updateUser,
5: self.mainMenu
}
switcher.get(userInput)()
self.mainMenu()
else:
print("This is nor a valid option try a number from 1-5.")
self.userInformation()
except ValueError:
print("This is nor a valid option try a number from 1-5.")
self.userInformation()
def termination(self):
self.db.close_connection()
print("The program has closed.")
sys.exit()