Exemplo n.º 1
0
        //private readonly String ContaUserName;

        public LancamentoAPIController(LancamentoDAO lancamentoDAO, ContaDAO contaDAO)
        {
            _LancamentoDAO = lancamentoDAO;
            _ContaDAO      = contaDAO;

            //ContaUserName = User.Identity.Name;
        }
        private void btn_CadastrarLancamento_Click(object sender, RoutedEventArgs e)
        {
            if (drop_SelectCategoria.SelectedItem == null || drop_SelectConta.SelectedItem == null || input_LancamentoValue.Text == "")
            {
                MessageBox.Show("Erro : Campo vazio", "Cadastrar lançamento - Erro ", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                int CategoriaId = (int)drop_SelectCategoria.SelectedValue;

                int ContaId = (int)drop_SelectConta.SelectedValue;

                double valor = Convert.ToDouble(input_LancamentoValue.Text);

                Lancamento c = new Lancamento();

                c.ContaId = ContaId;

                c.CategoriaId = CategoriaId;

                c.Valor = valor;

                LancamentoDAO.Create(c);

                MessageBox.Show("Lançamento no valor de " + c.Valor + " na Categoria " + LancamentoDAO.ReadById(c.Id).Categoria.Nome + " para a Conta " + LancamentoDAO.ReadById(c.Id).Conta.Nome + " Cadastrado com sucesso!!", "Listar Categorias", MessageBoxButton.OK, MessageBoxImage.Information);

                clearForm();
            }
        }
 private void btnConfirmar_Click(object sender, EventArgs e)
 {
     try
     {
         if (this.txtValorPago.Text.Trim() != string.Empty)
         {
             var retorno = string.Empty;
             //
             retorno = new LancamentoDAO().LancamentoInserir(new LancamentoModel
             {
                 IdLancamento   = this.lancamentoModel.IdLancamento,
                 DataLiquidacao = Convert.ToDateTime(this.dtpDataPagamento.Value),
                 ValorLiquidado = Convert.ToDecimal(this.txtValorPago.Text)
             });
             //
             if (Char.IsNumber(retorno, 0))
             {
                 Mensagens.MensagemInformacao("Título liquídado com sucesso !");
                 if (Convert.ToDecimal(this.txtValorPago.Text) > this.lancamentoModel.ValorTotal)
                 {
                     using (var f = new DespesaBoletoForm(new DespesaModel
                     {
                         Valor = Convert.ToDecimal(this.txtValorPago.Text) - this.lancamentoModel.ValorTotal,
                         Parceiro = this.lancamentoModel.Fornecedor,
                         Estabelecimento = this.lancamentoModel.Estabelecimento,
                         DataMovimento = this.dtpDataPagamento.Value,
                         DescricaoDespesa = string.Format("TAXA BOL.{0} FORN.{1}", this.lancamentoModel.NumeroDocumento,
                                                          this.lancamentoModel.Fornecedor.NomeFornecedor)
                     }))
                     {
                         f.ShowDialog();
                     }
                 }
                 this.Close();
             }
             else
             {
                 throw new Exception(string.Format("Erro ao líquidar lançamento !\n{0}", retorno));
             }
         }
         else
         {
             throw new Exception("Erro ao liquidar Lançamento !\nValor pago é Obrigatório.");
         }
     }
     catch (Exception exception)
     {
         Mensagens.MensagemErro(exception.Message);
     }
 }
 private void btnConfirmar_Click(object sender, EventArgs e)
 {
     try
     {
         if (string.IsNullOrEmpty(this.txtValorTotal.Text.Trim()))
         {
             this.txtValorTotal.Text = Convert.ToDecimal(0).ToString();
         }
         //
         var retorno = new LancamentoDAO().LancamentoInserir(this.ValidarLancamento(new LancamentoModel
         {
             IdLancamento          = this.lancamentoModel.IdLancamento,
             DataEntradaInicial    = Convert.ToDateTime(this.dtpDataEntrada.Value),
             DataVencimentoInicial = Convert.ToDateTime(this.dtpDataVencimento.Value),
             Estabelecimento       = new EstabelecimentoModel {
                 IdEstabelecimento = Convert.ToInt32(this.cbbEstabelecimento.SelectedValue)
             },
             Fornecedor = new FornecedorModel {
                 IdFornecedor = Convert.ToInt32(this.cbbFornecedor.SelectedValue)
             },
             NumeroDocumento = this.txtNumeroDocumento.Text,
             ValorTotal      = Convert.ToDecimal(this.txtValorTotal.Text)
         }));
         //
         if (Char.IsNumber(retorno, 0))
         {
             MessageBox.Show("Lançamento de boleto efetuado com sucesso !");
             this.Close();
         }
         else
         {
             throw new Exception(retorno);
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show(string.Format("Erro no lançamento do Boleto!\nDetalhes: {0}", exception.Message));
     }
 }
Exemplo n.º 5
0
        private void btn_PesquisarConta_Click(object sender, RoutedEventArgs e)
        {
            List <dynamic> list_Lanc = new List <dynamic>();

            if (drop_FindConta.SelectedItem != null)
            {
                int Id = (int)drop_FindConta.SelectedValue;

                Conta c = ContaDAO.ReadById(Id);

                //Verifica algum dos checkbox esta marcado.
                if (checkBox_Categoria.IsChecked.Value || checkBox_first.IsChecked.Value || checkBox_Mes.IsChecked.Value || checkBox_Dia.IsChecked.Value)
                {
                    //Verifica se os dois estão marcados juntos(categoria e valor)
                    if (checkBox_Categoria.IsChecked.Value && checkBox_first.IsChecked.Value)
                    {
                        int CategoriaId = (int)drop_FindCategoria.SelectedValue;

                        if (!string.IsNullOrEmpty(drop_FindCategoria.Text) && !string.IsNullOrEmpty(form_PesquisarLancamentoValor1.Text) && !string.IsNullOrEmpty(form_PesquisarLancamentoValor2.Text))
                        {
                            foreach (Lancamento l in LancamentoDAO.ReadByAll(c.Id, CategoriaId, Convert.ToDouble(form_PesquisarLancamentoValor1.Text), Convert.ToDouble(form_PesquisarLancamentoValor2.Text)))
                            {
                                dynamic Lancamentos = new
                                {
                                    Nome      = l.Conta.Nome,
                                    Categoria = l.Categoria.Nome,
                                    Valor     = l.Valor,
                                    Data      = l.CreationDate
                                };

                                list_Lanc.Add(Lancamentos);
                            }

                            dataGrid.ItemsSource = list_Lanc;

                            dataGrid.Items.Refresh();
                        }
                        else
                        {
                            MessageBox.Show("Erro - Filtro invalido", "Contas e lancamentos", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        }
                    }
                    else
                    {
                        //Pesquisar pelo intervalo de valor
                        if (checkBox_first.IsChecked.Value)
                        {
                            if (!string.IsNullOrEmpty(form_PesquisarLancamentoValor1.Text) && !string.IsNullOrEmpty(form_PesquisarLancamentoValor2.Text))
                            {
                                //MessageBox.Show("Erro - Filtro invalido - Intervalo de valores", "Contas e lancamentos", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                                foreach (Lancamento l in LancamentoDAO.ReadByValorInter(c.Id, Convert.ToDouble(form_PesquisarLancamentoValor1.Text), Convert.ToDouble(form_PesquisarLancamentoValor2.Text)))
                                {
                                    dynamic Lancamentos = new
                                    {
                                        Nome      = l.Conta.Nome,
                                        Categoria = l.Categoria.Nome,
                                        Valor     = l.Valor,
                                        Data      = l.CreationDate
                                    };

                                    list_Lanc.Add(Lancamentos);
                                }

                                dataGrid.ItemsSource = list_Lanc;

                                dataGrid.Items.Refresh();
                            }
                            else
                            {
                                MessageBox.Show("Erro - Filtro invalido - Intervalo de valores", "Contas e lancamentos", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                            }
                        }

                        //Pesquisar pela categoria
                        if (checkBox_Categoria.IsChecked.Value)
                        {
                            int CategoriaId = (int)drop_FindCategoria.SelectedValue;

                            if (!string.IsNullOrEmpty(drop_FindCategoria.Text))
                            {
                                foreach (Lancamento l in LancamentoDAO.ReadByTwo(c.Id, CategoriaId))
                                {
                                    dynamic Lancamentos = new
                                    {
                                        Nome      = l.Conta.Nome,
                                        Categoria = l.Categoria.Nome,
                                        Valor     = l.Valor,
                                        Data      = l.CreationDate
                                    };

                                    list_Lanc.Add(Lancamentos);
                                }

                                dataGrid.ItemsSource = list_Lanc;

                                dataGrid.Items.Refresh();

                                label3.Content = "Total gasto na categoria " + CategoriaDAO.ReadById(CategoriaId).Nome + ": R$" + ResumeController.TotalPorCategoria(c.Id, CategoriaId) + " , " + ResumeController.Porcentagem(c.Id, CategoriaId) + "% do Total gasto.";
                            }
                            else
                            {
                                MessageBox.Show("Erro - Filtro invalido - Categoria ", "Contas e lancamentos", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                            }
                        }

                        //Verifica se o campo de dia e mes estao marcados
                        if (checkBox_Mes.IsChecked.Value && checkBox_Dia.IsChecked.Value)
                        {
                            if (!string.IsNullOrEmpty(drop_FindMes.Text) || !string.IsNullOrEmpty(form_day1.Text) || !string.IsNullOrEmpty(form_day2.Text))
                            {
                                foreach (Lancamento l in LancamentoDAO.ReadByDate(c.Id, drop_FindMes.SelectedIndex + 1, Convert.ToInt32(form_day1.Text), Convert.ToInt32(form_day2.Text)))
                                {
                                    dynamic Lancamentos = new
                                    {
                                        Nome      = l.Conta.Nome,
                                        Categoria = l.Categoria.Nome,
                                        Valor     = l.Valor,
                                        Data      = l.CreationDate
                                    };

                                    list_Lanc.Add(Lancamentos);
                                }

                                dataGrid.ItemsSource = list_Lanc;

                                dataGrid.Items.Refresh();

                                label4.Content = "Total gasto durante o mes de " + drop_FindMes.SelectedItem + " entre os dias " + form_day1.Text + " e " + form_day2.Text + ": R$" + ResumeController.TotalNoMes(c.Id, drop_FindMes.SelectedIndex + 1);
                            }
                            else
                            {
                                MessageBox.Show("Erro - Filtro invalido - Campo vazio ", "Contas e lancamentos", MessageBoxButton.OK, MessageBoxImage.Error);
                            }
                        }
                        else
                        {
                            //Pesquisa pelo mes
                            if (checkBox_Mes.IsChecked.Value)
                            {
                                if (!string.IsNullOrEmpty(drop_FindMes.Text))
                                {
                                    //title_ContaNome.Content = drop_FindMes.SelectedValuePath;
                                    foreach (Lancamento l in LancamentoDAO.ReadByMonth(c.Id, drop_FindMes.SelectedIndex + 1))
                                    {
                                        dynamic Lancamentos = new
                                        {
                                            Nome      = l.Conta.Nome,
                                            Categoria = l.Categoria.Nome,
                                            Valor     = l.Valor,
                                            Data      = l.CreationDate
                                        };

                                        list_Lanc.Add(Lancamentos);
                                    }

                                    dataGrid.ItemsSource = list_Lanc;

                                    dataGrid.Items.Refresh();

                                    label4.Content = "Total gasto durante o mes de " + drop_FindMes.SelectedItem + " : R$" + ResumeController.TotalNoMes(c.Id, drop_FindMes.SelectedIndex + 1);
                                }
                                else
                                {
                                    MessageBox.Show("Erro - Filtro invalido - Mes ", "Contas e lancamentos", MessageBoxButton.OK, MessageBoxImage.Error);
                                }
                            }
                        }
                    }
                }
                else
                {
                    //Pesquisa apenas pelo nome
                    foreach (Lancamento l in LancamentoDAO.ReadByContaId(c.Id))
                    {
                        dynamic Lancamentos = new
                        {
                            Nome      = l.Conta.Nome,
                            Categoria = l.Categoria.Nome,
                            Valor     = l.Valor,
                            Data      = l.CreationDate
                        };

                        list_Lanc.Add(Lancamentos);
                    }

                    dataGrid.ItemsSource = list_Lanc;

                    dataGrid.Items.Refresh();
                }

                title_ContaNome.Content = c.Nome;

                title_Cpf.Content = c.Cpf;

                title_Criacao.Content = Convert.ToString(c.CreationDate);

                ContaDataNasc.Content = c.dataNasc;

                label2.Content = "Total gasto na conta de " + c.Nome + ": " + ResumeController.TotalDeGasto(c.Id) + "R$.";
            }
            else
            {
                MessageBox.Show("Erro - Campo vazio", "Contas e lancamentos", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }
Exemplo n.º 6
0
 public LancamentoController(LancamentoDAO lancamentoDAO, ContaDAO contaDAO, CategoriaDAO categoriaDAO)
 {
     _LancamentoDAO = lancamentoDAO;
     _ContaDAO      = contaDAO;
     _CategoriaDAO  = categoriaDAO;
 }
Exemplo n.º 7
0
 public HomeController(CategoriaDAO categoriaDAO, LancamentoDAO lancamentoDAO)
 {
     _LancamentoDAO = lancamentoDAO;
     _CategoriaDAO  = categoriaDAO;
 }
        private void btnConfirmar_Click(object sender, EventArgs e)
        {
            try
            {
                var totalDespesas = new decimal();
                //
                try
                {
                    foreach (DataGridViewRow linha in this.dataGridView1.Rows)
                    {
                        if (linha.Cells["clValorPago"].Value == null)
                        {
                            throw new Exception("Valor Pago inválido !");
                        }
                        else if (Convert.ToDecimal(linha.Cells["clValorPago"].Value) < Convert.ToDecimal(linha.Cells["clValorTotal"].Value))
                        {
                            throw new Exception("Valor pago não pode ser menor que o valor do Título !");
                        }
                        else
                        {
                            totalDespesas += Convert.ToDecimal(linha.Cells["clValorPago"].Value) - Convert.ToDecimal(linha.Cells["clValorTotal"].Value);
                        }
                    }
                }
                catch (InvalidCastException)
                {
                    throw new Exception("Valor Pago inválido !");
                }
                catch (ArgumentNullException)
                {
                    throw new Exception("Valor Pago inválido !");
                }
                catch (NullReferenceException)
                {
                    throw new Exception("Valor Pago inválido !");
                }
                catch (Exception exception)
                {
                    throw new Exception(exception.Message);
                }
                //
                if (MessageBox.Show(string.Format("Confirma a líquidação de {0} título ?", this.lancamentoListaModel.Count.ToString()), "Responda", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                {
                    try
                    {
                        foreach (DataGridViewRow linha in this.dataGridView1.Rows)
                        {
                            var retorno = string.Empty;
                            //
                            retorno = new LancamentoDAO().LancamentoInserir(new LancamentoModel
                            {
                                IdLancamento   = Convert.ToInt32(linha.Cells["clIdLancamento"].Value),
                                DataLiquidacao = Convert.ToDateTime(this.dtpDataPagamento.Value),
                                ValorLiquidado = Convert.ToDecimal(linha.Cells["clValorPago"].Value)
                                                 //
                            });
                            //
                            if (!Char.IsNumber(retorno, 0))
                            {
                                throw new Exception(string.Format("Erro ao líquidar lançamento !\n{0}", retorno));
                            }
                        }
                        //
                        Mensagens.MensagemInformacao("Títulos líquidados com sucesso !");
                        if (totalDespesas > 0)
                        {
                            var estabelecimento = new EstabelecimentoModel();
                            var fornecedor      = new FornecedorModel();
                            //
                            foreach (var item in this.lancamentoListaModel)
                            {
                                estabelecimento = new EstabelecimentoModel {
                                    IdEstabelecimento = item.Estabelecimento.IdEstabelecimento
                                };
                                fornecedor = new FornecedorModel {
                                    IdFornecedor = item.Fornecedor.IdFornecedor
                                };
                            }
                            using (var f = new DespesaBoletoForm(new DespesaModel
                            {
                                Valor = totalDespesas,
                                Parceiro = fornecedor,
                                Estabelecimento = estabelecimento,
                                DataMovimento = this.dtpDataPagamento.Value,
                                DescricaoDespesa = string.Format("TAXA BOL. LIQ LOTE")
                            }))
                            {
                                f.ShowDialog();
                            }
                        }


                        this.Close();
                    }
                    catch (FormatException)
                    {
                        Mensagens.MensagemErro("Valor Inválido");
                    }
                    catch (Exception exception)
                    {
                        Mensagens.MensagemErro(exception.Message);
                    }
                }
            }
            catch (Exception exception)
            {
                Mensagens.MensagemErro(exception.Message);
            }
        }
Exemplo n.º 9
0
        //
        private void CarregarTodosOsDatagrid()
        {
            try
            {
                this.dgvVencidos.AutoGenerateColumns = false;
                this.dgvAVencer.AutoGenerateColumns  = false;
                this.dgvQuitados.AutoGenerateColumns = false;
                //
                var Titulos = new LancamentoDAO().BoletosDataTable(new LancamentoModel
                {
                    DataEntradaInicial    = Convert.ToDateTime(this.dtpEntradaInicial.Value),
                    DataEntradaFinal      = Convert.ToDateTime(this.dtpEntradaFinal.Value),
                    DataVencimentoInicial = Convert.ToDateTime(this.dtpVencimentoInicial.Value),
                    DataVencimentoFinal   = Convert.ToDateTime(this.dtpVencimentoFinal.Value),
                    Fornecedor            = new FornecedorModel {
                        IdFornecedor = Convert.ToInt32(this.cbbFornecedor.SelectedValue)
                    },
                    Estabelecimento = new EstabelecimentoModel {
                        IdEstabelecimento = Convert.ToInt32(this.cbbEstabelecimento.SelectedValue)
                    }
                });
                //
                var valorTotalVencidos  = new Decimal();
                var valorTotalAVencer   = new Decimal();
                var valorTotalLiquidado = new Decimal();
                //
                var titulosVencidos   = Titulos.Clone();
                var titulosAVencer    = Titulos.Clone();
                var titulosLiquidados = Titulos.Clone();
                //
                foreach (DataRow linha in Titulos.Rows)
                {
                    switch (linha["status"].ToString())
                    {
                    case "Aberto":
                        valorTotalVencidos += Convert.ToDecimal(linha["valor_total"]);
                        titulosVencidos.ImportRow(linha);
                        break;

                    case "A vencer":
                        valorTotalAVencer += Convert.ToDecimal(linha["valor_total"]);
                        titulosAVencer.ImportRow(linha);
                        break;

                    case "Liquidado":
                        valorTotalLiquidado += Convert.ToDecimal(linha["valor_total"]);
                        titulosLiquidados.ImportRow(linha);
                        break;
                    }
                }
                //
                this.dgvVencidos.DataSource = titulosVencidos;
                this.dgvAVencer.DataSource  = titulosAVencer;
                this.dgvQuitados.DataSource = titulosLiquidados;
                //
                //
                this.txtAVencer.Text     = valorTotalAVencer.ToString("C2");
                this.txtTotalAberto.Text = valorTotalVencidos.ToString("C2");
                this.txtLiquidados.Text  = valorTotalLiquidado.ToString("C2");
                //
                //
                if (this.dgvVencidos.Rows.Count == 0)
                {
                    this.tabControl1.SelectedTab = tpAVencer;
                }
                else
                {
                    this.tabControl1.SelectedTab = tpVencido;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 10
0
 private void btnAlterar_Click(object sender, EventArgs e)
 {
     try
     {
         var listaLancamento = new LancamentoListaModel();
         var retorno         = string.Empty;
         if (this.tabControl1.SelectedTab == tpVencido || this.tabControl1.SelectedTab == tpAVencer)
         {
             if (this.dgvVencidos.Rows.Count > 0)
             {
                 foreach (DataGridViewRow row in this.dgvVencidos.Rows)
                 {
                     if (bool.Parse(row.Cells["clSelecionarAberto"].EditedFormattedValue.ToString()))//(row.Cells["clSelecionarAberto"].Value != null)
                     {
                         listaLancamento.Add(new LancamentoModel {
                             IdLancamento = Convert.ToInt32(row.Cells["clIdLancamentoAberto"].Value)
                         });
                     }
                 }
             }
             //
             else if (this.dgvAVencer.Rows.Count > 0)
             {
                 foreach (DataGridViewRow row in this.dgvAVencer.Rows)
                 {
                     if (bool.Parse(row.Cells["clSelecionarAVencer"].EditedFormattedValue.ToString()))//(row.Cells["clSelecionarAVencer"].Value != null)
                     {
                         listaLancamento.Add(new LancamentoModel {
                             IdLancamento = Convert.ToInt32(row.Cells["clIdLancamentoAVencer"].Value)
                         });
                     }
                 }
             }
             //
             //
             if (listaLancamento.Count <= 0)
             {
                 throw new Exception("Nenhum Boleto selecionado para exclusão !");
             }
             else if (MessageBox.Show(string.Format("Deseja realmente excluir o(s) titulo(s) selecionado(s) ?"), "Responda", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
             {
                 foreach (var item in listaLancamento)
                 {
                     retorno = new LancamentoDAO().LancamentoExcluir(item.IdLancamento);
                 }
                 MessageBox.Show(string.Format("Título(s) excluido(s) com sucesso ! {0}", listaLancamento.Count));
                 //
                 this.CarregarTodosOsDatagrid();
             }
             else
             {
                 listaLancamento = new LancamentoListaModel();
             }
         }
         else
         {
             MessageBox.Show("O título selecinado não pode ser alterado pois já se encontra Liquidado !", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     catch (Exception exception)
     {
         Mensagens.MensagemErro(exception.Message);
     }
 }