using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using MySql.Data.MySqlClient;
using fatd_faturamento.ENTIDADE;
using fatd_faturamento.DAL.Conexao;
using System.Runtime.Remoting;

namespace fatd_faturamento.DAL.Persistencia
{
    public class dalNfTransicao
    {
        string vFILTER = null;
        string vINNERJOIN = null;
        string vAND = null;
        string vORDERBY = null;

        bool blnTabNf;
        bool lstrFilPref;


        #region Métodos

        public void Insert(entidadeNfTransicao objNfTransicao)
        {
            MySqlCommand cmd = null;

            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {
                    vFILTER = vFILTER + "NUMNF        = ?NUMNF        , ";
                    vFILTER = vFILTER + "CODCLAS      = ?CODCLAS      , ";
                    vFILTER = vFILTER + "MESANO       = ?MESANO       , ";
                    vFILTER = vFILTER + "DATAVENC     = ?DATAVENC     , ";
                    vFILTER = vFILTER + "DATALEIT     = ?DATALEIT     , ";
                    vFILTER = vFILTER + "DATAAPR      = ?DATAAPR      , ";
                    vFILTER = vFILTER + "DATAEM       = ?DATAEM       , ";
                    vFILTER = vFILTER + "DATALEITANT  = ?DATALEITANT  , ";
                    vFILTER = vFILTER + "NSU          = ?NSU          , ";
                    vFILTER = vFILTER + "ZONA         = ?ZONA         , ";
                    vFILTER = vFILTER + "LIVRO        = ?LIVRO        , ";
                    vFILTER = vFILTER + "CONTA        = ?CONTA        , ";
                    vFILTER = vFILTER + "ROTA         = ?ROTA         , ";
                    vFILTER = vFILTER + "CONS_ID      = ?CONS_ID      , ";
                    vFILTER = vFILTER + "UNID_ID      = ?UNID_ID      , ";
                    vFILTER = vFILTER + "DATAPROXLEIT = ?DATAPROXLEIT , ";
                    vFILTER = vFILTER + "CFOP         = ?CFOP         , ";
                    vFILTER = vFILTER + "TA           = ?TA           , ";
                    vFILTER = vFILTER + "GRUPO        = ?GRUPO        , ";
                    vFILTER = vFILTER + "FASE         = ?FASE         , ";
                    vFILTER = vFILTER + "TENSAO       = ?TENSAO       , ";
                    vFILTER = vFILTER + "BANARREC     = ?BANARREC     , ";
                    vFILTER = vFILTER + "BANCO_FATUR  = ?BANCO_FATUR  , ";
                    vFILTER = vFILTER + "BANIDENT     = ?BANIDENT     , ";
                    vFILTER = vFILTER + "NUM_MED      = ?NUM_MED      , ";
                    vFILTER = vFILTER + "AGRUPA       = ?AGRUPA       , ";
                    vFILTER = vFILTER + "CPF_CNPJ     = ?CPF_CNPJ     , ";
                    vFILTER = vFILTER + "PAG_GOV      = ?PAG_GOV      , ";
                    vFILTER = vFILTER + "FLGMEDFAT    = ?FLGMEDFAT    , ";
                    vFILTER = vFILTER + "CONST_MED    = ?CONST_MED      ";



                    cmd = new MySqlCommand(this.QueryInsert);


                    cmd.Parameters.AddWithValue("?NUMNF", objNfTransicao.NUMNF);
                    cmd.Parameters.AddWithValue("?CODCLAS", objNfTransicao.CODCLAS.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MESANO ", objNfTransicao.MESANO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DATAVENC", objNfTransicao.DATAVENC);
                    cmd.Parameters.AddWithValue("?DATALEIT", objNfTransicao.DATALEIT);
                    cmd.Parameters.AddWithValue("?DATAAPR", objNfTransicao.DATAAPR);
                    cmd.Parameters.AddWithValue("?DATAEM ", objNfTransicao.DATAEM);
                    cmd.Parameters.AddWithValue("?DATALEITANT ", objNfTransicao.DATALEITANT);
                    cmd.Parameters.AddWithValue("?NSU", objNfTransicao.NSU);
                    cmd.Parameters.AddWithValue("?ZONA", objNfTransicao.ZONA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LIVRO", objNfTransicao.LIVRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTA", objNfTransicao.CONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?ROTA", objNfTransicao.ROTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONS_ID", objNfTransicao.CONS_ID);
                    cmd.Parameters.AddWithValue("?UNID_ID", objNfTransicao.UNID_ID);
                    cmd.Parameters.AddWithValue("?DATAPROXLEIT", objNfTransicao.DATAPROXLEIT);
                    cmd.Parameters.AddWithValue("?CFOP", objNfTransicao.CFOP);
                    cmd.Parameters.AddWithValue("?TA", objNfTransicao.TA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?GRUPO", objNfTransicao.GRUPO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?FASE", objNfTransicao.FASE.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?TENSAO", objNfTransicao.TENSAO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?BANARREC", objNfTransicao.BANARREC);
                    cmd.Parameters.AddWithValue("?BANCO_FATUR", objNfTransicao.BANCO_FATUR.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?BANIDENT", objNfTransicao.BANIDENT.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?NUM_MED", objNfTransicao.NUM_MED.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?AGRUPA", objNfTransicao.AGRUPA);
                    cmd.Parameters.AddWithValue("?CPF_CNPJ", objNfTransicao.CPF_CNPJ.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?PAG_GOV", objNfTransicao.PAG_GOV.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?FLGMEDFAT", objNfTransicao.FLGMEDFAT.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONST_MED", objNfTransicao.CONST_MED);


                    objGerenciadorTransacao.Execute(cmd);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public void Insert_1(entidadeNfTransicao objNfTransicao)
        {
            MySqlCommand cmd = null;

            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {
                    vFILTER = vFILTER + "NUMNF                 = ?NUMNF                 , ";
                    vFILTER = vFILTER + "NSU                   = ?NSU                   , ";
                    vFILTER = vFILTER + "MESANO                = ?MESANO                , ";
                    vFILTER = vFILTER + "MESANO_REF            = ?MESANO_REF            , ";
                    vFILTER = vFILTER + "ANOMES_FAT            = ?ANOMES_FAT            , ";
                    vFILTER = vFILTER + "CODCLAS               = ?CODCLAS               , ";
                    vFILTER = vFILTER + "DATAVENC              = ?DATAVENC              , ";
                    vFILTER = vFILTER + "DATALEIT              = ?DATALEIT              , ";
                    vFILTER = vFILTER + "DATALEITANT           = ?DATALEITANT           , ";
                    vFILTER = vFILTER + "DATAPROXLEIT          = ?DATAPROXLEIT          , ";
                    vFILTER = vFILTER + "DATAAPR               = ?DATAAPR               , ";
                    vFILTER = vFILTER + "DATAEM                = ?DATAEM                , ";
                    vFILTER = vFILTER + "ZONA                  = ?ZONA                  , ";
                    vFILTER = vFILTER + "LIVRO                 = ?LIVRO                 , ";
                    vFILTER = vFILTER + "CONTA                 = ?CONTA                 , ";
                    vFILTER = vFILTER + "ROTA                  = ?ROTA                  , ";
                    vFILTER = vFILTER + "CONS_ID               = ?CONS_ID               , ";
                    vFILTER = vFILTER + "UNID_ID               = ?UNID_ID               , ";
                    vFILTER = vFILTER + "MICRO_GERACAO         = ?MICRO_GERACAO         , ";
                    vFILTER = vFILTER + "IRRIGACAO_AQUICULTURA = ?IRRIGACAO_AQUICULTURA , ";
                    vFILTER = vFILTER + "MICRO_GERACAO_DISTRIBUIDA = ?MICRO_GERACAO_DISTRIBUIDA , ";
                    vFILTER = vFILTER + "TARIFA_BRANCA         = ?TARIFA_BRANCA         , ";
                    vFILTER = vFILTER + "CFOP                  = ?CFOP                  , ";
                    vFILTER = vFILTER + "TA                    = ?TA                    , ";
                    vFILTER = vFILTER + "GRUPO                 = ?GRUPO                 , ";
                    vFILTER = vFILTER + "FASE                  = ?FASE                  , ";
                    vFILTER = vFILTER + "TENSAO                = ?TENSAO                , ";
                    vFILTER = vFILTER + "BANARREC              = ?BANARREC              , ";
                    vFILTER = vFILTER + "BANCO_FATUR           = ?BANCO_FATUR           , ";
                    vFILTER = vFILTER + "BANIDENT              = ?BANIDENT              , ";
                    vFILTER = vFILTER + "NUM_MED               = ?NUM_MED               , ";
                    vFILTER = vFILTER + "CONST_MED             = ?CONST_MED             , ";
                    vFILTER = vFILTER + "AGRUPA                = ?AGRUPA                , ";
                    vFILTER = vFILTER + "AGRUPA_ROTA           = ?AGRUPA_ROTA           , ";
                    vFILTER = vFILTER + "AGRUPA_CADERNO        = ?AGRUPA_CADERNO        , ";
                    vFILTER = vFILTER + "AGRUPA_SEQUENCIA      = ?AGRUPA_SEQUENCIA      , ";
                    vFILTER = vFILTER + "CADERNO               = ?CADERNO               , ";
                    vFILTER = vFILTER + "CADERNO_SEQUENCIA     = ?CADERNO_SEQUENCIA     , ";
                    vFILTER = vFILTER + "ROTA_QUATRO           = ?ROTA_QUATRO           , ";
                    vFILTER = vFILTER + "PAG_GOV               = ?PAG_GOV               , ";
                    vFILTER = vFILTER + "AGENCIA               = ?AGENCIA               , ";
                    vFILTER = vFILTER + "CONTA_CORRENTE        = ?CONTA_CORRENTE        , ";
                    vFILTER = vFILTER + "CPF_CNPJ              = ?CPF_CNPJ              , ";
                    vFILTER = vFILTER + "MENSAGEM_BANDEIRA     = ?MENSAGEM_BANDEIRA     , ";

                    if (objNfTransicao.FLGMEDFAT == "2")
                    {
                        vFILTER = vFILTER + "FLGMEDFAT = 'S', ";
                        vFILTER = vFILTER + "CANCELADA_NUMNF = ?CANCELADA_NUMNF , ";
                        vFILTER = vFILTER + "CANCELADA_MESANO = ?CANCELADA_MESANO , ";
                    }
                    else
                    {
                        vFILTER = vFILTER + "FATURA_FINAL = ?FATURA_FINAL , ";
                        vFILTER = vFILTER + "FLGMEDFAT = 'N' , ";
                        vFILTER = vFILTER + "CANCELADA_NUMNF = ?CANCELADA_NUMNF , ";
                        vFILTER = vFILTER + "CANCELADA_MESANO = ?CANCELADA_MESANO , ";
                    }

                    vFILTER = vFILTER + "SGDENVIO    = ?SGDENVIO , ";

                    vFILTER = vFILTER + "UF    = ?UF , ";
                    vFILTER = vFILTER + "IBGE    = ?IBGE ";

                    cmd = new MySqlCommand(this.QueryInsert);


                    cmd.Parameters.AddWithValue("?NUMNF", objNfTransicao.NUMNF);
                    cmd.Parameters.AddWithValue("?NSU", objNfTransicao.NSU);
                    cmd.Parameters.AddWithValue("?MESANO", objNfTransicao.MESANO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MESANO_REF", objNfTransicao.MESANO_REF);
                    cmd.Parameters.AddWithValue("?ANOMES_FAT", objNfTransicao.ANOMES_FAT);
                    cmd.Parameters.AddWithValue("?CODCLAS", objNfTransicao.CODCLAS.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DATAVENC", objNfTransicao.DATAVENC);
                    cmd.Parameters.AddWithValue("?DATALEIT", objNfTransicao.DATALEIT);
                    cmd.Parameters.AddWithValue("?DATALEITANT", objNfTransicao.DATALEITANT);
                    cmd.Parameters.AddWithValue("?DATAPROXLEIT", objNfTransicao.DATAPROXLEIT);
                    cmd.Parameters.AddWithValue("?DATAAPR", objNfTransicao.DATAAPR);
                    cmd.Parameters.AddWithValue("?DATAEM", objNfTransicao.DATAEM);
                    cmd.Parameters.AddWithValue("?ZONA", objNfTransicao.ZONA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LIVRO", objNfTransicao.LIVRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTA", objNfTransicao.CONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?ROTA", objNfTransicao.ROTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONS_ID", objNfTransicao.CONS_ID);
                    cmd.Parameters.AddWithValue("?UNID_ID", objNfTransicao.UNID_ID);
                    cmd.Parameters.AddWithValue("?MICRO_GERACAO", objNfTransicao.MICRO_GERACAO);
                    cmd.Parameters.AddWithValue("?MICRO_GERACAO_DISTRIBUIDA", objNfTransicao.MICRO_GERACAO_DISTRIBUIDA);
                    cmd.Parameters.AddWithValue("?IRRIGACAO_AQUICULTURA", objNfTransicao.IRRIGACAO_AQUICULTURA);
                    cmd.Parameters.AddWithValue("?TARIFA_BRANCA", objNfTransicao.TARIFA_BRANCA);
                    cmd.Parameters.AddWithValue("?CFOP", objNfTransicao.CFOP);
                    cmd.Parameters.AddWithValue("?TA", objNfTransicao.TA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?GRUPO", objNfTransicao.GRUPO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?FASE", objNfTransicao.FASE.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?TENSAO", objNfTransicao.TENSAO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?BANARREC", objNfTransicao.BANARREC);
                    cmd.Parameters.AddWithValue("?BANCO_FATUR", objNfTransicao.BANCO_FATUR.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?BANIDENT", objNfTransicao.BANIDENT.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?NUM_MED", objNfTransicao.NUM_MED.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONST_MED", objNfTransicao.CONST_MED);
                    cmd.Parameters.AddWithValue("?AGRUPA", objNfTransicao.AGRUPA);
                    cmd.Parameters.AddWithValue("?AGRUPA_ROTA", objNfTransicao.AGRUPA_ROTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?AGRUPA_CADERNO", objNfTransicao.AGRUPA_CADERNO);
                    cmd.Parameters.AddWithValue("?AGRUPA_SEQUENCIA", objNfTransicao.AGRUPA_SEQUENCIA);
                    cmd.Parameters.AddWithValue("?CADERNO", objNfTransicao.CADERNO);
                    cmd.Parameters.AddWithValue("?CADERNO_SEQUENCIA", objNfTransicao.CADERNO_SEQUENCIA);
                    cmd.Parameters.AddWithValue("?ROTA_QUATRO", objNfTransicao.ROTA_QUATRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?PAG_GOV", objNfTransicao.PAG_GOV.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?AGENCIA", objNfTransicao.AGENCIA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTA_CORRENTE", objNfTransicao.CONTA_CORRENTE.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CPF_CNPJ", objNfTransicao.CPF_CNPJ.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MENSAGEM_BANDEIRA", objNfTransicao.MENSAGEM_BANDEIRA.ToString().ToUpper());

                    if (objNfTransicao.FLGMEDFAT == "2")
                    {
                        cmd.Parameters.AddWithValue("?CANCELADA_NUMNF", objNfTransicao.CANCELADA_NUMNF);
                        cmd.Parameters.AddWithValue("?CANCELADA_MESANO", objNfTransicao.CANCELADA_MESANO.ToString().ToUpper());
                    }
                    else
                    {
                        cmd.Parameters.AddWithValue("?FATURA_FINAL", objNfTransicao.FATURA_FINAL);
                        cmd.Parameters.AddWithValue("?CANCELADA_NUMNF", objNfTransicao.CANCELADA_NUMNF);
                        cmd.Parameters.AddWithValue("?CANCELADA_MESANO", objNfTransicao.CANCELADA_MESANO.ToString().ToUpper());
                    }

                    cmd.Parameters.AddWithValue("?SGDENVIO", objNfTransicao.SGDENVIO.ToString().ToUpper());

                    cmd.Parameters.AddWithValue("?UF", objNfTransicao.UF.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?IBGE", objNfTransicao.IBGE.ToString().ToUpper());

                    objGerenciadorTransacao.Execute(cmd);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public void Update_CodBarras(entidadeNfTransicao objNfTransicao)
        {
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {

                    vFILTER = vFILTER + "       CODBARRA         = ?CODBARRA , ";
                    vFILTER = vFILTER + "       DVCODBARRA       = ?DVCODBARRA , ";
                    vFILTER = vFILTER + "       CODBARRA_IMAGEM  = ?CODBARRA_IMAGEM ";

                    vAND = vAND + "   AND NUMNF      = ?NUMNF ";
                    vAND = vAND + "   AND MESANO_REF = ?MESANO_REF ";


                    cmd = new MySqlCommand(this.QueryUpdate);


                    cmd.Parameters.AddWithValue("?CODBARRA", objNfTransicao.CODBARRA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DVCODBARRA", objNfTransicao.DVCODBARRA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CODBARRA_IMAGEM", objNfTransicao.CODBARRA_IMAGEM.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MESANO_REF", objNfTransicao.MESANO_REF);
                    cmd.Parameters.AddWithValue("?NUMNF", objNfTransicao.NUMNF);



                    objGerenciadorTransacao.Execute(cmd);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public void Update(entidadeNfTransicao objNfTransicao)
        {
            MySqlCommand cmd = null;

            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {
                    vFILTER = vFILTER + "    FLGST    = ?FLGST, ";
                    vFILTER = vFILTER + "       DATAPAG  = ?DATAPAG, ";
                    vFILTER = vFILTER + "       BANARREC = ?BANARREC, ";
                    vFILTER = vFILTER + "       BANIDENT = ?BANIDENT ";

                    vAND = vAND + "AND MESANO_REF = ?MESANO_REF ";
                    vAND = vAND + "AND VALORLIQ = ?VALORLIQ ";

                    cmd = new MySqlCommand(this.QueryUpdate);


                    cmd.Parameters.AddWithValue("?FLGST", objNfTransicao.FLGST.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DATAPAG", objNfTransicao.DATAPAG);
                    cmd.Parameters.AddWithValue("?BANARREC", objNfTransicao.BANARREC);
                    cmd.Parameters.AddWithValue("?BANIDENT", objNfTransicao.BANIDENT.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MESANO_REF", objNfTransicao.MESANO_REF);
                    cmd.Parameters.AddWithValue("?VALORLIQ", objNfTransicao.VALORLIQ);

                    objGerenciadorTransacao.Execute(cmd);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public void Update_1(entidadeNfTransicao objNfTransicao)
        {
            MySqlCommand cmd = null;

            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {
                    vFILTER = vFILTER + "    ITENSSERV = CONCAT(ITENSSERV, ?ITENSSERV ) ";

                    vAND = vAND + "AND CONS_ID = ?CONS_ID ";
                    vAND = vAND + "AND UNID_ID = ?UNID_ID ";
                    vAND = vAND + "AND MESANO = ?MESANO ";

                    cmd = new MySqlCommand(this.QueryUpdate);


                    cmd.Parameters.AddWithValue("?ITENSSERV", objNfTransicao.ITENSSERV.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MESANO", objNfTransicao.MESANO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONS_ID", objNfTransicao.CONS_ID);
                    cmd.Parameters.AddWithValue("?UNID_ID", objNfTransicao.UNID_ID);


                    objGerenciadorTransacao.Execute(cmd);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public void Update_2(entidadeNfTransicao objNfTransicao)
        {
            MySqlCommand cmd = null;

            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {
                    vFILTER = vFILTER + "ITENSSERV = ?ITENSSERV, ";
                    vFILTER = vFILTER + "VALORTOT = ?VALORTOT , ";
                    vFILTER = vFILTER + "VALORLIQ = ?VALORLIQ , ";
                    vFILTER = vFILTER + "FLGST = '', ";
                    vFILTER = vFILTER + "DIAS = ?DIAS , ";
                    vFILTER = vFILTER + "DATAPAG ='0000-00-00',";
                    vFILTER = vFILTER + "CODBARRA = ?CODBARRA , ";
                    vFILTER = vFILTER + "DVCODBARRA = ?DVCODBARRA , ";
                    vFILTER = vFILTER + "CODHASH = ?CODHASH ";

                    vAND = vAND + "AND NUMNF = ?NUMNF ";
                    vAND = vAND + "AND MESANO = ?MESANO ";

                    cmd = new MySqlCommand(this.QueryUpdate);


                    cmd.Parameters.AddWithValue("?ITENSSERV", objNfTransicao.ITENSSERV.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?VALORTOT", objNfTransicao.VALORTOT);
                    cmd.Parameters.AddWithValue("?VALORLIQ", objNfTransicao.VALORLIQ);
                    cmd.Parameters.AddWithValue("?DIAS", objNfTransicao.DIAS.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CODBARRA", objNfTransicao.CODBARRA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DVCODBARRA", objNfTransicao.DVCODBARRA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?NUMNF", objNfTransicao.NUMNF);
                    cmd.Parameters.AddWithValue("?MESANO", objNfTransicao.MESANO.ToString().ToUpper());

                    objGerenciadorTransacao.Execute(cmd);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public void Update_3(entidadeNfTransicao objNfTransicao)
        {
            MySqlCommand cmd = null;

            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {
                    vFILTER = vFILTER + "NUMNF        = ?NUMNF        , ";
                    vFILTER = vFILTER + "CODCLAS      = ?CODCLAS      , ";
                    vFILTER = vFILTER + "MESANO       = ?MESANO       , ";
                    vFILTER = vFILTER + "DATAVENC     = ?DATAVENC     , ";
                    vFILTER = vFILTER + "DATALEIT     = ?DATALEIT     , ";
                    vFILTER = vFILTER + "DATAAPR      = ?DATAAPR      , ";
                    vFILTER = vFILTER + "DATAEM       = ?DATAEM       , ";
                    vFILTER = vFILTER + "DATALEITANT  = ?DATALEITANT  , ";
                    vFILTER = vFILTER + "NSU          = ?NSU          , ";
                    vFILTER = vFILTER + "ZONA         = ?ZONA         , ";
                    vFILTER = vFILTER + "LIVRO        = ?LIVRO        , ";
                    vFILTER = vFILTER + "CONTA        = ?CONTA        , ";
                    vFILTER = vFILTER + "ROTA         = ?ROTA         , ";
                    vFILTER = vFILTER + "CONS_ID      = ?CONS_ID      , ";
                    vFILTER = vFILTER + "UNID_ID      = ?UNID_ID      , ";
                    vFILTER = vFILTER + "DATAPROXLEIT = ?DATAPROXLEIT , ";
                    vFILTER = vFILTER + "CFOP         = ?CFOP         , ";
                    vFILTER = vFILTER + "TA           = ?TA           , ";
                    vFILTER = vFILTER + "GRUPO        = ?GRUPO        , ";
                    vFILTER = vFILTER + "FASE         = ?FASE         , ";
                    vFILTER = vFILTER + "TENSAO       = ?TENSAO       , ";
                    vFILTER = vFILTER + "BANARREC     = ?BANARREC     , ";
                    vFILTER = vFILTER + "BANCO_FATUR  = ?BANCO_FATUR  , ";
                    vFILTER = vFILTER + "BANIDENT     = ?BANIDENT     , ";
                    vFILTER = vFILTER + "NUM_MED      = ?NUM_MED      , ";
                    vFILTER = vFILTER + "AGRUPA       = ?AGRUPA       , ";
                    vFILTER = vFILTER + "CPF_CNPJ     = ?CPF_CNPJ     , ";
                    vFILTER = vFILTER + "PAG_GOV      = ?PAG_GOV      , ";
                    vFILTER = vFILTER + "FLGMEDFAT    = ?FLGMEDFAT    , ";
                    vFILTER = vFILTER + "CONST_MED    = ?CONST_MED      ";


                    vAND = vAND + "AND NUMNF = ?NUMNF ";
                    vAND = vAND + "AND MESANO = ?MESANO ";

                    cmd = new MySqlCommand(this.QueryUpdate);


                    cmd.Parameters.AddWithValue("?NUMNF", objNfTransicao.NUMNF);
                    cmd.Parameters.AddWithValue("?CODCLAS", objNfTransicao.CODCLAS.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MESANO ", objNfTransicao.MESANO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DATAVENC", objNfTransicao.DATAVENC);
                    cmd.Parameters.AddWithValue("?DATALEIT", objNfTransicao.DATALEIT);
                    cmd.Parameters.AddWithValue("?DATAAPR", objNfTransicao.DATAAPR);
                    cmd.Parameters.AddWithValue("?DATAEM ", objNfTransicao.DATAEM);
                    cmd.Parameters.AddWithValue("?DATALEITANT ", objNfTransicao.DATALEITANT);
                    cmd.Parameters.AddWithValue("?NSU", objNfTransicao.NSU);
                    cmd.Parameters.AddWithValue("?ZONA", objNfTransicao.ZONA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LIVRO", objNfTransicao.LIVRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTA", objNfTransicao.CONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?ROTA", objNfTransicao.ROTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONS_ID", objNfTransicao.CONS_ID);
                    cmd.Parameters.AddWithValue("?UNID_ID", objNfTransicao.UNID_ID);
                    cmd.Parameters.AddWithValue("?DATAPROXLEIT", objNfTransicao.DATAPROXLEIT);
                    cmd.Parameters.AddWithValue("?CFOP", objNfTransicao.CFOP);
                    cmd.Parameters.AddWithValue("?TA", objNfTransicao.TA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?GRUPO", objNfTransicao.GRUPO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?FASE", objNfTransicao.FASE.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?TENSAO", objNfTransicao.TENSAO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?BANARREC", objNfTransicao.BANARREC);
                    cmd.Parameters.AddWithValue("?BANCO_FATUR", objNfTransicao.BANCO_FATUR.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?BANIDENT", objNfTransicao.BANIDENT.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?NUM_MED", objNfTransicao.NUM_MED.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?AGRUPA", objNfTransicao.AGRUPA);
                    cmd.Parameters.AddWithValue("?CPF_CNPJ", objNfTransicao.CPF_CNPJ.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?PAG_GOV", objNfTransicao.PAG_GOV.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?FLGMEDFAT", objNfTransicao.FLGMEDFAT.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONST_MED", objNfTransicao.CONST_MED);


                    objGerenciadorTransacao.Execute(cmd);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public void Update_4(entidadeNfTransicao objNfTransicao)
        {
            MySqlCommand cmd = null;

            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {

                    vFILTER = vFILTER + "CODCLAS      = ?CODCLAS       ";

                    vAND = vAND + "AND NUMNF = ?NUMNF ";
                    vAND = vAND + "AND MESANO = ?MESANO ";

                    cmd = new MySqlCommand(this.QueryUpdate);


                    cmd.Parameters.AddWithValue("?NUMNF", objNfTransicao.NUMNF);
                    cmd.Parameters.AddWithValue("?CODCLAS", objNfTransicao.CODCLAS.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MESANO ", objNfTransicao.MESANO.ToString().ToUpper());


                    objGerenciadorTransacao.Execute(cmd);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public void Update_5(entidadeNfTransicao objNfTransicao)
        {
            MySqlCommand cmd = null;

            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {

                    vFILTER = vFILTER + "NUMNF                 = ?NUMNF                 , ";
                    vFILTER = vFILTER + "NSU                   = ?NSU                   , ";
                    vFILTER = vFILTER + "MESANO                = ?MESANO                , ";
                    vFILTER = vFILTER + "MESANO_REF            = ?MESANO_REF            , ";
                    vFILTER = vFILTER + "ANOMES_FAT            = ?ANOMES_FAT            , ";
                    vFILTER = vFILTER + "CODCLAS               = ?CODCLAS               , ";
                    vFILTER = vFILTER + "DATAVENC              = ?DATAVENC              , ";
                    vFILTER = vFILTER + "DATALEIT              = ?DATALEIT              , ";
                    vFILTER = vFILTER + "DATALEITANT           = ?DATALEITANT           , ";
                    vFILTER = vFILTER + "DATAPROXLEIT          = ?DATAPROXLEIT          , ";
                    vFILTER = vFILTER + "DATAAPR               = ?DATAAPR               , ";
                    vFILTER = vFILTER + "DATAEM                = ?DATAEM                , ";
                    vFILTER = vFILTER + "ZONA                  = ?ZONA                  , ";
                    vFILTER = vFILTER + "LIVRO                 = ?LIVRO                 , ";
                    vFILTER = vFILTER + "CONTA                 = ?CONTA                 , ";
                    vFILTER = vFILTER + "ROTA                  = ?ROTA                  , ";
                    vFILTER = vFILTER + "CONS_ID               = ?CONS_ID               , ";
                    vFILTER = vFILTER + "UNID_ID               = ?UNID_ID               , ";
                    vFILTER = vFILTER + "MICRO_GERACAO         = ?MICRO_GERACAO         , ";
                    vFILTER = vFILTER + "MICRO_GERACAO_DISTRIBUIDA = ?MICRO_GERACAO_DISTRIBUIDA , ";
                    vFILTER = vFILTER + "MICRO_GERACAO_CONVENIO_SEFAZ = ?MICRO_GERACAO_CONVENIO_SEFAZ , ";                  
                    vFILTER = vFILTER + "IRRIGACAO_AQUICULTURA = ?IRRIGACAO_AQUICULTURA , ";
                    vFILTER = vFILTER + "TARIFA_BRANCA         = ?TARIFA_BRANCA         , ";
                    vFILTER = vFILTER + "CFOP                  = ?CFOP                  , ";
                    vFILTER = vFILTER + "TA                    = ?TA                    , ";
                    vFILTER = vFILTER + "GRUPO                 = ?GRUPO                 , ";
                    vFILTER = vFILTER + "FASE                  = ?FASE                  , ";
                    vFILTER = vFILTER + "TENSAO                = ?TENSAO                , ";
                    vFILTER = vFILTER + "BANARREC              = ?BANARREC              , ";
                    vFILTER = vFILTER + "BANCO_FATUR           = ?BANCO_FATUR           , ";
                    vFILTER = vFILTER + "BANIDENT              = ?BANIDENT              , ";
                    vFILTER = vFILTER + "NUM_MED               = ?NUM_MED               , ";
                    vFILTER = vFILTER + "CONST_MED             = ?CONST_MED             , ";
                    vFILTER = vFILTER + "AGRUPA                = ?AGRUPA                , ";
                    vFILTER = vFILTER + "AGRUPA_ROTA           = ?AGRUPA_ROTA           , ";
                    vFILTER = vFILTER + "AGRUPA_CADERNO        = ?AGRUPA_CADERNO        , ";
                    vFILTER = vFILTER + "AGRUPA_SEQUENCIA      = ?AGRUPA_SEQUENCIA      , ";
                    vFILTER = vFILTER + "CADERNO               = ?CADERNO               , ";
                    vFILTER = vFILTER + "CADERNO_SEQUENCIA     = ?CADERNO_SEQUENCIA     , ";
                    vFILTER = vFILTER + "ROTA_QUATRO           = ?ROTA_QUATRO           , ";
                    vFILTER = vFILTER + "PAG_GOV               = ?PAG_GOV               , ";
                    vFILTER = vFILTER + "AGENCIA               = ?AGENCIA               , ";
                    vFILTER = vFILTER + "CONTA_CORRENTE        = ?CONTA_CORRENTE        , ";
                    vFILTER = vFILTER + "CPF_CNPJ              = ?CPF_CNPJ              , ";
                    vFILTER = vFILTER + "MENSAGEM_BANDEIRA     = ?MENSAGEM_BANDEIRA     , ";

                    if (objNfTransicao.FLGMEDFAT == "2")
                    {
                        vFILTER = vFILTER + "FLGMEDFAT = 'S', ";
                        vFILTER = vFILTER + "CANCELADA_NUMNF = ?CANCELADA_NUMNF , ";
                        vFILTER = vFILTER + "CANCELADA_MESANO = ?CANCELADA_MESANO , ";
                    }
                    else
                    {
                        vFILTER = vFILTER + "FATURA_FINAL = ?FATURA_FINAL , ";
                        vFILTER = vFILTER + "FLGMEDFAT = 'N' , ";
                        vFILTER = vFILTER + "CANCELADA_NUMNF = ?CANCELADA_NUMNF , ";
                        vFILTER = vFILTER + "CANCELADA_MESANO = ?CANCELADA_MESANO , ";
                    }

                    vFILTER = vFILTER + "SGDENVIO    = ?SGDENVIO , ";

                    vFILTER = vFILTER + "UF    = ?UF , ";
                    vFILTER = vFILTER + "IBGE    = ?IBGE ";

                    vAND = vAND + "AND NUMNF = ?NUMNF ";
                    vAND = vAND + "AND MESANO = ?MESANO ";

                    cmd = new MySqlCommand(this.QueryUpdate);


                    cmd.Parameters.AddWithValue("?NUMNF", objNfTransicao.NUMNF);
                    cmd.Parameters.AddWithValue("?NSU", objNfTransicao.NSU);
                    cmd.Parameters.AddWithValue("?MESANO", objNfTransicao.MESANO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MESANO_REF", objNfTransicao.MESANO_REF);
                    cmd.Parameters.AddWithValue("?ANOMES_FAT", objNfTransicao.ANOMES_FAT);
                    cmd.Parameters.AddWithValue("?CODCLAS", objNfTransicao.CODCLAS.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DATAVENC", objNfTransicao.DATAVENC);
                    cmd.Parameters.AddWithValue("?DATALEIT", objNfTransicao.DATALEIT);
                    cmd.Parameters.AddWithValue("?DATALEITANT", objNfTransicao.DATALEITANT);
                    cmd.Parameters.AddWithValue("?DATAPROXLEIT", objNfTransicao.DATAPROXLEIT);
                    cmd.Parameters.AddWithValue("?DATAAPR", objNfTransicao.DATAAPR);
                    cmd.Parameters.AddWithValue("?DATAEM", objNfTransicao.DATAEM);
                    cmd.Parameters.AddWithValue("?ZONA", objNfTransicao.ZONA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LIVRO", objNfTransicao.LIVRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTA", objNfTransicao.CONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?ROTA", objNfTransicao.ROTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONS_ID", objNfTransicao.CONS_ID);
                    cmd.Parameters.AddWithValue("?UNID_ID", objNfTransicao.UNID_ID);
                    cmd.Parameters.AddWithValue("?MICRO_GERACAO", objNfTransicao.MICRO_GERACAO);
                    cmd.Parameters.AddWithValue("?MICRO_GERACAO_DISTRIBUIDA", objNfTransicao.MICRO_GERACAO_DISTRIBUIDA);
                    cmd.Parameters.AddWithValue("?MICRO_GERACAO_CONVENIO_SEFAZ", objNfTransicao.MICRO_GERACAO_CONVENIO_SEFAZ);
                    cmd.Parameters.AddWithValue("?IRRIGACAO_AQUICULTURA", objNfTransicao.IRRIGACAO_AQUICULTURA);
                    cmd.Parameters.AddWithValue("?TARIFA_BRANCA", objNfTransicao.TARIFA_BRANCA);
                    cmd.Parameters.AddWithValue("?CFOP", objNfTransicao.CFOP);
                    cmd.Parameters.AddWithValue("?TA", objNfTransicao.TA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?GRUPO", objNfTransicao.GRUPO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?FASE", objNfTransicao.FASE.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?TENSAO", objNfTransicao.TENSAO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?BANARREC", objNfTransicao.BANARREC);
                    cmd.Parameters.AddWithValue("?BANCO_FATUR", objNfTransicao.BANCO_FATUR.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?BANIDENT", objNfTransicao.BANIDENT.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?NUM_MED", objNfTransicao.NUM_MED.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONST_MED", objNfTransicao.CONST_MED);
                    cmd.Parameters.AddWithValue("?AGRUPA", objNfTransicao.AGRUPA);
                    cmd.Parameters.AddWithValue("?AGRUPA_ROTA", objNfTransicao.AGRUPA_ROTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?AGRUPA_CADERNO", objNfTransicao.AGRUPA_CADERNO);
                    cmd.Parameters.AddWithValue("?AGRUPA_SEQUENCIA", objNfTransicao.AGRUPA_SEQUENCIA);
                    cmd.Parameters.AddWithValue("?CADERNO", objNfTransicao.CADERNO);
                    cmd.Parameters.AddWithValue("?CADERNO_SEQUENCIA", objNfTransicao.CADERNO_SEQUENCIA);
                    cmd.Parameters.AddWithValue("?ROTA_QUATRO", objNfTransicao.ROTA_QUATRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?PAG_GOV", objNfTransicao.PAG_GOV.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?AGENCIA", objNfTransicao.AGENCIA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTA_CORRENTE", objNfTransicao.CONTA_CORRENTE.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CPF_CNPJ", objNfTransicao.CPF_CNPJ.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MENSAGEM_BANDEIRA", objNfTransicao.MENSAGEM_BANDEIRA.ToString().ToUpper());

                    if (objNfTransicao.FLGMEDFAT == "2")
                    {
                        cmd.Parameters.AddWithValue("?CANCELADA_NUMNF", objNfTransicao.CANCELADA_NUMNF);
                        cmd.Parameters.AddWithValue("?CANCELADA_MESANO", objNfTransicao.CANCELADA_MESANO.ToString().ToUpper());
                    }
                    else
                    {
                        cmd.Parameters.AddWithValue("?FATURA_FINAL", objNfTransicao.FATURA_FINAL);
                        cmd.Parameters.AddWithValue("?CANCELADA_NUMNF", objNfTransicao.CANCELADA_NUMNF);
                        cmd.Parameters.AddWithValue("?CANCELADA_MESANO", objNfTransicao.CANCELADA_MESANO.ToString().ToUpper());
                    }

                    cmd.Parameters.AddWithValue("?SGDENVIO", objNfTransicao.SGDENVIO.ToString().ToUpper());

                    cmd.Parameters.AddWithValue("?UF", objNfTransicao.UF.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?IBGE", objNfTransicao.IBGE.ToString().ToUpper());


                    objGerenciadorTransacao.Execute(cmd);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public void Update_6(entidadeNfTransicao objNfTransicao)
        {
            MySqlCommand cmd = null;

            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {
                    vFILTER = vFILTER + "ITENSSERV = ?ITENSSERV , ";
                    vFILTER = vFILTER + "ITENSIMP = ?ITENSIMP , ";
                    vFILTER = vFILTER + "VALORTOT = ?VALORTOT , ";
                    vFILTER = vFILTER + "VALORLIQ = ?VALORLIQ , ";
                    vFILTER = vFILTER + "FLGST = ?FLGST , ";
                    vFILTER = vFILTER + "DIAS = ?DIAS , ";
                    vFILTER = vFILTER + "DATAPAG ='0000-00-00',";
                    vFILTER = vFILTER + "CODBARRA = ?CODBARRA , ";
                    vFILTER = vFILTER + "DVCODBARRA = ?DVCODBARRA , ";
                    vFILTER = vFILTER + "CODHASH = ?CODHASH ";

                    vAND = vAND + "AND NUMNF = ?NUMNF ";
                    vAND = vAND + "AND MESANO_REF = ?MESANO_REF ";

                    cmd = new MySqlCommand(this.QueryUpdate);


                    cmd.Parameters.AddWithValue("?ITENSSERV", objNfTransicao.ITENSSERV.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?ITENSIMP", objNfTransicao.ITENSIMP.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?VALORTOT", objNfTransicao.VALORTOT);
                    cmd.Parameters.AddWithValue("?VALORLIQ", objNfTransicao.VALORLIQ);
                    cmd.Parameters.AddWithValue("?FLGST", objNfTransicao.FLGST.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DIAS", objNfTransicao.DIAS.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CODBARRA", objNfTransicao.CODBARRA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DVCODBARRA", objNfTransicao.DVCODBARRA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?NUMNF", objNfTransicao.NUMNF);
                    cmd.Parameters.AddWithValue("?MESANO_REF", objNfTransicao.MESANO_REF.ToString().ToUpper());

                    objGerenciadorTransacao.Execute(cmd);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public void Update_7(entidadeNfTransicao objNfTransicao)
        {
            MySqlCommand cmd = null;

            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {
                    vFILTER = vFILTER + "ITENSSERV = ?ITENSSERV , ";
                    vFILTER = vFILTER + "ITENSIMP = ?ITENSIMP , ";
                    vFILTER = vFILTER + "VALORTOT = ?VALORTOT , ";
                    vFILTER = vFILTER + "VALORLIQ = ?VALORLIQ , ";
                    vFILTER = vFILTER + "FLGST = ?FLGST , ";
                    vFILTER = vFILTER + "DIAS = ?DIAS , ";
                    vFILTER = vFILTER + "DATAPAG ='0000-00-00',";
                    vFILTER = vFILTER + "CODBARRA = ?CODBARRA , ";
                    vFILTER = vFILTER + "DVCODBARRA = ?DVCODBARRA ,  ";
                    vFILTER = vFILTER + "CODHASH = ?CODHASH, ";
                    vFILTER = vFILTER + "CODBARRA_IMAGEM = ?CODBARRA_IMAGEM ";

                    vAND = vAND + "AND NUMNF = ?NUMNF ";
                    vAND = vAND + "AND MESANO_REF = ?MESANO_REF ";

                    cmd = new MySqlCommand(this.QueryUpdate);


                    cmd.Parameters.AddWithValue("?ITENSSERV", objNfTransicao.ITENSSERV.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?ITENSIMP", objNfTransicao.ITENSIMP.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?VALORTOT", objNfTransicao.VALORTOT);
                    cmd.Parameters.AddWithValue("?VALORLIQ", objNfTransicao.VALORLIQ);
                    cmd.Parameters.AddWithValue("?FLGST", objNfTransicao.FLGST.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DIAS", objNfTransicao.DIAS.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CODBARRA", objNfTransicao.CODBARRA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DVCODBARRA", objNfTransicao.DVCODBARRA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?NUMNF", objNfTransicao.NUMNF);
                    cmd.Parameters.AddWithValue("?MESANO_REF", objNfTransicao.MESANO_REF.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CODHASH", objNfTransicao.CODHASH.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CODBARRA_IMAGEM", objNfTransicao.CODBARRA_IMAGEM.ToString().ToUpper());

                    objGerenciadorTransacao.Execute(cmd);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable Select(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {

                    vFILTER = vFILTER + "NUMNF, ";
                    vFILTER = vFILTER + "CODCLAS, ";
                    vFILTER = vFILTER + "MESANO, ";
                    vFILTER = vFILTER + "MESANO_REF, ";
                    vFILTER = vFILTER + "DATAVENC, ";
                    vFILTER = vFILTER + "DATADIVIDA, ";
                    vFILTER = vFILTER + "DATALEIT, ";
                    vFILTER = vFILTER + "DATAAPR, ";
                    vFILTER = vFILTER + "DATAEM, ";
                    vFILTER = vFILTER + "DATALEITANT, ";
                    vFILTER = vFILTER + "DATAPAG, ";
                    vFILTER = vFILTER + "CODHASH, ";
                    vFILTER = vFILTER + "DATAST, ";
                    vFILTER = vFILTER + "FLGST, ";
                    vFILTER = vFILTER + "VALORTOT, ";
                    vFILTER = vFILTER + "ZONA, ";
                    vFILTER = vFILTER + "LIVRO, ";
                    vFILTER = vFILTER + "CONTA, ";
                    vFILTER = vFILTER + "ROTA, ";
                    vFILTER = vFILTER + "CONS_ID, ";
                    vFILTER = vFILTER + "UNID_ID, ";
                    vFILTER = vFILTER + "DATAPROXLEIT, ";
                    vFILTER = vFILTER + "BANARREC, ";
                    vFILTER = vFILTER + "BANIDENT, ";
                    vFILTER = vFILTER + "FLGMEDFAT, ";
                    vFILTER = vFILTER + "TIPOUC, ";
                    vFILTER = vFILTER + "CFOP, ";
                    vFILTER = vFILTER + "ITENSSERV, ";
                    vFILTER = vFILTER + "TA, ";
                    vFILTER = vFILTER + "GRUPO, ";
                    vFILTER = vFILTER + "FASE, ";
                    vFILTER = vFILTER + "TENSAO, ";
                    vFILTER = vFILTER + "NUM_MED, ";
                    vFILTER = vFILTER + "CONST_MED, ";
                    vFILTER = vFILTER + "MOTIVOCANC, ";
                    vFILTER = vFILTER + "BANCO_FATUR, ";
                    vFILTER = vFILTER + "SOCIAL, ";
                    vFILTER = vFILTER + "MULTA, ";
                    vFILTER = vFILTER + "DATAPRAZO, ";
                    vFILTER = vFILTER + "DIAS, ";
                    vFILTER = vFILTER + "VALORLIQ, ";
                    vFILTER = vFILTER + "NSU, ";
                    vFILTER = vFILTER + "CODBARRA, ";
                    vFILTER = vFILTER + "DVCODBARRA, ";
                    vFILTER = vFILTER + "AGRUPA, ";
                    vFILTER = vFILTER + "AGRUPA_ROTA, ";
                    vFILTER = vFILTER + "ITENSIMP, ";
                    vFILTER = vFILTER + "SGDENVIO, ";
                    vFILTER = vFILTER + "MOTIVOPGTO, ";
                    vFILTER = vFILTER + "MOTIVOSEGVIA, ";
                    vFILTER = vFILTER + "USUARIOSEGVIA, ";
                    vFILTER = vFILTER + "DATASEGVIA, ";
                    vFILTER = vFILTER + "CPF_CNPJ, ";
                    vFILTER = vFILTER + "PARCIALMENTE_CATIVO, ";
                    vFILTER = vFILTER + "LIVREESPECIAL, ";
                    vFILTER = vFILTER + "PERIODO_TESTE, ";
                    vFILTER = vFILTER + "MENSAGEM_BANDEIRA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO, ";
                    vFILTER = vFILTER + "IRRIGACAO_AQUICULTURA, ";
                    vFILTER = vFILTER + "AGRUPA_CADERNO, ";
                    vFILTER = vFILTER + "AGRUPA_SEQUENCIA, ";
                    vFILTER = vFILTER + "CADERNO, ";
                    vFILTER = vFILTER + "CADERNO_SEQUENCIA, ";
                    vFILTER = vFILTER + "ROTA_QUATRO, ";
                    vFILTER = vFILTER + "AGENCIA, ";
                    vFILTER = vFILTER + "CONTA_CORRENTE, ";
                    vFILTER = vFILTER + "LIVRE_VERDE, ";
                    vFILTER = vFILTER + "CANCELADA_MESANO, ";
                    vFILTER = vFILTER + "CANCELADA_NUMNF, ";
                    vFILTER = vFILTER + "ENVIO_BCO, ";
                    vFILTER = vFILTER + "FATURA_FINAL, ";
                    vFILTER = vFILTER + "PAG_GOV, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_DISTRIBUIDA, ";
                    vFILTER = vFILTER + "USINA, ";
                    vFILTER = vFILTER + "SUPRIMENTO, ";
                    vFILTER = vFILTER + "BAIXA_NFV, ";
                    vFILTER = vFILTER + "SITE_ENVIO, ";
                    vFILTER = vFILTER + "TARIFA_BRANCA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_CONVENIO_SEFAZ, ";
                    vFILTER = vFILTER + "REGIAO, ";
                    vFILTER = vFILTER + "FATURA_COMPLEMENTAR  ";

                    vINNERJOIN = " ";

                    vORDERBY = " ";


                    if (objNfTransicao.MESANO_REF != 0)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND MESANO_REF = ?MESANO_REF "; }
                        else
                        { vAND = "AND MESANO_REF = ?MESANO_REF "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = " "; }
                    }


                    if (objNfTransicao.CONS_ID != 0)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND CONS_ID = ?CONS_ID "; }
                        else
                        { vAND = "AND CONS_ID = ?CONS_ID "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = " "; }
                    }


                    if (objNfTransicao.UNID_ID != 0)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND UNID_ID = ?UNID_ID "; }
                        else
                        { vAND = "AND UNID_ID = ?UNID_ID "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = " "; }
                    }


                    if (objNfTransicao.ZONA != string.Empty)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND ZONA = ?ZONA "; }
                        else
                        { vAND = "AND ZONA = ?ZONA "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = " "; }
                    }

                    if (objNfTransicao.LIVRO != string.Empty)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND LIVRO = ?LIVRO "; }
                        else
                        { vAND = "AND LIVRO = ?LIVRO "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = " "; }
                    }


                    if (objNfTransicao.CONTA != string.Empty)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND CONTA = ?CONTA "; }
                        else
                        { vAND = "AND CONTA = ?CONTA "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = " "; }
                    }


                    if (objNfTransicao.GRUPO != string.Empty)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND GRUPO = ?GRUPO "; }
                        else
                        { vAND = "AND GRUPO = ?GRUPO "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = " "; }
                    }

                    cmd = new MySqlCommand(this.QuerySelect);

                    if (objNfTransicao.MESANO_REF != 0)
                    {
                        cmd.Parameters.AddWithValue("?MESANO_REF", objNfTransicao.MESANO_REF);
                    }

                    if (objNfTransicao.CONS_ID != 0)
                    {
                        cmd.Parameters.AddWithValue("?CONS_ID", objNfTransicao.CONS_ID);
                    }

                    if (objNfTransicao.UNID_ID != 0)
                    {
                        cmd.Parameters.AddWithValue("?UNID_ID", objNfTransicao.UNID_ID);
                    }

                    if (objNfTransicao.ZONA != string.Empty)
                    {
                        cmd.Parameters.AddWithValue("?ZONA", objNfTransicao.ZONA.ToString().ToUpper());
                    }

                    if (objNfTransicao.LIVRO != string.Empty)
                    {
                        cmd.Parameters.AddWithValue("?LIVRO", objNfTransicao.LIVRO.ToString().ToUpper());
                    }

                    if (objNfTransicao.CONTA != string.Empty)
                    {
                        cmd.Parameters.AddWithValue("?CONTA", objNfTransicao.CONTA.ToString().ToUpper());
                    }

                    if (objNfTransicao.GRUPO != string.Empty)
                    {
                        cmd.Parameters.AddWithValue("?GRUPO", objNfTransicao.GRUPO.ToString().ToUpper());
                    }


                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

                return dt;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable Select_1(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {
                    vFILTER = vFILTER + "NUMNF, ";
                    vFILTER = vFILTER + "CODCLAS, ";
                    vFILTER = vFILTER + "MESANO, ";
                    vFILTER = vFILTER + "MESANO_REF, ";
                    vFILTER = vFILTER + "DATAVENC, ";
                    vFILTER = vFILTER + "DATADIVIDA, ";
                    vFILTER = vFILTER + "DATALEIT, ";
                    vFILTER = vFILTER + "DATAAPR, ";
                    vFILTER = vFILTER + "DATAEM, ";
                    vFILTER = vFILTER + "DATALEITANT, ";
                    vFILTER = vFILTER + "DATAPAG, ";
                    vFILTER = vFILTER + "CODHASH, ";
                    vFILTER = vFILTER + "DATAST, ";
                    vFILTER = vFILTER + "FLGST, ";
                    vFILTER = vFILTER + "VALORTOT, ";
                    vFILTER = vFILTER + "ZONA, ";
                    vFILTER = vFILTER + "LIVRO, ";
                    vFILTER = vFILTER + "CONTA, ";
                    vFILTER = vFILTER + "ROTA, ";
                    vFILTER = vFILTER + "CONS_ID, ";
                    vFILTER = vFILTER + "UNID_ID, ";
                    vFILTER = vFILTER + "DATAPROXLEIT, ";
                    vFILTER = vFILTER + "BANARREC, ";
                    vFILTER = vFILTER + "BANIDENT, ";
                    vFILTER = vFILTER + "FLGMEDFAT, ";
                    vFILTER = vFILTER + "TIPOUC, ";
                    vFILTER = vFILTER + "CFOP, ";
                    vFILTER = vFILTER + "ITENSSERV, ";
                    vFILTER = vFILTER + "TA, ";
                    vFILTER = vFILTER + "GRUPO, ";
                    vFILTER = vFILTER + "FASE, ";
                    vFILTER = vFILTER + "TENSAO, ";
                    vFILTER = vFILTER + "NUM_MED, ";
                    vFILTER = vFILTER + "CONST_MED, ";
                    vFILTER = vFILTER + "MOTIVOCANC, ";
                    vFILTER = vFILTER + "BANCO_FATUR, ";
                    vFILTER = vFILTER + "SOCIAL, ";
                    vFILTER = vFILTER + "MULTA, ";
                    vFILTER = vFILTER + "DATAPRAZO, ";
                    vFILTER = vFILTER + "DIAS, ";
                    vFILTER = vFILTER + "VALORLIQ, ";
                    vFILTER = vFILTER + "NSU, ";
                    vFILTER = vFILTER + "CODBARRA, ";
                    vFILTER = vFILTER + "DVCODBARRA, ";
                    vFILTER = vFILTER + "AGRUPA, ";
                    vFILTER = vFILTER + "AGRUPA_ROTA, ";
                    vFILTER = vFILTER + "ITENSIMP, ";
                    vFILTER = vFILTER + "SGDENVIO, ";
                    vFILTER = vFILTER + "MOTIVOPGTO, ";
                    vFILTER = vFILTER + "MOTIVOSEGVIA, ";
                    vFILTER = vFILTER + "USUARIOSEGVIA, ";
                    vFILTER = vFILTER + "DATASEGVIA, ";
                    vFILTER = vFILTER + "CPF_CNPJ, ";
                    vFILTER = vFILTER + "PARCIALMENTE_CATIVO, ";
                    vFILTER = vFILTER + "LIVREESPECIAL, ";
                    vFILTER = vFILTER + "PERIODO_TESTE, ";
                    vFILTER = vFILTER + "MENSAGEM_BANDEIRA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO, ";
                    vFILTER = vFILTER + "IRRIGACAO_AQUICULTURA, ";
                    vFILTER = vFILTER + "AGRUPA_CADERNO, ";
                    vFILTER = vFILTER + "AGRUPA_SEQUENCIA, ";
                    vFILTER = vFILTER + "CADERNO, ";
                    vFILTER = vFILTER + "CADERNO_SEQUENCIA, ";
                    vFILTER = vFILTER + "ROTA_QUATRO, ";
                    vFILTER = vFILTER + "AGENCIA, ";
                    vFILTER = vFILTER + "CONTA_CORRENTE, ";
                    vFILTER = vFILTER + "LIVRE_VERDE, ";
                    vFILTER = vFILTER + "CANCELADA_MESANO, ";
                    vFILTER = vFILTER + "CANCELADA_NUMNF, ";
                    vFILTER = vFILTER + "ENVIO_BCO, ";
                    vFILTER = vFILTER + "FATURA_FINAL, ";
                    vFILTER = vFILTER + "PAG_GOV, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_DISTRIBUIDA, ";
                    vFILTER = vFILTER + "USINA, ";
                    vFILTER = vFILTER + "SUPRIMENTO, ";
                    vFILTER = vFILTER + "BAIXA_NFV, ";
                    vFILTER = vFILTER + "SITE_ENVIO, ";
                    vFILTER = vFILTER + "TARIFA_BRANCA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_CONVENIO_SEFAZ, ";
                    vFILTER = vFILTER + "REGIAO, ";
                    vFILTER = vFILTER + "FATURA_COMPLEMENTAR  ";

                    vINNERJOIN = " ";

                    vORDERBY = " ";

                    if (vAND != String.Empty)
                    { vAND = vAND + "AND FLGST in (?FLGST) "; }
                    else
                    { vAND = "AND FLGST in (?FLGST) "; }

                    if (objNfTransicao.CONS_ID != 0)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND CONS_ID = ?CONS_ID "; }
                        else
                        { vAND = "AND CONS_ID = ?CONS_ID "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = " "; }
                    }


                    if (objNfTransicao.UNID_ID != 0)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND UNID_ID = ?UNID_ID "; }
                        else
                        { vAND = "AND UNID_ID = ?UNID_ID "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = " "; }
                    }


                    if (objNfTransicao.ZONA != string.Empty)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND ZONA = ?ZONA "; }
                        else
                        { vAND = "AND ZONA = ?ZONA "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = " "; }
                    }

                    if (objNfTransicao.LIVRO != string.Empty)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND LIVRO = ?LIVRO "; }
                        else
                        { vAND = "AND LIVRO = ?LIVRO "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = " "; }
                    }


                    if (objNfTransicao.CONTA != string.Empty)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND CONTA = ?CONTA "; }
                        else
                        { vAND = "AND CONTA = ?CONTA "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = " "; }
                    }


                    cmd = new MySqlCommand(this.QuerySelect);

                    cmd.Parameters.AddWithValue("?FLGST", objNfTransicao.FLGST.ToString().ToUpper());

                    if (objNfTransicao.CONS_ID != 0)
                    {
                        cmd.Parameters.AddWithValue("?CONS_ID", objNfTransicao.CONS_ID);
                    }

                    if (objNfTransicao.UNID_ID != 0)
                    {
                        cmd.Parameters.AddWithValue("?UNID_ID", objNfTransicao.UNID_ID);
                    }

                    if (objNfTransicao.ZONA != string.Empty)
                    {
                        cmd.Parameters.AddWithValue("?ZONA", objNfTransicao.ZONA.ToString().ToUpper());
                    }

                    if (objNfTransicao.LIVRO != string.Empty)
                    {
                        cmd.Parameters.AddWithValue("?LIVRO", objNfTransicao.LIVRO.ToString().ToUpper());
                    }

                    if (objNfTransicao.CONTA != string.Empty)
                    {
                        cmd.Parameters.AddWithValue("?CONTA", objNfTransicao.CONTA.ToString().ToUpper());
                    }


                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

                return dt;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable Select_2(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {

                    vFILTER = vFILTER + "DISTINCT MID(NFTRANSICAO.ROTA,1,4) AS ROTA,  ";
                    vFILTER = vFILTER + "MID(NFTRANSICAO.TA,3,1) AS TA,  ";
                    vFILTER = vFILTER + "COUNT(*) as qtde ";

                    vINNERJOIN = vINNERJOIN + "USE INDEX(KEYMESANO, KEYROTA)  ";

                    vORDERBY = vORDERBY + "GROUP BY 1, 2  ";
                    vORDERBY = vORDERBY + "ORDER BY 2 ASC, 1 ASC ";

                    vAND = vAND + " AND NFTRANSICAO.MESANO = ?MESANO ";


                    cmd = new MySqlCommand(this.QuerySelect);

                    cmd.Parameters.AddWithValue("?MESANO", objNfTransicao.MESANO.ToString().ToUpper());


                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

                return dt;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable Select_3(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {
                    vFILTER = vFILTER + "       NFTRANSICAO.ZONA    AS ZONA    , ";
                    vFILTER = vFILTER + "       NFTRANSICAO.LIVRO   AS LIVRO   , ";
                    vFILTER = vFILTER + "       NFTRANSICAO.CONTA   AS CONTA   , ";
                    vFILTER = vFILTER + "       NFTRANSICAO.CONS_ID AS CONS_ID , ";
                    vFILTER = vFILTER + "       NFTRANSICAO.UNID_ID AS UNID_ID , ";
                    vFILTER = vFILTER + "       NFTRANSICAO.ROTA_QUATRO AS ROTA_QUATRO, ";
                    vFILTER = vFILTER + "       SUM(NFTRANSICAO.VALORTOT) AS VALORTOT, ";
                    vFILTER = vFILTER + "       COUNT(NFTRANSICAO.NUMNF) AS NUMNF ";

                    vINNERJOIN = " ";

                    vORDERBY = vORDERBY + " GROUP BY 1 ";

                    vAND = vAND + " AND  NFTRANSICAO.MESANO_REF = ?MESANO_REF ";

                    if (objNfTransicao.MICRO_GERACAO != 2)
                    {
                        if (objNfTransicao.MICRO_GERACAO == 1 && objNfTransicao.MICRO_GERACAO_DISTRIBUIDA == 1)
                        {
                            vAND = vAND + " AND (NFTRANSICAO.MICRO_GERACAO = 1 OR NFTRANSICAO.MICRO_GERACAO_DISTRIBUIDA = 1) ";
                        }
                        else
                        {
                            vAND = vAND + " AND NFTRANSICAO.MICRO_GERACAO = 0 ";
                            vAND = vAND + " AND NFTRANSICAO.MICRO_GERACAO_DISTRIBUIDA = 0 ";
                        }
                    }


                    if (objNfTransicao.ROTA != string.Empty)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND MID(NFTRANSICAO.ROTA,1,4) IN ( " + objNfTransicao.ROTA.ToString().ToUpper() + " ) "; }
                        else
                        { vAND = "AND MID(NFTRANSICAO.ROTA,1,4) IN ( " + objNfTransicao.ROTA.ToString().ToUpper() + " ) "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = " "; }
                    }


                    if (objNfTransicao.ZONA.Trim().Length > 0 && objNfTransicao.LIVRO.Trim().Length > 0 && objNfTransicao.CONTA.Trim().Length > 0)
                    {
                        if (vAND != String.Empty)
                        {
                            vAND = vAND + " AND NFTRANSICAO.ZONA = ?ZONA ";
                            vAND = vAND + " AND NFTRANSICAO.LIVRO = ?LIVRO ";
                            vAND = vAND + " AND NFTRANSICAO.CONTA = ?CONTA ";
                        }
                        else
                        {
                            vAND = vAND + " AND NFTRANSICAO.ZONA = ?ZONA ";
                            vAND = vAND + " AND NFTRANSICAO.LIVRO = ?LIVRO ";
                            vAND = vAND + " AND NFTRANSICAO.CONTA = ?CONTA ";
                        }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = " "; }
                    }


                    cmd = new MySqlCommand(this.QuerySelect);

                    cmd.Parameters.AddWithValue("?MESANO_REF", objNfTransicao.MESANO_REF);

                    if (objNfTransicao.ROTA != string.Empty)
                    {
                        cmd.Parameters.AddWithValue("?ROTA", objNfTransicao.ROTA.ToString().ToUpper());
                    }

                    if (objNfTransicao.ZONA.Trim().Length > 0 && objNfTransicao.LIVRO.Trim().Length > 0 && objNfTransicao.CONTA.Trim().Length > 0)
                    {

                        cmd.Parameters.AddWithValue("?ZONA", objNfTransicao.ZONA.ToString().ToUpper());

                        cmd.Parameters.AddWithValue("?LIVRO", objNfTransicao.LIVRO.ToString().ToUpper());

                        cmd.Parameters.AddWithValue("?CONTA", objNfTransicao.CONTA.ToString().ToUpper());

                    }

                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

                return dt;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable Select_4(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {

                    vFILTER = vFILTER + "NUMNF, ";
                    vFILTER = vFILTER + "CODCLAS, ";
                    vFILTER = vFILTER + "MESANO, ";
                    vFILTER = vFILTER + "MESANO_REF, ";
                    vFILTER = vFILTER + "DATAVENC, ";
                    vFILTER = vFILTER + "DATADIVIDA, ";
                    vFILTER = vFILTER + "DATALEIT, ";
                    vFILTER = vFILTER + "DATAAPR, ";
                    vFILTER = vFILTER + "DATAEM, ";
                    vFILTER = vFILTER + "DATALEITANT, ";
                    vFILTER = vFILTER + "DATAPAG, ";
                    vFILTER = vFILTER + "CODHASH, ";
                    vFILTER = vFILTER + "DATAST, ";
                    vFILTER = vFILTER + "FLGST, ";
                    vFILTER = vFILTER + "VALORTOT, ";
                    vFILTER = vFILTER + "ZONA, ";
                    vFILTER = vFILTER + "LIVRO, ";
                    vFILTER = vFILTER + "CONTA, ";
                    vFILTER = vFILTER + "ROTA, ";
                    vFILTER = vFILTER + "CONS_ID, ";
                    vFILTER = vFILTER + "UNID_ID, ";
                    vFILTER = vFILTER + "DATAPROXLEIT, ";
                    vFILTER = vFILTER + "BANARREC, ";
                    vFILTER = vFILTER + "BANIDENT, ";
                    vFILTER = vFILTER + "FLGMEDFAT, ";
                    vFILTER = vFILTER + "TIPOUC, ";
                    vFILTER = vFILTER + "CFOP, ";
                    vFILTER = vFILTER + "ITENSSERV, ";
                    vFILTER = vFILTER + "TA, ";
                    vFILTER = vFILTER + "GRUPO, ";
                    vFILTER = vFILTER + "FASE, ";
                    vFILTER = vFILTER + "TENSAO, ";
                    vFILTER = vFILTER + "NUM_MED, ";
                    vFILTER = vFILTER + "CONST_MED, ";
                    vFILTER = vFILTER + "MOTIVOCANC, ";
                    vFILTER = vFILTER + "BANCO_FATUR, ";
                    vFILTER = vFILTER + "SOCIAL, ";
                    vFILTER = vFILTER + "MULTA, ";
                    vFILTER = vFILTER + "DATAPRAZO, ";
                    vFILTER = vFILTER + "DIAS, ";
                    vFILTER = vFILTER + "VALORLIQ, ";
                    vFILTER = vFILTER + "NSU, ";
                    vFILTER = vFILTER + "CODBARRA, ";
                    vFILTER = vFILTER + "DVCODBARRA, ";
                    vFILTER = vFILTER + "AGRUPA, ";
                    vFILTER = vFILTER + "AGRUPA_ROTA, ";
                    vFILTER = vFILTER + "ITENSIMP, ";
                    vFILTER = vFILTER + "SGDENVIO, ";
                    vFILTER = vFILTER + "MOTIVOPGTO, ";
                    vFILTER = vFILTER + "MOTIVOSEGVIA, ";
                    vFILTER = vFILTER + "USUARIOSEGVIA, ";
                    vFILTER = vFILTER + "DATASEGVIA, ";
                    vFILTER = vFILTER + "CPF_CNPJ, ";
                    vFILTER = vFILTER + "PARCIALMENTE_CATIVO, ";
                    vFILTER = vFILTER + "LIVREESPECIAL, ";
                    vFILTER = vFILTER + "PERIODO_TESTE, ";
                    vFILTER = vFILTER + "MENSAGEM_BANDEIRA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO, ";
                    vFILTER = vFILTER + "IRRIGACAO_AQUICULTURA, ";
                    vFILTER = vFILTER + "AGRUPA_CADERNO, ";
                    vFILTER = vFILTER + "AGRUPA_SEQUENCIA, ";
                    vFILTER = vFILTER + "CADERNO, ";
                    vFILTER = vFILTER + "CADERNO_SEQUENCIA, ";
                    vFILTER = vFILTER + "ROTA_QUATRO, ";
                    vFILTER = vFILTER + "AGENCIA, ";
                    vFILTER = vFILTER + "CONTA_CORRENTE, ";
                    vFILTER = vFILTER + "LIVRE_VERDE, ";
                    vFILTER = vFILTER + "CANCELADA_MESANO, ";
                    vFILTER = vFILTER + "CANCELADA_NUMNF, ";
                    vFILTER = vFILTER + "ENVIO_BCO, ";
                    vFILTER = vFILTER + "FATURA_FINAL, ";
                    vFILTER = vFILTER + "PAG_GOV, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_DISTRIBUIDA, ";
                    vFILTER = vFILTER + "USINA, ";
                    vFILTER = vFILTER + "SUPRIMENTO, ";
                    vFILTER = vFILTER + "BAIXA_NFV, ";
                    vFILTER = vFILTER + "SITE_ENVIO, ";
                    vFILTER = vFILTER + "TARIFA_BRANCA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_CONVENIO_SEFAZ, ";
                    vFILTER = vFILTER + "REGIAO, ";
                    vFILTER = vFILTER + "FATURA_COMPLEMENTAR  ";

                    vINNERJOIN = " ";

                    vORDERBY = "GROUP BY 1 ";


                    vAND = vAND + "   AND  MESANO = ?MESANO ";
                    vAND = vAND + "   AND GRUPO = ?GRUPO ";
                    vAND = vAND + "   AND FATURA_COMPLEMENTAR " + objNfTransicao.AGENCIA.ToString() + " ?FATURA_COMPLEMENTAR ";


                    cmd = new MySqlCommand(this.QuerySelect);

                    cmd.Parameters.AddWithValue("?MESANO", objNfTransicao.MESANO);
                    cmd.Parameters.AddWithValue("?GRUPO", objNfTransicao.GRUPO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?FATURA_COMPLEMENTAR", objNfTransicao.FATURA_COMPLEMENTAR);


                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

                return dt;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable Select_5(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {

                    vFILTER = vFILTER + "NUMNF, ";
                    vFILTER = vFILTER + "CODCLAS, ";
                    vFILTER = vFILTER + "MESANO, ";
                    vFILTER = vFILTER + "MESANO_REF, ";
                    vFILTER = vFILTER + "DATAVENC, ";
                    vFILTER = vFILTER + "DATADIVIDA, ";
                    vFILTER = vFILTER + "DATALEIT, ";
                    vFILTER = vFILTER + "DATAAPR, ";
                    vFILTER = vFILTER + "DATAEM, ";
                    vFILTER = vFILTER + "DATALEITANT, ";
                    vFILTER = vFILTER + "DATAPAG, ";
                    vFILTER = vFILTER + "CODHASH, ";
                    vFILTER = vFILTER + "DATAST, ";
                    vFILTER = vFILTER + "FLGST, ";
                    vFILTER = vFILTER + "VALORTOT, ";
                    vFILTER = vFILTER + "ZONA, ";
                    vFILTER = vFILTER + "LIVRO, ";
                    vFILTER = vFILTER + "CONTA, ";
                    vFILTER = vFILTER + "ROTA, ";
                    vFILTER = vFILTER + "CONS_ID, ";
                    vFILTER = vFILTER + "UNID_ID, ";
                    vFILTER = vFILTER + "DATAPROXLEIT, ";
                    vFILTER = vFILTER + "BANARREC, ";
                    vFILTER = vFILTER + "BANIDENT, ";
                    vFILTER = vFILTER + "FLGMEDFAT, ";
                    vFILTER = vFILTER + "TIPOUC, ";
                    vFILTER = vFILTER + "CFOP, ";
                    vFILTER = vFILTER + "ITENSSERV, ";
                    vFILTER = vFILTER + "TA, ";
                    vFILTER = vFILTER + "GRUPO, ";
                    vFILTER = vFILTER + "FASE, ";
                    vFILTER = vFILTER + "TENSAO, ";
                    vFILTER = vFILTER + "NUM_MED, ";
                    vFILTER = vFILTER + "CONST_MED, ";
                    vFILTER = vFILTER + "MOTIVOCANC, ";
                    vFILTER = vFILTER + "BANCO_FATUR, ";
                    vFILTER = vFILTER + "SOCIAL, ";
                    vFILTER = vFILTER + "MULTA, ";
                    vFILTER = vFILTER + "DATAPRAZO, ";
                    vFILTER = vFILTER + "DIAS, ";
                    vFILTER = vFILTER + "VALORLIQ, ";
                    vFILTER = vFILTER + "NSU, ";
                    vFILTER = vFILTER + "CODBARRA, ";
                    vFILTER = vFILTER + "DVCODBARRA, ";
                    vFILTER = vFILTER + "AGRUPA, ";
                    vFILTER = vFILTER + "AGRUPA_ROTA, ";
                    vFILTER = vFILTER + "ITENSIMP, ";
                    vFILTER = vFILTER + "SGDENVIO, ";
                    vFILTER = vFILTER + "MOTIVOPGTO, ";
                    vFILTER = vFILTER + "MOTIVOSEGVIA, ";
                    vFILTER = vFILTER + "USUARIOSEGVIA, ";
                    vFILTER = vFILTER + "DATASEGVIA, ";
                    vFILTER = vFILTER + "CPF_CNPJ, ";
                    vFILTER = vFILTER + "PARCIALMENTE_CATIVO, ";
                    vFILTER = vFILTER + "LIVREESPECIAL, ";
                    vFILTER = vFILTER + "PERIODO_TESTE, ";
                    vFILTER = vFILTER + "MENSAGEM_BANDEIRA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO, ";
                    vFILTER = vFILTER + "IRRIGACAO_AQUICULTURA, ";
                    vFILTER = vFILTER + "AGRUPA_CADERNO, ";
                    vFILTER = vFILTER + "AGRUPA_SEQUENCIA, ";
                    vFILTER = vFILTER + "CADERNO, ";
                    vFILTER = vFILTER + "CADERNO_SEQUENCIA, ";
                    vFILTER = vFILTER + "ROTA_QUATRO, ";
                    vFILTER = vFILTER + "AGENCIA, ";
                    vFILTER = vFILTER + "CONTA_CORRENTE, ";
                    vFILTER = vFILTER + "LIVRE_VERDE, ";
                    vFILTER = vFILTER + "CANCELADA_MESANO, ";
                    vFILTER = vFILTER + "CANCELADA_NUMNF, ";
                    vFILTER = vFILTER + "ENVIO_BCO, ";
                    vFILTER = vFILTER + "FATURA_FINAL, ";
                    vFILTER = vFILTER + "PAG_GOV, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_DISTRIBUIDA, ";
                    vFILTER = vFILTER + "USINA, ";
                    vFILTER = vFILTER + "SUPRIMENTO, ";
                    vFILTER = vFILTER + "BAIXA_NFV, ";
                    vFILTER = vFILTER + "SITE_ENVIO, ";
                    vFILTER = vFILTER + "TARIFA_BRANCA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_CONVENIO_SEFAZ, ";
                    vFILTER = vFILTER + "REGIAO, ";
                    vFILTER = vFILTER + "FATURA_COMPLEMENTAR  ";

                    vINNERJOIN = " ";

                    vORDERBY = " ";


                    if (objNfTransicao.MESANO != string.Empty)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND MESANO = ?MESANO "; }
                        else
                        { vAND = "AND MESANO = ?MESANO "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = " "; }
                    }


                    if (objNfTransicao.CONS_ID != 0)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND CONS_ID = ?CONS_ID "; }
                        else
                        { vAND = "AND CONS_ID = ?CONS_ID "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = " "; }
                    }


                    if (objNfTransicao.UNID_ID != 0)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND UNID_ID = ?UNID_ID "; }
                        else
                        { vAND = "AND UNID_ID = ?UNID_ID "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = " "; }
                    }



                    cmd = new MySqlCommand(this.QuerySelect);

                    if (objNfTransicao.MESANO != string.Empty)
                    {
                        cmd.Parameters.AddWithValue("?MESANO", objNfTransicao.MESANO.ToString().ToUpper());
                    }

                    if (objNfTransicao.CONS_ID != 0)
                    {
                        cmd.Parameters.AddWithValue("?CONS_ID", objNfTransicao.CONS_ID);
                    }

                    if (objNfTransicao.UNID_ID != 0)
                    {
                        cmd.Parameters.AddWithValue("?UNID_ID", objNfTransicao.UNID_ID);
                    }


                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

                return dt;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable Select_6(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {

                    vFILTER = vFILTER + "NUMNF, ";
                    vFILTER = vFILTER + "CODCLAS, ";
                    vFILTER = vFILTER + "MESANO, ";
                    vFILTER = vFILTER + "MESANO_REF, ";
                    vFILTER = vFILTER + "DATAVENC, ";
                    vFILTER = vFILTER + "DATADIVIDA, ";
                    vFILTER = vFILTER + "DATALEIT, ";
                    vFILTER = vFILTER + "DATAAPR, ";
                    vFILTER = vFILTER + "DATAEM, ";
                    vFILTER = vFILTER + "DATALEITANT, ";
                    vFILTER = vFILTER + "DATAPAG, ";
                    vFILTER = vFILTER + "CODHASH, ";
                    vFILTER = vFILTER + "DATAST, ";
                    vFILTER = vFILTER + "FLGST, ";
                    vFILTER = vFILTER + "VALORTOT, ";
                    vFILTER = vFILTER + "ZONA, ";
                    vFILTER = vFILTER + "LIVRO, ";
                    vFILTER = vFILTER + "CONTA, ";
                    vFILTER = vFILTER + "ROTA, ";
                    vFILTER = vFILTER + "CONS_ID, ";
                    vFILTER = vFILTER + "UNID_ID, ";
                    vFILTER = vFILTER + "DATAPROXLEIT, ";
                    vFILTER = vFILTER + "BANARREC, ";
                    vFILTER = vFILTER + "BANIDENT, ";
                    vFILTER = vFILTER + "FLGMEDFAT, ";
                    vFILTER = vFILTER + "TIPOUC, ";
                    vFILTER = vFILTER + "CFOP, ";
                    vFILTER = vFILTER + "ITENSSERV, ";
                    vFILTER = vFILTER + "TA, ";
                    vFILTER = vFILTER + "GRUPO, ";
                    vFILTER = vFILTER + "FASE, ";
                    vFILTER = vFILTER + "TENSAO, ";
                    vFILTER = vFILTER + "NUM_MED, ";
                    vFILTER = vFILTER + "CONST_MED, ";
                    vFILTER = vFILTER + "MOTIVOCANC, ";
                    vFILTER = vFILTER + "BANCO_FATUR, ";
                    vFILTER = vFILTER + "SOCIAL, ";
                    vFILTER = vFILTER + "MULTA, ";
                    vFILTER = vFILTER + "DATAPRAZO, ";
                    vFILTER = vFILTER + "DIAS, ";
                    vFILTER = vFILTER + "VALORLIQ, ";
                    vFILTER = vFILTER + "NSU, ";
                    vFILTER = vFILTER + "CODBARRA, ";
                    vFILTER = vFILTER + "DVCODBARRA, ";
                    vFILTER = vFILTER + "AGRUPA, ";
                    vFILTER = vFILTER + "AGRUPA_ROTA, ";
                    vFILTER = vFILTER + "ITENSIMP, ";
                    vFILTER = vFILTER + "SGDENVIO, ";
                    vFILTER = vFILTER + "MOTIVOPGTO, ";
                    vFILTER = vFILTER + "MOTIVOSEGVIA, ";
                    vFILTER = vFILTER + "USUARIOSEGVIA, ";
                    vFILTER = vFILTER + "DATASEGVIA, ";
                    vFILTER = vFILTER + "CPF_CNPJ, ";
                    vFILTER = vFILTER + "PARCIALMENTE_CATIVO, ";
                    vFILTER = vFILTER + "LIVREESPECIAL, ";
                    vFILTER = vFILTER + "PERIODO_TESTE, ";
                    vFILTER = vFILTER + "MENSAGEM_BANDEIRA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO, ";
                    vFILTER = vFILTER + "IRRIGACAO_AQUICULTURA, ";
                    vFILTER = vFILTER + "AGRUPA_CADERNO, ";
                    vFILTER = vFILTER + "AGRUPA_SEQUENCIA, ";
                    vFILTER = vFILTER + "CADERNO, ";
                    vFILTER = vFILTER + "CADERNO_SEQUENCIA, ";
                    vFILTER = vFILTER + "ROTA_QUATRO, ";
                    vFILTER = vFILTER + "AGENCIA, ";
                    vFILTER = vFILTER + "CONTA_CORRENTE, ";
                    vFILTER = vFILTER + "LIVRE_VERDE, ";
                    vFILTER = vFILTER + "CANCELADA_MESANO, ";
                    vFILTER = vFILTER + "CANCELADA_NUMNF, ";
                    vFILTER = vFILTER + "ENVIO_BCO, ";
                    vFILTER = vFILTER + "FATURA_FINAL, ";
                    vFILTER = vFILTER + "PAG_GOV, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_DISTRIBUIDA, ";
                    vFILTER = vFILTER + "USINA, ";
                    vFILTER = vFILTER + "SUPRIMENTO, ";
                    vFILTER = vFILTER + "BAIXA_NFV, ";
                    vFILTER = vFILTER + "SITE_ENVIO, ";
                    vFILTER = vFILTER + "TARIFA_BRANCA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_CONVENIO_SEFAZ, ";
                    vFILTER = vFILTER + "REGIAO, ";
                    vFILTER = vFILTER + "FATURA_COMPLEMENTAR  ";

                    vINNERJOIN = " ";

                    vORDERBY = " ";

                    vAND = vAND + " AND ZONA = ?ZONA  ";
                    vAND = vAND + " AND LIVRO = ?LIVRO  ";
                    vAND = vAND + " AND CONTA = ?CONTA ";
                    vAND = vAND + " AND MESANO = ?MESANO ";
                    vAND = vAND + " AND CONS_ID = ?CONS_ID ";
                    vAND = vAND + " AND UNID_ID = ?UNID_ID ";


                    cmd = new MySqlCommand(this.QuerySelect);

                    cmd.Parameters.AddWithValue("?ZONA", objNfTransicao.ZONA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LIVRO", objNfTransicao.LIVRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTA", objNfTransicao.CONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MESANO", objNfTransicao.MESANO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONS_ID", objNfTransicao.CONS_ID);
                    cmd.Parameters.AddWithValue("?UNID_ID", objNfTransicao.UNID_ID);



                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

                return dt;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable Select_7(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {

                    vFILTER = vFILTER + "NUMNF, ";
                    vFILTER = vFILTER + "CODCLAS, ";
                    vFILTER = vFILTER + "MESANO, ";
                    vFILTER = vFILTER + "MESANO_REF, ";
                    vFILTER = vFILTER + "DATAVENC, ";
                    vFILTER = vFILTER + "DATADIVIDA, ";
                    vFILTER = vFILTER + "DATALEIT, ";
                    vFILTER = vFILTER + "DATAAPR, ";
                    vFILTER = vFILTER + "DATAEM, ";
                    vFILTER = vFILTER + "DATALEITANT, ";
                    vFILTER = vFILTER + "DATAPAG, ";
                    vFILTER = vFILTER + "CODHASH, ";
                    vFILTER = vFILTER + "DATAST, ";
                    vFILTER = vFILTER + "FLGST, ";
                    vFILTER = vFILTER + "VALORTOT, ";
                    vFILTER = vFILTER + "ZONA, ";
                    vFILTER = vFILTER + "LIVRO, ";
                    vFILTER = vFILTER + "CONTA, ";
                    vFILTER = vFILTER + "ROTA, ";
                    vFILTER = vFILTER + "CONS_ID, ";
                    vFILTER = vFILTER + "UNID_ID, ";
                    vFILTER = vFILTER + "DATAPROXLEIT, ";
                    vFILTER = vFILTER + "BANARREC, ";
                    vFILTER = vFILTER + "BANIDENT, ";
                    vFILTER = vFILTER + "FLGMEDFAT, ";
                    vFILTER = vFILTER + "TIPOUC, ";
                    vFILTER = vFILTER + "CFOP, ";
                    vFILTER = vFILTER + "ITENSSERV, ";
                    vFILTER = vFILTER + "TA, ";
                    vFILTER = vFILTER + "GRUPO, ";
                    vFILTER = vFILTER + "FASE, ";
                    vFILTER = vFILTER + "TENSAO, ";
                    vFILTER = vFILTER + "NUM_MED, ";
                    vFILTER = vFILTER + "CONST_MED, ";
                    vFILTER = vFILTER + "MOTIVOCANC, ";
                    vFILTER = vFILTER + "BANCO_FATUR, ";
                    vFILTER = vFILTER + "SOCIAL, ";
                    vFILTER = vFILTER + "MULTA, ";
                    vFILTER = vFILTER + "DATAPRAZO, ";
                    vFILTER = vFILTER + "DIAS, ";
                    vFILTER = vFILTER + "VALORLIQ, ";
                    vFILTER = vFILTER + "NSU, ";
                    vFILTER = vFILTER + "CODBARRA, ";
                    vFILTER = vFILTER + "DVCODBARRA, ";
                    vFILTER = vFILTER + "AGRUPA, ";
                    vFILTER = vFILTER + "AGRUPA_ROTA, ";
                    vFILTER = vFILTER + "ITENSIMP, ";
                    vFILTER = vFILTER + "SGDENVIO, ";
                    vFILTER = vFILTER + "MOTIVOPGTO, ";
                    vFILTER = vFILTER + "MOTIVOSEGVIA, ";
                    vFILTER = vFILTER + "USUARIOSEGVIA, ";
                    vFILTER = vFILTER + "DATASEGVIA, ";
                    vFILTER = vFILTER + "CPF_CNPJ, ";
                    vFILTER = vFILTER + "PARCIALMENTE_CATIVO, ";
                    vFILTER = vFILTER + "LIVREESPECIAL, ";
                    vFILTER = vFILTER + "PERIODO_TESTE, ";
                    vFILTER = vFILTER + "MENSAGEM_BANDEIRA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO, ";
                    vFILTER = vFILTER + "IRRIGACAO_AQUICULTURA, ";
                    vFILTER = vFILTER + "AGRUPA_CADERNO, ";
                    vFILTER = vFILTER + "AGRUPA_SEQUENCIA, ";
                    vFILTER = vFILTER + "CADERNO, ";
                    vFILTER = vFILTER + "CADERNO_SEQUENCIA, ";
                    vFILTER = vFILTER + "ROTA_QUATRO, ";
                    vFILTER = vFILTER + "AGENCIA, ";
                    vFILTER = vFILTER + "CONTA_CORRENTE, ";
                    vFILTER = vFILTER + "LIVRE_VERDE, ";
                    vFILTER = vFILTER + "CANCELADA_MESANO, ";
                    vFILTER = vFILTER + "CANCELADA_NUMNF, ";
                    vFILTER = vFILTER + "ENVIO_BCO, ";
                    vFILTER = vFILTER + "FATURA_FINAL, ";
                    vFILTER = vFILTER + "PAG_GOV, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_DISTRIBUIDA, ";
                    vFILTER = vFILTER + "USINA, ";
                    vFILTER = vFILTER + "SUPRIMENTO, ";
                    vFILTER = vFILTER + "BAIXA_NFV, ";
                    vFILTER = vFILTER + "SITE_ENVIO, ";
                    vFILTER = vFILTER + "TARIFA_BRANCA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_CONVENIO_SEFAZ, ";
                    vFILTER = vFILTER + "REGIAO, ";
                    vFILTER = vFILTER + "FATURA_COMPLEMENTAR  ";

                    vINNERJOIN = " ";

                    vORDERBY = " ";

                    vAND = vAND + "AND CONS_ID = ?CONS_ID ";
                    vAND = vAND + "AND UNID_ID = ?UNID_ID ";
                    vAND = vAND + "AND FATURA_COMPLEMENTAR = ?FATURA_COMPLEMENTAR ";
                    vAND = vAND + "AND GRUPO = ?GRUPO ";


                    cmd = new MySqlCommand(this.QuerySelect);

                    cmd.Parameters.AddWithValue("?CONS_ID", objNfTransicao.CONS_ID);
                    cmd.Parameters.AddWithValue("?UNID_ID", objNfTransicao.UNID_ID);
                    cmd.Parameters.AddWithValue("?FATURA_COMPLEMENTAR", objNfTransicao.FATURA_COMPLEMENTAR);
                    cmd.Parameters.AddWithValue("?GRUPO", objNfTransicao.GRUPO.ToString().ToUpper());
                

                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

                return dt;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable Select_8(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {

                    vFILTER = vFILTER + "NUMNF, ";
                    vFILTER = vFILTER + "CODCLAS, ";
                    vFILTER = vFILTER + "MESANO, ";
                    vFILTER = vFILTER + "MESANO_REF, ";
                    vFILTER = vFILTER + "DATAVENC, ";
                    vFILTER = vFILTER + "DATADIVIDA, ";
                    vFILTER = vFILTER + "DATALEIT, ";
                    vFILTER = vFILTER + "DATAAPR, ";
                    vFILTER = vFILTER + "DATAEM, ";
                    vFILTER = vFILTER + "DATALEITANT, ";
                    vFILTER = vFILTER + "DATAPAG, ";
                    vFILTER = vFILTER + "CODHASH, ";
                    vFILTER = vFILTER + "DATAST, ";
                    vFILTER = vFILTER + "FLGST, ";
                    vFILTER = vFILTER + "VALORTOT, ";
                    vFILTER = vFILTER + "ZONA, ";
                    vFILTER = vFILTER + "LIVRO, ";
                    vFILTER = vFILTER + "CONTA, ";
                    vFILTER = vFILTER + "ROTA, ";
                    vFILTER = vFILTER + "CONS_ID, ";
                    vFILTER = vFILTER + "UNID_ID, ";
                    vFILTER = vFILTER + "DATAPROXLEIT, ";
                    vFILTER = vFILTER + "BANARREC, ";
                    vFILTER = vFILTER + "BANIDENT, ";
                    vFILTER = vFILTER + "FLGMEDFAT, ";
                    vFILTER = vFILTER + "TIPOUC, ";
                    vFILTER = vFILTER + "CFOP, ";
                    vFILTER = vFILTER + "ITENSSERV, ";
                    vFILTER = vFILTER + "TA, ";
                    vFILTER = vFILTER + "GRUPO, ";
                    vFILTER = vFILTER + "FASE, ";
                    vFILTER = vFILTER + "TENSAO, ";
                    vFILTER = vFILTER + "NUM_MED, ";
                    vFILTER = vFILTER + "CONST_MED, ";
                    vFILTER = vFILTER + "MOTIVOCANC, ";
                    vFILTER = vFILTER + "BANCO_FATUR, ";
                    vFILTER = vFILTER + "SOCIAL, ";
                    vFILTER = vFILTER + "MULTA, ";
                    vFILTER = vFILTER + "DATAPRAZO, ";
                    vFILTER = vFILTER + "DIAS, ";
                    vFILTER = vFILTER + "VALORLIQ, ";
                    vFILTER = vFILTER + "NSU, ";
                    vFILTER = vFILTER + "CODBARRA, ";
                    vFILTER = vFILTER + "DVCODBARRA, ";
                    vFILTER = vFILTER + "AGRUPA, ";
                    vFILTER = vFILTER + "AGRUPA_ROTA, ";
                    vFILTER = vFILTER + "ITENSIMP, ";
                    vFILTER = vFILTER + "SGDENVIO, ";
                    vFILTER = vFILTER + "MOTIVOPGTO, ";
                    vFILTER = vFILTER + "MOTIVOSEGVIA, ";
                    vFILTER = vFILTER + "USUARIOSEGVIA, ";
                    vFILTER = vFILTER + "DATASEGVIA, ";
                    vFILTER = vFILTER + "CPF_CNPJ, ";
                    vFILTER = vFILTER + "PARCIALMENTE_CATIVO, ";
                    vFILTER = vFILTER + "LIVREESPECIAL, ";
                    vFILTER = vFILTER + "PERIODO_TESTE, ";
                    vFILTER = vFILTER + "MENSAGEM_BANDEIRA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO, ";
                    vFILTER = vFILTER + "IRRIGACAO_AQUICULTURA, ";
                    vFILTER = vFILTER + "AGRUPA_CADERNO, ";
                    vFILTER = vFILTER + "AGRUPA_SEQUENCIA, ";
                    vFILTER = vFILTER + "CADERNO, ";
                    vFILTER = vFILTER + "CADERNO_SEQUENCIA, ";
                    vFILTER = vFILTER + "ROTA_QUATRO, ";
                    vFILTER = vFILTER + "AGENCIA, ";
                    vFILTER = vFILTER + "CONTA_CORRENTE, ";
                    vFILTER = vFILTER + "LIVRE_VERDE, ";
                    vFILTER = vFILTER + "CANCELADA_MESANO, ";
                    vFILTER = vFILTER + "CANCELADA_NUMNF, ";
                    vFILTER = vFILTER + "ENVIO_BCO, ";
                    vFILTER = vFILTER + "FATURA_FINAL, ";
                    vFILTER = vFILTER + "PAG_GOV, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_DISTRIBUIDA, ";
                    vFILTER = vFILTER + "USINA, ";
                    vFILTER = vFILTER + "SUPRIMENTO, ";
                    vFILTER = vFILTER + "BAIXA_NFV, ";
                    vFILTER = vFILTER + "SITE_ENVIO, ";
                    vFILTER = vFILTER + "TARIFA_BRANCA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_CONVENIO_SEFAZ, ";
                    vFILTER = vFILTER + "REGIAO, ";
                    vFILTER = vFILTER + "FATURA_COMPLEMENTAR  ";

                    vINNERJOIN = " ";

                    vORDERBY = " ";

                    vAND = vAND + "AND ZONA = ?ZONA ";
                    vAND = vAND + "AND LIVRO = ?LIVRO ";
                    vAND = vAND + "AND CONTA = ?CONTA ";
                    vAND = vAND + "AND MESANO_REF = ?MESANO_REF ";
                    vAND = vAND + "AND ANOMES_FAT = ?ANOMES_FAT ";
                    vAND = vAND + "AND MESANO = ?MESANO ";
                    vAND = vAND + "AND CONS_ID = ?CONS_ID ";
                    vAND = vAND + "AND UNID_ID = ?UNID_ID ";
                    vAND = vAND + "AND GRUPO = ?GRUPO ";

                    if (objNfTransicao.FLGMEDFAT == "2")
                    {
                        vAND = vAND + "AND FLGMEDFAT = 'S' ";
                    }
                    else
                    {
                        vAND = vAND + "AND FLGMEDFAT <> 'S' ";
                    }

                    if (objNfTransicao.FATURA_FINAL == 1)
                    {
                        vAND = vAND + "AND FATURA_FINAL = ?FATURA_FINAL ";
                    }
                    else
                    {
                        vAND = vAND + "AND FATURA_FINAL = ?FATURA_FINAL ";
                    }


                    cmd = new MySqlCommand(this.QuerySelect);

                    cmd.Parameters.AddWithValue("?ZONA", objNfTransicao.ZONA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LIVRO", objNfTransicao.LIVRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTA", objNfTransicao.CONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MESANO_REF", objNfTransicao.MESANO_REF);
                    cmd.Parameters.AddWithValue("?ANOMES_FAT", objNfTransicao.ANOMES_FAT);
                    cmd.Parameters.AddWithValue("?MESANO", objNfTransicao.MESANO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONS_ID", objNfTransicao.CONS_ID);
                    cmd.Parameters.AddWithValue("?UNID_ID", objNfTransicao.UNID_ID);
                    cmd.Parameters.AddWithValue("?GRUPO", objNfTransicao.GRUPO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?FATURA_FINAL", objNfTransicao.FATURA_FINAL);

                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

                return dt;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable Select_9(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {

                    vFILTER = vFILTER + "NUMNF, ";
                    vFILTER = vFILTER + "CODCLAS, ";
                    vFILTER = vFILTER + "MESANO, ";
                    vFILTER = vFILTER + "MESANO_REF, ";
                    vFILTER = vFILTER + "DATAVENC, ";
                    vFILTER = vFILTER + "DATADIVIDA, ";
                    vFILTER = vFILTER + "DATALEIT, ";
                    vFILTER = vFILTER + "DATAAPR, ";
                    vFILTER = vFILTER + "DATAEM, ";
                    vFILTER = vFILTER + "DATALEITANT, ";
                    vFILTER = vFILTER + "DATAPAG, ";
                    vFILTER = vFILTER + "CODHASH, ";
                    vFILTER = vFILTER + "DATAST, ";
                    vFILTER = vFILTER + "FLGST, ";
                    vFILTER = vFILTER + "VALORTOT, ";
                    vFILTER = vFILTER + "ZONA, ";
                    vFILTER = vFILTER + "LIVRO, ";
                    vFILTER = vFILTER + "CONTA, ";
                    vFILTER = vFILTER + "ROTA, ";
                    vFILTER = vFILTER + "CONS_ID, ";
                    vFILTER = vFILTER + "UNID_ID, ";
                    vFILTER = vFILTER + "DATAPROXLEIT, ";
                    vFILTER = vFILTER + "BANARREC, ";
                    vFILTER = vFILTER + "BANIDENT, ";
                    vFILTER = vFILTER + "FLGMEDFAT, ";
                    vFILTER = vFILTER + "TIPOUC, ";
                    vFILTER = vFILTER + "CFOP, ";
                    vFILTER = vFILTER + "ITENSSERV, ";
                    vFILTER = vFILTER + "TA, ";
                    vFILTER = vFILTER + "GRUPO, ";
                    vFILTER = vFILTER + "FASE, ";
                    vFILTER = vFILTER + "TENSAO, ";
                    vFILTER = vFILTER + "NUM_MED, ";
                    vFILTER = vFILTER + "CONST_MED, ";
                    vFILTER = vFILTER + "MOTIVOCANC, ";
                    vFILTER = vFILTER + "BANCO_FATUR, ";
                    vFILTER = vFILTER + "SOCIAL, ";
                    vFILTER = vFILTER + "MULTA, ";
                    vFILTER = vFILTER + "DATAPRAZO, ";
                    vFILTER = vFILTER + "DIAS, ";
                    vFILTER = vFILTER + "VALORLIQ, ";
                    vFILTER = vFILTER + "NSU, ";
                    vFILTER = vFILTER + "CODBARRA, ";
                    vFILTER = vFILTER + "DVCODBARRA, ";
                    vFILTER = vFILTER + "AGRUPA, ";
                    vFILTER = vFILTER + "AGRUPA_ROTA, ";
                    vFILTER = vFILTER + "ITENSIMP, ";
                    vFILTER = vFILTER + "SGDENVIO, ";
                    vFILTER = vFILTER + "MOTIVOPGTO, ";
                    vFILTER = vFILTER + "MOTIVOSEGVIA, ";
                    vFILTER = vFILTER + "USUARIOSEGVIA, ";
                    vFILTER = vFILTER + "DATASEGVIA, ";
                    vFILTER = vFILTER + "CPF_CNPJ, ";
                    vFILTER = vFILTER + "PARCIALMENTE_CATIVO, ";
                    vFILTER = vFILTER + "LIVREESPECIAL, ";
                    vFILTER = vFILTER + "PERIODO_TESTE, ";
                    vFILTER = vFILTER + "MENSAGEM_BANDEIRA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO, ";
                    vFILTER = vFILTER + "IRRIGACAO_AQUICULTURA, ";
                    vFILTER = vFILTER + "AGRUPA_CADERNO, ";
                    vFILTER = vFILTER + "AGRUPA_SEQUENCIA, ";
                    vFILTER = vFILTER + "CADERNO, ";
                    vFILTER = vFILTER + "CADERNO_SEQUENCIA, ";
                    vFILTER = vFILTER + "ROTA_QUATRO, ";
                    vFILTER = vFILTER + "AGENCIA, ";
                    vFILTER = vFILTER + "CONTA_CORRENTE, ";
                    vFILTER = vFILTER + "LIVRE_VERDE, ";
                    vFILTER = vFILTER + "CANCELADA_MESANO, ";
                    vFILTER = vFILTER + "CANCELADA_NUMNF, ";
                    vFILTER = vFILTER + "ENVIO_BCO, ";
                    vFILTER = vFILTER + "FATURA_FINAL, ";
                    vFILTER = vFILTER + "PAG_GOV, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_DISTRIBUIDA, ";
                    vFILTER = vFILTER + "USINA, ";
                    vFILTER = vFILTER + "SUPRIMENTO, ";
                    vFILTER = vFILTER + "BAIXA_NFV, ";
                    vFILTER = vFILTER + "SITE_ENVIO, ";
                    vFILTER = vFILTER + "TARIFA_BRANCA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_CONVENIO_SEFAZ, ";
                    vFILTER = vFILTER + "REGIAO, ";
                    vFILTER = vFILTER + "FATURA_COMPLEMENTAR  ";

                    vINNERJOIN = " ";

                    vORDERBY = " ";


                    vAND = vAND + "AND MESANO = ?MESANO ";
                    vAND = vAND + "AND CONS_ID = ?CONS_ID ";
                    vAND = vAND + "AND UNID_ID = ?UNID_ID ";
                    vAND = vAND + "AND GRUPO = ?GRUPO ";
                    vAND = vAND + "AND FATURA_FINAL = ?FATURA_FINAL ";


                    cmd = new MySqlCommand(this.QuerySelect);


                    cmd.Parameters.AddWithValue("?MESANO", objNfTransicao.MESANO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONS_ID", objNfTransicao.CONS_ID);
                    cmd.Parameters.AddWithValue("?UNID_ID", objNfTransicao.UNID_ID);
                    cmd.Parameters.AddWithValue("?GRUPO", objNfTransicao.GRUPO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?FATURA_FINAL", objNfTransicao.FATURA_FINAL);

                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

                return dt;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable Select_10(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {


                    vFILTER = vFILTER + "DATEDIFF(dataleit, dataleitant) as difdias  ";

                    vINNERJOIN = " ";

                    vORDERBY = " ";

                    vAND = vAND + "AND NUMNF = ?NUMNF ";
                    vAND = vAND + "AND MESANO_REF = ?MESANO_REF ";

                    cmd = new MySqlCommand(this.QuerySelect);

                    cmd.Parameters.AddWithValue("?NUMNF", objNfTransicao.NUMNF);
                    cmd.Parameters.AddWithValue("?MESANO_REF", objNfTransicao.MESANO_REF.ToString().ToUpper());


                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

                return dt;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable Select_11(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {

                    vFILTER = vFILTER + "NUMNF, ";
                    vFILTER = vFILTER + "CODCLAS, ";
                    vFILTER = vFILTER + "MESANO, ";
                    vFILTER = vFILTER + "MESANO_REF, ";
                    vFILTER = vFILTER + "DATAVENC, ";
                    vFILTER = vFILTER + "DATADIVIDA, ";
                    vFILTER = vFILTER + "DATALEIT, ";
                    vFILTER = vFILTER + "DATAAPR, ";
                    vFILTER = vFILTER + "DATAEM, ";
                    vFILTER = vFILTER + "DATALEITANT, ";
                    vFILTER = vFILTER + "DATAPAG, ";
                    vFILTER = vFILTER + "CODHASH, ";
                    vFILTER = vFILTER + "DATAST, ";
                    vFILTER = vFILTER + "FLGST, ";
                    vFILTER = vFILTER + "VALORTOT, ";
                    vFILTER = vFILTER + "ZONA, ";
                    vFILTER = vFILTER + "LIVRO, ";
                    vFILTER = vFILTER + "CONTA, ";
                    vFILTER = vFILTER + "ROTA, ";
                    vFILTER = vFILTER + "CONS_ID, ";
                    vFILTER = vFILTER + "UNID_ID, ";
                    vFILTER = vFILTER + "DATAPROXLEIT, ";
                    vFILTER = vFILTER + "BANARREC, ";
                    vFILTER = vFILTER + "BANIDENT, ";
                    vFILTER = vFILTER + "FLGMEDFAT, ";
                    vFILTER = vFILTER + "TIPOUC, ";
                    vFILTER = vFILTER + "CFOP, ";
                    vFILTER = vFILTER + "ITENSSERV, ";
                    vFILTER = vFILTER + "TA, ";
                    vFILTER = vFILTER + "GRUPO, ";
                    vFILTER = vFILTER + "FASE, ";
                    vFILTER = vFILTER + "TENSAO, ";
                    vFILTER = vFILTER + "NUM_MED, ";
                    vFILTER = vFILTER + "CONST_MED, ";
                    vFILTER = vFILTER + "MOTIVOCANC, ";
                    vFILTER = vFILTER + "BANCO_FATUR, ";
                    vFILTER = vFILTER + "SOCIAL, ";
                    vFILTER = vFILTER + "MULTA, ";
                    vFILTER = vFILTER + "DATAPRAZO, ";
                    vFILTER = vFILTER + "DIAS, ";
                    vFILTER = vFILTER + "VALORLIQ, ";
                    vFILTER = vFILTER + "NSU, ";
                    vFILTER = vFILTER + "CODBARRA, ";
                    vFILTER = vFILTER + "DVCODBARRA, ";
                    vFILTER = vFILTER + "AGRUPA, ";
                    vFILTER = vFILTER + "AGRUPA_ROTA, ";
                    vFILTER = vFILTER + "ITENSIMP, ";
                    vFILTER = vFILTER + "SGDENVIO, ";
                    vFILTER = vFILTER + "MOTIVOPGTO, ";
                    vFILTER = vFILTER + "MOTIVOSEGVIA, ";
                    vFILTER = vFILTER + "USUARIOSEGVIA, ";
                    vFILTER = vFILTER + "DATASEGVIA, ";
                    vFILTER = vFILTER + "CPF_CNPJ, ";
                    vFILTER = vFILTER + "PARCIALMENTE_CATIVO, ";
                    vFILTER = vFILTER + "LIVREESPECIAL, ";
                    vFILTER = vFILTER + "PERIODO_TESTE, ";
                    vFILTER = vFILTER + "MENSAGEM_BANDEIRA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO, ";
                    vFILTER = vFILTER + "IRRIGACAO_AQUICULTURA, ";
                    vFILTER = vFILTER + "AGRUPA_CADERNO, ";
                    vFILTER = vFILTER + "AGRUPA_SEQUENCIA, ";
                    vFILTER = vFILTER + "CADERNO, ";
                    vFILTER = vFILTER + "CADERNO_SEQUENCIA, ";
                    vFILTER = vFILTER + "ROTA_QUATRO, ";
                    vFILTER = vFILTER + "AGENCIA, ";
                    vFILTER = vFILTER + "CONTA_CORRENTE, ";
                    vFILTER = vFILTER + "LIVRE_VERDE, ";
                    vFILTER = vFILTER + "CANCELADA_MESANO, ";
                    vFILTER = vFILTER + "CANCELADA_NUMNF, ";
                    vFILTER = vFILTER + "ENVIO_BCO, ";
                    vFILTER = vFILTER + "FATURA_FINAL, ";
                    vFILTER = vFILTER + "PAG_GOV, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_DISTRIBUIDA, ";
                    vFILTER = vFILTER + "USINA, ";
                    vFILTER = vFILTER + "SUPRIMENTO, ";
                    vFILTER = vFILTER + "BAIXA_NFV, ";
                    vFILTER = vFILTER + "SITE_ENVIO, ";
                    vFILTER = vFILTER + "TARIFA_BRANCA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_CONVENIO_SEFAZ, ";
                    vFILTER = vFILTER + "REGIAO, ";
                    vFILTER = vFILTER + "FATURA_COMPLEMENTAR  ";

                    vINNERJOIN = " ";

                    vORDERBY = " ";

                    vAND = vAND + "AND NUMNF = ?NUMNF ";

                    cmd = new MySqlCommand(this.QuerySelect);

                    cmd.Parameters.AddWithValue("?NUMNF", objNfTransicao.NUMNF);

                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

                return dt;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable Select_12(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {

                    //vFILTER = vFILTER + "NUMNF, ";
                    //vFILTER = vFILTER + "CODCLAS, ";
                    //vFILTER = vFILTER + "MESANO, ";
                    //vFILTER = vFILTER + "MESANO_REF, ";
                    //vFILTER = vFILTER + "DATAVENC, ";

                    //vFILTER = vFILTER + "REGIAO, ";
                    //vFILTER = vFILTER + "FATURA_COMPLEMENTAR  ";

                    //vINNERJOIN = " ";

                    //vORDERBY = "GROUP BY 1 ";

                    //vFILTER = vFILTER + " DISTINCT LEFT(ROTA ,4) AS ROTA ";
                    vFILTER = vFILTER + " DISTINCT CAST(LEFT(ROTA ,4) AS DECIMAL) AS ROTA  ";

                    vINNERJOIN = " ";

                    vORDERBY = "ORDER BY ROTA ASC  ";


                    vAND = vAND + "   AND  MESANO = ?MESANO ";
                    vAND = vAND + "   AND GRUPO = ?GRUPO ";
                    vAND = vAND + "   AND FATURA_COMPLEMENTAR " + objNfTransicao.AGENCIA.ToString() + " ?FATURA_COMPLEMENTAR ";


                    cmd = new MySqlCommand(this.QuerySelect);

                    cmd.Parameters.AddWithValue("?MESANO", objNfTransicao.MESANO);
                    cmd.Parameters.AddWithValue("?GRUPO", objNfTransicao.GRUPO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?FATURA_COMPLEMENTAR", objNfTransicao.FATURA_COMPLEMENTAR);


                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

                return dt;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable Select_13(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {
                    vFILTER = vFILTER + "       NFTRANSICAO.ZONA    AS ZONA    , ";
                    vFILTER = vFILTER + "       NFTRANSICAO.LIVRO   AS LIVRO   , ";
                    vFILTER = vFILTER + "       NFTRANSICAO.CONTA   AS CONTA   , ";
                    vFILTER = vFILTER + "       NFTRANSICAO.CONS_ID AS CONS_ID , ";
                    vFILTER = vFILTER + "       NFTRANSICAO.UNID_ID AS UNID_ID , ";
                    vFILTER = vFILTER + "       NFTRANSICAO.ROTA_QUATRO AS ROTA_QUATRO , ";
                    vFILTER = vFILTER + "       NFTRANSICAO.NUMNF AS NUMNF , ";
                    vFILTER = vFILTER + "       NFTRANSICAO.ANOMES_FAT AS ANOMES_FAT ";

                    vINNERJOIN = " ";

                    vORDERBY = vORDERBY + " ";

                    vAND = vAND + " AND  NFTRANSICAO.MESANO_REF = ?MESANO_REF ";

                    if (objNfTransicao.MICRO_GERACAO != 2)
                    {
                        if (objNfTransicao.MICRO_GERACAO == 1 && objNfTransicao.MICRO_GERACAO_DISTRIBUIDA == 1)
                        {
                            vAND = vAND + " AND (NFTRANSICAO.MICRO_GERACAO = 1 OR NFTRANSICAO.MICRO_GERACAO_DISTRIBUIDA = 1) ";
                        }
                        else
                        {
                            vAND = vAND + " AND NFTRANSICAO.MICRO_GERACAO = 0 ";
                            vAND = vAND + " AND NFTRANSICAO.MICRO_GERACAO_DISTRIBUIDA = 0 ";
                        }
                    }

                    if (objNfTransicao.ROTA != string.Empty)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND MID(NFTRANSICAO.ROTA,1,4) IN ( " + objNfTransicao.ROTA.ToString().ToUpper() + " ) "; }
                        else
                        { vAND = "AND MID(NFTRANSICAO.ROTA,1,4) IN ( " + objNfTransicao.ROTA.ToString().ToUpper() + " ) "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = " "; }
                    }


                    if (objNfTransicao.ZONA.Trim().Length > 0 && objNfTransicao.LIVRO.Trim().Length > 0 && objNfTransicao.CONTA.Trim().Length > 0)
                    {
                        if (vAND != String.Empty)
                        {
                            vAND = vAND + " AND NFTRANSICAO.ZONA = ?ZONA ";
                            vAND = vAND + " AND NFTRANSICAO.LIVRO = ?LIVRO ";
                            vAND = vAND + " AND NFTRANSICAO.CONTA = ?CONTA ";
                        }
                        else
                        {
                            vAND = vAND + " AND NFTRANSICAO.ZONA = ?ZONA ";
                            vAND = vAND + " AND NFTRANSICAO.LIVRO = ?LIVRO ";
                            vAND = vAND + " AND NFTRANSICAO.CONTA = ?CONTA ";
                        }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = " "; }
                    }


                    cmd = new MySqlCommand(this.QuerySelect);

                    cmd.Parameters.AddWithValue("?MESANO_REF", objNfTransicao.MESANO_REF);

                    if (objNfTransicao.ROTA != string.Empty)
                    {
                        cmd.Parameters.AddWithValue("?ROTA", objNfTransicao.ROTA.ToString().ToUpper());
                    }

                    if (objNfTransicao.ZONA.Trim().Length > 0 && objNfTransicao.LIVRO.Trim().Length > 0 && objNfTransicao.CONTA.Trim().Length > 0)
                    {

                        cmd.Parameters.AddWithValue("?ZONA", objNfTransicao.ZONA.ToString().ToUpper());

                        cmd.Parameters.AddWithValue("?LIVRO", objNfTransicao.LIVRO.ToString().ToUpper());

                        cmd.Parameters.AddWithValue("?CONTA", objNfTransicao.CONTA.ToString().ToUpper());

                    }

                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

                return dt;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable SelectOthersTables(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {

                    vFILTER = vFILTER + " NFTRANSICAO.*, CONSUM.CONSREG as C_CONSREG, CONSUM.MATRICULA as C_MATRICULA ";
                    vINNERJOIN = vINNERJOIN + " AS NFTRANSICAO ";
                    vINNERJOIN = vINNERJOIN + " LEFT JOIN CONSUM ON(CONSUM.CONSREG = NFTRANSICAO.CONS_ID) ";

                    vORDERBY = " ";

                    vAND = vAND + " AND NFTRANSICAO.ITENSSERV IS NOT NULL ";

                    if (objNfTransicao.ROTA_QUATRO == "1")
                    {
                        vAND = vAND + "   AND NFTRANSICAO.ROTA_QUATRO BETWEEN ?ROTAINI AND ?ROTAFIM ";
                    }

                    if (objNfTransicao.CADERNO == 1)
                    {
                        vAND = vAND + "   AND NFTRANSICAO.CADERNO BETWEEN ?ROTAINI AND ?ROTAFIM ";
                    }

                    vAND = vAND + " AND ( ";

                    if (objNfTransicao.REN863_2019 == false)
                    {
                        vAND = vAND + "  (NFTRANSICAO.MESANO_REF >= ?MESANOINI AND ";
                        vAND = vAND + "  NFTRANSICAO.MESANO_REF <= ?MESANOFIM )";
                    }
                    else
                    {
                        vAND = vAND + "  (NFTRANSICAO.ANOMES_FAT >= ?MESANOINI AND ";
                        vAND = vAND + "  NFTRANSICAO.ANOMES_FAT <= ?MESANOFIM )";
                    }

                    vAND = vAND + " OR ( ";
                    vAND = vAND + "        NFTRANSICAO.FLGST = ?FLGST AND ";
                    vAND = vAND + "         NFTRANSICAO.MESANO_REF <> DATE_FORMAT(DATAST,'%Y%M') AND ";
                    vAND = vAND + "         NFTRANSICAO.DATAST BETWEEN ?DATAINICIAL AND ?DATAFINAL ";
                    vAND = vAND + "   )";
                    vAND = vAND + " )";

                    if (objNfTransicao.ZONA != "")
                    {

                        vAND = vAND + " AND NFTRANSICAO.ZONA IN (  " + objNfTransicao.ZONA + " ) ";

                    }

                    if (objNfTransicao.GRUPO != "")
                    {
                        vAND = vAND + " AND NFTRANSICAO.GRUPO = ?GRUPO ";
                    }

                    if (objNfTransicao.MICRO_GERACAO != 0 && objNfTransicao.MICRO_GERACAO_DISTRIBUIDA != 0)
                    {
                        vAND = vAND + "   AND (NFTRANSICAO.MICRO_GERACAO = ?MICRO_GERACAO OR NFTRANSICAO.MICRO_GERACAO_DISTRIBUIDA = ?MICRO_GERACAO_DISTRIBUIDA) ";

                        if (objNfTransicao.MICRO_GERACAO_CONVENIO_SEFAZ == 1)
                        {
                            vAND = vAND + " AND NFTRANSICAO.MICRO_GERACAO_CONVENIO_SEFAZ  = ?MICRO_GERACAO_CONVENIO_SEFAZ";
                        }
                        else if (objNfTransicao.MICRO_GERACAO_CONVENIO_SEFAZ == 0)
                        {
                            vAND = vAND + "  AND NFTRANSICAO.MICRO_GERACAO_CONVENIO_SEFAZ  = ??MICRO_GERACAO_CONVENIO_SEFAZ";
                        }


                    }

                    if (objNfTransicao.REGIAO != "")
                    {
                        vAND = vAND + "  AND NFTRANSICAO.REGIAO = ?REGIAO";
                    }

                    if (objNfTransicao.FATURA_COMPLEMENTAR == 1)
                    {
                        vAND = vAND + "  AND NFTRANSICAO.FATURA_COMPLEMENTAR > 0";
                    }
                    else if (objNfTransicao.FATURA_COMPLEMENTAR == 0)
                    {
                        vAND = vAND + "  AND NFTRANSICAO.FATURA_COMPLEMENTAR = 0";
                    }

                    vAND = vAND + objNfTransicao.FLGMEDFAT.ToString().ToUpper();



                    cmd = new MySqlCommand(this.QuerySelect);


                    if (objNfTransicao.REGIAO != "")
                    {
                        cmd.Parameters.AddWithValue("?REGIAO", objNfTransicao.REGIAO);
                    }

                    if (objNfTransicao.MICRO_GERACAO != 0 && objNfTransicao.MICRO_GERACAO_DISTRIBUIDA != 0)
                    {

                        cmd.Parameters.AddWithValue("?MICRO_GERACAO", objNfTransicao.MICRO_GERACAO);
                        cmd.Parameters.AddWithValue("?MICRO_GERACAO_DISTRIBUIDA", objNfTransicao.MICRO_GERACAO_DISTRIBUIDA);

                        if (objNfTransicao.MICRO_GERACAO_CONVENIO_SEFAZ == 1)
                        {
                            cmd.Parameters.AddWithValue("?MICRO_GERACAO_CONVENIO_SEFAZ", objNfTransicao.MICRO_GERACAO_CONVENIO_SEFAZ);
                        }
                        else if (objNfTransicao.MICRO_GERACAO_CONVENIO_SEFAZ == 0)
                        {
                            cmd.Parameters.AddWithValue("?MICRO_GERACAO_CONVENIO_SEFAZ", objNfTransicao.MICRO_GERACAO_CONVENIO_SEFAZ);
                        }

                    }

                    if (objNfTransicao.GRUPO != "")
                    {
                        cmd.Parameters.AddWithValue("?GRUPO", objNfTransicao.GRUPO);
                    }

                    if (objNfTransicao.ZONA != "")
                    {
                        cmd.Parameters.AddWithValue("?ZONA", objNfTransicao.ZONA);

                    }

                    cmd.Parameters.AddWithValue("?FLGST", objNfTransicao.FLGST);


                    if (objNfTransicao.DATAINICIAL.Year != 1 && objNfTransicao.DATAFINAL.Year != 1)
                    {
                        cmd.Parameters.AddWithValue("?DATAINICIAL", objNfTransicao.DATAINICIAL);
                        cmd.Parameters.AddWithValue("?DATAFINAL", objNfTransicao.DATAFINAL);
                    }

                    if (!string.IsNullOrEmpty(objNfTransicao.MESANOINI) && !string.IsNullOrEmpty(objNfTransicao.MESANOFIM))
                    {
                        cmd.Parameters.AddWithValue("?MESANOINI", objNfTransicao.MESANOINI);
                        cmd.Parameters.AddWithValue("?MESANOFIM", objNfTransicao.MESANOFIM);
                    }

                    if (objNfTransicao.ROTAINI != 0 && objNfTransicao.ROTAFIM != 0)
                    {
                        cmd.Parameters.AddWithValue("?ROTAINI", objNfTransicao.ROTAINI);
                        cmd.Parameters.AddWithValue("?ROTAFIM", objNfTransicao.ROTAFIM);
                    }

                    dt = objGerenciadorTransacao.GetDataTable(cmd);

                }

                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable Select_14(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fatwin_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {

                    vFILTER = vFILTER + "NUMNF, ";
                    vFILTER = vFILTER + "CODCLAS, ";
                    vFILTER = vFILTER + "MESANO, ";
                    vFILTER = vFILTER + "MESANO_REF, ";
                    vFILTER = vFILTER + "DATAVENC, ";
                    vFILTER = vFILTER + "DATADIVIDA, ";
                    vFILTER = vFILTER + "DATALEIT, ";
                    vFILTER = vFILTER + "DATAAPR, ";
                    vFILTER = vFILTER + "DATAEM, ";
                    vFILTER = vFILTER + "DATALEITANT, ";
                    vFILTER = vFILTER + "DATAPAG, ";
                    vFILTER = vFILTER + "CODHASH, ";
                    vFILTER = vFILTER + "DATAST, ";
                    vFILTER = vFILTER + "FLGST, ";
                    vFILTER = vFILTER + "VALORTOT, ";
                    vFILTER = vFILTER + "ZONA, ";
                    vFILTER = vFILTER + "LIVRO, ";
                    vFILTER = vFILTER + "CONTA, ";
                    vFILTER = vFILTER + "ROTA, ";
                    vFILTER = vFILTER + "CONS_ID, ";
                    vFILTER = vFILTER + "UNID_ID, ";
                    vFILTER = vFILTER + "DATAPROXLEIT, ";
                    vFILTER = vFILTER + "BANARREC, ";
                    vFILTER = vFILTER + "BANIDENT, ";
                    vFILTER = vFILTER + "FLGMEDFAT, ";
                    vFILTER = vFILTER + "TIPOUC, ";
                    vFILTER = vFILTER + "CFOP, ";
                    vFILTER = vFILTER + "ITENSSERV, ";
                    vFILTER = vFILTER + "TA, ";
                    vFILTER = vFILTER + "GRUPO, ";
                    vFILTER = vFILTER + "FASE, ";
                    vFILTER = vFILTER + "TENSAO, ";
                    vFILTER = vFILTER + "NUM_MED, ";
                    vFILTER = vFILTER + "CONST_MED, ";
                    vFILTER = vFILTER + "MOTIVOCANC, ";
                    vFILTER = vFILTER + "BANCO_FATUR, ";
                    vFILTER = vFILTER + "SOCIAL, ";
                    vFILTER = vFILTER + "MULTA, ";
                    vFILTER = vFILTER + "DATAPRAZO, ";
                    vFILTER = vFILTER + "DIAS, ";
                    vFILTER = vFILTER + "VALORLIQ, ";
                    vFILTER = vFILTER + "NSU, ";
                    vFILTER = vFILTER + "CODBARRA, ";
                    vFILTER = vFILTER + "DVCODBARRA, ";
                    vFILTER = vFILTER + "AGRUPA, ";
                    vFILTER = vFILTER + "AGRUPA_ROTA, ";
                    vFILTER = vFILTER + "ITENSIMP, ";
                    vFILTER = vFILTER + "SGDENVIO, ";
                    vFILTER = vFILTER + "MOTIVOPGTO, ";
                    vFILTER = vFILTER + "MOTIVOSEGVIA, ";
                    vFILTER = vFILTER + "USUARIOSEGVIA, ";
                    vFILTER = vFILTER + "DATASEGVIA, ";
                    vFILTER = vFILTER + "CPF_CNPJ, ";
                    vFILTER = vFILTER + "PARCIALMENTE_CATIVO, ";
                    vFILTER = vFILTER + "LIVREESPECIAL, ";
                    vFILTER = vFILTER + "PERIODO_TESTE, ";
                    vFILTER = vFILTER + "MENSAGEM_BANDEIRA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO, ";
                    vFILTER = vFILTER + "IRRIGACAO_AQUICULTURA, ";
                    vFILTER = vFILTER + "AGRUPA_CADERNO, ";
                    vFILTER = vFILTER + "AGRUPA_SEQUENCIA, ";
                    vFILTER = vFILTER + "CADERNO, ";
                    vFILTER = vFILTER + "CADERNO_SEQUENCIA, ";
                    vFILTER = vFILTER + "ROTA_QUATRO, ";
                    vFILTER = vFILTER + "AGENCIA, ";
                    vFILTER = vFILTER + "CONTA_CORRENTE, ";
                    vFILTER = vFILTER + "LIVRE_VERDE, ";
                    vFILTER = vFILTER + "CANCELADA_MESANO, ";
                    vFILTER = vFILTER + "CANCELADA_NUMNF, ";
                    vFILTER = vFILTER + "ENVIO_BCO, ";
                    vFILTER = vFILTER + "FATURA_FINAL, ";
                    vFILTER = vFILTER + "PAG_GOV, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_DISTRIBUIDA, ";
                    vFILTER = vFILTER + "USINA, ";
                    vFILTER = vFILTER + "SUPRIMENTO, ";
                    vFILTER = vFILTER + "BAIXA_NFV, ";
                    vFILTER = vFILTER + "SITE_ENVIO, ";
                    vFILTER = vFILTER + "TARIFA_BRANCA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_CONVENIO_SEFAZ, ";
                    vFILTER = vFILTER + "REGIAO, ";
                    vFILTER = vFILTER + "FATURA_COMPLEMENTAR  ";

                    vINNERJOIN = " ";

                    vORDERBY = " ";

                    vAND = vAND + "AND NUMNF = ?NUMNF ";

                    cmd = new MySqlCommand(this.QuerySelect);

                    cmd.Parameters.AddWithValue("?NUMNF", objNfTransicao.NUMNF);

                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

                return dt;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable Select_15(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fatwin_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {

                    vFILTER = vFILTER + "NUMNF, ";
                    vFILTER = vFILTER + "CODCLAS, ";
                    vFILTER = vFILTER + "MESANO, ";
                    vFILTER = vFILTER + "MESANO_REF, ";
                    vFILTER = vFILTER + "DATAVENC, ";
                    vFILTER = vFILTER + "DATADIVIDA, ";
                    vFILTER = vFILTER + "DATALEIT, ";
                    vFILTER = vFILTER + "DATAAPR, ";
                    vFILTER = vFILTER + "DATAEM, ";
                    vFILTER = vFILTER + "DATALEITANT, ";
                    vFILTER = vFILTER + "DATAPAG, ";
                    vFILTER = vFILTER + "CODHASH, ";
                    vFILTER = vFILTER + "DATAST, ";
                    vFILTER = vFILTER + "FLGST, ";
                    vFILTER = vFILTER + "VALORTOT, ";
                    vFILTER = vFILTER + "ZONA, ";
                    vFILTER = vFILTER + "LIVRO, ";
                    vFILTER = vFILTER + "CONTA, ";
                    vFILTER = vFILTER + "ROTA, ";
                    vFILTER = vFILTER + "CONS_ID, ";
                    vFILTER = vFILTER + "UNID_ID, ";
                    vFILTER = vFILTER + "DATAPROXLEIT, ";
                    vFILTER = vFILTER + "BANARREC, ";
                    vFILTER = vFILTER + "BANIDENT, ";
                    vFILTER = vFILTER + "FLGMEDFAT, ";
                    vFILTER = vFILTER + "TIPOUC, ";
                    vFILTER = vFILTER + "CFOP, ";
                    vFILTER = vFILTER + "ITENSSERV, ";
                    vFILTER = vFILTER + "TA, ";
                    vFILTER = vFILTER + "GRUPO, ";
                    vFILTER = vFILTER + "FASE, ";
                    vFILTER = vFILTER + "TENSAO, ";
                    vFILTER = vFILTER + "NUM_MED, ";
                    vFILTER = vFILTER + "CONST_MED, ";
                    vFILTER = vFILTER + "MOTIVOCANC, ";
                    vFILTER = vFILTER + "BANCO_FATUR, ";
                    vFILTER = vFILTER + "SOCIAL, ";
                    vFILTER = vFILTER + "MULTA, ";
                    vFILTER = vFILTER + "DATAPRAZO, ";
                    vFILTER = vFILTER + "DIAS, ";
                    vFILTER = vFILTER + "VALORLIQ, ";
                    vFILTER = vFILTER + "NSU, ";
                    vFILTER = vFILTER + "CODBARRA, ";
                    vFILTER = vFILTER + "DVCODBARRA, ";
                    vFILTER = vFILTER + "AGRUPA, ";
                    vFILTER = vFILTER + "AGRUPA_ROTA, ";
                    vFILTER = vFILTER + "ITENSIMP, ";
                    vFILTER = vFILTER + "SGDENVIO, ";
                    vFILTER = vFILTER + "MOTIVOPGTO, ";
                    vFILTER = vFILTER + "MOTIVOSEGVIA, ";
                    vFILTER = vFILTER + "USUARIOSEGVIA, ";
                    vFILTER = vFILTER + "DATASEGVIA, ";
                    vFILTER = vFILTER + "CPF_CNPJ, ";
                    vFILTER = vFILTER + "PARCIALMENTE_CATIVO, ";
                    vFILTER = vFILTER + "LIVREESPECIAL, ";
                    vFILTER = vFILTER + "PERIODO_TESTE, ";
                    vFILTER = vFILTER + "MENSAGEM_BANDEIRA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO, ";
                    vFILTER = vFILTER + "IRRIGACAO_AQUICULTURA, ";
                    vFILTER = vFILTER + "AGRUPA_CADERNO, ";
                    vFILTER = vFILTER + "AGRUPA_SEQUENCIA, ";
                    vFILTER = vFILTER + "CADERNO, ";
                    vFILTER = vFILTER + "CADERNO_SEQUENCIA, ";
                    vFILTER = vFILTER + "ROTA_QUATRO, ";
                    vFILTER = vFILTER + "AGENCIA, ";
                    vFILTER = vFILTER + "CONTA_CORRENTE, ";
                    vFILTER = vFILTER + "LIVRE_VERDE, ";
                    vFILTER = vFILTER + "CANCELADA_MESANO, ";
                    vFILTER = vFILTER + "CANCELADA_NUMNF, ";
                    vFILTER = vFILTER + "ENVIO_BCO, ";
                    vFILTER = vFILTER + "FATURA_FINAL, ";
                    vFILTER = vFILTER + "PAG_GOV, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_DISTRIBUIDA, ";
                    vFILTER = vFILTER + "USINA, ";
                    vFILTER = vFILTER + "SUPRIMENTO, ";
                    vFILTER = vFILTER + "BAIXA_NFV, ";
                    vFILTER = vFILTER + "SITE_ENVIO, ";
                    vFILTER = vFILTER + "TARIFA_BRANCA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_CONVENIO_SEFAZ, ";
                    vFILTER = vFILTER + "REGIAO, ";
                    vFILTER = vFILTER + "FATURA_COMPLEMENTAR  ";

                    vINNERJOIN = " ";

                    vORDERBY = " ";

                    vAND = vAND + "AND NUMNF = ?NUMNF ";

                    cmd = new MySqlCommand(this.QuerySelect);

                    cmd.Parameters.AddWithValue("?NUMNF", objNfTransicao.NUMNF);

                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

                return dt;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable SelectOthersTables_1(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {

                    vFILTER = vFILTER + "SELECT  ";
                    vFILTER = vFILTER + "NUMNF, ";
                    vFILTER = vFILTER + "CODCLAS, ";
                    vFILTER = vFILTER + "MESANO, ";
                    vFILTER = vFILTER + "MESANO_REF, ";
                    vFILTER = vFILTER + "DATAVENC, ";
                    vFILTER = vFILTER + "DATADIVIDA, ";
                    vFILTER = vFILTER + "DATALEIT, ";
                    vFILTER = vFILTER + "DATAAPR, ";
                    vFILTER = vFILTER + "DATAEM, ";
                    vFILTER = vFILTER + "DATALEITANT, ";
                    vFILTER = vFILTER + "DATAPAG, ";
                    vFILTER = vFILTER + "CODHASH, ";
                    vFILTER = vFILTER + "DATAST, ";
                    vFILTER = vFILTER + "FLGST, ";
                    vFILTER = vFILTER + "VALORTOT, ";
                    vFILTER = vFILTER + "ZONA, ";
                    vFILTER = vFILTER + "LIVRO, ";
                    vFILTER = vFILTER + "CONTA, ";
                    vFILTER = vFILTER + "ROTA, ";
                    vFILTER = vFILTER + "CONS_ID, ";
                    vFILTER = vFILTER + "UNID_ID, ";
                    vFILTER = vFILTER + "DATAPROXLEIT, ";
                    vFILTER = vFILTER + "BANARREC, ";
                    vFILTER = vFILTER + "BANIDENT, ";
                    vFILTER = vFILTER + "FLGMEDFAT, ";
                    vFILTER = vFILTER + "TIPOUC, ";
                    vFILTER = vFILTER + "CFOP, ";
                    vFILTER = vFILTER + "ITENSSERV, ";
                    vFILTER = vFILTER + "TA, ";
                    vFILTER = vFILTER + "GRUPO, ";
                    vFILTER = vFILTER + "FASE, ";
                    vFILTER = vFILTER + "TENSAO, ";
                    vFILTER = vFILTER + "NUM_MED, ";
                    vFILTER = vFILTER + "CONST_MED, ";
                    vFILTER = vFILTER + "MOTIVOCANC, ";
                    vFILTER = vFILTER + "BANCO_FATUR, ";
                    vFILTER = vFILTER + "SOCIAL, ";
                    vFILTER = vFILTER + "MULTA, ";
                    vFILTER = vFILTER + "DATAPRAZO, ";
                    vFILTER = vFILTER + "DIAS, ";
                    vFILTER = vFILTER + "VALORLIQ, ";
                    vFILTER = vFILTER + "NSU, ";
                    vFILTER = vFILTER + "CODBARRA, ";
                    vFILTER = vFILTER + "DVCODBARRA, ";
                    vFILTER = vFILTER + "AGRUPA, ";
                    vFILTER = vFILTER + "AGRUPA_ROTA, ";
                    vFILTER = vFILTER + "ITENSIMP, ";
                    vFILTER = vFILTER + "SGDENVIO, ";
                    vFILTER = vFILTER + "MOTIVOPGTO, ";
                    vFILTER = vFILTER + "MOTIVOSEGVIA, ";
                    vFILTER = vFILTER + "USUARIOSEGVIA, ";
                    vFILTER = vFILTER + "DATASEGVIA, ";
                    vFILTER = vFILTER + "CPF_CNPJ, ";
                    vFILTER = vFILTER + "PARCIALMENTE_CATIVO, ";
                    vFILTER = vFILTER + "LIVREESPECIAL, ";
                    vFILTER = vFILTER + "PERIODO_TESTE, ";
                    vFILTER = vFILTER + "MENSAGEM_BANDEIRA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO, ";
                    vFILTER = vFILTER + "IRRIGACAO_AQUICULTURA, ";
                    vFILTER = vFILTER + "AGRUPA_CADERNO, ";
                    vFILTER = vFILTER + "AGRUPA_SEQUENCIA, ";
                    vFILTER = vFILTER + "CADERNO, ";
                    vFILTER = vFILTER + "CADERNO_SEQUENCIA, ";
                    vFILTER = vFILTER + "ROTA_QUATRO, ";
                    vFILTER = vFILTER + "AGENCIA, ";
                    vFILTER = vFILTER + "CONTA_CORRENTE, ";
                    vFILTER = vFILTER + "LIVRE_VERDE, ";
                    vFILTER = vFILTER + "CANCELADA_MESANO, ";
                    vFILTER = vFILTER + "CANCELADA_NUMNF, ";
                    vFILTER = vFILTER + "ENVIO_BCO, ";
                    vFILTER = vFILTER + "FATURA_FINAL, ";
                    vFILTER = vFILTER + "PAG_GOV, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_DISTRIBUIDA, ";
                    vFILTER = vFILTER + "USINA, ";
                    vFILTER = vFILTER + "SUPRIMENTO, ";
                    vFILTER = vFILTER + "BAIXA_NFV, ";
                    vFILTER = vFILTER + "SITE_ENVIO, ";
                    vFILTER = vFILTER + "TARIFA_BRANCA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_CONVENIO_SEFAZ, ";
                    vFILTER = vFILTER + "REGIAO, ";
                    vFILTER = vFILTER + "FATURA_COMPLEMENTAR  ";
                    vFILTER = vFILTER + "FROM  NF ";
                    vFILTER = vFILTER + "WHERE 1 = 1 ";


                    vORDERBY = " ";

                    vAND = vFILTER;

                    if (objNfTransicao.ZONA != string.Empty)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND ZONA = ?ZONA "; }
                        else
                        { vAND = vAND + "AND ZONA = ?ZONA "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = vAND + " "; }
                    }

                    if (objNfTransicao.LIVRO != string.Empty)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND LIVRO = ?LIVRO "; }
                        else
                        { vAND = vAND + "AND LIVRO = ?LIVRO "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = vAND + " "; }
                    }


                    if (objNfTransicao.CONTA != string.Empty)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND CONTA = ?CONTA "; }
                        else
                        { vAND = vAND + "AND CONTA = ?CONTA "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = vAND + " "; }
                    }


                    if (objNfTransicao.GRUPO != string.Empty)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND GRUPO = ?GRUPO "; }
                        else
                        { vAND = vAND + "AND GRUPO = ?GRUPO "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = vAND + " "; }
                    }

                    vFILTER = vAND;

                    vFILTER = vFILTER + "UNION ALL ";
                    vFILTER = vFILTER + "SELECT  ";
                    vFILTER = vFILTER + "NUMNF, ";
                    vFILTER = vFILTER + "CODCLAS, ";
                    vFILTER = vFILTER + "MESANO, ";
                    vFILTER = vFILTER + "MESANO_REF, ";
                    vFILTER = vFILTER + "DATAVENC, ";
                    vFILTER = vFILTER + "DATADIVIDA, ";
                    vFILTER = vFILTER + "DATALEIT, ";
                    vFILTER = vFILTER + "DATAAPR, ";
                    vFILTER = vFILTER + "DATAEM, ";
                    vFILTER = vFILTER + "DATALEITANT, ";
                    vFILTER = vFILTER + "DATAPAG, ";
                    vFILTER = vFILTER + "CODHASH, ";
                    vFILTER = vFILTER + "DATAST, ";
                    vFILTER = vFILTER + "FLGST, ";
                    vFILTER = vFILTER + "VALORTOT, ";
                    vFILTER = vFILTER + "ZONA, ";
                    vFILTER = vFILTER + "LIVRO, ";
                    vFILTER = vFILTER + "CONTA, ";
                    vFILTER = vFILTER + "ROTA, ";
                    vFILTER = vFILTER + "CONS_ID, ";
                    vFILTER = vFILTER + "UNID_ID, ";
                    vFILTER = vFILTER + "DATAPROXLEIT, ";
                    vFILTER = vFILTER + "BANARREC, ";
                    vFILTER = vFILTER + "BANIDENT, ";
                    vFILTER = vFILTER + "FLGMEDFAT, ";
                    vFILTER = vFILTER + "TIPOUC, ";
                    vFILTER = vFILTER + "CFOP, ";
                    vFILTER = vFILTER + "ITENSSERV, ";
                    vFILTER = vFILTER + "TA, ";
                    vFILTER = vFILTER + "GRUPO, ";
                    vFILTER = vFILTER + "FASE, ";
                    vFILTER = vFILTER + "TENSAO, ";
                    vFILTER = vFILTER + "NUM_MED, ";
                    vFILTER = vFILTER + "CONST_MED, ";
                    vFILTER = vFILTER + "MOTIVOCANC, ";
                    vFILTER = vFILTER + "BANCO_FATUR, ";
                    vFILTER = vFILTER + "SOCIAL, ";
                    vFILTER = vFILTER + "MULTA, ";
                    vFILTER = vFILTER + "DATAPRAZO, ";
                    vFILTER = vFILTER + "DIAS, ";
                    vFILTER = vFILTER + "VALORLIQ, ";
                    vFILTER = vFILTER + "NSU, ";
                    vFILTER = vFILTER + "CODBARRA, ";
                    vFILTER = vFILTER + "DVCODBARRA, ";
                    vFILTER = vFILTER + "AGRUPA, ";
                    vFILTER = vFILTER + "AGRUPA_ROTA, ";
                    vFILTER = vFILTER + "ITENSIMP, ";
                    vFILTER = vFILTER + "SGDENVIO, ";
                    vFILTER = vFILTER + "MOTIVOPGTO, ";
                    vFILTER = vFILTER + "MOTIVOSEGVIA, ";
                    vFILTER = vFILTER + "USUARIOSEGVIA, ";
                    vFILTER = vFILTER + "DATASEGVIA, ";
                    vFILTER = vFILTER + "CPF_CNPJ, ";
                    vFILTER = vFILTER + "PARCIALMENTE_CATIVO, ";
                    vFILTER = vFILTER + "LIVREESPECIAL, ";
                    vFILTER = vFILTER + "PERIODO_TESTE, ";
                    vFILTER = vFILTER + "MENSAGEM_BANDEIRA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO, ";
                    vFILTER = vFILTER + "IRRIGACAO_AQUICULTURA, ";
                    vFILTER = vFILTER + "AGRUPA_CADERNO, ";
                    vFILTER = vFILTER + "AGRUPA_SEQUENCIA, ";
                    vFILTER = vFILTER + "CADERNO, ";
                    vFILTER = vFILTER + "CADERNO_SEQUENCIA, ";
                    vFILTER = vFILTER + "ROTA_QUATRO, ";
                    vFILTER = vFILTER + "AGENCIA, ";
                    vFILTER = vFILTER + "CONTA_CORRENTE, ";
                    vFILTER = vFILTER + "LIVRE_VERDE, ";
                    vFILTER = vFILTER + "CANCELADA_MESANO, ";
                    vFILTER = vFILTER + "CANCELADA_NUMNF, ";
                    vFILTER = vFILTER + "ENVIO_BCO, ";
                    vFILTER = vFILTER + "FATURA_FINAL, ";
                    vFILTER = vFILTER + "PAG_GOV, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_DISTRIBUIDA, ";
                    vFILTER = vFILTER + "USINA, ";
                    vFILTER = vFILTER + "SUPRIMENTO, ";
                    vFILTER = vFILTER + "BAIXA_NFV, ";
                    vFILTER = vFILTER + "SITE_ENVIO, ";
                    vFILTER = vFILTER + "TARIFA_BRANCA, ";
                    vFILTER = vFILTER + "MICRO_GERACAO_CONVENIO_SEFAZ, ";
                    vFILTER = vFILTER + "REGIAO, ";
                    vFILTER = vFILTER + "FATURA_COMPLEMENTAR  ";
                    vFILTER = vFILTER + "FROM  NFTRANSICAO ";
                    vFILTER = vFILTER + "WHERE 1 = 1 ";

                    vAND = vFILTER;

                    if (objNfTransicao.ZONA != string.Empty)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND ZONA = ?ZONA "; }
                        else
                        { vAND = vAND + "AND ZONA = ?ZONA "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = vAND + " "; }
                    }

                    if (objNfTransicao.LIVRO != string.Empty)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND LIVRO = ?LIVRO "; }
                        else
                        { vAND = vAND + "AND LIVRO = ?LIVRO "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = vAND + " "; }
                    }


                    if (objNfTransicao.CONTA != string.Empty)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND CONTA = ?CONTA "; }
                        else
                        { vAND = vAND + "AND CONTA = ?CONTA "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = vAND + " "; }
                    }


                    if (objNfTransicao.GRUPO != string.Empty)
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + "AND GRUPO = ?GRUPO "; }
                        else
                        { vAND = vAND + "AND GRUPO = ?GRUPO "; }

                    }
                    else
                    {
                        if (vAND != String.Empty)
                        { vAND = vAND + " "; }
                        else
                        { vAND = vAND + " "; }
                    }


                    cmd = new MySqlCommand(this.QueryExecute);


                    if (objNfTransicao.ZONA != string.Empty)
                    {
                        cmd.Parameters.AddWithValue("?ZONA", objNfTransicao.ZONA.ToString().ToUpper());
                    }

                    if (objNfTransicao.LIVRO != string.Empty)
                    {
                        cmd.Parameters.AddWithValue("?LIVRO", objNfTransicao.LIVRO.ToString().ToUpper());
                    }

                    if (objNfTransicao.CONTA != string.Empty)
                    {
                        cmd.Parameters.AddWithValue("?CONTA", objNfTransicao.CONTA.ToString().ToUpper());
                    }

                    if (objNfTransicao.GRUPO != string.Empty)
                    {
                        cmd.Parameters.AddWithValue("?GRUPO", objNfTransicao.GRUPO.ToString().ToUpper());
                    }


                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

                return dt;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable SelectOthersTables_2(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {
                    vFILTER = vFILTER + "		SELECT ";
                    vFILTER = vFILTER + "	    FATURAS.NUMNF                    AS FATURAS_NUMNF, ";
                    vFILTER = vFILTER + "       FATURAS.CFOP                     AS FATURAS_CFOP, ";
                    vFILTER = vFILTER + "       FATURAS.ZONA                     AS FATURAS_ZONA, ";
                    vFILTER = vFILTER + "       FATURAS.LIVRO                    AS FATURAS_LIVRO, ";
                    vFILTER = vFILTER + "       FATURAS.CONTA                    AS FATURAS_CONTA, ";
                    vFILTER = vFILTER + "       FATURAS.ROTA                     AS FATURAS_ROTA, ";
                    vFILTER = vFILTER + "       FATURAS.VALORTOT                 AS FATURAS_VALORTOT, ";
                    vFILTER = vFILTER + "       FATURAS.VALORLIQ                 AS FATURAS_VALORLIQ, ";
                    vFILTER = vFILTER + "       FATURAS.CODCLAS                  AS FATURAS_CODCLAS, ";
                    vFILTER = vFILTER + "       FATURAS.DATAVENC                 AS FATURAS_DATAVENC, ";
                    vFILTER = vFILTER + "       FATURAS.BANIDENT                 AS FATURAS_BANIDENT, ";
                    vFILTER = vFILTER + "       FATURAS.BANCO_FATUR              AS FATURAS_BANCO_FATUR, ";
                    vFILTER = vFILTER + "       FATURAS.MESANO                   AS FATURAS_MESANO, ";
                    vFILTER = vFILTER + "       FATURAS.MESANO_REF               AS FATURAS_MESANO_REF, ";
                    vFILTER = vFILTER + "       FATURAS.DATAAPR                  AS FATURAS_DATAAPR, ";
                    vFILTER = vFILTER + "       FATURAS.DATAEM                   AS FATURAS_DATAEM, ";
                    vFILTER = vFILTER + "       FATURAS.DATAPROXLEIT             AS FATURAS_DATAPROXLEIT, ";
                    vFILTER = vFILTER + "       FATURAS.DATALEIT                 AS FATURAS_DATALEIT, ";
                    vFILTER = vFILTER + "       FATURAS.DATALEITANT              AS FATURAS_DATALEITANT, ";
                    vFILTER = vFILTER + "       FATURAS.FASE                     AS FATURAS_FASE, ";
                    vFILTER = vFILTER + "       FATURAS.TA                       AS FATURAS_TA, ";
                    vFILTER = vFILTER + "       FATURAS.TENSAO                   AS FATURAS_TENSAO, ";
                    vFILTER = vFILTER + "       FATURAS.CODHASH                  AS FATURAS_CODHASH, ";
                    vFILTER = vFILTER + "       FATURAS.ITENSSERV                AS FATURAS_ITENSSERV, ";
                    vFILTER = vFILTER + "       FATURAS.ITENSIMP                 AS FATURAS_ITENSIMP, ";
                    vFILTER = vFILTER + "       FATURAS.NSU                      AS FATURAS_NSU, ";
                    vFILTER = vFILTER + "       FATURAS.CODBARRA                 AS FATURAS_CODBARRA, ";
                    vFILTER = vFILTER + "       FATURAS.DVCODBARRA               AS FATURAS_DVCODBARRA, ";
                    vFILTER = vFILTER + "       FATURAS.CODBARRA_IMAGEM          AS FATURAS_CODBARRA_IMAGEM, ";
                    vFILTER = vFILTER + "       FATURAS.GRUPO                    AS FATURAS_GRUPO, ";
                    vFILTER = vFILTER + "       FATURAS.CONS_ID                  AS FATURAS_CONS_ID, ";
                    vFILTER = vFILTER + "       FATURAS.UNID_ID                  AS FATURAS_UNID_ID, ";
                    vFILTER = vFILTER + "       FATURAS.PERIODO_TESTE            AS FATURAS_PERIODO_TESTE, ";
                    vFILTER = vFILTER + "       FATURAS.MENSAGEM_BANDEIRA        AS FATURAS_MENSAGEM_BANDEIRA, ";
                    vFILTER = vFILTER + "       FATURAS.LIVRE_VERDE              AS FATURAS_LIVRE_VERDE, ";
                    vFILTER = vFILTER + "       FATURAS.MICRO_GERACAO            AS FATURAS_MICRO_GERACAO, ";
                    vFILTER = vFILTER + "       FATURAS.PARCIALMENTE_CATIVO      AS FATURAS_PARCIALMENTE_CATIVO, ";
                    vFILTER = vFILTER + "       FATURAS.CANCELADA_MESANO         AS FATURAS_CANCELADA_MESANO, ";
                    vFILTER = vFILTER + "       FATURAS.CANCELADA_NUMNF          AS FATURAS_CANCELADA_NUMNF, ";
                    vFILTER = vFILTER + "       CLASSE.CODIGO                    AS CLASSE_CODIGO, ";
                    vFILTER = vFILTER + "       CLASSE.DESCRICAO                 AS CLASSE_DESCRICAO, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.CPF_CNPJ          AS UC_FATURAMENTO_CPF_CNPJ, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.INSC              AS UC_FATURAMENTO_INSC, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.RG                AS UC_FATURAMENTO_RG, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.AGENC             AS UC_FATURAMENTO_AGENC, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.CC                AS UC_FATURAMENTO_CC, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.NOME              AS UC_FATURAMENTO_NOME, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.CIDADE            AS UC_FATURAMENTO_CIDADE, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.DISTRITO          AS UC_FATURAMENTO_DISTRITO, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.BAIRRO            AS UC_FATURAMENTO_BAIRRO, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.END               AS UC_FATURAMENTO_END, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.NUMERO            AS UC_FATURAMENTO_NUMERO, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.COMPLEMENT        AS UC_FATURAMENTO_COMPLEMENT, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.CEP               AS UC_FATURAMENTO_CEP, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.UF                AS UC_FATURAMENTO_UF, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.QUADRA            AS UC_FATURAMENTO_QUADRA, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.LOTE              AS UC_FATURAMENTO_LOTE, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.CID_ENTREGA       AS UC_FATURAMENTO_CID_ENTREGA, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.DIS_ENTREGA       AS UC_FATURAMENTO_DIS_ENTREGA, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.BAI_ENTREGA       AS UC_FATURAMENTO_BAI_ENTREGA, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.END_ENTREGA       AS UC_FATURAMENTO_END_ENTREGA, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.NUM_ENTREGA       AS UC_FATURAMENTO_NUM_ENTREGA, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.COMPL_ENTREGA     AS UC_FATURAMENTO_COMPL_ENTREGA, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.CEP_ENTREGA       AS UC_FATURAMENTO_CEP_ENTREGA, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.UF_ENTREGA        AS UC_FATURAMENTO_UF_ENTREGA, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.QUA_ENTREGA       AS UC_FATURAMENTO_QUA_ENTREGA, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.LOT_ENTREGA       AS UC_FATURAMENTO_LOT_ENTREGA, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.GRUPO             AS UC_FATURAMENTO_GRUPO, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.CONST_KW_P        AS UC_FATURAMENTO_CONST_DEMANDA, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.CONST_KW_FP       AS UC_FATURAMENTO_CONST_DEMANDA_FP, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.CONST_KWH_FP      AS UC_FATURAMENTO_CONST_CONS_FP, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.CONST_KWH_P       AS UC_FATURAMENTO_CONST_CONS_P, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.CONST_KVARH_P     AS UC_FATURAMENTO_CONST_REATIVO_P, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.CONST_KVARH_FP    AS UC_FATURAMENTO_CONST_REATIVO_FP, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.NUM               AS UC_FATURAMENTO_MEDIDORDEMANDA, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.MEDKVARK          AS UC_FATURAMENTO_MEDIDORREATIVO, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.ELETR             AS UC_FATURAMENTO_MEDIDORCONSUMO, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.DEM_CONTR_PONTA   AS UC_FATURAMENTO_DEM_CONTR_PONTA, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.DEM_CONTR_FP      AS UC_FATURAMENTO_DEM_CONTR_FP, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.CONST_KVARH       AS UC_FATURAMENTO_CONST_REATIVO, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.CONST_CONSUMO     AS UC_FATURAMENTO_CONST_CONSUMO, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.DEMANDA_CONTR     AS UC_FATURAMENTO_DEMANDA_CONTR, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.CARGA             AS UC_FATURAMENTO_CARGA, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.FINAL             AS UC_FATURAMENTO_FINAL, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.UNID_ID           AS UC_FATURAMENTO_UNID_ID, ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.SEQUENCIA         AS UC_FATURAMENTO_SEQUENCIA, ";
                    vFILTER = vFILTER + "       CONSUM.CONSREG                   AS CONSUMIDOR_CONSREG, ";
                    vFILTER = vFILTER + "       CONSUM.NOME                      AS CONSUMIDOR_NOME, ";
                    vFILTER = vFILTER + "       CONSUM.CEP                       AS CONSUMIDOR_CEP, ";
                    vFILTER = vFILTER + "       CONSUM.UF                        AS CONSUMIDOR_UF, ";
                    vFILTER = vFILTER + "       CONSUM.CGC                       AS CONSUMIDOR_CGC, ";
                    vFILTER = vFILTER + "       CONSUM.INSC                      AS CONSUMIDOR_INSC, ";
                    vFILTER = vFILTER + "       CONSUM.RG                        AS CONSUMIDOR_RG, ";
                    vFILTER = vFILTER + "       CONSUM.MATRICULA                 AS CONSUMIDOR_MATRICULA   ";
                    vFILTER = vFILTER + "   FROM NFTRANSICAO AS FATURAS ";
                    vFILTER = vFILTER + "   LEFT JOIN UC_FATURAMENTO  ON(UC_FATURAMENTO.ID =  FATURAS.UNID_ID) ";
                    vFILTER = vFILTER + "   LEFT JOIN CONSUM ON(CONSUM.CONSREG =  FATURAS.CONS_ID) ";
                    vFILTER = vFILTER + "   LEFT JOIN CLASSE ON(CLASSE.CODIGO =  FATURAS.CODCLAS) ";
                    vFILTER = vFILTER + "   WHERE 1 = 1  ";

                    vFILTER = vFILTER + objNfTransicao.TA.ToString();

                    vORDERBY = " ";

                    vAND = vFILTER;

                    cmd = new MySqlCommand(this.QueryExecute);

                    dt = objGerenciadorTransacao.GetDataTable(cmd);

                }

                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable SelectOthersTables_3(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {
                    vFILTER = vFILTER + "		SELECT ";
                    vFILTER = vFILTER + "       FATURAS.NUMNF                    AS FATURAS_NUMNF        , ";
                    vFILTER = vFILTER + "       FATURAS.CFOP                     AS FATURAS_CFOP         , ";
                    vFILTER = vFILTER + "       FATURAS.ZONA                     AS FATURAS_ZONA         , ";
                    vFILTER = vFILTER + "       FATURAS.LIVRO                    AS FATURAS_LIVRO        , ";
                    vFILTER = vFILTER + "       FATURAS.CONTA                    AS FATURAS_CONTA        , ";
                    vFILTER = vFILTER + "       FATURAS.ROTA                     AS FATURAS_ROTA         , ";
                    vFILTER = vFILTER + "       FATURAS.UNID_ID                  AS FATURAS_UNID_ID      , ";
                    vFILTER = vFILTER + "       FATURAS.CONS_ID                  AS FATURAS_CONS_ID      , ";
                    vFILTER = vFILTER + "       FATURAS.VALORTOT                 AS FATURAS_VALORTOT     , ";
                    vFILTER = vFILTER + "       FATURAS.VALORLIQ                 AS FATURAS_VALORLIQ     , ";
                    vFILTER = vFILTER + "       FATURAS.CODCLAS                  AS FATURAS_CODCLAS      , ";
                    vFILTER = vFILTER + "       FATURAS.DATAVENC                 AS FATURAS_DATAVENC     , ";
                    vFILTER = vFILTER + "       FATURAS.BANIDENT                 AS FATURAS_BANIDENT     , ";
                    vFILTER = vFILTER + "       FATURAS.BANCO_FATUR              AS FATURAS_BANCO_FATUR  , ";
                    vFILTER = vFILTER + "       FATURAS.MESANO                   AS FATURAS_MESANO       , ";
                    vFILTER = vFILTER + "       FATURAS.MESANO_REF               AS FATURAS_MESANO_REF   , ";
                    vFILTER = vFILTER + "       FATURAS.DATAAPR                  AS FATURAS_DATAAPR      , ";
                    vFILTER = vFILTER + "       FATURAS.DATAEM                   AS FATURAS_DATAEM       , ";
                    vFILTER = vFILTER + "       FATURAS.DATAPROXLEIT             AS FATURAS_DATAPROXLEIT , ";
                    vFILTER = vFILTER + "       FATURAS.DATALEIT                 AS FATURAS_DATALEIT     , ";
                    vFILTER = vFILTER + "       FATURAS.DATALEITANT              AS FATURAS_DATALEITANT  , ";
                    vFILTER = vFILTER + "       FATURAS.FASE                     AS FATURAS_FASE         , ";
                    vFILTER = vFILTER + "       FATURAS.TA                       AS FATURAS_TA           , ";
                    vFILTER = vFILTER + "       FATURAS.TENSAO                   AS FATURAS_TENSAO       , ";
                    vFILTER = vFILTER + "       FATURAS.CODHASH                  AS FATURAS_CODHASH      , ";
                    vFILTER = vFILTER + "       FATURAS.ITENSSERV                AS FATURAS_ITENSSERV    , ";
                    vFILTER = vFILTER + "       FATURAS.NSU                      AS FATURAS_NSU          , ";
                    vFILTER = vFILTER + "       FATURAS.CODBARRA                 AS FATURAS_CODBARRA     , ";
                    vFILTER = vFILTER + "       FATURAS.DVCODBARRA               AS FATURAS_DVCODBARRA   , ";
                    vFILTER = vFILTER + "       FATURAS.CODBARRA_IMAGEM          AS FATURAS_CODBARRA_IMAGEM   , ";
                    vFILTER = vFILTER + "       FATURAS.NUM_MED                  AS FATURAS_NUM_MED      , ";
                    vFILTER = vFILTER + "       FATURAS.CONST_MED                AS FATURAS_CONST_MED    , ";
                    vFILTER = vFILTER + "       FATURAS.ITENSIMP                 AS FATURAS_ITENSIMP     , ";
                    vFILTER = vFILTER + "       FATURAS.DIAS                     AS FATURAS_DIAS         , ";
                    vFILTER = vFILTER + "       FATURAS.MENSAGEM_BANDEIRA        AS FATURAS_MENSAGEM_BANDEIRA, ";
                    vFILTER = vFILTER + "       FATURAS.IRRIGACAO_AQUICULTURA    AS FATURAS_IRRIGACAO_AQUICULTURA, ";
                    vFILTER = vFILTER + "       FATURAS.MICRO_GERACAO            AS FATURAS_MICRO_GERACAO, ";
                    vFILTER = vFILTER + "       FATURAS.MICRO_GERACAO_DISTRIBUIDA AS FATURAS_MICRO_GERACAO_DISTRIBUIDA, ";
                    vFILTER = vFILTER + "       FATURAS.MICRO_GERACAO_CONVENIO_SEFAZ AS FATURAS_MICRO_GERACAO_CONVENIO_SEFAZ, ";
                    vFILTER = vFILTER + "       FATURAS.TARIFA_BRANCA            AS FATURAS_TARIFA_BRANCA, ";
                    vFILTER = vFILTER + "       FATURAS.CANCELADA_MESANO         AS FATURAS_CANCELADA_MESANO, ";
                    vFILTER = vFILTER + "       FATURAS.CANCELADA_NUMNF          AS FATURAS_CANCELADA_NUMNF, ";
                    vFILTER = vFILTER + "       CLASSE.CODIGO                    AS CLASSE_CODIGO        , ";
                    vFILTER = vFILTER + "       CLASSE.DESCRICAO                 AS CLASSE_DESCRICAO     , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.CPF_CNPJ          AS UC_FATURAMENTO_CPF_CNPJ       , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.INSC              AS UC_FATURAMENTO_INSC           , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.RG                AS UC_FATURAMENTO_RG             , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.AGENC             AS UC_FATURAMENTO_AGENC          , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.CC                AS UC_FATURAMENTO_CC             , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.NOME              AS UC_FATURAMENTO_NOME           , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.CIDADE            AS UC_FATURAMENTO_CIDADE         , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.DISTRITO          AS UC_FATURAMENTO_DISTRITO       , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.BAIRRO            AS UC_FATURAMENTO_BAIRRO         , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.END               AS UC_FATURAMENTO_END            , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.NUMERO            AS UC_FATURAMENTO_NUMERO         , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.COMPLEMENT        AS UC_FATURAMENTO_COMPLEMENT     , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.CEP               AS UC_FATURAMENTO_CEP            , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.UF                AS UC_FATURAMENTO_UF             , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.QUADRA            AS UC_FATURAMENTO_QUADRA         , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.LOTE              AS UC_FATURAMENTO_LOTE           , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.ENTREGA           AS UC_FATURAMENTO_ENTREGA        , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.CID_ENTREGA       AS UC_FATURAMENTO_CID_ENTREGA    , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.DIS_ENTREGA       AS UC_FATURAMENTO_DIS_ENTREGA    , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.BAI_ENTREGA       AS UC_FATURAMENTO_BAI_ENTREGA    , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.END_ENTREGA       AS UC_FATURAMENTO_END_ENTREGA    , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.NUM_ENTREGA       AS UC_FATURAMENTO_NUM_ENTREGA    , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.COMPL_ENTREGA     AS UC_FATURAMENTO_COMPL_ENTREGA  , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.CEP_ENTREGA       AS UC_FATURAMENTO_CEP_ENTREGA    , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.UF_ENTREGA        AS UC_FATURAMENTO_UF_ENTREGA     , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.QUA_ENTREGA       AS UC_FATURAMENTO_QUA_ENTREGA    , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.LOT_ENTREGA       AS UC_FATURAMENTO_LOT_ENTREGA    , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.ULTLEIT           AS UC_FATURAMENTO_ULTLEIT        , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.LEIT              AS UC_FATURAMENTO_LEIT           , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.GRUPO             AS UC_FATURAMENTO_GRUPO          , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.REGIAO            AS UC_FATURAMENTO_REGIAO         , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.UNID_ID           AS UC_FATURAMENTO_UNID_ID        , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.CONS_ID           AS UC_FATURAMENTO_CONS_ID        , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.CONJUGE_FATURA    AS UC_FATURAMENTO_CONJUGE_FATURA , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.SEQUENCIA         AS UC_FATURAMENTO_SEQUENCIA      , ";
                    vFILTER = vFILTER + "       UC_FATURAMENTO.ORDEM_JUDICIAL    AS UC_FATURAMENTO_ORDEM_JUDICIAL , ";
                    vFILTER = vFILTER + "       CONSUM.NOME                      AS CONSUMIDOR_NOME      , ";
                    vFILTER = vFILTER + "       CONSUM.NOME_CONJUGE              AS CONSUMIDOR_CONJUGE   , ";
                    vFILTER = vFILTER + "       CONSUM.CEP                       AS CONSUMIDOR_CEP       , ";
                    vFILTER = vFILTER + "       CONSUM.UF                        AS CONSUMIDOR_UF        , ";
                    vFILTER = vFILTER + "       CONSUM.CGC                       AS CONSUMIDOR_CGC       , ";
                    vFILTER = vFILTER + "       CONSUM.INSC                      AS CONSUMIDOR_INSC      , ";
                    vFILTER = vFILTER + "       CONSUM.RG                        AS CONSUMIDOR_RG        , ";
                    vFILTER = vFILTER + "       CONSUM.MATRICULA                 AS CONSUMIDOR_MATRICULA   ";
                    vFILTER = vFILTER + "   FROM NFTRANSICAO AS FATURAS ";
                    vFILTER = vFILTER + "   LEFT JOIN UC_FATURAMENTO ON(UC_FATURAMENTO.ID =  FATURAS.UNID_ID) ";
                    vFILTER = vFILTER + "   LEFT JOIN CONSUM ON(CONSUM.CONSREG =  FATURAS.CONS_ID) ";
                    vFILTER = vFILTER + "   LEFT JOIN CLASSE ON(CLASSE.CODIGO =  FATURAS.CODCLAS) ";
                    vFILTER = vFILTER + "   WHERE 1 = 1  ";

                    vFILTER = vFILTER + objNfTransicao.TA.ToString();


                    vORDERBY = "ORDER BY UC_FATURAMENTO.SEQUENCIA ASC ";

                    vAND = vFILTER;

                    cmd = new MySqlCommand(this.QueryExecute);

                    dt = objGerenciadorTransacao.GetDataTable(cmd);

                }

                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable SelectOthersTables_4(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {


                    vFILTER = vFILTER + "  DISTINCT DATALEIT  ";

                    vORDERBY = " GROUP BY 1 ";

                    if (objNfTransicao.REN863_2019)
                    {
                        vAND = vAND + "  AND ANOMES_FAT >= ?MESANOINI AND ";
                        vAND = vAND + "  ANOMES_FAT <= ?MESANOFIM ";
                    }
                    else
                    {
                        vAND = vAND + "  AND MESANO_REF >= ?MESANOINI AND ";
                        vAND = vAND + "  MESANO_REF <= ?MESANOFIM ";
                    }

                    cmd = new MySqlCommand(this.QuerySelect);

                    if (!string.IsNullOrEmpty(objNfTransicao.MESANOINI) && !string.IsNullOrEmpty(objNfTransicao.MESANOFIM))
                    {
                        cmd.Parameters.AddWithValue("?MESANOINI", objNfTransicao.MESANOINI);
                        cmd.Parameters.AddWithValue("?MESANOFIM", objNfTransicao.MESANOFIM);
                    }

                    dt = objGerenciadorTransacao.GetDataTable(cmd);

                }

                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable SelectOthersTables_5(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {
                    vFILTER = vFILTER + "		SELECT ";
                    vFILTER = vFILTER + "       FATURAS.ROTA                       AS FATURAS_ROTA, ";
                    vFILTER = vFILTER + "       FATURAS.MESANO                     AS FATURAS_MESANO, ";
                    vFILTER = vFILTER + "       CONSUM.NOME                        AS CONSUMIDOR_NOME, ";
                    vFILTER = vFILTER + "       CONSUM.EMAIL                       AS CONSUMIDOR_EMAIL ";
                    vFILTER = vFILTER + "   FROM NFTRANSICAO AS FATURAS ";
                    vFILTER = vFILTER + "   LEFT JOIN UC_FATURAMENTO  ON(UC_FATURAMENTO.ID =  FATURAS.UNID_ID) ";
                    vFILTER = vFILTER + "   LEFT JOIN CONSUM ON(CONSUM.CONSREG =  FATURAS.CONS_ID) ";
                    vFILTER = vFILTER + "   LEFT JOIN CLASSE ON(CLASSE.CODIGO =  FATURAS.CODCLAS) ";
                    vFILTER = vFILTER + "   WHERE 1 = 1  ";

                    vFILTER = vFILTER + "   AND FATURAS.NUMNF  = ?NUMNF ";
                    vFILTER = vFILTER + "   AND FATURAS.MESANO = ?MESANO ";

                    vORDERBY = " ";

                    vAND = vFILTER;

                    cmd = new MySqlCommand(this.QueryExecute);
                    cmd.Parameters.AddWithValue("?NUMNF", objNfTransicao.NUMNF);
                    cmd.Parameters.AddWithValue("?MESANO", objNfTransicao.MESANO);
                    cmd.CommandTimeout = 3600;

                    dt = objGerenciadorTransacao.GetDataTable(cmd);

                }

                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable SelectCount(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {
                    vFILTER = vFILTER + "COUNT(*) ";

                    vINNERJOIN = " ";

                    vORDERBY = " ";

                    vAND = vAND + "AND MESANO = ?MESANO ";


                    cmd = new MySqlCommand(this.QuerySelect);


                    cmd.Parameters.AddWithValue("?MESANO", objNfTransicao.MESANO.ToString().ToUpper());


                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

                return dt;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable SelectCount_1(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {

                    vFILTER = vFILTER + "COUNT(*) ";

                    vINNERJOIN = " ";

                    vORDERBY = " ";

                    vAND = vAND + " AND NUMNF = ?NUMNF ";
                    vAND = vAND + " AND MESANO = ?MESANO ";



                    cmd = new MySqlCommand(this.QuerySelect);


                    cmd.Parameters.AddWithValue("?MESANO", objNfTransicao.MESANO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?NUMNF", objNfTransicao.NUMNF);


                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

                return dt;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable SelectCount_2(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {

                    vFILTER = vFILTER + "COUNT(*) AS QTD ";


                    vINNERJOIN = " ";

                    vORDERBY = " ";

                    vAND = vAND + "AND NUMNF = ?NUMNF ";
                    vAND = vAND + "AND MESANO_REF = ?MESANO_REF ";


                    cmd = new MySqlCommand(this.QuerySelect);

                    cmd.Parameters.AddWithValue("?NUMNF", objNfTransicao.NUMNF);
                    cmd.Parameters.AddWithValue("?MESANO_REF", objNfTransicao.MESANO_REF);


                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

                return dt;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        public DataTable Delete(entidadeNfTransicao objNfTransicao)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

                using (objGerenciadorTransacao = FabricaGerenciadorTransacao.GetGerenciador(TipoBDGerenciador.MySql))
                {
                    vORDERBY = " ";

                    vAND = vAND + "AND EXISTS (SELECT * FROM NF WHERE NF.NUMNF = NFTRANSICAO.NUMNF AND NF.MESANO = NFTRANSICAO.MESANO) ";


                    cmd = new MySqlCommand(this.QueryDelete);

                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

                return dt;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        #endregion

        #region " Comandos SQL "

        StringBuilder sb = new StringBuilder();

        protected string QueryInsert
        {
            get
            {
                this.sb.Clear();

                this.sb.AppendLine("INSERT INTO  ");
                this.sb.AppendLine("NFTRANSICAO SET  ");
                this.sb.AppendLine(vFILTER);

                return sb.ToString();
            }
        }

        protected string QueryUpdate
        {
            get
            {
                this.sb.Clear();

                this.sb.AppendLine("UPDATE  ");
                this.sb.AppendLine("NFTRANSICAO SET  ");
                this.sb.AppendLine(vFILTER);
                this.sb.AppendLine("WHERE 1 = 1 ");
                this.sb.AppendLine(vAND);

                return sb.ToString();
            }
        }

        protected string QueryDelete
        {
            get
            {
                this.sb.Clear();

                this.sb.AppendLine("DELETE FROM NFTRANSICAO ");
                this.sb.AppendLine("WHERE 1 = 1 ");
                this.sb.AppendLine(vAND);
                this.sb.AppendLine(vORDERBY);

                return sb.ToString();
            }
        }

        protected string QuerySelect
        {
            get
            {
                this.sb.Clear();

                this.sb.AppendLine("SELECT ");
                this.sb.AppendLine(vFILTER);
                this.sb.AppendLine("FROM ");
                this.sb.AppendLine("NFTRANSICAO  ");
                this.sb.AppendLine(vINNERJOIN);
                this.sb.AppendLine("WHERE 1 = 1  ");
                this.sb.AppendLine(vAND);
                this.sb.AppendLine(vORDERBY);

                return sb.ToString();
            }
        }

        protected string QueryExecute
        {
            get
            {
                this.sb.Clear();

                this.sb.AppendLine(vAND);
                this.sb.AppendLine(vORDERBY);

                return sb.ToString();
            }
        }


        #endregion


    }
}
