示例#1
0
    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
示例#2
0
 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!')
示例#3
0
    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]()
示例#4
0
 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')
示例#5
0
 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')
示例#6
0
 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]()
示例#7
0
    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]()
示例#8
0
 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
示例#9
0
 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
示例#10
0
 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
示例#11
0
 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]
示例#12
0
 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]
示例#13
0
 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')
示例#14
0
 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!')
示例#15
0
 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!')