def read_db_for_sales(): '''Read show_db SQLite database and populate sales list''' try: db = sqlite3.connect('data/show_db.db') cur = db.cursor() cur.execute("PRAGMA foreign_keys=ON") # Fetch some data, using the cursor. This returns another cursor object # that can be iterated over for row in cur.execute('select * from sales'): #ui.message(row) update_ind = g.BLANK sales = Sales(row[1], row[2], row[3], row[4], update_ind) sales.set_id(row[0]) g.sales_list.append(sales) # ui.message('************* Sales **************') # ui.message(g.sales_list) # ui.message('') except sqlite3.Error as e: # As we are reading, no changes to roll back print('Error reading from database', e) logging.error('Database error {}'.format(e)) traceback.print_exc() finally: db.close()
def modify_sales_record(sale_index, sale_id): print('Your record to modify is:') print(g.sales_list[sale_index]) while True: clear() while True: try: saleitemid = int(input('Enter the item ID of the sale item (an integer from above list): ')) if saleitemid < 0: message('Enter a positive number') else: break except ValueError: message('Enter a whole number') while True: try: salequantity = int(input('Enter the quantity of sales items sold: ')) if salequantity < 0: message('Enter a positive number') else: break except ValueError: message('Enter a whole number') while True: try: saletotal = float(input('Enter the total sale dollar amount: ')) if saletotal < 0: message('Enter a positive amount') else: break except ValueError: message('Enter a positive amount') while True: try: showid = int(input('Enter the Show ID (an integer from the above list): ')) if showid < 0: message('Enter a positive number') else: break except ValueError: message('Enter a whole number') message('You entered {} {} {} {} '.format(saleitemid, salequantity, saletotal, showid)) check = input('Is this correct? "y" or "n": ') if check.lower() == 'y': break update_ind = g.MODIFY sale = Sales(saleitemid, salequantity, saletotal, showid, update_ind) # generate a new replacement object sale.set_id(sale_id) g.sales_list.insert(sale_index, sale) # insert the object back into the list where it came from