def register_user(defaults=None): layout = [[ sg.T("Nome", size=(6, 0)), sg.Input(default_text=defaults[0] if defaults else '', size=(10, 0)) ], [ sg.T("Idade", size=(6, 0)), sg.Input(default_text=defaults[1] if defaults else '', size=(10, 0)) ], [ sg.T("Telefone", size=(6, 0)), sg.Input(default_text=defaults[2] if defaults else '', size=(10, 0)) ], [sg.Submit("Enviar", key=1), sg.B("Voltar", key=2)]] window = sg.Window('Registrar', layout) answer = window.read(close=True)[1] nome = answer[0] idade = answer[1] telefone = answer[2] if not idade.isnumeric(): GeneralView.message("Idade inválida") return return nome, idade, telefone
def cadastrar(self): try: data = UserView.register_user() if data is None: return nome, idade, telefone = data id = len(self.__usuarios) user = User(id, nome, idade, telefone) self.__usuarios.append(user) table, dict = user.toDict() insert(table, dict) except: GeneralView.message('Não foi possível cadastrar o usuário, tente novamente!')
def iniciar(self): opts = [ self.carController, self.userController, self.aluguelController ] optsString = ['Carros', 'Usuários', 'Aluguéis'] while True: opt = GeneralView.menu(optsString, voltar='Sair') if opt is None or opt >= len(opts): GeneralView.message('Adeus') break else: opts[opt]()
def verCarros(self): try: data = CarView.show_cars(self.__carros) except: GeneralView.message('Não foi possível ver os carros') return if data is None: return try: botao, index, carro = data if botao == 'Editar': self.editarCarro(index, carro) elif botao == 'Deletar': self.deletarCarro(index) except: GeneralView.message(f'Não foi possível realizar a sua ação')
def verUsuarios(self): try: data = UserView.show_users(self.__usuarios) except Exception as e: print(e) GeneralView.message('Não foi possível ver os usuários') return if data is None: return try: botao, index, usuario = data if botao == 'Editar': self.editarUsuario(index, usuario) elif botao == 'Deletar': self.deletarUsuario(index) except Exception as e: print(e) GeneralView.message('Não foi possível realizar a sua ação')
def iniciar(self): opts = [self.cadastrar, self.verCarros] optsString = ['Cadastrar carro', 'Ver carros'] while True: opt = GeneralView.menu(optsString) if opt is None or opt >= len(opts): break else: opts[opt]()
def iniciar(self): opts = [self.alugarCarro, self.verAlugueis] optsString = ['Alugar carro', 'Ver alguéis'] while True: opt = GeneralView.menu(optsString) if opt is None or opt >= len(opts): break else: opts[opt]()
def editarCarro(self, index, car): data = CarView.register_car(defaults=[car.modelo, car.ano, car.placa]) if not data: return type, model, age, license_plate = data if license_plate != car.placa and license_plate in list( map(lambda carro: carro.placa, self.__carros)): GeneralView.message('Carro com placa já cadastrada') else: if type == 'Luxo': car = Luxury_car(model, age, license_plate) elif type == 'Popular': car = Popular_car(model, age, license_plate) elif type == 'SUV': car = Suv_car(model, age, license_plate) else: GeneralView.message('Tipo do carro desconhecido') return self.__carros[index] = car
def getUser(listaUsuarios): if len(listaUsuarios) == 0: GeneralView.message('Não tem carros para mostrar') else: layout = [[ sg.Radio( f"ID: {user.id}, Nome: {user.nome}, Idade: {user.idade}, Telefone: {user.telefone}", 'users') ] for index, user in enumerate(listaUsuarios) ] + [[sg.B('Cancelar')], [sg.Submit("Enviar")]] window = sg.Window("Escolha o Cliente", layout) data = window.read(close=True) botao = data[0] if not data: return try: index = [key for key, value in data[1].items() if value][0] except IndexError: return usuarios = listaUsuarios[index] return botao, usuarios
def getCarro(listaCarros): if len(listaCarros) == 0: GeneralView.message('Não tem usuários para mostrar') else: layout = [[ sg.Radio( f"Tipo: {listaCarro.tipo}, Modelo: {listaCarro.modelo}, Ano: {listaCarro.ano}, Placa: {listaCarro.placa}", 'carros') ] for index, listaCarro in enumerate(listaCarros)] + [[ sg.B("Cancelar"), sg.Submit("Confirmar") ]] window = sg.Window("Escolha o Carro", layout) data = window.read(close=True) botao = data[0] if not data: return try: index = [key for key, value in data[1].items() if value][0] except IndexError: return carros = listaCarros[index] return botao, carros
def show_users(users): if len(users) == 0: GeneralView.message('Não tem usuários para mostrar') else: layout = [[ sg.Radio( f"ID: {user.id}, Nome: {user.nome}, Idade: {user.idade}, Telefone: {user.telefone}", 'users') ] for index, user in enumerate(users)] + [[ sg.B("Voltar"), sg.Submit("Editar"), sg.Submit("Deletar") ]] window = sg.Window("Painel usuário", layout) data = window.read(close=True) if not data: return botao = data[0] try: userIndex = [key for key, value in data[1].items() if value][0] except IndexError: return return botao, userIndex, users[userIndex]
def show_cars(cars): if len(cars) == 0: GeneralView.message('Não tem carros para mostrar') else: layout = [[ sg.Radio( """{} - Tipo: {}, Modelo: {}, Ano: {}, Placa: {}""".format( index, car.tipo, car.modelo, car.ano, car.placa), 'car') ] for index, car in enumerate(cars)] + [[ sg.B("Voltar"), sg.Submit("Editar"), sg.Submit("Deletar") ]] window = sg.Window("Painel carro", layout) data = window.read(close=True) if not data: return botao = data[0] try: carIndex = [key for key, value in data[1].items() if value][0] except IndexError: return return botao, carIndex, cars[carIndex]
def verAlugueis(self): if len(self.__alugueis) == 0: GeneralView.message('Nenhum carro alugado') return try: data = AluguelView.show_alugueis(self.__alugueis) except Exception as e: print(e) GeneralView.message('Não foi possível ver os alugueis') return if data is None: return try: botao, index, aluguel = data if botao == 'Prolongar aluguel': self.prolongarAluguel(aluguel) elif botao == 'Devolver carro': self.devolverCarro(index) except: GeneralView.message('Não foi possível realizar a sua ação')
def alugarCarro(self): listaUsuarios = [ user for user in self.__usuarios if user not in map( lambda aluguel: aluguel.locatario, self.__alugueis) ] listaCarros = [ carro for carro in self.__carros if carro not in map(lambda aluguel: aluguel.carro, self.__alugueis) ] if len(listaUsuarios) == 0: GeneralView.message('Todos os usuários já alugaram um carro') return if len(listaCarros) == 0: GeneralView.message('Todos os carros já foram alugados') return try: data = AluguelView.getUser(listaUsuarios) if data is None: return botao, user = data if botao == 'Cancelar': return data = AluguelView.getCarro(listaCarros) if data is None: return botao, carro = data if botao == 'Cancelar': return data = AluguelView.duracao() if data is None: return duracao = data aluguel = Aluguel(user, carro, duracao=duracao) self.__alugueis.append(aluguel) except Exception as e: print(e) GeneralView.message( 'Não foi possível alugar o carro, tente novamente!')
def cadastrar(self): try: data = CarView.register_car() if data is None: return tipo, modelo, ano, placa = data if placa in list( map(lambda carro: carro.license_plate, self.__carros)): GeneralView.message('Carro com license_plate já cadastrada') else: if tipo == 'Luxo': car = Luxury_car(modelo, ano, placa) elif tipo == 'Popular': car = Popular_car(modelo, ano, placa) elif tipo == 'SUV': car = Suv_car(modelo, ano, placa) else: GeneralView.message('Tipo do carro desconhecido') return self.__carros.append(car) except: GeneralView.message( 'Não foi possível cadastrar o carro, tente novamente!')