Exemplo n.º 1
0
        public override bool execute( )
        {
            if (base.execute() == false)
            {
                return(false);
            }

            Registry("execute load_edu_emp_virtual ");

            /// USER [ execute ]

            StreamReader reader = new StreamReader(archive);

            T_Edu_EmpresaVirtual emp_virtual = new T_Edu_EmpresaVirtual(this);

            try
            {
                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine().Replace("'", "");

                    if (line == "")
                    {
                        continue;
                    }

                    var_util.indexCSV(line);

                    emp_virtual.set_st_nome(var_util.getCSV(0));
                    emp_virtual.set_st_codigo(var_util.getCSV(1));
                    emp_virtual.set_vr_valorAcao(10000);

                    emp_virtual.create_T_Edu_EmpresaVirtual();
                }
            }
            catch (System.Exception ex)
            {
                Registry(ex.ToString());
                reader.Close();

                return(false);
            }

            reader.Close();

            /// USER [ execute ] END

            Registry("execute done load_edu_emp_virtual ");

            return(true);
        }
Exemplo n.º 2
0
        public override bool execute( )
        {
            if (base.execute() == false)
            {
                return(false);
            }

            Registry("execute schedule_edu_fundo ");

            /// USER [ execute ]

            if (DateTime.Now.DayOfWeek == DayOfWeek.Saturday ||
                DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
            {
                return(true);
            }

            T_Edu_EmpresaVirtual virt     = new T_Edu_EmpresaVirtual(this);
            T_Edu_EmpresaVirtual virt_upd = new T_Edu_EmpresaVirtual(this);

            string dt_time = DateTime.Now.Year.ToString() + "-" +
                             DateTime.Now.Month.ToString().PadLeft(2, '0') + "-" +
                             DateTime.Now.Day.ToString().PadLeft(2, '0') + " 00:00:00";

            LOG_Edu_RendimentoEmpresa rend = new LOG_Edu_RendimentoEmpresa(this);

            if (virt.selectAll())
            {
                while (virt.fetch())
                {
                    bool web_Ok = false;

                    while (!web_Ok)
                    {
                        try
                        {
                            #region - busca valor de oscilação -

                            int    index   = 0;
                            string osc_web = "";

                            WebClient client = new WebClient();

                            string web = client.DownloadString("http://www.bovespa.com.br/Cotacoes2000/formCotacoesMobile.asp?codsocemi=" +
                                                               virt.get_st_codigo() +
                                                               "3");

                            client.Dispose();

                            Trace(web);

                            if (web.IndexOf("NUMERO_DO_ERRO") == -1)
                            {
                                index   = web.IndexOf("OSCILACAO=") + 11;
                                osc_web = web.Substring(index, 15);
                                osc_web = osc_web.Substring(0, osc_web.IndexOf(" ") - 1);
                            }
                            else
                            {
                                osc_web = "0,0000";
                            }

                            if (osc_web.IndexOf(",") == -1)
                            {
                                osc_web += ",0000";
                            }

                            index = osc_web.IndexOf(",") + 1;

                            int diff = osc_web.Length - index;

                            // força 4 casas após a virgula
                            if (diff < 4)
                            {
                                osc_web = osc_web.PadRight(4 - diff, '0');
                            }

                            #endregion

                            // pega valor inteiro, acrescenta 4 casas
                            double oscilacao = Convert.ToDouble(osc_web) * 10000;
                            // converte para string
                            string osc_rend = Convert.ToInt64(oscilacao).ToString();

                            if (osc_web.IndexOf("-") >= 0)
                            {
                                rend.set_tg_neg(Context.TRUE);
                            }
                            else
                            {
                                rend.set_tg_neg(Context.FALSE);
                            }

                            rend.set_vr_pct(osc_rend.Replace("-", ""));
                            rend.set_fk_empresaVirtual(virt.get_identity());
                            rend.set_dt_rend(dt_time);

                            rend.create_LOG_Edu_RendimentoEmpresa();

                            oscilacao /= 10000;
                            oscilacao /= 100;

                            virt_upd.selectIdentity(virt.get_identity());

                            long final_fundo = virt_upd.get_int_vr_valorAcao() + Convert.ToInt64(virt_upd.get_int_vr_valorAcao() * oscilacao);

                            virt_upd.set_vr_valorAcao(final_fundo.ToString());

                            virt_upd.synchronize_T_Edu_EmpresaVirtual();

                            web_Ok = true;
                        }
                        catch (System.Exception ex)
                        {
                            Registry(ex.ToString());

                            Thread.Sleep(250);

                            Registry("Trying again");
                        }
                    }
                }
            }

            // descobre o rank
            T_Cartao cart_rank = new T_Cartao(this);
            T_Cartao cart_upd  = new T_Cartao(this);

            LINK_Edu_FundoEmpresa lnk = new LINK_Edu_FundoEmpresa(this);
            T_Edu_EmpresaVirtual  emp = new T_Edu_EmpresaVirtual(this);

            if (cart_rank.select_rows_tipo(TipoCartao.educacional))
            {
                Hashtable hshVal = new Hashtable();
                ArrayList lstVal = new ArrayList();

                while (cart_rank.fetch())
                {
                    long invest_virtual = 0;

                    if (lnk.select_fk_cart(cart_rank.get_identity()))
                    {
                        while (lnk.fetch())
                        {
                            if (!emp.selectIdentity(lnk.get_fk_empresa()))
                            {
                                return(false);
                            }

                            invest_virtual += lnk.get_int_vr_fundo() * emp.get_int_vr_valorAcao();
                        }
                    }

                    if (invest_virtual > 0)
                    {
                        invest_virtual += cart_rank.get_int_vr_edu_disp_virtual();

                        lstVal.Add(invest_virtual);

                        if (hshVal [invest_virtual] == null)
                        {
                            hshVal [invest_virtual] = new ArrayList();
                        }

                        ArrayList tmp = hshVal [invest_virtual] as ArrayList;

                        tmp.Add(cart_rank.get_identity());
                    }
                }

                lstVal.Sort();

                for (int t = lstVal.Count - 1, rank = 1; t >= 0; --t, ++rank)
                {
                    ArrayList tmp = hshVal [(long)lstVal[t]] as ArrayList;

                    for (int y = 0; y < tmp.Count; ++y)
                    {
                        string ident = tmp [y].ToString();

                        cart_upd.ExclusiveAccess();
                        cart_upd.selectIdentity(ident);

                        cart_upd.set_nu_rankVirtual(rank.ToString());
                        cart_upd.set_vr_edu_total_ranking(lstVal[t].ToString());

                        cart_upd.synchronize_T_Cartao();
                        cart_upd.ReleaseExclusive();
                    }
                }
            }

            /// USER [ execute ] END

            Registry("execute done schedule_edu_fundo ");

            return(true);
        }
Exemplo n.º 3
0
        public override bool execute( )
        {
            Registry("execute web_fetch_edu_virtual ");

            /// USER [ execute ]

            input_st_cartao = input_st_cartao.PadLeft(14, '0');
            input_dt_mov    = input_dt_mov.Substring(0, 11) + "00:00:00";

            T_Cartao cart = new T_Cartao(this);

            if (!cart.select_rows_tudo(input_st_cartao.Substring(0, 6),
                                       input_st_cartao.Substring(6, 6),
                                       input_st_cartao.Substring(12, 2)))
            {
                PublishError("Cartão inválido");
                return(false);
            }

            if (!cart.fetch())
            {
                return(false);
            }

            if (cart.get_st_senha() != input_st_senha)
            {
                PublishError("Senha aluno inválida");
                return(false);
            }

            output_cont_dce.set_st_aluno(cart.get_st_aluno());
            output_cont_dce.set_vr_diario(cart.get_vr_edu_diario());
            output_cont_dce.set_vr_disp(cart.get_vr_disp_educacional());
            output_cont_dce.set_vr_depot(cart.get_vr_educacional());
            output_cont_dce.set_vr_disp_virtual(cart.get_vr_edu_disp_virtual());
            output_cont_dce.set_nu_vrRank(cart.get_nu_rankVirtual());

            long invest_virtual = 0;

            LINK_Edu_FundoEmpresa     lnk      = new LINK_Edu_FundoEmpresa(this);
            T_Edu_EmpresaVirtual      emp      = new T_Edu_EmpresaVirtual(this);
            LOG_Edu_RendimentoEmpresa log_rend = new LOG_Edu_RendimentoEmpresa(this);

            T_Edu_AplicacaoVirtual app = new T_Edu_AplicacaoVirtual(this);

            if (lnk.select_fk_cart(cart.get_identity()))
            {
                while (lnk.fetch())
                {
                    DadosMovEmpresaVirtual dMovAtual = new DadosMovEmpresaVirtual();

                    if (!emp.selectIdentity(lnk.get_fk_empresa()))
                    {
                        return(false);
                    }

                    dMovAtual.set_st_nome(emp.get_st_nome());
                    dMovAtual.set_vr_acoes(lnk.get_vr_fundo());
                    dMovAtual.set_vr_dia(emp.get_vr_valorAcao());

                    invest_virtual += lnk.get_int_vr_fundo() * emp.get_int_vr_valorAcao();

                    if (log_rend.select_rows_date(GetDataBaseTime(), emp.get_identity()))
                    {
                        if (!log_rend.fetch())
                        {
                            return(false);
                        }

                        if (log_rend.get_tg_neg() == Context.TRUE)
                        {
                            dMovAtual.set_vr_osc("-" + log_rend.get_vr_pct());
                        }
                        else
                        {
                            dMovAtual.set_vr_osc(log_rend.get_vr_pct());
                        }
                    }

                    //  busca preço médio
                    long preco_medio = 0;

                    if (app.select_rows_cart_emp(cart.get_identity(), emp.get_identity()))
                    {
                        while (app.fetch())
                        {
                            preco_medio += app.get_int_vr_preco_fundo();
                        }

                        preco_medio = preco_medio / app.RowCount();

                        app.Reset();
                    }

                    dMovAtual.set_vr_preco_medio(preco_medio.ToString());

                    output_array_generic_lstEmp.Add(dMovAtual);
                }
            }

            if (lnk.select_fk_cart(cart.get_identity()))
            {
                while (lnk.fetch())
                {
                    if (!emp.selectIdentity(lnk.get_fk_empresa()))
                    {
                        return(false);
                    }

                    long aplic = 0;

                    if (app.select_rows_date(input_dt_mov, cart.get_identity()))
                    {
                        while (app.fetch())
                        {
                            if (app.get_fk_empresaVirtual() != lnk.get_fk_empresa())
                            {
                                continue;
                            }

                            DadosMovEmpresaVirtual dMov = new DadosMovEmpresaVirtual();

                            dMov.set_st_nome(emp.get_st_nome());

                            if (app.get_tg_neg() == Context.TRUE)
                            {
                                dMov.set_vr_mov_fundo("-" + app.get_vr_aplicado());
                                aplic -= app.get_int_vr_aplicado();

                                dMov.set_vr_total((Convert.ToInt64(app.get_vr_fundo_hora()) -
                                                   Convert.ToInt64(app.get_vr_aplicado())).ToString());
                            }
                            else
                            {
                                dMov.set_vr_mov_fundo(app.get_vr_aplicado());
                                aplic += app.get_int_vr_aplicado();

                                dMov.set_vr_total((Convert.ToInt64(app.get_vr_fundo_hora()) +
                                                   Convert.ToInt64(app.get_vr_aplicado())).ToString());
                            }

                            output_array_generic_lst.Add(dMov);
                        }
                    }
                }
            }

            output_cont_dce.set_vr_invest_virtual(invest_virtual.ToString());

            /// USER [ execute ] END

            Registry("execute done web_fetch_edu_virtual ");

            return(true);
        }
        public override bool execute( )
        {
            Registry("execute web_fetch_edu_emp_hist ");

            /// USER [ execute ]

            StringBuilder sb = new StringBuilder();

            LOG_Edu_RendimentoEmpresa rend_emp = new LOG_Edu_RendimentoEmpresa(this);
            T_Edu_EmpresaVirtual      emp      = new T_Edu_EmpresaVirtual(this);

            if (!emp.select_rows_codigo(input_st_codigo))
            {
                PublishError("Código inválido");
                return(false);
            }

            if (!emp.fetch())
            {
                return(false);
            }

            for (int t = 0; t < 31; ++t)
            {
                DateTime tim = DateTime.Now.AddDays(-t);

                string dt_dia = tim.Year.ToString() + "-" +
                                tim.Month.ToString().PadLeft(2, '0') + "-" +
                                tim.Day.ToString().PadLeft(2, '0') + " 00:00:00";

                if (rend_emp.select_rows_date(dt_dia, emp.get_identity()))
                {
                    if (!rend_emp.fetch())
                    {
                        return(false);
                    }

                    DadosMovEmpresaVirtual mov = new DadosMovEmpresaVirtual();

                    if (rend_emp.get_tg_neg() == Context.TRUE)
                    {
                        mov.set_vr_osc("-" + rend_emp.get_vr_pct());
                    }
                    else
                    {
                        mov.set_vr_osc(rend_emp.get_vr_pct());
                    }

                    mov.set_dt_dia(dt_dia);
                    mov.set_st_nome(emp.get_st_nome());

                    DataPortable mem = mov as DataPortable;

                    string index = MemorySave(ref mem);

                    sb.Append(index);
                    sb.Append(",");
                }
            }

            output_st_csv = sb.ToString().TrimEnd(',');

            /// USER [ execute ] END

            Registry("execute done web_fetch_edu_emp_hist ");

            return(true);
        }
Exemplo n.º 5
0
 public void copy(ref T_Edu_EmpresaVirtual cpy)
 {
     st_nome      = cpy.st_nome;
     st_codigo    = cpy.st_codigo;
     vr_valorAcao = cpy.vr_valorAcao;
 }
Exemplo n.º 6
0
        public override bool execute( )
        {
            Registry("execute web_exec_edu_aplic_fundo ");

            /// USER [ execute ]

            #region - busca cartao e empresa -

            input_st_cartao = input_st_cartao.PadLeft(14, '0');

            T_Cartao cart = new T_Cartao(this);

            cart.ExclusiveAccess();

            if (!cart.select_rows_tudo(input_st_cartao.Substring(0, 6),
                                       input_st_cartao.Substring(6, 6),
                                       input_st_cartao.Substring(12, 2)))
            {
                PublishError("Cartão inválido");
                return(false);
            }

            if (!cart.fetch())
            {
                return(false);
            }

            if (cart.get_st_senha() != input_st_senha)
            {
                PublishError("Senha aluno inválida");
                return(false);
            }

            T_Edu_EmpresaVirtual emp = new T_Edu_EmpresaVirtual(this);

            if (!emp.select_rows_codigo(input_st_codigo))
            {
                PublishError("Código inválido");
                return(false);
            }

            if (!emp.fetch())
            {
                return(false);
            }

            #endregion

            long val       = Convert.ToInt64(input_st_valor);                           // valor requerido
            long val_emp   = emp.get_int_vr_valorAcao();                                // valor da empresa
            long val_acoes = Convert.ToInt64(val / val_emp);                            // arrendonda para numro de acoes
            long val_din   = val_acoes * emp.get_int_vr_valorAcao();                    // valor real de compra
            long val_max   = (val_acoes - 1) * emp.get_int_vr_valorAcao();
            long virt_calc = cart.get_int_vr_edu_disp_virtual() - val_din - 25;

            if (val_acoes == 0)
            {
                PublishError("Valor mínimo de compra: " + new money().setMoneyFormat(val_emp));
                return(false);
            }

            if (virt_calc < 0)
            {
                // pegar maximo valor possível

                long max_virt_calc = cart.get_int_vr_edu_disp_virtual() - 25;
                long max_val_acoes = Convert.ToInt64(max_virt_calc / val_emp);
                long max_val_din   = max_val_acoes * emp.get_int_vr_valorAcao();

                PublishError("Valor máximo " + new money().setMoneyFormat(max_val_din) + " excedido");
                return(false);
            }

            T_Edu_AplicacaoVirtual app = new T_Edu_AplicacaoVirtual(this);

            app.set_vr_preco_fundo(emp.get_vr_valorAcao());

            app.set_dt_aplic(DateTime.Now.Year.ToString() + "-" +
                             DateTime.Now.Month.ToString().PadLeft(2, '0') + "-" +
                             DateTime.Now.Day.ToString().PadLeft(2, '0') +
                             " 00:00:00");

            app.set_fk_cartao(cart.get_identity());
            app.set_fk_empresaVirtual(emp.get_identity());

            if (val < 0)
            {
                app.set_tg_neg(Context.TRUE);
            }
            else
            {
                app.set_tg_neg(Context.FALSE);
            }

            app.set_vr_aplicado(val_acoes.ToString().Replace("-", ""));

            LINK_Edu_FundoEmpresa lnk_fundo = new LINK_Edu_FundoEmpresa(this);

            lnk_fundo.ExclusiveAccess();

            if (!lnk_fundo.select_fk_cart_emp(cart.get_identity(), emp.get_identity()))
            {
                app.set_vr_fundo_hora("0");

                if (val <= 0)
                {
                    PublishError("Sem fundos disponíveis para venda");
                    return(false);
                }

                lnk_fundo.set_fk_cartao(cart.get_identity());
                lnk_fundo.set_fk_empresa(emp.get_identity());
                lnk_fundo.set_vr_fundo(val_acoes.ToString());

                if (!lnk_fundo.create_LINK_Edu_FundoEmpresa())
                {
                    return(false);
                }
            }
            else
            {
                if (!lnk_fundo.fetch())
                {
                    return(false);
                }

                long val_final = lnk_fundo.get_int_vr_fundo() + val_acoes;

                app.set_vr_fundo_hora(lnk_fundo.get_vr_fundo());

                if (val_final < 0)
                {
                    PublishError("Valor de resgate superior ao fundo");
                    return(false);
                }

                lnk_fundo.set_vr_fundo(val_final.ToString());

                if (!lnk_fundo.synchronize_LINK_Edu_FundoEmpresa())
                {
                    return(false);
                }
            }

            if (!app.create_T_Edu_AplicacaoVirtual())
            {
                return(false);
            }

            cart.set_vr_edu_disp_virtual(virt_calc.ToString());

            if (!cart.synchronize_T_Cartao())
            {
                return(false);
            }

            /// USER [ execute ] END

            Registry("execute done web_exec_edu_aplic_fundo ");

            return(true);
        }