Пример #1
0
 def add_room_type(self):
     while True:
         room_type = userinput.input_int("Enter the new room type: ")
         if room_type is None:
             return
         if room_type in lister.room_types():
             if userinput.yes_or_no("Room already exists. Try again?"):
                 continue
             else:
                 return
         else:
             break
     values_to_insert = [room_type]
     beds = userinput.input_int("Enter the number of beds: ")
     if beds is None:
         return
     ac = int(userinput.yes_or_no("AC available?"))
     if ac is None:
         return
     rate = userinput.input_int("Enter the rate: ")
     if rate is None:
         return
     values_to_insert += [beds, ac, rate]
     values_to_insert = tuple(values_to_insert)
     with self._cursor() as cursor:
         cursor.execute(
             "insert into `rates` (`room type`, `beds`, `AC`, `rate`)\
                        values (%s, %s, %s, %s);",
             values_to_insert,
         )
Пример #2
0
def main():
    while True:
        _clear_screen()
        print("WELCOME TO", HOTEL_NAME)
        print()
        print("You are:")
        option = choose_option(("Guest", "Manager"))
        if option:
            while True:
                try:
                    password = get_password()
                except (EOFError, KeyboardInterrupt):
                    if yes_or_no("Do you want to logout?"):
                        print()
                        break
                if Check().password(ADMIN_USERNAME, password):
                    user_object = users.Admin(password)
                    _helper(user_object)
                    break
                else:
                    if not yes_or_no("Try again?"):
                        break
        else:
            user_object = users.Guest()
            _helper(user_object)
Пример #3
0
 def delete_room(self):
     room = selecter.room_number("Enter the room number to be deleted: ")
     if room is not None:
         print(f"Room {room} shall be deleted.")
         if userinput.yes_or_no("Are you sure?"):
             with self._cursor() as cursor:
                 cursor.execute(
                     f"DELETE FROM `rooms` WHERE `room number` = '{room}'")
Пример #4
0
 def room_type(self, prompt="Please enter the room type: ") -> Union[int, None]:
     with self._cursor() as cursor:
         cursor.execute("select `room type` from `rates`;")
         room_types = cursor.fetchall()
         room_types = [z for (z,) in room_types]
     while True:
         room_type = input(prompt)
         if not (room_type.isdigit() and int(room_type) in room_types):
             if not userinput.yes_or_no("Invalid room type. Try again?"):
                 return None
         else:
             break
     return int(room_type)
Пример #5
0
 def delete_room_type(self):
     room_type = selecter.room_type("Enter the room type to be deleted: ")
     if room_type is not None:
         if room_type in lister.room_types_being_used():
             print(
                 "Before deleting room type, please remove or modify all rooms associated with it."
             )
             return
         else:
             print(f"Room type {room_type} shall be deleted.")
             if userinput.yes_or_no("Are you sure?"):
                 with self._cursor() as cursor:
                     cursor.execute(
                         f"DELETE FROM `rates` WHERE `room type` = '{room_type}'"
                     )
Пример #6
0
 def modify_room_type(self):
     room_type = selecter.room_type("Enter the room type to change: ")
     if room_type is None:
         return
     for param in ("beds", "AC", "rate"):
         with self._cursor() as cursor:
             cursor.execute(f"select `{param}` from `rates`\
                            where `room type` = '{room_type}'")
             old_value = cursor.fetchall()[0][0]
         if param == "AC":
             print(param, "is", ["not ", ""][bool(old_value)] + "available")
             new_value = None
             if userinput.yes_or_no("Do you want to change it?"):
                 new_value = int(userinput.yes_or_no("AC available now?"))
         else:
             print(param, "is", old_value)
             new_value = None
             if userinput.yes_or_no("Do you want to change it?"):
                 new_value = userinput.input_int("Enter the new value: ")
         if new_value is not None:
             with self._cursor() as cursor:
                 cursor.execute(f"update `rates`\
                                set `{param}` = '{new_value}' \
                                where `room type` = '{room_type}'")
Пример #7
0
def _helper(user_object):
    _clear_screen()
    while True:
        print("Welcome!")
        print()
        print("What would you like to do?")
        try:
            user_object.functions[choose_option(user_object.actions)]()
        except EOFError as E:
            if not isinstance(E, Logout):
                print()
            if yes_or_no("Do you want to logout?"):
                break
            _clear_screen()
        except KeyboardInterrupt:
            print()
            exit(0)
Пример #8
0
 def add_room(self):
     while True:
         room_number = userinput.input_int("Enter the new room number: ")
         if room_number is None:
             return
         if room_number in lister.room_numbers():
             if userinput.yes_or_no("Room already exists. Try again?"):
                 continue
             else:
                 return
         else:
             break
     self.show_room_types()
     room_type = selecter.room_type("Enter the room type: ")
     if room_type is None:
         return
     with self._cursor() as cursor:
         cursor.execute(f"""INSERT INTO `rooms` (`room number`, `room type`)
                        VALUES ('{room_number}','{room_type}');""")