Ejemplo n.º 1
0
        protected void gdvMeusInvestimentos_SelectedIndexChanged(object sender, EventArgs e)
        {
            int rowIndex = gdvMeusInvestimentos.SelectedIndex;
            int id       = Convert.ToInt32(gdvMeusInvestimentos.DataKeys[rowIndex].Value);

            iC = new InvestimentoDAO().BuscarInvestimento(new InvestimentoConta()
            {
                Id = id
            });
            Session["investimentoConta"] = iC;

            Response.Redirect("~/Views/vwsResgate.aspx");
        }
        public void TestInvestimentoDAO3()
        {
            InvestimentoConta ic = new InvestimentoConta()
            {
                Conta        = new ContaDAO().PesquisarContaPorNumero(4) as ContaCorrente,
                Investimento = new InvestimentoDAO().BuscarInvestimentoPorId(1),
                DataInicio   = DateTime.Now,
                DataFim      = DateTime.Now.AddYears(1),
                Valor        = 1000
            };

            Assert.IsNotNull(new InvestimentoDAO().InserirInvestimento(ic));
        }
        public void TestInvestimentoDAO6()
        {
            InvestimentoConta ic = new InvestimentoConta()
            {
                Id           = 1,
                Conta        = new ContaDAO().PesquisarContaPorNumero(4) as ContaCorrente,
                Investimento = new InvestimentoDAO().BuscarInvestimentoPorId(2),
                DataInicio   = DateTime.Now,
                DataFim      = DateTime.Now.AddYears(1),
                Valor        = 1000,
            };

            Assert.IsInstanceOfType(new InvestimentoDAO().BuscarInvestimento(ic), typeof(InvestimentoConta));
        }
Ejemplo n.º 4
0
        public float Resgate(InvestimentoConta investimentoConta, DateTime dataResgate)
        {
            var valor = InvestimentoOPS.Resgate(investimentoConta, dataResgate);

            if (new ContaDAO().Transferir(new ContaDAO().PesquisarContaPorNumero(1),
                                          investimentoConta.Conta, (float)valor, "Resgate de investimento") != null)
            {
                if (AtualizaInvestimentoConta(investimentoConta, dataResgate, (float)valor) != null)
                {
                    return((float)valor);
                }
            }

            return(-1);
        }
        public void TestInvestimentoDAO4()
        {
            InvestimentoConta ic = new InvestimentoConta()
            {
                Conta        = new ContaDAO().PesquisarContaPorNumero(4) as ContaCorrente,
                Investimento = new InvestimentoDAO().BuscarInvestimentoPorId(1),
                DataInicio   = DateTime.Now,
                DataFim      = DateTime.Now.AddYears(1),
                Valor        = 1000,
            };

            var invest = new InvestimentoDAO().Resgate(ic, DateTime.Now.AddMonths(6));

            Console.Write(invest);
            Assert.IsTrue(invest > -1);
        }
Ejemplo n.º 6
0
        public static double Resgate(InvestimentoConta investimentoConta, DateTime dataResgate)
        {
            Random   random = new Random();
            TimeSpan mes;

            mes = dataResgate.Subtract(investimentoConta.DataInicio);
            float valorInicial = (float)investimentoConta.Valor;

            int meses = (int)(mes.TotalDays / 30);

            if (investimentoConta.Investimento.Rentabilidade > 0)
            {
                investimentoConta.Investimento.PreFixada = true;
            }
            else
            {
                investimentoConta.Investimento.PreFixada = false;
            }


            if (investimentoConta.Investimento.PreFixada)
            {
                for (int i = 0; i < meses; i++)
                {
                    investimentoConta        = AtualizaInvestimento(investimentoConta);
                    investimentoConta.Valor -= investimentoConta.Valor * (investimentoConta.Investimento.Taxa.Valor / 100) / 12;
                }
                if (investimentoConta.DataFim > dataResgate)
                {
                    investimentoConta.Valor -= investimentoConta.Valor * 0.0005 * (investimentoConta.DataFim.Subtract(dataResgate).TotalDays);
                }
            }

            else
            {
                for (int i = 0; i < meses; i++)
                {
                    investimentoConta        = AtualizaInvestimento(investimentoConta, random.Next(4, 7)); // Taxa de rentabilidade aleatoria entre 7% e 13% ao mês
                    investimentoConta.Valor -= investimentoConta.Valor * (investimentoConta.Investimento.Taxa.Valor / 100) / 12;
                }
            }

            return(investimentoConta.Valor < valorInicial ? valorInicial : investimentoConta.Valor);
        }
        public void TestInvestimentoOPS1()
        {
            Taxa taxa = new Taxa()
            {
                Id    = 1,
                Nome  = "Taxa louca",
                Valor = 12
            };

            Investimento investimento = new Investimento()
            {
                Nome          = "Tesouro Direto",
                PreFixada     = true,
                Rentabilidade = 4,
                Taxa          = taxa,
            };

            ContaCorrente conta = new ContaCorrente()
            {
                Limite        = 1000,
                Emprestimos   = null,
                Investimentos = null,
                Numero        = 1213,
                Pessoa        = null,
                Saldo         = 1500,
                Senha         = "1234"
            };

            InvestimentoConta investimentoConta = new InvestimentoConta()
            {
                Conta        = conta,
                Investimento = investimento,
                Valor        = 1000,
                DataInicio   = DateTime.Now,
                DataFim      = DateTime.Now.AddYears(1)
            };
            double saidaDouble = InvestimentoOPS.Resgate(investimentoConta, DateTime.Now.AddMonths(3));

            Console.Write(saidaDouble);
            int saidaInt = Convert.ToInt32(saidaDouble);

            Assert.AreEqual(955, saidaInt);
        }
Ejemplo n.º 8
0
        public InvestimentoConta AtualizaInvestimentoConta(InvestimentoConta investimentoConta, DateTime dataResgate, float valor)
        {
            MySqlCommand command = Connection.Instance.CreateCommand();
            string       sql     = ("UPDATE projetobanking.investimento_conta " +
                                    "SET Investimento_Resgate = @Investimento_Resgate, Investimento_Valor_Resgate = @valorResgate" +
                                    " WHERE Investimento_Conta_Id = " + investimentoConta.Id) + ";";

            command.CommandText = sql;
            command.Parameters.AddWithValue("@Investimento_Resgate", dataResgate);
            command.Parameters.AddWithValue("@valorResgate", valor);
            int retorno = command.ExecuteNonQuery();

            if (retorno > 0)
            {
                return(investimentoConta);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 9
0
        public InvestimentoConta InserirInvestimento(InvestimentoConta investimentoConta)
        {
            try
            {
                if (investimentoConta.Conta.Saldo > investimentoConta.Valor) // Necessário ter saldo suficiente para investir
                {
                    MySqlCommand command = Connection.Instance.CreateCommand();
                    string       sql     = ("INSERT INTO Investimento_Conta (Investimento_Investimento_id, Conta_Corrente_Conta_Conta_Corrente_id," +
                                            " Investimento_Conta_Valor, Investimento_Inicio, Investimento_Fim)  VALUES (@Investimento_Investimento_id, @Conta_Corrente_Conta_Conta_Corrente_id," +
                                            " @Investimento_Conta_valor, @Investimento_Inicio, @Investimento_Fim)");

                    command.CommandText = sql;
                    command.Parameters.AddWithValue("@Investimento_Investimento_id", investimentoConta.Investimento.Id);
                    command.Parameters.AddWithValue("@Conta_Corrente_Conta_Conta_Corrente_id", investimentoConta.Conta.Numero);
                    command.Parameters.AddWithValue("@Investimento_Conta_valor", investimentoConta.Valor);
                    command.Parameters.AddWithValue("@Investimento_Inicio", investimentoConta.DataInicio);
                    command.Parameters.AddWithValue("@Investimento_Fim", investimentoConta.DataFim);

                    int retorno = command.ExecuteNonQuery();


                    if (retorno > 0)
                    {
                        if (new ContaDAO().Transferir(investimentoConta.Conta, new ContaDAO().PesquisarContaPorNumero(1), (float)investimentoConta.Valor, "Realização de investimento") != null)
                        {
                            //Caso esteja tudo certo com a operação de inserção de investimento, o mesmo é sensibilizado na Conta Contábil de investimentos
                            return(investimentoConta);
                        }
                    }
                }

                return(null);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw e;
            }
        }
Ejemplo n.º 10
0
        public InvestimentoConta BuscarInvestimento(InvestimentoConta investimentoConta)
        {
            MySqlCommand command = Connection.Instance.CreateCommand();

            command.CommandText = "SELECT * FROM Investimento_Conta WHERE Investimento_Conta_Id=@Investimento_Conta_Id;";
            command.Parameters.AddWithValue("@Investimento_Conta_Id", investimentoConta.Id);

            var reader = command.ExecuteReader();
            int contaId = -1, investimentoId = -1;
            InvestimentoConta iC = null;

            while (reader.Read())
            {
                iC = new InvestimentoConta()
                {
                    Id         = int.Parse(reader["Investimento_Conta_id"].ToString()),
                    DataFim    = DateTime.Parse(reader["Investimento_Fim"].ToString()),
                    DataInicio = DateTime.Parse(reader["Investimento_Inicio"].ToString()),
                    Valor      = double.Parse(reader["Investimento_Conta_Valor"].ToString()),
                };
            }

            if (reader["Investimento_Resgate"].GetType() != typeof(DBNull))
            {
                iC.Resgatado    = true;
                iC.DataResgate  = DateTime.Parse(reader["Investimento_Resgate"].ToString());
                iC.ValorResgate = float.Parse(reader["Investimento_Valor_Resgate"].ToString());
            }

            contaId        = int.Parse(reader["Conta_Corrente_Conta_Conta_Corrente_id"].ToString());
            investimentoId = int.Parse(reader["Investimento_Investimento_id"].ToString());
            reader.Close();

            iC.Investimento = new InvestimentoDAO().BuscarInvestimentoPorId(investimentoId);
            iC.Conta        = new ContaDAO().PesquisarContaPorNumero(contaId) as ContaCorrente;


            return(iC);
        }
Ejemplo n.º 11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            cc = Session["contaCorrente"] as ContaCorrente;
            if (cc == null)
            {
                Response.Redirect("~/Views/vwLogin.aspx");
            }
            iC           = Session["investimentoConta"] as InvestimentoConta;
            valorInicial = (float)(Session["investimentoConta"] as InvestimentoConta).Valor;

            if (iC == null)
            {
                Response.Redirect("~/Views/vwsContaCorrente.aspx");
            }

            if (!IsPostBack)
            {
                PreencherCampos();
                if (!iC.Resgatado)
                {
                    SimularInvestimento();
                }
            }
        }
Ejemplo n.º 12
0
        protected void btnEfetuar_Click(object sender, EventArgs e)
        {
            InvestimentoDAO   investimentoDao   = new InvestimentoDAO();
            Investimento      investimento      = investimentoDao.BuscarInvestimentoPorId(int.Parse(ddlInvestimentos.SelectedValue));
            InvestimentoConta investimentoConta = new InvestimentoConta()
            {
                Conta        = cc,
                Investimento = investimento,
                DataInicio   = DateTime.Parse(txtDataIni.Text),
                DataFim      = DateTime.Parse(txtDataFim.Text),
                Valor        = double.Parse(txtValorIni.Text, CultureInfo.InvariantCulture.NumberFormat)
            };

            if (investimentoDao.InserirInvestimento(investimentoConta) != null)
            {
                dadosSimulacaoBtn.Visible = false;
                lblResultado.Text         = "Investimento realizado com sucesso!";
            }
            else
            {
                lblResultado.Text = "Falha ao realizar investimento...";
            }
            AtualizaLabels();
        }
Ejemplo n.º 13
0
 public static InvestimentoConta AtualizaInvestimento(InvestimentoConta investimentoConta, double rentabilidadeAtual)
 {
     investimentoConta.Valor += investimentoConta.Valor * (rentabilidadeAtual / 100);
     return(investimentoConta);
 }
Ejemplo n.º 14
0
 public static InvestimentoConta AtualizaInvestimento(InvestimentoConta investimentoConta)
 {
     investimentoConta.Valor += investimentoConta.Valor * (investimentoConta.Investimento.Rentabilidade / 100);
     return(investimentoConta);
 }
Ejemplo n.º 15
0
        protected void BtnSimular_Click(object sender, EventArgs e)
        {
            lblResultado.Text = "";
            try
            {
                float valorIni = float.Parse(txtValorIni.Text, CultureInfo.InvariantCulture.NumberFormat);
                if (cc.Saldo >= valorIni)
                {
                    if (valorIni > 0)
                    {
                        if (DateTime.Parse(txtDataIni.Text) < DateTime.Parse(txtDataFim.Text))
                        {
                            if (DateTime.Parse(txtDataIni.Text) >= DateTime.Now.Date)
                            {
                                InvestimentoDAO investimentoDao = new InvestimentoDAO();
                                Investimento    investimento    = investimentoDao.BuscarInvestimentoPorId(int.Parse(ddlInvestimentos.SelectedValue));

                                InvestimentoConta investimentoConta = new InvestimentoConta()
                                {
                                    Conta        = cc,
                                    Investimento = investimento,
                                    DataInicio   = DateTime.Parse(txtDataIni.Text),
                                    DataFim      = DateTime.Parse(txtDataFim.Text),
                                    Valor        = valorIni
                                };

                                //investimentoDao.InserirInvestimento(investimentoConta);
                                txtValorFim.Text = "";

                                if (!investimento.PreFixada)
                                {
                                    txtValorFim.Text = "Aproximadamente ";
                                }

                                txtValorFim.Text         += investimentoDao.SimulaResgate(investimentoConta, DateTime.Parse(txtDataFim.Text)).ToString("c2");
                                dadosSimulacao.Visible    = true;
                                dadosSimulacaoBtn.Visible = true;
                                lblResultado.Text         = "";
                            }

                            else
                            {
                                lblResultado.Text = "Insira as datas de forma válida!";
                                txtValorFim.Text  = "";
                            }
                        }
                    }
                    else
                    {
                        lblResultado.Text = "O valor precisa ser maior que zero!";
                    }
                }
                else
                {
                    lblResultado.Text = "O valor não pode ser maior que o saldo!";
                }
            }
            catch
            {
                lblResultado.Text = "Entrada inválida!";
            }
        }
Ejemplo n.º 16
0
 public float SimulaResgate(InvestimentoConta investimentoConta, DateTime dataResgate)
 {
     return((float)InvestimentoOPS.Resgate(investimentoConta, dataResgate));
 }