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 dalLeitmensal
    {
        string vFILTER = null;
        string vINNERJOIN = null;
        string vAND = null;
        string vORDERBY = null;

        #region Métodos

        public void Insert(entidadeLeitmensal objLeitmensal)
        {
            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 + "STATUS = ?STATUS , ";
                    vFILTER = vFILTER + "ROTA = ?ROTA , ";
                    vFILTER = vFILTER + "SEQ  = ?SEQ  , ";
                    vFILTER = vFILTER + "ZONA = ?ZONA , ";
                    vFILTER = vFILTER + "LIVRO  = ?LIVRO  , ";
                    vFILTER = vFILTER + "CONTA  = ?CONTA  , ";
                    vFILTER = vFILTER + "LEIT_ANT = ?LEIT_ANT , ";
                    vFILTER = vFILTER + "LEIT_ATUAL = ?LEIT_ATUAL , ";
                    vFILTER = vFILTER + "MEDIDOR  = ?MEDIDOR  , ";
                    if (!string.IsNullOrWhiteSpace(objLeitmensal.ENDERECO))
                    {
                        vFILTER = vFILTER + "ENDERECO = ?ENDERECO , ";
                    }
                    vFILTER = vFILTER + "NOME = ?NOME , ";
                    //vFILTER = vFILTER + "MUNICIP  = ?MUNICIP  , ";
                    if (!string.IsNullOrWhiteSpace(objLeitmensal.MUNICIP))
                    {
                        vFILTER = vFILTER + "MUNICIP = ?MUNICIP , ";
                    }
                    vFILTER = vFILTER + "MEDIA  = ?MEDIA  , ";
                    vFILTER = vFILTER + "OCORRENC = ?OCORRENC , ";
                    vFILTER = vFILTER + "RESIDUO  = ?RESIDUO  , ";
                    vFILTER = vFILTER + "MEDKVARH = ?MEDKVARH , ";
                    vFILTER = vFILTER + "KVARH  = ?KVARH  , ";
                    vFILTER = vFILTER + "KVARHATUAL = ?KVARHATUAL , ";
                    vFILTER = vFILTER + "DT_LEIT  = ?DT_LEIT  , ";
                    vFILTER = vFILTER + "DT_LEITANT = ?DT_LEITANT , ";
                    vFILTER = vFILTER + "CONS_ID  = ?CONS_ID  , ";
                    vFILTER = vFILTER + "UNID_ID  = ?UNID_ID  , ";
                    vFILTER = vFILTER + "LEIT_REVERSO_ANT = ?LEIT_REVERSO_ANT , ";
                    vFILTER = vFILTER + "LEIT_REVERSO_ATUAL = ?LEIT_REVERSO_ATUAL , ";
                    vFILTER = vFILTER + "KWH_REVERSO  = ?KWH_REVERSO  , ";
                    vFILTER = vFILTER + "KWH_REVERSO_RES  = ?KWH_REVERSO_RES  , ";
                    vFILTER = vFILTER + "LEIT_IRRIGANTE_ANT = ?LEIT_IRRIGANTE_ANT , ";
                    vFILTER = vFILTER + "LEIT_IRRIGANTE_ATUAL = ?LEIT_IRRIGANTE_ATUAL , ";
                    vFILTER = vFILTER + "KWH_IRRIGANTE  = ?KWH_IRRIGANTE  , ";
                    vFILTER = vFILTER + "KWH_IRRIGANTE_RES  = ?KWH_IRRIGANTE_RES  , ";
                    vFILTER = vFILTER + "LEITURA_ANT_PONTA = ?LEITURA_ANT_PONTA , ";
                    vFILTER = vFILTER + "LEITURA_ATUAL_PONTA = ?LEITURA_ATUAL_PONTA , ";
                    vFILTER = vFILTER + "LEITURA_ANT_INTERMEDIARIO = ?LEITURA_ANT_INTERMEDIARIO , ";
                    vFILTER = vFILTER + "LEITURA_ATUAL_INTERMEDIARIO = ?LEITURA_ATUAL_INTERMEDIARIO , ";
                    vFILTER = vFILTER + "LEITURA_ANT_FORA_PONTA = ?LEITURA_ANT_FORA_PONTA , ";
                    vFILTER = vFILTER + "LEITURA_ATUAL_FORA_PONTA = ?LEITURA_ATUAL_FORA_PONTA , ";
                    vFILTER = vFILTER + "KWH_PONTA = ?KWH_PONTA , ";
                    vFILTER = vFILTER + "KWH_INTERMEDIARIO = ?KWH_INTERMEDIARIO , ";
                    vFILTER = vFILTER + "KWH_FORA_PONTA = ?KWH_FORA_PONTA , ";
                    vFILTER = vFILTER + "RESIDUO_PONTA = ?RESIDUO_PONTA , ";
                    vFILTER = vFILTER + "RESIDUO_INTERMEDIARIO = ?RESIDUO_INTERMEDIARIO , ";
                    vFILTER = vFILTER + "RESIDUO_FORA_PONTA = ?RESIDUO_FORA_PONTA , ";
                    vFILTER = vFILTER + "SIT = ?SIT,  ";
                    vFILTER = vFILTER + "VERIFICADO = ?VERIFICADO,  ";
                    vFILTER = vFILTER + "MEDIA_CRITICA = ?MEDIA_CRITICA  ";



                    cmd = new MySqlCommand(this.QueryInsert);

                    cmd.Parameters.AddWithValue("?STATUS", objLeitmensal.STATUS);
                    cmd.Parameters.AddWithValue("?ROTA", objLeitmensal.ROTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?SEQ", objLeitmensal.SEQ.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?ZONA", objLeitmensal.ZONA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LIVRO", objLeitmensal.LIVRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTA", objLeitmensal.CONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEIT_ANT", objLeitmensal.LEIT_ANT.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEIT_ATUAL", objLeitmensal.LEIT_ATUAL.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MEDIDOR", objLeitmensal.MEDIDOR.ToString().ToUpper());
                    if (!string.IsNullOrWhiteSpace(objLeitmensal.ENDERECO))
                    {
                        cmd.Parameters.AddWithValue("?ENDERECO", objLeitmensal.ENDERECO.ToString().ToUpper());
                    }
                    cmd.Parameters.AddWithValue("?NOME", objLeitmensal.NOME.ToString().ToUpper());
                    //cmd.Parameters.AddWithValue("?MUNICIP", objLeitmensal.MUNICIP.ToString().ToUpper());
                    if (!string.IsNullOrWhiteSpace(objLeitmensal.MUNICIP))
                    {
                        cmd.Parameters.AddWithValue("?MUNICIP", objLeitmensal.MUNICIP.ToString().ToUpper());
                    }
                    cmd.Parameters.AddWithValue("?MEDIA", objLeitmensal.MEDIA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?OCORRENC", objLeitmensal.OCORRENC.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?RESIDUO", objLeitmensal.RESIDUO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MEDKVARH", objLeitmensal.MEDKVARH.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?KVARH", objLeitmensal.KVARH);
                    cmd.Parameters.AddWithValue("?KVARHATUAL", objLeitmensal.KVARHATUAL);
                    cmd.Parameters.AddWithValue("?DT_LEIT", objLeitmensal.DT_LEIT);
                    cmd.Parameters.AddWithValue("?DT_LEITANT", objLeitmensal.DT_LEITANT);
                    cmd.Parameters.AddWithValue("?CONS_ID", objLeitmensal.CONS_ID);
                    cmd.Parameters.AddWithValue("?UNID_ID", objLeitmensal.UNID_ID);
                    cmd.Parameters.AddWithValue("?LEIT_REVERSO_ANT", objLeitmensal.LEIT_REVERSO_ANT.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEIT_REVERSO_ATUAL", objLeitmensal.LEIT_REVERSO_ATUAL.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?KWH_REVERSO", objLeitmensal.KWH_REVERSO);
                    cmd.Parameters.AddWithValue("?KWH_REVERSO_RES", objLeitmensal.KWH_REVERSO_RES);
                    cmd.Parameters.AddWithValue("?LEIT_IRRIGANTE_ANT", objLeitmensal.LEIT_IRRIGANTE_ANT.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEIT_IRRIGANTE_ATUAL", objLeitmensal.LEIT_IRRIGANTE_ATUAL.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?KWH_IRRIGANTE", objLeitmensal.KWH_IRRIGANTE);
                    cmd.Parameters.AddWithValue("?KWH_IRRIGANTE_RES", objLeitmensal.KWH_IRRIGANTE_RES);
                    cmd.Parameters.AddWithValue("?LEITURA_ANT_PONTA", objLeitmensal.LEITURA_ANT_PONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEITURA_ATUAL_PONTA", objLeitmensal.LEITURA_ATUAL_PONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEITURA_ANT_INTERMEDIARIO", objLeitmensal.LEITURA_ANT_INTERMEDIARIO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEITURA_ATUAL_INTERMEDIARIO", objLeitmensal.LEITURA_ATUAL_INTERMEDIARIO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEITURA_ANT_FORA_PONTA", objLeitmensal.LEITURA_ANT_FORA_PONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEITURA_ATUAL_FORA_PONTA", objLeitmensal.LEITURA_ATUAL_FORA_PONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?KWH_PONTA", objLeitmensal.KWH_PONTA);
                    cmd.Parameters.AddWithValue("?KWH_INTERMEDIARIO", objLeitmensal.KWH_INTERMEDIARIO);
                    cmd.Parameters.AddWithValue("?KWH_FORA_PONTA", objLeitmensal.KWH_FORA_PONTA);
                    cmd.Parameters.AddWithValue("?RESIDUO_PONTA", objLeitmensal.RESIDUO_PONTA);
                    cmd.Parameters.AddWithValue("?RESIDUO_INTERMEDIARIO", objLeitmensal.RESIDUO_INTERMEDIARIO);
                    cmd.Parameters.AddWithValue("?RESIDUO_FORA_PONTA", objLeitmensal.RESIDUO_FORA_PONTA);
                    cmd.Parameters.AddWithValue("?SIT", objLeitmensal.SIT.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?VERIFICADO", objLeitmensal.VERIFICADO);
                    cmd.Parameters.AddWithValue("?MEDIA_CRITICA", objLeitmensal.MEDIA_CRITICA);

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

        public void Insert_1(entidadeLeitmensal objLeitmensal)
        {
            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 + "STATUS = ?STATUS , ";
                    vFILTER = vFILTER + "ROTA = ?ROTA , ";
                    vFILTER = vFILTER + "SEQ  = ?SEQ  , ";
                    vFILTER = vFILTER + "ZONA = ?ZONA , ";
                    vFILTER = vFILTER + "LIVRO  = ?LIVRO  , ";
                    vFILTER = vFILTER + "CONTA  = ?CONTA  , ";
                    vFILTER = vFILTER + "LEIT_ANT = ?LEIT_ANT , ";
                    vFILTER = vFILTER + "LEIT_ATUAL = ?LEIT_ATUAL , ";
                    vFILTER = vFILTER + "MEDIDOR  = ?MEDIDOR  , ";
                    vFILTER = vFILTER + "ENDERECO = ?ENDERECO , ";
                    vFILTER = vFILTER + "NOME = ?NOME , ";
                    vFILTER = vFILTER + "MUNICIP  = ?MUNICIP  , ";
                    vFILTER = vFILTER + "MEDIA  = ?MEDIA  , ";
                    vFILTER = vFILTER + "OCORRENC = ?OCORRENC , ";
                    vFILTER = vFILTER + "RESIDUO  = ?RESIDUO  , ";
                    vFILTER = vFILTER + "MEDKVARH = ?MEDKVARH , ";
                    vFILTER = vFILTER + "KVARH  = ?KVARH  , ";
                    vFILTER = vFILTER + "KVARHATUAL = ?KVARHATUAL , ";
                    vFILTER = vFILTER + "DT_LEIT  = ?DT_LEIT  , ";
                    vFILTER = vFILTER + "CONS_ID  = ?CONS_ID  , ";
                    vFILTER = vFILTER + "UNID_ID  = ?UNID_ID   ";




                    cmd = new MySqlCommand(this.QueryInsert);

                    cmd.Parameters.AddWithValue("?STATUS", objLeitmensal.STATUS);
                    cmd.Parameters.AddWithValue("?ROTA", objLeitmensal.ROTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?SEQ", objLeitmensal.SEQ.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?ZONA", objLeitmensal.ZONA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LIVRO", objLeitmensal.LIVRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTA", objLeitmensal.CONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEIT_ANT", objLeitmensal.LEIT_ANT.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEIT_ATUAL", objLeitmensal.LEIT_ATUAL.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MEDIDOR", objLeitmensal.MEDIDOR.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?ENDERECO", objLeitmensal.ENDERECO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?NOME", objLeitmensal.NOME.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MUNICIP", objLeitmensal.MUNICIP.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MEDIA", objLeitmensal.MEDIA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?OCORRENC", objLeitmensal.OCORRENC.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?RESIDUO", objLeitmensal.RESIDUO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MEDKVARH", objLeitmensal.MEDKVARH.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?KVARH", objLeitmensal.KVARH);
                    cmd.Parameters.AddWithValue("?KVARHATUAL", objLeitmensal.KVARHATUAL);
                    cmd.Parameters.AddWithValue("?DT_LEIT", objLeitmensal.DT_LEIT);
                    cmd.Parameters.AddWithValue("?CONS_ID", objLeitmensal.CONS_ID);
                    cmd.Parameters.AddWithValue("?UNID_ID", objLeitmensal.UNID_ID);

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

        public void Update(entidadeLeitmensal objLeitmensal)
        {
            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 = string.Empty;
                    vAND = string.Empty;

                    if (objLeitmensal.LEIT_ANT != String.Empty)
                    {
                        if (vFILTER != String.Empty)
                        { vFILTER = vFILTER + "LEIT_ANT = ?LEIT_ANT , "; }
                        else
                        { vFILTER = "LEIT_ANT = ?LEIT_ANT , "; }

                    }

                    if (objLeitmensal.LEIT_REVERSO_ANT != String.Empty)
                    {
                        if (vFILTER != String.Empty)
                        { vFILTER = vFILTER + "LEIT_REVERSO_ANT = ?LEIT_REVERSO_ANT , "; }
                        else
                        { vFILTER = "LEIT_REVERSO_ANT = ?LEIT_REVERSO_ANT , "; }

                    }


                    if (objLeitmensal.KWH_REVERSO_RES != 0)
                    {
                        if (vFILTER != String.Empty)
                        { vFILTER = vFILTER + "KWH_REVERSO_RES = ?KWH_REVERSO_RES , "; }
                        else
                        { vFILTER = "KWH_REVERSO_RES = ?KWH_REVERSO_RES , "; }

                    }


                    if (objLeitmensal.ULT_LEIT_CORTE != 0)
                    {
                        if (vFILTER != String.Empty)
                        { vFILTER = vFILTER + "ULT_LEIT_CORTE = ?ULT_LEIT_CORTE , "; }
                        else
                        { vFILTER = "ULT_LEIT_CORTE = ?ULT_LEIT_CORTE , "; }

                    }


                    if (objLeitmensal.RESIDUO != 0)
                    {
                        if (vFILTER != String.Empty)
                        { vFILTER = vFILTER + "RESIDUO = ?RESIDUO , "; }
                        else
                        { vFILTER = "RESIDUO = ?RESIDUO , "; }

                    }


                    vFILTER = vFILTER + "ROTA  = ?ROTA ";


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

                    }


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

                    }


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

                    }


                    //if (objLeitmensal.DT_LEIT != Convert.ToDateTime("01/01/0001"))
                    //''{
                    //    if (vAND != String.Empty)
                    //    { vAND = vAND + "AND DATE_FORMAT(DT_LEIT, '%Y%m')  = ?DT_LEIT "; }
                    //    else
                    //    { vAND = "AND DATE_FORMAT(DT_LEIT, '%Y%m') =  = ?DT_LEIT "; }

                    //}


                    cmd = new MySqlCommand(this.QueryUpdate);

                    if (objLeitmensal.LEIT_ANT != String.Empty)
                    {
                        cmd.Parameters.AddWithValue("?LEIT_ANT", objLeitmensal.LEIT_ANT.ToString().ToUpper());
                    }

                    if (objLeitmensal.LEIT_REVERSO_ANT != String.Empty)
                    {
                        cmd.Parameters.AddWithValue("?LEIT_REVERSO_ANT", objLeitmensal.LEIT_REVERSO_ANT.ToString().ToUpper());
                    }

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

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

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

                    cmd.Parameters.AddWithValue("?ROTA", objLeitmensal.ROTA.ToString().ToUpper());


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


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


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

                    //if (objLeitmensal.DT_LEIT != Convert.ToDateTime("01/01/0001"))
                    //{
                    //    cmd.Parameters.AddWithValue("?DT_LEIT", objLeitmensal.DT_LEIT.ToString().ToUpper());
                    //}


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

        public void Update_1(entidadeLeitmensal objLeitmensal)
        {
            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 + "LEIT_ATUAL = ? LEIT_ATUAL ,";
                    vFILTER = vFILTER + "OCORRENC = ?OCORRENC   ,";
                    vFILTER = vFILTER + "RESIDUO = ?RESIDUO    ,";
                    vFILTER = vFILTER + "LEIT_REVERSO_ANT = ?LEIT_REVERSO_ANT  ,";
                    vFILTER = vFILTER + "LEIT_REVERSO_ATUAL = ?LEIT_REVERSO_ATUAL,";
                    vFILTER = vFILTER + "KWH_REVERSO = ?KWH_REVERSO       ,";
                    vFILTER = vFILTER + "KWH_REVERSO_RES = ?KWH_REVERSO_RES   ,";
                    vFILTER = vFILTER + "LEIT_IRRIGANTE_ANT = ?LEIT_IRRIGANTE_ANT   ,";
                    vFILTER = vFILTER + "LEIT_IRRIGANTE_ATUAL = ?LEIT_IRRIGANTE_ATUAL ,";
                    vFILTER = vFILTER + "KWH_IRRIGANTE = ?KWH_IRRIGANTE        ,";
                    vFILTER = vFILTER + "KWH_IRRIGANTE_RES = ?KWH_IRRIGANTE_RES    ,";
                    vFILTER = vFILTER + "LEITURA_ANT_PONTA = ?LEITURA_ANT_PONTA           ,";
                    vFILTER = vFILTER + "LEITURA_ATUAL_PONTA = ?LEITURA_ATUAL_PONTA         ,";
                    vFILTER = vFILTER + "LEITURA_ANT_INTERMEDIARIO = ?LEITURA_ANT_INTERMEDIARIO   ,";
                    vFILTER = vFILTER + "LEITURA_ATUAL_INTERMEDIARIO = ?LEITURA_ATUAL_INTERMEDIARIO ,";
                    vFILTER = vFILTER + "LEITURA_ANT_FORA_PONTA = ?LEITURA_ANT_FORA_PONTA      ,";
                    vFILTER = vFILTER + "LEITURA_ATUAL_FORA_PONTA = ?LEITURA_ATUAL_FORA_PONTA    ,";
                    vFILTER = vFILTER + "KWH_PONTA = ?KWH_PONTA                   ,";
                    vFILTER = vFILTER + "KWH_INTERMEDIARIO = ?KWH_INTERMEDIARIO           ,";
                    vFILTER = vFILTER + "KWH_FORA_PONTA = ?KWH_FORA_PONTA              ,";
                    vFILTER = vFILTER + "RESIDUO_PONTA = ?RESIDUO_PONTA               ,";
                    vFILTER = vFILTER + "RESIDUO_INTERMEDIARIO = ?RESIDUO_INTERMEDIARIO       ,";
                    vFILTER = vFILTER + "RESIDUO_FORA_PONTA = ?RESIDUO_FORA_PONTA          ,";
                    vFILTER = vFILTER + "MEDIA = ?MEDIA";


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



                    cmd = new MySqlCommand(this.QueryUpdate);

                    cmd.Parameters.AddWithValue("?LEIT_ATUAL ", objLeitmensal.LEIT_ATUAL.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?OCORRENC ", objLeitmensal.OCORRENC.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?RESIDUO", objLeitmensal.RESIDUO);
                    cmd.Parameters.AddWithValue("?LEIT_REVERSO_ANT", objLeitmensal.LEIT_REVERSO_ANT.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEIT_REVERSO_ATUAL", objLeitmensal.LEIT_REVERSO_ATUAL.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?KWH_REVERSO", objLeitmensal.KWH_REVERSO);
                    cmd.Parameters.AddWithValue("?KWH_REVERSO_RES", objLeitmensal.KWH_REVERSO_RES);
                    cmd.Parameters.AddWithValue("?LEIT_IRRIGANTE_ANT", objLeitmensal.LEIT_IRRIGANTE_ANT.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEIT_IRRIGANTE_ATUAL", objLeitmensal.LEIT_IRRIGANTE_ATUAL.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?KWH_IRRIGANTE", objLeitmensal.KWH_IRRIGANTE);
                    cmd.Parameters.AddWithValue("?KWH_IRRIGANTE_RES", objLeitmensal.KWH_IRRIGANTE_RES);
                    cmd.Parameters.AddWithValue("?LEITURA_ANT_PONTA", objLeitmensal.LEITURA_ANT_PONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEITURA_ATUAL_PONTA", objLeitmensal.LEITURA_ATUAL_PONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEITURA_ANT_INTERMEDIARIO", objLeitmensal.LEITURA_ANT_INTERMEDIARIO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEITURA_ATUAL_INTERMEDIARIO", objLeitmensal.LEITURA_ATUAL_INTERMEDIARIO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEITURA_ANT_FORA_PONTA", objLeitmensal.LEITURA_ANT_FORA_PONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEITURA_ATUAL_FORA_PONTA", objLeitmensal.LEITURA_ATUAL_FORA_PONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?KWH_PONTA", objLeitmensal.KWH_PONTA);
                    cmd.Parameters.AddWithValue("?KWH_INTERMEDIARIO", objLeitmensal.KWH_INTERMEDIARIO);
                    cmd.Parameters.AddWithValue("?KWH_FORA_PONTA", objLeitmensal.KWH_FORA_PONTA);
                    cmd.Parameters.AddWithValue("?RESIDUO_PONTA", objLeitmensal.RESIDUO_PONTA);
                    cmd.Parameters.AddWithValue("?RESIDUO_INTERMEDIARIO", objLeitmensal.RESIDUO_INTERMEDIARIO);
                    cmd.Parameters.AddWithValue("?RESIDUO_FORA_PONTA", objLeitmensal.RESIDUO_FORA_PONTA);
                    cmd.Parameters.AddWithValue("?MEDIA", objLeitmensal.MEDIA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?ZONA", objLeitmensal.ZONA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LIVRO", objLeitmensal.LIVRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTA", objLeitmensal.CONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?UNID_ID", objLeitmensal.UNID_ID);



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

        public void Update_2(entidadeLeitmensal objLeitmensal)
        {
            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 + "VERIFICADO = ?VERIFICADO ,";
                    vFILTER = vFILTER + "MEDIA_CRITICA = ?MEDIA_CRITICA ,";
                    vFILTER = vFILTER + "MEDIDOR = ?MEDIDOR ,";
                    vFILTER = vFILTER + "LEIT_ANT = ?LEIT_ANT ,";
                    vFILTER = vFILTER + "LEIT_ATUAL = ?LEIT_ATUAL ,";
                    vFILTER = vFILTER + "MEDKVARH = ?MEDKVARH ,";
                    vFILTER = vFILTER + "KVARH = ?KVARH ,";
                    vFILTER = vFILTER + "KVARHATUAL = ?KVARHATUAL ,";
                    vFILTER = vFILTER + "OCORRENC = ?OCORRENC ,";
                    vFILTER = vFILTER + "RESIDUO = ?RESIDUO ,";
                    vFILTER = vFILTER + "ENDERECO = ?ENDERECO ,";
                    vFILTER = vFILTER + "NOME = ?NOME ,";
                    vFILTER = vFILTER + "MUNICIP = ?MUNICIP ,";
                    vFILTER = vFILTER + "DT_LEIT = ?DT_LEIT ,";
                    vFILTER = vFILTER + "DT_LEITANT = ?DT_LEITANT ,";
                    vFILTER = vFILTER + "LEIT_REVERSO_ANT = ?LEIT_REVERSO_ANT ,";
                    vFILTER = vFILTER + "LEIT_REVERSO_ATUAL = ?LEIT_REVERSO_ATUAL ,";
                    vFILTER = vFILTER + "KWH_REVERSO   = ?KWH_REVERSO   ,";
                    vFILTER = vFILTER + "KWH_REVERSO_RES = ?KWH_REVERSO_RES ,";
                    vFILTER = vFILTER + "LEIT_IRRIGANTE_ANT = ?LEIT_IRRIGANTE_ANT ,";
                    vFILTER = vFILTER + "LEIT_IRRIGANTE_ATUAL = ?LEIT_IRRIGANTE_ATUAL ,";
                    vFILTER = vFILTER + "KWH_IRRIGANTE = ?KWH_IRRIGANTE ,";
                    vFILTER = vFILTER + "KWH_IRRIGANTE_RES = ?KWH_IRRIGANTE_RES ,";
                    vFILTER = vFILTER + "LEITURA_ANT_PONTA     = ?LEITURA_ANT_PONTA     ,";
                    vFILTER = vFILTER + "LEITURA_ATUAL_PONTA  = ?LEITURA_ATUAL_PONTA  ,";
                    vFILTER = vFILTER + "LEITURA_ANT_INTERMEDIARIO = ?LEITURA_ANT_INTERMEDIARIO ,";
                    vFILTER = vFILTER + "LEITURA_ATUAL_INTERMEDIARIO = ?LEITURA_ATUAL_INTERMEDIARIO ,";
                    vFILTER = vFILTER + "LEITURA_ANT_FORA_PONTA  = ?LEITURA_ANT_FORA_PONTA  ,";
                    vFILTER = vFILTER + "LEITURA_ATUAL_FORA_PONTA = ?LEITURA_ATUAL_FORA_PONTA ,";
                    vFILTER = vFILTER + "KWH_PONTA          = ?KWH_PONTA          ,";
                    vFILTER = vFILTER + "KWH_INTERMEDIARIO  = ?KWH_INTERMEDIARIO  ,";
                    vFILTER = vFILTER + "KWH_FORA_PONTA      = ?KWH_FORA_PONTA      ,";
                    vFILTER = vFILTER + "RESIDUO_PONTA         = ?RESIDUO_PONTA         ,";
                    vFILTER = vFILTER + "RESIDUO_INTERMEDIARIO = ?RESIDUO_INTERMEDIARIO ,";
                    vFILTER = vFILTER + "RESIDUO_FORA_PONTA = ?RESIDUO_FORA_PONTA ,";
                    vFILTER = vFILTER + "MEDIA = ?MEDIA ,";
                    vFILTER = vFILTER + "INT_MICRO_GERACAO = ?INT_MICRO_GERACAO ";

                    vAND = vAND + "   AND ZONA  = ?ZONA ";
                    vAND = vAND + "   AND LIVRO = ?LIVRO ";
                    vAND = vAND + "   AND CONTA = ?CONTA ";
                    vAND = vAND + "   AND UNID_ID = ?UNID_ID ";
                    vAND = vAND + "   AND DATE_FORMAT(DT_LEIT, '%Y-%m') = DATE_FORMAT(?DT_LEIT, '%Y-%m') ";


                    cmd = new MySqlCommand(this.QueryUpdate);

                    cmd.Parameters.AddWithValue("?VERIFICADO", objLeitmensal.VERIFICADO);
                    cmd.Parameters.AddWithValue("?MEDIA_CRITICA", objLeitmensal.MEDIA_CRITICA);
                    cmd.Parameters.AddWithValue("?MEDIDOR", objLeitmensal.MEDIDOR.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEIT_ANT", objLeitmensal.LEIT_ANT.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEIT_ATUAL", objLeitmensal.LEIT_ATUAL.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MEDKVARH", objLeitmensal.MEDKVARH.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?KVARH", objLeitmensal.KVARH);
                    cmd.Parameters.AddWithValue("?KVARHATUAL", objLeitmensal.KVARHATUAL);
                    cmd.Parameters.AddWithValue("?OCORRENC", objLeitmensal.OCORRENC.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?RESIDUO", objLeitmensal.RESIDUO);
                    cmd.Parameters.AddWithValue("?ENDERECO", objLeitmensal.ENDERECO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?NOME", objLeitmensal.NOME.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?MUNICIP", objLeitmensal.MUNICIP.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DT_LEIT", objLeitmensal.DT_LEIT);
                    cmd.Parameters.AddWithValue("?DT_LEITANT", objLeitmensal.DT_LEITANT);
                    cmd.Parameters.AddWithValue("?LEIT_REVERSO_ANT", objLeitmensal.LEIT_REVERSO_ANT.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEIT_REVERSO_ATUAL", objLeitmensal.LEIT_REVERSO_ATUAL.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?KWH_REVERSO", objLeitmensal.KWH_REVERSO);
                    cmd.Parameters.AddWithValue("?KWH_REVERSO_RES", objLeitmensal.KWH_REVERSO_RES);
                    cmd.Parameters.AddWithValue("?LEIT_IRRIGANTE_ANT", objLeitmensal.LEIT_IRRIGANTE_ANT.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEIT_IRRIGANTE_ATUAL", objLeitmensal.LEIT_IRRIGANTE_ATUAL.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?KWH_IRRIGANTE", objLeitmensal.KWH_IRRIGANTE);
                    cmd.Parameters.AddWithValue("?KWH_IRRIGANTE_RES", objLeitmensal.KWH_IRRIGANTE_RES);
                    cmd.Parameters.AddWithValue("?LEITURA_ANT_PONTA", objLeitmensal.LEITURA_ANT_PONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEITURA_ATUAL_PONTA", objLeitmensal.LEITURA_ATUAL_PONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEITURA_ANT_INTERMEDIARIO", objLeitmensal.LEITURA_ANT_INTERMEDIARIO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEITURA_ATUAL_INTERMEDIARIO", objLeitmensal.LEITURA_ATUAL_INTERMEDIARIO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEITURA_ANT_FORA_PONTA", objLeitmensal.LEITURA_ANT_FORA_PONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEITURA_ATUAL_FORA_PONTA", objLeitmensal.LEITURA_ATUAL_FORA_PONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?KWH_PONTA", objLeitmensal.KWH_PONTA);
                    cmd.Parameters.AddWithValue("?KWH_INTERMEDIARIO", objLeitmensal.KWH_INTERMEDIARIO);
                    cmd.Parameters.AddWithValue("?KWH_FORA_PONTA", objLeitmensal.KWH_FORA_PONTA);
                    cmd.Parameters.AddWithValue("?RESIDUO_PONTA", objLeitmensal.RESIDUO_PONTA);
                    cmd.Parameters.AddWithValue("?RESIDUO_INTERMEDIARIO", objLeitmensal.RESIDUO_INTERMEDIARIO);
                    cmd.Parameters.AddWithValue("?RESIDUO_FORA_PONTA", objLeitmensal.RESIDUO_FORA_PONTA);
                    cmd.Parameters.AddWithValue("?MEDIA", objLeitmensal.MEDIA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?INT_MICRO_GERACAO", objLeitmensal.INT_MICRO_GERACAO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?ZONA", objLeitmensal.ZONA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LIVRO", objLeitmensal.LIVRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTA", objLeitmensal.CONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?UNID_ID", objLeitmensal.UNID_ID);

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

        public void Update_3(entidadeLeitmensal objLeitmensal)
        {
            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 + "LEIT_ATUAL = ?LEIT_ATUAL ,";
                    vFILTER = vFILTER + "DT_LEIT = ?DT_LEIT ";

                    vAND = vAND + "   AND ZONA  = ?ZONA ";
                    vAND = vAND + "   AND LIVRO = ?LIVRO ";
                    vAND = vAND + "   AND CONTA = ?CONTA ";


                    cmd = new MySqlCommand(this.QueryUpdate);


                    cmd.Parameters.AddWithValue("?LEIT_ATUAL", objLeitmensal.LEIT_ATUAL.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DT_LEIT", objLeitmensal.DT_LEIT);
                    cmd.Parameters.AddWithValue("?ZONA", objLeitmensal.ZONA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LIVRO", objLeitmensal.LIVRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTA", objLeitmensal.CONTA.ToString().ToUpper());

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

        public void Update_4(entidadeLeitmensal objLeitmensal)
        {
            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 + " CONSUMO         = ?CONSUMO , ";
                    vFILTER = vFILTER + " CONSUMOFAT      = ?CONSUMOFAT , ";
                    vFILTER = vFILTER + " CONSUMOKVARH    = ?CONSUMOKVARH , ";
                    vFILTER = vFILTER + " RESIDUO         = ?RESIDUO , ";
                    vFILTER = vFILTER + " KVARH           = ?KVARH , ";
                    vFILTER = vFILTER + " KVARHATUAL      = ?KVARHATUAL , ";
                    //Micro geração
                    vFILTER = vFILTER + " KWH_REVERSO     = ?KWH_REVERSO , ";
                    vFILTER = vFILTER + " KWH_REVERSO_FAT = ?KWH_REVERSO_FAT , ";
                    vFILTER = vFILTER + " KWH_REVERSO_RES =  ?KWH_REVERSO_RES , ";
                    vFILTER = vFILTER + " KWH_REVERSO_MES_ANT = ?KWH_REVERSO_MES_ANT, ";
                    vFILTER = vFILTER + " KWH_RECEBIDO_FORA_PONTA = ?KWH_RECEBIDO_FORA_PONTA , ";
                    //Irrigante
                    vFILTER = vFILTER + " KWH_IRRIGANTE     = ?KWH_IRRIGANTE , ";
                    vFILTER = vFILTER + " KWH_IRRIGANTE_FAT = ?KWH_IRRIGANTE_FAT , ";
                    vFILTER = vFILTER + " KWH_IRRIGANTE_RES = ?KWH_IRRIGANTE_RES , ";
                    //Tarifa Branca
                    vFILTER = vFILTER + " KWH_PONTA         =  ?KWH_PONTA , ";
                    vFILTER = vFILTER + " KWH_INTERMEDIARIO =  ?KWH_INTERMEDIARIO , ";
                    vFILTER = vFILTER + " KWH_FORA_PONTA    =  ?KWH_FORA_PONTA , ";
                    //
                    vFILTER = vFILTER + "CUSTO_CONEXAO   = ?CUSTO_CONEXAO , ";
                    //

                    if (objLeitmensal.CONST != 0)
                    {
                        vFILTER = vFILTER + " CONST           = ?CONST , ";
                    }
                    if (objLeitmensal.CONSTFP != 0)
                    {
                        vFILTER = vFILTER + " CONSTFP         = ?CONSTFP , ";
                    }
                    if (objLeitmensal.CONSTI != 0)
                    {
                        vFILTER = vFILTER + " CONSTI          = ?CONSTI , ";
                    }

                    vFILTER = vFILTER + " CLASSE          = ?CLASSE ,";
                    vFILTER = vFILTER + " DIAVENC         = ?DIAVENC ,";
                    vFILTER = vFILTER + " TA              = ?TA ,";
                    vFILTER = vFILTER + " CPOF            = ?CPOF ,";
                    vFILTER = vFILTER + " DT_APREST       = ?DT_APREST ,";
                    vFILTER = vFILTER + " DT_FATURAMENTO  = ?DT_FATURAMENTO ,";
                    vFILTER = vFILTER + " DT_LEITANT      = ?DT_LEITANT ,";
                    vFILTER = vFILTER + " DT_VCTO         = ?DT_VCTO ,";
                    vFILTER = vFILTER + " DT_PROXIMA_LEIT = ?DT_PROXIMA_LEIT ,";
                    vFILTER = vFILTER + " DT_VECTOPP      = ?DT_VECTOPP ,";
                    //vFILTER = vFILTER + " CONSUMORESERV  = ?CONSUMORESERV ,";
                    vFILTER = vFILTER + " FP              = ?FP ,";
                    vFILTER = vFILTER + " TENSAO          = ?TENSAO ,";
                   // vFILTER = vFILTER + " CPFCNPJ         = ?CPFCNPJ ,";
                    vFILTER = vFILTER + " RGIE            = ?RGIE ,";
                    vFILTER = vFILTER + " INSC            = ?INSC ,";
                    vFILTER = vFILTER + " BANCO           = ?BANCO ,";
                    vFILTER = vFILTER + " AGENCIA         = ?AGENCIA ,";
                    vFILTER = vFILTER + " CONTACORRENTE   = ?CONTACORRENTE ,";
                    vFILTER = vFILTER + " FASE            = ?FASE ,";
                    vFILTER = vFILTER + " BANARREC        = ?BANARREC ,";
                    vFILTER = vFILTER + " CONS_ID         = ?CONS_ID ";

                    vAND = vAND + "   AND ZONA  = ?ZONA ";
                    vAND = vAND + "   AND LIVRO = ?LIVRO ";
                    vAND = vAND + "   AND CONTA = ?CONTA ";


                    cmd = new MySqlCommand(this.QueryUpdate);


                    cmd.Parameters.AddWithValue("?CONSUMO", objLeitmensal.CONSUMO);
                    cmd.Parameters.AddWithValue("?CONSUMOFAT", objLeitmensal.CONSUMOFAT);
                    cmd.Parameters.AddWithValue("?CONSUMOKVARH", objLeitmensal.CONSUMOKVARH);
                    cmd.Parameters.AddWithValue("?RESIDUO", objLeitmensal.RESIDUO);
                    cmd.Parameters.AddWithValue("?KVARH", objLeitmensal.KVARH);
                    cmd.Parameters.AddWithValue("?KVARHATUAL", objLeitmensal.KVARHATUAL);
                    //Micro geração
                    cmd.Parameters.AddWithValue("?KWH_REVERSO", objLeitmensal.KWH_REVERSO);
                    cmd.Parameters.AddWithValue("?KWH_REVERSO_FAT", objLeitmensal.KWH_REVERSO_FAT);
                    cmd.Parameters.AddWithValue("?KWH_REVERSO_RES", objLeitmensal.KWH_REVERSO_RES);
                    cmd.Parameters.AddWithValue("?KWH_REVERSO_MES_ANT", objLeitmensal.KWH_REVERSO_MES_ANT);
                    cmd.Parameters.AddWithValue("?KWH_RECEBIDO_FORA_PONTA", objLeitmensal.KWH_RECEBIDO_FORA_PONTA);
                    //Irrigante
                    cmd.Parameters.AddWithValue("?KWH_IRRIGANTE", objLeitmensal.KWH_IRRIGANTE);
                    cmd.Parameters.AddWithValue("?KWH_IRRIGANTE_FAT", objLeitmensal.KWH_IRRIGANTE_FAT);
                    cmd.Parameters.AddWithValue("?KWH_IRRIGANTE_RES", objLeitmensal.KWH_IRRIGANTE_RES);
                    //Tarifa Branca
                    cmd.Parameters.AddWithValue("?KWH_PONTA", objLeitmensal.KWH_PONTA);
                    cmd.Parameters.AddWithValue("?KWH_INTERMEDIARIO", objLeitmensal.KWH_INTERMEDIARIO);
                    cmd.Parameters.AddWithValue("?KWH_FORA_PONTA", objLeitmensal.KWH_FORA_PONTA);
                    //
                    cmd.Parameters.AddWithValue("?CUSTO_CONEXAO", objLeitmensal.CUSTO_CONEXAO);
                    //

                    if (objLeitmensal.CONST != 0)
                    {
                        cmd.Parameters.AddWithValue("?CONST", objLeitmensal.CONST);
                    }
                    if (objLeitmensal.CONSTFP != 0)
                    {
                        cmd.Parameters.AddWithValue("?CONSTFP", objLeitmensal.CONSTFP);
                    }
                    if (objLeitmensal.CONSTI != 0)
                    {
                        cmd.Parameters.AddWithValue("?CONSTI", objLeitmensal.CONSTI);
                    }

                    cmd.Parameters.AddWithValue("?CLASSE", objLeitmensal.CLASSE.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DIAVENC", objLeitmensal.DIAVENC.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?TA", objLeitmensal.TA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CPOF", objLeitmensal.CPOF.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DT_APREST", objLeitmensal.DT_APREST);
                    cmd.Parameters.AddWithValue("?DT_FATURAMENTO", objLeitmensal.DT_FATURAMENTO);
                    cmd.Parameters.AddWithValue("?DT_LEITANT", objLeitmensal.DT_LEITANT);
                    cmd.Parameters.AddWithValue("?DT_VCTO", objLeitmensal.DT_VCTO);
                    cmd.Parameters.AddWithValue("?DT_PROXIMA_LEIT", objLeitmensal.DT_PROXIMA_LEIT);
                    cmd.Parameters.AddWithValue("?DT_VECTOPP", objLeitmensal.DT_VECTOPP);
                    //cmd.Parameters.AddWithValue("?CONSUMORESERV", objLeitmensal.CONSUMORESERV.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?FP", objLeitmensal.FP);
                    cmd.Parameters.AddWithValue("?TENSAO", objLeitmensal.TENSAO.ToString().ToUpper());
                    //cmd.Parameters.AddWithValue("?CPFCNPJ", objLeitmensal.CPFCNPJ.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?RGIE", objLeitmensal.RGIE.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?INSC", objLeitmensal.INSC.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?BANCO", objLeitmensal.BANCO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?AGENCIA", objLeitmensal.AGENCIA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTACORRENTE", objLeitmensal.CONTACORRENTE.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?FASE", objLeitmensal.FASE.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?BANARREC", objLeitmensal.BANARREC);
                    cmd.Parameters.AddWithValue("?CONS_ID", objLeitmensal.CONS_ID);
                    cmd.Parameters.AddWithValue("?ZONA", objLeitmensal.ZONA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LIVRO", objLeitmensal.LIVRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTA", objLeitmensal.CONTA.ToString().ToUpper());

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

        public void Update_5(entidadeLeitmensal objLeitmensal)
        {
            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 + " CONSUMO           = NULL , ";
                    vFILTER = vFILTER + " CONSUMOFAT        = NULL , ";
                    vFILTER = vFILTER + " CONSUMOKVARH      = NULL , ";
                    vFILTER = vFILTER + " CONSUMORESERV     = NULL , ";
                    vFILTER = vFILTER + " KWH_REVERSO 	    = NULL , ";
                    vFILTER = vFILTER + " KWH_REVERSO_FAT   = NULL , ";
                    vFILTER = vFILTER + " KWH_REVERSO_RES   = NULL , ";
                    vFILTER = vFILTER + " KWH_IRRIGANTE 	= NULL , ";
                    vFILTER = vFILTER + " KWH_IRRIGANTE_FAT = NULL , ";
                    vFILTER = vFILTER + " KWH_IRRIGANTE_RES = NULL , ";
                    vFILTER = vFILTER + " LEIT_ATUAL      = ?LEIT_ATUAL , ";
                    vFILTER = vFILTER + " DIAVENC         = ?DIAVENC , ";
                    vFILTER = vFILTER + " DT_APREST       = ?DT_APREST , ";
                    vFILTER = vFILTER + " DT_FATURAMENTO  = ?DT_FATURAMENTO , ";
                    vFILTER = vFILTER + " DT_LEITANT      = ?DT_LEITANT , ";
                    vFILTER = vFILTER + " DT_VCTO         = ?DT_VCTO , ";
                    vFILTER = vFILTER + " DT_PROXIMA_LEIT = ?DT_PROXIMA_LEIT , ";
                    vFILTER = vFILTER + " DT_VECTOPP      = ?DT_VECTOPP ";

                    vAND = vAND + "   AND ZONA  = ?ZONA ";
                    vAND = vAND + "   AND LIVRO = ?LIVRO ";
                    vAND = vAND + "   AND CONTA = ?CONTA ";


                    cmd = new MySqlCommand(this.QueryUpdate);


                    cmd.Parameters.AddWithValue("?LEIT_ATUAL", objLeitmensal.LEIT_ATUAL.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DIAVENC", objLeitmensal.DIAVENC.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DT_APREST", objLeitmensal.DT_APREST);
                    cmd.Parameters.AddWithValue("?DT_FATURAMENTO", objLeitmensal.DT_FATURAMENTO);
                    cmd.Parameters.AddWithValue("?DT_LEITANT", objLeitmensal.DT_LEITANT);
                    cmd.Parameters.AddWithValue("?DT_VCTO", objLeitmensal.DT_VCTO);
                    cmd.Parameters.AddWithValue("?DT_PROXIMA_LEIT", objLeitmensal.DT_PROXIMA_LEIT);
                    cmd.Parameters.AddWithValue("?DT_VECTOPP", objLeitmensal.DT_VECTOPP);
                    cmd.Parameters.AddWithValue("?ZONA", objLeitmensal.ZONA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LIVRO", objLeitmensal.LIVRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTA", objLeitmensal.CONTA.ToString().ToUpper());

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

        public void UpdateLeituraAtualAPP(entidadeAgenciaVirtual objAgenciaVirtual)
        {
            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 + " LEIT_ATUAL  = ?LEIT_ATUAL,  ";
                    vFILTER = vFILTER + " DT_LEIT     = ?DT_LEIT,  ";
                    vFILTER = vFILTER + " MEDIA     = ?MEDIA,  ";
                    vFILTER = vFILTER + " OCORRENC     = ?OCORRENC  ";

                    vAND = vAND + "   AND unid_id  = ?UC ";

                    cmd = new MySqlCommand(this.QueryUpdate);

                    cmd.Parameters.AddWithValue("?LEIT_ATUAL", objAgenciaVirtual.CanalLeituraAtual.ToString());
                    cmd.Parameters.AddWithValue("?DT_LEIT", objAgenciaVirtual.Atualizacao);
                    cmd.Parameters.AddWithValue("?MEDIA", objAgenciaVirtual.TipoOcorrenciaId.ToString());
                    cmd.Parameters.AddWithValue("?OCORRENC", objAgenciaVirtual.TipoOcorrenciaId.ToString());

                    cmd.Parameters.AddWithValue("?UC", objAgenciaVirtual.UC);


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

        public void Update_7(entidadeLeitmensal objLeitmensal)
        {
            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 + "LEIT_ANT = ?LEIT_ANT ,";
                    vFILTER = vFILTER + "LEIT_ATUAL = ?LEIT_ATUAL ,";
                    vFILTER = vFILTER + "DT_LEIT = ?DT_LEIT , ";
                    vFILTER = vFILTER + "DT_APREST = ?DT_APREST , ";
                    vFILTER = vFILTER + "DT_FATURAMENTO = ?DT_FATURAMENTO , ";
                    vFILTER = vFILTER + "DT_LEITANT = ?DT_LEITANT , ";
                    vFILTER = vFILTER + "DT_VCTO = ?DT_VCTO , ";
                    vFILTER = vFILTER + "DT_PROXIMA_LEIT = ?DT_PROXIMA_LEIT , ";
                    vFILTER = vFILTER + "DT_VECTOPP = ?DT_VECTOPP  ";

                    vAND = vAND + "   AND ZONA  = ?ZONA ";
                    vAND = vAND + "   AND LIVRO = ?LIVRO ";
                    vAND = vAND + "   AND CONTA = ?CONTA ";


                    cmd = new MySqlCommand(this.QueryUpdate);


                    cmd.Parameters.AddWithValue("?LEIT_ANT", objLeitmensal.LEIT_ANT.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LEIT_ATUAL", objLeitmensal.LEIT_ATUAL.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DT_LEIT", objLeitmensal.DT_LEIT);
                    cmd.Parameters.AddWithValue("?DT_APREST", objLeitmensal.DT_APREST);
                    cmd.Parameters.AddWithValue("?DT_FATURAMENTO", objLeitmensal.DT_FATURAMENTO);
                    cmd.Parameters.AddWithValue("?DT_LEITANT", objLeitmensal.DT_LEITANT);
                    cmd.Parameters.AddWithValue("?DT_VCTO", objLeitmensal.DT_VCTO);
                    cmd.Parameters.AddWithValue("?DT_PROXIMA_LEIT", objLeitmensal.DT_PROXIMA_LEIT);
                    cmd.Parameters.AddWithValue("?DT_VECTOPP", objLeitmensal.DT_VECTOPP);
                    cmd.Parameters.AddWithValue("?ZONA", objLeitmensal.ZONA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LIVRO", objLeitmensal.LIVRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTA", objLeitmensal.CONTA.ToString().ToUpper());

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

        public DataTable Select(entidadeLeitmensal objLeitmensal)
        {
            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 + "       LEIT_ATUAL, ";
                    vFILTER = vFILTER + "       LEITURA_ATUAL_PONTA, ";
                    vFILTER = vFILTER + "       LEITURA_ATUAL_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "       LEITURA_ATUAL_FORA_PONTA, ";
                    vFILTER = vFILTER + "       LEIT_REVERSO_ATUAL, ";
                    vFILTER = vFILTER + "       LEIT_IRRIGANTE_ATUAL, ";
                    vFILTER = vFILTER + "       CONSUMO, ";
                    vFILTER = vFILTER + "       OCORRENC, ";
                    vFILTER = vFILTER + "       MEDIA, ";
                    vFILTER = vFILTER + "       KVARHATUAL, ";
                    vFILTER = vFILTER + "       KVARH, ";
                    vFILTER = vFILTER + "       KWH_PONTA, ";
                    vFILTER = vFILTER + "       KWH_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "       KWH_FORA_PONTA ";

                    vINNERJOIN = " ";

                    vORDERBY = " ";

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


                    cmd = new MySqlCommand(this.QuerySelect);

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


                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

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

        public DataTable Select_1(entidadeLeitmensal objLeitmensal)
        {
            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 + "       leitmensal.UNID_ID, ";
                    vFILTER = vFILTER + "       leitmensal.ZONA, ";
                    vFILTER = vFILTER + "       leitmensal.LIVRO, ";
                    vFILTER = vFILTER + "       leitmensal.CONTA, ";
                    vFILTER = vFILTER + "       LEIT_ANT, ";
                    vFILTER = vFILTER + "       LEIT_ATUAL, ";
                    vFILTER = vFILTER + "       KVARH, ";
                    vFILTER = vFILTER + "       KVARHATUAL, ";
                    vFILTER = vFILTER + "       OCORRENC, ";
                    vFILTER = vFILTER + "       MEDIA, ";
                    vFILTER = vFILTER + "       RESIDUO, ";
                    vFILTER = vFILTER + "       CONSUMO, ";
                    vFILTER = vFILTER + "       LEIT_REVERSO_ANT, ";
                    vFILTER = vFILTER + "       LEIT_REVERSO_ATUAL, ";
                    vFILTER = vFILTER + "       KWH_REVERSO, ";
                    vFILTER = vFILTER + "       KWH_REVERSO_RES, ";
                    vFILTER = vFILTER + "       LEIT_IRRIGANTE_ANT, ";
                    vFILTER = vFILTER + "       LEIT_IRRIGANTE_ATUAL, ";
                    vFILTER = vFILTER + "       KWH_IRRIGANTE, ";
                    vFILTER = vFILTER + "       KWH_IRRIGANTE_RES, ";
                    vFILTER = vFILTER + "       LEITURA_ANT_PONTA, ";
                    vFILTER = vFILTER + "       LEITURA_ATUAL_PONTA, ";
                    vFILTER = vFILTER + "       LEITURA_ANT_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "       LEITURA_ATUAL_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "       LEITURA_ANT_FORA_PONTA, ";
                    vFILTER = vFILTER + "       LEITURA_ATUAL_FORA_PONTA, ";
                    vFILTER = vFILTER + "       KWH_PONTA, ";
                    vFILTER = vFILTER + "       KWH_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "       KWH_FORA_PONTA, ";
                    vFILTER = vFILTER + "       RESIDUO_PONTA, ";
                    vFILTER = vFILTER + "       RESIDUO_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "       RESIDUO_FORA_PONTA, ";
                    vFILTER = vFILTER + "       VERIFICADO, ";
                    vFILTER = vFILTER + "       MEDIA_CRITICA, ";
                    vFILTER = vFILTER + "       MEDIDOR, ";
                    vFILTER = vFILTER + "       MEDKVARH, ";
                    vFILTER = vFILTER + "       DT_LEIT, ";
                    vFILTER = vFILTER + "       DT_LEITANT, ";
                    vFILTER = vFILTER + "       INT_MICRO_GERACAO, "; 
                    vFILTER = vFILTER + "       COUNT(DISTINCT ft.id) AS FOTO_EVIDENCIA ";

                    vINNERJOIN = " LEFT JOIN leitura_mensal_foto_evidencia ft ON ft.unid_id = leitmensal.unid_id";                    

                    vAND = vAND + " AND leitmensal.UNID_ID = ?UNID_ID ";
                    vAND = vAND + " AND leitmensal.ZONA = ?ZONA ";
                    vAND = vAND + " AND leitmensal.LIVRO = ?LIVRO ";
                    vAND = vAND + " AND leitmensal.CONTA = ?CONTA ";
                    vAND = vAND + " AND DATE_FORMAT(DT_LEIT, '%Y-%m') = DATE_FORMAT(?DT_LEIT, '%Y-%m') ";
                    
                    vORDERBY = " GROUP BY leitmensal.unid_id";

                    cmd = new MySqlCommand(this.QuerySelect);

                    cmd.Parameters.AddWithValue("?UNID_ID", objLeitmensal.UNID_ID);
                    cmd.Parameters.AddWithValue("?ZONA", objLeitmensal.ZONA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LIVRO", objLeitmensal.LIVRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTA", objLeitmensal.CONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DT_LEIT", objLeitmensal.DT_LEIT);

                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

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

        public DataTable Select_2(entidadeLeitmensal objLeitmensal)
        {
            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 + "       LEIT_ATUAL, ";
                    vFILTER = vFILTER + "       LEIT_AJUST ";


                    vINNERJOIN = " ";

                    vORDERBY = " ";


                    vAND = vAND + "   AND ZONA = ?ZONA ";
                    vAND = vAND + "   AND LIVRO = ?LIVRO ";
                    vAND = vAND + "   AND CONTA = ?CONTA ";


                    cmd = new MySqlCommand(this.QuerySelect);


                    cmd.Parameters.AddWithValue("?ZONA", objLeitmensal.ZONA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LIVRO", objLeitmensal.LIVRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTA", objLeitmensal.CONTA.ToString().ToUpper());


                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

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

        public DataTable Select_3(entidadeLeitmensal objLeitmensal)
        {
            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 + "       RESIDUO ";


                    vINNERJOIN = " ";

                    vORDERBY = " ";


                    vAND = vAND + "   AND ZONA = ?ZONA ";
                    vAND = vAND + "   AND LIVRO = ?LIVRO ";
                    vAND = vAND + "   AND CONTA = ?CONTA ";


                    cmd = new MySqlCommand(this.QuerySelect);


                    cmd.Parameters.AddWithValue("?ZONA", objLeitmensal.ZONA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LIVRO", objLeitmensal.LIVRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTA", objLeitmensal.CONTA.ToString().ToUpper());


                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

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

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


            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

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


                    vFILTER = vFILTER + "       DISTINCT cast(LEFT(ROTA,4) as decimal)  ROTA ";

                    vINNERJOIN = " ";

                    vORDERBY = "ORDER BY ROTA ASC ";

                    vAND = vAND + "   AND `rota` IS NOT NULL  ";

                    cmd = new MySqlCommand(this.QuerySelect);

                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

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

        public DataTable Select_5(entidadeLeitmensal objLeitmensal)
        {
            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 + "STATUS, ";
                    vFILTER = vFILTER + "ROTA, ";
                    vFILTER = vFILTER + "SEQ, ";
                    vFILTER = vFILTER + "ZONA, ";
                    vFILTER = vFILTER + "LIVRO, ";
                    vFILTER = vFILTER + "CONTA, ";
                    vFILTER = vFILTER + "LEIT_ANT, ";
                    vFILTER = vFILTER + "LEIT_ATUAL, ";
                    vFILTER = vFILTER + "MEDIDOR, ";
                    vFILTER = vFILTER + "ENDERECO, ";
                    vFILTER = vFILTER + "NOME, ";
                    vFILTER = vFILTER + "MUNICIP, ";
                    vFILTER = vFILTER + "MEDIA, ";
                    vFILTER = vFILTER + "OCORRENC, ";
                    vFILTER = vFILTER + "MEDKVARH, ";
                    vFILTER = vFILTER + "KVARH, ";
                    vFILTER = vFILTER + "KVARHATUAL, ";
                    vFILTER = vFILTER + "DT_LEIT, ";
                    vFILTER = vFILTER + "CONS_ID, ";
                    vFILTER = vFILTER + "UNID_ID, ";
                    vFILTER = vFILTER + "CONSUMO, ";
                    vFILTER = vFILTER + "CONSUMOFAT, ";
                    vFILTER = vFILTER + "CONSUMOKVARH, ";
                    vFILTER = vFILTER + "DT_APREST, ";
                    vFILTER = vFILTER + "DT_FATURAMENTO, ";
                    vFILTER = vFILTER + "DT_LEITANT, ";
                    vFILTER = vFILTER + "DT_VCTO, ";
                    vFILTER = vFILTER + "DT_PROXIMA_LEIT, ";
                    vFILTER = vFILTER + "DT_VECTOPP, ";
                    vFILTER = vFILTER + "TA, ";
                    vFILTER = vFILTER + "ARREDONDA, ";
                    vFILTER = vFILTER + "CONST, ";
                    vFILTER = vFILTER + "CONSTFP, ";
                    vFILTER = vFILTER + "CLASSE, ";
                    vFILTER = vFILTER + "DIAVENC, ";
                    vFILTER = vFILTER + "SIT, ";
                    vFILTER = vFILTER + "CPOF, ";
                    vFILTER = vFILTER + "FP, ";
                    vFILTER = vFILTER + "TENSAO, ";
                    vFILTER = vFILTER + "CPFCNPJ, ";
                    vFILTER = vFILTER + "RGIE, ";
                    vFILTER = vFILTER + "INSC, ";
                    vFILTER = vFILTER + "BANCO, ";
                    vFILTER = vFILTER + "AGENCIA, ";
                    vFILTER = vFILTER + "CONTACORRENTE, ";
                    vFILTER = vFILTER + "FASE, ";
                    vFILTER = vFILTER + "BANARREC, ";
                    vFILTER = vFILTER + "RESIDUO, ";
                    vFILTER = vFILTER + "LEIT_AJUST, ";
                    vFILTER = vFILTER + "LEIT_REVERSO_ANT, ";
                    vFILTER = vFILTER + "LEIT_REVERSO_ATUAL, ";
                    vFILTER = vFILTER + "LEIT_IRRIGANTE_ANT, ";
                    vFILTER = vFILTER + "LEIT_IRRIGANTE_ATUAL, ";
                    vFILTER = vFILTER + "KWH_IRRIGANTE, ";
                    vFILTER = vFILTER + "KWH_IRRIGANTE_FAT, ";
                    vFILTER = vFILTER + "KWH_REVERSO, ";
                    vFILTER = vFILTER + "KWH_REVERSO_FAT, ";
                    vFILTER = vFILTER + "KWH_REVERSO_RES, ";
                    vFILTER = vFILTER + "KWH_REVERSO_MES_ANT, ";
                    vFILTER = vFILTER + "KWH_IRRIGANTE_RES, ";
                    vFILTER = vFILTER + "LEITURA_ANT_PONTA, ";
                    vFILTER = vFILTER + "LEITURA_ATUAL_PONTA, ";
                    vFILTER = vFILTER + "LEITURA_ANT_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "LEITURA_ATUAL_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "LEITURA_ANT_FORA_PONTA, ";
                    vFILTER = vFILTER + "LEITURA_ATUAL_FORA_PONTA, ";
                    vFILTER = vFILTER + "KWH_PONTA, ";
                    vFILTER = vFILTER + "KWH_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "KWH_FORA_PONTA, ";
                    vFILTER = vFILTER + "RESIDUO_PONTA, ";
                    vFILTER = vFILTER + "RESIDUO_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "RESIDUO_FORA_PONTA, ";
                    vFILTER = vFILTER + "ULT_LEIT_CORTE, ";
                    vFILTER = vFILTER + "CONSTI, ";
                    vFILTER = vFILTER + "CUSTO_CONEXAO, ";
                    vFILTER = vFILTER + "KWH_RECEBIDO_PONTA, ";
                    vFILTER = vFILTER + "KWH_RECEBIDO_INTERMEDIARIA, ";
                    vFILTER = vFILTER + "KWH_RECEBIDO_FORA_PONTA ";


                    vINNERJOIN = " ";

                    vORDERBY = " ";

                    vAND = " ";

                    cmd = new MySqlCommand(this.QuerySelect);

                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

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

        public DataTable Select_6(entidadeLeitmensal objLeitmensal)
        {
            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 + "STATUS, ";
                    vFILTER = vFILTER + "ROTA, ";
                    vFILTER = vFILTER + "SEQ, ";
                    vFILTER = vFILTER + "ZONA, ";
                    vFILTER = vFILTER + "LIVRO, ";
                    vFILTER = vFILTER + "CONTA, ";
                    vFILTER = vFILTER + "LEIT_ANT, ";
                    vFILTER = vFILTER + "LEIT_ATUAL, ";
                    vFILTER = vFILTER + "MEDIDOR, ";
                    vFILTER = vFILTER + "ENDERECO, ";
                    vFILTER = vFILTER + "NOME, ";
                    vFILTER = vFILTER + "MUNICIP, ";
                    vFILTER = vFILTER + "MEDIA, ";
                    vFILTER = vFILTER + "OCORRENC, ";
                    vFILTER = vFILTER + "MEDKVARH, ";
                    vFILTER = vFILTER + "KVARH, ";
                    vFILTER = vFILTER + "KVARHATUAL, ";
                    vFILTER = vFILTER + "DT_LEIT, ";
                    vFILTER = vFILTER + "CONS_ID, ";
                    vFILTER = vFILTER + "UNID_ID, ";
                    vFILTER = vFILTER + "CONSUMO, ";
                    vFILTER = vFILTER + "CONSUMOFAT, ";
                    vFILTER = vFILTER + "CONSUMOKVARH, ";
                    vFILTER = vFILTER + "DT_APREST, ";
                    vFILTER = vFILTER + "DT_FATURAMENTO, ";
                    vFILTER = vFILTER + "DT_LEITANT, ";
                    vFILTER = vFILTER + "DT_VCTO, ";
                    vFILTER = vFILTER + "DT_PROXIMA_LEIT, ";
                    vFILTER = vFILTER + "DT_VECTOPP, ";
                    vFILTER = vFILTER + "TA, ";
                    vFILTER = vFILTER + "ARREDONDA, ";
                    vFILTER = vFILTER + "CONST, ";
                    vFILTER = vFILTER + "CONSTFP, ";
                    vFILTER = vFILTER + "CLASSE, ";
                    vFILTER = vFILTER + "DIAVENC, ";
                    vFILTER = vFILTER + "SIT, ";
                    vFILTER = vFILTER + "CPOF, ";
                    vFILTER = vFILTER + "FP, ";
                    vFILTER = vFILTER + "TENSAO, ";
                    vFILTER = vFILTER + "CPFCNPJ, ";
                    vFILTER = vFILTER + "RGIE, ";
                    vFILTER = vFILTER + "INSC, ";
                    vFILTER = vFILTER + "BANCO, ";
                    vFILTER = vFILTER + "AGENCIA, ";
                    vFILTER = vFILTER + "CONTACORRENTE, ";
                    vFILTER = vFILTER + "FASE, ";
                    vFILTER = vFILTER + "BANARREC, ";
                    vFILTER = vFILTER + "RESIDUO, ";
                    vFILTER = vFILTER + "LEIT_AJUST, ";
                    vFILTER = vFILTER + "LEIT_REVERSO_ANT, ";
                    vFILTER = vFILTER + "LEIT_REVERSO_ATUAL, ";
                    vFILTER = vFILTER + "LEIT_IRRIGANTE_ANT, ";
                    vFILTER = vFILTER + "LEIT_IRRIGANTE_ATUAL, ";
                    vFILTER = vFILTER + "KWH_IRRIGANTE, ";
                    vFILTER = vFILTER + "KWH_IRRIGANTE_FAT, ";
                    vFILTER = vFILTER + "KWH_REVERSO, ";
                    vFILTER = vFILTER + "KWH_REVERSO_FAT, ";
                    vFILTER = vFILTER + "KWH_REVERSO_RES, ";
                    vFILTER = vFILTER + "KWH_REVERSO_MES_ANT, ";
                    vFILTER = vFILTER + "KWH_IRRIGANTE_RES, ";
                    vFILTER = vFILTER + "LEITURA_ANT_PONTA, ";
                    vFILTER = vFILTER + "LEITURA_ATUAL_PONTA, ";
                    vFILTER = vFILTER + "LEITURA_ANT_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "LEITURA_ATUAL_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "LEITURA_ANT_FORA_PONTA, ";
                    vFILTER = vFILTER + "LEITURA_ATUAL_FORA_PONTA, ";
                    vFILTER = vFILTER + "KWH_PONTA, ";
                    vFILTER = vFILTER + "KWH_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "KWH_FORA_PONTA, ";
                    vFILTER = vFILTER + "RESIDUO_PONTA, ";
                    vFILTER = vFILTER + "RESIDUO_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "RESIDUO_FORA_PONTA, ";
                    vFILTER = vFILTER + "ULT_LEIT_CORTE, ";
                    vFILTER = vFILTER + "CONSTI, ";
                    vFILTER = vFILTER + "CUSTO_CONEXAO, ";
                    vFILTER = vFILTER + "KWH_RECEBIDO_PONTA, ";
                    vFILTER = vFILTER + "KWH_RECEBIDO_INTERMEDIARIA, ";
                    vFILTER = vFILTER + "KWH_RECEBIDO_FORA_PONTA ";


                    vINNERJOIN = " ";

                    vORDERBY = " ";

                    vAND = vAND + "   AND ZONA = ?ZONA ";
                    vAND = vAND + "   AND LIVRO = ?LIVRO ";
                    vAND = vAND + "   AND CONTA = ?CONTA ";


                    cmd = new MySqlCommand(this.QuerySelect);


                    cmd.Parameters.AddWithValue("?ZONA", objLeitmensal.ZONA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LIVRO", objLeitmensal.LIVRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTA", objLeitmensal.CONTA.ToString().ToUpper());


                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

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

        public DataTable Select_7(entidadeLeitmensal objLeitmensal)
        {
            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 + "`leitmensal`.STATUS, ";
                    vFILTER = vFILTER + "`leitmensal`.ROTA, ";
                    vFILTER = vFILTER + "`leitmensal`.SEQ, ";
                    vFILTER = vFILTER + "`leitmensal`.ZONA, ";
                    vFILTER = vFILTER + "`leitmensal`.LIVRO, ";
                    vFILTER = vFILTER + "`leitmensal`.CONTA, ";
                    vFILTER = vFILTER + "`leitmensal`.LEIT_ANT, ";
                    vFILTER = vFILTER + "`leitmensal`.LEIT_ATUAL, ";
                    vFILTER = vFILTER + "`leitmensal`.MEDIDOR, ";
                    vFILTER = vFILTER + "`leitmensal`.ENDERECO, ";
                    vFILTER = vFILTER + "`leitmensal`.NOME, ";
                    vFILTER = vFILTER + "`leitmensal`.MUNICIP, ";
                    vFILTER = vFILTER + "`leitmensal`.MEDIA, ";
                    vFILTER = vFILTER + "`leitmensal`.OCORRENC, ";
                    vFILTER = vFILTER + "`leitmensal`.MEDKVARH, ";
                    vFILTER = vFILTER + "`leitmensal`.KVARH, ";
                    vFILTER = vFILTER + "`leitmensal`.KVARHATUAL, ";
                    vFILTER = vFILTER + "`leitmensal`.DT_LEIT, ";
                    vFILTER = vFILTER + "`leitmensal`.CONS_ID, ";
                    vFILTER = vFILTER + "`leitmensal`.UNID_ID, ";
                    vFILTER = vFILTER + "`leitmensal`.CONSUMO, ";
                    vFILTER = vFILTER + "`leitmensal`.CONSUMOFAT, ";
                    vFILTER = vFILTER + "`leitmensal`.CONSUMOKVARH, ";
                    vFILTER = vFILTER + "`leitmensal`.DT_APREST, ";
                    vFILTER = vFILTER + "`leitmensal`.DT_FATURAMENTO, ";
                    vFILTER = vFILTER + "`leitmensal`.DT_LEITANT, ";
                    vFILTER = vFILTER + "`leitmensal`.DT_VCTO, ";
                    vFILTER = vFILTER + "`leitmensal`.DT_PROXIMA_LEIT, ";
                    vFILTER = vFILTER + "`leitmensal`.DT_VECTOPP, ";
                    vFILTER = vFILTER + "`leitmensal`.TA, ";
                    vFILTER = vFILTER + "`leitmensal`.ARREDONDA, ";
                    vFILTER = vFILTER + "`leitmensal`.CONST, ";
                    vFILTER = vFILTER + "`leitmensal`.CONSTFP, ";
                    vFILTER = vFILTER + "`leitmensal`.CLASSE, ";
                    vFILTER = vFILTER + "`leitmensal`.DIAVENC, ";
                    vFILTER = vFILTER + "`leitmensal`.SIT, ";
                    vFILTER = vFILTER + "`leitmensal`.CPOF, ";
                    vFILTER = vFILTER + "`leitmensal`.FP, ";
                    vFILTER = vFILTER + "`leitmensal`.TENSAO, ";
                    vFILTER = vFILTER + "`leitmensal`.CPFCNPJ, ";
                    vFILTER = vFILTER + "`leitmensal`.RGIE, ";
                    vFILTER = vFILTER + "`leitmensal`.INSC, ";
                    vFILTER = vFILTER + "`leitmensal`.BANCO, ";
                    vFILTER = vFILTER + "`leitmensal`.AGENCIA, ";
                    vFILTER = vFILTER + "`leitmensal`.CONTACORRENTE, ";
                    vFILTER = vFILTER + "`leitmensal`.FASE, ";
                    vFILTER = vFILTER + "`leitmensal`.BANARREC, ";
                    vFILTER = vFILTER + "`leitmensal`.RESIDUO, ";
                    vFILTER = vFILTER + "`leitmensal`.LEIT_AJUST, ";
                    vFILTER = vFILTER + "`leitmensal`.LEIT_REVERSO_ANT, ";
                    vFILTER = vFILTER + "`leitmensal`.LEIT_REVERSO_ATUAL, ";
                    vFILTER = vFILTER + "`leitmensal`.LEIT_IRRIGANTE_ANT, ";
                    vFILTER = vFILTER + "`leitmensal`.LEIT_IRRIGANTE_ATUAL, ";
                    vFILTER = vFILTER + "`leitmensal`.KWH_IRRIGANTE, ";
                    vFILTER = vFILTER + "`leitmensal`.KWH_IRRIGANTE_FAT, ";
                    vFILTER = vFILTER + "`leitmensal`.KWH_REVERSO, ";
                    vFILTER = vFILTER + "`leitmensal`.KWH_REVERSO_FAT, ";
                    vFILTER = vFILTER + "`leitmensal`.KWH_REVERSO_RES, ";
                    vFILTER = vFILTER + "`leitmensal`.KWH_REVERSO_MES_ANT, ";
                    vFILTER = vFILTER + "`leitmensal`.KWH_IRRIGANTE_RES, ";
                    vFILTER = vFILTER + "`leitmensal`.LEITURA_ANT_PONTA, ";
                    vFILTER = vFILTER + "`leitmensal`.LEITURA_ATUAL_PONTA, ";
                    vFILTER = vFILTER + "`leitmensal`.LEITURA_ANT_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "`leitmensal`.LEITURA_ATUAL_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "`leitmensal`.LEITURA_ANT_FORA_PONTA, ";
                    vFILTER = vFILTER + "`leitmensal`.LEITURA_ATUAL_FORA_PONTA, ";
                    vFILTER = vFILTER + "`leitmensal`.KWH_PONTA, ";
                    vFILTER = vFILTER + "`leitmensal`.KWH_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "`leitmensal`.KWH_FORA_PONTA, ";
                    vFILTER = vFILTER + "`leitmensal`.RESIDUO_PONTA, ";
                    vFILTER = vFILTER + "`leitmensal`.RESIDUO_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "`leitmensal`.RESIDUO_FORA_PONTA, ";
                    vFILTER = vFILTER + "`leitmensal`.ULT_LEIT_CORTE, ";
                    vFILTER = vFILTER + "`leitmensal`.CONSTI, ";
                    vFILTER = vFILTER + "`leitmensal`.CUSTO_CONEXAO, ";
                    vFILTER = vFILTER + "`leitmensal`.KWH_RECEBIDO_PONTA, ";
                    vFILTER = vFILTER + "`leitmensal`.KWH_RECEBIDO_INTERMEDIARIA, ";
                    vFILTER = vFILTER + "`leitmensal`.KWH_RECEBIDO_FORA_PONTA, ";
                    vFILTER = vFILTER + "`leitmensal`.VERIFICADO, ";
                    vFILTER = vFILTER + "`leitmensal`.MEDIA_CRITICA, ";
                    vFILTER = vFILTER + "`leitmensal`.INT_MICRO_GERACAO ";

                    vINNERJOIN = " ";
                    //vINNERJOIN = " INNER JOIN `nftransicao` `nf` ON `nf`.`unid_id` = `leitmensal`.`unid_id`";

                    vORDERBY = " ";

                    vAND = vAND + "   AND `leitmensal`.DT_LEIT <= ?DT_LEIT ";
                    vAND = vAND + "   AND `leitmensal`.STATUS <> ?STATUS ";
                    vAND = vAND + "   AND `leitmensal`.OCORRENC <> 97 ";


                    if (objLeitmensal.ROTA_INICIAL != string.Empty && objLeitmensal.ROTA_FINAL != string.Empty)
                    {
                        vAND = vAND + "   AND(`leitmensal`.ROTA BETWEEN ?ROTA_INICIAL AND ?ROTA_FINAL) ";
                        //vAND = vAND + "   AND OCORRENC <> 97 ";
                    }

                    if (objLeitmensal.ROTA_INICIAL != string.Empty && objLeitmensal.ROTA_FINAL != string.Empty)
                    {
                        vAND = vAND + "   AND(`leitmensal`.ROTA BETWEEN ?ROTA_INICIAL AND ?ROTA_FINAL) ";
                    }

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

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

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

                    //if (objLeitmensal.INT_MICRO_GERACAO >0)
                    //{
                        vAND = vAND + "   AND INT_MICRO_GERACAO = ?INT_MICRO_GERACAO ";
                    //}

                    if (objLeitmensal.ROTA != string.Empty)
                    {
                        vAND = vAND + "    AND MID(TRIM(ROTA), 1, 4) IN ( ?ROTA ) ";
                    }                  

                    cmd = new MySqlCommand(this.QuerySelect);

                    cmd.Parameters.AddWithValue("?DT_LEIT", objLeitmensal.DT_LEIT);
                    cmd.Parameters.AddWithValue("?STATUS", objLeitmensal.STATUS);

                    if (objLeitmensal.ROTA_INICIAL != string.Empty && objLeitmensal.ROTA_FINAL != string.Empty)
                    {
                        cmd.Parameters.AddWithValue("?ROTA_INICIAL", objLeitmensal.ROTA_INICIAL.ToString().ToUpper());
                        cmd.Parameters.AddWithValue("?ROTA_FINAL", objLeitmensal.ROTA_FINAL.ToString().ToUpper());
                    }

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

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

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

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

                    //if (objLeitmensal.INT_MICRO_GERACAO >0)
                    //{
                        cmd.Parameters.AddWithValue("?INT_MICRO_GERACAO", objLeitmensal.INT_MICRO_GERACAO);
                    //}

                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

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

        public DataTable Select_8(entidadeLeitmensal objLeitmensal)
        {
            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 + "UC_FATURAMENTO.SITUACAO, ";
                    vFILTER = vFILTER + "COUNT(*) AS QTDE ";

                    vINNERJOIN = ", UC_FATURAMENTO ";

                    vORDERBY = "GROUP BY UC_FATURAMENTO.SITUACAO ";

                    vAND = vAND + "   AND LEITMENSAL.STATUS <> ?STATUS ";

                    if (objLeitmensal.ROTA_INICIAL != string.Empty && objLeitmensal.ROTA_FINAL != string.Empty)
                    {
                        vAND = vAND + "   AND(LEITMENSAL.ROTA BETWEEN ?ROTA_INICIAL AND ?ROTA_FINAL) ";
                    }

                    if (objLeitmensal.ZONA != string.Empty)
                    {
                        vAND = vAND + "   AND LEITMENSAL.ZONA = ?ZONA ";
                        vAND = vAND + "   AND LEITMENSAL.ZONA = UC_FATURAMENTO.ZONA ";
                    }
                    else
                    {
                        vAND = vAND + "   AND LEITMENSAL.ZONA = UC_FATURAMENTO.ZONA ";
                    }

                    if (objLeitmensal.LIVRO != string.Empty)
                    {
                        vAND = vAND + "   AND LEITMENSAL.LIVRO = ?LIVRO ";
                        vAND = vAND + "   AND LEITMENSAL.LIVRO = UC_FATURAMENTO.LIVRO ";
                    }
                    else
                    {
                        vAND = vAND + "   AND LEITMENSAL.LIVRO = UC_FATURAMENTO.LIVRO ";
                    }

                    if (objLeitmensal.CONTA != string.Empty)
                    {
                        vAND = vAND + "   AND LEITMENSAL.CONTA = ?CONTA ";
                        vAND = vAND + "   AND LEITMENSAL.CONTA = UC_FATURAMENTO.CONTA ";
                    }
                    else
                    {
                        vAND = vAND + "   AND LEITMENSAL.CONTA = UC_FATURAMENTO.CONTA ";
                    }

                    if (objLeitmensal.ROTA != string.Empty)
                    {
                        vAND = vAND + "    AND MID(TRIM(LEITMENSAL.ROTA), 1, 4) IN ( ?ROTA ) ";
                    }


                    cmd = new MySqlCommand(this.QuerySelect);

                    cmd.Parameters.AddWithValue("?STATUS", objLeitmensal.STATUS);

                    if (objLeitmensal.ROTA_INICIAL != string.Empty && objLeitmensal.ROTA_FINAL != string.Empty)
                    {
                        cmd.Parameters.AddWithValue("?ROTA_INICIAL", objLeitmensal.ROTA_INICIAL.ToString().ToUpper());
                        cmd.Parameters.AddWithValue("?ROTA_FINAL", objLeitmensal.ROTA_FINAL.ToString().ToUpper());
                    }

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

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

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

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

                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

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

        public DataTable Select_9(entidadeLeitmensal objLeitmensal)
        {
            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 + "STATUS, ";
                    vFILTER = vFILTER + "ROTA, ";
                    vFILTER = vFILTER + "SEQ, ";
                    vFILTER = vFILTER + "ZONA, ";
                    vFILTER = vFILTER + "LIVRO, ";
                    vFILTER = vFILTER + "CONTA, ";
                    vFILTER = vFILTER + "LEIT_ANT, ";
                    vFILTER = vFILTER + "LEIT_ATUAL, ";
                    vFILTER = vFILTER + "MEDIDOR, ";
                    vFILTER = vFILTER + "ENDERECO, ";
                    vFILTER = vFILTER + "NOME, ";
                    vFILTER = vFILTER + "MUNICIP, ";
                    vFILTER = vFILTER + "MEDIA, ";
                    vFILTER = vFILTER + "OCORRENC, ";
                    vFILTER = vFILTER + "MEDKVARH, ";
                    vFILTER = vFILTER + "KVARH, ";
                    vFILTER = vFILTER + "KVARHATUAL, ";
                    vFILTER = vFILTER + "DT_LEIT, ";
                    vFILTER = vFILTER + "CONS_ID, ";
                    vFILTER = vFILTER + "UNID_ID, ";
                    vFILTER = vFILTER + "CONSUMO, ";
                    vFILTER = vFILTER + "CONSUMOFAT, ";
                    vFILTER = vFILTER + "CONSUMOKVARH, ";
                    vFILTER = vFILTER + "DT_APREST, ";
                    vFILTER = vFILTER + "DT_FATURAMENTO, ";
                    vFILTER = vFILTER + "DT_LEITANT, ";
                    vFILTER = vFILTER + "DT_VCTO, ";
                    vFILTER = vFILTER + "DT_PROXIMA_LEIT, ";
                    vFILTER = vFILTER + "DT_VECTOPP, ";
                    vFILTER = vFILTER + "TA, ";
                    vFILTER = vFILTER + "ARREDONDA, ";
                    vFILTER = vFILTER + "CONST, ";
                    vFILTER = vFILTER + "CONSTFP, ";
                    vFILTER = vFILTER + "CLASSE, ";
                    vFILTER = vFILTER + "DIAVENC, ";
                    vFILTER = vFILTER + "SIT, ";
                    vFILTER = vFILTER + "CPOF, ";
                    vFILTER = vFILTER + "FP, ";
                    vFILTER = vFILTER + "TENSAO, ";
                    vFILTER = vFILTER + "CPFCNPJ, ";
                    vFILTER = vFILTER + "RGIE, ";
                    vFILTER = vFILTER + "INSC, ";
                    vFILTER = vFILTER + "BANCO, ";
                    vFILTER = vFILTER + "AGENCIA, ";
                    vFILTER = vFILTER + "CONTACORRENTE, ";
                    vFILTER = vFILTER + "FASE, ";
                    vFILTER = vFILTER + "BANARREC, ";
                    vFILTER = vFILTER + "RESIDUO, ";
                    vFILTER = vFILTER + "LEIT_AJUST, ";
                    vFILTER = vFILTER + "LEIT_REVERSO_ANT, ";
                    vFILTER = vFILTER + "LEIT_REVERSO_ATUAL, ";
                    vFILTER = vFILTER + "LEIT_IRRIGANTE_ANT, ";
                    vFILTER = vFILTER + "LEIT_IRRIGANTE_ATUAL, ";
                    vFILTER = vFILTER + "KWH_IRRIGANTE, ";
                    vFILTER = vFILTER + "KWH_IRRIGANTE_FAT, ";
                    vFILTER = vFILTER + "KWH_REVERSO, ";
                    vFILTER = vFILTER + "KWH_REVERSO_FAT, ";
                    vFILTER = vFILTER + "KWH_REVERSO_RES, ";
                    vFILTER = vFILTER + "KWH_REVERSO_MES_ANT, ";
                    vFILTER = vFILTER + "KWH_IRRIGANTE_RES, ";
                    vFILTER = vFILTER + "LEITURA_ANT_PONTA, ";
                    vFILTER = vFILTER + "LEITURA_ATUAL_PONTA, ";
                    vFILTER = vFILTER + "LEITURA_ANT_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "LEITURA_ATUAL_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "LEITURA_ANT_FORA_PONTA, ";
                    vFILTER = vFILTER + "LEITURA_ATUAL_FORA_PONTA, ";
                    vFILTER = vFILTER + "KWH_PONTA, ";
                    vFILTER = vFILTER + "KWH_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "KWH_FORA_PONTA, ";
                    vFILTER = vFILTER + "RESIDUO_PONTA, ";
                    vFILTER = vFILTER + "RESIDUO_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "RESIDUO_FORA_PONTA, ";
                    vFILTER = vFILTER + "ULT_LEIT_CORTE, ";
                    vFILTER = vFILTER + "CONSTI, ";
                    vFILTER = vFILTER + "CUSTO_CONEXAO, ";
                    vFILTER = vFILTER + "KWH_RECEBIDO_PONTA, ";
                    vFILTER = vFILTER + "KWH_RECEBIDO_INTERMEDIARIA, ";
                    vFILTER = vFILTER + "KWH_RECEBIDO_FORA_PONTA ";


                    vINNERJOIN = " ";

                    vORDERBY = "ORDER BY ROTA ASC ";

                    vAND = vAND + "   AND STATUS <> ?STATUS ";

                    if (objLeitmensal.ROTA_INICIAL != string.Empty && objLeitmensal.ROTA_FINAL != string.Empty)
                    {
                        vAND = vAND + "   AND(ROTA BETWEEN ?ROTA_INICIAL AND ?ROTA_FINAL) ";
                    }

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

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

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

                    if (objLeitmensal.ROTA != string.Empty)
                    {
                        vAND = vAND + "    AND MID(TRIM(ROTA), 1, 4) IN ( ?ROTA ) ";
                    }


                    cmd = new MySqlCommand(this.QuerySelect);

                    cmd.Parameters.AddWithValue("?STATUS", objLeitmensal.STATUS);

                    if (objLeitmensal.ROTA_INICIAL != string.Empty && objLeitmensal.ROTA_FINAL != string.Empty)
                    {
                        cmd.Parameters.AddWithValue("?ROTA_INICIAL", objLeitmensal.ROTA_INICIAL.ToString().ToUpper());
                        cmd.Parameters.AddWithValue("?ROTA_FINAL", objLeitmensal.ROTA_FINAL.ToString().ToUpper());
                    }

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

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

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

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

                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

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

        public DataTable Select_10(entidadeLeitmensal objLeitmensal)
        {
            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 + "STATUS, ";
                    vFILTER = vFILTER + "ROTA, ";
                    vFILTER = vFILTER + "SEQ, ";
                    vFILTER = vFILTER + "ZONA, ";
                    vFILTER = vFILTER + "LIVRO, ";
                    vFILTER = vFILTER + "CONTA, ";
                    vFILTER = vFILTER + "LEIT_ANT, ";
                    vFILTER = vFILTER + "LEIT_ATUAL, ";
                    vFILTER = vFILTER + "MEDIDOR, ";
                    vFILTER = vFILTER + "ENDERECO, ";
                    vFILTER = vFILTER + "NOME, ";
                    vFILTER = vFILTER + "MUNICIP, ";
                    vFILTER = vFILTER + "MEDIA, ";
                    vFILTER = vFILTER + "OCORRENC, ";
                    vFILTER = vFILTER + "MEDKVARH, ";
                    vFILTER = vFILTER + "KVARH, ";
                    vFILTER = vFILTER + "KVARHATUAL, ";
                    vFILTER = vFILTER + "DT_LEIT, ";
                    vFILTER = vFILTER + "CONS_ID, ";
                    vFILTER = vFILTER + "UNID_ID, ";
                    vFILTER = vFILTER + "CONSUMO, ";
                    vFILTER = vFILTER + "CONSUMOFAT, ";
                    vFILTER = vFILTER + "CONSUMOKVARH, ";
                    vFILTER = vFILTER + "DT_APREST, ";
                    vFILTER = vFILTER + "DT_FATURAMENTO, ";
                    vFILTER = vFILTER + "DT_LEITANT, ";
                    vFILTER = vFILTER + "DT_VCTO, ";
                    vFILTER = vFILTER + "DT_PROXIMA_LEIT, ";
                    vFILTER = vFILTER + "DT_VECTOPP, ";
                    vFILTER = vFILTER + "TA, ";
                    vFILTER = vFILTER + "ARREDONDA, ";
                    vFILTER = vFILTER + "CONST, ";
                    vFILTER = vFILTER + "CONSTFP, ";
                    vFILTER = vFILTER + "CLASSE, ";
                    vFILTER = vFILTER + "DIAVENC, ";
                    vFILTER = vFILTER + "SIT, ";
                    vFILTER = vFILTER + "CPOF, ";
                    vFILTER = vFILTER + "FP, ";
                    vFILTER = vFILTER + "TENSAO, ";
                    vFILTER = vFILTER + "CPFCNPJ, ";
                    vFILTER = vFILTER + "RGIE, ";
                    vFILTER = vFILTER + "INSC, ";
                    vFILTER = vFILTER + "BANCO, ";
                    vFILTER = vFILTER + "AGENCIA, ";
                    vFILTER = vFILTER + "CONTACORRENTE, ";
                    vFILTER = vFILTER + "FASE, ";
                    vFILTER = vFILTER + "BANARREC, ";
                    vFILTER = vFILTER + "RESIDUO, ";
                    vFILTER = vFILTER + "LEIT_AJUST, ";
                    vFILTER = vFILTER + "LEIT_REVERSO_ANT, ";
                    vFILTER = vFILTER + "LEIT_REVERSO_ATUAL, ";
                    vFILTER = vFILTER + "LEIT_IRRIGANTE_ANT, ";
                    vFILTER = vFILTER + "LEIT_IRRIGANTE_ATUAL, ";
                    vFILTER = vFILTER + "KWH_IRRIGANTE, ";
                    vFILTER = vFILTER + "KWH_IRRIGANTE_FAT, ";
                    vFILTER = vFILTER + "KWH_REVERSO, ";
                    vFILTER = vFILTER + "KWH_REVERSO_FAT, ";
                    vFILTER = vFILTER + "KWH_REVERSO_RES, ";
                    vFILTER = vFILTER + "KWH_REVERSO_MES_ANT, ";
                    vFILTER = vFILTER + "KWH_IRRIGANTE_RES, ";
                    vFILTER = vFILTER + "LEITURA_ANT_PONTA, ";
                    vFILTER = vFILTER + "LEITURA_ATUAL_PONTA, ";
                    vFILTER = vFILTER + "LEITURA_ANT_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "LEITURA_ATUAL_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "LEITURA_ANT_FORA_PONTA, ";
                    vFILTER = vFILTER + "LEITURA_ATUAL_FORA_PONTA, ";
                    vFILTER = vFILTER + "KWH_PONTA, ";
                    vFILTER = vFILTER + "KWH_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "KWH_FORA_PONTA, ";
                    vFILTER = vFILTER + "RESIDUO_PONTA, ";
                    vFILTER = vFILTER + "RESIDUO_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "RESIDUO_FORA_PONTA, ";
                    vFILTER = vFILTER + "ULT_LEIT_CORTE, ";
                    vFILTER = vFILTER + "CONSTI, ";
                    vFILTER = vFILTER + "CUSTO_CONEXAO, ";
                    vFILTER = vFILTER + "KWH_RECEBIDO_PONTA, ";
                    vFILTER = vFILTER + "KWH_RECEBIDO_INTERMEDIARIA, ";
                    vFILTER = vFILTER + "KWH_RECEBIDO_FORA_PONTA ";


                    vINNERJOIN = " ";

                    vORDERBY = " ";

                    vAND = vAND + "   AND DT_LEIT <= ?DT_LEIT ";
                    vAND = vAND + "   AND STATUS <> ?STATUS ";
                    vAND = vAND + "   AND CONS_ID = ?CONS_ID ";
                    vAND = vAND + "   AND UNID_ID = ?UNID_ID ";


                    cmd = new MySqlCommand(this.QuerySelect);

                    cmd.Parameters.AddWithValue("?DT_LEIT", objLeitmensal.DT_LEIT);
                    cmd.Parameters.AddWithValue("?STATUS", objLeitmensal.STATUS);
                    cmd.Parameters.AddWithValue("?CONS_ID", objLeitmensal.CONS_ID.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?UNID_ID", objLeitmensal.UNID_ID.ToString().ToUpper());


                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

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

        public DataTable Select_11(entidadeLeitmensal objLeitmensal)
        {
            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 + "STATUS, ";
                    vFILTER = vFILTER + "ROTA, ";
                    vFILTER = vFILTER + "SEQ, ";
                    vFILTER = vFILTER + "ZONA, ";
                    vFILTER = vFILTER + "LIVRO, ";
                    vFILTER = vFILTER + "CONTA, ";
                    vFILTER = vFILTER + "LEIT_ANT, ";
                    vFILTER = vFILTER + "LEIT_ATUAL, ";
                    vFILTER = vFILTER + "MEDIDOR, ";
                    vFILTER = vFILTER + "ENDERECO, ";
                    vFILTER = vFILTER + "NOME, ";
                    vFILTER = vFILTER + "MUNICIP, ";
                    vFILTER = vFILTER + "MEDIA, ";
                    vFILTER = vFILTER + "OCORRENC, ";
                    vFILTER = vFILTER + "MEDKVARH, ";
                    vFILTER = vFILTER + "KVARH, ";
                    vFILTER = vFILTER + "KVARHATUAL, ";
                    vFILTER = vFILTER + "DT_LEIT, ";
                    vFILTER = vFILTER + "CONS_ID, ";
                    vFILTER = vFILTER + "UNID_ID, ";
                    vFILTER = vFILTER + "CONSUMO, ";
                    vFILTER = vFILTER + "CONSUMOFAT, ";
                    vFILTER = vFILTER + "CONSUMOKVARH, ";
                    vFILTER = vFILTER + "DT_APREST, ";
                    vFILTER = vFILTER + "DT_FATURAMENTO, ";
                    vFILTER = vFILTER + "DT_LEITANT, ";
                    vFILTER = vFILTER + "DT_VCTO, ";
                    vFILTER = vFILTER + "DT_PROXIMA_LEIT, ";
                    vFILTER = vFILTER + "DT_VECTOPP, ";
                    vFILTER = vFILTER + "TA, ";
                    vFILTER = vFILTER + "ARREDONDA, ";
                    vFILTER = vFILTER + "CONST, ";
                    vFILTER = vFILTER + "CONSTFP, ";
                    vFILTER = vFILTER + "CLASSE, ";
                    vFILTER = vFILTER + "DIAVENC, ";
                    vFILTER = vFILTER + "SIT, ";
                    vFILTER = vFILTER + "CPOF, ";
                    vFILTER = vFILTER + "FP, ";
                    vFILTER = vFILTER + "TENSAO, ";
                    vFILTER = vFILTER + "CPFCNPJ, ";
                    vFILTER = vFILTER + "RGIE, ";
                    vFILTER = vFILTER + "INSC, ";
                    vFILTER = vFILTER + "BANCO, ";
                    vFILTER = vFILTER + "AGENCIA, ";
                    vFILTER = vFILTER + "CONTACORRENTE, ";
                    vFILTER = vFILTER + "FASE, ";
                    vFILTER = vFILTER + "BANARREC, ";
                    vFILTER = vFILTER + "RESIDUO, ";
                    vFILTER = vFILTER + "LEIT_AJUST, ";
                    vFILTER = vFILTER + "LEIT_REVERSO_ANT, ";
                    vFILTER = vFILTER + "LEIT_REVERSO_ATUAL, ";
                    vFILTER = vFILTER + "LEIT_IRRIGANTE_ANT, ";
                    vFILTER = vFILTER + "LEIT_IRRIGANTE_ATUAL, ";
                    vFILTER = vFILTER + "KWH_IRRIGANTE, ";
                    vFILTER = vFILTER + "KWH_IRRIGANTE_FAT, ";
                    vFILTER = vFILTER + "KWH_REVERSO, ";
                    vFILTER = vFILTER + "KWH_REVERSO_FAT, ";
                    vFILTER = vFILTER + "KWH_REVERSO_RES, ";
                    vFILTER = vFILTER + "KWH_REVERSO_MES_ANT, ";
                    vFILTER = vFILTER + "KWH_IRRIGANTE_RES, ";
                    vFILTER = vFILTER + "LEITURA_ANT_PONTA, ";
                    vFILTER = vFILTER + "LEITURA_ATUAL_PONTA, ";
                    vFILTER = vFILTER + "LEITURA_ANT_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "LEITURA_ATUAL_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "LEITURA_ANT_FORA_PONTA, ";
                    vFILTER = vFILTER + "LEITURA_ATUAL_FORA_PONTA, ";
                    vFILTER = vFILTER + "KWH_PONTA, ";
                    vFILTER = vFILTER + "KWH_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "KWH_FORA_PONTA, ";
                    vFILTER = vFILTER + "RESIDUO_PONTA, ";
                    vFILTER = vFILTER + "RESIDUO_INTERMEDIARIO, ";
                    vFILTER = vFILTER + "RESIDUO_FORA_PONTA, ";
                    vFILTER = vFILTER + "ULT_LEIT_CORTE, ";
                    vFILTER = vFILTER + "CONSTI, ";
                    vFILTER = vFILTER + "CUSTO_CONEXAO, ";
                    vFILTER = vFILTER + "KWH_RECEBIDO_PONTA, ";
                    vFILTER = vFILTER + "KWH_RECEBIDO_INTERMEDIARIA, ";
                    vFILTER = vFILTER + "KWH_RECEBIDO_FORA_PONTA ";


                    vINNERJOIN = " ";

                    vORDERBY = " ";

                    vAND = vAND + "   AND ZONA = ?ZONA ";
                    vAND = vAND + "   AND LIVRO = ?LIVRO ";
                    vAND = vAND + "   AND CONTA = ?CONTA ";
                    vAND = vAND + "   AND DT_LEIT <= ?DT_LEIT ";


                    cmd = new MySqlCommand(this.QuerySelect);


                    cmd.Parameters.AddWithValue("?ZONA", objLeitmensal.ZONA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LIVRO", objLeitmensal.LIVRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTA", objLeitmensal.CONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DT_LEIT", objLeitmensal.DT_LEIT.ToString("yyyy-MM-dd").ToUpper());


                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

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

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

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

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

                    vFILTER = vFILTER + "COUNT(*) ";

                    vINNERJOIN = " ";

                    vORDERBY = " ";

                    vAND = vAND + "   AND ZONA  = ?ZONA ";
                    vAND = vAND + "   AND LIVRO = ?LIVRO ";
                    vAND = vAND + "   AND CONTA = ?CONTA ";
                    vAND = vAND + "   AND UNID_ID = ?UNID_ID ";
                    vAND = vAND + "   AND DATE_FORMAT(DT_LEIT, '%Y-%m') = DATE_FORMAT(?DT_LEIT, '%Y-%m') ";

                    cmd = new MySqlCommand(this.QuerySelect);

                    cmd.Parameters.AddWithValue("?ZONA", objLeitmensal.ZONA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?LIVRO", objLeitmensal.LIVRO.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?CONTA", objLeitmensal.CONTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?UNID_ID", objLeitmensal.UNID_ID);
                    cmd.Parameters.AddWithValue("?DT_LEIT", objLeitmensal.DT_LEIT);

                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

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

        public DataTable SelectCountRota(entidadeLeitmensal objLeitmensal)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            StringBuilder lstrSql = new StringBuilder();
            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

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

                    vFILTER = vFILTER + "SELECT DISTINCT ROTA ";

                    vINNERJOIN = "FROM  UC_FATURAMENTO ";

                    vAND = vAND + " WHERE LPAD(LEFT(ROTA, 4), 4,'0') IN (" + objLeitmensal.ROTA + ") ";

                    vAND = vAND + " AND NOT EXISTS( SELECT 1 FROM leitmensal WHERE leitmensal.rota = uc_faturamento.rota) ";

                    lstrSql.Clear();
                    lstrSql.AppendLine(vFILTER);
                    lstrSql.AppendLine(vINNERJOIN);
                    lstrSql.AppendLine(vAND);


                    cmd = new MySqlCommand(lstrSql.ToString());

                    cmd.Parameters.AddWithValue("?ROTA", objLeitmensal.ROTA.ToString().ToUpper());


                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

                return dt;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }
        public DataTable SelectCountRotaRecebida(entidadeLeitmensal objLeitmensal)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            StringBuilder lstrSql = new StringBuilder();
            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

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

                    vFILTER = vFILTER + " SELECT ROTA ";

                    vINNERJOIN = " FROM  LEITMENSAL ";

                    vAND = vAND + " WHERE LPAD(LEFT(ROTA, 4), 4,'0') IN (" + objLeitmensal.ROTA + ") ";
                    vAND = vAND + " AND LEIT_ATUAL <> 0 ";

                    vAND = vAND + " GROUP BY ROTA HAVING COUNT(*) > 0 ";

                    lstrSql.Clear();
                    lstrSql.AppendLine(vFILTER);
                    lstrSql.AppendLine(vINNERJOIN);
                    lstrSql.AppendLine(vAND);


                    cmd = new MySqlCommand(lstrSql.ToString());

                    cmd.Parameters.AddWithValue("?ROTA", objLeitmensal.ROTA.ToString().ToUpper());


                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

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

        public DataTable SelectOthersTables(entidadeLeitmensal objLeitmensal)
        {
            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 + "DT_LEITANT,  ";
                    vFILTER = vFILTER + "DT_LEIT  ";

                    vINNERJOIN = " , UC_FATURAMENTO ";

                    vORDERBY = " ";

                    vAND = vAND + "   AND MID(TRIM(LEITMENSAL.ROTA), 1, 4) = ?ROTA ";
                    vAND = vAND + "   AND DATE_FORMAT( LEITMENSAL.DT_LEIT, '%Y-%m') = '" + objLeitmensal.DT_LEIT.ToString("yyyy-MM") + "' ";
                    vAND = vAND + "   AND LEITMENSAL.ZONA = UC_FATURAMENTO.ZONA ";
                    vAND = vAND + "   AND LEITMENSAL.LIVRO = UC_FATURAMENTO.LIVRO ";
                    vAND = vAND + "   AND LEITMENSAL.CONTA = UC_FATURAMENTO.CONTA ";
                    vAND = vAND + "   AND LEITMENSAL.UNID_ID = UC_FATURAMENTO.ID ";

                    if (objLeitmensal.DIAVENC != " ")
                    {
                        vAND = vAND + "  AND UC_FATURAMENTO.DIAVENC = ?DIAVENC ";
                    }

                    vAND = vAND + "   AND UC_FATURAMENTO.ZONA <> '999' ";
                    vAND = vAND + "   AND UC_FATURAMENTO.SITUACAO IN( " + objLeitmensal.SIT.ToString().ToUpper() + ") ";

                    cmd = new MySqlCommand(this.QuerySelect);

                    cmd.Parameters.AddWithValue("?ROTA", objLeitmensal.ROTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DT_LEIT", objLeitmensal.DT_LEIT.ToString("yyyy-MM"));

                    if (objLeitmensal.DIAVENC != " ")
                    {
                        cmd.Parameters.AddWithValue("?DIAVENC", objLeitmensal.DIAVENC.ToString().ToUpper());
                    }

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

                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

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


        public DataTable SelectOthersTables_1(entidadeLeitmensal objLeitmensal)
        {
            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 + "DT_LEITANT,  ";
                    vFILTER = vFILTER + "DT_LEIT  ";

                    vINNERJOIN = " , UC_FATURAMENTO ";

                    vORDERBY = " ";
                    vORDERBY = "ORDER BY UC_FATURAMENTO.SEQUENCIA ";

                    vAND = vAND + "   AND MID(TRIM(LEITMENSAL.ROTA), 1, 4) = ?ROTA ";
                    vAND = vAND + "   AND DATE_FORMAT( LEITMENSAL.DT_LEIT, '%Y-%m') = '" + objLeitmensal.DT_LEIT.ToString("yyyy-MM") + "' ";
                    vAND = vAND + "   AND LEITMENSAL.ZONA = UC_FATURAMENTO.ZONA ";
                    vAND = vAND + "   AND LEITMENSAL.LIVRO = UC_FATURAMENTO.LIVRO ";
                    vAND = vAND + "   AND LEITMENSAL.CONTA = UC_FATURAMENTO.CONTA ";
                    vAND = vAND + "   AND LEITMENSAL.UNID_ID = UC_FATURAMENTO.ID ";

                    if (objLeitmensal.DIAVENC != " ")
                    {
                        vAND = vAND + "  AND UC_FATURAMENTO.DIAVENC = ?DIAVENC ";
                    }

                    vAND = vAND + "   AND UC_FATURAMENTO.ZONA <> '999' ";
                    vAND = vAND + "   AND UC_FATURAMENTO.SITUACAO IN( " + objLeitmensal.SIT.ToString().ToUpper() + ") ";

                    if (objLeitmensal.MICRO_GERACAO == true) {vAND = vAND + "   AND UC_FATURAMENTO.MICRO_GERACAO IN( " + (objLeitmensal.MICRO_GERACAO == true ? 1 : 0) + ") "; }

                    

                    cmd = new MySqlCommand(this.QuerySelect);

                    cmd.Parameters.AddWithValue("?ROTA", objLeitmensal.ROTA.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?DT_LEIT", objLeitmensal.DT_LEIT.ToString("yyyy-MM"));

                    if (objLeitmensal.DIAVENC != " ")
                    {
                        cmd.Parameters.AddWithValue("?DIAVENC", objLeitmensal.DIAVENC.ToString().ToUpper());
                    }

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

                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

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

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

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

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

                    vAND = " ";

                    cmd = new MySqlCommand(this.QueryDelete);

                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

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

        public DataTable Delete_1(entidadeLeitmensal objLeitmensal)
        {
            DataTable dt = null;
            MySqlCommand cmd = null;
            IGerenciadorTransacao objGerenciadorTransacao = null;
            ConexaoBD objconexaoBD = null;

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

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

                    vAND = "LEFT(ROTA, 4) IN(?ROTA) ";

                    cmd = new MySqlCommand(this.QueryDelete);

                    cmd.Parameters.AddWithValue("?ROTA", objLeitmensal.ROTA.ToString().ToUpper());

                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

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

        #endregion

        #region " Comandos SQL "

        StringBuilder sb = new StringBuilder();


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

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

                return sb.ToString();
            }
        }

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

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

                return sb.ToString();
            }
        }

        #endregion



    }

    public class dalLeitmensalFoto
    {
        string vFILTER = null;
        string vINNERJOIN = null;
        string vAND = null;
        string vORDERBY = null;

        #region Métodos

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

            try
            {
                objconexaoBD = new ConexaoBD();

                objconexaoBD.SetarConexaoBanco(TipoBDConexao.fat_BD);

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

                    vAND = " ";

                    cmd = new MySqlCommand(this.QueryDelete);

                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

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

        public DataTable Select_Fotos_UC(string unid_id)
        {
            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 = vFILTER + "id, ";
                    vFILTER = vFILTER + "rota_item_id, ";
                    vFILTER = vFILTER + "unid_id, ";
                    vFILTER = vFILTER + "zona, ";
                    vFILTER = vFILTER + "livro, ";
                    vFILTER = vFILTER + "conta, ";
                    vFILTER = vFILTER + "foto AS Base64";

                    vINNERJOIN = " ";                

                    vAND = " ";
                    vAND = vAND + " AND unid_id IN (" + unid_id + ") ";

                    vORDERBY = " ";

                    cmd = new MySqlCommand(this.QuerySelect);

                    //cmd.Parameters.AddWithValue("?UNID_ID", unid_id);

                    dt = objGerenciadorTransacao.GetDataTable(cmd);
                }

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



        public void InsereImagemDoApp(entidadeAgenciaVirtualFoto objLeitmensalFoto)
        {
            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 = vFILTER + " id = ?id , ";
                    vFILTER = vFILTER + " rota_item_id = ?rota_item_id , ";
                    vFILTER = vFILTER + " unid_id  = ?unid_id  , ";
                    vFILTER = vFILTER + " zona  = ?zona  , ";
                    vFILTER = vFILTER + " livro  = ?livro  , ";
                    vFILTER = vFILTER + " conta  = ?conta  , ";
                    vFILTER = vFILTER + " foto = ?foto  ";

                    cmd = new MySqlCommand(this.QueryInsert);

                    cmd.Parameters.AddWithValue("?id", objLeitmensalFoto.Id);
                    cmd.Parameters.AddWithValue("?rota_item_id", objLeitmensalFoto.RotaItemId.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?unid_id", objLeitmensalFoto.unid_id.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?zona", objLeitmensalFoto.zona.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?livro", objLeitmensalFoto.livro.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?conta", objLeitmensalFoto.conta.ToString().ToUpper());
                    cmd.Parameters.AddWithValue("?foto", objLeitmensalFoto.Base64);

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


        #endregion

        #region " Comandos SQL "

        StringBuilder sb = new StringBuilder();


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

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

                return sb.ToString();
            }
        }

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

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

                return sb.ToString();
            }
        }

        #endregion



    }
}
