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

            Registry("execute fetch_listaEmpresas ");

            /// USER [ execute ]

            T_Empresa m_emp = new T_Empresa(this);

            for (int t = 0; t < var_util.indexCSV(input_st_csv_empresas); ++t)
            {
                if (!m_emp.fetch_rows_empresa(var_util.getCSV(t)))
                {
                    return(false);
                }

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

                LINK_LojaEmpresa loj_emp = new LINK_LojaEmpresa(this);

                loj_emp.fetch_fk_empresa_geral(m_emp.get_identity());

                DadosEmpresa de = new DadosEmpresa();

                de.set_nu_CNPJ(m_emp.get_nu_CNPJ());
                de.set_st_empresa(m_emp.get_st_empresa());
                de.set_st_fantasia(m_emp.get_st_fantasia());
                de.set_st_cidade(m_emp.get_st_cidade());
                de.set_st_estado(m_emp.get_st_estado());
                de.set_nu_cartoes(m_emp.get_nu_cartoes());
                de.set_nu_parcelas(m_emp.get_nu_parcelas());
                de.set_vr_taxa(m_emp.get_vr_taxa());
                de.set_nu_lojas(loj_emp.RowCount().ToString());

                output_array_generic_lst.Add(de);
            }

            /// USER [ execute ] END

            Registry("execute done fetch_listaEmpresas ");

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

            Registry("execute fetch_consultaEmpresa ");

            /// USER [ execute ]

            StringBuilder sb = new StringBuilder();

            string nome   = input_cont_dce.get_st_nome(),
                   cidade = input_cont_dce.get_st_cidade(),
                   estado = input_cont_dce.get_st_estado();

            long vr_min   = 0,
                 vr_max   = 0,
                 qtd_cart = 0,
                 qtd_parc = 0,
                 nu_lojas = 0,
                 val      = 0;

            // ## Prepara filtros

            if (input_cont_dce.get_nu_cartoes().Length > 0)
            {
                qtd_cart = Convert.ToInt32(input_cont_dce.get_nu_cartoes());
            }
            if (input_cont_dce.get_nu_parcelas().Length > 0)
            {
                qtd_parc = Convert.ToInt32(input_cont_dce.get_nu_parcelas());
            }
            if (input_cont_dce.get_nu_lojas().Length > 0)
            {
                nu_lojas = Convert.ToInt32(input_cont_dce.get_nu_lojas());
            }

            if (input_cont_dce.get_vr_taxa_min().Length > 0)
            {
                vr_min = Convert.ToInt32(input_cont_dce.get_vr_taxa_min());
            }
            if (input_cont_dce.get_vr_taxa_min().Length > 0)
            {
                vr_max = Convert.ToInt32(input_cont_dce.get_vr_taxa_max());
            }

            LINK_LojaEmpresa loj_emp = new LINK_LojaEmpresa(this);

            // ## Busca todos os registros

            nome = nome.ToUpper();

            while (emp.fetch())
            {
                val = emp.get_int_vr_mensalidade();

                if (vr_min > 0)
                {
                    if (val < vr_min)
                    {
                        continue;
                    }
                }

                if (vr_max > 0)
                {
                    if (val > vr_max)
                    {
                        continue;
                    }
                }

                if (vr_min > 0 && vr_max > 0)
                {
                    if (val < vr_min || val > vr_max)
                    {
                        continue;
                    }
                }

                if (qtd_cart > 0)
                {
                    if (emp.get_int_nu_cartoes() < qtd_cart)
                    {
                        continue;
                    }
                }

                if (qtd_parc > 0)
                {
                    if (emp.get_int_nu_parcelas() < qtd_parc)
                    {
                        continue;
                    }
                }

                if (nome.Length > 0)
                {
                    if (!emp.get_st_social().ToUpper().Contains(nome))
                    {
                        if (!emp.get_st_fantasia().ToUpper().Contains(nome))
                        {
                            continue;
                        }
                    }
                }

                if (cidade.Length > 0)
                {
                    if (!emp.get_st_cidade().Contains(cidade))
                    {
                        continue;
                    }
                }
                if (estado.Length > 0)
                {
                    if (!emp.get_st_estado().Contains(estado))
                    {
                        continue;
                    }
                }

                // ## Contabiliza numero de lojas

                loj_emp.SetCountMode();
                loj_emp.select_fk_empresa_geral(emp.get_identity());

                if (input_cont_dce.get_nu_lojas().Length > 0)
                {
                    if (loj_emp.GetCount() < nu_lojas)
                    {
                        continue;
                    }
                }

                // ## Copia dados para memória

                DadosEmpresa de = new DadosEmpresa();

                de.set_nu_lojas(loj_emp.GetCount().ToString());

                de.set_st_empresa(emp.get_st_empresa());
                de.set_st_fantasia(emp.get_st_fantasia().Trim() + " - " + emp.get_st_social().Trim());
                de.set_st_cidade(emp.get_st_cidade());
                de.set_st_estado(emp.get_st_estado());
                de.set_nu_cartoes(emp.get_nu_cartoes());
                de.set_nu_parcelas(emp.get_nu_parcelas());
                de.set_vr_mensalidade(emp.get_vr_mensalidade());
                de.set_nu_CNPJ(emp.get_nu_CNPJ());
                de.set_tg_bloq(emp.get_tg_bloq());

                DataPortable tmp = de as DataPortable;

                // ## indexa em CSV

                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 identificador de bloco

            output_st_csv_empresas = MemorySave(ref dp);

            /// USER [ execute ] END

            Registry("execute done fetch_consultaEmpresa ");

            return(true);
        }