Exemplo n.º 1
0
def list_orders(id):
    valid = True  # Was this command valid/successful?
    packagesOut = pd.execute_command(
        "SELECT packageID, cost FROM package WHERE sender={}".format(id))
    packagesIn = pd.execute_command(
        "SELECT packageID, cost FROM package WHERE receiver={}".format(id))
    if packagesIn or packagesOut == "Invalid SQL":
        valid = False
    return valid, packagesOut, packagesIn
Exemplo n.º 2
0
def track_package(tracking_number):
    valid = True  # Was this command valid/successful?
    locationID = pd.execute_command(
        "SELECT locationID FROM log WHERE trackingnumber={}".format(
            tracking_number))
    location = pd.execute_command(
        "SELECT * FROM location WHERE locationID={}".format(locationID[0][0]))
    if locationID == "Invalid SQL" or location == "Invalid SQL":
        valid = False
    return valid, location[0][1]
Exemplo n.º 3
0
    def submit(self):
        input = self.entry.get()
        self.terminal_write("> " + input)

        if self.id != "":
            if input != "":
                if input == "role" or input == "myrole" or input == "getrole":
                    if self.role == "admin" or self.role == "employee":
                        self.terminal_write("You are an {}.".format(self.role))
                    else:
                        self.terminal_write("You are a {}.".format(self.role))
                elif input == "logout" or input == "log out":
                    self.id = ""
                    self.role = ""
                    self.terminal_write(
                        "You have been successfully logged out.")
                    self.terminal_write(
                        "To log in, please enter your ID, or \"new\" if you are a new user."
                    )
                else:
                    response = db.parse_and_execute(input, self.id, self.role)
                    self.terminal_write(response)
        elif self.new:
            if input == "customer" or input == "employee" or input == "admin":
                self.role = input
                self.id = db.new(self.role)
                self.terminal_write(
                    "Your account has been created. You are logged in with the ID: {}. "
                    "\nUse \"help\" for available commands.".format(self.id))
            else:
                self.terminal_write(
                    "\"{}\" is not a valid role.".format(input))
                self.terminal_write("What is your role?")
        else:
            if input == "new":
                self.new = True
                self.terminal_write(
                    "What is your role? (customer/employee/admin)")
            elif db.login(input):
                self.id = input
                self.role = db.get_role(self.id)
                self.terminal_write(
                    "You have successfully been logged in.\nUse \"help\" for available commands."
                )
            else:
                self.terminal_write("'{}' is not a valid ID.".format(input))
                self.terminal_write(
                    "Please enter your ID, or \"new\" if you are a new user.")
        self.entry.delete(0, 'end')
Exemplo n.º 4
0
def bill_status(packageID):
    valid = True  # Was this command valid/successful?
    total = pd.execute_command(
        "SELECT cost FROM package WHERE packageID={}".format(packageID))
    if total == "Invalid SQL":
        valid = False
    return valid, "Bill total: " + str(total)
Exemplo n.º 5
0
def place_order(
        id, type, weight,
        destination_addr):  # TODO: Address needs to be standardized somehow.
    valid = True  # Was this command valid/successful?
    cost_for_delivery = int(weight) * 51 / 100
    last_id = pd.execute_command("SELECT MAX(id) FROM package")
    receiver_id = pd.execute_command(
        "SELECT id FROM address WHERE state='{}' AND zip={} AND city='{}'".
        format(destination_addr[4], destination_addr[5], destination_addr[3]))
    result = pd.execute_command((
        "INSERT INTO package VALUES ({}, {}, {}, {}, '{}', '{}', '{}', '{}', {}, {})"
        .format(last_id[0][0] + 1, id, receiver_id[0][0], cost_for_delivery,
                type, "medium", "false", "false", weight, 2)))
    if result == "Invalid SQL":
        valid = False
    return valid, cost_for_delivery
def mark_as_delivered(trackingnumber):
    timestamp = time.time()
    date = datetime.datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
    valid = True
    result = pd.execute_command("UPDATE entry SET deliveredtime='{}' WHERE trackingnumber={}".format(date, trackingnumber))
    if result == "Invalid SQL":
        valid = False
    return valid
Exemplo n.º 7
0
def accept_charge(id):
    valid = True  # Was this command valid/successful?
    #  TODO: need query here to get users payment type
    payment_type = pd.execute_command(
        "SELECT payment_type FROM person WHERE id={}".format(id))
    if payment_type == "Invalid SQL":
        valid = False
    if active_c != 0:
        return valid, "Charge of " + str(
            active_c) + " accepted using payment type" + payment_type
    else:
        return valid, "No, active charge."
def execute_admin_command(command):  # execute sql directly
    return pd.execute_command(command)
def mark_in_transit(packageid, locationid):
    valid = True
    result = pd.execute_command("UPDATE log SET locationid={} WHERE trackingnumber={}".format(locationid, packageid))
    if result == "Invalid SQL":
        valid = False
    return valid
def list_packages(limit):
    valid = True
    result = pd.execute_command("SELECT * FROM package LIMIT {}".format(limit))
    if result == "Invalid SQL":
        valid = False
    return valid, result