forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHotel-Management.py
393 lines (311 loc) · 10 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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
def menu():
print("")
print("")
print(" Welcome to Hotel Database Management Software")
print("")
print("")
print("1-Add new customer details")
print("2-Modify already existing customer details")
print("3-Search customer details")
print("4-View all customer details")
print("5-Delete customer details")
print("6-Exit the program")
print("")
user_input = int(input("Enter your choice(1-6): "))
if user_input == 1:
add()
elif user_input == 2:
modify()
elif user_input == 3:
search()
elif user_input == 4:
view()
elif user_input == 5:
remove()
elif user_input == 6:
exit()
def add():
print("")
Name1 = input("Enter your first name: ")
print("")
Name2 = input("Enter your last name: ")
print("")
Phone_Num = input("Enter your phone number(without +91): ")
print("")
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)")
print("")
Room_Type = int(input("Which type you want(1-4): "))
print("")
if Room_Type == 1:
x = 500
Room_Type = "Normal"
elif Room_Type == 2:
x = 1000
Room_Type = "Deluxe"
elif Room_Type == 3:
x = 1500
Room_Type = "Super Deluxe"
elif Room_Type == 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("")
File = open("Management.txt", "r")
string = File.read()
string = string.replace("'", '"')
dictionary = json.loads(string)
File.close()
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)
File = open("Management.txt", "w", encoding="utf-8")
File.write(str(dictionary))
File.close()
print("")
print("Your data has been successfully added to our database.")
exit_menu()
import os
import json
filecheck = os.path.isfile("Management.txt")
if filecheck == False:
File = open("Management.txt", "a", encoding="utf-8")
temp1 = {
"First_Name": [],
"Last_Name": [],
"Phone_num": [],
"Room_Type": [],
"Days": [],
"Price": [],
"Room": [],
}
File.write(str(temp1))
File.close()
def modify():
File = open("Management.txt", "r")
string = File.read()
string = string.replace("'", '"')
dictionary = json.loads(string)
File.close()
dict_num = dictionary.get("Room")
dict_len = len(dict_num)
if dict_len == 0:
print("")
print("There is no data in our database")
print("")
menu()
else:
print("")
Room = input("Enter your Room Number: ")
listt = dictionary["Room"]
index = int(listt.index(Room))
print("")
print("1-Change your first name")
print("2-Change your last name")
print("3-Change your phone number")
print("")
choice = input("Enter your choice: ")
print("")
File = open("Management.txt", "w", encoding="utf-8")
if choice == str(1):
user_input = input("Enter New First Name: ")
listt1 = dictionary["First_Name"]
listt1[index] = user_input
dictionary["First_Name"] = None
dictionary["First_Name"] = listt1
File.write(str(dictionary))
File.close()
elif choice == str(2):
user_input = input("Enter New Last Name: ")
listt1 = dictionary["Last_Name"]
listt1[index] = user_input
dictionary["Last_Name"] = None
dictionary["Last_Name"] = listt1
File.write(str(dictionary))
File.close()
elif choice == str(3):
user_input = input("Enter New Phone Number: ")
listt1 = dictionary["Phone_num"]
listt1[index] = user_input
dictionary["Phone_num"] = None
dictionary["Phone_num"] = listt1
File.write(str(dictionary))
File.close()
print("")
print("Your data has been successfully updated")
exit_menu()
def search():
File = open("Management.txt", "r")
string = File.read()
string = string.replace("'", '"')
dictionary = json.loads(string)
File.close()
dict_num = dictionary.get("Room")
dict_len = len(dict_num)
if dict_len == 0:
print("")
print("There is no data in our database")
print("")
menu()
else:
print("")
Room = input("Enter your Room Number: ")
print("")
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")
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])
exit_menu()
def remove():
File = open("Management.txt", "r")
string = File.read()
string = string.replace("'", '"')
dictionary = json.loads(string)
File.close()
dict_num = dictionary.get("Room")
dict_len = len(dict_num)
if dict_len == 0:
print("")
print("There is no data in our database")
print("")
menu()
else:
print("")
Room = input("Enter your Room Number: ")
print("")
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
file1 = open("Management.txt", "w", encoding="utf-8")
file1.write(str(dictionary))
file1.close()
print("Details has been removed successfully")
exit_menu()
def view():
File = open("Management.txt", "r")
string = File.read()
string = string.replace("'", '"')
dictionary = json.loads(string)
File.close()
dict_num = dictionary.get("Room")
dict_len = len(dict_num)
if dict_len == 0:
print("")
print("There is no data in our database")
print("")
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()