Пример #1
0
    def issue_ticket(self):
        print()
        print("Issuing a ticket.")
        registration_number = input_util.read_int(
            "Please enter registration number: ")

        self.cursor.execute(
            """
            SELECT r.fname, r.lname, v.make, v.model, v.year, v.color
            FROM registrations r, vehicles v
            WHERE r.regno = ? AND r.vin = v.vin;
        """, (registration_number, ))
        row = self.cursor.fetchone()

        if row is None:
            print("Record not found.")
            return
        print("|".join(str(elem) for elem in row))

        violation_date = input_util.read_date("Please enter violation date: ",
                                              optional=True)
        violation_text = input("Please enter violation text: ")
        fine_amount = input_util.read_int("Please enter fine amount: ")

        self.cursor.execute(
            """
            INSERT INTO tickets 
            VALUES ((SELECT max(tno) + 1 FROM tickets), ?, ?, ?, IFNULL(?, DATE('now')));
        """,
            (registration_number, fine_amount, violation_text, violation_date))
        self.connection.commit()

        print("Ticket Issued.")
Пример #2
0
    def __add_person(
        self,
        fname: str = None,
        lname: str = None,
        bdate: str = None,
        bplace: str = None,
        address: str = None,
        phone: str = None,
    ):
        text = "Enter the person's"
        if fname is None:
            fname = input_util.read_string(f"{text} first name: ")
        if lname is None:
            lname = input_util.read_string(f"{text} last name: ")
        if bdate is None:
            bdate = input_util.read_date(f"{text} birth date: ", optional=True)
        if bplace is None:
            bplace = input_util.read_string(f"{text} birth place: ",
                                            optional=True)
        if address is None:
            address = input_util.read_string(f"{text} address: ",
                                             optional=True)
        if phone is None:
            phone = input_util.read_string(f"{text} phone number: ",
                                           optional=True)

        self.cursor.execute(
            """
            INSERT INTO persons
            VALUES(?, ?, ?, ?, ?, ?);
        """, (fname, lname, bdate, bplace, address, phone))
Пример #3
0
    def __add_person(
        self,
        fname: str = "",
        lname: str = "",
        bdate: str = "",
        bplace: str = "",
        address: str = "",
        phone: str = "",
    ):
        text = "Enter the person's"
        if fname == "":
            fname = input_util.read_name(text + " first name: ")
        if lname == "":
            lname = input_util.read_name(text + " last name: ")
        if bdate == "":
            bdate = input_util.read_date(text + " birth date: ", optional=True)
        if bplace == "":
            bplace = input_util.read_string(text + " birth place: ",
                                            optional=True)
        if address == "":
            address = input_util.read_string(text + " address: ",
                                             optional=True)

        phone_regex = re.compile(r"\d{3}-\d{3}-\d{4}$")
        if phone == "":
            phone = None
            while phone is None:
                phone = input_util.read_string(
                    text + " phone number (XXX-XXX-XXXX): ", optional=True)
                if phone is None:  # optional
                    break
                if not phone_regex.match(phone):
                    phone = None
                    print(
                        "Phone number entered in wrong format, please try again, or leave blank"
                    )

        self.cursor.execute(
            """
            INSERT INTO persons
            VALUES(?, ?, ?, ?, ?, ?);
        """,
            (fname, lname, bdate, bplace, address, phone),
        )
Пример #4
0
    def register_birth(self, username):
        print()
        print("Registering a birth")

        first_name = input_util.read_name("Please enter baby's first name: ")
        last_name = input_util.read_name("Please enter baby's last name: ")

        self.cursor.execute(
            """
            SELECT *
            FROM births b, persons p
            WHERE (b.fname LIKE ? AND b.lname LIKE ?) OR
                  (p.fname LIKE ? AND p.lname LIKE ?);
        """,
            (first_name, last_name, first_name, last_name),
        )

        if self.cursor.fetchone() is not None:
            print(
                "\nPerson with same name already exists. Cancelling registration..."
            )
            return

        gender = None
        while True:
            gender = input_util.read_string(
                "Please enter baby's gender (M/F): ")
            if (gender.casefold() == "m".casefold()
                    or gender.casefold() == "f".casefold()):
                break
            print("Gender must either be m or f, please try again")

        while True:
            birth_date = input_util.read_date(
                "Please enter baby's birth date: ")
            bday_date = datetime.strptime(birth_date, "%Y-%m-%d").date()
            if bday_date > date.today():
                print("Baby can't be born in the future.")
            else:
                break

        birth_place = input_util.read_string(
            "Please enter baby's birth place: ")
        mother_fname = input_util.read_name(
            "Please enter mother's first name: ")
        mother_lname = input_util.read_name(
            "Please enter mother's last name: ")
        father_fname = input_util.read_name(
            "Please enter father's first name: ")
        father_lname = input_util.read_name(
            "Please enter father's last name: ")
        registration_date = date.today().strftime("%Y-%m-%d")

        if (first_name.lower() == mother_fname.lower()
                and last_name.lower() == mother_lname.lower()) or (
                    first_name.lower() == father_fname.lower()
                    and last_name.lower() == father_lname.lower()):
            print("A person cannot give birth to him or herself.")
            return
        elif (mother_fname.lower() == father_fname.lower()
              and mother_lname.lower() == father_lname.lower()):
            print("A person cannot have the same mother and father.")
            return

        self.cursor.execute(
            """
            SELECT city
            FROM users
            WHERE uid LIKE ?;
        """,
            (username, ),
        )
        (city, ) = self.cursor.fetchone()

        mother = self.__get_person(mother_fname, mother_lname)
        if mother is None:
            print(
                "Mother does not exist in database, please enter her details.")
            self.__add_person(fname=mother_fname, lname=mother_lname)
            mother = self.__get_person(mother_fname, mother_lname)

        father = self.__get_person(father_fname, father_lname)
        if father is None:
            print(
                "Father does not exist in database, please enter his details.")
            self.__add_person(fname=father_fname, lname=father_lname)
            father = self.__get_person(father_fname, father_lname)

        address = mother[4]
        phone = mother[5]

        self.__add_person(first_name, last_name, birth_date, birth_place,
                          address, phone)

        self.cursor.execute(
            """
            INSERT INTO births
            VALUES((SELECT MAX(regno) + 1 FROM births), ?, ?, ?, ?, ?, ?, ?, ?, ?);
        """,
            (
                first_name,
                last_name,
                registration_date,
                city,
                gender,
                father[0],
                father[1],
                mother[0],
                mother[1],
            ),
        )
        self.connection.commit()

        print("Birth registered.")
Пример #5
0
    def register_birth(self, username):
        print()
        print("Registering a birth")

        first_name = input_util.read_string("Please enter baby's first name: ")
        last_name = input_util.read_string("Please enter baby's last name: ")
        gender = input_util.read_string(
            "Please enter baby's gender (M/F): ")  # TODO: Validation
        birth_date = input_util.read_date("Please enter baby's birth date: ")
        birth_place = input_util.read_string(
            "Please enter baby's birth place: ")
        mother_fname = input_util.read_string(
            "Please enter mother's first name: ")
        mother_lname = input_util.read_string(
            "Please enter mother's last name: ")
        father_fname = input_util.read_string(
            "Please enter father's first name: ")
        father_lname = input_util.read_string(
            "Please enter father's last name: ")
        registration_date = date.today().strftime("%Y-%m-%d")

        self.cursor.execute(
            """
            SELECT city
            FROM users
            WHERE uid LIKE ?;
        """, (username, ))
        (city, ) = self.cursor.fetchone()

        mother = self.__get_person(mother_fname, mother_lname)
        if mother is None:
            print(
                "Mother does not exist in database, please enter her details.")
            self.__add_person(fname=mother_fname, lname=mother_lname)
            mother = self.__get_person(mother_fname, mother_lname)

        father = self.__get_person(father_fname, father_lname)
        if father is None:
            print(
                "Father does not exist in database, please enter his details.")
            self.__add_person(fname=father_fname, lname=father_lname)
            father = self.__get_person(father_fname, father_lname)

        address = mother[4]
        phone = mother[5]
        if address is None:
            address = "NULL"
        if phone is None:
            phone = "NULL"

        self.__add_person(first_name, last_name, birth_date, birth_place,
                          address, phone)

        self.cursor.execute(
            """
            INSERT INTO births
            VALUES((SELECT MAX(regno) + 1 FROM births), ?, ?, ?, ?, ?, ?, ?, ?, ?);
        """, (first_name, last_name, registration_date, city, gender,
              father[0], father[1], mother[0], mother[1]))
        self.connection.commit()

        print("Birth registered.")