def viewCostControl(listOfApartments): ''' Function that controls the view part of the aplication :param listOfApartments: :return: None ''' print("\n") subCommand = readInt("Selectati comanda dorita: ") print("\n" * 2) if subCommand == 1: type = readStr("Dati tipul de cheltuiala: ") totalSum = totalSumForCost(listOfApartments, type) print("Suma totala pentru ", convertFromEnToRo(totalSum[0]), " este ", totalSum[1]) print("\n" * 2) print("\n" * 2) elif subCommand == 2: type = readStr("Dati tipul de cheltuiala dupa care se vrea a fi sortata lista: ") printSortedAfterType(listOfApartments, type) elif subCommand == 3: try: index = readInt("Dati numarul apartamentului pentru tiparirea costului: ") print("Costul total pentru apartamentul ", index, " este ", getTotalCost(listOfApartments, index - 1)) except IndexError: print("Indxul este prea mare sau prea mic!!")
def menuBasedUI(): ''' control the menuBased UI :return: ''' listOfApartments = initApartments() backUpList = {} while True: printMenu() command = readInt("Selectati comanda dorita: ") if command == 1: printAddSubmenu() domain.apartment.addCostControl(listOfApartments, backUpList) elif command == 2: printDeleteSubmenu() domain.apartment.deleteCostControl(listOfApartments, backUpList) elif command == 3: printSearchSubmenu() domain.apartment.searchingCostControl(listOfApartments) elif command == 4: printViewSubmenu() domain.apartment.viewCostControl(listOfApartments) elif command == 5: printFilterSubmenu() domain.apartment.filterCostControl(listOfApartments) elif command == 6: listOfApartments = domain.apartment.undo(listOfApartments, backUpList) elif command == 7: exit()
def filterCostControl(listOfApartments): ''' Function that controls the filter feature of the application :param listOfApartments: :return: none ''' print('\n') subCommand = readInt("Selectati comanda dorita: ") print("\n" * 2) if subCommand == 1: type = readStr("Dati tipul dorit: ") filterAp(listOfApartments, type) elif subCommand == 2: sum = readInt("Dati suma dorita: ") filterApSum(listOfApartments, sum)
def addCostControl(listOfApartments, backUpList): ''' Function that controls the subcommand1 (adding a new cost to an apartment) Takes no arguments Doesn't return anything ''' makeBackUp(listOfApartments, backUpList) print("\n") subCommand = readInt("Selectati comanda dorita: ") print("\n" * 2) if subCommand == 1: try: index = readInt("Dati numarul apartamentului: ") sumCost = readInt("Dati suma cheltuielii: ") type = readStr("Specificati tipul cheltuielii: ") day = readInt("Dati ziua in care se adauga cheltuiala: ") addToCost(listOfApartments, index - 1, sumCost, type, day) clearScreen() except IndexError: print("\nIndexul este prea mare sau negativ !!\n") elif subCommand == 2: try: index = readInt("Dati numarul apartamentului ") sumCost = readInt("Dati suma cheltuielii: ") type = readStr("Specificati tipul cheltuielii: ") day = readInt("Dati ziua in care se modifica cheltuiala: ") modifyApartmentCost(listOfApartments, index - 1, sumCost, type, day) clearScreen() except IndexError: print("\nIndexul este prea mare sau negativ!!\n")
def searchingCostControl(listOfApartments): ''' Function that controls the searching part of the aplication Takes the list of costs as parameter Doesn't return anything ''' print("\n") subCommand = readInt("Selectati comanda dorita :") print("\n" * 2) if subCommand == 1: sum = readInt("Dati suma de comparare: ") print("\n" * 2) printCostLargerThanSum(costsLargerThanSum(listOfApartments, sum), sum) print("\n" * 2) elif subCommand == 2: type = readStr("Dati tipul de cheltuiala ce se vrea afisat de la toate apartamentele: ") printCostTypeFromAll(costTypeFromAll(listOfApartments, type), type) elif subCommand == 3: day = readInt("Dati ziua: ") sum = readInt("Dati suma de comparare: ") costBeforDay(listOfApartments, day, sum)
def deleteCostControl(listOfApartments, backUpList): ''' Function that controls the subcommand2 (deleting cost of an apartment) Takes no arguments Doesn't return anything ''' makeBackUp(listOfApartments, backUpList) print("\n" * 2) subCommand = readInt("Selectati comanda dorita :") print("\n" * 2) if subCommand == 1: try: index = readInt("Dati numarul apartamentului: ") day = readInt("Dati ziua in care se face stergerea: ") deleteApartmentCost(listOfApartments, index - 1, day) clearScreen() except IndexError: print("Indexul este prea mare sau prea mic!!") elif subCommand == 2: try: startIndex = readInt("Dati primul apartamentul de la care se incepe stergerea: ") endIndex = readInt("Dati ultimul apartament la care se face stergere") if startIndex > endIndex: startIndex, endIndex = endIndex, startIndex deleteFromAtoB(listOfApartments, startIndex - 1, endIndex) clearScreen() except IndexError: print("Indecsii sunt prea mari sau prea mici!!") elif subCommand == 3: type = readStr("Dati tipul de cheltuiala care se vrea a fi stearsa: ") date = readInt("Dati ziua in care se face stergerea: ") deleteCostFromAll(listOfApartments, type, date) clearScreen()
def startUI(): ''' Function that starts the user interface menu Takes no argument Doesn't return anything ''' while True: try: specfiyMenu = readInt( "Apasati 1 pentru Menu Based UI sau 2 pentru Command Based UI: " ) if specfiyMenu == 1: menuBasedUI() elif specfiyMenu == 2: commandBasedUI() else: raise TypeError("NUMARUL INTRODUS POATE FI DOAR 1 SAU 2") except TypeError as msg: print(msg)
def initApartments(): numofApartments = readInt("Dati numarul de apartamente: ") listOfApartments = createNewList(numofApartments) return listOfApartments