Example #1
0
def deleteData(option):
    # games
    if option == '1':
        gameID = gameIDValidation('delete')

        # delete object only needs a proper ID to find and delete the records from the table
        deleteGameObj = Game(gameID, '', 1)

        # if the record has been successfully deleted, delete from the list as well
        if data.gameManipulate(deleteGameObj, 3):
            for game in globalData['games']:
                if game['gameID'] == gameID:
                    globalData['games'].remove(game)

    # merchandise
    elif option == '2':
        mercID = mercIDValidation('delete')

        # delete object only needs a proper ID to find and delete the records from the table
        deleteMercObj = Merchandise(mercID, '', 1)

        # if the record has been successfully deleted, delete from the list as well
        if data.merchandiseManipulate(deleteMercObj, 3):
            for item in globalData['merchandise']:
                if item['mercID'] == mercID:
                    globalData['merchandise'].remove(item)

    # sales
    elif option == '3':
        gameID, mercID, exist = salesDataValidation()

        # only perform deletion when the record with the same gameID and mercID exists
        if exist:
            # delete object only needs a proper ID to find and delete the records from the table
            deleteSalesObj = Sales(gameID, mercID, 0)

            # if the record has been successfully deleted, delete from the list as well
            if data.salesManipulate(deleteSalesObj, 3):
                for sale in globalData['sales']:
                    if sale['gameID'] == gameID and sale['mercID'] == mercID:
                        globalData['sales'].remove(sale)
        else:
            message(
                'Sales record with the same GameID and MerchandiseID does not exist!'
            )

    # venues
    elif option == '4':
        venueID = venueIDValidation('delete')

        # delete object only needs a proper ID to find and delete the records from the table
        deleteVenueObj = Venue(venueID, '')

        # if the record has been successfully deleted, delete from the list as well
        if data.venuesManipulate(deleteVenueObj, 3):
            for venue in globalData['venues']:
                if venue['venueID'] == venueID:
                    globalData['venues'].remove(venue)
Example #2
0
def salesDataValidation():
    # GameID validation/confirmation
    while True:
        try:
            gameID = int(input('Enter a gameID: '))
            gameDate = data.getDates(gameID)
            if gameDate is None:
                message("There are no data with that GameID")
            else:
                confirm = False
                while confirm == False:
                    yn = input(
                        'ID:{} is for the game on {}. Is this correct?(Y/N) '.
                        format(gameID, gameDate)).upper()
                    confirm = ui.confirm(yn)
                if yn == 'Y':
                    yn = ''
                    break
        except ValueError:
            message('Enter a valid merchandiseID')

    # mercID validation/confirmation
    while True:
        try:
            mercID = int(input('Enter a merchandiseID: '))
            mercName, mercPrice = data.getMercInfo(mercID)
            if (mercName or mercPrice) is None:
                message("There are no data with that merchandiseID")
            else:
                confirm = False
                while confirm == False:
                    yn = input(
                        'ID:{} is for the {} that costs ${}. Is this correct?(Y/N) '
                        .format(mercID, mercName, mercPrice)).upper()
                    confirm = ui.confirm(yn)
                if yn == 'Y':
                    break
        except ValueError:
            message('Enter a valid merchandiseID')

    # create a temporary sales object to check if the sales record with the same gameID and mercID already exist
    tempSalesObj = Sales(gameID, mercID, 0)

    exist = data.checkSalesExist(tempSalesObj)

    return gameID, mercID, exist
Example #3
0
def insertData(option):
    # games
    if option == '1':
        date, venueID, exist = gameDataValidation()
        # if there are no games data with the same date, create a new game object
        if not exist:
            # newGameID is the max gameID + 1
            newGameID = max([x['gameID'] for x in globalData['games']]) + 1
            newGameObj = Game(newGameID, date, venueID)

            # if added to the database successfully, append to the globalData as well
            if data.gameManipulate(newGameObj, 1):
                globalData['games'].append({
                    'gameID': newGameID,
                    'dates': date,
                    'venueID': venueID
                })
                globalData['games'] = sorted(globalData['games'],
                                             key=itemgetter('gameID'))

    # merchandise
    elif option == '2':
        mercName, price, exist = mercDataValidation()
        # if there are no merchandise data with the same name, create a new merchandise object
        if not exist:
            # newMercID is the max mercID + 1
            newMercID = max([x['mercID']
                             for x in globalData['merchandise']]) + 1
            newMercObj = Merchandise(newMercID, mercName, price)

            # if added to the database successfully, append to the globalData as well
            if data.merchandiseManipulate(newMercObj, 1):
                globalData['merchandise'].append({
                    'mercID': newMercID,
                    'name': mercName,
                    'price': price
                })
                globalData['merchandise'] = sorted(globalData['merchandise'],
                                                   key=itemgetter('mercID'))

    # sales
    elif option == '3':
        newGameID, newMercID, exist = salesDataValidation()
        # if it doesn't exist, continue on to gather information about the number of item sold. Otherwise, back to the main menu
        if not exist:
            mercName, price = data.getMercInfo(newMercID)
            sold = soldValidation(mercName)
            # create a new Sales object
            newSalesObj = Sales(newGameID, newMercID, sold)

            # if added to the database successfully, append to the globalData as well
            if data.salesManipulate(newSalesObj, 1):
                globalData['sales'].append({
                    'gameID': newGameID,
                    'mercID': newMercID,
                    'sold': sold
                })
                globalData['sales'] = sorted(globalData['sales'],
                                             key=itemgetter('gameID'))
        else:
            message(
                'Sale record with the same GameID and MerchandiseID already exist!'
            )

    # venues
    elif option == '4':
        venueName, exist = venuesDataValidation()
        # create new Venues object if the record with the same venue name does not exist
        if not exist:
            # newVenueID is the max VenueID + 1
            newVenueID = max([x['venueID'] for x in globalData['venues']]) + 1
            newVenueObj = Venue(newVenueID, venueName)

            # if added to the database successfully, append to the globalData as well
            if data.venuesManipulate(newVenueObj, 1):
                globalData['venues'].append({
                    'venueID': newVenueID,
                    'name': venueName
                })
                globalData['venues'] = sorted(globalData['venues'],
                                              key=itemgetter('venueID'))
Example #4
0
def updateData(option):
    # games
    if option == '1':
        gameID = gameIDValidation('update')
        newDate, newVenueID, exist = gameDataValidation()
        # create a game object if the record with the same date does not exist
        if not exist:
            updateGamesObj = Game(gameID, newDate, newVenueID)

            # if updated database successfully, modify the globalData with the new values as well
            if data.gameManipulate(updateGamesObj, 2):
                for game in globalData['games']:
                    if game['gameID'] == gameID:
                        game['dates'] = newDate
                        game['venueID'] = newVenueID

    # merchandise
    elif option == '2':
        mercID = mercIDValidation('update')
        newMercName, newPrice, exist = mercDataValidation()
        # create a merchandise object if the record with the same name does not exist
        if not exist:
            updateMercObj = Merchandise(mercID, newMercName, newPrice)

            # if updated database successfully, modify the globalData with the new values as well
            if data.merchandiseManipulate(updateMercObj, 2):
                for item in globalData['merchandise']:
                    if item['mercID'] == mercID:
                        item['name'] = newMercName
                        item['price'] = newPrice

    # sales
    elif option == '3':
        gameID, mercID, exist = salesDataValidation()
        # continue updating if the data with the same gameID and mercID combination
        if exist:
            mercName, price = data.getMercInfo(newMercID)
            sold = soldValidation(mercName)

            updateSalesObj = Sales(gameID, mercID, sold)

            # if updated database successfully, modify the globalData with the new values as well
            if data.salesManipulate(updateSalesObj, 2):
                for sale in globalData['sales']:
                    if sale['gameID'] == gameID and sale['mercID'] == mercID:
                        sale['sold'] = sold
        else:
            message(
                'Sales record with the same GameID and MerchandiseID does not exist!'
            )

    # venues
    elif option == '4':
        venueID = venueIDValidation('update')
        newVenueName, exist = venuesDataValidation()
        if not exist:
            updateVenueObj = Venue(venueID, newVenueName)

            # if updated database successfully, modify the globalData with the new values as well
            if data.venuesManipulate(updateVenueObj, 2):
                for venue in globalData['venues']:
                    if venue['venueID'] == venueID:
                        venue['name'] = newVenueName