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;

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

        #region Métodos

        public void Insert(entidadeTempFaturaA objTempFaturaA)
        {

            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 + "SEGVIA                  = ?SEGVIA   , ";
                    vFILTER = vFILTER + "NOMEMAQUINA             = ?NOMEMAQUINA   , ";
                    //DADOS DA FATURA
                    vFILTER = vFILTER + "NUMNF                   = ?NUMNF   , ";
                    vFILTER = vFILTER + "CFOP                    = ?CFOP   , ";
                    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 + "VALORTOT                = ?VALORTOT   , ";
                    vFILTER = vFILTER + "VALORLIQ                = ?VALORLIQ   , ";
                    vFILTER = vFILTER + "CODCLAS                 = ?CODCLAS   , ";
                    vFILTER = vFILTER + "DATAVENC                = ?DATAVENC   , ";
                    vFILTER = vFILTER + "BANCO_FATUR             = ?BANCO_FATUR   , ";
                    vFILTER = vFILTER + "MESANO                  = ?MESANO   , ";
                    vFILTER = vFILTER + "MESANOREF               = ?MESANOREF , ";
                    vFILTER = vFILTER + "ANOMES_FAT              = ?ANOMES_FAT ,   ";
                    vFILTER = vFILTER + "DATAAPR                 = ?DATAAPR   , ";
                    vFILTER = vFILTER + "DATAEMISSAO             = ?DATAEMISSAO   , ";
                    vFILTER = vFILTER + "DATAPROXLEIT            = ?DATAPROXLEIT   , ";
                    vFILTER = vFILTER + "DATALEIT                = ?DATALEIT   , ";
                    vFILTER = vFILTER + "DATALEITANT             = ?DATALEITANT   , ";
                    vFILTER = vFILTER + "FASE                    = ?FASE   , ";
                    vFILTER = vFILTER + "TA                      = ?TA   , ";
                    vFILTER = vFILTER + "TENSAO                  = ?TENSAO   , ";
                    vFILTER = vFILTER + "CODHASH                 = ?CODHASH   , ";
                    vFILTER = vFILTER + "CODBARRA                = ?CODBARRA   , ";
                    vFILTER = vFILTER + "LINHADIGITAVEL          = ?LINHADIGITAVEL   , ";
                    vFILTER = vFILTER + "DVCODBARRA              = ?DVCODBARRA   , ";
                    vFILTER = vFILTER + "DESCLASSE               = ?DESCLASSE   , ";
                    vFILTER = vFILTER + "FLGST                   = ?FLGST   , ";
                    vFILTER = vFILTER + "CANCELADA_MESANO        = ?CANCELADA_MESANO   , ";
                    vFILTER = vFILTER + "CANCELADA_NUMNF         = ?CANCELADA_NUMNF   , ";
                    //DADOS DA UNIDADE
                    vFILTER = vFILTER + "CGC                     = ?CGC   , ";
                    vFILTER = vFILTER + "INSC                    = ?INSC   , ";
                    vFILTER = vFILTER + "RG                      = ?RG   , ";
                    vFILTER = vFILTER + "AGENC                   = ?AGENC   , ";
                    vFILTER = vFILTER + "CC                      = ?CC   , ";
                    vFILTER = vFILTER + "NOMECONS                = ?NOMECONS   , ";
                    vFILTER = vFILTER + "CIDADE                  = ?CIDADE   , ";
                    vFILTER = vFILTER + "DISTRITO                = ?DISTRITO   , ";
                    vFILTER = vFILTER + "BAIRRO                  = ?BAIRRO   , ";
                    vFILTER = vFILTER + "END                     = ?END   , ";
                    vFILTER = vFILTER + "NUMERO                  = ?NUMERO   , ";
                    vFILTER = vFILTER + "COMPLEMENT              = ?COMPLEMENT   , ";
                    vFILTER = vFILTER + "CEP                     = ?CEP   , ";
                    vFILTER = vFILTER + "UF                      = ?UF   , ";
                    vFILTER = vFILTER + "QUADRA                  = ?QUADRA   , ";
                    vFILTER = vFILTER + "LOTE                    = ?LOTE   , ";
                    vFILTER = vFILTER + "CID_ENTREGA             = ?CID_ENTREGA   , ";
                    vFILTER = vFILTER + "DIS_ENTREGA             = ?DIS_ENTREGA   , ";
                    vFILTER = vFILTER + "BAI_ENTREGA             = ?BAI_ENTREGA   , ";
                    vFILTER = vFILTER + "END_ENTREGA             = ?END_ENTREGA   , ";
                    vFILTER = vFILTER + "NUM_ENTREGA             = ?NUM_ENTREGA   , ";
                    vFILTER = vFILTER + "COMPL_ENTREGA           = ?COMPL_ENTREGA   , ";
                    vFILTER = vFILTER + "CEP_ENTREGA             = ?CEP_ENTREGA   , ";
                    vFILTER = vFILTER + "UF_ENTREGA              = ?UF_ENTREGA   , ";
                    vFILTER = vFILTER + "QUA_ENTREGA             = ?QUA_ENTREGA   , ";
                    vFILTER = vFILTER + "LOT_ENTREGA             = ?LOT_ENTREGA   , ";
                    vFILTER = vFILTER + "GRUPO                   = ?GRUPO   , ";
                    vFILTER = vFILTER + "CONST_DEMANDA           = ?CONST_DEMANDA   , ";
                    vFILTER = vFILTER + "CONST_CONS_FP           = ?CONST_CONS_FP   , ";
                    vFILTER = vFILTER + "CONST_CONS_P            = ?CONST_CONS_P   , ";
                    vFILTER = vFILTER + "CONST_KVARH_P           = ?CONST_KVARH_P   , ";
                    vFILTER = vFILTER + "CONST_KVARH_FP          = ?CONST_KVARH_FP   , ";
                    vFILTER = vFILTER + "MEDKW                   = ?MEDKW   , ";
                    vFILTER = vFILTER + "MEDKVARK                = ?MEDKVARK   , ";
                    vFILTER = vFILTER + "ELETR                   = ?ELETR   , ";
                    vFILTER = vFILTER + "DEMCONTRP               = ?DEMCONTRP   , ";
                    vFILTER = vFILTER + "DEMCONTRFP              = ?DEMCONTRFP   , ";
                    vFILTER = vFILTER + "DEMCONTRPANTERIOR       = ?DEMCONTRPANTERIOR   , ";
                    vFILTER = vFILTER + "DEMCONTRFPANTERIOR      = ?DEMCONTRFPANTERIOR   , ";
                    vFILTER = vFILTER + "PERIODO_TESTE           = ?PERIODO_TESTE   , ";
                    vFILTER = vFILTER + "CONST_KVARH             = ?CONST_KVARH   , ";
                    vFILTER = vFILTER + "CONST_KW                = ?CONST_KW   , ";
                    vFILTER = vFILTER + "CONST_KWH               = ?CONST_KWH   , ";
                    vFILTER = vFILTER + "CONST_DEMANDA_FP        = ?CONST_DEMANDA_FP   , ";
                    vFILTER = vFILTER + "KW_CONT                 = ?KW_CONT   , ";
                    vFILTER = vFILTER + "CARGA                   = ?CARGA   , ";
                    vFILTER = vFILTER + "PERDA                   = ?PERDA   , ";
                    vFILTER = vFILTER + "REFCONS                 = ?REFCONS   , ";
                    //LEITURAS
                    //REATIVO CONSUMO
                    vFILTER = vFILTER + "LEIT_KVARH_ANT          = ?LEIT_KVARH_ANT   , ";
                    vFILTER = vFILTER + "LEIT_KVARH_ATUAL        = ?LEIT_KVARH_ATUAL   , ";
                    vFILTER = vFILTER + "LEITANT_KVARH_P         = ?LEITANT_KVARH_P   , ";
                    vFILTER = vFILTER + "LEIT_KVARH_P            = ?LEIT_KVARH_P   , ";
                    vFILTER = vFILTER + "LEITANT_KVARH_FP        = ?LEITANT_KVARH_FP   , ";
                    vFILTER = vFILTER + "LEIT_KVARH_FP           = ?LEIT_KVARH_FP   , ";
                    //DEMANDA
                    vFILTER = vFILTER + "LEIT_KW_ANT             = ?LEIT_KW_ANT   , ";
                    vFILTER = vFILTER + "LEIT_KW_ATUAL           = ?LEIT_KW_ATUAL   , ";
                    vFILTER = vFILTER + "LEITANT_KW_P            = ?LEITANT_KW_P   , ";
                    vFILTER = vFILTER + "LEIT_KW_P               = ?LEIT_KW_P   , ";
                    vFILTER = vFILTER + "LEITANT_KW_FP           = ?LEITANT_KW_FP   , ";
                    vFILTER = vFILTER + "LEIT_KW_FP              = ?LEIT_KW_FP   , ";
                    //CONSUMO
                    vFILTER = vFILTER + "LEIT_KWH_ANT            = ?LEIT_KWH_ANT   , ";
                    vFILTER = vFILTER + "LEIT_KWH_ATUAL          = ?LEIT_KWH_ATUAL   , ";
                    vFILTER = vFILTER + "LEITANT_KWH_P           = ?LEITANT_KWH_P   , ";
                    vFILTER = vFILTER + "LEIT_KWH_P              = ?LEIT_KWH_P   , ";
                    vFILTER = vFILTER + "LEITANT_KWH_FP          = ?LEITANT_KWH_FP   , ";
                    vFILTER = vFILTER + "LEIT_KWH_FP             = ?LEIT_KWH_FP   , ";
                    //MICRO GERAÇÃO
                    vFILTER = vFILTER + "LEITANT_REVERSO_P       = ?LEITANT_REVERSO_P   , ";
                    vFILTER = vFILTER + "LEIT_REVERSO_P          = ?LEIT_REVERSO_P   , ";
                    vFILTER = vFILTER + "LEITANT_REVERSO_FP      = ?LEITANT_REVERSO_FP   , ";
                    vFILTER = vFILTER + "LEIT_REVERSO_FP         = ?LEIT_REVERSO_FP   , ";
                    vFILTER = vFILTER + "MICRO_GERACAO           = ?MICRO_GERACAO   , ";
                    //CONSUMO RESERVADO
                    vFILTER = vFILTER + "LEITANT_KWH_RES         = ?LEITANT_KWH_RES   , ";
                    vFILTER = vFILTER + "LEIT_KWH_RES            = ?LEIT_KWH_RES   , ";
                    //QUANTIDADES
                    //CONSUMO
                    vFILTER = vFILTER + "CONSMEDIDOP             = ?CONSMEDIDOP   , ";
                    vFILTER = vFILTER + "CONSMEDIDOFP            = ?CONSMEDIDOFP   , ";
                    vFILTER = vFILTER + "CONSFATURADOP           = ?CONSFATURADOP   , ";
                    vFILTER = vFILTER + "CONSFATURADOFP          = ?CONSFATURADOFP   , ";
                    vFILTER = vFILTER + "CONSCONTRP              = ?CONSCONTRP   , ";
                    vFILTER = vFILTER + "CONSCONTRFP             = ?CONSCONTRFP   , ";
                    vFILTER = vFILTER + "KWH_MED                 = ?KWH_MED   , ";
                    vFILTER = vFILTER + "KWH_FAT                 = ?KWH_FAT   , ";
                    vFILTER = vFILTER + "CONSRESERVADO           = ?CONSRESERVADO   , ";
                    //MICRO GERAÇÃO
                    vFILTER = vFILTER + "KWH_REVERSO_P           = ?KWH_REVERSO_P   , ";
                    vFILTER = vFILTER + "KWH_REVERSO_FP          = ?KWH_REVERSO_FP   , ";
                    vFILTER = vFILTER + "KWH_REVERSO_RES_P       = ?KWH_REVERSO_RES_P   , ";
                    vFILTER = vFILTER + "KWH_REVERSO_RES_FP      = ?KWH_REVERSO_RES_FP   , ";
                    vFILTER = vFILTER + "KWH_REVERSO_REC_P       = ?KWH_REVERSO_REC_P   , ";
                    vFILTER = vFILTER + "KWH_REVERSO_REC_FP      = ?KWH_REVERSO_REC_FP   , ";
                    vFILTER = vFILTER + "KWH_ENVIADO             = ?KWH_ENVIADO          , ";
                    vFILTER = vFILTER + "KWH_SALDO               = ?KWH_SALDO            , ";
                    //DEMANDA
                    vFILTER = vFILTER + "DEMMEDIDAP              = ?DEMMEDIDAP   , ";
                    vFILTER = vFILTER + "DEMMEDIDAFP             = ?DEMMEDIDAFP   , ";
                    vFILTER = vFILTER + "DEMFATURP               = ?DEMFATURP   , ";
                    vFILTER = vFILTER + "DEMFATURFP              = ?DEMFATURFP   , ";
                    vFILTER = vFILTER + "ULTRAP                  = ?ULTRAP   , ";
                    vFILTER = vFILTER + "ULTRAFP                 = ?ULTRAFP   , ";
                    vFILTER = vFILTER + "KW_MED                  = ?KW_MED   , ";
                    vFILTER = vFILTER + "KW_FAT                  = ?KW_FAT   , ";
                    vFILTER = vFILTER + "KW_ULTRA                = ?KW_ULTRA   , ";
                    //FATOR DE POTENCIA
                    vFILTER = vFILTER + "KVARH_FPOT              = ?KVARH_FPOT   , ";
                    //REATIVO CONSUMO
                    vFILTER = vFILTER + "FER_P                   = ?FER_P   , ";
                    vFILTER = vFILTER + "FER_FP                  = ?FER_FP   , ";
                    vFILTER = vFILTER + "KVARH_MED               = ?KVARH_MED   , ";
                    //REATIVO DEMANDA
                    vFILTER = vFILTER + "LEIT_KVAR_P             = ?LEIT_KVAR_P   , ";
                    vFILTER = vFILTER + "LEIT_KVAR_FP            = ?LEIT_KVAR_FP   , ";
                    //TRIBUTOS
                    //ICMS
                    vFILTER = vFILTER + "BASE_ICMS               = ?BASE_ICMS   , ";
                    vFILTER = vFILTER + "ALIQ_ICMS               = ?ALIQ_ICMS   , ";
                    vFILTER = vFILTER + "VLR_ICMS                = ?VLR_ICMS   , ";
                    vFILTER = vFILTER + "BASE_ICMS2              = ?BASE_ICMS2   , ";
                    vFILTER = vFILTER + "ALIQ_ICMS2              = ?ALIQ_ICMS2   , ";
                    vFILTER = vFILTER + "VLR_ICMS2               = ?VLR_ICMS2   , ";
                    //PIS
                    vFILTER = vFILTER + "BASEPIS                 = ?BASEPIS   , ";
                    vFILTER = vFILTER + "ALIQPIS                 = ?ALIQPIS   , ";
                    vFILTER = vFILTER + "VLRPIS                  = ?VLRPIS   , ";
                    //COFINS
                    vFILTER = vFILTER + "BASECOFINS              = ?BASECOFINS   , ";
                    vFILTER = vFILTER + "ALIQCOFINS              = ?ALIQCOFINS   , ";
                    vFILTER = vFILTER + "VLRCOFINS               = ?VLRCOFINS   , ";
                    //********************************************
                    //TRIBUTAÇÃO DA COMERCIALIZAÇÃO DOS LIVRES
                    // ICMS
                    vFILTER = vFILTER + "BASE_ICMS_ST            = ?BASE_ICMS_ST   , ";
                    vFILTER = vFILTER + "ALIQ_ICMS_ST            = ?ALIQ_ICMS_ST   , ";
                    vFILTER = vFILTER + "VLR_ICMS_ST             = ?VLR_ICMS_ST   , ";
                    //PIS
                    vFILTER = vFILTER + "BASEPIS_ST              = ?BASEPIS_ST   , ";
                    vFILTER = vFILTER + "ALIQPIS_ST              = ?ALIQPIS_ST   , ";
                    vFILTER = vFILTER + "VLRPIS_ST               = ?VLRPIS_ST   , ";
                    //COFINS
                    vFILTER = vFILTER + "BASECOFINS_ST           = ?BASECOFINS_ST   , ";
                    vFILTER = vFILTER + "ALIQCOFINS_ST           = ?ALIQCOFINS_ST   , ";
                    vFILTER = vFILTER + "VLRCOFINS_ST            = ?VLRCOFINS_ST   , ";
                    //VALOR DA COMPRA (R$)
                    vFILTER = vFILTER + "VLRENERGIA_ST           = ?VLRENERGIA_ST   , ";
                    vFILTER = vFILTER + "VLRPCMEDIO_ST           = ?VLRPCMEDIO_ST   , ";
                    vFILTER = vFILTER + "VLRCONSUMO_ST           = ?VLRCONSUMO_ST   , ";
                    vFILTER = vFILTER + "REFERENCIA_ST           = ?REFERENCIA_ST   , ";
                    //********************************************
                    //INDICADOR DE CONTINUIDADE
                    vFILTER = vFILTER + "DEC_META                = ?DEC_META   , ";
                    vFILTER = vFILTER + "FEC_META                = ?FEC_META   , ";
                    vFILTER = vFILTER + "DIC_META                = ?DIC_META   , ";
                    vFILTER = vFILTER + "FIC_META                = ?FIC_META   , ";
                    vFILTER = vFILTER + "DMIC                    = ?DMIC   , ";
                    vFILTER = vFILTER + "DEC_REA                 = ?DEC_REA   , ";
                    vFILTER = vFILTER + "FEC_REA                 = ?FEC_REA   , ";
                    vFILTER = vFILTER + "DIC_REA                 = ?DIC_REA   , ";
                    vFILTER = vFILTER + "FIC_REA                 = ?FIC_REA   , ";
                    vFILTER = vFILTER + "DMIC_REA                = ?DMIC_REA   , ";
                    vFILTER = vFILTER + "REFINDICADOR            = ?REFINDICADOR   , ";
                    //RENTENÇÃO TRIBUTÁRIA
                    //CONSUMO
                    vFILTER = vFILTER + "RET_PIS                 = ?RET_PIS   , ";
                    vFILTER = vFILTER + "RET_COFINS              = ?RET_COFINS   , ";
                    vFILTER = vFILTER + "RET_CSLL                = ?RET_CSLL   , ";
                    vFILTER = vFILTER + "RET_IRPJC               = ?RET_IRPJC   , ";
                    //DEMANDA
                    vFILTER = vFILTER + "RET_IRPJD               = ?RET_IRPJD   , ";
                    vFILTER = vFILTER + "RET_CSLLD               = ?RET_CSLLD   , ";
                    vFILTER = vFILTER + "RET_COFINSD             = ?RET_COFINSD   , ";
                    vFILTER = vFILTER + "RET_PISD                = ?RET_PISD   , ";
                    //COMPOSIÇÃO DA FATURA
                    vFILTER = vFILTER + "COMP_ENERGIA            = ?COMP_ENERGIA   , ";
                    vFILTER = vFILTER + "COMP_TRANSMISSAO        = ?COMP_TRANSMISSAO   , ";
                    vFILTER = vFILTER + "COMP_DISTRIBUICAO       = ?COMP_DISTRIBUICAO   , ";
                    vFILTER = vFILTER + "COMP_ENCARGOS_SETORIAIS = ?COMP_ENCARGOS_SETORIAIS   , ";
                    //TARIFAS
                    vFILTER = vFILTER + "TA_DEMP                 = ?TA_DEMP   , ";
                    vFILTER = vFILTER + "TA_DEMFP                = ?TA_DEMFP   , ";
                    vFILTER = vFILTER + "TA_ULTRAP               = ?TA_ULTRAP   , ";
                    vFILTER = vFILTER + "TA_ULTRAFP              = ?TA_ULTRAFP   , ";
                    vFILTER = vFILTER + "TA_CONSP                = ?TA_CONSP   , ";
                    vFILTER = vFILTER + "TA_CONSFP               = ?TA_CONSFP   , ";
                    //MENSAGEM DA FATURA
                    vFILTER = vFILTER + "MENSAGEM_BANDEIRA       = ?MENSAGEM_BANDEIRA   , ";
                    vFILTER = vFILTER + "BANDEIRA                = ?BANDEIRA   , ";
                    vFILTER = vFILTER + "FRENTEVERSO             = ?FRENTEVERSO   , ";
                    vFILTER = vFILTER + "LIVRE_VERDE             = ?LIVRE_VERDE   , ";
                    vFILTER = vFILTER + "PARC_CATIVO             = ?PARC_CATIVO   , ";
                    vFILTER = vFILTER + "MENSAGEM                = ?MENSAGEM   , ";
                    vFILTER = vFILTER + "ITENSIMP                = ?ITENSIMP   , ";
                    vFILTER = vFILTER + "SEQUENCIA               = ?SEQUENCIA  , ";
                    vFILTER = vFILTER + "MATRICULA               = ?MATRICULA ";


                    cmd = new MySqlCommand(this.QueryInsert);


                    cmd.Parameters.AddWithValue("?SEGVIA", objTempFaturaA.SEGVIA);
                    cmd.Parameters.AddWithValue("?NOMEMAQUINA", objTempFaturaA.NOMEMAQUINA.ToString().ToUpper());
                    //DADOS DA FATURA
                    cmd.Parameters.AddWithValue("?NUMNF", objTempFaturaA.NUMNF);
                    cmd.Parameters.AddWithValue("?CFOP", objTempFaturaA.CFOP);
                    cmd.Parameters.AddWithValue("?ZONA", objTempFaturaA.ZONA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LIVRO", objTempFaturaA.LIVRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTA", objTempFaturaA.CONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?ROTA", objTempFaturaA.ROTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONS_ID", objTempFaturaA.CONS_ID.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?UNID_ID", objTempFaturaA.UNID_ID.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?VALORTOT", objTempFaturaA.VALORTOT);
                    cmd.Parameters.AddWithValue("?VALORLIQ", objTempFaturaA.VALORLIQ);
                    cmd.Parameters.AddWithValue("?CODCLAS", objTempFaturaA.CODCLAS.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DATAVENC", objTempFaturaA.DATAVENC);
                    cmd.Parameters.AddWithValue("?BANCO_FATUR", objTempFaturaA.BANCO_FATUR.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MESANO", objTempFaturaA.MESANO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MESANOREF", objTempFaturaA.MESANOREF);

                    cmd.Parameters.AddWithValue("?DATAAPR", objTempFaturaA.DATAAPR);
                    cmd.Parameters.AddWithValue("?DATAEMISSAO", objTempFaturaA.DATAEMISSAO);
                    cmd.Parameters.AddWithValue("?DATAPROXLEIT", objTempFaturaA.DATAPROXLEIT);
                    cmd.Parameters.AddWithValue("?DATALEIT", objTempFaturaA.DATALEIT);
                    cmd.Parameters.AddWithValue("?DATALEITANT", objTempFaturaA.DATALEITANT);
                    cmd.Parameters.AddWithValue("?FASE", objTempFaturaA.FASE.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?TA", objTempFaturaA.TA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?TENSAO", objTempFaturaA.TENSAO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CODHASH", objTempFaturaA.CODHASH.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CODBARRA", objTempFaturaA.CODBARRA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DVCODBARRA", objTempFaturaA.DVCODBARRA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LINHADIGITAVEL", objTempFaturaA.LINHADIGITAVEL.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DESCLASSE", objTempFaturaA.DESCLASSE.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?FLGST", objTempFaturaA.FLGST.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CANCELADA_MESANO", objTempFaturaA.CANCELADA_MESANO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CANCELADA_NUMNF", objTempFaturaA.CANCELADA_NUMNF);
                    //DADOS DA UNIDADE
                    cmd.Parameters.AddWithValue("?CGC", objTempFaturaA.CGC.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?INSC", objTempFaturaA.INSC.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?RG", objTempFaturaA.RG.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?AGENC", objTempFaturaA.AGENC.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CC", objTempFaturaA.CC.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?NOMECONS", objTempFaturaA.NOMECONS.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CIDADE", objTempFaturaA.CIDADE.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DISTRITO", objTempFaturaA.DISTRITO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?BAIRRO", objTempFaturaA.BAIRRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?END", objTempFaturaA.END.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?NUMERO", objTempFaturaA.NUMERO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?COMPLEMENT", objTempFaturaA.COMPLEMENT.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CEP", objTempFaturaA.CEP.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?UF", objTempFaturaA.UF.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?QUADRA", objTempFaturaA.QUADRA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LOTE", objTempFaturaA.LOTE.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CID_ENTREGA", objTempFaturaA.CID_ENTREGA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DIS_ENTREGA", objTempFaturaA.DIS_ENTREGA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?BAI_ENTREGA", objTempFaturaA.BAI_ENTREGA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?END_ENTREGA", objTempFaturaA.END_ENTREGA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?NUM_ENTREGA", objTempFaturaA.NUM_ENTREGA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?COMPL_ENTREGA", objTempFaturaA.COMPL_ENTREGA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CEP_ENTREGA", objTempFaturaA.CEP_ENTREGA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?UF_ENTREGA", objTempFaturaA.UF_ENTREGA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?QUA_ENTREGA", objTempFaturaA.QUA_ENTREGA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LOT_ENTREGA", objTempFaturaA.LOT_ENTREGA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?GRUPO", objTempFaturaA.GRUPO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONST_DEMANDA", objTempFaturaA.CONST_DEMANDA);
                    cmd.Parameters.AddWithValue("?CONST_CONS_FP", objTempFaturaA.CONST_CONS_FP);
                    cmd.Parameters.AddWithValue("?CONST_CONS_P", objTempFaturaA.CONST_CONS_P);
                    cmd.Parameters.AddWithValue("?CONST_KVARH_P", objTempFaturaA.CONST_KVARH_P);
                    cmd.Parameters.AddWithValue("?CONST_KVARH_FP", objTempFaturaA.CONST_KVARH_FP);
                    cmd.Parameters.AddWithValue("?MEDKW", objTempFaturaA.MEDKW.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MEDKVARK", objTempFaturaA.MEDKVARK);
                    cmd.Parameters.AddWithValue("?ELETR", objTempFaturaA.ELETR);
                    cmd.Parameters.AddWithValue("?DEMCONTRP", objTempFaturaA.DEMCONTRP);
                    cmd.Parameters.AddWithValue("?DEMCONTRFP", objTempFaturaA.DEMCONTRFP);
                    cmd.Parameters.AddWithValue("?DEMCONTRPANTERIOR", objTempFaturaA.DEMCONTRPANTERIOR);
                    cmd.Parameters.AddWithValue("?DEMCONTRFPANTERIOR", objTempFaturaA.DEMCONTRFPANTERIOR);
                    cmd.Parameters.AddWithValue("?PERIODO_TESTE", objTempFaturaA.PERIODO_TESTE);
                    cmd.Parameters.AddWithValue("?CONST_KVARH", objTempFaturaA.CONST_KVARH);
                    cmd.Parameters.AddWithValue("?CONST_KW", objTempFaturaA.CONST_KW);
                    cmd.Parameters.AddWithValue("?CONST_KWH", objTempFaturaA.CONST_KWH);
                    cmd.Parameters.AddWithValue("?CONST_DEMANDA_FP", objTempFaturaA.CONST_DEMANDA_FP);
                    cmd.Parameters.AddWithValue("?KW_CONT", objTempFaturaA.KW_CONT);
                    cmd.Parameters.AddWithValue("?CARGA", objTempFaturaA.CARGA);
                    cmd.Parameters.AddWithValue("?PERDA", objTempFaturaA.PERDA);
                    cmd.Parameters.AddWithValue("?REFCONS", objTempFaturaA.REFCONS);
                    //LEITURAS
                    //REATIVO CONSUMO
                    cmd.Parameters.AddWithValue("?LEIT_KVARH_ANT", objTempFaturaA.LEIT_KVARH_ANT);
                    cmd.Parameters.AddWithValue("?LEIT_KVARH_ATUAL", objTempFaturaA.LEIT_KVARH_ATUAL);
                    cmd.Parameters.AddWithValue("?LEITANT_KVARH_P", objTempFaturaA.LEITANT_KVARH_P);
                    cmd.Parameters.AddWithValue("?LEIT_KVARH_P", objTempFaturaA.LEIT_KVARH_P);
                    cmd.Parameters.AddWithValue("?LEITANT_KVARH_FP", objTempFaturaA.LEITANT_KVARH_FP);
                    cmd.Parameters.AddWithValue("?LEIT_KVARH_FP", objTempFaturaA.LEIT_KVARH_FP);
                    //DEMANDA
                    cmd.Parameters.AddWithValue("?LEIT_KW_ANT", objTempFaturaA.LEIT_KW_ANT);
                    cmd.Parameters.AddWithValue("?LEIT_KW_ATUAL", objTempFaturaA.LEIT_KW_ATUAL);
                    cmd.Parameters.AddWithValue("?LEITANT_KW_P", objTempFaturaA.LEITANT_KW_P);
                    cmd.Parameters.AddWithValue("?LEIT_KW_P", objTempFaturaA.LEIT_KW_P);
                    cmd.Parameters.AddWithValue("?LEITANT_KW_FP", objTempFaturaA.LEITANT_KW_FP);
                    cmd.Parameters.AddWithValue("?LEIT_KW_FP", objTempFaturaA.LEIT_KW_FP);
                    //CONSUMO
                    cmd.Parameters.AddWithValue("?LEIT_KWH_ANT", objTempFaturaA.LEIT_KWH_ANT);
                    cmd.Parameters.AddWithValue("?LEIT_KWH_ATUAL", objTempFaturaA.LEIT_KWH_ATUAL);
                    cmd.Parameters.AddWithValue("?LEITANT_KWH_P", objTempFaturaA.LEITANT_KWH_P);
                    cmd.Parameters.AddWithValue("?LEIT_KWH_P", objTempFaturaA.LEIT_KWH_P);
                    cmd.Parameters.AddWithValue("?LEITANT_KWH_FP", objTempFaturaA.LEITANT_KWH_FP);
                    cmd.Parameters.AddWithValue("?LEIT_KWH_FP", objTempFaturaA.LEIT_KWH_FP);
                    //MICRO GERAÇÃO
                    cmd.Parameters.AddWithValue("?LEITANT_REVERSO_P", objTempFaturaA.LEITANT_REVERSO_P);
                    cmd.Parameters.AddWithValue("?LEIT_REVERSO_P", objTempFaturaA.LEIT_REVERSO_P);
                    cmd.Parameters.AddWithValue("?LEITANT_REVERSO_FP", objTempFaturaA.LEITANT_REVERSO_FP);
                    cmd.Parameters.AddWithValue("?LEIT_REVERSO_FP", objTempFaturaA.LEIT_REVERSO_FP);
                    cmd.Parameters.AddWithValue("?MICRO_GERACAO", objTempFaturaA.MICRO_GERACAO);
                    //CONSUMO RESERVADO
                    cmd.Parameters.AddWithValue("?LEITANT_KWH_RES", objTempFaturaA.LEITANT_KWH_RES);
                    cmd.Parameters.AddWithValue("?LEIT_KWH_RES", objTempFaturaA.LEIT_KWH_RES);
                    //QUANTIDADES
                    //CONSUMO
                    cmd.Parameters.AddWithValue("?CONSMEDIDOP", objTempFaturaA.CONSMEDIDOP);
                    cmd.Parameters.AddWithValue("?CONSMEDIDOFP", objTempFaturaA.CONSMEDIDOFP);
                    cmd.Parameters.AddWithValue("?CONSFATURADOP", objTempFaturaA.CONSFATURADOP);
                    cmd.Parameters.AddWithValue("?CONSFATURADOFP", objTempFaturaA.CONSFATURADOFP);
                    cmd.Parameters.AddWithValue("?CONSCONTRP", objTempFaturaA.CONSCONTRP);
                    cmd.Parameters.AddWithValue("?CONSCONTRFP", objTempFaturaA.CONSCONTRFP);
                    cmd.Parameters.AddWithValue("?KWH_MED", objTempFaturaA.KWH_MED);
                    cmd.Parameters.AddWithValue("?KWH_FAT", objTempFaturaA.KWH_FAT);
                    cmd.Parameters.AddWithValue("?CONSRESERVADO", objTempFaturaA.CONSRESERVADO);
                    //MICRO GERAÇÃO
                    cmd.Parameters.AddWithValue("?KWH_REVERSO_P", objTempFaturaA.KWH_REVERSO_P);
                    cmd.Parameters.AddWithValue("?KWH_REVERSO_FP", objTempFaturaA.KWH_REVERSO_FP);
                    cmd.Parameters.AddWithValue("?KWH_REVERSO_RES_P", objTempFaturaA.KWH_REVERSO_RES_P);
                    cmd.Parameters.AddWithValue("?KWH_REVERSO_RES_FP", objTempFaturaA.KWH_REVERSO_RES_FP);
                    cmd.Parameters.AddWithValue("?KWH_REVERSO_REC_P", objTempFaturaA.KWH_REVERSO_REC_P);
                    cmd.Parameters.AddWithValue("?KWH_REVERSO_REC_FP", objTempFaturaA.KWH_REVERSO_REC_FP);
                    cmd.Parameters.AddWithValue("?KWH_ENVIADO", objTempFaturaA.KWH_ENVIADO);
                    cmd.Parameters.AddWithValue("?KWH_SALDO", objTempFaturaA.KWH_SALDO);
                    //DEMANDA
                    cmd.Parameters.AddWithValue("?DEMMEDIDAP", objTempFaturaA.DEMMEDIDAP);
                    cmd.Parameters.AddWithValue("?DEMMEDIDAFP", objTempFaturaA.DEMMEDIDAFP);
                    cmd.Parameters.AddWithValue("?DEMFATURP", objTempFaturaA.DEMFATURP);
                    cmd.Parameters.AddWithValue("?DEMFATURFP", objTempFaturaA.DEMFATURFP);
                    cmd.Parameters.AddWithValue("?ULTRAP", objTempFaturaA.ULTRAP);
                    cmd.Parameters.AddWithValue("?ULTRAFP", objTempFaturaA.ULTRAFP);
                    cmd.Parameters.AddWithValue("?KW_MED", objTempFaturaA.KW_MED);
                    cmd.Parameters.AddWithValue("?KW_FAT", objTempFaturaA.KW_FAT);
                    cmd.Parameters.AddWithValue("?KW_ULTRA", objTempFaturaA.KW_ULTRA);
                    //FATOR DE POTENCIA
                    cmd.Parameters.AddWithValue("?KVARH_FPOT", objTempFaturaA.KVARH_FPOT);
                    //REATIVO CONSUMO
                    cmd.Parameters.AddWithValue("?FER_P", objTempFaturaA.FER_P);
                    cmd.Parameters.AddWithValue("?FER_FP", objTempFaturaA.FER_FP);
                    cmd.Parameters.AddWithValue("?KVARH_MED", objTempFaturaA.KVARH_MED);
                    //REATIVO DEMANDA
                    cmd.Parameters.AddWithValue("?LEIT_KVAR_P", objTempFaturaA.LEIT_KVAR_P);
                    cmd.Parameters.AddWithValue("?LEIT_KVAR_FP", objTempFaturaA.LEIT_KVAR_FP);
                    //TRIBUTOS
                    //ICMS
                    cmd.Parameters.AddWithValue("?BASE_ICMS", objTempFaturaA.BASE_ICMS);
                    cmd.Parameters.AddWithValue("?ALIQ_ICMS", objTempFaturaA.ALIQ_ICMS);
                    cmd.Parameters.AddWithValue("?VLR_ICMS", objTempFaturaA.VLR_ICMS);
                    cmd.Parameters.AddWithValue("?BASE_ICMS2", objTempFaturaA.BASE_ICMS2);
                    cmd.Parameters.AddWithValue("?ALIQ_ICMS2", objTempFaturaA.ALIQ_ICMS2);
                    cmd.Parameters.AddWithValue("?VLR_ICMS2", objTempFaturaA.VLR_ICMS2);
                    //PIS
                    cmd.Parameters.AddWithValue("?BASEPIS", objTempFaturaA.BASEPIS);
                    cmd.Parameters.AddWithValue("?ALIQPIS", objTempFaturaA.ALIQPIS);
                    cmd.Parameters.AddWithValue("?VLRPIS", objTempFaturaA.VLRPIS);
                    //COFINS
                    cmd.Parameters.AddWithValue("?BASECOFINS", objTempFaturaA.BASECOFINS);
                    cmd.Parameters.AddWithValue("?ALIQCOFINS", objTempFaturaA.ALIQCOFINS);
                    cmd.Parameters.AddWithValue("?VLRCOFINS", objTempFaturaA.VLRCOFINS);
                    //********************************************
                    //TRIBUTAÇÃO DA COMERCIALIZAÇÃO DOS LIVRES
                    // ICMS
                    cmd.Parameters.AddWithValue("?BASE_ICMS_ST", objTempFaturaA.BASE_ICMS_ST);
                    cmd.Parameters.AddWithValue("?ALIQ_ICMS_ST", objTempFaturaA.ALIQ_ICMS_ST);
                    cmd.Parameters.AddWithValue("?VLR_ICMS_ST", objTempFaturaA.VLR_ICMS_ST);
                    //PIS
                    cmd.Parameters.AddWithValue("?BASEPIS_ST", objTempFaturaA.BASEPIS_ST);
                    cmd.Parameters.AddWithValue("?ALIQPIS_ST", objTempFaturaA.ALIQPIS_ST);
                    cmd.Parameters.AddWithValue("?VLRPIS_ST", objTempFaturaA.VLRPIS_ST);
                    //COFINS
                    cmd.Parameters.AddWithValue("?BASECOFINS_ST", objTempFaturaA.BASECOFINS_ST);
                    cmd.Parameters.AddWithValue("?ALIQCOFINS_ST", objTempFaturaA.ALIQCOFINS_ST);
                    cmd.Parameters.AddWithValue("?VLRCOFINS_ST", objTempFaturaA.VLRCOFINS_ST);
                    //VALOR DA COMPRA (R$)
                    cmd.Parameters.AddWithValue("?VLRENERGIA_ST", objTempFaturaA.VLRENERGIA_ST);
                    cmd.Parameters.AddWithValue("?VLRPCMEDIO_ST", objTempFaturaA.VLRPCMEDIO_ST);
                    cmd.Parameters.AddWithValue("?VLRCONSUMO_ST", objTempFaturaA.VLRCONSUMO_ST);
                    cmd.Parameters.AddWithValue("?REFERENCIA_ST", objTempFaturaA.REFERENCIA_ST.ToString().ToUpper());
                    //********************************************
                    //INDICADOR DE CONTINUIDADE
                    cmd.Parameters.AddWithValue("?DEC_META", objTempFaturaA.DEC_META);
                    cmd.Parameters.AddWithValue("?FEC_META", objTempFaturaA.FEC_META);
                    cmd.Parameters.AddWithValue("?DIC_META", objTempFaturaA.DIC_META);
                    cmd.Parameters.AddWithValue("?FIC_META", objTempFaturaA.FIC_META);
                    cmd.Parameters.AddWithValue("?DMIC", objTempFaturaA.DMIC);
                    cmd.Parameters.AddWithValue("?DEC_REA", objTempFaturaA.DEC_REA);
                    cmd.Parameters.AddWithValue("?FEC_REA", objTempFaturaA.FEC_REA);
                    cmd.Parameters.AddWithValue("?DIC_REA", objTempFaturaA.DIC_REA);
                    cmd.Parameters.AddWithValue("?FIC_REA", objTempFaturaA.FIC_REA);
                    cmd.Parameters.AddWithValue("?DMIC_REA", objTempFaturaA.DMIC_REA);
                    cmd.Parameters.AddWithValue("?REFINDICADOR", objTempFaturaA.REFINDICADOR.ToString().ToUpper());
                    //RENTENÇÃO TRIBUTÁRIA
                    //CONSUMO
                    cmd.Parameters.AddWithValue("?RET_PIS", objTempFaturaA.RET_PIS);
                    cmd.Parameters.AddWithValue("?RET_COFINS", objTempFaturaA.RET_COFINS);
                    cmd.Parameters.AddWithValue("?RET_CSLL", objTempFaturaA.RET_CSLL);
                    cmd.Parameters.AddWithValue("?RET_IRPJC", objTempFaturaA.RET_IRPJC);
                    //DEMANDA
                    cmd.Parameters.AddWithValue("?RET_IRPJD", objTempFaturaA.RET_IRPJD);
                    cmd.Parameters.AddWithValue("?RET_CSLLD", objTempFaturaA.RET_CSLLD);
                    cmd.Parameters.AddWithValue("?RET_COFINSD", objTempFaturaA.RET_COFINSD);
                    cmd.Parameters.AddWithValue("?RET_PISD", objTempFaturaA.RET_PISD);
                    //COMPOSIÇÃO DA FATURA
                    cmd.Parameters.AddWithValue("?COMP_ENERGIA", objTempFaturaA.COMP_ENERGIA);
                    cmd.Parameters.AddWithValue("?COMP_TRANSMISSAO", objTempFaturaA.COMP_TRANSMISSAO);
                    cmd.Parameters.AddWithValue("?COMP_DISTRIBUICAO", objTempFaturaA.COMP_DISTRIBUICAO);
                    cmd.Parameters.AddWithValue("?COMP_ENCARGOS_SETORIAIS", objTempFaturaA.COMP_ENCARGOS_SETORIAIS);
                    //TARIFAS
                    cmd.Parameters.AddWithValue("?TA_DEMP", objTempFaturaA.TA_DEMP.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?TA_DEMFP", objTempFaturaA.TA_DEMFP.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?TA_ULTRAP", objTempFaturaA.TA_ULTRAP.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?TA_ULTRAFP", objTempFaturaA.TA_ULTRAFP.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?TA_CONSP", objTempFaturaA.TA_CONSP.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?TA_CONSFP", objTempFaturaA.TA_CONSFP.ToString().ToUpper());
                    //MENSAGEM DA FATURA
                    cmd.Parameters.AddWithValue("?MENSAGEM_BANDEIRA", objTempFaturaA.MENSAGEM_BANDEIRA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?BANDEIRA", objTempFaturaA.BANDEIRA);
                    cmd.Parameters.AddWithValue("?FRENTEVERSO", objTempFaturaA.FRENTEVERSO);
                    cmd.Parameters.AddWithValue("?LIVRE_VERDE", objTempFaturaA.LIVRE_VERDE);
                    cmd.Parameters.AddWithValue("?PARC_CATIVO", objTempFaturaA.PARC_CATIVO);
                    cmd.Parameters.AddWithValue("?MENSAGEM", objTempFaturaA.MENSAGEM);
                    cmd.Parameters.AddWithValue("?ITENSIMP", objTempFaturaA.ITENSIMP.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?SEQUENCIA", objTempFaturaA.SEQUENCIA);
                    cmd.Parameters.AddWithValue("?MATRICULA", objTempFaturaA.MATRICULA);
                    cmd.Parameters.AddWithValue("?ANOMES_FAT", objTempFaturaA.ANOMES_FAT);

                    objGerenciadorTransacao.Execute(cmd);
                }

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

        public void Update(entidadeTempFaturaA objTempFaturaA)
        {

            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 + "     TEMP_FATURA_A.FAT_PENDENTES = (SELECT COUNT(NF.NUMNF) ";
                    vFILTER = vFILTER + "                                             FROM NF ";
                    vFILTER = vFILTER + "                                            WHERE NF.ZONA  = TEMP_FATURA_A.ZONA ";
                    vFILTER = vFILTER + "                                              AND NF.LIVRO = TEMP_FATURA_A.LIVRO ";
                    vFILTER = vFILTER + "                                              AND NF.CONTA = TEMP_FATURA_A.CONTA ";
                    vFILTER = vFILTER + "                                              AND TRIM(NF.FLGST) = ''";
                    vFILTER = vFILTER + "                                              AND (NF.DATAPAG = '0000-00-00' OR NF.DATAPAG IS NULL)";
                    vFILTER = vFILTER + "                                              AND NF.MESANO <> ?MESANO ) ";
                    vAND = vAND + "AND TEMP_FATURA_A.MESANO = ?MESANO ";
                    vAND = vAND + "AND TEMP_FATURA_A.NOMEMAQUINA = ?NOMEMAQUINA ";

                    cmd = new MySqlCommand(this.QueryUpdate);


                    cmd.Parameters.AddWithValue("?MESANO", objTempFaturaA.ANOMES_FAT.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?NOMEMAQUINA", objTempFaturaA.NOMEMAQUINA.ToString().ToUpper());


                    objGerenciadorTransacao.Execute(cmd);
                }


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

        public void Update_1(entidadeTempFaturaA objTempFaturaA)
        {

            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 + "SEGVIA                  = ?SEGVIA   , ";
                    vFILTER = vFILTER + "NOMEMAQUINA             = ?NOMEMAQUINA   , ";
                    //DADOS DA FATURA
                    vFILTER = vFILTER + "NUMNF                   = ?NUMNF   , ";
                    vFILTER = vFILTER + "CFOP                    = ?CFOP   , ";
                    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 + "VALORTOT                = ?VALORTOT   , ";
                    vFILTER = vFILTER + "VALORLIQ                = ?VALORLIQ   , ";
                    vFILTER = vFILTER + "CODCLAS                 = ?CODCLAS   , ";
                    vFILTER = vFILTER + "DATAVENC                = ?DATAVENC   , ";
                    vFILTER = vFILTER + "BANCO_FATUR             = ?BANCO_FATUR   , ";
                    vFILTER = vFILTER + "MESANO                  = ?MESANO   , ";
                    vFILTER = vFILTER + "MESANOREF               = ?MESANOREF , ";
                    vFILTER = vFILTER + "ANOMES_FAT              = ?ANOMES_FAT ,   ";
                    vFILTER = vFILTER + "DATAAPR                 = ?DATAAPR   , ";
                    vFILTER = vFILTER + "DATAEMISSAO             = ?DATAEMISSAO   , ";
                    vFILTER = vFILTER + "DATAPROXLEIT            = ?DATAPROXLEIT   , ";
                    vFILTER = vFILTER + "DATALEIT                = ?DATALEIT   , ";
                    vFILTER = vFILTER + "DATALEITANT             = ?DATALEITANT   , ";
                    vFILTER = vFILTER + "FASE                    = ?FASE   , ";
                    vFILTER = vFILTER + "TA                      = ?TA   , ";
                    vFILTER = vFILTER + "TENSAO                  = ?TENSAO   , ";
                    vFILTER = vFILTER + "CODHASH                 = ?CODHASH   , ";
                    vFILTER = vFILTER + "CODBARRA                = ?CODBARRA   , ";
                    vFILTER = vFILTER + "LINHADIGITAVEL          = ?LINHADIGITAVEL   , ";
                    vFILTER = vFILTER + "DVCODBARRA              = ?DVCODBARRA   , ";
                    vFILTER = vFILTER + "DESCLASSE               = ?DESCLASSE   , ";
                    vFILTER = vFILTER + "FLGST                   = ?FLGST   , ";
                    vFILTER = vFILTER + "CANCELADA_MESANO        = ?CANCELADA_MESANO   , ";
                    vFILTER = vFILTER + "CANCELADA_NUMNF         = ?CANCELADA_NUMNF   , ";
                    //DADOS DA UNIDADE
                    vFILTER = vFILTER + "CGC                     = ?CGC   , ";
                    vFILTER = vFILTER + "INSC                    = ?INSC   , ";
                    vFILTER = vFILTER + "RG                      = ?RG   , ";
                    vFILTER = vFILTER + "AGENC                   = ?AGENC   , ";
                    vFILTER = vFILTER + "CC                      = ?CC   , ";
                    vFILTER = vFILTER + "NOMECONS                = ?NOMECONS   , ";
                    vFILTER = vFILTER + "CIDADE                  = ?CIDADE   , ";
                    vFILTER = vFILTER + "DISTRITO                = ?DISTRITO   , ";
                    vFILTER = vFILTER + "BAIRRO                  = ?BAIRRO   , ";
                    vFILTER = vFILTER + "END                     = ?END   , ";
                    vFILTER = vFILTER + "NUMERO                  = ?NUMERO   , ";
                    vFILTER = vFILTER + "COMPLEMENT              = ?COMPLEMENT   , ";
                    vFILTER = vFILTER + "CEP                     = ?CEP   , ";
                    vFILTER = vFILTER + "UF                      = ?UF   , ";
                    vFILTER = vFILTER + "QUADRA                  = ?QUADRA   , ";
                    vFILTER = vFILTER + "LOTE                    = ?LOTE   , ";
                    vFILTER = vFILTER + "CID_ENTREGA             = ?CID_ENTREGA   , ";
                    vFILTER = vFILTER + "DIS_ENTREGA             = ?DIS_ENTREGA   , ";
                    vFILTER = vFILTER + "BAI_ENTREGA             = ?BAI_ENTREGA   , ";
                    vFILTER = vFILTER + "END_ENTREGA             = ?END_ENTREGA   , ";
                    vFILTER = vFILTER + "NUM_ENTREGA             = ?NUM_ENTREGA   , ";
                    vFILTER = vFILTER + "COMPL_ENTREGA           = ?COMPL_ENTREGA   , ";
                    vFILTER = vFILTER + "CEP_ENTREGA             = ?CEP_ENTREGA   , ";
                    vFILTER = vFILTER + "UF_ENTREGA              = ?UF_ENTREGA   , ";
                    vFILTER = vFILTER + "QUA_ENTREGA             = ?QUA_ENTREGA   , ";
                    vFILTER = vFILTER + "LOT_ENTREGA             = ?LOT_ENTREGA   , ";
                    vFILTER = vFILTER + "GRUPO                   = ?GRUPO   , ";
                    vFILTER = vFILTER + "CONST_DEMANDA           = ?CONST_DEMANDA   , ";
                    vFILTER = vFILTER + "CONST_CONS_FP           = ?CONST_CONS_FP   , ";
                    vFILTER = vFILTER + "CONST_CONS_P            = ?CONST_CONS_P   , ";
                    vFILTER = vFILTER + "CONST_KVARH_P           = ?CONST_KVARH_P   , ";
                    vFILTER = vFILTER + "CONST_KVARH_FP          = ?CONST_KVARH_FP   , ";
                    vFILTER = vFILTER + "MEDKW                   = ?MEDKW   , ";
                    vFILTER = vFILTER + "MEDKVARK                = ?MEDKVARK   , ";
                    vFILTER = vFILTER + "ELETR                   = ?ELETR   , ";
                    vFILTER = vFILTER + "DEMCONTRP               = ?DEMCONTRP   , ";
                    vFILTER = vFILTER + "DEMCONTRFP              = ?DEMCONTRFP   , ";
                    vFILTER = vFILTER + "DEMCONTRPANTERIOR       = ?DEMCONTRPANTERIOR   , ";
                    vFILTER = vFILTER + "DEMCONTRFPANTERIOR      = ?DEMCONTRFPANTERIOR   , ";
                    vFILTER = vFILTER + "PERIODO_TESTE           = ?PERIODO_TESTE   , ";
                    vFILTER = vFILTER + "CONST_KVARH             = ?CONST_KVARH   , ";
                    vFILTER = vFILTER + "CONST_KW                = ?CONST_KW   , ";
                    vFILTER = vFILTER + "CONST_KWH               = ?CONST_KWH   , ";
                    vFILTER = vFILTER + "CONST_DEMANDA_FP        = ?CONST_DEMANDA_FP   , ";
                    vFILTER = vFILTER + "KW_CONT                 = ?KW_CONT   , ";
                    vFILTER = vFILTER + "CARGA                   = ?CARGA   , ";
                    vFILTER = vFILTER + "PERDA                   = ?PERDA   , ";
                    vFILTER = vFILTER + "REFCONS                 = ?REFCONS   , ";
                    //LEITURAS
                    //REATIVO CONSUMO
                    vFILTER = vFILTER + "LEIT_KVARH_ANT          = ?LEIT_KVARH_ANT   , ";
                    vFILTER = vFILTER + "LEIT_KVARH_ATUAL        = ?LEIT_KVARH_ATUAL   , ";
                    vFILTER = vFILTER + "LEITANT_KVARH_P         = ?LEITANT_KVARH_P   , ";
                    vFILTER = vFILTER + "LEIT_KVARH_P            = ?LEIT_KVARH_P   , ";
                    vFILTER = vFILTER + "LEITANT_KVARH_FP        = ?LEITANT_KVARH_FP   , ";
                    vFILTER = vFILTER + "LEIT_KVARH_FP           = ?LEIT_KVARH_FP   , ";
                    //DEMANDA
                    vFILTER = vFILTER + "LEIT_KW_ANT             = ?LEIT_KW_ANT   , ";
                    vFILTER = vFILTER + "LEIT_KW_ATUAL           = ?LEIT_KW_ATUAL   , ";
                    vFILTER = vFILTER + "LEITANT_KW_P            = ?LEITANT_KW_P   , ";
                    vFILTER = vFILTER + "LEIT_KW_P               = ?LEIT_KW_P   , ";
                    vFILTER = vFILTER + "LEITANT_KW_FP           = ?LEITANT_KW_FP   , ";
                    vFILTER = vFILTER + "LEIT_KW_FP              = ?LEIT_KW_FP   , ";
                    //CONSUMO
                    vFILTER = vFILTER + "LEIT_KWH_ANT            = ?LEIT_KWH_ANT   , ";
                    vFILTER = vFILTER + "LEIT_KWH_ATUAL          = ?LEIT_KWH_ATUAL   , ";
                    vFILTER = vFILTER + "LEITANT_KWH_P           = ?LEITANT_KWH_P   , ";
                    vFILTER = vFILTER + "LEIT_KWH_P              = ?LEIT_KWH_P   , ";
                    vFILTER = vFILTER + "LEITANT_KWH_FP          = ?LEITANT_KWH_FP   , ";
                    vFILTER = vFILTER + "LEIT_KWH_FP             = ?LEIT_KWH_FP   , ";
                    //MICRO GERAÇÃO
                    vFILTER = vFILTER + "LEITANT_REVERSO_P       = ?LEITANT_REVERSO_P   , ";
                    vFILTER = vFILTER + "LEIT_REVERSO_P          = ?LEIT_REVERSO_P   , ";
                    vFILTER = vFILTER + "LEITANT_REVERSO_FP      = ?LEITANT_REVERSO_FP   , ";
                    vFILTER = vFILTER + "LEIT_REVERSO_FP         = ?LEIT_REVERSO_FP   , ";
                    vFILTER = vFILTER + "MICRO_GERACAO           = ?MICRO_GERACAO   , ";
                    //CONSUMO RESERVADO
                    vFILTER = vFILTER + "LEITANT_KWH_RES         = ?LEITANT_KWH_RES   , ";
                    vFILTER = vFILTER + "LEIT_KWH_RES            = ?LEIT_KWH_RES   , ";
                    //QUANTIDADES
                    //CONSUMO
                    vFILTER = vFILTER + "CONSMEDIDOP             = ?CONSMEDIDOP   , ";
                    vFILTER = vFILTER + "CONSMEDIDOFP            = ?CONSMEDIDOFP   , ";
                    vFILTER = vFILTER + "CONSFATURADOP           = ?CONSFATURADOP   , ";
                    vFILTER = vFILTER + "CONSFATURADOFP          = ?CONSFATURADOFP   , ";
                    vFILTER = vFILTER + "CONSCONTRP              = ?CONSCONTRP   , ";
                    vFILTER = vFILTER + "CONSCONTRFP             = ?CONSCONTRFP   , ";
                    vFILTER = vFILTER + "KWH_MED                 = ?KWH_MED   , ";
                    vFILTER = vFILTER + "KWH_FAT                 = ?KWH_FAT   , ";
                    vFILTER = vFILTER + "CONSRESERVADO           = ?CONSRESERVADO   , ";
                    //MICRO GERAÇÃO
                    vFILTER = vFILTER + "KWH_REVERSO_P           = ?KWH_REVERSO_P   , ";
                    vFILTER = vFILTER + "KWH_REVERSO_FP          = ?KWH_REVERSO_FP   , ";
                    vFILTER = vFILTER + "KWH_REVERSO_RES_P       = ?KWH_REVERSO_RES_P   , ";
                    vFILTER = vFILTER + "KWH_REVERSO_RES_FP      = ?KWH_REVERSO_RES_FP   , ";
                    vFILTER = vFILTER + "KWH_REVERSO_REC_P       = ?KWH_REVERSO_REC_P   , ";
                    vFILTER = vFILTER + "KWH_REVERSO_REC_FP      = ?KWH_REVERSO_REC_FP   , ";
                    vFILTER = vFILTER + "KWH_ENVIADO             = ?KWH_ENVIADO          , ";
                    vFILTER = vFILTER + "KWH_SALDO               = ?KWH_SALDO            , ";
                    //DEMANDA
                    vFILTER = vFILTER + "DEMMEDIDAP              = ?DEMMEDIDAP   , ";
                    vFILTER = vFILTER + "DEMMEDIDAFP             = ?DEMMEDIDAFP   , ";
                    vFILTER = vFILTER + "DEMFATURP               = ?DEMFATURP   , ";
                    vFILTER = vFILTER + "DEMFATURFP              = ?DEMFATURFP   , ";
                    vFILTER = vFILTER + "ULTRAP                  = ?ULTRAP   , ";
                    vFILTER = vFILTER + "ULTRAFP                 = ?ULTRAFP   , ";
                    vFILTER = vFILTER + "KW_MED                  = ?KW_MED   , ";
                    vFILTER = vFILTER + "KW_FAT                  = ?KW_FAT   , ";
                    vFILTER = vFILTER + "KW_ULTRA                = ?KW_ULTRA   , ";
                    //FATOR DE POTENCIA
                    vFILTER = vFILTER + "KVARH_FPOT              = ?KVARH_FPOT   , ";
                    //REATIVO CONSUMO
                    vFILTER = vFILTER + "FER_P                   = ?FER_P   , ";
                    vFILTER = vFILTER + "FER_FP                  = ?FER_FP   , ";
                    vFILTER = vFILTER + "KVARH_MED               = ?KVARH_MED   , ";
                    //REATIVO DEMANDA
                    vFILTER = vFILTER + "LEIT_KVAR_P             = ?LEIT_KVAR_P   , ";
                    vFILTER = vFILTER + "LEIT_KVAR_FP            = ?LEIT_KVAR_FP   , ";
                    //TRIBUTOS
                    //ICMS
                    vFILTER = vFILTER + "BASE_ICMS               = ?BASE_ICMS   , ";
                    vFILTER = vFILTER + "ALIQ_ICMS               = ?ALIQ_ICMS   , ";
                    vFILTER = vFILTER + "VLR_ICMS                = ?VLR_ICMS   , ";
                    vFILTER = vFILTER + "BASE_ICMS2              = ?BASE_ICMS2   , ";
                    vFILTER = vFILTER + "ALIQ_ICMS2              = ?ALIQ_ICMS2   , ";
                    vFILTER = vFILTER + "VLR_ICMS2               = ?VLR_ICMS2   , ";
                    //PIS
                    vFILTER = vFILTER + "BASEPIS                 = ?BASEPIS   , ";
                    vFILTER = vFILTER + "ALIQPIS                 = ?ALIQPIS   , ";
                    vFILTER = vFILTER + "VLRPIS                  = ?VLRPIS   , ";
                    //COFINS
                    vFILTER = vFILTER + "BASECOFINS              = ?BASECOFINS   , ";
                    vFILTER = vFILTER + "ALIQCOFINS              = ?ALIQCOFINS   , ";
                    vFILTER = vFILTER + "VLRCOFINS               = ?VLRCOFINS   , ";
                    //********************************************
                    //TRIBUTAÇÃO DA COMERCIALIZAÇÃO DOS LIVRES
                    // ICMS
                    vFILTER = vFILTER + "BASE_ICMS_ST            = ?BASE_ICMS_ST   , ";
                    vFILTER = vFILTER + "ALIQ_ICMS_ST            = ?ALIQ_ICMS_ST   , ";
                    vFILTER = vFILTER + "VLR_ICMS_ST             = ?VLR_ICMS_ST   , ";
                    //PIS
                    vFILTER = vFILTER + "BASEPIS_ST              = ?BASEPIS_ST   , ";
                    vFILTER = vFILTER + "ALIQPIS_ST              = ?ALIQPIS_ST   , ";
                    vFILTER = vFILTER + "VLRPIS_ST               = ?VLRPIS_ST   , ";
                    //COFINS
                    vFILTER = vFILTER + "BASECOFINS_ST           = ?BASECOFINS_ST   , ";
                    vFILTER = vFILTER + "ALIQCOFINS_ST           = ?ALIQCOFINS_ST   , ";
                    vFILTER = vFILTER + "VLRCOFINS_ST            = ?VLRCOFINS_ST   , ";
                    //VALOR DA COMPRA (R$)
                    vFILTER = vFILTER + "VLRENERGIA_ST           = ?VLRENERGIA_ST   , ";
                    vFILTER = vFILTER + "VLRPCMEDIO_ST           = ?VLRPCMEDIO_ST   , ";
                    vFILTER = vFILTER + "VLRCONSUMO_ST           = ?VLRCONSUMO_ST   , ";
                    vFILTER = vFILTER + "REFERENCIA_ST           = ?REFERENCIA_ST   , ";
                    //********************************************
                    //INDICADOR DE CONTINUIDADE
                    vFILTER = vFILTER + "DEC_META                = ?DEC_META   , ";
                    vFILTER = vFILTER + "FEC_META                = ?FEC_META   , ";
                    vFILTER = vFILTER + "DIC_META                = ?DIC_META   , ";
                    vFILTER = vFILTER + "FIC_META                = ?FIC_META   , ";
                    vFILTER = vFILTER + "DMIC                    = ?DMIC   , ";
                    vFILTER = vFILTER + "DEC_REA                 = ?DEC_REA   , ";
                    vFILTER = vFILTER + "FEC_REA                 = ?FEC_REA   , ";
                    vFILTER = vFILTER + "DIC_REA                 = ?DIC_REA   , ";
                    vFILTER = vFILTER + "FIC_REA                 = ?FIC_REA   , ";
                    vFILTER = vFILTER + "DMIC_REA                = ?DMIC_REA   , ";
                    vFILTER = vFILTER + "REFINDICADOR            = ?REFINDICADOR   , ";
                    //RENTENÇÃO TRIBUTÁRIA
                    //CONSUMO
                    vFILTER = vFILTER + "RET_PIS                 = ?RET_PIS   , ";
                    vFILTER = vFILTER + "RET_COFINS              = ?RET_COFINS   , ";
                    vFILTER = vFILTER + "RET_CSLL                = ?RET_CSLL   , ";
                    vFILTER = vFILTER + "RET_IRPJC               = ?RET_IRPJC   , ";
                    //DEMANDA
                    vFILTER = vFILTER + "RET_IRPJD               = ?RET_IRPJD   , ";
                    vFILTER = vFILTER + "RET_CSLLD               = ?RET_CSLLD   , ";
                    vFILTER = vFILTER + "RET_COFINSD             = ?RET_COFINSD   , ";
                    vFILTER = vFILTER + "RET_PISD                = ?RET_PISD   , ";
                    //COMPOSIÇÃO DA FATURA
                    vFILTER = vFILTER + "COMP_ENERGIA            = ?COMP_ENERGIA   , ";
                    vFILTER = vFILTER + "COMP_TRANSMISSAO        = ?COMP_TRANSMISSAO   , ";
                    vFILTER = vFILTER + "COMP_DISTRIBUICAO       = ?COMP_DISTRIBUICAO   , ";
                    vFILTER = vFILTER + "COMP_ENCARGOS_SETORIAIS = ?COMP_ENCARGOS_SETORIAIS   , ";
                    //TARIFAS
                    vFILTER = vFILTER + "TA_DEMP                 = ?TA_DEMP   , ";
                    vFILTER = vFILTER + "TA_DEMFP                = ?TA_DEMFP   , ";
                    vFILTER = vFILTER + "TA_ULTRAP               = ?TA_ULTRAP   , ";
                    vFILTER = vFILTER + "TA_ULTRAFP              = ?TA_ULTRAFP   , ";
                    vFILTER = vFILTER + "TA_CONSP                = ?TA_CONSP   , ";
                    vFILTER = vFILTER + "TA_CONSFP               = ?TA_CONSFP   , ";
                    //MENSAGEM DA FATURA
                    vFILTER = vFILTER + "MENSAGEM_BANDEIRA       = ?MENSAGEM_BANDEIRA   , ";
                    vFILTER = vFILTER + "BANDEIRA                = ?BANDEIRA   , ";
                    vFILTER = vFILTER + "FRENTEVERSO             = ?FRENTEVERSO   , ";
                    vFILTER = vFILTER + "LIVRE_VERDE             = ?LIVRE_VERDE   , ";
                    vFILTER = vFILTER + "PARC_CATIVO             = ?PARC_CATIVO   , ";
                    vFILTER = vFILTER + "MENSAGEM                = ?MENSAGEM   , ";
                    vFILTER = vFILTER + "ITENSIMP                = ?ITENSIMP   , ";
                    vFILTER = vFILTER + "SEQUENCIA               = ?SEQUENCIA  , ";
                    vFILTER = vFILTER + "MATRICULA               = ?MATRICULA ";

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

                    cmd = new MySqlCommand(this.QueryUpdate);


                    cmd.Parameters.AddWithValue("?SEGVIA", objTempFaturaA.SEGVIA);
                    cmd.Parameters.AddWithValue("?NOMEMAQUINA", objTempFaturaA.NOMEMAQUINA.ToString().ToUpper());
                    //DADOS DA FATURA
                    cmd.Parameters.AddWithValue("?NUMNF", objTempFaturaA.NUMNF);
                    cmd.Parameters.AddWithValue("?CFOP", objTempFaturaA.CFOP);
                    cmd.Parameters.AddWithValue("?ZONA", objTempFaturaA.ZONA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LIVRO", objTempFaturaA.LIVRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTA", objTempFaturaA.CONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?ROTA", objTempFaturaA.ROTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONS_ID", objTempFaturaA.CONS_ID.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?UNID_ID", objTempFaturaA.UNID_ID.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?VALORTOT", objTempFaturaA.VALORTOT);
                    cmd.Parameters.AddWithValue("?VALORLIQ", objTempFaturaA.VALORLIQ);
                    cmd.Parameters.AddWithValue("?CODCLAS", objTempFaturaA.CODCLAS.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DATAVENC", objTempFaturaA.DATAVENC);
                    cmd.Parameters.AddWithValue("?BANCO_FATUR", objTempFaturaA.BANCO_FATUR.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MESANO", objTempFaturaA.MESANO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MESANOREF", objTempFaturaA.MESANOREF);

                    cmd.Parameters.AddWithValue("?DATAAPR", objTempFaturaA.DATAAPR);
                    cmd.Parameters.AddWithValue("?DATAEMISSAO", objTempFaturaA.DATAEMISSAO);
                    cmd.Parameters.AddWithValue("?DATAPROXLEIT", objTempFaturaA.DATAPROXLEIT);
                    cmd.Parameters.AddWithValue("?DATALEIT", objTempFaturaA.DATALEIT);
                    cmd.Parameters.AddWithValue("?DATALEITANT", objTempFaturaA.DATALEITANT);
                    cmd.Parameters.AddWithValue("?FASE", objTempFaturaA.FASE.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?TA", objTempFaturaA.TA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?TENSAO", objTempFaturaA.TENSAO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CODHASH", objTempFaturaA.CODHASH.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CODBARRA", objTempFaturaA.CODBARRA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DVCODBARRA", objTempFaturaA.DVCODBARRA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LINHADIGITAVEL", objTempFaturaA.LINHADIGITAVEL.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DESCLASSE", objTempFaturaA.DESCLASSE.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?FLGST", objTempFaturaA.FLGST.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CANCELADA_MESANO", objTempFaturaA.CANCELADA_MESANO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CANCELADA_NUMNF", objTempFaturaA.CANCELADA_NUMNF);
                    //DADOS DA UNIDADE
                    cmd.Parameters.AddWithValue("?CGC", objTempFaturaA.CGC.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?INSC", objTempFaturaA.INSC.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?RG", objTempFaturaA.RG.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?AGENC", objTempFaturaA.AGENC.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CC", objTempFaturaA.CC.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?NOMECONS", objTempFaturaA.NOMECONS.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CIDADE", objTempFaturaA.CIDADE.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DISTRITO", objTempFaturaA.DISTRITO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?BAIRRO", objTempFaturaA.BAIRRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?END", objTempFaturaA.END.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?NUMERO", objTempFaturaA.NUMERO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?COMPLEMENT", objTempFaturaA.COMPLEMENT.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CEP", objTempFaturaA.CEP.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?UF", objTempFaturaA.UF.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?QUADRA", objTempFaturaA.QUADRA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LOTE", objTempFaturaA.LOTE.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CID_ENTREGA", objTempFaturaA.CID_ENTREGA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DIS_ENTREGA", objTempFaturaA.DIS_ENTREGA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?BAI_ENTREGA", objTempFaturaA.BAI_ENTREGA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?END_ENTREGA", objTempFaturaA.END_ENTREGA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?NUM_ENTREGA", objTempFaturaA.NUM_ENTREGA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?COMPL_ENTREGA", objTempFaturaA.COMPL_ENTREGA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CEP_ENTREGA", objTempFaturaA.CEP_ENTREGA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?UF_ENTREGA", objTempFaturaA.UF_ENTREGA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?QUA_ENTREGA", objTempFaturaA.QUA_ENTREGA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LOT_ENTREGA", objTempFaturaA.LOT_ENTREGA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?GRUPO", objTempFaturaA.GRUPO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONST_DEMANDA", objTempFaturaA.CONST_DEMANDA);
                    cmd.Parameters.AddWithValue("?CONST_CONS_FP", objTempFaturaA.CONST_CONS_FP);
                    cmd.Parameters.AddWithValue("?CONST_CONS_P", objTempFaturaA.CONST_CONS_P);
                    cmd.Parameters.AddWithValue("?CONST_KVARH_P", objTempFaturaA.CONST_KVARH_P);
                    cmd.Parameters.AddWithValue("?CONST_KVARH_FP", objTempFaturaA.CONST_KVARH_FP);
                    cmd.Parameters.AddWithValue("?MEDKW", objTempFaturaA.MEDKW);
                    cmd.Parameters.AddWithValue("?MEDKVARK", objTempFaturaA.MEDKVARK);
                    cmd.Parameters.AddWithValue("?ELETR", objTempFaturaA.ELETR);
                    cmd.Parameters.AddWithValue("?DEMCONTRP", objTempFaturaA.DEMCONTRP);
                    cmd.Parameters.AddWithValue("?DEMCONTRFP", objTempFaturaA.DEMCONTRFP);
                    cmd.Parameters.AddWithValue("?DEMCONTRPANTERIOR", objTempFaturaA.DEMCONTRPANTERIOR);
                    cmd.Parameters.AddWithValue("?DEMCONTRFPANTERIOR", objTempFaturaA.DEMCONTRFPANTERIOR);
                    cmd.Parameters.AddWithValue("?PERIODO_TESTE", objTempFaturaA.PERIODO_TESTE);
                    cmd.Parameters.AddWithValue("?CONST_KVARH", objTempFaturaA.CONST_KVARH);
                    cmd.Parameters.AddWithValue("?CONST_KW", objTempFaturaA.CONST_KW);
                    cmd.Parameters.AddWithValue("?CONST_KWH", objTempFaturaA.CONST_KWH);
                    cmd.Parameters.AddWithValue("?CONST_DEMANDA_FP", objTempFaturaA.CONST_DEMANDA_FP);
                    cmd.Parameters.AddWithValue("?KW_CONT", objTempFaturaA.KW_CONT);
                    cmd.Parameters.AddWithValue("?CARGA", objTempFaturaA.CARGA);
                    cmd.Parameters.AddWithValue("?PERDA", objTempFaturaA.PERDA);
                    cmd.Parameters.AddWithValue("?REFCONS", objTempFaturaA.REFCONS);
                    //LEITURAS
                    //REATIVO CONSUMO
                    cmd.Parameters.AddWithValue("?LEIT_KVARH_ANT", objTempFaturaA.LEIT_KVARH_ANT);
                    cmd.Parameters.AddWithValue("?LEIT_KVARH_ATUAL", objTempFaturaA.LEIT_KVARH_ATUAL);
                    cmd.Parameters.AddWithValue("?LEITANT_KVARH_P", objTempFaturaA.LEITANT_KVARH_P);
                    cmd.Parameters.AddWithValue("?LEIT_KVARH_P", objTempFaturaA.LEIT_KVARH_P);
                    cmd.Parameters.AddWithValue("?LEITANT_KVARH_FP", objTempFaturaA.LEITANT_KVARH_FP);
                    cmd.Parameters.AddWithValue("?LEIT_KVARH_FP", objTempFaturaA.LEIT_KVARH_FP);
                    //DEMANDA
                    cmd.Parameters.AddWithValue("?LEIT_KW_ANT", objTempFaturaA.LEIT_KW_ANT);
                    cmd.Parameters.AddWithValue("?LEIT_KW_ATUAL", objTempFaturaA.LEIT_KW_ATUAL);
                    cmd.Parameters.AddWithValue("?LEITANT_KW_P", objTempFaturaA.LEITANT_KW_P);
                    cmd.Parameters.AddWithValue("?LEIT_KW_P", objTempFaturaA.LEIT_KW_P);
                    cmd.Parameters.AddWithValue("?LEITANT_KW_FP", objTempFaturaA.LEITANT_KW_FP);
                    cmd.Parameters.AddWithValue("?LEIT_KW_FP", objTempFaturaA.LEIT_KW_FP);
                    //CONSUMO
                    cmd.Parameters.AddWithValue("?LEIT_KWH_ANT", objTempFaturaA.LEIT_KWH_ANT);
                    cmd.Parameters.AddWithValue("?LEIT_KWH_ATUAL", objTempFaturaA.LEIT_KWH_ATUAL);
                    cmd.Parameters.AddWithValue("?LEITANT_KWH_P", objTempFaturaA.LEITANT_KWH_P);
                    cmd.Parameters.AddWithValue("?LEIT_KWH_P", objTempFaturaA.LEIT_KWH_P);
                    cmd.Parameters.AddWithValue("?LEITANT_KWH_FP", objTempFaturaA.LEITANT_KWH_FP);
                    cmd.Parameters.AddWithValue("?LEIT_KWH_FP", objTempFaturaA.LEIT_KWH_FP);
                    //MICRO GERAÇÃO
                    cmd.Parameters.AddWithValue("?LEITANT_REVERSO_P", objTempFaturaA.LEITANT_REVERSO_P);
                    cmd.Parameters.AddWithValue("?LEIT_REVERSO_P", objTempFaturaA.LEIT_REVERSO_P);
                    cmd.Parameters.AddWithValue("?LEITANT_REVERSO_FP", objTempFaturaA.LEITANT_REVERSO_FP);
                    cmd.Parameters.AddWithValue("?LEIT_REVERSO_FP", objTempFaturaA.LEIT_REVERSO_FP);
                    cmd.Parameters.AddWithValue("?MICRO_GERACAO", objTempFaturaA.MICRO_GERACAO);
                    //CONSUMO RESERVADO
                    cmd.Parameters.AddWithValue("?LEITANT_KWH_RES", objTempFaturaA.LEITANT_KWH_RES);
                    cmd.Parameters.AddWithValue("?LEIT_KWH_RES", objTempFaturaA.LEIT_KWH_RES);
                    //QUANTIDADES
                    //CONSUMO
                    cmd.Parameters.AddWithValue("?CONSMEDIDOP", objTempFaturaA.CONSMEDIDOP);
                    cmd.Parameters.AddWithValue("?CONSMEDIDOFP", objTempFaturaA.CONSMEDIDOFP);
                    cmd.Parameters.AddWithValue("?CONSFATURADOP", objTempFaturaA.CONSFATURADOP);
                    cmd.Parameters.AddWithValue("?CONSFATURADOFP", objTempFaturaA.CONSFATURADOFP);
                    cmd.Parameters.AddWithValue("?CONSCONTRP", objTempFaturaA.CONSCONTRP);
                    cmd.Parameters.AddWithValue("?CONSCONTRFP", objTempFaturaA.CONSCONTRFP);
                    cmd.Parameters.AddWithValue("?KWH_MED", objTempFaturaA.KWH_MED);
                    cmd.Parameters.AddWithValue("?KWH_FAT", objTempFaturaA.KWH_FAT);
                    cmd.Parameters.AddWithValue("?CONSRESERVADO", objTempFaturaA.CONSRESERVADO);
                    //MICRO GERAÇÃO
                    cmd.Parameters.AddWithValue("?KWH_REVERSO_P", objTempFaturaA.KWH_REVERSO_P);
                    cmd.Parameters.AddWithValue("?KWH_REVERSO_FP", objTempFaturaA.KWH_REVERSO_FP);
                    cmd.Parameters.AddWithValue("?KWH_REVERSO_RES_P", objTempFaturaA.KWH_REVERSO_RES_P);
                    cmd.Parameters.AddWithValue("?KWH_REVERSO_RES_FP", objTempFaturaA.KWH_REVERSO_RES_FP);
                    cmd.Parameters.AddWithValue("?KWH_REVERSO_REC_P", objTempFaturaA.KWH_REVERSO_REC_P);
                    cmd.Parameters.AddWithValue("?KWH_REVERSO_REC_FP", objTempFaturaA.KWH_REVERSO_REC_FP);
                    cmd.Parameters.AddWithValue("?KWH_ENVIADO", objTempFaturaA.KWH_ENVIADO);
                    cmd.Parameters.AddWithValue("?KWH_SALDO", objTempFaturaA.KWH_SALDO);
                    //DEMANDA
                    cmd.Parameters.AddWithValue("?DEMMEDIDAP", objTempFaturaA.DEMMEDIDAP);
                    cmd.Parameters.AddWithValue("?DEMMEDIDAFP", objTempFaturaA.DEMMEDIDAFP);
                    cmd.Parameters.AddWithValue("?DEMFATURP", objTempFaturaA.DEMFATURP);
                    cmd.Parameters.AddWithValue("?DEMFATURFP", objTempFaturaA.DEMFATURFP);
                    cmd.Parameters.AddWithValue("?ULTRAP", objTempFaturaA.ULTRAP);
                    cmd.Parameters.AddWithValue("?ULTRAFP", objTempFaturaA.ULTRAFP);
                    cmd.Parameters.AddWithValue("?KW_MED", objTempFaturaA.KW_MED);
                    cmd.Parameters.AddWithValue("?KW_FAT", objTempFaturaA.KW_FAT);
                    cmd.Parameters.AddWithValue("?KW_ULTRA", objTempFaturaA.KW_ULTRA);
                    //FATOR DE POTENCIA
                    cmd.Parameters.AddWithValue("?KVARH_FPOT", objTempFaturaA.KVARH_FPOT);
                    //REATIVO CONSUMO
                    cmd.Parameters.AddWithValue("?FER_P", objTempFaturaA.FER_P);
                    cmd.Parameters.AddWithValue("?FER_FP", objTempFaturaA.FER_FP);
                    cmd.Parameters.AddWithValue("?KVARH_MED", objTempFaturaA.KVARH_MED);
                    //REATIVO DEMANDA
                    cmd.Parameters.AddWithValue("?LEIT_KVAR_P", objTempFaturaA.LEIT_KVAR_P);
                    cmd.Parameters.AddWithValue("?LEIT_KVAR_FP", objTempFaturaA.LEIT_KVAR_FP);
                    //TRIBUTOS
                    //ICMS
                    cmd.Parameters.AddWithValue("?BASE_ICMS", objTempFaturaA.BASE_ICMS);
                    cmd.Parameters.AddWithValue("?ALIQ_ICMS", objTempFaturaA.ALIQ_ICMS);
                    cmd.Parameters.AddWithValue("?VLR_ICMS", objTempFaturaA.VLR_ICMS);
                    cmd.Parameters.AddWithValue("?BASE_ICMS2", objTempFaturaA.BASE_ICMS2);
                    cmd.Parameters.AddWithValue("?ALIQ_ICMS2", objTempFaturaA.ALIQ_ICMS2);
                    cmd.Parameters.AddWithValue("?VLR_ICMS2", objTempFaturaA.VLR_ICMS2);
                    //PIS
                    cmd.Parameters.AddWithValue("?BASEPIS", objTempFaturaA.BASEPIS);
                    cmd.Parameters.AddWithValue("?ALIQPIS", objTempFaturaA.ALIQPIS);
                    cmd.Parameters.AddWithValue("?VLRPIS", objTempFaturaA.VLRPIS);
                    //COFINS
                    cmd.Parameters.AddWithValue("?BASECOFINS", objTempFaturaA.BASECOFINS);
                    cmd.Parameters.AddWithValue("?ALIQCOFINS", objTempFaturaA.ALIQCOFINS);
                    cmd.Parameters.AddWithValue("?VLRCOFINS", objTempFaturaA.VLRCOFINS);
                    //********************************************
                    //TRIBUTAÇÃO DA COMERCIALIZAÇÃO DOS LIVRES
                    // ICMS
                    cmd.Parameters.AddWithValue("?BASE_ICMS_ST", objTempFaturaA.BASE_ICMS_ST);
                    cmd.Parameters.AddWithValue("?ALIQ_ICMS_ST", objTempFaturaA.ALIQ_ICMS_ST);
                    cmd.Parameters.AddWithValue("?VLR_ICMS_ST", objTempFaturaA.VLR_ICMS_ST);
                    //PIS
                    cmd.Parameters.AddWithValue("?BASEPIS_ST", objTempFaturaA.BASEPIS_ST);
                    cmd.Parameters.AddWithValue("?ALIQPIS_ST", objTempFaturaA.ALIQPIS_ST);
                    cmd.Parameters.AddWithValue("?VLRPIS_ST", objTempFaturaA.VLRPIS_ST);
                    //COFINS
                    cmd.Parameters.AddWithValue("?BASECOFINS_ST", objTempFaturaA.BASECOFINS_ST);
                    cmd.Parameters.AddWithValue("?ALIQCOFINS_ST", objTempFaturaA.ALIQCOFINS_ST);
                    cmd.Parameters.AddWithValue("?VLRCOFINS_ST", objTempFaturaA.VLRCOFINS_ST);
                    //VALOR DA COMPRA (R$)
                    cmd.Parameters.AddWithValue("?VLRENERGIA_ST", objTempFaturaA.VLRENERGIA_ST);
                    cmd.Parameters.AddWithValue("?VLRPCMEDIO_ST", objTempFaturaA.VLRPCMEDIO_ST);
                    cmd.Parameters.AddWithValue("?VLRCONSUMO_ST", objTempFaturaA.VLRCONSUMO_ST);
                    cmd.Parameters.AddWithValue("?REFERENCIA_ST", objTempFaturaA.REFERENCIA_ST.ToString().ToUpper());
                    //********************************************
                    //INDICADOR DE CONTINUIDADE
                    cmd.Parameters.AddWithValue("?DEC_META", objTempFaturaA.DEC_META);
                    cmd.Parameters.AddWithValue("?FEC_META", objTempFaturaA.FEC_META);
                    cmd.Parameters.AddWithValue("?DIC_META", objTempFaturaA.DIC_META);
                    cmd.Parameters.AddWithValue("?FIC_META", objTempFaturaA.FIC_META);
                    cmd.Parameters.AddWithValue("?DMIC", objTempFaturaA.DMIC);
                    cmd.Parameters.AddWithValue("?DEC_REA", objTempFaturaA.DEC_REA);
                    cmd.Parameters.AddWithValue("?FEC_REA", objTempFaturaA.FEC_REA);
                    cmd.Parameters.AddWithValue("?DIC_REA", objTempFaturaA.DIC_REA);
                    cmd.Parameters.AddWithValue("?FIC_REA", objTempFaturaA.FIC_REA);
                    cmd.Parameters.AddWithValue("?DMIC_REA", objTempFaturaA.DMIC_REA);
                    cmd.Parameters.AddWithValue("?REFINDICADOR", objTempFaturaA.REFINDICADOR.ToString().ToUpper());
                    //RENTENÇÃO TRIBUTÁRIA
                    //CONSUMO
                    cmd.Parameters.AddWithValue("?RET_PIS", objTempFaturaA.RET_PIS);
                    cmd.Parameters.AddWithValue("?RET_COFINS", objTempFaturaA.RET_COFINS);
                    cmd.Parameters.AddWithValue("?RET_CSLL", objTempFaturaA.RET_CSLL);
                    cmd.Parameters.AddWithValue("?RET_IRPJC", objTempFaturaA.RET_IRPJC);
                    //DEMANDA
                    cmd.Parameters.AddWithValue("?RET_IRPJD", objTempFaturaA.RET_IRPJD);
                    cmd.Parameters.AddWithValue("?RET_CSLLD", objTempFaturaA.RET_CSLLD);
                    cmd.Parameters.AddWithValue("?RET_COFINSD", objTempFaturaA.RET_COFINSD);
                    cmd.Parameters.AddWithValue("?RET_PISD", objTempFaturaA.RET_PISD);
                    //COMPOSIÇÃO DA FATURA
                    cmd.Parameters.AddWithValue("?COMP_ENERGIA", objTempFaturaA.COMP_ENERGIA);
                    cmd.Parameters.AddWithValue("?COMP_TRANSMISSAO", objTempFaturaA.COMP_TRANSMISSAO);
                    cmd.Parameters.AddWithValue("?COMP_DISTRIBUICAO", objTempFaturaA.COMP_DISTRIBUICAO);
                    cmd.Parameters.AddWithValue("?COMP_ENCARGOS_SETORIAIS", objTempFaturaA.COMP_ENCARGOS_SETORIAIS);
                    //TARIFAS
                    cmd.Parameters.AddWithValue("?TA_DEMP", objTempFaturaA.TA_DEMP.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?TA_DEMFP", objTempFaturaA.TA_DEMFP.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?TA_ULTRAP", objTempFaturaA.TA_ULTRAP.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?TA_ULTRAFP", objTempFaturaA.TA_ULTRAFP.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?TA_CONSP", objTempFaturaA.TA_CONSP.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?TA_CONSFP", objTempFaturaA.TA_CONSFP.ToString().ToUpper());
                    //MENSAGEM DA FATURA
                    cmd.Parameters.AddWithValue("?MENSAGEM_BANDEIRA", objTempFaturaA.MENSAGEM_BANDEIRA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?BANDEIRA", objTempFaturaA.BANDEIRA);
                    cmd.Parameters.AddWithValue("?FRENTEVERSO", objTempFaturaA.FRENTEVERSO);
                    cmd.Parameters.AddWithValue("?LIVRE_VERDE", objTempFaturaA.LIVRE_VERDE);
                    cmd.Parameters.AddWithValue("?PARC_CATIVO", objTempFaturaA.PARC_CATIVO);
                    cmd.Parameters.AddWithValue("?MENSAGEM", objTempFaturaA.MENSAGEM);
                    cmd.Parameters.AddWithValue("?ITENSIMP", objTempFaturaA.ITENSIMP.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?SEQUENCIA", objTempFaturaA.SEQUENCIA);
                    cmd.Parameters.AddWithValue("?MATRICULA", objTempFaturaA.MATRICULA);
                    cmd.Parameters.AddWithValue("?ANOMES_FAT", objTempFaturaA.ANOMES_FAT);

                    objGerenciadorTransacao.Execute(cmd);
                }

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

        public void Delete(entidadeTempFaturaA objTempFaturaA)
        {

            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 NOMEMAQUINA = ?NOMEMAQUINA ";


                    cmd = new MySqlCommand(this.QueryDelete);


                    cmd.Parameters.AddWithValue("?NOMEMAQUINA", objTempFaturaA.NOMEMAQUINA.ToString().ToUpper());


                    objGerenciadorTransacao.Execute(cmd);
                }

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

        public DataTable Select(entidadeTempFaturaA objTempFaturaA)
        {
            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 + "CFOP, ";
                    vFILTER = vFILTER + "ZONA, ";
                    vFILTER = vFILTER + "LIVRO, ";
                    vFILTER = vFILTER + "CONTA, ";
                    vFILTER = vFILTER + "UNID_ID, ";
                    vFILTER = vFILTER + "CONS_ID, ";
                    vFILTER = vFILTER + "ROTA, ";
                    vFILTER = vFILTER + "AGENC, ";
                    vFILTER = vFILTER + "CC, ";
                    vFILTER = vFILTER + "VALORTOT, ";
                    vFILTER = vFILTER + "CODCLAS, ";
                    vFILTER = vFILTER + "DESCLASSE, ";
                    vFILTER = vFILTER + "DATAVENC, ";
                    vFILTER = vFILTER + "BANCO_FATUR, ";
                    vFILTER = vFILTER + "MESANO, ";
                    vFILTER = vFILTER + "NOMECONS, ";
                    vFILTER = vFILTER + "REFCONS, ";
                    vFILTER = vFILTER + "CGC, ";
                    vFILTER = vFILTER + "INSC, ";
                    vFILTER = vFILTER + "RG, ";
                    vFILTER = vFILTER + "CIDADE, ";
                    vFILTER = vFILTER + "DISTRITO, ";
                    vFILTER = vFILTER + "BAIRRO, ";
                    vFILTER = vFILTER + "END, ";
                    vFILTER = vFILTER + "NUMERO, ";
                    vFILTER = vFILTER + "COMPLEMENT, ";
                    vFILTER = vFILTER + "QUADRA, ";
                    vFILTER = vFILTER + "LOTE, ";
                    vFILTER = vFILTER + "CEP, ";
                    vFILTER = vFILTER + "UF, ";
                    vFILTER = vFILTER + "CID_ENTREGA, ";
                    vFILTER = vFILTER + "DIS_ENTREGA, ";
                    vFILTER = vFILTER + "BAI_ENTREGA, ";
                    vFILTER = vFILTER + "END_ENTREGA, ";
                    vFILTER = vFILTER + "NUM_ENTREGA, ";
                    vFILTER = vFILTER + "COMPL_ENTREGA, ";
                    vFILTER = vFILTER + "QUA_ENTREGA, ";
                    vFILTER = vFILTER + "LOT_ENTREGA, ";
                    vFILTER = vFILTER + "CEP_ENTREGA, ";
                    vFILTER = vFILTER + "UF_ENTREGA, ";
                    vFILTER = vFILTER + "DATAAPR, ";
                    vFILTER = vFILTER + "DATAEMISSAO, ";
                    vFILTER = vFILTER + "DATAPROXLEIT, ";
                    vFILTER = vFILTER + "DATALEIT, ";
                    vFILTER = vFILTER + "DATALEITANT, ";
                    vFILTER = vFILTER + "TA_CONSP, ";
                    vFILTER = vFILTER + "TA_CONSFP, ";
                    vFILTER = vFILTER + "TA_DEMP, ";
                    vFILTER = vFILTER + "TA_DEMFP, ";
                    vFILTER = vFILTER + "TA_ULTRAP, ";
                    vFILTER = vFILTER + "TA_ULTRAFP, ";
                    vFILTER = vFILTER + "FASE, ";
                    vFILTER = vFILTER + "TA, ";
                    vFILTER = vFILTER + "TENSAO, ";
                    vFILTER = vFILTER + "GRUPO, ";
                    vFILTER = vFILTER + "CODHASH, ";
                    vFILTER = vFILTER + "CONST_DEMANDA, ";
                    vFILTER = vFILTER + "CONST_DEMANDA_FP, ";
                    vFILTER = vFILTER + "CONST_CONS_FP, ";
                    vFILTER = vFILTER + "CONST_CONS_P, ";
                    vFILTER = vFILTER + "CONST_KVARH_P, ";
                    vFILTER = vFILTER + "CONST_KVARH_FP, ";
                    vFILTER = vFILTER + "MEDKW, ";
                    vFILTER = vFILTER + "MEDKVARK, ";
                    vFILTER = vFILTER + "ELETR, ";
                    vFILTER = vFILTER + "PERDA, ";
                    vFILTER = vFILTER + "FER_P, ";
                    vFILTER = vFILTER + "FER_FP, ";
                    vFILTER = vFILTER + "CONSMEDIDOP, ";
                    vFILTER = vFILTER + "CONSMEDIDOFP, ";
                    vFILTER = vFILTER + "CONSFATURADOP, ";
                    vFILTER = vFILTER + "CONSFATURADOFP, ";
                    vFILTER = vFILTER + "CONSCONTRP, ";
                    vFILTER = vFILTER + "CONSCONTRFP, ";
                    vFILTER = vFILTER + "DEMMEDIDAP, ";
                    vFILTER = vFILTER + "DEMMEDIDAFP, ";
                    vFILTER = vFILTER + "DEMCONTRP, ";
                    vFILTER = vFILTER + "DEMCONTRFP, ";
                    vFILTER = vFILTER + "DEMCONTRPANTERIOR, ";
                    vFILTER = vFILTER + "DEMCONTRFPANTERIOR, ";
                    vFILTER = vFILTER + "PERIODO_TESTE, ";
                    vFILTER = vFILTER + "DEMFATURP, ";
                    vFILTER = vFILTER + "DEMFATURFP, ";
                    vFILTER = vFILTER + "BASE_ICMS, ";
                    vFILTER = vFILTER + "ALIQ_ICMS, ";
                    vFILTER = vFILTER + "VLR_ICMS, ";
                    vFILTER = vFILTER + "CODBARRA, ";
                    vFILTER = vFILTER + "DVCODBARRA, ";
                    vFILTER = vFILTER + "LINHADIGITAVEL, ";
                    vFILTER = vFILTER + "DEC_META, ";
                    vFILTER = vFILTER + "FEC_META, ";
                    vFILTER = vFILTER + "DIC_META, ";
                    vFILTER = vFILTER + "FIC_META, ";
                    vFILTER = vFILTER + "DEC_REA, ";
                    vFILTER = vFILTER + "FEC_REA, ";
                    vFILTER = vFILTER + "DIC_REA, ";
                    vFILTER = vFILTER + "FIC_REA, ";
                    vFILTER = vFILTER + "DMIC, ";
                    vFILTER = vFILTER + "DMIC_REA, ";
                    vFILTER = vFILTER + "DMICM, ";
                    vFILTER = vFILTER + "REFINDICADOR, ";
                    vFILTER = vFILTER + "CONST_KVARH, ";
                    vFILTER = vFILTER + "LEIT_KVARH_ATUAL, ";
                    vFILTER = vFILTER + "LEIT_KVARH_ANT, ";
                    vFILTER = vFILTER + "CONST_KW, ";
                    vFILTER = vFILTER + "LEIT_KW_ATUAL, ";
                    vFILTER = vFILTER + "LEIT_KW_ANT, ";
                    vFILTER = vFILTER + "CONST_KWH, ";
                    vFILTER = vFILTER + "LEIT_KWH_ATUAL, ";
                    vFILTER = vFILTER + "LEIT_KWH_ANT, ";
                    vFILTER = vFILTER + "KWH_MED, ";
                    vFILTER = vFILTER + "KWH_FAT, ";
                    vFILTER = vFILTER + "KW_MED, ";
                    vFILTER = vFILTER + "KW_FAT, ";
                    vFILTER = vFILTER + "KW_ULTRA, ";
                    vFILTER = vFILTER + "KW_CONT, ";
                    vFILTER = vFILTER + "KVARH_MED, ";
                    vFILTER = vFILTER + "KVARH_FAT, ";
                    vFILTER = vFILTER + "KVARH_FPOT, ";
                    vFILTER = vFILTER + "CARGA, ";
                    vFILTER = vFILTER + "MENSAGEM, ";
                    vFILTER = vFILTER + "ALIQPIS, ";
                    vFILTER = vFILTER + "BASEPIS, ";
                    vFILTER = vFILTER + "VLRPIS, ";
                    vFILTER = vFILTER + "ALIQCOFINS, ";
                    vFILTER = vFILTER + "BASECOFINS, ";
                    vFILTER = vFILTER + "VLRCOFINS, ";
                    vFILTER = vFILTER + "FAT_PENDENTES, ";
                    vFILTER = vFILTER + "CONJUNTO, ";
                    vFILTER = vFILTER + "MESREF, ";
                    vFILTER = vFILTER + "LEIT_KWH_P, ";
                    vFILTER = vFILTER + "LEIT_KWH_FP, ";
                    vFILTER = vFILTER + "LEIT_KW_P, ";
                    vFILTER = vFILTER + "LEIT_KW_FP, ";
                    vFILTER = vFILTER + "LEIT_KVARH_P, ";
                    vFILTER = vFILTER + "LEIT_KVARH_FP, ";
                    vFILTER = vFILTER + "LEIT_KVAR_P, ";
                    vFILTER = vFILTER + "LEIT_KVAR_FP, ";
                    vFILTER = vFILTER + "LEITANT_KWH_P, ";
                    vFILTER = vFILTER + "LEITANT_KWH_FP, ";
                    vFILTER = vFILTER + "LEITANT_KW_P, ";
                    vFILTER = vFILTER + "LEITANT_KW_FP, ";
                    vFILTER = vFILTER + "LEITANT_KVARH_P, ";
                    vFILTER = vFILTER + "LEITANT_KVARH_FP, ";
                    vFILTER = vFILTER + "LEITANT_KWH_RES, ";
                    vFILTER = vFILTER + "LEIT_KWH_RES, ";
                    vFILTER = vFILTER + "CONSRESERVADO, ";
                    vFILTER = vFILTER + "ULTRAP, ";
                    vFILTER = vFILTER + "ULTRAFP, ";
                    vFILTER = vFILTER + "RET_PIS, ";
                    vFILTER = vFILTER + "RET_CSLL, ";
                    vFILTER = vFILTER + "RET_COFINS, ";
                    vFILTER = vFILTER + "RET_IRPJC, ";
                    vFILTER = vFILTER + "RET_IRPJD, ";
                    vFILTER = vFILTER + "RET_CSLLD, ";
                    vFILTER = vFILTER + "RET_COFINSD, ";
                    vFILTER = vFILTER + "RET_PISD, ";
                    vFILTER = vFILTER + "VALORLIQ, ";
                    vFILTER = vFILTER + "SEGVIA, ";
                    vFILTER = vFILTER + "NOMEMAQUINA, ";
                    vFILTER = vFILTER + "COMP_ENERGIA, ";
                    vFILTER = vFILTER + "COMP_TRANSMISSAO, ";
                    vFILTER = vFILTER + "COMP_DISTRIBUICAO, ";
                    vFILTER = vFILTER + "COMP_ENCARGOS_SETORIAIS, ";
                    vFILTER = vFILTER + "COMP_PERDAS, ";
                    vFILTER = vFILTER + "COMP_TRIBUTOS, ";
                    vFILTER = vFILTER + "COMP_OUTROS, ";
                    vFILTER = vFILTER + "BASE_ICMS2, ";
                    vFILTER = vFILTER + "ALIQ_ICMS2, ";
                    vFILTER = vFILTER + "VLR_ICMS2, ";
                    vFILTER = vFILTER + "BANDEIRA, ";
                    vFILTER = vFILTER + "BASE_ICMS_ST, ";
                    vFILTER = vFILTER + "ALIQ_ICMS_ST, ";
                    vFILTER = vFILTER + "VLR_ICMS_ST, ";
                    vFILTER = vFILTER + "ALIQPIS_ST, ";
                    vFILTER = vFILTER + "BASEPIS_ST, ";
                    vFILTER = vFILTER + "VLRPIS_ST, ";
                    vFILTER = vFILTER + "ALIQCOFINS_ST, ";
                    vFILTER = vFILTER + "BASECOFINS_ST, ";
                    vFILTER = vFILTER + "VLRCOFINS_ST, ";
                    vFILTER = vFILTER + "VLRENERGIA_ST, ";
                    vFILTER = vFILTER + "VLRPCMEDIO_ST, ";
                    vFILTER = vFILTER + "VLRCONSUMO_ST, ";
                    vFILTER = vFILTER + "REFERENCIA_ST, ";
                    vFILTER = vFILTER + "MENSAGEM_BANDEIRA, ";
                    vFILTER = vFILTER + "FRENTEVERSO, ";
                    vFILTER = vFILTER + "LIVRE_VERDE, ";
                    vFILTER = vFILTER + "MESANOREF, ";
                    vFILTER = vFILTER + "PARC_CATIVO, ";
                    vFILTER = vFILTER + "LEIT_REVERSO_P, ";
                    vFILTER = vFILTER + "LEIT_REVERSO_FP, ";
                    vFILTER = vFILTER + "LEITANT_REVERSO_P, ";
                    vFILTER = vFILTER + "LEITANT_REVERSO_FP, ";
                    vFILTER = vFILTER + "KWH_REVERSO_P, ";
                    vFILTER = vFILTER + "KWH_REVERSO_FP, ";
                    vFILTER = vFILTER + "MICRO_GERACAO, ";
                    vFILTER = vFILTER + "IRRIGACAO_AQUICULTURA, ";
                    vFILTER = vFILTER + "KWH_REVERSO_RES_P, ";
                    vFILTER = vFILTER + "KWH_REVERSO_RES_FP, ";
                    vFILTER = vFILTER + "KWH_REVERSO_REC_P, ";
                    vFILTER = vFILTER + "KWH_REVERSO_REC_FP, ";
                    vFILTER = vFILTER + "KWH_ENVIADO, ";
                    vFILTER = vFILTER + "KWH_SALDO, ";
                    vFILTER = vFILTER + "ITENSIMP, ";
                    vFILTER = vFILTER + "ANOMES_FAT, ";
                    vFILTER = vFILTER + "FLGST , ";
                    vFILTER = vFILTER + "CANCELADA_MESANO , ";
                    vFILTER = vFILTER + "CANCELADA_NUMNF  , ";
                    vFILTER = vFILTER + "MATRICULA   ";

                    vINNERJOIN = " ";

                    vORDERBY = "ORDER BY SEQUENCIA ASC ";

                    vAND = vAND + "AND NOMEMAQUINA = ?NOMEMAQUINA ";


                    cmd = new MySqlCommand(this.QuerySelect);

                    cmd.Parameters.AddWithValue("?NOMEMAQUINA", objTempFaturaA.NOMEMAQUINA.ToString().ToUpper());

                    dt = objGerenciadorTransacao.GetDataTable(cmd);

                }

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

        public DataTable SelectOthersTables(entidadeTempFaturaA objTempFaturaA)
        {
            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 + "FATURAS.NUMNF, ";
                    vFILTER = vFILTER + "FATURAS.CFOP, ";
                    vFILTER = vFILTER + "FATURAS.ZONA, ";
                    vFILTER = vFILTER + "FATURAS.LIVRO, ";
                    vFILTER = vFILTER + "FATURAS.CONTA, ";
                    vFILTER = vFILTER + "FATURAS.UNID_ID, ";
                    vFILTER = vFILTER + "FATURAS.CONS_ID, ";
                    vFILTER = vFILTER + "FATURAS.ROTA, ";
                    vFILTER = vFILTER + "FATURAS.AGENC, ";
                    vFILTER = vFILTER + "FATURAS.CC, ";
                    vFILTER = vFILTER + "FATURAS.VALORTOT, ";
                    vFILTER = vFILTER + "FATURAS.CODCLAS, ";
                    vFILTER = vFILTER + "FATURAS.DESCLASSE, ";
                    vFILTER = vFILTER + "FATURAS.DATAVENC, ";
                    vFILTER = vFILTER + "FATURAS.BANCO_FATUR, ";
                    vFILTER = vFILTER + "FATURAS.MESANO, ";
                    vFILTER = vFILTER + "FATURAS.NOMECONS, ";
                    vFILTER = vFILTER + "FATURAS.REFCONS, ";
                    vFILTER = vFILTER + "FATURAS.CGC, ";
                    vFILTER = vFILTER + "FATURAS.INSC, ";
                    vFILTER = vFILTER + "FATURAS.RG, ";
                    vFILTER = vFILTER + "FATURAS.CIDADE, ";
                    vFILTER = vFILTER + "FATURAS.DISTRITO, ";
                    vFILTER = vFILTER + "FATURAS.BAIRRO, ";
                    vFILTER = vFILTER + "FATURAS.END, ";
                    vFILTER = vFILTER + "FATURAS.NUMERO, ";
                    vFILTER = vFILTER + "FATURAS.COMPLEMENT, ";
                    vFILTER = vFILTER + "FATURAS.QUADRA, ";
                    vFILTER = vFILTER + "FATURAS.LOTE, ";
                    vFILTER = vFILTER + "FATURAS.CEP, ";
                    vFILTER = vFILTER + "FATURAS.UF, ";
                    vFILTER = vFILTER + "FATURAS.CID_ENTREGA, ";
                    vFILTER = vFILTER + "FATURAS.DIS_ENTREGA, ";
                    vFILTER = vFILTER + "FATURAS.BAI_ENTREGA, ";
                    vFILTER = vFILTER + "FATURAS.END_ENTREGA, ";
                    vFILTER = vFILTER + "FATURAS.NUM_ENTREGA, ";
                    vFILTER = vFILTER + "FATURAS.COMPL_ENTREGA, ";
                    vFILTER = vFILTER + "FATURAS.QUA_ENTREGA, ";
                    vFILTER = vFILTER + "FATURAS.LOT_ENTREGA, ";
                    vFILTER = vFILTER + "FATURAS.CEP_ENTREGA, ";
                    vFILTER = vFILTER + "FATURAS.UF_ENTREGA, ";
                    vFILTER = vFILTER + "FATURAS.DATAAPR, ";
                    vFILTER = vFILTER + "FATURAS.DATAEMISSAO, ";
                    vFILTER = vFILTER + "FATURAS.DATAPROXLEIT, ";
                    vFILTER = vFILTER + "FATURAS.DATALEIT, ";
                    vFILTER = vFILTER + "FATURAS.DATALEITANT, ";
                    vFILTER = vFILTER + "FATURAS.TA_CONSP, ";
                    vFILTER = vFILTER + "FATURAS.TA_CONSFP, ";
                    vFILTER = vFILTER + "FATURAS.TA_DEMP, ";
                    vFILTER = vFILTER + "FATURAS.TA_DEMFP, ";
                    vFILTER = vFILTER + "FATURAS.TA_ULTRAP, ";
                    vFILTER = vFILTER + "FATURAS.TA_ULTRAFP, ";
                    vFILTER = vFILTER + "FATURAS.FASE, ";
                    vFILTER = vFILTER + "FATURAS.TA, ";
                    vFILTER = vFILTER + "FATURAS.TENSAO, ";
                    vFILTER = vFILTER + "FATURAS.GRUPO, ";
                    vFILTER = vFILTER + "FATURAS.CODHASH, ";
                    vFILTER = vFILTER + "FATURAS.CONST_DEMANDA, ";
                    vFILTER = vFILTER + "FATURAS.CONST_DEMANDA_FP, ";
                    vFILTER = vFILTER + "FATURAS.CONST_CONS_FP, ";
                    vFILTER = vFILTER + "FATURAS.CONST_CONS_P, ";
                    vFILTER = vFILTER + "FATURAS.CONST_KVARH_P, ";
                    vFILTER = vFILTER + "FATURAS.CONST_KVARH_FP, ";
                    vFILTER = vFILTER + "FATURAS.MEDKW, ";
                    vFILTER = vFILTER + "FATURAS.MEDKVARK, ";
                    vFILTER = vFILTER + "FATURAS.ELETR, ";
                    vFILTER = vFILTER + "FATURAS.PERDA, ";
                    vFILTER = vFILTER + "FATURAS.FER_P, ";
                    vFILTER = vFILTER + "FATURAS.FER_FP, ";
                    vFILTER = vFILTER + "FATURAS.CONSMEDIDOP, ";
                    vFILTER = vFILTER + "FATURAS.CONSMEDIDOFP, ";
                    vFILTER = vFILTER + "FATURAS.CONSFATURADOP, ";
                    vFILTER = vFILTER + "FATURAS.CONSFATURADOFP, ";
                    vFILTER = vFILTER + "FATURAS.CONSCONTRP, ";
                    vFILTER = vFILTER + "FATURAS.CONSCONTRFP, ";
                    vFILTER = vFILTER + "FATURAS.DEMMEDIDAP, ";
                    vFILTER = vFILTER + "FATURAS.DEMMEDIDAFP, ";
                    vFILTER = vFILTER + "FATURAS.DEMCONTRP, ";
                    vFILTER = vFILTER + "FATURAS.DEMCONTRFP, ";
                    vFILTER = vFILTER + "FATURAS.DEMCONTRPANTERIOR, ";
                    vFILTER = vFILTER + "FATURAS.DEMCONTRFPANTERIOR, ";
                    vFILTER = vFILTER + "FATURAS.PERIODO_TESTE, ";
                    vFILTER = vFILTER + "FATURAS.DEMFATURP, ";
                    vFILTER = vFILTER + "FATURAS.DEMFATURFP, ";
                    vFILTER = vFILTER + "FATURAS.BASE_ICMS, ";
                    vFILTER = vFILTER + "FATURAS.ALIQ_ICMS, ";
                    vFILTER = vFILTER + "FATURAS.VLR_ICMS, ";
                    vFILTER = vFILTER + "FATURAS.CODBARRA, ";
                    vFILTER = vFILTER + "FATURAS.DVCODBARRA, ";
                    vFILTER = vFILTER + "FATURAS.LINHADIGITAVEL, ";
                    vFILTER = vFILTER + "FATURAS.DEC_META, ";
                    vFILTER = vFILTER + "FATURAS.FEC_META, ";
                    vFILTER = vFILTER + "FATURAS.DIC_META, ";
                    vFILTER = vFILTER + "FATURAS.FIC_META, ";
                    vFILTER = vFILTER + "FATURAS.DEC_REA, ";
                    vFILTER = vFILTER + "FATURAS.FEC_REA, ";
                    vFILTER = vFILTER + "FATURAS.DIC_REA, ";
                    vFILTER = vFILTER + "FATURAS.FIC_REA, ";
                    vFILTER = vFILTER + "FATURAS.DMIC, ";
                    vFILTER = vFILTER + "FATURAS.DMIC_REA, ";
                    vFILTER = vFILTER + "FATURAS.DMICM, ";
                    vFILTER = vFILTER + "FATURAS.REFINDICADOR, ";
                    vFILTER = vFILTER + "FATURAS.CONST_KVARH, ";
                    vFILTER = vFILTER + "FATURAS.LEIT_KVARH_ATUAL, ";
                    vFILTER = vFILTER + "FATURAS.LEIT_KVARH_ANT, ";
                    vFILTER = vFILTER + "FATURAS.CONST_KW, ";
                    vFILTER = vFILTER + "FATURAS.LEIT_KW_ATUAL, ";
                    vFILTER = vFILTER + "FATURAS.LEIT_KW_ANT, ";
                    vFILTER = vFILTER + "FATURAS.CONST_KWH, ";
                    vFILTER = vFILTER + "FATURAS.LEIT_KWH_ATUAL, ";
                    vFILTER = vFILTER + "FATURAS.LEIT_KWH_ANT, ";
                    vFILTER = vFILTER + "FATURAS.KWH_MED, ";
                    vFILTER = vFILTER + "FATURAS.KWH_FAT, ";
                    vFILTER = vFILTER + "FATURAS.KW_MED, ";
                    vFILTER = vFILTER + "FATURAS.KW_FAT, ";
                    vFILTER = vFILTER + "FATURAS.KW_ULTRA, ";
                    vFILTER = vFILTER + "FATURAS.KW_CONT, ";
                    vFILTER = vFILTER + "FATURAS.KVARH_MED, ";
                    vFILTER = vFILTER + "FATURAS.KVARH_FAT, ";
                    vFILTER = vFILTER + "FATURAS.KVARH_FPOT, ";
                    vFILTER = vFILTER + "FATURAS.CARGA, ";
                    vFILTER = vFILTER + "FATURAS.MENSAGEM, ";
                    vFILTER = vFILTER + "FATURAS.ALIQPIS, ";
                    vFILTER = vFILTER + "FATURAS.BASEPIS, ";
                    vFILTER = vFILTER + "FATURAS.VLRPIS, ";
                    vFILTER = vFILTER + "FATURAS.ALIQCOFINS, ";
                    vFILTER = vFILTER + "FATURAS.BASECOFINS, ";
                    vFILTER = vFILTER + "FATURAS.VLRCOFINS, ";
                    vFILTER = vFILTER + "FATURAS.FAT_PENDENTES, ";
                    vFILTER = vFILTER + "FATURAS.CONJUNTO, ";
                    vFILTER = vFILTER + "FATURAS.MESREF, ";
                    vFILTER = vFILTER + "FATURAS.LEIT_KWH_P, ";
                    vFILTER = vFILTER + "FATURAS.LEIT_KWH_FP, ";
                    vFILTER = vFILTER + "FATURAS.LEIT_KW_P, ";
                    vFILTER = vFILTER + "FATURAS.LEIT_KW_FP, ";
                    vFILTER = vFILTER + "FATURAS.LEIT_KVARH_P, ";
                    vFILTER = vFILTER + "FATURAS.LEIT_KVARH_FP, ";
                    vFILTER = vFILTER + "FATURAS.LEIT_KVAR_P, ";
                    vFILTER = vFILTER + "FATURAS.LEIT_KVAR_FP, ";
                    vFILTER = vFILTER + "FATURAS.LEITANT_KWH_P, ";
                    vFILTER = vFILTER + "FATURAS.LEITANT_KWH_FP, ";
                    vFILTER = vFILTER + "FATURAS.LEITANT_KW_P, ";
                    vFILTER = vFILTER + "FATURAS.LEITANT_KW_FP, ";
                    vFILTER = vFILTER + "FATURAS.LEITANT_KVARH_P, ";
                    vFILTER = vFILTER + "FATURAS.LEITANT_KVARH_FP, ";
                    vFILTER = vFILTER + "FATURAS.LEITANT_KWH_RES, ";
                    vFILTER = vFILTER + "FATURAS.LEIT_KWH_RES, ";
                    vFILTER = vFILTER + "FATURAS.CONSRESERVADO, ";
                    vFILTER = vFILTER + "FATURAS.ULTRAP, ";
                    vFILTER = vFILTER + "FATURAS.ULTRAFP, ";
                    vFILTER = vFILTER + "FATURAS.RET_PIS, ";
                    vFILTER = vFILTER + "FATURAS.RET_CSLL, ";
                    vFILTER = vFILTER + "FATURAS.RET_COFINS, ";
                    vFILTER = vFILTER + "FATURAS.RET_IRPJC, ";
                    vFILTER = vFILTER + "FATURAS.RET_IRPJD, ";
                    vFILTER = vFILTER + "FATURAS.RET_CSLLD, ";
                    vFILTER = vFILTER + "FATURAS.RET_COFINSD, ";
                    vFILTER = vFILTER + "FATURAS.RET_PISD, ";
                    vFILTER = vFILTER + "FATURAS.VALORLIQ, ";
                    vFILTER = vFILTER + "FATURAS.SEGVIA, ";
                    vFILTER = vFILTER + "FATURAS.NOMEMAQUINA, ";
                    vFILTER = vFILTER + "FATURAS.COMP_ENERGIA, ";
                    vFILTER = vFILTER + "FATURAS.COMP_TRANSMISSAO, ";
                    vFILTER = vFILTER + "FATURAS.COMP_DISTRIBUICAO, ";
                    vFILTER = vFILTER + "FATURAS.COMP_ENCARGOS_SETORIAIS, ";
                    vFILTER = vFILTER + "FATURAS.COMP_PERDAS, ";
                    vFILTER = vFILTER + "FATURAS.COMP_TRIBUTOS, ";
                    vFILTER = vFILTER + "FATURAS.COMP_OUTROS, ";
                    vFILTER = vFILTER + "FATURAS.BASE_ICMS2, ";
                    vFILTER = vFILTER + "FATURAS.ALIQ_ICMS2, ";
                    vFILTER = vFILTER + "FATURAS.VLR_ICMS2, ";
                    vFILTER = vFILTER + "FATURAS.BANDEIRA, ";
                    vFILTER = vFILTER + "FATURAS.BASE_ICMS_ST, ";
                    vFILTER = vFILTER + "FATURAS.ALIQ_ICMS_ST, ";
                    vFILTER = vFILTER + "FATURAS.VLR_ICMS_ST, ";
                    vFILTER = vFILTER + "FATURAS.ALIQPIS_ST, ";
                    vFILTER = vFILTER + "FATURAS.BASEPIS_ST, ";
                    vFILTER = vFILTER + "FATURAS.VLRPIS_ST, ";
                    vFILTER = vFILTER + "FATURAS.ALIQCOFINS_ST, ";
                    vFILTER = vFILTER + "FATURAS.BASECOFINS_ST, ";
                    vFILTER = vFILTER + "FATURAS.VLRCOFINS_ST, ";
                    vFILTER = vFILTER + "FATURAS.VLRENERGIA_ST, ";
                    vFILTER = vFILTER + "FATURAS.VLRPCMEDIO_ST, ";
                    vFILTER = vFILTER + "FATURAS.VLRCONSUMO_ST, ";
                    vFILTER = vFILTER + "FATURAS.REFERENCIA_ST, ";
                    vFILTER = vFILTER + "FATURAS.MENSAGEM_BANDEIRA, ";
                    vFILTER = vFILTER + "FATURAS.FRENTEVERSO, ";
                    vFILTER = vFILTER + "FATURAS.LIVRE_VERDE, ";
                    vFILTER = vFILTER + "FATURAS.MESANOREF, ";
                    vFILTER = vFILTER + "FATURAS.PARC_CATIVO, ";
                    vFILTER = vFILTER + "FATURAS.LEIT_REVERSO_P, ";
                    vFILTER = vFILTER + "FATURAS.LEIT_REVERSO_FP, ";
                    vFILTER = vFILTER + "FATURAS.LEITANT_REVERSO_P, ";
                    vFILTER = vFILTER + "FATURAS.LEITANT_REVERSO_FP, ";
                    vFILTER = vFILTER + "FATURAS.KWH_REVERSO_P, ";
                    vFILTER = vFILTER + "FATURAS.KWH_REVERSO_FP, ";
                    vFILTER = vFILTER + "FATURAS.MICRO_GERACAO, ";
                    vFILTER = vFILTER + "FATURAS.IRRIGACAO_AQUICULTURA, ";
                    vFILTER = vFILTER + "FATURAS.KWH_REVERSO_RES_P, ";
                    vFILTER = vFILTER + "FATURAS.KWH_REVERSO_RES_FP, ";
                    vFILTER = vFILTER + "FATURAS.KWH_REVERSO_REC_P, ";
                    vFILTER = vFILTER + "FATURAS.KWH_REVERSO_REC_FP, ";
                    vFILTER = vFILTER + "FATURAS.KWH_ENVIADO, ";
                    vFILTER = vFILTER + "FATURAS.KWH_SALDO, ";
                    vFILTER = vFILTER + "FATURAS.ITENSIMP, ";
                    vFILTER = vFILTER + "FATURAS.ANOMES_FAT, ";
                    vFILTER = vFILTER + "FATURAS.FLGST , ";
                    vFILTER = vFILTER + "FATURAS.CANCELADA_MESANO , ";
                    vFILTER = vFILTER + "FATURAS.CANCELADA_NUMNF  , ";
                    vFILTER = vFILTER + "FATURAS.MATRICULA ,  ";
                    vFILTER = vFILTER + "IMAGEPIXBARRAS.IMAGEBARRAS  AS IMAGE_BARCODE , ";
                    vFILTER = vFILTER + "IMAGEPIXBARRAS.IMAGEPIX  AS IMAGE_PIX ";


                    vINNERJOIN = " AS FATURAS  ";
                    vINNERJOIN = vINNERJOIN + "INNER JOIN  TEMP_FATURA_A_IMAGE_PIX_BARRAS AS IMAGEPIXBARRAS ON FATURAS.NUMNF = IMAGEPIXBARRAS.NUMNF AND FATURAS.NOMEMAQUINA = IMAGEPIXBARRAS.NOMEMAQUINA";


                    vORDERBY = "ORDER BY SEQUENCIA ASC ";

                    vAND = vAND + "AND FATURAS.NOMEMAQUINA = ?NOMEMAQUINA ";


                    cmd = new MySqlCommand(this.QuerySelect);

                    cmd.Parameters.AddWithValue("?NOMEMAQUINA", objTempFaturaA.NOMEMAQUINA.ToString().ToUpper());

                    dt = objGerenciadorTransacao.GetDataTable(cmd);

                }

                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            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("TEMP_FATURA_A SET  ");
                this.sb.AppendLine(vFILTER);

                return sb.ToString();
            }
        }

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

                this.sb.AppendLine("UPDATE  ");
                this.sb.AppendLine("TEMP_FATURA_A 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 TEMP_FATURA_A ");
                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("TEMP_FATURA_A  ");
                this.sb.AppendLine(vINNERJOIN);
                this.sb.AppendLine("WHERE 1 = 1  ");
                this.sb.AppendLine(vAND);
                this.sb.AppendLine(vORDERBY);

                return sb.ToString();
            }
        }

        #endregion



    }
}
