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 frmRelInadimplencia
	Inherits System.Windows.Forms.Form
    Private istrNmArq As String
    Private ilngPerAno(73) As Integer
	Private idteBase As Date
    Private istrCaminho As String

    Private objAtualizaBancoDados As New entidadeAtualizaBancoDados
    Private repositorioAtualizaBancoDados As New repositorioAtualizaBancoDados

    Private objExecAtualizaBancoDados As New entidadeAtualizaBancoDados
    Private repositorioExecAtualizaBancoDados As New repositorioAtualizaBancoDados
    Private dt, dt1, dt2, dt3, dtinterno As DataTable
    Private bload As Boolean
    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 Sub cmdArquivo_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdArquivo.Click

        Try

            fbdInad.ShowDialog()
            txtDir.Text = fbdInad.SelectedPath '& "\" & IIf(strNomeArquivo = "", strNomeArquivoSecundario, strNomeArquivo)

        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cbSalvarArq_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
        Try
            If Me.opbCSV.Checked Then
                Call ExportaCSV()
            ElseIf Me.opbXML.Checked Then
                Call ExportaXML()
            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 ExportaXML()
        Dim lstrSigla As String
        Dim lstrLinha As String
        Dim lstrColuna As String
        '
        Dim ldblValor As Double
        '
        Dim lintARQ As Short
        Dim lstrNMArq As String
        '
        Dim lstrSql As String

        Try

            If Trim(Me.txtDir.Text) <> "" And Trim(Me.txtArquivo.Text) <> "" Then

                lstrSql = "SELECT `id`, `sigla`, `linha`, `coluna` FROM `inadimplencia_cod_xml` ORDER BY `id` ASC"
                lstrNMArq = Me.txtDir.Text & IIf(VB.Right(Trim(Me.txtDir.Text), 1) <> "\", "\", "") & Me.txtArquivo.Text
                objAtualizaBancoDados.QUERY_NAME = lstrSql
                dt = repositorioExecAtualizaBancoDados.Consultar(objAtualizaBancoDados)

                'Call Conectar(lstrSql, lrstAux)

                If dt.Rows.Count > 0 Then
                    Call BarraProgresso(Me.ProgressBar(1), Me.lblPerc(1), (Me.lblInfo), 0, dt.Rows.Count, " Inadimplência ")
                    lintARQ = FreeFile()
                    FileOpen(lintARQ, lstrNMArq, OpenMode.Output)
                    PrintLine(lintARQ, "<?xml version=""1.0"" encoding=""ISO8859-1""?>")
                    PrintLine(lintARQ, "<TIQ Tipo=""indicadores"" " & "CodigoConcessionario=""" & gstrEmpresa_CodRes89 & """ " & "Sigla=""" & gstrEmpresa_Sigla & """ " & "DataGeracaoArquivo=""" & VB6.Format(idteBase, "dd/MM/yyyy") & """ " & "Sequencial=""S" & Me.txtVersao.Text & """>")

                    For Each row As DataRow In dt.Rows

                        lstrSigla = IIf(IsDBNull(row.Item("sigla")), "", row.Item("sigla"))
                        lstrLinha = IIf(IsDBNull(row.Item("linha")), "", row.Item("linha"))
                        lstrColuna = IIf(IsDBNull(row.Item("coluna")), "", row.Item("coluna"))
                        ldblValor = GetValorLinhaColunaDataFlex(lstrLinha, lstrColuna)

                        PrintLine(lintARQ, vbTab & "<indicador>")
                        PrintLine(lintARQ, vbTab & vbTab & "<codigo_conjunto/>")
                        PrintLine(lintARQ, vbTab & vbTab & "<codigo_UC/>")
                        PrintLine(lintARQ, vbTab & vbTab & "<sigla_indice>" & lstrSigla & "</sigla_indice>")
                        PrintLine(lintARQ, vbTab & vbTab & "<valor_indicador>" & Replace(CStr(ldblValor), ",", ".") & "</valor_indicador>")
                        PrintLine(lintARQ, vbTab & vbTab & "<periodo_competencia>" & VB6.Format(Month(Me.dtpMesAno.Value), "00") & "</periodo_competencia>")
                        PrintLine(lintARQ, vbTab & vbTab & "<ano_competencia>" & VB6.Format(Year(Me.dtpMesAno.Value), "0000") & "</ano_competencia>")
                        PrintLine(lintARQ, vbTab & "</indicador>")

                        'Call .MoveNext()
                        Call BarraProgresso(Me.ProgressBar(1), Me.lblPerc(1), (Me.lblInfo), 1,  , " Inadimplência ")
                    Next
                    PrintLine(lintARQ, "</TIQ>")
                    FileClose(lintARQ)
                    Call MsgBox("Arquivo gerado com sucesso!", MsgBoxStyle.Information, gstrTituloMensagem)
                End If

                dt = Nothing

            Else
                Call MsgBox("Você deve selecionar o caminho para gerar o XML", MsgBoxStyle.Information, gstrTituloMensagem)
            End If

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

    End Sub

    Private Function GetValorLinhaColunaDataFlex(ByVal astrLinha As String, ByVal astrColuna As String) As Double
        Dim ldblRet As Double
        Dim lintLin As Short
        Dim lintCol As Short

        Try
            With Me.mfgDados
                For lintLin = 1 To .Rows - 1
                    If .get_TextMatrix(lintLin, 0) = astrLinha Then
                        For lintCol = 1 To .Cols - 1
                            If .get_TextMatrix(0, lintCol) = astrColuna Then
                                ldblRet = IIf(IsNumeric(.get_TextMatrix(lintLin, lintCol)), .get_TextMatrix(lintLin, lintCol), 0)
                            End If
                        Next lintCol
                    End If
                Next lintLin
            End With
            GetValorLinhaColunaDataFlex = ldblRet

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

    Private Sub ExportaCSV()
        'Controle Arquivo
        Dim lstrCla As String
        Dim lstrMes As String
        Dim llngSus As Integer
        Dim ldblPer As Double
        Dim ldblFat As Double
        Dim ldblAbe As Double
        Dim lintAux As Short
        Dim lstrLin As String
        Dim lintARQ As Short
        Dim lstrNMArq As String
        Dim lstrSql As String

        Try

            lstrNMArq = Me.txtDir.Text & IIf(VB.Right(Trim(Me.txtDir.Text), 1) <> "\", "\", "") & Me.txtArquivo.Text

            If Trim(Me.txtDir.Text) <> "" And Trim(Me.txtArquivo.Text) <> "" Then
                lstrSql = ""
                lstrSql = lstrSql & "SELECT "
                lstrSql = lstrSql & "`nomemaquina`, `classe`, `suspendido`, " & vbCrLf
                For lintAux = 0 To 72
                    lstrSql = lstrSql & "`mes_" & VB6.Format(lintAux, "00") & "`, "
                Next lintAux
                lstrSql = lstrSql & vbCrLf

                For lintAux = 0 To 72
                    lstrSql = lstrSql & "`per_" & VB6.Format(lintAux, "00") & "`, "
                Next lintAux
                lstrSql = lstrSql & vbCrLf

                For lintAux = 0 To 72
                    lstrSql = lstrSql & "`fat_" & VB6.Format(lintAux, "00") & "`, "
                Next lintAux
                lstrSql = lstrSql & vbCrLf

                For lintAux = 0 To 72
                    lstrSql = lstrSql & "`abe_" & VB6.Format(lintAux, "00") & "`, "
                Next lintAux
                lstrSql = VB.Left(lstrSql, Len(lstrSql) - 2)
                lstrSql = lstrSql & "  FROM temp_inadimplentes"
                lstrSql = lstrSql & " WHERE `nomemaquina` = '" & My.Computer.Name & "' "
                objAtualizaBancoDados.QUERY_NAME = lstrSql
                dt = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

                'Call Conectar(lstrSql, lrstAux)

                If dt.Rows.Count > 0 Then
                    Call BarraProgresso(Me.ProgressBar(1), Me.lblPerc(1), (Me.lblInfo), 0, dt.Rows.Count, " Gerando Arquivo CSV ")
                    lintARQ = FreeFile()
                    FileOpen(lintARQ, lstrNMArq, OpenMode.Output)

                    For Each rowinterno As DataRow In dt.Rows
                        'Cabeçalho
                        lstrMes = IIf(IsDBNull(rowinterno.Item("mes_00")), "", rowinterno.Item("mes_00"))
                        lstrLin = ""
                        lstrLin = lstrLin & VB.Right(lstrMes, 4) & ";Mês de referência;;;"

                        For lintAux = 0 To 72
                            lstrMes = IIf(IsDBNull(rowinterno.Item("mes_" & VB6.Format(lintAux, "00"))), "", rowinterno.Item("mes_" & VB6.Format(lintAux, "00")))
                            If lstrMes <> "00/0000" Then
                                lstrLin = lstrLin & lintAux & IIf(lintAux = 1, " mês ", " meses ") & "antes" & ";;;"
                            End If
                            If Me.opbInadimplencia.Checked Then
                                lstrLin = lstrLin & "Suspendido;"
                            End If
                        Next lintAux

                        If CInt(Len(lstrLin)) > 0 Then
                            PrintLine(lintARQ, lstrLin)
                        End If

                        lstrLin = ""
                        lstrLin = lstrLin & "Dados do faturamento (R$);"
                        For lintAux = 0 To 72
                            lstrMes = IIf(IsDBNull(rowinterno.Item("mes_" & VB6.Format(lintAux, "00"))), "", rowinterno.Item("mes_" & VB6.Format(lintAux, "00")))
                            If lstrMes <> "00/0000" Then
                                lstrLin = lstrLin & "Percentual " & lstrMes & ";Faturamento " & lstrMes & ";Faturamento " & lstrMes & " e não recebido até " & IIf(IsDBNull(rowinterno.Item("mes_00")), "", rowinterno.Item("mes_00")) & ";"
                            End If
                        Next lintAux

                        If CInt(Len(lstrLin)) > 0 Then
                            PrintLine(lintARQ, lstrLin)
                        End If


                        lstrCla = Trim(IIf(IsDBNull(rowinterno.Item("classe")), "", rowinterno.Item("classe")))
                        llngSus = CInt(IIf(IsDBNull(rowinterno.Item("suspendido")), "0", rowinterno.Item("suspendido")))

                        lstrLin = ""
                        lstrLin = lstrLin & lstrCla & ";"
                        For lintAux = 0 To 72
                            ldblPer = CDbl(IIf(IsDBNull(rowinterno("per_" & VB6.Format(lintAux, "00"))), 0, rowinterno.Item("per_" & VB6.Format(lintAux, "00"))))
                            ldblFat = CDbl(IIf(IsDBNull(rowinterno.Item("fat_" & VB6.Format(lintAux, "00"))), 0, rowinterno.Item("fat_" & VB6.Format(lintAux, "00"))))
                            ldblAbe = CDbl(IIf(IsDBNull(rowinterno.Item("abe_" & VB6.Format(lintAux, "00"))), 0, rowinterno.Item("abe_" & VB6.Format(lintAux, "00"))))
                            lstrMes = IIf(IsDBNull(rowinterno.Item("mes_" & VB6.Format(lintAux, "00"))), "", rowinterno.Item("mes_" & VB6.Format(lintAux, "00")))
                            If lstrMes <> "00/0000" Then
                                lstrLin = lstrLin & VB6.Format(ldblPer, "#,##0.00") & ";" & VB6.Format(ldblFat, "#,##0.00") & ";" & VB6.Format(ldblAbe, "#,##0.00") & ";"
                            End If
                        Next lintAux

                        If CInt(Len(lstrLin)) > 0 Then
                            PrintLine(lintARQ, lstrLin)
                        End If

                        'Call .MoveNext()
                        Call BarraProgresso(Me.ProgressBar(1), Me.lblPerc(1), (Me.lblInfo), 1,  , " Gerando Arquivo CSV ")
                    Next

                    FileClose(lintARQ)
                    Call MsgBox("Arquivo gerado com sucesso!", MsgBoxStyle.Information, gstrTituloMensagem)
                End If

                dt = Nothing

            End If

        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: ExportaCSV" & "", "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 dtpMesAno_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles dtpMesAno.ClickEvent
    '    Call dtpMesAno_Change(dtpMesAno, New System.EventArgs())
    'End Sub

    Private Sub frmRelInadimplencia_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
        Dim lintAux As Short
        Dim lstrSql As String

        Try
            idteBase = Date.Now()

            bload = True

            istrCaminho = GetConfig("caminho.xml.tiq")
            If istrCaminho = "-1" Then
                istrCaminho = My.Application.Info.DirectoryPath
                'Call CriaParConfig("CAMINHO_XML_TIQ", Replace(istrCaminho, "\", "\\"), False, "Caminho de gravação para o arquivo XML INDQUAL.")
            ElseIf istrCaminho = "" Then
                istrCaminho = My.Application.Info.DirectoryPath
                ' Call GravaConfig("CAMINHO_XML_TIQ", Replace(istrCaminho, "\", "\\"))
            End If

            If VB.Right(Trim(istrCaminho), 1) <> "\" Then
                istrCaminho = istrCaminho & "\"
            End If
            Me.txtVersao.Text = "01"

            With Me.lsvMeses
                Call .Items.Clear()
                Call .Columns.Clear()
                If .Columns.Count <= 1 Then
                    Call .Columns.Add("", "Mês", CInt(VB6.TwipsToPixelsX(650)))
                End If
                For lintAux = 1 To 72
                    Call .Items.Add(CStr(lintAux))
                    If InStr(1, "24,21,18,12,06,03,01", VB6.Format(lintAux, "00")) > 0 Then
                        .Items.Item(lintAux - 1).Checked = True
                    Else
                        .Items.Item(lintAux - 1).Checked = False
                    End If
                Next lintAux
            End With

            Call MontaGrade()
            Me.dtpMesAno.Value = idteBase
            Call NomeArquivoXML()
            Call CriaTabelaAuxiliar()

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

    End Sub
    Private Sub cmdProcessar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdProcessar.Click
        Try
            Call LigDes(False)
            Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
            Call MontaGrade()
            Call EncheGrade()
            Call TotalizaGrade()
            If Not MontaTabela() Then
                Call MontaTabela()
            End If
            Me.lblInfo.Text = " Finalizado."
            Call Me.lblInfo.Refresh()
            Me.Cursor = System.Windows.Forms.Cursors.Default
            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 MontaGrade()
        Dim lintAux As Short
        Dim lintTam As Short
        Try
            With Me.mfgDados
                Call .Clear()
                .Redraw = False
                .Rows = 12
                For lintAux = 0 To 72
                    .set_TextMatrix(0, lintAux, VB6.Format(lintAux, "00") & "(%)")
                    .set_ColWidth(lintAux, 1200)
                    If lintAux <> 0 Then
                        If Me.lsvMeses.Items.Item(lintAux - 1).Checked = False Then
                            .set_ColWidth(lintAux, 0)
                        End If
                    End If
                Next lintAux
                .set_TextMatrix(0, lintAux, "Suspensão")
                .set_ColWidth(lintAux, 1200)
                .set_TextMatrix(1, 0, "RESIDENCIAL TOTAL")
                .set_TextMatrix(2, 0, "RESIDENCIAL BAIXA RENDA")
                .set_TextMatrix(3, 0, "RESIDENCIAL NORMAL")
                .set_TextMatrix(4, 0, "INDUSTRIAL")
                .set_TextMatrix(5, 0, "COMERCIAL")
                .set_TextMatrix(6, 0, "RURAL")
                .set_TextMatrix(7, 0, "PODER PÚBLICO")
                .set_TextMatrix(8, 0, "ILUMINAÇÃO PÚBLICA")
                .set_TextMatrix(9, 0, "SERVIÇO PÚBLICO")
                .set_TextMatrix(10, 0, "CONSUMO PRÓPRIO")
                .set_TextMatrix(11, 0, "TOTAL")
                .Redraw = True
            End With

            With Me.mfgFaturado
                Call .Clear()
                .Redraw = False
                .Rows = Me.mfgDados.Rows
                For lintAux = 0 To 72
                    .set_TextMatrix(0, lintAux, VB6.Format(lintAux, "00"))
                    '.set_ColWidth(lintAux, Me.mfgDados.get_ColWidth(lintAux))
                    .set_ColWidth(lintAux, 1500)
                Next lintAux
                .Redraw = True
            End With

            With Me.mfgAberto
                Call .Clear()
                .Redraw = False
                .Rows = Me.mfgDados.Rows
                For lintAux = 0 To 72
                    .set_TextMatrix(0, lintAux, VB6.Format(lintAux, "00"))
                    '.set_ColWidth(lintAux, Me.mfgDados.get_ColWidth(lintAux))
                    .set_ColWidth(lintAux, 1500)
                Next lintAux
                .Redraw = True
            End With

            Me.mfgDados.set_ColWidth(0, 2200)
            Me.mfgDados.set_TextMatrix(0, 0, "Classe")
            Call ConfigTipo()
        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: MontaGrade" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try
    End Sub

    Private Sub EncheGrade()
        Dim ldblNumNf As Double
        Dim lstrMesAno As String
        Dim llngMesano As Integer
        Dim lstrZona As String
        Dim lstrLivro As String
        Dim lstrConta As String
        Dim llngConsId As Integer
        Dim llngUnidId As Integer
        Dim lstrGruTar As String
        Dim lstrGrupo As String
        Dim ldblVlrFat As Double
        Dim ldblVlrLiq As Double
        Dim llngCdClas As Integer
        Dim lstrFlgSit As String
        Dim ldteFlgSit As Date
        Dim ldtePagto As Date
        Dim lintAux As Short
        Dim ldteAux As Date
        Dim ldteBas As Date
        Dim lstrMes As String
        Dim lblnAux As Boolean
        Dim lblnCon As Boolean
        Dim lstrSql As String

        Try

            Me.lblInfo.Text = " Buscando os dados aguarde..."
            Call Me.lblInfo.Refresh()
            lblnAux = True
            ldteBas = CDate("01/" & VB6.Format(Me.dtpMesAno.Value, "MM/yyyy"))

            Dim a As String

            For lintAux = 0 To 72
                ilngPerAno(lintAux + 1) = CInt(VB6.Format(DateAdd(Microsoft.VisualBasic.DateInterval.Month, IIf(lintAux = 0, 0, lintAux * -1), ldteBas), "yyyyMM"))
                a = VB.Right(CStr(ilngPerAno(lintAux + 1)), 2) & "/" & VB.Left(CStr(ilngPerAno(lintAux + 1)), 4)
                Me.mfgFaturado.set_TextMatrix(0, lintAux, VB.Right(CStr(ilngPerAno(lintAux + 1)), 2) & "/" & VB.Left(CStr(ilngPerAno(lintAux + 1)), 4))
                Me.mfgAberto.set_TextMatrix(0, lintAux, VB.Right(CStr(ilngPerAno(lintAux + 1)), 2) & "/" & VB.Left(CStr(ilngPerAno(lintAux + 1)), 4))
                Me.mfgAberto.Refresh()
                System.Windows.Forms.Application.DoEvents()
            Next lintAux
            System.Windows.Forms.Application.DoEvents()

            ldteBas = CDate(UltimoDiaMes(Month(Me.dtpMesAno.Value), Year(Me.dtpMesAno.Value)) & "/" & VB6.Format(Me.dtpMesAno.Value, "MM/yyyy"))
            Me.lblAux(2).Text = "Em Aberto até: " & VB6.Format(ldteBas, "dd/MM/yyyy")
            Call Me.lblAux(2).Refresh()
            Call BarraProgresso(Me.ProgressBar(0), Me.lblPerc(0), (Me.lblInfo), 0, 73)
            Me.lblInfo.Text = " Buscando mês de referência "

            Call Me.lblInfo.Refresh()

            For lintAux = 1 To 72
                If lintAux = 0 Then
                    lblnAux = True
                Else
                    lblnAux = Me.lsvMeses.Items.Item(lintAux - 1).Checked
                End If
                If lblnAux Then
                    Me.lblInfo.Text = " Buscando os dados de " & Me.mfgFaturado.get_TextMatrix(0, lintAux) & " aguarde..."
                    Call Me.lblInfo.Refresh()
                    lstrSql = ""
                    lstrSql = lstrSql & "SELECT numnf, mesano, mesano_ref, ta, zona, livro, conta, cons_id, unid_id, grupo, valortot, valorliq, codclas, flgst, datast, datapag " & vbCrLf
                    lstrSql = lstrSql & "  FROM nf " & vbCrLf
                    lstrSql = lstrSql & " WHERE mesano_ref = " & CInt(VB.Right(Me.mfgFaturado.get_TextMatrix(0, lintAux), 4) & VB.Left(Me.mfgFaturado.get_TextMatrix(0, lintAux), 2))
                    objAtualizaBancoDados.QUERY_NAME = lstrSql
                    dt = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

                    'Call Conectar(lstrSql, lrstAux)

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

                            ldblNumNf = CDbl(IIf(IsDBNull(row.Item("numnf")), 0, row.Item("numnf")))
                            lstrMesAno = Trim(IIf(IsDBNull(row.Item("mesano")), "", row.Item("mesano")))
                            llngMesano = CInt(IIf(IsDBNull(row.Item("mesano_ref")), 0, row.Item("mesano_ref")))
                            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")))
                            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")))
                            lstrGruTar = Trim(IIf(IsDBNull(row.Item("ta")), "B1", row.Item("ta")))
                            lstrGrupo = Trim(IIf(IsDBNull(row.Item("grupo")), "B", row.Item("grupo")))
                            ldblVlrFat = CDbl(IIf(IsDBNull(row.Item("valortot")), 0, row.Item("valortot")))
                            ldblVlrLiq = CDbl(IIf(IsDBNull(row.Item("valorliq")), 0, row.Item("valorliq")))
                            llngCdClas = CInt(IIf(IsDBNull(row.Item("codclas")), 0, row.Item("codclas")))
                            lstrFlgSit = Trim(IIf(IsDBNull(row.Item("flgst")), "", row.Item("flgst")))
                            ldteFlgSit = CDate(IIf(IsDBNull(row.Item("datast")), "1900-01-01", row.Item("datast")))
                            ldtePagto = CDate(IIf(IsDBNull(row.Item("datapag")), "1900-01-01", row.Item("datapag")))
                            ldteAux = CDate(UltimoDiaMes(CShort(VB.Left(lstrMesAno, 2)), CShort(VB.Right(lstrMesAno, 4))) & "/" & lstrMesAno)
                            lblnCon = True
                            If Me.opbIrrecuperaveis.Checked Then
                                If Mid(lstrGruTar, 3, 2) = "AL" Then
                                    If Me.chkLivres.CheckState = System.Windows.Forms.CheckState.Unchecked Then
                                        lblnCon = False
                                    End If
                                ElseIf llngCdClas > 8000 And llngCdClas < 8999 Then
                                    If Me.chkConsumoProprio.CheckState = System.Windows.Forms.CheckState.Unchecked Then
                                        lblnCon = False
                                    End If
                                End If
                            End If
                            If lblnCon Then
                                'Faturado
                                If lstrFlgSit <> "C" Or (lstrFlgSit = "C" And ldteFlgSit > ldteAux) Then
                                    Call AdicionaGrade(0, lstrMesAno, llngCdClas, ldblVlrFat, IIf(VerificaCorte(ldblNumNf, lstrMesAno, ldteBas), 1, 0))
                                End If
                                'Aberto
                                If (ldtePagto = CDate("01/01/1900") Or ldtePagto > ldteBas) And (lstrFlgSit <> "C" Or (lstrFlgSit = "C" And ldteFlgSit > ldteAux)) Then
                                    Call AdicionaGrade(1, lstrMesAno, llngCdClas, ldblVlrFat, 0)
                                End If
                            End If
                            ' Call .MoveNext()
                            Call BarraProgresso(Me.ProgressBar(1), Me.lblPerc(1), (Me.lblInfo), 1,  , " " & lstrMesAno & " ")
                        Next
                    End If

                    dt = Nothing

                End If
                Call BarraProgresso(Me.ProgressBar(0), Me.lblPerc(0), (Me.lblInfo), 1)
            Next lintAux
        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 AdicionaGrade(ByVal aintTipo As Short, ByVal astrMesAno As String, ByVal alngCodClas As Integer, ByVal adblValor As Double, ByVal aintSuspendido As Short)

        Dim llngRow As Integer
        Dim llngCol As Integer
        Dim llngAux As Integer

        Try
            If CDbl(VB.Left(CStr(alngCodClas), 1)) < 4 Then
                llngRow = 4
            ElseIf CDbl(VB.Left(CStr(alngCodClas), 1)) = 4 Then
                llngRow = 5
            ElseIf CDbl(VB.Left(CStr(alngCodClas), 1)) = 5 Then
                llngRow = 6
            ElseIf CDbl(VB.Left(CStr(alngCodClas), 1)) = 6 Then
                If CDbl(VB.Left(CStr(alngCodClas), 2)) = 64 Then
                    llngRow = 8
                Else
                    llngRow = 7
                End If
            ElseIf CDbl(VB.Left(CStr(alngCodClas), 1)) = 7 Then
                llngRow = 9
            ElseIf CDbl(VB.Left(CStr(alngCodClas), 1)) = 8 Then
                llngRow = 10
            ElseIf CDbl(VB.Left(CStr(alngCodClas), 1)) = 9 Then
                If CDbl(VB.Right(CStr(alngCodClas), 1)) = 2 Or CDbl(VB.Right(CStr(alngCodClas), 1)) = 4 Or CDbl(VB.Right(CStr(alngCodClas), 1)) = 5 Or CDbl(VB.Right(CStr(alngCodClas), 1)) = 6 Then
                    llngRow = 2
                Else
                    llngRow = 3
                End If
            End If
            llngCol = 0
            If aintTipo = 0 Then
                With Me.mfgFaturado
                    For llngAux = 0 To 72
                        If .get_TextMatrix(0, llngAux) = astrMesAno Then
                            llngCol = llngAux
                            llngAux = 72
                        End If
                    Next llngAux
                    .set_TextMatrix(llngRow, llngCol, VB6.Format(IIf(IsNumeric(.get_TextMatrix(llngRow, llngCol)), .get_TextMatrix(llngRow, llngCol), 0) + adblValor, "#,##0.00"))
                End With
            ElseIf aintTipo = 1 Then
                With Me.mfgAberto
                    For llngAux = 0 To 72
                        If .get_TextMatrix(0, llngAux) = astrMesAno Then
                            llngCol = llngAux
                            llngAux = 72
                        End If
                    Next llngAux
                    .set_TextMatrix(llngRow, llngCol, VB6.Format(IIf(IsNumeric(.get_TextMatrix(llngRow, llngCol)), .get_TextMatrix(llngRow, llngCol), 0) + adblValor, "#,##0.00"))
                End With
            End If
            If llngCol > 0 Then
                With Me.mfgDados

                    If Me.lsvMeses.Items.Item(llngCol).Checked = True Then 'InStr(1, istrAneel, Strings.Format(llngCol, "00")) > 0 Then
                        .set_TextMatrix(llngRow, 73, VB6.Format(IIf(IsNumeric(.get_TextMatrix(llngRow, 73)), .get_TextMatrix(llngRow, 73), 0) + aintSuspendido, "#,##0")) 'ANEEL
                    End If
                End With
            End If


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

    Private Sub TotalizaGrade()
        Dim llngCol As Integer
        Dim llngRow As Integer
        Dim llngAux As Integer
        Dim ldblPer As Double
        Dim ldblTot As Double
        Dim ldblAbe As Double

        Try
            For llngCol = 0 To 72
                Me.mfgFaturado.set_TextMatrix(1, llngCol, "")
                Me.mfgFaturado.set_TextMatrix(11, llngCol, "")
                Me.mfgAberto.set_TextMatrix(1, llngCol, "")
                Me.mfgAberto.set_TextMatrix(11, llngCol, "")
            Next llngCol

            'Totaliza fatura e em aberto
            For llngCol = 0 To 72
                For llngRow = 2 To 10
                    If llngRow <= 3 Then
                        With Me.mfgFaturado
                            .set_TextMatrix(1, llngCol, VB6.Format(CDbl(IIf(IsNumeric(.get_TextMatrix(1, llngCol)), .get_TextMatrix(1, llngCol), 0)) + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, llngCol)), .get_TextMatrix(llngRow, llngCol), 0)), "#,##0.00"))
                        End With
                        With Me.mfgAberto
                            .set_TextMatrix(1, llngCol, VB6.Format(CDbl(IIf(IsNumeric(.get_TextMatrix(1, llngCol)), .get_TextMatrix(1, llngCol), 0)) + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, llngCol)), .get_TextMatrix(llngRow, llngCol), 0)), "#,##0.00"))
                        End With
                    End If
                    With Me.mfgFaturado
                        .set_TextMatrix(11, llngCol, VB6.Format(CDbl(IIf(IsNumeric(.get_TextMatrix(11, llngCol)), .get_TextMatrix(11, llngCol), 0)) + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, llngCol)), .get_TextMatrix(llngRow, llngCol), 0)), "#,##0.00"))
                    End With
                    With Me.mfgAberto
                        .set_TextMatrix(11, llngCol, VB6.Format(CDbl(IIf(IsNumeric(.get_TextMatrix(11, llngCol)), .get_TextMatrix(11, llngCol), 0)) + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, llngCol)), .get_TextMatrix(llngRow, llngCol), 0)), "#,##0.00"))
                    End With
                Next llngRow
            Next llngCol
            'Calcula percentual de inadimplência
            For llngCol = 1 To 72
                With Me.mfgFaturado
                    ldblTot = CDbl(IIf(IsNumeric(.get_TextMatrix(11, llngCol)), .get_TextMatrix(11, llngCol), 0))
                End With
                For llngRow = 2 To 10
                    With Me.mfgAberto
                        ldblAbe = CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, llngCol)), .get_TextMatrix(llngRow, llngCol), 0))
                    End With
                    If ldblTot <> 0 Then
                        ldblPer = Arredondar((ldblAbe / ldblTot) * 100, 2)
                    Else
                        ldblPer = 0
                    End If
                    With Me.mfgDados
                        .set_TextMatrix(llngRow, llngCol, VB6.Format(ldblPer, "#,##0.00"))
                    End With
                Next llngRow
            Next llngCol
            For llngCol = 1 To 73
                For llngRow = 2 To 10
                    If llngRow <= 3 Then
                        With Me.mfgDados
                            .set_TextMatrix(1, llngCol, VB6.Format(CDbl(IIf(IsNumeric(.get_TextMatrix(1, llngCol)), .get_TextMatrix(1, llngCol), 0)) + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, llngCol)), .get_TextMatrix(llngRow, llngCol), 0)), IIf(llngCol < 25, "#,##0.00", "#,##0")))
                        End With
                    End If
                    With Me.mfgDados
                        .set_TextMatrix(11, llngCol, VB6.Format(CDbl(IIf(IsNumeric(.get_TextMatrix(11, llngCol)), .get_TextMatrix(11, llngCol), 0)) + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, llngCol)), .get_TextMatrix(llngRow, llngCol), 0)), IIf(llngCol < 25, "#,##0.00", "#,##0")))
                    End With
                Next llngRow
            Next llngCol

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

    Private Function MontaTabela() As Boolean
        Dim lblnErro As Boolean
        Dim lstrSql As String
        Dim llngCol As Integer
        Dim llngRow As Integer
        Dim lintAux As Short

        Try

            objExecAtualizaBancoDados.QUERY_NAME = "DELETE FROM `temp_inadimplentes` WHERE `nomemaquina` = '" & My.Computer.Name & "'"
            repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

            lstrSql = ""
            lstrSql = lstrSql & "INSERT INTO `temp_inadimplentes` (`nomemaquina`, `classe`, `suspendido`, " & vbCrLf
            For lintAux = 0 To 72
                lstrSql = lstrSql & "`mes_" & VB6.Format(lintAux, "00") & "`, "
            Next lintAux
            lstrSql = lstrSql & vbCrLf
            For lintAux = 0 To 72
                lstrSql = lstrSql & "`per_" & VB6.Format(lintAux, "00") & "`, "
            Next lintAux
            lstrSql = lstrSql & vbCrLf
            For lintAux = 0 To 72
                lstrSql = lstrSql & "`fat_" & VB6.Format(lintAux, "00") & "`, "
            Next lintAux
            lstrSql = lstrSql & vbCrLf
            For lintAux = 0 To 72
                lstrSql = lstrSql & "`abe_" & VB6.Format(lintAux, "00") & "`, "
            Next lintAux
            lstrSql = VB.Left(lstrSql, Len(lstrSql) - 2)
            lstrSql = lstrSql & ") VALUES "

            For llngRow = 1 To Me.mfgDados.Rows - 1
                lstrSql = lstrSql & vbCrLf & "('" & My.Computer.Name & "', "
                lstrSql = lstrSql & "'" & Me.mfgDados.get_TextMatrix(llngRow, 0) & "',"
                lstrSql = lstrSql & " " & Replace(CStr(CDbl(IIf(IsNumeric(Me.mfgDados.get_TextMatrix(llngRow, 73)), Me.mfgDados.get_TextMatrix(llngRow, 73), 0))), ",", ".") & ", " & vbCrLf
                'Meses

                For llngCol = 0 To 72
                    If llngCol = 0 Then
                        lstrSql = lstrSql & "'" & Me.mfgFaturado.get_TextMatrix(0, llngCol) & "', "
                    ElseIf Me.lsvMeses.Items.Item(llngCol - 1).Checked Then
                        lstrSql = lstrSql & "'" & Me.mfgFaturado.get_TextMatrix(0, llngCol) & "', "
                    Else
                        lstrSql = lstrSql & "'00/0000', "
                    End If
                Next llngCol

                lstrSql = lstrSql & vbCrLf
                'Percentuais
                For llngCol = 0 To 72
                    If IsNumeric(Me.mfgDados.get_TextMatrix(llngRow, llngCol)) Then
                        lstrSql = lstrSql & " " & Replace(IIf(llngCol = 0, 0, CDbl(Me.mfgDados.get_TextMatrix(llngRow, llngCol))), ",", ".") & ", "
                    Else
                        lstrSql = lstrSql & " " & Replace(IIf(llngCol = 0, 0, Me.mfgDados.get_TextMatrix(llngRow, llngCol)), ",", ".") & ", "
                    End If
                Next llngCol
                lstrSql = lstrSql & vbCrLf
                'Faturado
                For llngCol = 0 To 72
                    lstrSql = lstrSql & " " & Replace(CStr(CDbl(IIf(IsNumeric(Me.mfgFaturado.get_TextMatrix(llngRow, llngCol)), Me.mfgFaturado.get_TextMatrix(llngRow, llngCol), 0))), ",", ".") & ", "
                Next llngCol
                lstrSql = lstrSql & vbCrLf
                'Aberto
                For llngCol = 0 To 72
                    lstrSql = lstrSql & " " & Replace(CStr(CDbl(IIf(IsNumeric(Me.mfgAberto.get_TextMatrix(llngRow, llngCol)), Me.mfgAberto.get_TextMatrix(llngRow, llngCol), 0))), ",", ".") & ", "
                Next llngCol
                lstrSql = VB.Left(lstrSql, Len(lstrSql) - 2) & "),"
            Next llngRow
            lstrSql = VB.Left(lstrSql, Len(lstrSql) - 1) & ";"
            objExecAtualizaBancoDados.QUERY_NAME = lstrSql
            repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

            ' lblnErro = (Not Executar(lstrSql))
            'ErroMontaTabela:
            'If lblnErro Then
            '    'Recria tabela temp_diversos
            '    Call Executar("DROP TABLE IF EXISTS `temp_inadimplentes`")
            '    Call CriaTabelaAuxiliar()
            '    'Call MsgBox("Recriado a tabela auxiliar, favor tente novamente", vbInformation, gstrTituloMensagem)
            'ElseIf Err.Number > 0 Then
            '    Call MsgBox(Err.Number & " - " & GetErrosVB(Err.Number, Err.Description), MsgBoxStyle.Exclamation, gstrTituloMensagem)
            'End If
            MontaTabela = (Not lblnErro)

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

    End Function

    Private Sub ConfigTipo()
        Dim llngAux As Short
        Try
            With Me.mfgDados
                For llngAux = 1 To 72
                    .set_ColWidth(llngAux, 1200)
                    Me.mfgFaturado.set_ColWidth(llngAux, 1200)
                    Me.mfgAberto.set_ColWidth(llngAux, 1200)
                    If Me.lsvMeses.Items.Item(llngAux - 1).Checked = False Then '  InStr(1, istrAneel, Left(.TextMatrix(0, llngAux), 2)) = 0 Then
                        .set_ColWidth(llngAux, 0)
                        Me.mfgFaturado.set_ColWidth(llngAux, 0)
                        Me.mfgAberto.set_ColWidth(llngAux, 0)
                    End If
                Next llngAux
                .set_ColWidth(llngAux, 1200)
            End With
            With Me.mfgDados
                .FillStyle = MSFlexGridLib.FillStyleSettings.flexFillRepeat
                .Row = 1
                .Col = 0
                .ColSel = .Cols - 1
                .CellFontBold = True
                .Row = 11
                .ColSel = .Cols - 1
                .CellFontBold = True
                .FillStyle = MSFlexGridLib.FillStyleSettings.flexFillSingle
            End With
            With Me.mfgFaturado
                .FillStyle = MSFlexGridLib.FillStyleSettings.flexFillRepeat
                .Row = 1
                .Col = 0
                .ColSel = .Cols - 1
                .CellFontBold = True
                .Row = 11
                .ColSel = .Cols - 1
                .CellFontBold = True
                .FillStyle = MSFlexGridLib.FillStyleSettings.flexFillSingle
            End With
            With Me.mfgAberto
                .FillStyle = MSFlexGridLib.FillStyleSettings.flexFillRepeat
                .Row = 1
                .Col = 0
                .ColSel = .Cols - 1
                .CellFontBold = True
                .Row = 11
                .ColSel = .Cols - 1
                .CellFontBold = True
                .FillStyle = MSFlexGridLib.FillStyleSettings.flexFillSingle
            End With

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

    Private Sub dtpMesAno_ValueChanged(sender As Object, e As EventArgs) Handles dtpMesAno.ValueChanged

        Try

            If Me.opbCSV.Checked Then
                Call NomeArquivoCsv()
            ElseIf Me.opbXML.Checked Then
                Call NomeArquivoXML()
            End If

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

    Private Sub LigDes(ByVal ablnModo As Boolean)

        Me.cmdFechar.Enabled = ablnModo
        Me.cmdProcessar.Enabled = ablnModo
        Me.cmdImprimir.Enabled = ablnModo
        Me.cmdExporta.Enabled = ablnModo
        Me.cmdArquivo.Enabled = ablnModo
        Me.dtpMesAno.Enabled = ablnModo
        Me.fmeAux(0).Enabled = ablnModo
        Me.fmeAux(1).Enabled = ablnModo
        Me.lsvMeses.Enabled = ablnModo

    End Sub

    Private Function VerificaCorte(ByVal adblNumNf As Double, ByVal astrMesAno As String, ByVal adteBase As Date) As Boolean
        Dim lblnRet As Boolean
        Dim lstrSql As String

        Try
            lblnRet = False

            If Me.mfgFaturado.get_TextMatrix(0, 0) <> astrMesAno Then
                lstrSql = ""
                lstrSql = lstrSql & "SELECT * "
                lstrSql = lstrSql & "  FROM `concorte` "
                lstrSql = lstrSql & " WHERE `numnf`  = " & adblNumNf & " "
                lstrSql = lstrSql & "   AND `mesano` = '" & astrMesAno & "' "
                lstrSql = lstrSql & "   AND `datacorte` IS NOT NULL "
                lstrSql = lstrSql & "   AND `datacorte` <> '0000-00-00' "
                lstrSql = lstrSql & "   AND `datacorte` <= '" & VB6.Format(adteBase, "yyyy-MM-dd") & "' "
                objAtualizaBancoDados.QUERY_NAME = lstrSql
                dtinterno = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

                lblnRet = (dtinterno.Rows.Count > 0)

                dtinterno = Nothing

            End If

            VerificaCorte = lblnRet

        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: VerificaCorte" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Function
        End Try
    End Function
    'Private Sub lsvMeses_ItemCheck(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.ItemCheckEventArgs) Handles lsvMeses.ItemCheck
    '    Dim Item As System.Windows.Forms.ListViewItem = lsvMeses.Items(eventArgs.Index)
    '    If bload Then
    '        Call MontaGrade()
    '    End If
    'End Sub

    'UPGRADE_WARNING: Event opbCSV.CheckedChanged 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 opbCSV_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbCSV.CheckedChanged
        If eventSender.Checked Then
            Call NomeArquivoCsv()
        End If
    End Sub

    'UPGRADE_WARNING: Event opbInadimplencia.CheckedChanged 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 opbInadimplencia_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbInadimplencia.CheckedChanged
        Try
            If eventSender.Checked Then
                Dim lintAux As Short
                With Me.lsvMeses
                    Call .Items.Clear()
                    Call .Columns.Clear()
                    If .Columns.Count <= 1 Then
                        Call .Columns.Add("", "Mês", CInt(VB6.TwipsToPixelsX(650)))
                    End If
                    For lintAux = 1 To 72
                        Call .Items.Add(CStr(lintAux))
                        If InStr(1, "24,21,18,12,06,03,01", VB6.Format(lintAux, "00")) > 0 Then
                            .Items.Item(lintAux - 1).Checked = True
                        Else
                            .Items.Item(lintAux - 1).Checked = False
                        End If
                    Next lintAux
                End With
                'With Me.lsvMeses
                '    For lintAux = 1 To 72
                '        If InStr(1, "24,21,18,12,06,03,01", VB6.Format(lintAux, "00")) > 0 Then
                '            .Items.Item(lintAux - 1).Checked = True
                '        Else
                '            .Items.Item(lintAux - 1).Checked = False
                '        End If
                '    Next lintAux
                'End With

                If bload Then
                    Call MontaGrade()
                    Me.chkLivres.Enabled = True
                    Me.chkConsumoProprio.Enabled = True
                    Me.chkLivres.CheckState = System.Windows.Forms.CheckState.Checked
                    Me.chkConsumoProprio.CheckState = System.Windows.Forms.CheckState.Checked
                End If
            End If

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

    End Sub

    '	'UPGRADE_WARNING: Event opbIrrecuperaveis.CheckedChanged 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 opbIrrecuperaveis_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbIrrecuperaveis.CheckedChanged

        Try
            If eventSender.Checked Then
                Dim lintAux As Short
                With Me.lsvMeses
                    Call .Items.Clear()
                    Call .Columns.Clear()
                    If .Columns.Count <= 1 Then
                        Call .Columns.Add("", "Mês", CInt(VB6.TwipsToPixelsX(650)))
                    End If
                    For lintAux = 1 To 72
                        Call .Items.Add(CStr(lintAux))
                        If InStr(1, "36,30,24,21,18,15,12,09,06,05,04,03,02,01", VB6.Format(lintAux, "00")) > 0 Then
                            .Items.Item(lintAux - 1).Checked = True
                        Else
                            .Items.Item(lintAux - 1).Checked = False
                        End If
                    Next lintAux
                End With
                'With Me.lsvMeses
                '    For lintAux = 1 To 72
                '        If InStr(1, "36,30,24,21,18,15,12,09,06,05,04,03,02,01", VB6.Format(lintAux, "00")) > 0 Then
                '            'UPGRADE_WARNING: Lower bound of collection Me.lsvMeses.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(lintAux).Checked = True
                '        Else
                '            'UPGRADE_WARNING: Lower bound of collection Me.lsvMeses.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(lintAux).Checked = False
                '        End If
                '    Next lintAux
                'End With

                If bload Then
                    Call MontaGrade()
                    Me.chkLivres.Enabled = False
                    Me.chkConsumoProprio.Enabled = False
                    Me.chkLivres.CheckState = System.Windows.Forms.CheckState.Unchecked
                    Me.chkConsumoProprio.CheckState = System.Windows.Forms.CheckState.Unchecked
                End If
            End If

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

    Private Sub NomeArquivoCsv()
        Dim lstrAux As String

        Try
            istrNmArq = IIf(Me.opbInadimplencia.Checked, Me.opbInadimplencia.Text, Me.opbIrrecuperaveis.Text) & VB6.Format(Me.dtpMesAno.Value, "MMyyyy")
            Me.txtArquivo.Text = istrCaminho
            Me.txtArquivo.Text = istrNmArq & ".CSV"
            System.Windows.Forms.Application.DoEvents()

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

    End Sub

    Private Sub cmdImprimir_Click(sender As Object, e As EventArgs) Handles cmdImprimir.Click

        Try

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

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

    Private Sub NomeArquivoXML()
        Try
            istrNmArq = "APLTIQ" & VB6.Format(VB.Left(gstrEmpresa_CodRes89, 4), "0000") & "INDICADORES_"
            Me.txtArquivo.Text = istrCaminho
            Me.txtArquivo.Text = istrNmArq & VB6.Format(idteBase, "ddMMyyyy") & "_S" & VB6.Format(Me.txtVersao.Text, "00") & ".XML"
            System.Windows.Forms.Application.DoEvents()

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

    End Sub

    Private Sub frmRelInadimplencia_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
        Try

            objExecAtualizaBancoDados.QUERY_NAME = "DELETE FROM `temp_inadimplentes` WHERE `nomemaquina` = '" & My.Computer.Name & "'"
            repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

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

    End Sub

    Private Sub CriaTabelaAuxiliar()
        Dim lstrSql As String
        Dim lintAux As Short

        Try
            lstrSql = ""
            lstrSql = lstrSql & "CREATE TABLE IF NOT EXISTS `temp_inadimplentes` ("
            lstrSql = lstrSql & "`nomemaquina`            varchar(255) DEFAULT NULL, "
            lstrSql = lstrSql & "`classe`                 varchar(100) DEFAULT NULL, "
            lstrSql = lstrSql & "`suspendido`             int(11) NOT NULL default '0', "
            For lintAux = 0 To 72
                lstrSql = lstrSql & "`mes_" & VB6.Format(lintAux, "00") & "`                 varchar(7) NOT NULL default '', "
            Next lintAux
            For lintAux = 0 To 72
                lstrSql = lstrSql & "`per_" & VB6.Format(lintAux, "00") & "`                 decimal(14,2) default NULL, "
            Next lintAux
            For lintAux = 0 To 72
                lstrSql = lstrSql & "`fat_" & VB6.Format(lintAux, "00") & "`                 decimal(14,2) default NULL, "
            Next lintAux
            For lintAux = 0 To 72
                lstrSql = lstrSql & "`abe_" & VB6.Format(lintAux, "00") & "`                 decimal(14,2) default NULL, "
            Next lintAux
            lstrSql = VB.Left(lstrSql, Len(lstrSql) - 2) & ")"
            objExecAtualizaBancoDados.QUERY_NAME = lstrSql
            repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

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

    End Sub

    '	'UPGRADE_WARNING: Event opbXML.CheckedChanged 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 opbXML_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbXML.CheckedChanged
        If eventSender.Checked Then
            Call NomeArquivoXML()
        End If
    End Sub

    Private Sub txtInadiCovid_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtInadiCovid.Click
        ' Call frmRelInadimplencia_Covid.Show()
    End Sub

    '	'UPGRADE_WARNING: Event txtVersao.TextChanged 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 txtVersao_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtVersao.TextChanged
        If Me.opbXML.Checked Then
            Call NomeArquivoXML()
        End If
    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 bytBLOBData() As Byte

            Dim vlist

            Dim objEmpresa As New entidadeEmpresa
            Dim repositorioEmpresa As New repositorioEmpresa


            vlist = repositorioEmpresa.Select(objEmpresa)

            If vlist.Count <> 0 Then

                For Each objEmpresaFor As entidadeEmpresa In vlist

                    bytBLOBData = objEmpresaFor.LOGOTIPO

                Next

            End If


            Dim rpt As New ReportDocument()

            'rptRelSampNovoBaixaRenda
            If vNomeRPT = "rptRelInadimplencia" Then

                dt_2 = New DataTable()
                dt_2.Columns.Add("NOMEMAQUINA", GetType(String))
                dt_2.Columns.Add("CLASSE", GetType(String))
                dt_2.Columns.Add("SUSPENDIDO", GetType(String))
                dt_2.Columns.Add("MES_00", GetType(String))
                dt_2.Columns.Add("MES_01", GetType(String))
                dt_2.Columns.Add("MES_02", GetType(String))
                dt_2.Columns.Add("MES_03", GetType(String))
                dt_2.Columns.Add("MES_04", GetType(String))
                dt_2.Columns.Add("MES_05", GetType(String))
                dt_2.Columns.Add("MES_06", GetType(String))
                dt_2.Columns.Add("MES_07", GetType(String))
                dt_2.Columns.Add("MES_08", GetType(String))
                dt_2.Columns.Add("MES_09", GetType(String))
                dt_2.Columns.Add("MES_10", GetType(String))
                dt_2.Columns.Add("MES_11", GetType(String))
                dt_2.Columns.Add("MES_12", GetType(String))
                dt_2.Columns.Add("MES_13", GetType(String))
                dt_2.Columns.Add("MES_14", GetType(String))
                dt_2.Columns.Add("MES_15", GetType(String))
                dt_2.Columns.Add("MES_16", GetType(String))
                dt_2.Columns.Add("MES_17", GetType(String))
                dt_2.Columns.Add("MES_18", GetType(String))
                dt_2.Columns.Add("MES_19", GetType(String))
                dt_2.Columns.Add("MES_20", GetType(String))
                dt_2.Columns.Add("MES_21", GetType(String))
                dt_2.Columns.Add("MES_22", GetType(String))
                dt_2.Columns.Add("MES_23", GetType(String))
                dt_2.Columns.Add("MES_24", GetType(String))
                dt_2.Columns.Add("MES_25", GetType(String))
                dt_2.Columns.Add("MES_26", GetType(String))
                dt_2.Columns.Add("MES_27", GetType(String))
                dt_2.Columns.Add("MES_28", GetType(String))
                dt_2.Columns.Add("MES_29", GetType(String))
                dt_2.Columns.Add("MES_30", GetType(String))
                dt_2.Columns.Add("MES_31", GetType(String))
                dt_2.Columns.Add("MES_32", GetType(String))
                dt_2.Columns.Add("MES_33", GetType(String))
                dt_2.Columns.Add("MES_34", GetType(String))
                dt_2.Columns.Add("MES_35", GetType(String))
                dt_2.Columns.Add("MES_36", GetType(String))
                dt_2.Columns.Add("PER_00", GetType(String))
                dt_2.Columns.Add("PER_01", GetType(String))
                dt_2.Columns.Add("PER_02", GetType(String))
                dt_2.Columns.Add("PER_03", GetType(String))
                dt_2.Columns.Add("PER_04", GetType(String))
                dt_2.Columns.Add("PER_05", GetType(String))
                dt_2.Columns.Add("PER_06", GetType(String))
                dt_2.Columns.Add("PER_07", GetType(String))
                dt_2.Columns.Add("PER_08", GetType(String))
                dt_2.Columns.Add("PER_09", GetType(String))
                dt_2.Columns.Add("PER_10", GetType(String))
                dt_2.Columns.Add("PER_11", GetType(String))
                dt_2.Columns.Add("PER_12", GetType(String))
                dt_2.Columns.Add("PER_13", GetType(String))
                dt_2.Columns.Add("PER_14", GetType(String))
                dt_2.Columns.Add("PER_15", GetType(String))
                dt_2.Columns.Add("PER_16", GetType(String))
                dt_2.Columns.Add("PER_17", GetType(String))
                dt_2.Columns.Add("PER_18", GetType(String))
                dt_2.Columns.Add("PER_19", GetType(String))
                dt_2.Columns.Add("PER_20", GetType(String))
                dt_2.Columns.Add("PER_21", GetType(String))
                dt_2.Columns.Add("PER_22", GetType(String))
                dt_2.Columns.Add("PER_23", GetType(String))
                dt_2.Columns.Add("PER_24", GetType(String))
                dt_2.Columns.Add("PER_25", GetType(String))
                dt_2.Columns.Add("PER_26", GetType(String))
                dt_2.Columns.Add("PER_27", GetType(String))
                dt_2.Columns.Add("PER_28", GetType(String))
                dt_2.Columns.Add("PER_29", GetType(String))
                dt_2.Columns.Add("PER_30", GetType(String))
                dt_2.Columns.Add("PER_31", GetType(String))
                dt_2.Columns.Add("PER_32", GetType(String))
                dt_2.Columns.Add("PER_33", GetType(String))
                dt_2.Columns.Add("PER_34", GetType(String))
                dt_2.Columns.Add("PER_35", GetType(String))
                dt_2.Columns.Add("PER_36", GetType(String))
                dt_2.Columns.Add("FAT_00", GetType(String))
                dt_2.Columns.Add("FAT_01", GetType(String))
                dt_2.Columns.Add("FAT_02", GetType(String))
                dt_2.Columns.Add("FAT_03", GetType(String))
                dt_2.Columns.Add("FAT_04", GetType(String))
                dt_2.Columns.Add("FAT_05", GetType(String))
                dt_2.Columns.Add("FAT_06", GetType(String))
                dt_2.Columns.Add("FAT_07", GetType(String))
                dt_2.Columns.Add("FAT_08", GetType(String))
                dt_2.Columns.Add("FAT_09", GetType(String))
                dt_2.Columns.Add("FAT_10", GetType(String))
                dt_2.Columns.Add("FAT_11", GetType(String))
                dt_2.Columns.Add("FAT_12", GetType(String))
                dt_2.Columns.Add("FAT_13", GetType(String))
                dt_2.Columns.Add("FAT_14", GetType(String))
                dt_2.Columns.Add("FAT_15", GetType(String))
                dt_2.Columns.Add("FAT_16", GetType(String))
                dt_2.Columns.Add("FAT_17", GetType(String))
                dt_2.Columns.Add("FAT_18", GetType(String))
                dt_2.Columns.Add("FAT_19", GetType(String))
                dt_2.Columns.Add("FAT_20", GetType(String))
                dt_2.Columns.Add("FAT_21", GetType(String))
                dt_2.Columns.Add("FAT_22", GetType(String))
                dt_2.Columns.Add("FAT_23", GetType(String))
                dt_2.Columns.Add("FAT_24", GetType(String))
                dt_2.Columns.Add("FAT_25", GetType(String))
                dt_2.Columns.Add("FAT_26", GetType(String))
                dt_2.Columns.Add("FAT_27", GetType(String))
                dt_2.Columns.Add("FAT_28", GetType(String))
                dt_2.Columns.Add("FAT_29", GetType(String))
                dt_2.Columns.Add("FAT_30", GetType(String))
                dt_2.Columns.Add("FAT_31", GetType(String))
                dt_2.Columns.Add("FAT_32", GetType(String))
                dt_2.Columns.Add("FAT_33", GetType(String))
                dt_2.Columns.Add("FAT_34", GetType(String))
                dt_2.Columns.Add("FAT_35", GetType(String))
                dt_2.Columns.Add("FAT_36", GetType(String))
                dt_2.Columns.Add("ABE_00", GetType(String))
                dt_2.Columns.Add("ABE_01", GetType(String))
                dt_2.Columns.Add("ABE_02", GetType(String))
                dt_2.Columns.Add("ABE_03", GetType(String))
                dt_2.Columns.Add("ABE_04", GetType(String))
                dt_2.Columns.Add("ABE_05", GetType(String))
                dt_2.Columns.Add("ABE_06", GetType(String))
                dt_2.Columns.Add("ABE_07", GetType(String))
                dt_2.Columns.Add("ABE_08", GetType(String))
                dt_2.Columns.Add("ABE_09", GetType(String))
                dt_2.Columns.Add("ABE_10", GetType(String))
                dt_2.Columns.Add("ABE_11", GetType(String))
                dt_2.Columns.Add("ABE_12", GetType(String))
                dt_2.Columns.Add("ABE_13", GetType(String))
                dt_2.Columns.Add("ABE_14", GetType(String))
                dt_2.Columns.Add("ABE_15", GetType(String))
                dt_2.Columns.Add("ABE_16", GetType(String))
                dt_2.Columns.Add("ABE_17", GetType(String))
                dt_2.Columns.Add("ABE_18", GetType(String))
                dt_2.Columns.Add("ABE_19", GetType(String))
                dt_2.Columns.Add("ABE_20", GetType(String))
                dt_2.Columns.Add("ABE_21", GetType(String))
                dt_2.Columns.Add("ABE_22", GetType(String))
                dt_2.Columns.Add("ABE_23", GetType(String))
                dt_2.Columns.Add("ABE_24", GetType(String))
                dt_2.Columns.Add("ABE_25", GetType(String))
                dt_2.Columns.Add("ABE_26", GetType(String))
                dt_2.Columns.Add("ABE_27", GetType(String))
                dt_2.Columns.Add("ABE_28", GetType(String))
                dt_2.Columns.Add("ABE_29", GetType(String))
                dt_2.Columns.Add("ABE_30", GetType(String))
                dt_2.Columns.Add("ABE_31", GetType(String))
                dt_2.Columns.Add("ABE_32", GetType(String))
                dt_2.Columns.Add("ABE_33", GetType(String))
                dt_2.Columns.Add("ABE_34", GetType(String))
                dt_2.Columns.Add("ABE_35", GetType(String))
                dt_2.Columns.Add("ABE_36", GetType(String))
                dt_2.Columns.Add("IMAGEM", GetType(Byte()))
                ds = New DataSet


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

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

                        dt_2.Rows.Add(dr_1("NOMEMAQUINA"),
                                          dr_1("CLASSE"),
                                          dr_1("SUSPENDIDO"),
                                          dr_1("MES_00"),
                                          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"),
                                          dr_1("MES_13"),
                                          dr_1("MES_14"),
                                          dr_1("MES_15"),
                                          dr_1("MES_16"),
                                          dr_1("MES_17"),
                                          dr_1("MES_18"),
                                          dr_1("MES_19"),
                                          dr_1("MES_20"),
                                          dr_1("MES_21"),
                                          dr_1("MES_22"),
                                          dr_1("MES_23"),
                                          dr_1("MES_24"),
                                          dr_1("MES_25"),
                                          dr_1("MES_26"),
                                          dr_1("MES_27"),
                                          dr_1("MES_28"),
                                          dr_1("MES_29"),
                                          dr_1("MES_30"),
                                          dr_1("MES_31"),
                                          dr_1("MES_32"),
                                          dr_1("MES_33"),
                                          dr_1("MES_34"),
                                          dr_1("MES_35"),
                                          dr_1("PER_00"),
                                          dr_1("PER_01"),
                                          dr_1("PER_02"),
                                          dr_1("PER_03"),
                                          dr_1("PER_04"),
                                          dr_1("PER_05"),
                                          dr_1("PER_06"),
                                          dr_1("PER_07"),
                                          dr_1("PER_08"),
                                          dr_1("PER_09"),
                                          dr_1("PER_10"),
                                          dr_1("PER_11"),
                                          dr_1("PER_12"),
                                          dr_1("PER_13"),
                                          dr_1("PER_14"),
                                          dr_1("PER_15"),
                                          dr_1("PER_16"),
                                          dr_1("PER_17"),
                                          dr_1("PER_18"),
                                          dr_1("PER_19"),
                                          dr_1("PER_20"),
                                          dr_1("PER_21"),
                                          dr_1("PER_22"),
                                          dr_1("PER_23"),
                                          dr_1("PER_24"),
                                          dr_1("PER_25"),
                                          dr_1("PER_26"),
                                          dr_1("PER_27"),
                                          dr_1("PER_28"),
                                          dr_1("PER_29"),
                                          dr_1("PER_30"),
                                          dr_1("PER_31"),
                                          dr_1("PER_32"),
                                          dr_1("PER_33"),
                                          dr_1("PER_34"),
                                          dr_1("PER_35"),
                                          dr_1("PER_36"),
                                          dr_1("FAT_00"),
                                          dr_1("FAT_01"),
                                          dr_1("FAT_02"),
                                          dr_1("FAT_03"),
                                          dr_1("FAT_04"),
                                          dr_1("FAT_05"),
                                          dr_1("FAT_06"),
                                          dr_1("FAT_07"),
                                          dr_1("FAT_08"),
                                          dr_1("FAT_09"),
                                          dr_1("FAT_10"),
                                          dr_1("FAT_11"),
                                          dr_1("FAT_12"),
                                          dr_1("FAT_13"),
                                          dr_1("FAT_14"),
                                          dr_1("FAT_15"),
                                          dr_1("FAT_16"),
                                          dr_1("FAT_17"),
                                          dr_1("FAT_18"),
                                          dr_1("FAT_19"),
                                          dr_1("FAT_20"),
                                          dr_1("FAT_21"),
                                          dr_1("FAT_22"),
                                          dr_1("FAT_23"),
                                          dr_1("FAT_24"),
                                          dr_1("FAT_25"),
                                          dr_1("FAT_26"),
                                          dr_1("FAT_27"),
                                          dr_1("FAT_28"),
                                          dr_1("FAT_29"),
                                          dr_1("FAT_30"),
                                          dr_1("FAT_31"),
                                          dr_1("FAT_32"),
                                          dr_1("FAT_33"),
                                          dr_1("FAT_34"),
                                          dr_1("FAT_35"),
                                          dr_1("FAT_36"),
                                          dr_1("ABE_00"),
                                          dr_1("ABE_01"),
                                          dr_1("ABE_02"),
                                          dr_1("ABE_03"),
                                          dr_1("ABE_04"),
                                          dr_1("ABE_05"),
                                          dr_1("ABE_06"),
                                          dr_1("ABE_07"),
                                          dr_1("ABE_08"),
                                          dr_1("ABE_09"),
                                          dr_1("ABE_10"),
                                          dr_1("ABE_11"),
                                          dr_1("ABE_12"),
                                          dr_1("ABE_13"),
                                          dr_1("ABE_14"),
                                          dr_1("ABE_15"),
                                          dr_1("ABE_16"),
                                          dr_1("ABE_17"),
                                          dr_1("ABE_18"),
                                          dr_1("ABE_19"),
                                          dr_1("ABE_20"),
                                          dr_1("ABE_21"),
                                          dr_1("ABE_22"),
                                          dr_1("ABE_23"),
                                          dr_1("ABE_24"),
                                          dr_1("ABE_25"),
                                          dr_1("ABE_26"),
                                          dr_1("ABE_27"),
                                          dr_1("ABE_28"),
                                          dr_1("ABE_29"),
                                          dr_1("ABE_30"),
                                          dr_1("ABE_31"),
                                          dr_1("ABE_32"),
                                          dr_1("ABE_33"),
                                          dr_1("ABE_34"),
                                          dr_1("ABE_35"),
                                          dr_1("ABE_36"),
                                          bytBLOBData)

                    Next dr_1
                End If

                ds.Tables.Add(dt)
                ds.Tables(0).TableName = "REL_INADIMPLENCIA"

                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 rptRelinadimplencia

                    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("MesAnoRef", Month(dtpMesAno.Value) & "/" & Year(dtpMesAno.Value))
                    'rpt.SetParameterValue("NomeRel", "Grupo A - Livre\Parcial.Cativo")

                    frmViewRelatorios.rpt = rpt

                    frmViewRelatorios.CRViewer.Zoom((100))
                    frmViewRelatorios.Text = "Relatório Grupo A - Livre\Parcial.Cativo"
                    frmViewRelatorios.ShowDialog()

                End If


            End If
        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