Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            int aluguelID   = int.Parse(tbAluguel.Text);
            int imovelID    = int.Parse(tbImovel.Text);
            int pessoaID    = int.Parse(tbPessoa.Text);
            int pagamentoID = int.Parse(tbPagamento.Text);

            Alugueis alugueis = new Alugueis();

            alugueis.i_alugueis   = aluguelID;
            alugueis.i_imoveis    = imovelID;
            alugueis.i_pagamentos = pagamentoID;
            alugueis.i_pessoas    = pessoaID;

            bool incluiu = AlugueisDB.setIncluiAlugueis(conexao, alugueis);

            if (incluiu)
            {
                MessageBox.Show("Aluguel cadastrado com sucesso!");
                Close();
            }
            else
            {
                MessageBox.Show("Erro ao cadastrar aluguel!");
            }
        }
Exemplo n.º 2
0
        private void button3_Click(object sender, EventArgs e)
        {
            int codigoPagamento = int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString());
            int codigoImovel    = int.Parse(dataGridView1.CurrentRow.Cells[1].Value.ToString());
            int codigoPessoa    = int.Parse(dataGridView1.CurrentRow.Cells[2].Value.ToString());
            int codigoAluguel   = int.Parse(dataGridView1.CurrentRow.Cells[3].Value.ToString());

            Alugueis alugueis = new Alugueis();

            alugueis.i_pagamentos = codigoPagamento;
            alugueis.i_imoveis    = codigoImovel;
            alugueis.i_pessoas    = codigoPessoa;
            alugueis.i_alugueis   = codigoAluguel;

            bool alterou = AlugueisDB.setAlteraAlugueis(conexao, alugueis);

            if (alterou)
            {
                MessageBox.Show("Aluguel alterado com sucesso!");
            }
            else
            {
                MessageBox.Show("Erro ao alterar aluguel!");
            }
            atualizaTela();
        }
Exemplo n.º 3
0
        public static bool setAlteraAlugueis(NpgsqlConnection conexao, Alugueis alugueis)
        {
            bool alterou = false;

            try
            {
                String        sql = "update alugueis set i_pagamentos = @i_pagamentos,i_imoveis = @i_imoveis, i_pessoas = @i_pessoas where i_alugueis = @codigo";
                NpgsqlCommand cmd = new NpgsqlCommand(sql, conexao);
                cmd.Parameters.Add("@i_pagamentos", NpgsqlTypes.NpgsqlDbType.Integer).Value = alugueis.i_pagamentos;
                cmd.Parameters.Add("@i_imoveis", NpgsqlTypes.NpgsqlDbType.Integer).Value    = alugueis.i_imoveis;
                cmd.Parameters.Add("@codigo", NpgsqlTypes.NpgsqlDbType.Integer).Value       = alugueis.i_alugueis;
                cmd.Parameters.Add("@i_pessoas", NpgsqlTypes.NpgsqlDbType.Integer).Value    = alugueis.i_pessoas;

                int valor = cmd.ExecuteNonQuery();
                if (valor == 1)
                {
                    alterou = true;
                }
            }
            catch (NpgsqlException erro)
            {
                MessageBox.Show("Erro de sql:" + erro.Message);
                Console.WriteLine("Erro de sql:" + erro.Message);
            }
            return(alterou);
        }
Exemplo n.º 4
0
        public static bool setIncluiAlugueis(NpgsqlConnection conexao, Alugueis alugueis)
        {
            bool incluiu = false;

            try
            {
                String        sql = "insert into alugueis(i_alugueis,i_imoveis, i_pessoas, i_pagamentos) values(@i_alugueis,@i_imoveis, @i_pessoas, @i_pagamentos)";
                NpgsqlCommand cmd = new NpgsqlCommand(sql, conexao);
                cmd.Parameters.Add("@i_alugueis", NpgsqlTypes.NpgsqlDbType.Integer).Value   = alugueis.i_alugueis;
                cmd.Parameters.Add("@i_imoveis", NpgsqlTypes.NpgsqlDbType.Integer).Value    = alugueis.i_imoveis;
                cmd.Parameters.Add("@i_pessoas", NpgsqlTypes.NpgsqlDbType.Integer).Value    = alugueis.i_pessoas;
                cmd.Parameters.Add("@i_pagamentos", NpgsqlTypes.NpgsqlDbType.Integer).Value = alugueis.i_pagamentos;

                int valor = cmd.ExecuteNonQuery();
                if (valor == 1)
                {
                    incluiu = true;
                }
            }
            catch (NpgsqlException erro)
            {
                MessageBox.Show("Erro de SQL:" + erro.Message);
                Console.WriteLine("Erro de SQL:" + erro.Message);
            }
            return(incluiu);
        }
Exemplo n.º 5
0
        public SimulacaoAluguelDTO Simular(SimularAlugueisDTO Aluguel)
        {
            Carros Carro = this._carrosRepositorio.GetById(Aluguel.CarroId);

            if (Carro == null)
            {
                throw new Exception($"Carro com id: {Aluguel.CarroId} não encontrado.");
            }

            Alugueis AluguelSimulacao = new Alugueis
            {
                Carro        = Carro,
                Cliente      = null,
                DataAluguel  = DateTime.Now,
                DataCheckin  = Aluguel.DataCheckin,
                DataCheckout = Aluguel.DataCheckout,
                Origem       = Aluguel.Origem,
                PrecoNoDia   = Carro.ValorHora
            };

            return(new SimulacaoAluguelDTO
            {
                Carro = Carro,
                DateCheckin = AluguelSimulacao.DataCheckin,
                DateCheckout = AluguelSimulacao.DataCheckout,
                Horas = AluguelSimulacao.Horas,
                PrecoTotal = AluguelSimulacao.PrecoTotal
            });
        }
Exemplo n.º 6
0
 public Alugueis Add(Alugueis Aluguel)
 {
     try
     {
         _contexto.Alugueis.Add(Aluguel);
         _contexto.SaveChanges();
         return(_contexto.Alugueis.Include(i => i.Carro.Modelo).FirstOrDefault(f => f.Id == Aluguel.Id));
     }
     catch (Exception e)
     {
         throw new Exception("Erro ao inserir Aluguel: " + e.Message + " (" + e.InnerException + ")");
     }
 }
Exemplo n.º 7
0
        public IActionResult CadastrarAluguel(AlugueisDTO Aluguel)
        {
            try
            {
                Alugueis Retorno = this._alugueisBLL.Alugar(Aluguel);

                return(Created("api/Alugueis/ObterAluguel?Aluguel=" + Retorno.Id, new SaidaAPI {
                    ExecutadoComSucesso = true, Data = Retorno
                }));
            }
            catch (Exception e)
            {
                return(BadRequest(new SaidaAPI {
                    ExecutadoComSucesso = false, Mensagem = e.Message
                }));
            }
        }
Exemplo n.º 8
0
        public IActionResult ObterAluguel(int Aluguel)
        {
            try
            {
                Alugueis Retorno = _alugueisBLL.ObterPorId(Aluguel);

                if (Retorno == null)
                {
                    return(NotFound(new SaidaAPI {
                        ExecutadoComSucesso = false, Mensagem = "Aluguel não encontrado com o Id: " + Aluguel
                    }));
                }

                return(Ok(new SaidaAPI {
                    ExecutadoComSucesso = true, Data = Retorno
                }));
            }
            catch (Exception e)
            {
                return(BadRequest(new SaidaAPI {
                    ExecutadoComSucesso = false, Mensagem = e.Message
                }));
            }
        }