Beispiel #1
0
        public override bool execute( )
        {
            if (base.execute() == false)
            {
                return(false);
            }

            Registry("execute fetch_termLoja ");

            /// USER [ execute ]

            T_Terminal term = new T_Terminal(this);

            if (!term.select_fk_loja(loj.get_identity()))
            {
                PublishError("Nenhum terminal cadastrado para a loja");
                return(false);
            }

            while (term.fetch())
            {
                DadosTerminal dt = new DadosTerminal();

                dt.set_st_terminal(term.get_nu_terminal());
                dt.set_st_localizacao(term.get_st_localizacao());

                output_array_generic_lst.Add(dt);
            }

            /// USER [ execute ] END

            Registry("execute done fetch_termLoja ");

            return(true);
        }
Beispiel #2
0
        public override bool authenticate( )
        {
            if (base.authenticate() == false)
            {
                return(false);
            }

            Registry("authenticate fetch_terminalLoja ");

            /// USER [ authenticate ]

            loj = new T_Loja(this);

            if (!loj.select_rows_loja(input_st_cnpj_loja))
            {
                PublishError("Loja inexistente");
                return(false);
            }

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

            term = new T_Terminal(this);

            if (!term.select_fk_loja(loj.get_identity()))
            {
                PublishError("Nenhum terminal cadastrado para esta loja");
                return(false);
            }

            /// USER [ authenticate ] END

            Registry("authenticate done fetch_terminalLoja ");

            return(true);
        }
Beispiel #3
0
        public override bool authenticate( )
        {
            if (base.authenticate() == false)
            {
                return(false);
            }

            Registry("authenticate del_Terminal ");

            /// USER [ authenticate ]

            loj = new T_Loja(this);

            if (!loj.select_rows_cnpj(input_st_loja_cnpj))
            {
                PublishError("Loja não cadastrada");
                return(false);
            }

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

            term = new T_Terminal(this);

            if (!term.select_fk_loja(loj.get_identity()))
            {
                return(false);
            }

            /// USER [ authenticate ] END

            Registry("authenticate done del_Terminal ");

            return(true);
        }
        public override bool execute( )
        {
            if (base.execute() == false)
            {
                return(false);
            }

            Registry("execute exec_vincula_lojista ");

            /// USER [ execute ]

            T_Loja loj = new T_Loja(this);

            if (!loj.select_rows_loja(input_st_cod_loja))
            {
                PublishError("loja inexistente");
                return(false);
            }

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

            T_Usuario lojista = new T_Usuario(this);

            if (!lojista.selectIdentity(input_id_usuario))
            {
                PublishError("Usuário inexistente");
                return(false);
            }

            if (lojista.get_tg_nivel() != TipoUsuario.Lojista)
            {
                PublishError("Usuário incorreto");
                return(false);
            }

            T_Terminal term = new T_Terminal(this);

            if (!term.select_fk_loja(loj.get_identity()))
            {
                PublishError("Loja não possui terminais");
                return(false);
            }

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

            LINK_UsuarioTerminal lut = new LINK_UsuarioTerminal(this);

            if (lut.select_fk_user(lojista.get_identity()))
            {
                PublishError("Usuário já possui terminal");
                return(false);
            }

            lut.set_fk_term(term.get_identity());
            lut.set_fk_user(lojista.get_identity());

            if (!lut.create_LINK_UsuarioTerminal())
            {
                return(false);
            }

            PublishNote("Lojista vinculado ao seu terminal com sucesso");

            /// USER [ execute ] END

            Registry("execute done exec_vincula_lojista ");

            return(true);
        }
        public override bool execute( )
        {
            if (base.execute() == false)
            {
                return(false);
            }

            Registry("execute fetch_rel_listaLojas ");

            /// USER [ execute ]

            T_Empresa emp = new T_Empresa(this);

            if (!emp.select_rows_empresa(input_emp))
            {
                PublishError("Empresa " + input_emp + " não disponível");
                return(false);
            }

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

            output_nome_emp = emp.get_st_fantasia();

            LINK_LojaEmpresa loj_emp = new LINK_LojaEmpresa(this);

            if (!loj_emp.select_fk_empresa_geral(emp.get_identity()))
            {
                PublishError("Nenhuma loja cadastrada");
                return(false);
            }

            T_Loja     loj  = new T_Loja(this);
            T_Terminal term = new T_Terminal(this);

            StringBuilder sb = new StringBuilder();

            while (loj_emp.fetch())
            {
                if (!loj.selectIdentity(loj_emp.get_fk_loja()))
                {
                    continue;
                }

                if (!term.select_fk_loja(loj.get_identity()))
                {
                    continue;
                }

                DataPortable port = new DataPortable();

                port.setValue("cod", loj.get_st_loja());
                port.setValue("nome", loj.get_st_nome() + " - " + loj.get_st_social());
                port.setValue("tel", loj.get_nu_telefone());
                port.setValue("cid", loj.get_st_cidade());
                port.setValue("est", loj.get_st_estado());
                port.setValue("term", term.RowCount().ToString());
                port.setValue("cnpj", loj.get_nu_CNPJ());
                port.setValue("drep", loj_emp.get_nu_dias_repasse());
                port.setValue("prep", loj_emp.get_tx_admin().PadLeft(4, '0').Insert(2, ",") + " %");

                sb.Append(MemorySave(ref port));
                sb.Append(",");
            }

            string list_ids = sb.ToString().TrimEnd(',');

            DataPortable dp = new DataPortable();

            dp.setValue("ids", list_ids);

            // ## obtem indice geral

            output_id = MemorySave(ref dp);

            /// USER [ execute ] END

            Registry("execute done fetch_rel_listaLojas ");

            return(true);
        }
        public override bool authenticate( )
        {
            Registry("authenticate exec_pos_vendaEmpresarialSITEF ");

            /// USER [ authenticate ]

            cart  = new T_Cartao(this);
            emp   = new T_Empresa(this);
            l_nsu = new LOG_NSU(this);
            info  = new T_InfoAdicionais(this);
            prot  = new T_Proprietario(this);
            loj   = new T_Loja(this);

            // Default é erro genérico
            var_codResp = "9999";

            // Normal
            var_nu_nsuAtual    = Context.NONE;
            var_nu_nsuEntidade = Context.NONE;

            // Cancelamento
            var_nu_nsuOrig    = Context.NONE;
            var_nu_nsuEntOrig = Context.NONE;

            // Valores básicos de comércio
            var_vr_total    = input_cont_pe.get_vr_valor();
            var_nu_parcelas = input_cont_pe.get_nu_parcelas();

            var_codResp = "0606";

            // alterado

            #region - valida loja AO INVES DE TERMINAL (antigo) -

            // ## Busca terminal pelo seu código

            // pega os 7 ultimos
            if (!loj.select_rows_loja(input_cont_pe.get_st_terminal().Substring(1).TrimStart('0')))
            {
                output_st_msg = "Loja inexistente";
                var_codResp   = "0303";
                return(false);
            }

            if (!loj.fetch())
            {
                output_st_msg = "Erro aplicativo";
                return(false);
            }

            // alterado!
            // busca o primeiro terminal vinculado

            if (!term.select_fk_loja(loj.get_identity()))
            {
                output_st_msg = "Erro do terminal";
                return(false);
            }

            term.fetch();

            #endregion

            // continua igual

            #region - valida empresa -

            // ## Busca empresa informada

            if (!emp.select_rows_empresa(input_cont_pe.get_st_empresa()))
            {
                output_st_msg = "Empresa inexistente";
                var_codResp   = "0303";
                return(false);
            }

            if (!emp.fetch())
            {
                output_st_msg = "Erro de aplicativo";
                return(false);
            }

            // ## Caso empresa bloqueada, sair

            if (emp.get_tg_bloq() == Context.TRUE)
            {
                output_st_msg = "Empresa bloqueada";
                var_codResp   = "0303";
                return(false);
            }

            #endregion

            // alterado!

            #region - valida relação da Loja do Terminal com Empresa (Convênio)

            LINK_LojaEmpresa loj_emp = new LINK_LojaEmpresa(this);

            if (!loj_emp.select_fk_empresa_loja(emp.get_identity(), loj.get_identity()))
            {
                output_st_msg = "Loja não conveniada";
                var_codResp   = "0303";
                return(false);
            }

            if (loj.get_tg_blocked() == Context.TRUE)
            {
                output_st_msg = "Loja bloqueada";
                var_codResp   = "0303";
                return(false);
            }

            if (loj.get_tg_cancel() == Context.TRUE)
            {
                output_st_msg = "Loja cancelada";
                var_codResp   = "0303";
                return(false);
            }

            #endregion

            // continua igual

            #region - valida cartão -

            if (!cart.select_rows_tudo(input_cont_pe.get_st_empresa(),
                                       input_cont_pe.get_st_matricula(),
                                       input_cont_pe.get_st_titularidade()))
            {
                output_st_msg = "Cartão inexistente";
                var_codResp   = "0606";
                return(false);
            }

            if (!cart.fetch())
            {
                output_st_msg = "Erro aplicativo";
                return(false);
            }

            // ## Verifica bloqueio

            if (cart.get_tg_status() == CartaoStatus.Bloqueado)
            {
                output_st_msg = "Cartão inválido";
                var_codResp   = "0505";
                return(false);
            }

            if (cart.get_tg_emitido() != StatusExpedicao.Expedido)
            {
                output_st_msg = "Cartão inválido";
                var_codResp   = "0505";
                return(false);
            }

            if (cart.get_tg_tipoCartao() == TipoCartao.educacional)
            {
                // ## No caso educacional, permitir somente venda
                // ## em uma parcela

                if (input_cont_pe.get_nu_parcelas().TrimStart('0') != "1")
                {
                    output_st_msg = "Somente uma parcela";
                    var_codResp   = "0606";
                    return(false);
                }
            }

            // ## Conferir vencto do cartão

            /*
             * if ( cart.get_tg_tipoCartao() == TipoCartao.empresarial )
             * {
             *      int year  = 2000 + Convert.ToInt32 ( cart.get_st_venctoCartao().Substring ( 2,2 ) );
             *      int month = Convert.ToInt32 ( cart.get_st_venctoCartao().Substring ( 0,2 ) );
             *      int day   = 1;
             *
             * DateTime tim_venc = new DateTime ( year, month, day );
             *
             * if ( tim_venc < DateTime.Now )
             *      {
             * output_st_msg     = "Cartão vencido";
             * var_codResp       = "7676";
             * return false;
             *      }
             * }
             */

            #endregion

            var_vr_total    = input_cont_pe.get_vr_valor();
            var_nu_parcelas = input_cont_pe.get_nu_parcelas();

            SQL_LOGGING_ENABLE = false;

            // continua igual

            #region - Verifica disponivel mensal nas parcelas -

            T_Parcelas parc = new T_Parcelas(this);

            string myId = cart.get_identity();

            if (cart.get_st_titularidade() != "01")
            {
                cart.select_rows_tudo(cart.get_st_empresa(),
                                      cart.get_st_matricula(),
                                      "01");
                cart.fetch();
            }

            vr_dispMes = cart.get_int_vr_limiteMensal() + cart.get_int_vr_extraCota();
            vr_dispTot = cart.get_int_vr_limiteTotal() + cart.get_int_vr_extraCota();

            vr_valor = Convert.ToInt64(input_cont_pe.get_vr_valor());

            if (cart.get_tg_tipoCartao() != TipoCartao.presente)
            {
                new ApplicationUtil().GetSaldoDisponivel(ref cart, ref vr_dispMes, ref vr_dispTot);

                int tmp_nu_parc = Convert.ToInt32(input_cont_pe.get_nu_parcelas());

                if (tmp_nu_parc > 1)
                {
                    if (vr_valor > vr_dispTot)
                    {
                        output_st_msg = "limite excedido";
                        var_codResp   = "2727";

                        SQL_LOGGING_ENABLE = true;

                        return(false);
                    }

                    LOG_Transacoes ltr     = new LOG_Transacoes(this);
                    T_Parcelas     parcTot = new T_Parcelas(this);

                    string tmp = input_cont_pe.get_st_valores();

                    ArrayList lstCartoes = new ArrayList();

                    T_Cartao c_t = new T_Cartao(this);

                    c_t.select_rows_empresa_matricula(cart.get_st_empresa(),
                                                      cart.get_st_matricula());

                    while (c_t.fetch())
                    {
                        lstCartoes.Add(c_t.get_identity());
                    }

                    for (int t = 1, index_pos = 0; t <= tmp_nu_parc; ++t)
                    {
                        long valor_unit_parc = Convert.ToInt64(tmp.Substring(index_pos, 12));

                        index_pos += 12;

                        if (valor_unit_parc > cart.get_int_vr_limiteMensal())
                        {
                            output_st_msg = "limite excedido";
                            var_codResp   = "2727";

                            SQL_LOGGING_ENABLE = true;

                            return(false);
                        }

                        long dispMesParc = cart.get_int_vr_limiteMensal();

                        // Verifica disponivel mensal nas parcelas
                        if (parcTot.select_rows_cartao_mensal(ref lstCartoes, t.ToString()))                              // este mês
                        {
                            while (parcTot.fetch())
                            {
                                if (ltr.selectIdentity(parcTot.get_fk_log_transacoes()))                                      // busca transação
                                {
                                    if (ltr.get_tg_confirmada() == TipoConfirmacao.Confirmada ||
                                        ltr.get_tg_confirmada() == TipoConfirmacao.Pendente)
                                    {
                                        dispMesParc -= parcTot.get_int_vr_valor();
                                    }
                                }
                            }
                        }

                        if (valor_unit_parc > dispMesParc)
                        {
                            output_st_msg = "limite excedido";
                            var_codResp   = "2727";

                            SQL_LOGGING_ENABLE = true;

                            return(false);
                        }
                    }
                }
                else
                {
                    if (vr_valor > vr_dispMes || vr_valor > vr_dispTot)
                    {
                        output_st_msg = "limite excedido";
                        var_codResp   = "2727";

                        SQL_LOGGING_ENABLE = true;

                        return(false);
                    }
                }
            }
            else
            {
                if (vr_valor > cart.get_int_vr_limiteTotal())
                {
                    output_st_msg = "limite excedido";
                    var_codResp   = "2727";

                    SQL_LOGGING_ENABLE = true;

                    return(false);
                }
            }

            if (myId != cart.get_identity())
            {
                // restaurar cartão dep
                cart.selectIdentity(myId);
            }

            #endregion

            SQL_LOGGING_ENABLE = true;

            /// USER [ authenticate ] END

            Registry("authenticate done exec_pos_vendaEmpresarialSITEF ");

            return(true);
        }
Beispiel #7
0
        public override bool execute( )
        {
            Registry("execute exec_login ");

            /// USER [ execute ]

            output_tg_trocaSenha = Context.FALSE;

            user = new T_Usuario(this);

            user.ExclusiveAccess();

            // ## Busca usuário com nome e cód de empresa

            if (loginLojista)
            {
                string st_loja = input_st_empresa.Replace("L", "");

                T_Loja loj = new T_Loja(this);

                if (!loj.select_rows_loja(st_loja))
                {
                    PublishError("Usuário ou senha incorretos");
                    return(false);
                }

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

                T_Terminal term = new T_Terminal(this);

                if (!term.select_fk_loja(loj.get_identity()))
                {
                    PublishError("Usuário ou senha incorretos");
                    return(false);
                }

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

                LINK_UsuarioTerminal lut = new LINK_UsuarioTerminal(this);

                if (!lut.select_fk_term(term.get_identity()))
                {
                    PublishError("Usuário ou senha incorretos");
                    return(false);
                }

                bool found = false;

                T_Usuario usr_lojista = new T_Usuario(this);

                while (lut.fetch())
                {
                    if (!usr_lojista.selectIdentity(lut.get_fk_user()))
                    {
                        return(false);
                    }

                    Trace(usr_lojista.get_st_nome());

                    if (usr_lojista.get_st_nome() == input_st_nome)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    PublishError("Usuário ou senha incorretos");
                    return(false);
                }

                if (!user.selectIdentity(usr_lojista.get_identity()))
                {
                    return(false);
                }

                input_st_empresa = st_loja;

                output_cont_header.set_nu_terminal(term.get_nu_terminal());
            }
            else
            {
                if (!user.select_rows_login(input_st_nome, input_st_empresa))
                {
                    PublishError("Usuário ou senha incorretos");
                    return(false);
                }

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

            // ## Confere bloqueio

            if (user.get_tg_bloqueio() != Context.FALSE)
            {
                PublishError("Usuário ou senha incorretos");
                return(false);
            }

            // ## Confere senha

            if (user.get_st_senha() != input_st_senha)
            {
                user.set_nu_senhaErrada(Convert.ToString(user.get_int_nu_senhaErrada() + 1));

                if (user.get_int_nu_senhaErrada() >= 3)
                {
                    // ## Na terceira senha errada, bloqueia cartão

                    //user.set_tg_bloqueio      ( Context.TRUE  );
                    //user.set_nu_senhaErrada   (  0            );
                }

                // ## Atualiza

                if (!user.synchronize_T_Usuario())
                {
                    return(false);
                }

                PublishError("Usuário ou senha incorretos");
                return(false);
            }
            else
            {
                // ## Zera senhas erradas

                ut_coverMark(1);

                user.set_nu_senhaErrada(0);
            }

            // ## Caso o ultimo logoff não foi executado, ou seja,
            // ## o usuário não fechou corretamente sua última instância

            if (user.get_tg_logoff() == Context.FALSE)
            {
                // ## Mais de cinco minutos se passaram...

                if (TimeSpanCtrl(user.get_dt_ultUso(),
                                 TSpan_Mode.MORE_THAN,
                                 5,
                                 TSpan_Range.Minutes) == true)
                {
                    PublishNote("Disconectando sessão ociosa por mais de cinco minutos");
                }
                else
                {
                    PublishError("Não são permitidas multiplas sessões");
                    return(false);
                }
            }

            // ## Seto que o logoff precisa ser feito

            user.set_tg_logoff(Context.FALSE);

            // ## Confere se senha expirou...

            if (TimeSpanCtrl(user.get_dt_trocaSenha(),
                             TSpan_Mode.MORE_THAN,
                             60,
                             TSpan_Range.Days) == true)
            {
                output_tg_trocaSenha = Context.TRUE;

                PublishNote("É necessário trocar sua senha");
            }

            // ## Confere se admin requisitou troca de senha

            if (user.get_tg_trocaSenha() == Context.TRUE)
            {
                output_tg_trocaSenha = Context.TRUE;

                PublishNote("É necessário trocar sua senha");
            }

            // ## Seto login feito agora

            user.set_dt_ultUso(GetDataBaseTime());

            // ## Atualizo usuário

            if (!user.synchronize_T_Usuario())
            {
                return(false);
            }

            output_cont_header.set_st_session(var_SessionKey);
            output_cont_header.set_st_empresa(input_st_empresa);
            output_cont_header.set_st_user_id(user.get_identity());
            output_cont_header.set_tg_user_type(user.get_tg_nivel());

            /// USER [ execute ] END

            Registry("execute done exec_login ");

            return(true);
        }
        public override bool execute( )
        {
            if (base.execute() == false)
            {
                return(false);
            }

            Registry("execute fetch_consultaLojasGift ");

            /// USER [ execute ]

            input_st_empresa = input_st_empresa.PadLeft(6, '0');

            T_Empresa emp = new T_Empresa(this);

            if (!emp.select_rows_empresa(input_st_empresa))
            {
                PublishError("Empresa não disponível");
                return(false);
            }

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

            LINK_LojaEmpresa lje  = new LINK_LojaEmpresa(this);
            T_Loja           loj  = new T_Loja(this);
            T_Terminal       term = new T_Terminal(this);

            StringBuilder sb = new StringBuilder();

            ArrayList lstSort = new ArrayList();

            if (lje.select_fk_empresa_geral(emp.get_identity()))
            {
                SQL_LOGGING_ENABLE = false;

                while (lje.fetch())
                {
                    if (loj.selectIdentity(lje.get_fk_loja()))
                    {
                        lstSort.Add(loj.get_st_nome());
                    }
                }

                lstSort.Sort();

                for (int t = 0; t < lstSort.Count; ++t)
                {
                    string nome_loja = lstSort[t].ToString();

                    if (loj.select_rows_nome(nome_loja))
                    {
                        if (loj.fetch())
                        {
                            if (!term.select_fk_loja(loj.get_identity()))
                            {
                                return(false);
                            }

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

                            DadosLoja dl = new DadosLoja();

                            dl.set_st_nome(loj.get_st_nome() + " - " + loj.get_st_social());
                            dl.set_st_obs(term.get_nu_terminal());

                            DataPortable tmp = dl as DataPortable;

                            // ## obtem indexador

                            sb.Append(MemorySave(ref tmp));
                            sb.Append(",");
                        }
                    }
                }

                SQL_LOGGING_ENABLE = true;
            }

            string list_ids = sb.ToString().TrimEnd(',');

            if (list_ids == "")
            {
                PublishNote("Nenhum resultado foi encontrado");
                return(true);
            }

            DataPortable dp = new DataPortable();

            dp.setValue("ids", list_ids);

            // ## Obtem indexador geral

            output_st_csv_id = MemorySave(ref dp);

            /// USER [ execute ] END

            Registry("execute done fetch_consultaLojasGift ");

            return(true);
        }
        public override bool execute( )
        {
            if (base.execute() == false)
            {
                return(false);
            }

            Registry("execute fetch_pf_telefoneLojista ");

            /// USER [ execute ]

            // ## Obtem loja por código

            T_Loja loj = new T_Loja(this);

            if (loj.select_rows_loja(input_st_loja))
            {
                if (!loj.fetch())
                {
                    return(false);
                }

                // ## Obtem terminais vinculados

                T_Terminal term = new T_Terminal(this);

                if (term.select_fk_loja(loj.get_identity()))
                {
                    T_PayFone pf = new T_PayFone(this);

                    // ## Para todos os terminais

                    while (term.fetch())
                    {
                        // ## busca payfone

                        if (pf.select_fk_term(term.get_identity()))
                        {
                            // ## para todos os registros

                            while (pf.fetch())
                            {
                                // ## somente lojista

                                if (pf.get_tg_tipoCelular() == TipoCelular.LOJA)
                                {
                                    // ## Achou telefone

                                    output_st_telefone = pf.get_st_telefone();
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }

            ///
            /// USER [ execute ] END

            Registry("execute done fetch_pf_telefoneLojista ");

            return(true);
        }
        public override bool execute( )
        {
            if (base.execute() == false)
            {
                return(false);
            }

            Registry("execute fetch_consultaLoja ");

            /// USER [ execute ]

            T_Terminal term = new T_Terminal(this);

            // ## Obtem filtros da entrada

            string nome   = input_cont_dcl.get_st_nome().ToUpper(),
                   cidade = input_cont_dcl.get_st_cidade(),
                   estado = input_cont_dcl.get_st_estado(),
                   codigo = input_cont_dcl.get_st_loja();

            long min_qtd = 0;

            if (input_cont_dcl.get_nu_qtd_term().Length > 0)
            {
                min_qtd = Convert.ToInt32(input_cont_dcl.get_nu_qtd_term());
            }

            long memory = Convert.ToInt64(new InstallData().maxPacket) / 360;

            Hashtable hshLojas = new Hashtable();

            #region - lojas para um determinado administrador -

            if (user.get_tg_nivel() == TipoUsuario.Administrador)
            {
                if (!emp.select_rows_empresa(user.get_st_empresa()))
                {
                    PublishError("CNPJ de empresa inválido");
                    return(false);
                }

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

                LINK_LojaEmpresa lnk = new LINK_LojaEmpresa(this);

                if (lnk.select_fk_empresa_geral(emp.get_identity()))
                {
                    while (lnk.fetch())
                    {
                        hshLojas [lnk.get_fk_loja()] = "*";
                    }
                }
            }

            #endregion

            bool bNome = false;

            if (nome.Length > 0)
            {
                bNome = true;
            }

            bool bCod = false;

            if (codigo.Length > 0)
            {
                bCod = true;
            }

            ArrayList lstSortLojas = new ArrayList();
            Hashtable hshSortLojas = new Hashtable();

            LINK_LojaEmpresa loj_emp_conv = new LINK_LojaEmpresa(this);
            T_Empresa        emp_comp     = new T_Empresa(this);

            // ## Loop diferente para ambos os tipos de consulta
            // ## em um só bloco

            for (;;)
            {
                if (IsEmpresa)
                {
                    // ## Busca do relacionamento loja e empresa

                    if (!loj_emp.fetch())
                    {
                        break;
                    }

                    // ## Se loja não existir, sair

                    if (!loj.selectIdentity(loj_emp.get_fk_loja()))
                    {
                        return(false);
                    }
                }
                else
                {
                    // ## busca proximo registro do select all

                    if (!loj.fetch())
                    {
                        break;
                    }

                    if (hshLojas.Count > 0)
                    {
                        // ##  filtro lojas no caso de admin

                        if (hshLojas [loj.get_identity()] == null)
                        {
                            continue;
                        }
                    }
                }

                // ## Verifica qtd de terminais

                term.select_fk_loja(loj.get_identity());

                if (bCod)
                {
                    if (loj.get_st_loja() != codigo)
                    {
                        continue;
                    }
                }

                if (bNome)
                {
                    if (!loj.get_st_nome().ToUpper().Contains(nome))
                    {
                        if (!loj.get_st_social().ToUpper().Contains(nome))
                        {
                            continue;
                        }
                    }
                }

                if (min_qtd > 0)
                {
                    if (term.GetCount() < min_qtd)
                    {
                        continue;
                    }
                }

                if (cidade.Length > 0)
                {
                    if (!loj.get_st_cidade().Contains(cidade))
                    {
                        continue;
                    }
                }

                if (estado.Length > 0)
                {
                    if (!loj.get_st_estado().Contains(estado))
                    {
                        continue;
                    }
                }

                // ## Copia dados para memória

                DadosLoja dl = new DadosLoja();

                string id_loja = loj.get_st_nome().Trim() + " - " + loj.get_st_social().Trim();

                lstSortLojas.Add(id_loja);

                dl.set_st_loja(loj.get_st_loja());
                dl.set_st_nome(id_loja);
                dl.set_st_cidade(loj.get_st_cidade());
                dl.set_st_estado(loj.get_st_estado());

                dl.set_st_endereco("Tel: " + loj.get_nu_telefone() + " End: " + loj.get_st_endereco());

                dl.set_nu_diasRep(loj_emp.get_nu_dias_repasse());

                string tx = loj_emp.get_tx_admin().PadLeft(3, '0');

                dl.set_nu_pctRep(tx.Insert(tx.Length - 2, ",") + "%");

                string st_terms = " (";

                int terms = 0;

                while (term.fetch())
                {
                    if (term.get_fk_loja() == Context.NOT_SET)
                    {
                        continue;
                    }

                    terms++;

                    st_terms += term.get_nu_terminal().TrimStart('0') + ", ";
                }

                st_terms = terms.ToString() + st_terms.Trim().TrimEnd(',') + ")";

                dl.set_st_obs(st_terms);
                dl.set_nu_CNPJ(loj.get_nu_CNPJ());

                string convs = "";

                if (loj_emp_conv.select_fk_loja(loj.get_identity()))
                {
                    while (loj_emp_conv.fetch())
                    {
                        emp_comp.selectIdentity(loj_emp_conv.get_fk_empresa());

                        convs += emp_comp.get_st_empresa().TrimStart('0') + ",";
                    }
                }

                dl.set_st_convenios(convs.TrimEnd(','));

                hshSortLojas [id_loja] = dl;
            }

            lstSortLojas.Sort();

            StringBuilder sb = new StringBuilder();

            for (int t = 0; t < lstSortLojas.Count; ++t)
            {
                DadosLoja dl = hshSortLojas [lstSortLojas [t]] as DadosLoja;

                DataPortable tmp = dl as DataPortable;

                // ## obtem indexador

                sb.Append(MemorySave(ref tmp));
                sb.Append(",");
            }

            string list_ids = sb.ToString().TrimEnd(',');

            if (list_ids == "")
            {
                PublishNote("Nenhum resultado foi encontrado");
                return(true);
            }

            DataPortable dp = new DataPortable();

            dp.setValue("ids", list_ids);

            // ## Obtem indexador geral

            output_st_csv_id = MemorySave(ref dp);

            /// USER [ execute ] END

            Registry("execute done fetch_consultaLoja ");

            return(true);
        }