Пример #1
0
def roundBooking(email, CONN_STRING, flightno, rs, dep_date, ret_date, source, dest):
    row = rs[flightno-1]
    if row[-2] <= 0:
        print("tickets not exists, please choose another flight")
        printInfo(email, CONN_STRING, source, dest, dep_date, "1")
    try:
        sql = "select max(tno) from tickets"
        maxTno = main.sqlWithReturn(sql, CONN_STRING)[0][0]
        sql = "select name from passengers where email = '{0}'".format(email)
        name = main.sqlWithReturn(sql, CONN_STRING)[0][0]
        sql = "insert into tickets values({0}, '{1}', '{2}', '{3}')".format(maxTno+1, name, email, row[-1])
        main.sqlWithNoReturn(sql, CONN_STRING)
        sql = "insert into bookings values({0}, '{1}', '{2}', to_date('{3}', 'DD/MM/YYYY'), null)".format(maxTno+1, row[0], row[8], dep_date)
        main.sqlWithNoReturn(sql, CONN_STRING)
        sql = "insert into bookings values({0}, '{1}', '{2}', to_date('{3}', 'DD/MM/YYYY'), null)".format(maxTno+1, row[10], row[-5], ret_date)
        main.sqlWithNoReturn(sql, CONN_STRING)
        if row[1] is not None:
            sql = "insert into bookings values({0}, '{1}', '{2}', to_date('{3}', 'DD/MM/YYYY'), null)".format(maxTno+1, row[1], row[9], dep_date)
            main.sqlWithNoReturn(sql, CONN_STRING)
        if row[11] is not None:
            sql = "insert into bookings values({0}, '{1}', '{2}', to_date('{3}', 'DD/MM/YYYY'), null)".format(maxTno+1, row[11], row[-4], ret_date)
            main.sqlWithNoReturn(sql, CONN_STRING)
        print("success")
    except:
        print("There was an error during booking. Please try again")
        main.menu(email, CONN_STRING)
    printRoundInfo(email, CONN_STRING, source, dest, dep_date, ret_date)
Пример #2
0
def booking(email, CONN_STRING, flightno, rs, dep_date, source, dest):

    # if user is not a passenger prompt user to enter information 
    # and add it to passenger table
    sql = "select * from passengers where email = '{0}'".format(email)
    isPassenger = main.sqlWithReturn(sql, CONN_STRING)
    if len(isPassenger) == 0:
        print("You are currently not a passenger. Please enter the information below.")
        name = input("Name: ")
        country = input("Country: ")
        sql = "insert into passengers values('{0}', '{1}', '{2}')".format(email, name, country)
        main.sqlWithNoReturn(sql, CONN_STRING)
    row = rs[flightno-1]

    # get ticket number to be created
    sql = "select max(tno) from tickets"
    maxTno = main.sqlWithReturn(sql, CONN_STRING)[0][0]
    # get name of the passenger
    sql = "select name from passengers where email = '{0}'".format(email)
    name = main.sqlWithReturn(sql, CONN_STRING)[0][0]
    # create a ticket for this purchase
    sql = "insert into tickets values({0}, '{1}', '{2}', '{3}')".format(maxTno+1, name, email, row[-4])
    main.sqlWithNoReturn(sql, CONN_STRING)
    # record the flight booking information
    sql = "insert into bookings values({0}, '{1}', '{2}', to_date('{3}', 'DD/MM/YYYY'), null)".format(maxTno+1, row[0], row[-3], dep_date)
    main.sqlWithNoReturn(sql, CONN_STRING)
    # record the second flight booking information if there is one
    if row[1] is not None:
        sql = "insert into bookings values({0}, '{1}', '{2}', to_date('{3}', 'DD/MM/YYYY'), null)".format(maxTno+1, row[1], row[-2], dep_date)
        main.sqlWithNoReturn(sql, CONN_STRING)
    # print success message and ticket number and go back
    print("success, your ticket number is ", maxTno+1)
    return printInfo(email, CONN_STRING, source, dest, dep_date, "1")
Пример #3
0
def recordDepart(email, CONN_STRING):
    # get user input
    flightno = input("Please enter the flight number: ")
    
    # check if the user entered a value
    if len(flightno) == 0:
        print("Flight number cannot be blank")
        return main.menu(email, CONN_STRING)
        
    # get more user input
    dep_date = input("Please enter the departure date(DD/MM/YYYY): ")

    if len(dep_date) == 0:
        print("Departure date must have a value.")
        return main.menu(email, CONN_STRING)

    # check if the user's input flight exists
    sql ="""
    select * from sch_flights 
    where flightno = '{0}' 
    and to_char(dep_date, 'DD/MM/YYYY') = '{1}'
    """.format(flightno, dep_date)
    try:
        output = main.sqlWithReturn(sql, CONN_STRING)
    except:
        print("Improper input. Please try again")
        return main.menu(email, CONN_STRING)
    if len(output) == 0:
        print("There is no flight with that flight number and departure date")
        return main.menu(email, CONN_STRING)

    # get the value of the date and time of the actual departure time
    act_dep_time = input("Please enter the actual departure time(DD/MM/YYYY HH24:MI): ")
    
    # create command to update act_dep_time in sch_flights table
    sql = "update sch_flights set act_dep_time = to_date('{0}', 'DD/MM/YYYY HH24:MI') where flightno = '{1}' and to_char(dep_date, 'DD/MM/YYYY') = '{2}'".format(act_dep_time, flightno, dep_date)

    # see if the command works
    try:
        main.sqlWithNoReturn(sql, CONN_STRING)
    except:
        # if it does not, tell the user and return to the menu
        print("failed to record")
        return main.menu(email, CONN_STRING)

    # if it does, tell the user and return to the menu
    print("successfully recorded")
    return main.menu(email, CONN_STRING)
Пример #4
0
def recordArr(email, CONN_STRING):
    # get the user's desired flightno
    flightno = input("Please enter the flight number: ")
    
    # check if the user actually entered anything
    if len(flightno) == 0:
        print("Flight number cannot be blank")
        main.menu(email, CONN_STRING)
        
    # get the user's flight's desired departure date
    dep_date = input("Please enter the departure date(DD/MM/YYYY): ")
    
    # check if the user actually entered anything
    if len(dep_date) == 0:
        print("Departure date must have a value.")
        main.menu(email, CONN_STRING)
           
    # check if the user's input flight exists
    sql ="""
    select * from sch_flights 
    where flightno = '{0}' 
    and to_char(dep_date, 'DD/MM/YYYY') = '{1}'
    """.format(flightno, dep_date)
    try:
        output = main.sqlWithReturn(sql, CONN_STRING)
    except:
        print("Improper input. Please try again")
        main.menu(email, CONN_STRING)
    if len(output) == 0:
        print("There is no flight with that flight number and departure date")
        main.menu(email, CONN_STRING)
        
    # get the departure date and time from the user
    act_arr_time = input("Please enter the actual arrival time(DD/MM/YYYY HH24:MI): ")
    
    # sql command that sets the actual arrival time of the flight
    sql = "update sch_flights set act_arr_time = to_date('{0}', 'DD/MM/YYYY HH24:MI') where flightno = '{1}' and to_char(dep_date, 'DD/MM/YYYY') = '{2}'".format(act_arr_time, flightno, dep_date)

    # see if the command can successfully execute
    try:
        main.sqlWithNoReturn(sql, CONN_STRING)
    except:
        # if it can't, tell the user and go to the menu
        print("failed to record")
        main.menu(email, CONN_STRING)
    # if it can, tell the user and go to the menu
    print("successfully recorded")
    main.menu(email, CONN_STRING)