def view(): print() print("View Options: ") print("2: All data") print("3: Year wise data") print("0: Home") print("1: Management Information") ch = input("Enter your choice: ") while ch not in '0123' or len(ch) != 1: ch = input("Invalid choice! Enter again: ") if ch == '0': return '0' elif ch == '1': return '1' elif ch == '2': actions.format_print(actions.get_columns("Management"), actions.show_all("Management")) elif ch == '3': years = input( "Enter year range(yyyy-yyyy) Leave empty to include all years: ") while years != '' and ( len(years) != 9 or years.count('-') != 1 or not (len(years.split('-')[0]) == len(years.split('-')[1]) == 4) or not years.replace('-', '0').isdigit()): years = input( "Year range you entered is not correct! enter again: ") if years == '': cur.execute( """select Year, sum(CostPrice), sum(SellingPrice), sum(NetGain), sum(NetGain)/sum(CostPrice)*100 from Management group by Year""" ) columns = ("Year", "CostPrice", "SellingPrice", "NetGain", "NetPercent") values = cur.fetchall() else: query = f"""select Year, sum(CostPrice), sum(SellingPrice), sum(NetGain), sum(NetGain)/sum(CostPrice)*100 from Management group by Year having year<= '{years.split('-')[1]}' and year>='{years.split('-')[0]}'""" cur.execute(query) values = cur.fetchall() columns = ("Year", "CostPrice", "SellingPrice", "NetGain", "NetPercent") actions.format_print(columns, values)
def menu(): db = DataBase() escolha = '' while (escolha != '0'): print( 'Digite 1 para cadastrar | 2 para listar usuarios | 3 para alterar o nome do usuario' ) print('4 para encriptar um texto | 5 para decriptar | 0 para terminar') escolha = input() # Cadastra usuario if (escolha == '1'): actions.store(db) # Retorna todos os usuarios if (escolha == '2'): actions.show_all(db) # Altera o nome do usuario if (escolha == '3'): actions.alter_user(db) if escolha == '4': text = input('Digite o texto que deseja encriptar > ') print('Saida > ' + my_encrypt.crypt(text)) if escolha == '5': text = input('Digite o texto encriptado que deseja decriptar > ') print('Saida > ' + my_encrypt.decrypt(text)) # Comando clear do terminal para limpar campo de texto if (escolha == 'clear'): os.system('clear') print('\n') print('Ate logo ...')
def view(): print() print("How many columns do you want to view:") print("2: All columns, All records") print("3: All columns, Some records") print("4: Some columns, All records") print("5: Some columns, Some records") print("6: Expired Medicines") print("0: Go to home") print("1: Go to Stock Information") ch = input() columns_all = actions.get_columns("Stock") col_dict = {i + 1: columns_all[i] for i in range(len(columns_all))} while ch not in '0123456' or len(ch) != 1: ch = input("Invalid choice. Enter again: ") if ch == '0': return '0' elif ch == '1': return '1' elif ch == '2': actions.format_print(columns_all, actions.show_all("Stock")) elif ch == '3': print("The columns are:") print(str(col_dict).lstrip('{').rstrip('}')) column = input( "Which column no. do you want to use for record matching: ").lower( ) while not column.isdigit() or int(column) not in col_dict: column = input( "Column no. you entered is not in option. Please enter again: " ).lower() records = actions.input_rows() actions.format_print( columns_all, actions.search_multiple("Stock", col_dict[int(column)], records)) elif ch == '4': clm = actions.input_cols("Stock") actions.format_print(clm, actions.show_columns("Stock", clm)) elif ch == '5': columns = actions.input_cols("Stock") column = input( "Which column no. do you want to use for record matching").lower() while not column.isdigit() or int(column) not in col_dict: column = input( "Column no. you entered is not in option. Please enter again: " ).lower() records = actions.input_rows() actions.format_print( columns, actions.search_multiple("Stock", col_dict[int(column)], records, columns)) elif ch == '6': cur.execute("select * from Stock where Exp<(select sysdate())") data = cur.fetchall() actions.format_print(actions.get_columns("Stock"), data)
def view(): print() print("How many columns do you want to view:") print("2: All columns, All records") print("3: All columns, Some records") print("4: Some columns, All records") print("5: Some columns, Some records") print("0: Go to home") print("1: Go to Medicine Information") ch = input() columns_all = actions.get_columns("MedicineInfo") col_dict = {i + 1: columns_all[i] for i in range(len(columns_all))} while ch not in '012345' or len(ch) != 1: ch = input("Invalid choice. Enter again: ") if ch == '0': return '0' elif ch == '1': return '1' elif ch == '2': actions.format_print(actions.get_columns("MedicineInfo"), actions.show_all("MedicineInfo")) elif ch == '3': print("All columns are:") print(str(col_dict).lstrip('{').rstrip('}')) column = input( "Which column no. do you want to use for record matching: ").lower( ) while not column.isdigit() or int(column) not in col_dict: column = input( "Column no. you entered is not in option. Please enter again: " ).lower() records = actions.input_rows() column = col_dict[int(column)] if column.lower() == "composition": q = f"select * from MedicineInfo where {column} like '%{records[0]}%' " for i in range(1, len(records)): q += f"or {column} like '%{records[i]}%' " cur.execute(q) actions.format_print(columns_all, cur.fetchall()) else: actions.format_print( columns_all, actions.search_multiple("MedicineInfo", column, records)) elif ch == '4': clm = actions.input_cols("MedicineInfo") actions.format_print(clm, actions.show_columns("MedicineInfo", clm)) elif ch == '5': columns = actions.input_cols("MedicineInfo") column = input( "Which column no. do you want to use for record matching: ").lower( ) while not column.isdigit() or int(column) not in col_dict: column = input( "Column no. you entered is not in option. Please enter again: " ).lower() column = col_dict[int(column)] records = tuple(actions.input_rows()) cols = str(columns).lstrip('[').rstrip(']').replace("'", '') if column.lower() == "composition": q = f"select {cols} from MedicineInfo where {column} like '%{records[0]}%' " for i in range(1, len(records)): q += f"or {column} like '%{records[i]}%' " cur.execute(q) actions.format_print(columns, cur.fetchall()) else: actions.format_print( columns, actions.search_multiple("MedicineInfo", column, records))
def view(): print() print("Viewing Options:") print("2: All data") print("3: One record using Receipt No.") print("4: many records using Receipt No.") print("5: All Receipt Numbers") print("6: Receipt numbers by condition") print("7: All costumers") print("0: Go to home") print("1: Go to Medicine Information") ch = input() while ch not in '01234567' or len(ch) != 1: ch = input("Invalid choice. Enter again: ") num = 0 if ch == '0': return '0' elif ch == '1': return '1' elif ch == '2': values = actions.get_values("Sale", "ReceiptNo") for i in values: print_format(i) if len(values) == 0: print("No records!!") elif ch == '3': num = 1 elif ch == '4': num = input("How many records do tou want to view: ") while not num.isdigit(): num = input("No. of records should be integer only! Enter again: ") elif ch == '5': cur.execute("select ReceiptNo from Sale") actions.format_print([ "ReceiptNo", ], cur.fetchall()) elif ch == '6': print("All columns are") print(actions.get_columns("Sale")) condition = input( 'Enter condition(<column_name><operator>"<value>"): ') while True: try: cur.execute(f"select 1+2 from Sale where {condition}") cur.fetchall() break except Exception as e: print(e) condition = input( 'Your condition had above error! Enter again(<column_name><operator>"<value>"): ' ) try: cur.execute(f"select ReceiptNo from Sale where {condition}") actions.format_print(["ReceiptNo"], cur.fetchall()) except Exception as e: print("Your condition had an error!!") print(e) traceback.print_exc() elif ch == '7': actions.format_print(actions.get_columns("Sale"), actions.show_all("Sale")) records = [] receipts = actions.get_values("Sale", "ReceiptNo") for i in range(int(num)): rec = input(f"Enter record{i + 1} Receipt No.: ") while rec not in receipts or not rec.isdigit(): if not rec.isdigit(): rec = input("Receipt No. should be an integer! Enter again: ") else: rec = input(f"Receipt No.: {rec} is not there! Enter again: ") records.append(rec) for i in records: print_format(i)