forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hotel-Management.py
351 lines (268 loc) · 9.39 KB
/
Hotel-Management.py
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
def menu():
options = {
1 : {
"title" : "Add new customer details",
"method": lambda : add()
},
2 : {
"title" : "Modify already existing customer details",
"method": lambda : modify()
},
3 : {
"title" : "Search customer details",
"method": lambda : search()
},
4 : {
"title" : "View all customer details",
"method": lambda : view()
},
5 : {
"title" : "Delete customer details",
"method": lambda : remove()
},
6 : {
"title" : "Exit the program",
"method": lambda : exit()
}
}
print(f"\n\n{' '*25}Welcome to Hotel Database Management Software\n\n")
for num, option in options.items():
print(f"{num}: {option.get('title')}")
print()
options.get( int(input("Enter your choice(1-6): ")) ).get("method")()
def add():
Name1 = input("\nEnter your first name: \n")
Name2 = input("\nEnter your last name: \n")
Phone_Num = input("\nEnter your phone number(without +91): \n")
print("These are the rooms that are currently available")
print("1-Normal (500/Day)")
print("2-Deluxe (1000/Day)")
print("3-Super Deluxe (1500/Day)")
print("4-Premium Deluxe (2000/Day)")
Room_Type = int(input("\nWhich type you want(1-4): \n"))
match Room_Type:
case 1:
x = 500
Room_Type = "Normal"
case 2:
x = 1000
Room_Type = "Deluxe"
case 3:
x = 1500
Room_Type = "Super Deluxe"
case 4:
x = 2000
Room_Type = "Premium"
Days = int(input("How many days you will stay: "))
Money = x * Days
Money = str(Money)
print("")
print("You have to pay ", (Money))
print("")
Payment = input("Mode of payment(Card/Cash/Online): ").capitalize()
if Payment == "Card":
print("Payment with card")
elif Payment == "Cash":
print("Payment with cash")
elif Payment == "Online":
print("Online payment")
print("")
with open("Management.txt", "r") as File:
string = File.read()
string = string.replace("'", '"')
dictionary = json.loads(string)
if len(dictionary.get("Room")) == 0:
Room_num = "501"
else:
listt = dictionary.get("Room")
tempp = len(listt) - 1
temppp = int(listt[tempp])
Room_num = 1 + temppp
Room_num = str(Room_num)
print("You have been assigned Room Number", Room_num)
print(f"name : {Name1} {Name2}")
print(f"phone number : +91{Phone_Num}")
print(f"Room type : {Room_Type}")
print(f"Stay (day) : {Days}")
dictionary["First_Name"].append(Name1)
dictionary["Last_Name"].append(Name2)
dictionary["Phone_num"].append(Phone_Num)
dictionary["Room_Type"].append(Room_Type)
dictionary["Days"].append(Days)
dictionary["Price"].append(Money)
dictionary["Room"].append(Room_num)
with open("Management.txt", "w", encoding="utf-8") as File:
File.write(str(dictionary))
print("\nYour data has been successfully added to our database.")
exit_menu()
import os
import json
filecheck = os.path.isfile("Management.txt")
if not filecheck:
with open("Management.txt", "a", encoding="utf-8") as File:
temp1 = {
"First_Name": [],
"Last_Name": [],
"Phone_num": [],
"Room_Type": [],
"Days": [],
"Price": [],
"Room": [],
}
File.write(str(temp1))
def modify():
with open("Management.txt", "r") as File:
string = File.read()
string = string.replace("'", '"')
dictionary = json.loads(string)
dict_num = dictionary.get("Room")
dict_len = len(dict_num)
if dict_len == 0:
print("\nThere is no data in our database\n")
menu()
else:
Room = input("\nEnter your Room Number: ")
listt = dictionary["Room"]
index = int(listt.index(Room))
print("\n1-Change your first name")
print("2-Change your last name")
print("3-Change your phone number")
choice = int(input("\nEnter your choice: "))
print()
with open("Management.txt", "w", encoding="utf-8") as File:
match choice:
case 1:
category = "First_Name"
case 2:
category = "Last_Name"
case 3:
category = "Phone_num"
user_input = input(f"Enter New {category.replace('_', ' ')}")
listt1 = dictionary[category]
listt1[index] = user_input
dictionary[category] = None
dictionary[category] = listt1
File.write(str(dictionary))
print("\nYour data has been successfully updated")
exit_menu()
def search():
with open("Management.txt") as File:
dictionary = json.loads(File.read().replace("'", '"'))
dict_num = dictionary.get("Room")
dict_len = len(dict_num)
if dict_len == 0:
print("\nThere is no data in our database\n")
menu()
else:
Room = input("\nEnter your Room Number: ")
listt_num = dictionary.get("Room")
index = int(listt_num.index(Room))
listt_fname = dictionary.get("First_Name")
listt_lname = dictionary.get("Last_Name")
listt_phone = dictionary.get("Phone_num")
listt_type = dictionary.get("Room_Type")
listt_days = dictionary.get("Days")
listt_price = dictionary.get("Price")
print(f"\nFirst Name: {listt_fname[index]}")
print(f"Last Name: {listt_lname[index]}")
print(f"Phone number: {listt_phone[index]}")
print(f"Room Type: {listt_type[index]}")
print(f"Days staying: {listt_days[index]}")
print(f"Money paid: {listt_price[index]}")
print(f"Room Number: {listt_num[index]}")
exit_menu()
def remove():
with open("Management.txt") as File:
dictionary = json.loads(File.read().replace("'", '"'))
dict_num = dictionary.get("Room")
dict_len = len(dict_num)
if dict_len == 0:
print("\nThere is no data in our database\n")
menu()
else:
Room = input("\nEnter your Room Number: ")
listt = dictionary["Room"]
index = int(listt.index(Room))
listt_fname = dictionary.get("First_Name")
listt_lname = dictionary.get("Last_Name")
listt_phone = dictionary.get("Phone_num")
listt_type = dictionary.get("Room_Type")
listt_days = dictionary.get("Days")
listt_price = dictionary.get("Price")
listt_num = dictionary.get("Room")
del listt_fname[index]
del listt_lname[index]
del listt_phone[index]
del listt_type[index]
del listt_days[index]
del listt_price[index]
del listt_num[index]
dictionary["First_Name"] = None
dictionary["First_Name"] = listt_fname
dictionary["Last_Name"] = None
dictionary["Last_Name"] = listt_lname
dictionary["Phone_num"] = None
dictionary["Phone_num"] = listt_phone
dictionary["Room_Type"] = None
dictionary["Room_Type"] = listt_type
dictionary["Days"] = None
dictionary["Days"] = listt_days
dictionary["Price"] = None
dictionary["Price"] = listt_price
dictionary["Room"] = None
dictionary["Room"] = listt_num
with open("Management.txt", "w", encoding="utf-8") as file1:
file1.write(str(dictionary))
print("Details has been removed successfully")
exit_menu()
def view():
with open("Management.txt") as File:
dictionary = json.loads(File.read().replace("'", '"'))
dict_num = dictionary.get("Room")
dict_len = len(dict_num)
if dict_len == 0:
print("\nThere is no data in our database\n")
menu()
else:
listt = dictionary["Room"]
a = len(listt)
index = 0
while index != a:
listt_fname = dictionary.get("First_Name")
listt_lname = dictionary.get("Last_Name")
listt_phone = dictionary.get("Phone_num")
listt_type = dictionary.get("Room_Type")
listt_days = dictionary.get("Days")
listt_price = dictionary.get("Price")
listt_num = dictionary.get("Room")
print("")
print("First Name:", listt_fname[index])
print("Last Name:", listt_lname[index])
print("Phone number:", listt_phone[index])
print("Room Type:", listt_type[index])
print("Days staying:", listt_days[index])
print("Money paid:", listt_price[index])
print("Room Number:", listt_num[index])
print("")
index = index + 1
exit_menu()
def exit():
print("")
print(" Thanks for visiting")
print(" Goodbye")
def exit_menu():
print("")
print("Do you want to exit the program or return to main menu")
print("1-Main Menu")
print("2-Exit")
print("")
user_input = int(input("Enter your choice: "))
if user_input == 2:
exit()
elif user_input == 1:
menu()
try:
menu()
except KeyboardInterrupt as exit:
print("\nexiting...!")
# menu()