Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Imports fatd_faturamento.BLL.Repositorio
Imports fatd_faturamento.ENTIDADE
Imports CrystalDecisions.CrystalReports.Engine
Friend Class frmRelPee
    Inherits System.Windows.Forms.Form
    Private dt, dt1, dt2, dt3, dtinterno As DataTable

    Private objAtualizaBancoDados As New entidadeAtualizaBancoDados
    Private repositorioAtualizaBancoDados As New repositorioAtualizaBancoDados

    Private objExecAtualizaBancoDados As New entidadeAtualizaBancoDados
    Private repositorioExecAtualizaBancoDados As New repositorioAtualizaBancoDados
    Private LImagem() As Byte
    Private sNomeEmpresa As String
    Private sEnderecoEmpresa As String
    Private sCepEmpresa As String
    Private sCidadeEmpresa As String
    Private sUFempresa As String
    Private sBairroEmpresa As String
    Private sFoneEmpresa As String
    Private sWebEmpresa As String
    Private bValidacao As Boolean
    Private sTitulo As String

    'UPGRADE_WARNING: Event chkFaturadoEm.CheckStateChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
    Private Sub chkFaturadoEm_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkFaturadoEm.CheckStateChanged
        Me.dtpFaturadoEm.Enabled = (Me.chkFaturadoEm.CheckState = System.Windows.Forms.CheckState.Checked)
        Me.chkSomenteMesAno.Enabled = (Me.chkFaturadoEm.CheckState = System.Windows.Forms.CheckState.Checked)
    End Sub

    ''UPGRADE_WARNING: Event chkMesAno.CheckStateChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
    Private Sub chkMesAno_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkMesAno.CheckStateChanged
        Me.dtpMesAno.Enabled = (Me.chkMesAno.CheckState = System.Windows.Forms.CheckState.Checked)
    End Sub

    Private Sub cmdArquivo_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdArquivo.Click
        Try
            Me.dialArqOpen.DefaultExt = "CSV"
            'UPGRADE_WARNING: Filter has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
            Me.dialArqOpen.Filter = "*|." & Me.dialArqOpen.DefaultExt
            Me.dialArqOpen.FileName = My.Application.Info.DirectoryPath & "\PEE_" & VB6.Format(Date.Now, "YYYYMMDDHHMMSS") & "." & Me.dialArqOpen.DefaultExt
            Me.dialArqOpen.Title = "Arquivo de exportação de P.E.E."
            Me.dialArqOpen.ShowDialog()
            Me.txtArquivo.Text = Me.dialArqOpen.FileName

        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmdArquivo_Click" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try
    End Sub

    Private Sub cmdExporta_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExporta.Click
        Dim lstrLin As String
        Dim lintARQ As Short
        Dim llngRow As Integer
        Dim llngCol As Integer
        Dim lstrSql As String

        Try
            'Dim lrstAux As ADODB.Recordset
            'lrstAux = New ADODB.Recordset
            If Trim(Me.txtArquivo.Text) <> "" Then
                Call LigDes(False)
                lstrSql = ""
                lstrSql = lstrSql & "SELECT "
                lstrSql = lstrSql & "       `bairro`, `identificacao`, `caderno`, `sequencia`, `classe`, `nome`, "
                lstrSql = lstrSql & "       `end_log`, `end_num`, `end_com`, `end_cid`, `end_dis`, "
                lstrSql = lstrSql & "       `medidor`, `regiao`, `fase`, `situacao`, `grupo`, `nis`, "
                lstrSql = lstrSql & "       `mes_01`, `mes_02`, `mes_03`, `mes_04`, `mes_05`, `mes_06`, `mes_07`, `mes_08`, `mes_09`, `mes_10`, `mes_11`, `mes_12`, "
                lstrSql = lstrSql & "       `vlr_01`, `vlr_02`, `vlr_03`, `vlr_04`, `vlr_05`, `vlr_06`, `vlr_07`, `vlr_08`, `vlr_09`, `vlr_10`, `vlr_11`, `vlr_12`, "
                lstrSql = lstrSql & "       `icms_01`, `icms_02`, `icms_03`, `icms_04`, `icms_05`, `icms_06`, `icms_07`, `icms_08`, `icms_09`, `icms_10`, `icms_11`, `icms_12`, "
                lstrSql = lstrSql & "       `pis_01`, `pis_02`, `pis_03`, `pis_04`, `pis_05`, `pis_06`, `pis_07`, `pis_08`, `pis_09`, `pis_10`, `pis_11`, `pis_12`, "
                lstrSql = lstrSql & "       `cofins_01`, `cofins_02`, `cofins_03`, `cofins_04`, `cofins_05`, `cofins_06`, `cofins_07`, `cofins_08`, `cofins_09`, `cofins_10`, `cofins_11`, `cofins_12`, "
                lstrSql = lstrSql & "       `ene_01`, `ene_02`, `ene_03`, `ene_04`, `ene_05`, `ene_06`, `ene_07`, `ene_08`, `ene_09`, `ene_10`, `ene_11`, `ene_12`, "
                lstrSql = lstrSql & "       `tra_01`, `tra_02`, `tra_03`, `tra_04`, `tra_05`, `tra_06`, `tra_07`, `tra_08`, `tra_09`, `tra_10`, `tra_11`, `tra_12`, "
                lstrSql = lstrSql & "       `dis_01`, `dis_02`, `dis_03`, `dis_04`, `dis_05`, `dis_06`, `dis_07`, `dis_08`, `dis_09`, `dis_10`, `dis_11`, `dis_12`, "
                lstrSql = lstrSql & "       `enc_01`, `enc_02`, `enc_03`, `enc_04`, `enc_05`, `enc_06`, `enc_07`, `enc_08`, `enc_09`, `enc_10`, `enc_11`, `enc_12`, "
                lstrSql = lstrSql & "       `per_01`, `per_02`, `per_03`, `per_04`, `per_05`, `per_06`, `per_07`, `per_08`, `per_09`, `per_10`, `per_11`, `per_12`, "
                lstrSql = lstrSql & "       `tic_01`, `tic_02`, `tic_03`, `tic_04`, `tic_05`, `tic_06`, `tic_07`, `tic_08`, `tic_09`, `tic_10`, `tic_11`, `tic_12`, "
                lstrSql = lstrSql & "       `tpc_01`, `tpc_02`, `tpc_03`, `tpc_04`, `tpc_05`, `tpc_06`, `tpc_07`, `tpc_08`, `tpc_09`, `tpc_10`, `tpc_11`, `tpc_12` "
                lstrSql = lstrSql & "  FROM `AUX_RELPEE` "
                lstrSql = lstrSql & " WHERE `nomemaquina` = '" & My.Computer.Name & "' "
                ' Call Conectar(lstrSql, lrstAuxque)
                objAtualizaBancoDados.QUERY_NAME = lstrSql
                dt = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

                'If .RecordCount > 0 Then
                '    Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount)
                '    lintARQ = FreeFile()
                '    FileOpen(lintARQ, Me.txtArquivo.Text, OpenMode.Output)
                '    lstrLin = ""
                '    For llngCol = 0 To .Fields.Count - 1
                '        'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
                '        lstrLin = lstrLin & IIf(IsDBNull(.Fields(llngCol).Name), "", .Fields(llngCol).Name) & ";"
                '    Next llngCol
                '    PrintLine(lintARQ, lstrLin)
                '    While Not .EOF
                '        lstrLin = ""
                '        For llngCol = 0 To .Fields.Count - 1
                '            'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
                '            lstrLin = lstrLin & IIf(IsDBNull(.Fields(llngCol).value), "", .Fields(llngCol).value) & ";"
                '        Next llngCol
                '        PrintLine(lintARQ, lstrLin)
                '        Call .MoveNext()
                '        Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
                '    End While
                '    FileClose(lintARQ)
                'End If

                Dim sNomeArquivo As String
                Dim lstrTab As String
                Dim i As Integer

                If dt.Rows.Count > 0 Then
                    Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, dt.Rows.Count)
                    'adoStream.Open()
                    'adoStream.Charset = "UTF-8"
                    lintARQ = FreeFile()
                    sNomeArquivo = ""
                    sNomeArquivo = txtArquivo.Text '& IIf(VB.Right(Me.txtArquivo.Text, 1) = "\", "", "\") & "Unidades_Consumidoras_" & gstrEmpresa_Sigla & ".csv" 'For Output As lintARQ
                    FileOpen(lintARQ, sNomeArquivo, OpenMode.Output)
                    lstrTab = ""

                    For Each columns As DataColumn In dt.Columns
                        lstrTab = lstrTab & IIf(IsDBNull(columns.ColumnName), "", columns.ColumnName) & ";"
                    Next
                    PrintLine(lintARQ, lstrTab)

                    For Each row As DataRow In dt.Rows
                        lstrTab = ""
                        i = 0
                        For Each columns2 As DataColumn In dt.Columns
                            lstrTab = lstrTab & IIf(IsDBNull(row.Item(i)), "", row.Item(i)) & ";"
                            i = i + 1
                        Next
                        PrintLine(lintARQ, lstrTab)
                        Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
                    Next
                    FileClose(lintARQ)

                    Call LigDes(True)
                    Call MsgBox("Arquivo gerado com sucesso!", MsgBoxStyle.Information, gstrTituloMensagem)
                Else

                    Call LigDes(True)
                    Call MsgBox("Sem registros para gerar o arquivo !", MsgBoxStyle.Information, gstrTituloMensagem)
                End If

            Else
                Call MsgBox("Você precisa selecionar o caminho e o arquivo para exportação!", MsgBoxStyle.Information, gstrTituloMensagem)
            End If

        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmdExporta_Click" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try
    End Sub

    Private Sub cmdFechar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFechar.Click
        Call Me.Close()
    End Sub

    Private Sub cmdImprimir_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdImprimir.Click

        Call LigDes(False)
        Call ImprimirPee()
        Call LigDes(True)

    End Sub

    Private Sub cmdProcessar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdProcessar.Click
        Dim lstrsql As String
        Call LigDes(False)
        Try

            lstrsql = "DELETE FROM `AUX_RELPEE` WHERE `NOMEMAQUINA` = '" & My.Computer.Name & "' "
            objExecAtualizaBancoDados.QUERY_NAME = lstrsql
            repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

            Call EncheGrade()
            Call LigDes(True)

        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmdProcessar_Click" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try
    End Sub

    Private Sub frmRelPee_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
        Try
            Dim lstrSql As String

            Call CarregaRotas()
            Call CarregaClasses((Me.lsvClasses))
            Call sCriaTabelaAuxiliar()
            Me.dtpMesAno.Value = Date.Now()
            Me.dtpFaturadoEm.Value = Me.dtpMesAno.Value
            Me.dtpMesAno.Enabled = False
            Me.dtpFaturadoEm.Enabled = False

        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: frmRelPee_Load" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub EncheGrade()
        Dim lstrZona As String
        Dim lstrLivro As String
        Dim lstrConta As String
        Dim lstrRota As String
        Dim lstrRegiao As String
        Dim lstrFase As String
        Dim lstrSituacao As String
        Dim lstrGrupo As String
        Dim lstrClas As String
        Dim lstrNome As String
        Dim lstrEndCid As String
        Dim lstrEndDis As String
        Dim lstrEndBai As String
        Dim lstrEndLog As String
        Dim lstrEndNum As String
        Dim lstrEndCom As String
        Dim lstrMedidor As String
        Dim llngConsId As Integer
        Dim llngUnidId As Integer
        Dim ldblNumNf As Double
        Dim llngMesano As Integer
        Dim ldteLeitura As Date
        Dim lstrGruTar As String
        Dim lstrClasFat As String
        Dim lstrItens As String
        Dim lstrNrCpf As String
        Dim lstrNrNis As String
        'UPGRADE_WARNING: Lower bound of array ldblkWhFat was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
        Dim ldblkWhFat(12) As Double
        'UPGRADE_WARNING: Lower bound of array ldblVlrkWhFat was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
        Dim ldblVlrkWhFat(12) As Double
        'UPGRADE_WARNING: Lower bound of array ldblIcms was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
        Dim ldblIcms(12) As Double
        'UPGRADE_WARNING: Lower bound of array ldblPis was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
        Dim ldblPis(12) As Double
        'UPGRADE_WARNING: Lower bound of array ldblCofins was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
        Dim ldblCofins(12) As Double
        'UPGRADE_WARNING: Lower bound of array ldblEnergia was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
        Dim ldblEnergia(12) As Double
        'UPGRADE_WARNING: Lower bound of array ldblTransimissao was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
        Dim ldblTransimissao(12) As Double
        'UPGRADE_WARNING: Lower bound of array ldblDistribuicao was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
        Dim ldblDistribuicao(12) As Double
        'UPGRADE_WARNING: Lower bound of array ldblEncSet was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
        Dim ldblEncSet(12) As Double
        'UPGRADE_WARNING: Lower bound of array ldblPerdas was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
        Dim ldblPerdas(12) As Double
        'UPGRADE_WARNING: Lower bound of array ldblTriIcms was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
        Dim ldblTriIcms(12) As Double
        'UPGRADE_WARNING: Lower bound of array ldblTriPiCo was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
        Dim ldblTriPiCo(12) As Double
        Dim lintAux As Short
        Dim lblnContinua As Boolean
        Dim lstrSql As String
        'Dim lrstAux As ADODB.Recordset
        'Dim lrstFat As ADODB.Recordset
        'lrstAux = New ADODB.Recordset
        'lrstFat = New ADODB.Recordset
        Try
            lstrSql = ""
            If Me.chkGrupoB.CheckState = System.Windows.Forms.CheckState.Checked Then
                lstrSql = lstrSql & "SELECT " & vbCrLf
                lstrSql = lstrSql & "       `cons_id`, " & vbCrLf
                lstrSql = lstrSql & "       `unid_id`, " & vbCrLf
                lstrSql = lstrSql & "       `zona`, " & vbCrLf
                lstrSql = lstrSql & "       `livro`, " & vbCrLf
                lstrSql = lstrSql & "       `conta`, " & vbCrLf
                lstrSql = lstrSql & "       `rota`, " & vbCrLf
                lstrSql = lstrSql & "       `regiao`, " & vbCrLf
                lstrSql = lstrSql & "       `fase`, " & vbCrLf
                lstrSql = lstrSql & "       `situacao`, " & vbCrLf
                lstrSql = lstrSql & "       `grupo`, " & vbCrLf
                lstrSql = lstrSql & "       `clas`, " & vbCrLf
                lstrSql = lstrSql & "       `nome`, " & vbCrLf
                lstrSql = lstrSql & "       `cidade`, " & vbCrLf
                lstrSql = lstrSql & "       `distrito`, " & vbCrLf
                lstrSql = lstrSql & "       `bairro`, " & vbCrLf
                lstrSql = lstrSql & "       `end`, " & vbCrLf
                lstrSql = lstrSql & "       `numero`, " & vbCrLf
                lstrSql = lstrSql & "       `complement`, " & vbCrLf
                lstrSql = lstrSql & "       `num` AS `medidor`, " & vbCrLf
                lstrSql = lstrSql & "       `cpf_cnpj` " & vbCrLf
                lstrSql = lstrSql & "  FROM `uc_faturamento` " & vbCrLf
                lstrSql = lstrSql & " WHERE 1 = 1 " & vbCrLf
                If Me.chkLigados.CheckState = System.Windows.Forms.CheckState.Checked Or Me.chkDesligados.CheckState = System.Windows.Forms.CheckState.Checked Or Me.chkCortados.CheckState = System.Windows.Forms.CheckState.Checked Or Me.chkDesativados.CheckState = System.Windows.Forms.CheckState.Checked Then
                    lstrSql = lstrSql & "  AND `situacao` IN("
                    If Me.chkLigados.CheckState = System.Windows.Forms.CheckState.Checked Then
                        lstrSql = lstrSql & "'L',"
                    End If
                    If Me.chkDesligados.CheckState = System.Windows.Forms.CheckState.Checked Then
                        lstrSql = lstrSql & "'D',"
                    End If
                    If Me.chkCortados.CheckState = System.Windows.Forms.CheckState.Checked Then
                        lstrSql = lstrSql & "'C',"
                    End If
                    If Me.chkDesativados.CheckState = System.Windows.Forms.CheckState.Checked Then
                        lstrSql = lstrSql & "'I',"
                    End If
                    lstrSql = VB.Left(lstrSql, Len(lstrSql) - 1) & ")" & vbCrLf
                End If
                lstrSql = lstrSql & MontaFiltroRotas() & vbCrLf
                lstrSql = lstrSql & MontaFiltroClasse() & vbCrLf
            End If
            'If Me.chkGrupoB.CheckState = System.Windows.Forms.CheckState.Checked And Me.chkGrupoA.CheckState = System.Windows.Forms.CheckState.Checked Then
            '    lstrSql = lstrSql & "UNION " & vbCrLf
            'End If
            'If Me.chkGrupoA.CheckState = System.Windows.Forms.CheckState.Checked Then
            '    lstrSql = lstrSql & "SELECT " & vbCrLf
            '    lstrSql = lstrSql & "       `cons_id`, " & vbCrLf
            '    lstrSql = lstrSql & "       `unid_id`, " & vbCrLf
            '    lstrSql = lstrSql & "       `zona`, " & vbCrLf
            '    lstrSql = lstrSql & "       `livro`, " & vbCrLf
            '    lstrSql = lstrSql & "       `conta`, " & vbCrLf
            '    lstrSql = lstrSql & "       `rota`, " & vbCrLf
            '    lstrSql = lstrSql & "       `regiao`, " & vbCrLf
            '    lstrSql = lstrSql & "       `fase`, " & vbCrLf
            '    lstrSql = lstrSql & "       `situacao`, " & vbCrLf
            '    lstrSql = lstrSql & "       `grupo`, " & vbCrLf
            '    lstrSql = lstrSql & "       `clas`, " & vbCrLf
            '    lstrSql = lstrSql & "       `nome`, " & vbCrLf
            '    lstrSql = lstrSql & "       `cidade`, " & vbCrLf
            '    lstrSql = lstrSql & "       `distrito`, " & vbCrLf
            '    lstrSql = lstrSql & "       `bairro`, " & vbCrLf
            '    lstrSql = lstrSql & "       `end`, " & vbCrLf
            '    lstrSql = lstrSql & "       `numero`, " & vbCrLf
            '    lstrSql = lstrSql & "       `complement`, " & vbCrLf
            '    lstrSql = lstrSql & "       `eletr` AS `medidor`, " & vbCrLf
            '    lstrSql = lstrSql & "       `cpf_cnpj` " & vbCrLf
            '    lstrSql = lstrSql & "  FROM `unida` " & vbCrLf
            '    lstrSql = lstrSql & " WHERE 1 = 1 " & vbCrLf
            '    If Me.chkLigados.CheckState = System.Windows.Forms.CheckState.Checked Or Me.chkDesligados.CheckState = System.Windows.Forms.CheckState.Checked Or Me.chkCortados.CheckState = System.Windows.Forms.CheckState.Checked Or Me.chkDesativados.CheckState = System.Windows.Forms.CheckState.Checked Then
            '        lstrSql = lstrSql & "  AND `situacao` IN("
            '        If Me.chkLigados.CheckState = System.Windows.Forms.CheckState.Checked Then
            '            lstrSql = lstrSql & "'L',"
            '        End If
            '        If Me.chkDesligados.CheckState = System.Windows.Forms.CheckState.Checked Then
            '            lstrSql = lstrSql & "'D',"
            '        End If
            '        If Me.chkCortados.CheckState = System.Windows.Forms.CheckState.Checked Then
            '            lstrSql = lstrSql & "'C',"
            '        End If
            '        If Me.chkDesativados.CheckState = System.Windows.Forms.CheckState.Checked Then
            '            lstrSql = lstrSql & "'I',"
            '        End If
            '        lstrSql = VB.Left(lstrSql, Len(lstrSql) - 1) & ")" & vbCrLf
            '    End If
            '    lstrSql = lstrSql & MontaFiltroRotas & vbCrLf
            '    lstrSql = lstrSql & MontaFiltroClasse & vbCrLf
            'End If
            'Call Conectar(lstrSql, lrstAux)
            objAtualizaBancoDados.QUERY_NAME = lstrSql
            dt = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

            If dt.Rows.Count > 0 Then
                Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, dt.Rows.Count)
                For Each row As DataRow In dt.Rows

                    lstrZona = Trim(IIf(IsDBNull(row.Item("zona")), "", row.Item("zona")))
                    lstrLivro = Trim(IIf(IsDBNull(row.Item("livro")), "", row.Item("livro")))
                    lstrConta = Trim(IIf(IsDBNull(row.Item("conta")), "", row.Item("conta")))
                    lstrRota = Trim(IIf(IsDBNull(row.Item("rota")), "", row.Item("rota")))
                    lstrRegiao = Trim(IIf(IsDBNull(row.Item("regiao")), "U", row.Item("regiao")))
                    lstrFase = Trim(IIf(IsDBNull(row.Item("fase")), "M", row.Item("fase")))
                    lstrSituacao = Trim(IIf(IsDBNull(row.Item("situacao")), "L", row.Item("situacao")))
                    lstrGrupo = Trim(IIf(IsDBNull(row.Item("grupo")), "B", row.Item("grupo")))
                    lstrClas = Trim(IIf(IsDBNull(row.Item("clas")), "0000", row.Item("clas")))
                    lstrNome = Trim(IIf(IsDBNull(row.Item("nome")), "", row.Item("nome")))
                    lstrEndCid = Trim(IIf(IsDBNull(row.Item("cidade")), "", row.Item("cidade")))
                    lstrEndDis = Trim(IIf(IsDBNull(row.Item("distrito")), "", row.Item("distrito")))
                    lstrEndBai = Trim(IIf(IsDBNull(row.Item("bairro")), "", row.Item("bairro")))
                    lstrEndLog = Trim(IIf(IsDBNull(row.Item("end")), "", row.Item("end")))
                    lstrEndNum = Trim(IIf(IsDBNull(row.Item("numero")), "", row.Item("numero")))
                    lstrEndCom = Trim(IIf(IsDBNull(row.Item("complement")), "", row.Item("complement")))
                    lstrMedidor = Trim(IIf(IsDBNull(row.Item("medidor")), "", row.Item("medidor")))
                    llngConsId = CInt(IIf(IsDBNull(row.Item("cons_id")), 0, row.Item("cons_id")))
                    llngUnidId = CInt(IIf(IsDBNull(row.Item("unid_id")), 0, row.Item("unid_id")))
                    lblnContinua = True

                    If Me.chkEmDia.CheckState = System.Windows.Forms.CheckState.Checked Then
                        lblnContinua = (Pedente(llngConsId) = False) 'se ele for false é por que não tem nada em aberto, dai coloca na grade
                    End If
                    'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
                    lstrNrCpf = Trim(IIf(IsDBNull(row.Item("cpf_cnpj")), "", row.Item("cpf_cnpj")))
                    If VB.Left(lstrGrupo, 1) = "B" Then
                        lstrNrNis = BuscaNis(lstrZona, lstrLivro, lstrConta, llngUnidId, lstrNrCpf)
                    Else
                        lstrNrNis = ""
                    End If
                    If Me.chkFaturadoEm.CheckState = System.Windows.Forms.CheckState.Checked And Me.chkSomenteMesAno.CheckState = System.Windows.Forms.CheckState.Unchecked Then
                        lblnContinua = VerificaFaturamento(lstrGrupo, lstrZona, lstrLivro, lstrConta, llngUnidId)
                    End If
                    If lblnContinua Then
                        lstrSql = ""
                        lstrSql = lstrSql & "SELECT "
                        lstrSql = lstrSql & "       nf.numnf, "
                        lstrSql = lstrSql & "       nf.mesano_ref, "
                        lstrSql = lstrSql & "       nf.cons_id, "
                        lstrSql = lstrSql & "       nf.unid_id, "
                        lstrSql = lstrSql & "       nf.zona, "
                        lstrSql = lstrSql & "       nf.livro, "
                        lstrSql = lstrSql & "       nf.conta, "
                        lstrSql = lstrSql & "       nf.dataleit, "
                        lstrSql = lstrSql & "       nf.ta, "
                        lstrSql = lstrSql & "       nf.codclas, "
                        lstrSql = lstrSql & "       nf.itensserv "
                        lstrSql = lstrSql & "  FROM nf "
                        lstrSql = lstrSql & " WHERE nf.zona    = '" & lstrZona & "' "
                        lstrSql = lstrSql & "   AND nf.livro   = '" & lstrLivro & "' "
                        lstrSql = lstrSql & "   AND nf.conta   = '" & lstrConta & "' "
                        lstrSql = lstrSql & "   AND nf.cons_id =  " & llngConsId & " "
                        lstrSql = lstrSql & "   AND nf.unid_id =  " & llngUnidId & " "
                        lstrSql = lstrSql & "   AND nf.grupo   = '" & VB.Left(lstrGrupo, 1) & "' "
                        If Me.chkMesAno.CheckState = System.Windows.Forms.CheckState.Checked Then
                            lstrSql = lstrSql & "   AND nf.mesano_ref <= " & CInt(VB6.Format(Me.dtpMesAno.Value, "yyyyMM"))
                        ElseIf Me.chkSomenteMesAno.CheckState = System.Windows.Forms.CheckState.Checked Then
                            lstrSql = lstrSql & "   AND nf.mesano_ref = " & CInt(VB6.Format(Me.dtpFaturadoEm.Value, "yyyyMM"))
                        End If
                        lstrSql = lstrSql & " ORDER BY nf.mesano_ref DESC LIMIT 0, 12 "
                        ' Call Conectar(lstrSql, lrstFat)
                        objAtualizaBancoDados.QUERY_NAME = lstrSql
                        dt3 = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

                        If dt3.Rows.Count > 0 Then
                            lintAux = 1
                            For Each row3 As DataRow In dt3.Rows

                                ldblNumNf = CDbl(IIf(IsDBNull(row3.Item("numnf").value), 0, row3.Item("numnf").value))
                                llngMesano = CInt(IIf(IsDBNull(row3.Item("mesano_ref").value), 0, row3.Item("mesano_ref").value))
                                ldteLeitura = CDate(IIf(IsDBNull(row3.Item("dataleit").value), "1900-01-01", row3.Item("dataleit").value))
                                lstrGruTar = Trim(IIf(IsDBNull(row3.Item("ta").value), "01B100", row3.Item("ta").value))
                                lstrClasFat = Trim(IIf(IsDBNull(row3.Item("codclas").value), "9101", row3.Item("codclas").value))
                                lstrItens = Trim(IIf(IsDBNull(row3.Item("itensserv").value), "", row3.Item("itensserv").value))
                                If VB.Left(lstrGrupo, 1) = "B" Then
                                    ldblkWhFat(lintAux) = BuscaVlrItem(lstrItens, "030201009")
                                    ldblVlrkWhFat(lintAux) = BuscaVlrItem(lstrItens, "030202009")
                                Else
                                    If Mid(lstrGruTar, 3, 2) = "A4" Or Mid(lstrGruTar, 3, 2) = "AS" Then
                                        ldblkWhFat(lintAux) = BuscaVlrItem(lstrItens, "0302010009")
                                        ldblVlrkWhFat(lintAux) = BuscaVlrItem(lstrItens, "0302020009")
                                    Else
                                        ldblkWhFat(lintAux) = BuscaVlrItem(lstrItens, "0302010010") + BuscaVlrItem(lstrItens, "0302010011")
                                        ldblVlrkWhFat(lintAux) = BuscaVlrItem(lstrItens, "0302020010") + BuscaVlrItem(lstrItens, "0302020011")
                                    End If
                                End If
                                ldblIcms(lintAux) = BuscaVlrItem(lstrItens, "0302030009") + BuscaVlrItem(lstrItens, "0302030010")
                                ldblPis(lintAux) = BuscaVlrItem(lstrItens, "0302020029")
                                ldblCofins(lintAux) = BuscaVlrItem(lstrItens, "0302020030")
                                Call ComponentesFatura(llngMesano, lstrGruTar, lstrClasFat, lstrItens, ldteLeitura, ldblEnergia(lintAux), ldblTransimissao(lintAux), ldblDistribuicao(lintAux), ldblEncSet(lintAux), ldblPerdas(lintAux), ldblTriIcms(lintAux), ldblTriPiCo(lintAux))
                                lintAux = lintAux + 1
                            Next
                        End If

                        lstrSql = ""
                        lstrSql = lstrSql & "INSERT INTO `AUX_RELPEE` SET " & vbCrLf
                        lstrSql = lstrSql & "  `nomemaquina`   = '" & My.Computer.Name & "'," & vbCrLf
                        lstrSql = lstrSql & "  `bairro`        = '" & Replace(lstrEndBai, "'", "\'") & "'," & vbCrLf
                        lstrSql = lstrSql & "  `identificacao` = '" & lstrZona & "." & lstrLivro & "." & lstrConta & "'," & vbCrLf
                        lstrSql = lstrSql & "  `caderno`       = '" & VB.Left(lstrRota, 4) & "'," & vbCrLf
                        lstrSql = lstrSql & "  `sequencia`     = '" & VB.Right(lstrRota, 4) & "'," & vbCrLf
                        lstrSql = lstrSql & "  `classe`        = '" & Replace(BuscaClasse(lstrClas), "'", "\'") & "'," & vbCrLf
                        lstrSql = lstrSql & "  `nome`          = '" & Replace(lstrNome, "'", "\'") & "'," & vbCrLf
                        lstrSql = lstrSql & "  `end_log`       = '" & Replace(lstrEndLog, "'", "\'") & "'," & vbCrLf
                        lstrSql = lstrSql & "  `end_num`       = '" & Replace(lstrEndNum, "'", "\'") & "'," & vbCrLf
                        lstrSql = lstrSql & "  `end_com`       = '" & Replace(lstrEndCom, "'", "\'") & "'," & vbCrLf
                        lstrSql = lstrSql & "  `end_cid`       = '" & Replace(lstrEndCid, "'", "\'") & "'," & vbCrLf
                        lstrSql = lstrSql & "  `end_dis`       = '" & Replace(lstrEndDis, "'", "\'") & "'," & vbCrLf
                        lstrSql = lstrSql & "  `medidor`       = '" & lstrMedidor & "'," & vbCrLf
                        lstrSql = lstrSql & "  `regiao`        = '" & IIf(lstrRegiao = "R", "Rural", "Urbana") & "'," & vbCrLf
                        lstrSql = lstrSql & "  `fase`          = '" & IIf(lstrFase = "M", "Monofásico", IIf(lstrFase = "B", "Bifásico", "Trifásico")) & "'," & vbCrLf
                        lstrSql = lstrSql & "  `situacao`      = '" & IIf(lstrSituacao = "L", "Ligado", IIf(lstrSituacao = "D", "Desligado", IIf(lstrSituacao = "C", "Suspenso", IIf(lstrSituacao = "I", "Desativado", "Não Ligado")))) & "'," & vbCrLf
                        lstrSql = lstrSql & "  `grupo`         = '" & lstrGrupo & "'," & vbCrLf
                        For lintAux = 1 To 12
                            lstrSql = lstrSql & "  `mes_" & VB6.Format(lintAux, "00") & "`    = " & Replace(CStr(ldblkWhFat(lintAux)), ",", ".") & "," & vbCrLf
                            lstrSql = lstrSql & "  `vlr_" & VB6.Format(lintAux, "00") & "`    = " & Replace(CStr(ldblVlrkWhFat(lintAux)), ",", ".") & "," & vbCrLf
                            lstrSql = lstrSql & "  `icms_" & VB6.Format(lintAux, "00") & "`   = " & Replace(CStr(ldblIcms(lintAux)), ",", ".") & "," & vbCrLf
                            lstrSql = lstrSql & "  `pis_" & VB6.Format(lintAux, "00") & "`    = " & Replace(CStr(ldblPis(lintAux)), ",", ".") & "," & vbCrLf
                            lstrSql = lstrSql & "  `cofins_" & VB6.Format(lintAux, "00") & "` = " & Replace(CStr(ldblCofins(lintAux)), ",", ".") & "," & vbCrLf
                            lstrSql = lstrSql & "  `ene_" & VB6.Format(lintAux, "00") & "`    = " & Replace(CStr(ldblEnergia(lintAux)), ",", ".") & "," & vbCrLf
                            lstrSql = lstrSql & "  `tra_" & VB6.Format(lintAux, "00") & "`    = " & Replace(CStr(ldblTransimissao(lintAux)), ",", ".") & "," & vbCrLf
                            lstrSql = lstrSql & "  `dis_" & VB6.Format(lintAux, "00") & "`    = " & Replace(CStr(ldblDistribuicao(lintAux)), ",", ".") & "," & vbCrLf
                            lstrSql = lstrSql & "  `enc_" & VB6.Format(lintAux, "00") & "`    = " & Replace(CStr(ldblEncSet(lintAux)), ",", ".") & "," & vbCrLf
                            lstrSql = lstrSql & "  `per_" & VB6.Format(lintAux, "00") & "`    = " & Replace(CStr(ldblPerdas(lintAux)), ",", ".") & "," & vbCrLf
                            lstrSql = lstrSql & "  `tic_" & VB6.Format(lintAux, "00") & "`    = " & Replace(CStr(ldblTriIcms(lintAux)), ",", ".") & "," & vbCrLf
                            lstrSql = lstrSql & "  `tpc_" & VB6.Format(lintAux, "00") & "`    = " & Replace(CStr(ldblTriPiCo(lintAux)), ",", ".") & "," & vbCrLf
                        Next lintAux
                        lstrSql = lstrSql & "  `nis`           = '" & lstrNrNis & "';" & vbCrLf
                        objExecAtualizaBancoDados.QUERY_NAME = lstrSql
                        repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)
                    End If
                    'Call .MoveNext()
                    Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
                Next
            End If

            ''UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
            'lrstAux = Nothing
            ''UPGRADE_NOTE: Object lrstFat may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
            'lrstFat = Nothing

        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: EncheGrade" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try
    End Sub
    Private Sub ComponentesFatura(ByVal alngMesAno As Integer, ByVal astrGruTar As String, ByVal astrClasse As String, ByVal astrItens As String, ByVal adteLeitura As Date, ByRef adblVlrEnergia As Double, ByRef adblVlrTransmissao As Double, ByRef adblVlrDistribuicao As Double, ByRef adblVlrEncSetoriais As Double, ByRef adblVlrPerdas As Double, ByRef adblVlrTributosIcms As Double, ByRef adblVlrTributosPisCof As Double)

        'Revisado OK
        Dim lstrGruTar As String
        Dim lstrItens As String
        Dim lstrRet As String
        Dim lstrCodigo As String
        Dim lstrMesAnoAux As String
        Dim lstrMesAnoOld As String
        '
        Dim ldblPerEnergia As Double 'Percentual
        Dim ldblPerTransmissao As Double 'Percentual
        Dim ldblPerDistribuicao As Double 'Percentual
        Dim ldblPerEncSetoriais As Double 'Percentual
        Dim ldblPerPerdas As Double 'Percentual
        Dim ldblPerTributosIcms As Double 'Percentual
        Dim ldblPerTributosPisCof As Double 'Percentual
        '
        Dim ldblVlrEnergia As Double 'valor
        Dim ldblVlrTransmissao As Double 'valor
        Dim ldblVlrDistribuicao As Double 'valor
        Dim ldblVlrEncSetoriais As Double 'valor
        Dim ldblVlrPerdas As Double 'valor
        Dim ldblVlrTributosIcms As Double 'valor
        Dim ldblVlrTributosPisCof As Double 'valor
        '
        Dim ldblItenValor As Double
        Dim lstrSql As String
        Try
            'Dim lrstAux As ADODB.Recordset
            ' lrstAux = New ADODB.Recordset
            ldblVlrEnergia = 0
            ldblVlrTransmissao = 0
            ldblVlrDistribuicao = 0
            ldblVlrEncSetoriais = 0
            ldblVlrPerdas = 0
            ldblVlrTributosIcms = 0
            ldblVlrTributosPisCof = 0
            '
            Call GetTarifasComposicao(adteLeitura, ldblPerEnergia, ldblPerTransmissao, ldblPerDistribuicao, ldblPerEncSetoriais, ldblPerPerdas, ldblPerTributosIcms, ldblPerTributosPisCof)
            '
            lstrMesAnoAux = ""
            lstrMesAnoOld = ""
            lstrRet = ""
            lstrGruTar = astrGruTar
            lstrItens = astrItens
            If CDbl(VB.Left(astrClasse, 1)) = 9 And CDbl(VB.Right(astrClasse, 1)) <> 1 Then
                lstrGruTar = VB.Left(lstrGruTar, 5) & 2
            End If
            lstrSql = ""
            lstrSql = lstrSql & "  SELECT * "
            lstrSql = lstrSql & "    FROM `composicao` "
            lstrSql = lstrSql & "   WHERE `referencia` <= " & alngMesAno & " "
            lstrSql = lstrSql & "     AND `ta` = '" & lstrGruTar & "' "
            lstrSql = lstrSql & "ORDER BY `referencia` DESC, `codigo` ASC "
            'Call Conectar(lstrSql, lrstAux)

            objAtualizaBancoDados.QUERY_NAME = lstrSql
            dtinterno = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

            If dtinterno.Rows.Count > 0 Then
                For Each row As DataRow In dtinterno.Rows
                    'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
                    lstrMesAnoAux = IIf(IsDBNull(row.Item("mesano")), "", row.Item("mesano"))
                    If Len(Trim(lstrMesAnoOld)) = 0 Then
                        lstrMesAnoOld = lstrMesAnoAux
                    End If
                    If lstrMesAnoAux = lstrMesAnoOld Then
                        'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
                        lstrCodigo = Trim(IIf(IsDBNull(row.Item("codigo")), "", row.Item("codigo")))
                        '
                        'Calculo do rateio
                        '
                        ldblItenValor = BuscaVlrItem(lstrItens, lstrCodigo)
                        If ldblItenValor <> 0 Then
                            ldblVlrEnergia = ldblVlrEnergia + (ldblItenValor * (ldblPerEnergia / 100))
                            ldblVlrTransmissao = ldblVlrTransmissao + (ldblItenValor * (ldblPerTransmissao / 100))
                            ldblVlrDistribuicao = ldblVlrDistribuicao + (ldblItenValor * (ldblPerDistribuicao / 100))
                            ldblVlrEncSetoriais = ldblVlrEncSetoriais + (ldblItenValor * (ldblPerEncSetoriais / 100))
                            ldblVlrPerdas = ldblVlrPerdas + (ldblItenValor * (ldblPerPerdas / 100))
                            ldblVlrTributosIcms = ldblVlrTributosIcms + (ldblItenValor * (ldblPerTributosIcms / 100))
                            ldblVlrTributosPisCof = ldblVlrTributosPisCof + (ldblItenValor * (ldblPerTributosPisCof / 100))
                        End If
                        ' Call .MoveNext()
                    Else
                        'Call .MoveLast()
                        'Call .MoveNext()
                    End If
                Next
            End If


            If (ldblVlrEnergia + ldblVlrTransmissao + ldblVlrDistribuicao + ldblVlrEncSetoriais + ldblVlrPerdas + ldblVlrTributosIcms + ldblVlrTributosPisCof) <> 0 Then
                adblVlrEnergia = ldblVlrEnergia
                adblVlrTransmissao = ldblVlrTransmissao
                adblVlrDistribuicao = ldblVlrDistribuicao
                adblVlrEncSetoriais = ldblVlrEncSetoriais
                adblVlrPerdas = ldblVlrPerdas
                adblVlrTributosIcms = ldblVlrTributosIcms
                adblVlrTributosPisCof = ldblVlrTributosPisCof
            End If
            'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
            'lrstAux = Nothing

        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: ComponentesFatura" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try
    End Sub

    Private Sub CarregaClasses(ByRef alsvAuxiliar As System.Windows.Forms.ListView)

        Try
            Dim lstrNome As String
            Dim lstrZona As String
            With Me.lsvClasses
                Call .Items.Clear()
                If .Columns.Count <= 1 Then
                    Call .Columns.Add("", "Descrição", CInt(VB6.TwipsToPixelsX(5490)))
                    Call .Columns.Add("", "Condição", CInt(VB6.TwipsToPixelsX(0)))
                End If
                ' Call .Items.Add("Marcar Todas")
                'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                'Call .Items.Item(.Items.Count).SubItems.Add(" = 0")
                Call .Items.Add("Residencial")
                'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                Call .Items.Item(.Items.Count - 1).SubItems.Add(" = 9101")
                Call .Items.Add("Industrial")
                'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                Call .Items.Item(.Items.Count - 1).SubItems.Add(" < 4")
                Call .Items.Add("Livre")
                'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                Call .Items.Item(.Items.Count - 1).SubItems.Add(" = 0100")
                Call .Items.Add("Comercial")
                'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                Call .Items.Item(.Items.Count - 1).SubItems.Add(" = 4")
                Call .Items.Add("Rural")
                'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                Call .Items.Item(.Items.Count - 1).SubItems.Add(" = 5")
                Call .Items.Add("Poder Público Municipal")
                'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                Call .Items.Item(.Items.Count - 1).SubItems.Add(" = 61")
                Call .Items.Add("Poder Público Estadual")
                'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                Call .Items.Item(.Items.Count - 1).SubItems.Add(" = 62")
                Call .Items.Add("Poder Público Federal")
                'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                Call .Items.Item(.Items.Count - 1).SubItems.Add(" = 63")
                Call .Items.Add("Iluminação Pública")
                'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                Call .Items.Item(.Items.Count - 1).SubItems.Add(" = 64")
                Call .Items.Add("Serviço Púplico")
                'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                Call .Items.Item(.Items.Count - 1).SubItems.Add(" = 7")
                Call .Items.Add("Consumo Próprio")
                'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                Call .Items.Item(.Items.Count - 1).SubItems.Add(" = 8")
                'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                .Items.Item(0).Font = VB6.FontChangeBold(.Items.Item(1).Font, True)
                'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                ' .Items.Item(0).Checked = True
                'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                'Call lsvClasses_ItemCheck(lsvClasses, New System.Windows.Forms.ItemCheckEventArgs(.Items.Item(1).Index, System.Windows.Forms.CheckState.Indeterminate, .Items.Item(1).Checked))
            End With
            System.Windows.Forms.Application.DoEvents()

        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: CarregaClasses" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try
    End Sub
    Private Sub CarregaRotas()

        Try
            Dim lstrRota As String
            Dim llngLigados As Integer
            Dim llngNaoLigados As Integer
            Dim lstrSql As String
            ' Dim lrstAux As ADODB.Recordset
            ' lrstAux = New ADODB.Recordset
            With Me.lsvRotas
                Call .Items.Clear()
                Call .Columns.Clear()
                If .Columns.Count <= 1 Then
                    Call .Columns.Add("", "Rota", CInt(VB6.TwipsToPixelsX(2100)))
                    Call .Columns.Add("Ligados", CInt(VB6.TwipsToPixelsX(1700)), System.Windows.Forms.HorizontalAlignment.Right)
                    Call .Columns.Add("Não Ligados", CInt(VB6.TwipsToPixelsX(1700)), System.Windows.Forms.HorizontalAlignment.Right)
                End If
            End With
            lstrSql = ""
            lstrSql = lstrSql & "SELECT LEFT(`uc_faturamento`.`rota`, 4) AS `rotaunid`, " & vbCrLf
            lstrSql = lstrSql & "       SUM(IF(`uc_faturamento`.`situacao` = 'L', 1, 0)) AS `ligados`, " & vbCrLf
            lstrSql = lstrSql & "       SUM(IF(`uc_faturamento`.`situacao` <> 'L', 1, 0)) AS `naoligados` " & vbCrLf
            lstrSql = lstrSql & "  FROM `uc_faturamento` " & vbCrLf
            lstrSql = lstrSql & " WHERE TRIM(`uc_faturamento`.`rota`) <> '' " & vbCrLf
            lstrSql = lstrSql & "   AND LEFT(`uc_faturamento`.`rota`, 4) <> '9999' " & vbCrLf
            lstrSql = lstrSql & " GROUP BY 1 " & vbCrLf
            'lstrSql = lstrSql & "UNION " & vbCrLf
            'lstrSql = lstrSql & "SELECT LEFT(`unida`.`rota`, 4) AS `rotaunid`, " & vbCrLf
            'lstrSql = lstrSql & "       SUM(IF(`unida`.`situacao` = 'L', 1, 0)) AS `ligados`, " & vbCrLf
            'lstrSql = lstrSql & "       SUM(IF(`unida`.`situacao` <> 'L', 1, 0)) AS `naoligados` " & vbCrLf
            'lstrSql = lstrSql & "  FROM `unida` " & vbCrLf
            'lstrSql = lstrSql & " WHERE TRIM(`unida`.`rota`) <> '' " & vbCrLf
            'lstrSql = lstrSql & "   AND LEFT(`unida`.`rota`, 4) <> '9999' " & vbCrLf
            'lstrSql = lstrSql & " GROUP BY 1 " & vbCrLf
            lstrSql = lstrSql & " ORDER BY 1 ASC"
            objAtualizaBancoDados.QUERY_NAME = lstrSql
            dt = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)
            'Call Conectar(lstrSql, lrstAux)

            ' ----- Insere os dados na ListView de rotas

            If dt.Rows.Count > 0 Then
                'With Me.lsvRotas
                '    Call .Items.Add("Marcar Todas")
                '    Call .Items.Item(.Items.Count).SubItems.Add("")
                '    Call .Items.Item(.Items.Count).SubItems.Add("")
                'End With
                For Each row As DataRow In dt.Rows
                    'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
                    lstrRota = VB6.Format(IIf(IsDBNull(row.Item("rotaunid")), "0", row.Item("rotaunid")), "0000")
                    'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
                    llngLigados = IIf(IsDBNull(row.Item("ligados")), 0, row.Item("ligados"))
                    'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
                    llngNaoLigados = IIf(IsDBNull(row.Item("naoligados")), 0, row.Item("naoligados"))
                    With Me.lsvRotas
                        Call .Items.Add(lstrRota)
                        'UPGRADE_WARNING: Lower bound of collection Me.lsvRotas.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                        Call .Items.Item(.Items.Count - 1).SubItems.Add(CStr(llngLigados))
                        'UPGRADE_WARNING: Lower bound of collection Me.lsvRotas.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                        Call .Items.Item(.Items.Count - 1).SubItems.Add(CStr(llngNaoLigados))
                    End With
                Next
            End If

            'UPGRADE_WARNING: Lower bound of collection Me.lsvRotas.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
            Me.lsvRotas.Items.Item(0).Font = VB6.FontChangeBold(Me.lsvRotas.Items.Item(1).Font, True)
            'UPGRADE_WARNING: Lower bound of collection Me.lsvRotas.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
            ' Me.lsvRotas.Items.Item(0).Checked = True
            'UPGRADE_WARNING: Lower bound of collection Me.lsvRotas.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
            'Call lsvRotas_ItemCheck(lsvRotas, New System.Windows.Forms.ItemCheckEventArgs(Me.lsvRotas.Items.Item(1).Index, System.Windows.Forms.CheckState.Indeterminate, Me.lsvRotas.Items.Item(1).Checked))
            ''UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
            'lrstAux = Nothing
            System.Windows.Forms.Application.DoEvents()

        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: CarregaRotas" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try
    End Sub

    Private Function MontaFiltroRotas() As String
        Try
            Dim lstrAux As String
            Dim lintIdx As Short
            lstrAux = ""
            With Me.lsvRotas
                'UPGRADE_WARNING: Lower bound of collection Me.lsvRotas.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                If .Items.Item(1).Checked = False Then
                    For lintIdx = 0 To .Items.Count - 1
                        'UPGRADE_WARNING: Lower bound of collection Me.lsvRotas.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                        If .Items.Item(lintIdx).Checked = True Then
                            'UPGRADE_WARNING: Lower bound of collection Me.lsvRotas.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                            lstrAux = lstrAux & "'" & .Items.Item(lintIdx).Text & "',"
                        End If
                    Next lintIdx
                    If Len(Trim(lstrAux)) > 0 Then
                        lstrAux = " (" & VB.Left(lstrAux, Len(lstrAux) - 1) & ") "
                    End If
                    If Len(Trim(lstrAux)) > 0 Then
                        lstrAux = " AND LEFT(`rota`, 4) IN " & lstrAux & " "
                    End If
                End If
            End With
            MontaFiltroRotas = lstrAux

        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: MontaFiltroRotas" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Function
        End Try
    End Function

    Private Function MontaFiltroClasse() As String

        Try
            Dim lstrAux1 As String
            Dim lstrAux2 As String
            Dim lintIdx As Short
            lstrAux1 = ""
            lstrAux2 = ""
            With Me.lsvClasses
                'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                If .Items.Item(1).Checked = False Then
                    lstrAux1 = " AND ("
                    For lintIdx = 0 To .Items.Count - 1
                        'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                        If .Items.Item(lintIdx).Checked = True Then
                            'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                            'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.ListItems.Item() has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                            lstrAux1 = lstrAux1 & " LEFT(`clas`," & Len(Trim(Str_Retira(.Items.Item(lintIdx).SubItems(1).Text, "<="))) & ")" & .Items.Item(lintIdx).SubItems(1).Text & " OR "
                            'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
                            If Trim(.Items.Item(lintIdx).Text) = "Industrial" And .Items.Item(4).Checked = False Then
                                lstrAux2 = " AND `clas` <> 0100 "
                            Else
                                lstrAux2 = ""
                            End If
                        End If
                    Next lintIdx
                    If lstrAux1 = " AND (" Then
                        lstrAux1 = ""
                        lstrAux2 = ""
                    Else
                        lstrAux1 = VB.Left(lstrAux1, Len(lstrAux1) - 3) & ") "
                    End If
                End If
            End With
            MontaFiltroClasse = lstrAux1 & lstrAux2

        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: MontaFiltroClasse" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Function
        End Try
    End Function

    Private Function BuscaClasse(ByVal astrClasse As String) As String
        Try
            Select Case CInt(VB.Left(astrClasse, 1))
                Case Is = 9
                    BuscaClasse = "Residencial"
                Case Is < 4
                    If astrClasse = "0100" Then
                        BuscaClasse = "Livre"
                    Else
                        BuscaClasse = "Industrial"
                    End If
                Case Is = 4
                    BuscaClasse = "Comercial"
                Case Is = 5
                    BuscaClasse = "Rural"
                Case Is = 6
                    If CInt(VB.Left(astrClasse, 2)) = 61 Then
                        BuscaClasse = "Poder Público Municipal"
                    ElseIf CInt(VB.Left(astrClasse, 2)) = 62 Then
                        BuscaClasse = "Poder Público Estadual"
                    ElseIf CInt(VB.Left(astrClasse, 2)) = 63 Then
                        BuscaClasse = "Poder Público Federal"
                    ElseIf CInt(VB.Left(astrClasse, 2)) = 64 Then
                        BuscaClasse = "Iluminação Pública"
                    End If
                Case Is = 7
                    BuscaClasse = "Serviço Púplico"
                Case Is = 8
                    BuscaClasse = "Consumo Próprio"
                Case Else
                    BuscaClasse = "----------"
            End Select

        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: BuscaClasse" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Function
        End Try
    End Function

    Private Sub ImprimirPee()
        Dim lstrSql As String
        Dim llngRow As Integer
        Dim lstrAux As String
        Dim lstrCri As String

        Try
            '
            ' lstrCri = "{AUX_RELPEE.nomemaquina} = '" & gstrNmEstacao & "' "
            sTitulo = " Grupo (A, B"
            'If Me.chkGrupoA.CheckState = System.Windows.Forms.CheckState.Checked Then
            '    sTitulo = sTitulo & "A"
            'End If
            'If Me.chkGrupoB.CheckState = 1 Then
            '    sTitulo = sTitulo & "B"
            'End If
            sTitulo = sTitulo & ") - Situação ("
            If Me.chkLigados.CheckState = System.Windows.Forms.CheckState.Checked Then
                sTitulo = sTitulo & "L,"
            End If
            If Me.chkCortados.CheckState = System.Windows.Forms.CheckState.Checked Then
                sTitulo = sTitulo & "C,"
            End If
            If Me.chkDesligados.CheckState = System.Windows.Forms.CheckState.Checked Then
                sTitulo = sTitulo & "D,"
            End If
            If Me.chkDesativados.CheckState = System.Windows.Forms.CheckState.Checked Then
                sTitulo = sTitulo & "I,"
            End If
            sTitulo = VB.Left(sTitulo, Len(sTitulo) - 1) & ")"

            Call sDadosEmpresa(LImagem, sNomeEmpresa, sEnderecoEmpresa, sCepEmpresa, sCidadeEmpresa, sUFempresa, sBairroEmpresa, sFoneEmpresa, sWebEmpresa)
            Call lPrint("rptRelPee")

        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: ImprimirPee" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try
    End Sub

    Private Function BuscaNis(ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String, ByVal alngUnidId As Integer, ByVal astrCpf As String) As String
        Dim lstrRet As String
        Dim lstrSql As String
        Try
            lstrRet = ""
            lstrSql = ""
            lstrSql = lstrSql & "SELECT " & vbCrLf
            lstrSql = lstrSql & "       `nis`.`cpf`, " & vbCrLf
            lstrSql = lstrSql & "       `nis`.`zona`, " & vbCrLf
            lstrSql = lstrSql & "       `nis`.`livro`, " & vbCrLf
            lstrSql = lstrSql & "       `nis`.`conta`, " & vbCrLf
            lstrSql = lstrSql & "       `nis`.`unid_id`, " & vbCrLf
            lstrSql = lstrSql & "       `nis`.`nis`, " & vbCrLf
            lstrSql = lstrSql & "       `nis`.`evento` " & vbCrLf
            lstrSql = lstrSql & "  FROM `nis` " & vbCrLf
            lstrSql = lstrSql & " WHERE `nis`.`cpf`     = '" & astrCpf & "' " & vbCrLf
            lstrSql = lstrSql & "   AND `nis`.`zona`    = '" & astrZona & "' " & vbCrLf
            lstrSql = lstrSql & "   AND `nis`.`livro`   = '" & astrLivro & "' " & vbCrLf
            lstrSql = lstrSql & "   AND `nis`.`conta`   = '" & astrConta & "' " & vbCrLf
            lstrSql = lstrSql & "   AND `nis`.`unid_id` = " & alngUnidId & vbCrLf
            lstrSql = lstrSql & "   AND `nis`.`evento` <> 'D' " & vbCrLf
            lstrSql = lstrSql & "   AND `nis`.`nis` <> '' " & vbCrLf
            objAtualizaBancoDados.QUERY_NAME = lstrSql
            dtinterno = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

            If dtinterno.Rows.Count > 0 Then
                For Each rowinterno As DataRow In dtinterno.Rows
                    lstrRet = Trim(IIf(IsDBNull(rowinterno.Item("nis")), "", rowinterno.Item("nis")))
                Next
            End If

            dtinterno = Nothing

            BuscaNis = lstrRet

        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: BuscaNis" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Function
        End Try
    End Function

    Private Function Pedente(ByVal alngConsId As Object) As Boolean
        Dim lblnRet As Boolean
        Dim lstrSql As String

        Try

            lblnRet = False
            lstrSql = ""
            lstrSql = lstrSql & "SELECT numnf, mesano, mesano_ref, zona, livro, conta, cons_id, unid_id, flgst, datavenc "
            lstrSql = lstrSql & "  FROM nf "
            'UPGRADE_WARNING: Couldn't resolve default property of object alngConsId. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            lstrSql = lstrSql & " WHERE nf.cons_id = " & alngConsId
            lstrSql = lstrSql & "   AND nf.flgst = '' "
            lstrSql = lstrSql & "   AND nf.datavenc < '" & VB6.Format(Date.Now, "yyyy-MM-dd") & "' "
            lstrSql = lstrSql & "  LIMIT 0, 1 "
            'Call Conectar(lstrSql, lrstAux)
            objAtualizaBancoDados.QUERY_NAME = lstrSql
            dtinterno = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

            lblnRet = (dtinterno.Rows.Count > 0)

            dtinterno = Nothing

            'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
            'lrstAux = Nothing
            Pedente = lblnRet

        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: Pedente" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Function
        End Try

    End Function

    Private Sub chkrotas_CheckedChanged(sender As Object, e As EventArgs) Handles chkrotas.CheckedChanged
        Dim intConta As Short

        Try
            If chkrotas.Checked = True Then
                For intConta = 0 To lsvRotas.Items.Count - 1
                    lsvRotas.Items.Item(intConta).Checked = True
                Next

            ElseIf chkrotas.Checked = False Then
                For intConta = 0 To lsvRotas.Items.Count - 1
                    lsvRotas.Items.Item(intConta).Checked = False
                Next intConta
            End If

        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: chkrotas_CheckedChanged" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try
    End Sub

    Private Sub chkClasses_CheckedChanged(sender As Object, e As EventArgs) Handles chkClasses.CheckedChanged
        Dim intConta As Short

        Try
            If chkClasses.Checked = True Then
                For intConta = 0 To lsvClasses.Items.Count - 1
                    lsvClasses.Items.Item(intConta).Checked = True
                Next

            ElseIf chkClasses.Checked = False Then
                For intConta = 0 To lsvClasses.Items.Count - 1
                    lsvClasses.Items.Item(intConta).Checked = False
                Next intConta
            End If

        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: chkClasses_CheckedChanged" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try
    End Sub



    Private Sub LigDes(ByVal ablnModo As Boolean)
        Try
            Me.chkGrupoA.Enabled = ablnModo
            Me.chkGrupoB.Enabled = ablnModo
            Me.chkLigados.Enabled = ablnModo
            Me.chkDesligados.Enabled = ablnModo
            Me.chkCortados.Enabled = ablnModo
            Me.chkDesativados.Enabled = ablnModo
            Me.chkMesAno.Enabled = ablnModo
            Me.chkFaturadoEm.Enabled = ablnModo
            Me.dtpMesAno.Enabled = ablnModo
            Me.chkSomenteMesAno.Enabled = IIf(Me.chkFaturadoEm.Enabled And Me.chkFaturadoEm.CheckState = System.Windows.Forms.CheckState.Checked, True, False)
            If Me.dtpMesAno.Enabled Then
                Me.dtpMesAno.Enabled = (Me.chkMesAno.CheckState = System.Windows.Forms.CheckState.Checked)
            End If
            Me.dtpFaturadoEm.Enabled = ablnModo
            If Me.dtpMesAno.Enabled Then
                Me.dtpFaturadoEm.Enabled = (Me.chkFaturadoEm.CheckState = System.Windows.Forms.CheckState.Checked)
            End If
            Me.chkEmDia.Enabled = ablnModo
            Me.lsvRotas.Enabled = ablnModo
            Me.lsvClasses.Enabled = ablnModo
            Me.cmdProcessar.Enabled = ablnModo
            Me.cmdExporta.Enabled = ablnModo
            Me.cmdImprimir.Enabled = ablnModo
            Me.cmdFechar.Enabled = ablnModo
            Me.cmdArquivo.Enabled = ablnModo

        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: LigDes" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try
    End Sub


    Private Function VerificaFaturamento(ByVal astrGrupo As String, ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String, ByVal alngUnidId As Integer) As Boolean
        Dim lblnRet As Boolean
        Dim lstrSql As String

        Try
            lblnRet = False
            lstrSql = ""
            lstrSql = lstrSql & "   SELECT * " & vbCrLf
            lstrSql = lstrSql & "     FROM `nf` " & vbCrLf
            lstrSql = lstrSql & "    WHERE `nf`.`zona`       = '" & astrZona & "' " & vbCrLf
            lstrSql = lstrSql & "      AND `nf`.`livro`      = '" & astrLivro & "' " & vbCrLf
            lstrSql = lstrSql & "      AND `nf`.`conta`      = '" & astrConta & "' " & vbCrLf
            lstrSql = lstrSql & "      AND `nf`.`unid_id`    = '" & alngUnidId & "' " & vbCrLf
            lstrSql = lstrSql & "      AND `nf`.`grupo`      = '" & VB.Left(astrGrupo, 1) & "' " & vbCrLf
            lstrSql = lstrSql & "      AND `nf`.`mesano_ref` = " & CInt(VB6.Format(Me.dtpFaturadoEm.Value, "YYYYMM")) & " " & vbCrLf
            lstrSql = lstrSql & "    LIMIT 0, 1 "
            objAtualizaBancoDados.QUERY_NAME = lstrSql
            dtinterno = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

            lblnRet = (dtinterno.Rows.Count > 0)

            dtinterno = Nothing

            VerificaFaturamento = lblnRet

        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: VerificaFaturamento" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Function
        End Try
    End Function

    Private Sub sCriaTabelaAuxiliar()
        Try
            Dim lstrsql As String

            objExecAtualizaBancoDados.QUERY_NAME = "drop table if exists AUX_RELPEE"
            repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

            lstrsql = ""
            lstrsql = lstrsql & "CREATE TABLE IF NOT EXISTS `AUX_RELPEE` (" & vbCrLf
            lstrsql = lstrsql & "  `nomemaquina`   varchar(255) NOT NULL DEFAULT ''," & vbCrLf
            lstrsql = lstrsql & "  `bairro`        varchar(60) DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `identificacao` varchar(13) DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `caderno`       varchar(4) DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `sequencia`     varchar(4) DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `classe`        varchar(60) DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `nome`          varchar(85) DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `end_log`       varchar(60) DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `end_num`       varchar(10) DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `end_com`       varchar(100) DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `end_cid`       varchar(60) DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `end_dis`       varchar(60) DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `medidor`       varchar(11) DEFAULT ''," & vbCrLf
            lstrsql = lstrsql & "  `regiao`        varchar(10) DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `fase`          varchar(10) DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `situacao`      varchar(10) DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `grupo`         char(2) DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `nis`           varchar(15) DEFAULT NULL," & vbCrLf
            '
            lstrsql = lstrsql & "  `mes_01`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `mes_02`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `mes_03`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `mes_04`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `mes_05`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `mes_06`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `mes_07`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `mes_08`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `mes_09`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `mes_10`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `mes_11`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `mes_12`        double DEFAULT NULL," & vbCrLf
            '
            lstrsql = lstrsql & "  `vlr_01`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `vlr_02`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `vlr_03`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `vlr_04`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `vlr_05`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `vlr_06`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `vlr_07`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `vlr_08`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `vlr_09`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `vlr_10`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `vlr_11`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `vlr_12`        double DEFAULT NULL," & vbCrLf
            '
            lstrsql = lstrsql & "  `icms_01`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `icms_02`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `icms_03`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `icms_04`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `icms_05`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `icms_06`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `icms_07`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `icms_08`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `icms_09`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `icms_10`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `icms_11`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `icms_12`        double DEFAULT NULL," & vbCrLf
            '
            lstrsql = lstrsql & "  `pis_01`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `pis_02`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `pis_03`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `pis_04`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `pis_05`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `pis_06`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `pis_07`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `pis_08`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `pis_09`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `pis_10`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `pis_11`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `pis_12`        double DEFAULT NULL," & vbCrLf
            '
            lstrsql = lstrsql & "  `cofins_01`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `cofins_02`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `cofins_03`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `cofins_04`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `cofins_05`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `cofins_06`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `cofins_07`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `cofins_08`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `cofins_09`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `cofins_10`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `cofins_11`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `cofins_12`        double DEFAULT NULL," & vbCrLf
            '
            lstrsql = lstrsql & "  `ene_01`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `ene_02`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `ene_03`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `ene_04`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `ene_05`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `ene_06`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `ene_07`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `ene_08`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `ene_09`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `ene_10`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `ene_11`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `ene_12`        double DEFAULT NULL," & vbCrLf
            '
            lstrsql = lstrsql & "  `tra_01`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tra_02`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tra_03`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tra_04`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tra_05`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tra_06`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tra_07`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tra_08`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tra_09`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tra_10`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tra_11`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tra_12`        double DEFAULT NULL," & vbCrLf
            '
            lstrsql = lstrsql & "  `dis_01`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `dis_02`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `dis_03`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `dis_04`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `dis_05`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `dis_06`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `dis_07`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `dis_08`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `dis_09`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `dis_10`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `dis_11`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `dis_12`        double DEFAULT NULL," & vbCrLf
            '
            lstrsql = lstrsql & "  `enc_01`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `enc_02`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `enc_03`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `enc_04`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `enc_05`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `enc_06`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `enc_07`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `enc_08`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `enc_09`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `enc_10`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `enc_11`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `enc_12`        double DEFAULT NULL," & vbCrLf
            '
            lstrsql = lstrsql & "  `per_01`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `per_02`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `per_03`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `per_04`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `per_05`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `per_06`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `per_07`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `per_08`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `per_09`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `per_10`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `per_11`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `per_12`        double DEFAULT NULL," & vbCrLf
            '
            lstrsql = lstrsql & "  `tic_01`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tic_02`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tic_03`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tic_04`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tic_05`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tic_06`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tic_07`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tic_08`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tic_09`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tic_10`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tic_11`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tic_12`        double DEFAULT NULL," & vbCrLf
            '
            lstrsql = lstrsql & "  `tpc_01`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tpc_02`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tpc_03`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tpc_04`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tpc_05`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tpc_06`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tpc_07`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tpc_08`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tpc_09`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tpc_10`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tpc_11`        double DEFAULT NULL," & vbCrLf
            lstrsql = lstrsql & "  `tpc_12`        double DEFAULT NULL," & vbCrLf
            '
            lstrsql = lstrsql & "  PRIMARY KEY (`nomemaquina`,`identificacao`)," & vbCrLf
            lstrsql = lstrsql & "  KEY `keyrota` (`caderno`)" & vbCrLf
            lstrsql = lstrsql & ") ENGINE=InnoDB DEFAULT CHARSET=latin1"
            objExecAtualizaBancoDados.QUERY_NAME = lstrsql
            repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: sCriaTabelaAuxiliar" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub lPrint(ByVal vNomeRPT As String)

        Dim dt As DataTable
        Dim dt_1 As DataTable
        Dim dt_2 As DataTable
        Dim dt_3 As DataTable
        Dim dc As DataColumn
        Dim ds As DataSet
        Dim lstrsql As String

        Dim bytBLOBData() As Byte

        Dim objEmpresa As New entidadeEmpresa
        Dim repositorioEmpresa As New repositorioEmpresa

        Dim vlist

        Try
            Dim rpt As New ReportDocument()

            'rptConsumidorAVencer
            If vNomeRPT = "rptRelPee" Then


                dt_3 = New DataTable()
                dt_3.Columns.Add("NOMEMAQUINA", GetType(String))
                dt_3.Columns.Add("BAIRRO", GetType(String))
                dt_3.Columns.Add("IDENTIFICACAO", GetType(String))
                dt_3.Columns.Add("CADERNO", GetType(String))
                dt_3.Columns.Add("SEQUENCIA", GetType(String))
                dt_3.Columns.Add("CLASSE", GetType(String))
                dt_3.Columns.Add("NOME", GetType(String))
                dt_3.Columns.Add("END_LOG", GetType(String))
                dt_3.Columns.Add("END_NUM", GetType(String))
                dt_3.Columns.Add("END_COM", GetType(String))
                dt_3.Columns.Add("END_CID", GetType(String))
                dt_3.Columns.Add("END_DIS", GetType(String))
                dt_3.Columns.Add("MEDIDOR", GetType(String))
                dt_3.Columns.Add("REGIAO", GetType(String))
                dt_3.Columns.Add("FASE", GetType(String))
                dt_3.Columns.Add("SITUACAO", GetType(String))
                dt_3.Columns.Add("GRUPO", GetType(String))
                dt_3.Columns.Add("MES_01", GetType(String))
                dt_3.Columns.Add("MES_02", GetType(String))
                dt_3.Columns.Add("MES_03", GetType(String))
                dt_3.Columns.Add("MES_04", GetType(String))
                dt_3.Columns.Add("MES_05", GetType(String))
                dt_3.Columns.Add("MES_06", GetType(String))
                dt_3.Columns.Add("MES_07", GetType(String))
                dt_3.Columns.Add("MES_08", GetType(String))
                dt_3.Columns.Add("MES_09", GetType(String))
                dt_3.Columns.Add("MES_10", GetType(String))
                dt_3.Columns.Add("MES_11", GetType(String))
                dt_3.Columns.Add("MES_12", GetType(String))

                ds = New DataSet

                lstrsql = ""
                lstrsql = "SELECT * FROM AUX_RELPEE  WHERE NOMEMAQUINA = '" & My.Computer.Name & "'"
                objAtualizaBancoDados.QUERY_NAME = lstrsql
                dt1 = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

                If dt1.Rows.Count > 0 Then
                    For Each dr_1 As DataRow In dt1.Rows

                        dt_3.Rows.Add(dr_1("NOMEMAQUINA"),
                                          dr_1("BAIRRO"),
                                          dr_1("IDENTIFICACAO"),
                                          dr_1("CADERNO"),
                                          dr_1("SEQUENCIA"),
                                          dr_1("CLASSE"),
                                          dr_1("NOME"),
                                          dr_1("END_LOG"),
                                          dr_1("END_NUM"),
                                          dr_1("END_COM"),
                                          dr_1("END_CID"),
                                          dr_1("END_DIS"),
                                          dr_1("MEDIDOR"),
                                          dr_1("REGIAO"),
                                          dr_1("FASE"),
                                          dr_1("SITUACAO"),
                                          dr_1("GRUPO"),
                                          dr_1("MES_01"),
                                          dr_1("MES_02"),
                                          dr_1("MES_03"),
                                          dr_1("MES_04"),
                                          dr_1("MES_05"),
                                          dr_1("MES_06"),
                                          dr_1("MES_07"),
                                          dr_1("MES_08"),
                                          dr_1("MES_09"),
                                          dr_1("MES_10"),
                                          dr_1("MES_11"),
                                          dr_1("MES_12"))


                    Next dr_1
                End If


                ds.Tables.Add(dt1)
                ds.Tables(0).TableName = "REL_PEE"

                If ds.Tables(0).Rows.Count = 0 Then
                    MessageBox.Show("Não há registros para o relatório escolhido! ", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    Exit Sub
                Else

                    rpt = New rptRelPee

                    rpt.SetDataSource(ds)
                    rpt.SetParameterValue("nomeempresa", sNomeEmpresa)
                    rpt.SetParameterValue("enderecoempresa", sEnderecoEmpresa)
                    rpt.SetParameterValue("cepempresa", sCepEmpresa)
                    rpt.SetParameterValue("ufempresa", sUFempresa)
                    rpt.SetParameterValue("cidadeempresa", sCidadeEmpresa)
                    rpt.SetParameterValue("bairroempresa", sBairroEmpresa)
                    rpt.SetParameterValue("foneempresa", sFoneEmpresa)
                    rpt.SetParameterValue("websiteempresa", sWebEmpresa)
                    rpt.SetParameterValue("F_Titulo", sTitulo)
                    'rpt.SetParameterValue("MesAnoRef", Month(dtpMesAno.Value) & "/" & Year(dtpMesAno.Value))
                    ' rpt.SetParameterValue("NomeRel", "Grupo A - Período de: " & dtpIni.Value & " Até: " & dtpFim.Value)

                    frmViewRelatorios.rpt = rpt

                    frmViewRelatorios.CRViewer.Zoom((100))
                    frmViewRelatorios.Text = "Relatório Consumidor a Vencer"
                    frmViewRelatorios.ShowDialog()

                End If

            End If

            Me.Cursor = System.Windows.Forms.Cursors.Default

        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: lPrint" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub
End Class