Exemplo n.º 1
0
        private void Uc_locacao_Load(object sender, EventArgs e)
        {
            try
            {
                LocacaoDAO ldao = new LocacaoDAO();
                dataGridView1.DataSource = ldao.lista_locacao();

                FuncionarioDAO fdao = new FuncionarioDAO();
                cb_funcionario.DataSource    = fdao.lista_funcionario();
                cb_funcionario.DisplayMember = "Nome";
                cb_funcionario.ValueMember   = "Id";

                ClienteDAO cdao = new ClienteDAO();
                cb_cliente.DataSource    = cdao.mostra_cliente();
                cb_cliente.DisplayMember = "Nome";
                cb_cliente.ValueMember   = "ID";

                AutomovelDAO adao = new AutomovelDAO();
                cb_carro.DataSource    = adao.lista_auto();
                cb_carro.DisplayMember = "Veiculo";
                cb_carro.ValueMember   = "ID";
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 2
0
 private void Button2_Click(object sender, EventArgs e)
 {
     try
     {
         if (!verificaCampos())
         {
             MessageBox.Show("Preencha todos os campos!");
         }
         else
         {
             if (MessageBox.Show("Deseja alterar o dado de locação de ID:" + dataGridView1.CurrentRow.Cells[0].Value.ToString() + " ??"
                                 , "Alterar Locação", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
             {
                 Locacao objl = new Locacao
                 {
                     locacao_id        = (int)dataGridView1.CurrentRow.Cells[0].Value,
                     locacao_tipo      = txt_tipo.Text,
                     locacao_valor     = double.Parse(txt_valor.Text),
                     locacao_dt_inicio = Convert.ToDateTime(txt_inicio.Text),
                     locacao_dt_fim    = Convert.ToDateTime(txt_fim.Text),
                     automovel         = (int)cb_carro.SelectedValue,
                     cliente           = (int)cb_carro.SelectedValue,
                     funcionario       = (int)cb_funcionario.SelectedValue
                 };
                 LocacaoDAO ldao = new LocacaoDAO();
                 ldao.altera(objl);
                 Uc_locacao_Load(null, null);
             }
         }
     }
     catch (Exception)
     {
         MessageBox.Show("Erro ao alterar o funcionario");
     }
 }
Exemplo n.º 3
0
 private void Button1_Click(object sender, EventArgs e)
 {
     if (verificaCampos())
     {
         try
         {
             Locacao objl = new Locacao
             {
                 locacao_tipo      = txt_tipo.Text,
                 locacao_valor     = double.Parse(txt_valor.Text),
                 locacao_dt_inicio = Convert.ToDateTime(txt_inicio.Text),
                 locacao_dt_fim    = Convert.ToDateTime(txt_fim.Text),
                 automovel         = (int)cb_carro.SelectedValue,
                 cliente           = (int)cb_carro.SelectedValue,
                 funcionario       = (int)cb_funcionario.SelectedValue
             };
             LocacaoDAO ldao = new LocacaoDAO();
             ldao.cadastra_locacao(objl);
             Uc_locacao_Load(null, null);
         }
         catch (Exception t)
         {
             MessageBox.Show("Erro: " + t);
         }
     }
     else
     {
         MessageBox.Show("Preencha todos os campos.");
     }
 }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            string status;

            foreach (Locacao l in LocacaoDAO.Listar())
            {
                string x = l.totalLocacao.ToString("C2");
                if (l.devolvido)
                {
                    status = "Disponível";
                }
                else
                {
                    status = "Locado";
                }
                dtaLocacao.Items.Add(new DataGridItems
                {
                    Id       = l.id.ToString(),
                    Cliente  = l.cliente.nome,
                    Agente   = l.agente.nome,
                    Veiculo  = l.veiculo.modelo,
                    Locacao  = status,
                    Previsao = l.previsaoEntrega.ToString(),
                    Preco    = x
                });
            }
        }
        private void btnConcluir_Click(object sender, RoutedEventArgs e)
        {
            Locacao l = new Locacao
            {
                NomeCliente       = TxtNomeCliente.Text,
                CpfCliente        = TxtCpfCliente.Text,
                CnhCliente        = TxtCnhCliente.Text,
                Status            = TxtStatus.Text,
                Modelo            = TxtModelo.Text,
                Placa             = TxtPlaca.Text,
                NomeFuncionario   = TxtNomeFuncionario.Text,
                CpfFuncionario    = TxtCpfFuncionario.Text,
                QntdDiasLocacao   = Convert.ToInt32(TxtDiasLocacao.Text),
                ValorSemMulta     = Convert.ToDouble(TxtValorPrevisto.Text),
                DataInicio        = TxtDataInicio.Text,
                DevolucaoPrevista = Convert.ToDateTime(TxtDataPrevistaEntrega.Text),
            };

            if (LocacaoDAO.CadastrarLocacao(l))
            {
                MessageBox.Show("Locação cadastrado com sucesso!");
                LimparFormulario();
            }
            else
            {
                MessageBox.Show("Favor Rever Dados!");
            }
        }
Exemplo n.º 6
0
        private void Button3_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Deseja excluir a locação de ID:" + dataGridView1.CurrentRow.Cells[0].Value.ToString() + " ??"
                                    , "EXCLUSÃO", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                {
                    Locacao objl = new Locacao
                    {
                        locacao_id = (int)dataGridView1.CurrentRow.Cells[0].Value
                    };
                    LocacaoDAO ldao = new LocacaoDAO();
                    ldao.exclui(objl);

                    Uc_locacao_Load(null, null);
                }
                else
                {
                    MessageBox.Show("Exclusão cancelada !");
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Erro.");
            }
        }
        private void Popular()
        {
            string status;

            foreach (Locacao loc in LocacaoDAO.ListarLocado())
            {
                if (loc.devolvido)
                {
                    status = "Disponível";
                }
                else
                {
                    status = "Locado";
                }
                dynamic item = new
                {
                    id          = loc.id,
                    cliente     = loc.cliente.nome,
                    veiculo     = loc.veiculo.modelo,
                    prevEntrega = loc.previsaoEntrega,
                    situacao    = status
                };

                locacoesAtivas.Add(item);
            }

            dtaLocacoes.ItemsSource = locacoesAtivas;
        }
Exemplo n.º 8
0
 public LocacaoController(LocacaoDAO locacaoDAO, ClienteDAO clienteDAO, FuncionarioDAO funcionarioDAO, VeiculoDAO veiculoDAO, ReservaDAO reservaDAO)
 {
     _locacaoDAO     = locacaoDAO;
     _clienteDAO     = clienteDAO;
     _funcionarioDAO = funcionarioDAO;
     _veiculoDAO     = veiculoDAO;
     _reservaDAO     = reservaDAO;
 }
        private void btn_frmPessoa_Alterar_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("Devolução Feita?", "Alterar Locação", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                locacao = new Locacao();
                livro   = new Livro();
                pessoa  = new Pessoa();
                locacao.LocacaoDataAluguel = DateTime.Today;
                locacao.LocacaoDataLimite  = DateTime.Today.AddDays(10);


                livro.IdLivro = Convert.ToInt16(txt_CodLivro_Locacao.Text);

                try
                {
                    locacao.LocacaoLivro = LivroDAO.VerificarLivroPorCod(livro);
                }
                catch
                {
                    MessageBox.Show("Livro Não Encontrado", "Livro",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                }


                pessoa.PessoaCpf = txt_CpfPessoa_Locacao.Text;

                try
                {
                    locacao.LocacaoPessoa = PessoaDAO.VerificarPessoaPorCPF(pessoa);
                }
                catch
                {
                    MessageBox.Show("asjdlkajsd", "Livro",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                }

                if (txt_Situacao.Text == "Alugado")
                {
                    locacao.LocacaoStatus = true;
                }
                else
                {
                    locacao.LocacaoStatus = false;
                }

                if (LocacaoDAO.AlterarLocacao(locacao))
                {
                    MessageBox.Show("Gravado com sucesso!", "Locação",
                                    MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    MessageBox.Show("Não foi possível gravar!", "Locação",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
Exemplo n.º 10
0
        private void BtnBuscarLocacao_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                l = LocacaoDAO.BuscarLocacaoPorId(Convert.ToInt32(txtIdLocacao.Text));

                if (l == null) //Verifica se a locação existe
                {
                    throw new Exception("Locação não encontrada");
                }

                if (l.Status == false)
                {
                    throw new Exception("Está devolução já foi efetivada"); //Verifica se a devolução já foi feita
                }

                //Preenche os campos
                txtCliente.Text    = l.Cliente.Nome;
                txtCPFCliente.Text = l.Cliente.Cpf;
                txtDtLocacao.Text  = l.DataLocacao.ToString();

                btnDevolucao.IsEnabled = true; //Ativa o botão

                //Laço para preencher todos os ITEMFILME no GRID
                foreach (ItemFilme x in l.Filmes)
                {
                    x.Filme.Titulo.ToLower();
                    dynamic filmeDyn = new
                    {
                        Filme      = x.Filme.Titulo,
                        Valor      = x.Valor,
                        Quantidade = x.Quantidade,
                        Subtotal   = x.Valor * x.Quantidade
                    };
                    //Preencher GRID
                    produtosGrid.Add(filmeDyn);
                    dtFilmesLocados.ItemsSource = produtosGrid;
                    dtFilmesLocados.Items.Refresh();

                    total = total + (x.Valor * x.Quantidade); //Soma total
                }

                lbTotal.Content = total;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                total = 0;
            }
        }
Exemplo n.º 11
0
        private void DtLocacaoXCliente_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            dynamic objetoClicado = dtLocacaoXCliente.SelectedItem;

            Model.Locacao locacaoSelecionada = LocacaoDAO.BuscarLocacaoPorId(objetoClicado.ID);

            List <ItemFilme> listaItemFilmeClicado = locacaoSelecionada.Filmes;

            foreach (ItemFilme x in listaItemFilmeClicado)
            {
                MessageBox.Show("Filme: " + x.Filme.ToString() + "\n -----> QTD: "
                                + x.Quantidade + "\n -----> Valor:" + x.Valor);
            }
        }
        private void Salvar_Click_1(object sender, RoutedEventArgs e)
        {
            int idCliente     = (int)cboClientes.SelectedValue;
            int idFuncionario = (int)cboFuncionarios.SelectedValue;
            int idVeiculo     = (int)cboVeiculos.SelectedValue;

            locacao = new Locacao
            {
                cliente         = ClienteDAO.BuscarPorId(idCliente),
                agente          = AgenteDAO.BuscarPorId(idFuncionario),
                veiculo         = VeiculoDAO.BuscarPorId(idVeiculo),
                formaPagamento  = cboFormaPagamento.Text,
                previsaoEntrega = Convert.ToDateTime(txtDataEntrega.Text)
            };
            if (LocacaoDAO.ValidarCatCnh(locacao))
            {
                if (ValidarLocCli(locacao.cliente))
                {
                    if (LocacaoDAO.Salvar(locacao))
                    {
                        int    dias  = locacao.previsaoEntrega.Day - locacao.criadoEm.Day;
                        double total = locacao.veiculo.valorDiaria * dias;
                        LimparFormulario();
                        MessageBox.Show($"Locação Cadastrada no total de R$ {total}", "Locação - WPF",
                                        MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        MessageBox.Show("Veículo não está disponível!",
                                        "Locação - WPF", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Cliente informado já está com locação ativa!",
                                    "Locação - WPF", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("Cliente não está habilitado para dirigir este veículo!",
                                "Locação - WPF", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 13
0
 public bool Gravar(Locacao obj)
 {
     if (obj.ObjCliente.Nome != string.Empty && obj.ObjCliente.Cpf != string.Empty)
     {
         int sucesso = new LocacaoDAO().Gravar(obj);
         if (sucesso != 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
        private bool ValidarLocCli(Cliente cli)
        {
            int            cont = 0;
            List <Locacao> loc  = LocacaoDAO.ListarLocPorCli(cli.cpf);

            foreach (Locacao l in loc)
            {
                if (!l.devolvido)
                {
                    cont++;
                }
            }

            if (cont != 0)
            {
                return(false);
            }
            return(true);
        }
        private void btn_frmEmprestimo_Buscar_Click(object sender, RoutedEventArgs e)
        {
            locacao = new Locacao();

            locacao.IdLocacao = Convert.ToInt16(txt_IdLocacao_Buscar.Text);

            locacao = LocacaoDAO.VerificarLocacaoPorIdLocacao(locacao);

            if (!string.IsNullOrEmpty(txt_IdLocacao_Buscar.Text))
            {
                if (locacao != null)
                {
                    txt_NomeLivro_Locacao.Text = locacao.LocacaoLivro.LivroNome;
                    txt_CodLivro_Locacao.Text  = Convert.ToString(locacao.LocacaoLivro.IdLivro);

                    txt_NomePessoa_Locacao.Text = locacao.LocacaoPessoa.PessoaNome;
                    txt_CpfPessoa_Locacao.Text  = locacao.LocacaoPessoa.PessoaCpf;

                    txt_Data_Limite_Devolucao.Text = Convert.ToString(locacao.LocacaoDataAluguel);

                    if (locacao.LocacaoStatus == true)
                    {
                        txt_Situacao.Text = "Alugado";
                    }
                    else
                    {
                        txt_Situacao.Text = "Devolvido";
                    }
                }
                else
                {
                    MessageBox.Show("Locação não encontrado!", "Locação de Livros",
                                    MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            else
            {
                MessageBox.Show("Favor preencher o campo da busca", "Locação de Livros",
                                MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
        private void btnBuscar_Click_1(object sender, RoutedEventArgs e)
        {
            List <Locacao> vazia = new List <Locacao>();

            Cliente cli = ClienteDAO.BuscarCpf(txtCpf.Text);

            if (cli != null)
            {
                locacoes.Clear();
                string status;
                foreach (Locacao loc in LocacaoDAO.ListarLocPorCli(txtCpf.Text))
                {
                    if (loc.devolvido)
                    {
                        status = "Entregue";
                    }
                    else
                    {
                        status = "Com cliente";
                    }
                    dynamic item = new
                    {
                        cliente     = cli.nome,
                        veiculo     = loc.veiculo.modelo,
                        prevEntrega = loc.previsaoEntrega.ToString(),
                        situacao    = status,
                        preco       = loc.totalLocacao.ToString("C2")
                    };
                    locacoes.Add(item);
                }
                dtaLocacoes.ItemsSource = locacoes;
            }
            else
            {
                MessageBox.Show("Cliente não possui locações cadastradas!",
                                "Locação - WPF", MessageBoxButton.OK, MessageBoxImage.Error);
                txtCpf.Clear();
                txtCpf.Focus();
            }
        }
Exemplo n.º 17
0
        private void BtnLocar_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ItemFilme iff = new ItemFilme();

                l.Cliente = c;
                l.DataLocacao = dtLocacao.SelectedDate.Value;
                l.DataDevolucao = dtDevolucao.SelectedDate.Value;
                l.Filmes = filmesAdicionados;
                l.Funcionario = func;
                l.DataDevolucao = dtDevolucao.SelectedDate.Value;
                l.Valor = Convert.ToDouble(lbTotal.Content);

                if (l.Cliente.Status == false)
                {
                    throw new Exception("O Cliente está inativo. \nNão é possivel realizar a locação.");
                }
                if (l.Funcionario.Status == false)
                {
                    throw new Exception("O funcionário está inativo. \nNão é possivel realizar a locação.");
                }

                double comissaoFuncionario = FuncionarioDAO.EfetivarComissao(l); //Retorna o valor da comissão daquela venda

                LocacaoDAO.CadastrarLocacao(l);

                //BAIXAR ESTOQUE PRODUTOS
                FilmeDAO.BaixarEstoque(filmesAdicionados);
                MessageBox.Show("Locação realizada!");

                LimparFormulario();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
Exemplo n.º 18
0
        private void BtnDevolucao_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                l.DataDevolvida = txtDataDevolucao.SelectedDate.Value; //Verifica se a data de devolução não é <= data de locação

                if (l.DataDevolucao.Date <= l.DataLocacao.Date)
                {
                    throw new Exception("A data de devolução NÃO pode ser MENOR ou IGUAL que a data de Locação!");
                }
                if (l.DataDevolvida > l.DataDevolucao) // Verifica se há atraso na devolução
                {
                    int    diferencaData = l.DataDevolvida.Value.Subtract(l.DataDevolucao).Days;
                    double valorMulta    = LocacaoDAO.CalcularMulta(l);
                    MessageBox.Show("A locação está sendo entregue " + diferencaData + " dia(s) atrasado! \nSerá cobrado R$ " + valorMulta + " de multa.");
                    lbValorMulta.Content = valorMulta;
                }

                Filme f = FilmeDAO.VerificaInatividadeListaFilme(l.Filmes); //Verifica se na lista há filmes inativos

                if (f != null)                                              //Se o método acima retornar um objeto Filme, ele está INATIVO.
                {
                    throw new Exception("O filme " + f.Titulo + " está inativo, não é possivel efetuar a devolução");
                }

                if (!(LocacaoDAO.InativarLocacao(l))) //Status da locação = false
                {
                    throw new Exception("Não foi possivel realizar a devolução. \nEntre em contato com o desenvolvedor");
                }

                //LocacaoDAO.InativarLocacao(l);
                MessageBox.Show("Devolução realizada com sucesso!");
                LimparFormulario();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            dynamic loc = dtaLocacoes.SelectedItem;

            Locacao lo = LocacaoDAO.BuscarPorId(loc.id);

            lo.dataEntrega    = DateTime.Now;
            lo.devolvido      = true;
            lo.veiculo.locado = false;


            if (lo.dataEntrega.Month > lo.previsaoEntrega.Month)
            {
                int dias = (lo.dataEntrega - lo.previsaoEntrega).Days;
                lo.custoVariavel = lo.veiculo.valorDiaria * dias;
                lo.totalLocacao += lo.custoVariavel;

                LocacaoDAO.Alterar(lo);
                MessageBox.Show($"Veículo entregue! Pelo atraso de {dias} dias, " +
                                $"houve a cobrança extra no valor de R$ {lo.custoVariavel}", "Locação - WPF",
                                MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else if (lo.dataEntrega.Day > lo.previsaoEntrega.Day)
            {
                int atraso = lo.dataEntrega.Day - lo.previsaoEntrega.Day;
                lo.custoVariavel = lo.veiculo.valorDiaria * atraso;
                lo.totalLocacao += lo.custoVariavel;

                LocacaoDAO.Alterar(lo);
                MessageBox.Show($"Veículo entregue! Pelo atraso de {atraso} dias, " +
                                $"houve a cobrança extra no valor de R$ {lo.custoVariavel}", "Locação - WPF",
                                MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else if (lo.dataEntrega.Day < lo.previsaoEntrega.Day)
            {
                int dias = lo.previsaoEntrega.Day - lo.dataEntrega.Day;
                lo.custoVariavel = lo.veiculo.valorDiaria * dias;
                lo.totalLocacao -= lo.custoVariavel;

                if (lo.totalLocacao == 0)
                {
                    lo.custoVariavel -= lo.veiculo.valorDiaria;
                    lo.totalLocacao   = lo.veiculo.valorDiaria;

                    LocacaoDAO.Alterar(lo);
                    MessageBox.Show($"Veículo entregue! Pela entrega antecipada de {dias} dias, " +
                                    $"houve o desconto de R$ {lo.custoVariavel}", "Locação - WPF",
                                    MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    LocacaoDAO.Alterar(lo);
                    MessageBox.Show($"Veículo entregue! Pela entrega antecipada de {dias} dias, " +
                                    $"houve o desconto de R$ {lo.custoVariavel}", "Locação - WPF",
                                    MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            else
            {
                LocacaoDAO.Alterar(lo);
                MessageBox.Show($"Veículo entregue na data esperada!", "Locação - WPF",
                                MessageBoxButton.OK, MessageBoxImage.Information);
            }

            List <Locacao> vazia = new List <Locacao>();

            locacoesAtivas.Clear();
            dtaLocacoes.ItemsSource = vazia;
            dtaLocacoes.Items.Refresh();
            Popular();
        }
Exemplo n.º 20
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     dtaLocacoes.ItemsSource       = LocacaoDAO.ListarLocacao();
     dtaLocacoes.DisplayMemberPath = "Nome";
     dtaLocacoes.SelectedValuePath = "Id";
 }