Option Strict Off
Option Explicit On

Imports fatd_faturamento.BLL.Repositorio
Imports fatd_faturamento.ENTIDADE
Friend Class frmCadCobDevGrupoA
    Inherits System.Windows.Forms.Form

    Dim iintMesIniPerSeco As Short
    Dim iintMesFimPerSeco As Short
    Dim iintBanderiaVigente As Short
    Dim idteBandeira As Date
    Dim ilngUnidId As Integer
    Dim ilngConsId As Integer
    Dim istrGrupo As String
    Dim idblId As Double

#Region "Propriedades"

    Private Sub frmCadCobDevGrupoA_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load

        Try


            idblId = 0
            iintMesIniPerSeco = Val(GetConfig("mes.ini.periodo.seco"))
            iintMesFimPerSeco = iintMesIniPerSeco + 6

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtMesAno_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtMesAno.Enter


        Try



            With Me.txtMesAno
                .Text = Replace(.Text, "/", "")
                .SelectionStart = 0
                .SelectionLength = CInt(Len(.Text))
            End With


        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtMesAno_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtMesAno.Leave

        Try


            Me.txtMesAno.Text = FormataData(txtMesAno, 1)



        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtMesAnoFat_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtMesAnoFat.Enter


        Try



            With Me.txtMesAnoFat
                .Text = Replace(.Text, "/", "")
                .SelectionStart = 0
                .SelectionLength = CInt(Len(.Text))
            End With


        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtMesAnoFat_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtMesAnoFat.Leave


        Try

            Me.txtMesAnoFat.Text = FormataData(txtMesAnoFat, 1)




        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtNQtd_Con_P_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtNQtd_Con_P.Enter


        Try


            With Me.txtNQtd_Con_P
                .Text = Replace(.Text, ".", "")
                .SelectionStart = 0
                .SelectionLength = CInt(Len(.Text))
            End With



        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtNQtd_Con_P_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtNQtd_Con_P.KeyPress

        Dim KeyAscii As Short = Asc(eventArgs.KeyChar)


        Try


            If KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
                If KeyAscii = System.Windows.Forms.Keys.Delete Then
                    KeyAscii = System.Windows.Forms.Keys.Snapshot
                End If
                If KeyAscii <> System.Windows.Forms.Keys.Snapshot Then
                    KeyAscii = 0
                Else
                    If InStr(1, Me.txtNQtd_Con_P.Text, ",") > 0 Then
                        KeyAscii = 0
                    End If
                End If
            End If

            eventArgs.KeyChar = Chr(KeyAscii)

            If KeyAscii = 0 Then
                eventArgs.Handled = True
            End If



        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtNQtd_Con_P_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtNQtd_Con_P.Leave


        Try


            With Me.txtNQtd_Con_P
                .Text = VB6.Format(IIf(Len(.Text) = 0, 0, .Text), "#,##0.00")
            End With
            CalcVlr_Dif()



        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtNQtd_Con_F_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtNQtd_Con_F.Enter


        Try


            With Me.txtNQtd_Con_F
                .Text = Replace(.Text, ".", "")
                .SelectionStart = 0
                .SelectionLength = CInt(Len(.Text))
            End With



        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtNQtd_Con_F_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtNQtd_Con_F.KeyPress

        Dim KeyAscii As Short = Asc(eventArgs.KeyChar)


        Try

            If KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
                If KeyAscii = System.Windows.Forms.Keys.Delete Then
                    KeyAscii = System.Windows.Forms.Keys.Snapshot
                End If
                If KeyAscii <> System.Windows.Forms.Keys.Snapshot Then
                    KeyAscii = 0
                Else
                    If InStr(1, Me.txtNQtd_Con_F.Text, ",") > 0 Then
                        KeyAscii = 0
                    End If
                End If
            End If

            eventArgs.KeyChar = Chr(KeyAscii)

            If KeyAscii = 0 Then
                eventArgs.Handled = True
            End If




        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtNQtd_Con_F_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtNQtd_Con_F.Leave


        Try


            With Me.txtNQtd_Con_F
                .Text = VB6.Format(IIf(Len(.Text) = 0, 0, .Text), "#,##0.00")
            End With
            CalcVlr_Dif()



        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtNQtd_Dem_P_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtNQtd_Dem_P.Enter


        Try


            With Me.txtNQtd_Dem_P
                .Text = Replace(.Text, ".", "")
                .SelectionStart = 0
                .SelectionLength = CInt(Len(.Text))
            End With



        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtNQtd_Dem_P_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtNQtd_Dem_P.KeyPress

        Dim KeyAscii As Short = Asc(eventArgs.KeyChar)


        Try


            If KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
                If KeyAscii = System.Windows.Forms.Keys.Delete Then
                    KeyAscii = System.Windows.Forms.Keys.Snapshot
                End If
                If KeyAscii <> System.Windows.Forms.Keys.Snapshot Then
                    KeyAscii = 0
                Else
                    If InStr(1, Me.txtNQtd_Dem_P.Text, ",") > 0 Then
                        KeyAscii = 0
                    End If
                End If
            End If

            eventArgs.KeyChar = Chr(KeyAscii)

            If KeyAscii = 0 Then
                eventArgs.Handled = True
            End If



        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtNQtd_Dem_P_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtNQtd_Dem_P.Leave


        Try


            With Me.txtNQtd_Dem_P
                .Text = VB6.Format(IIf(Len(.Text) = 0, 0, .Text), "#,##0.00")
            End With
            CalcVlr_Dif()



        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtNQtd_Dem_F_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtNQtd_Dem_F.Enter


        Try


            With Me.txtNQtd_Dem_F
                .Text = Replace(.Text, ".", "")
                .SelectionStart = 0
                .SelectionLength = CInt(Len(.Text))
            End With



        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtNQtd_Dem_F_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtNQtd_Dem_F.KeyPress

        Dim KeyAscii As Short = Asc(eventArgs.KeyChar)


        Try


            If KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
                If KeyAscii = System.Windows.Forms.Keys.Delete Then
                    KeyAscii = System.Windows.Forms.Keys.Snapshot
                End If
                If KeyAscii <> System.Windows.Forms.Keys.Snapshot Then
                    KeyAscii = 0
                Else
                    If InStr(1, Me.txtNQtd_Dem_F.Text, ",") > 0 Then
                        KeyAscii = 0
                    End If
                End If
            End If

            eventArgs.KeyChar = Chr(KeyAscii)

            If KeyAscii = 0 Then
                eventArgs.Handled = True
            End If



        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtNQtd_Dem_F_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtNQtd_Dem_F.Leave


        Try



            With Me.txtNQtd_Dem_F
                .Text = VB6.Format(IIf(Len(.Text) = 0, 0, .Text), "#,##0.00")
            End With
            CalcVlr_Dif()


        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtNQtd_Rea_P_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtNQtd_Rea_P.Enter

        Try



            With Me.txtNQtd_Rea_P
                .Text = Replace(.Text, ".", "")
                .SelectionStart = 0
                .SelectionLength = CInt(Len(.Text))
            End With



        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtNQtd_Rea_P_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtNQtd_Rea_P.KeyPress
        Dim KeyAscii As Short = Asc(eventArgs.KeyChar)

        Try


            If KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
                If KeyAscii = System.Windows.Forms.Keys.Delete Then
                    KeyAscii = System.Windows.Forms.Keys.Snapshot
                End If
                If KeyAscii <> System.Windows.Forms.Keys.Snapshot Then
                    KeyAscii = 0
                Else
                    If InStr(1, Me.txtNQtd_Rea_P.Text, ",") > 0 Then
                        KeyAscii = 0
                    End If
                End If
            End If

            eventArgs.KeyChar = Chr(KeyAscii)

            If KeyAscii = 0 Then
                eventArgs.Handled = True
            End If




        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtNQtd_Rea_P_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtNQtd_Rea_P.Leave


        Try


            With Me.txtNQtd_Rea_P
                .Text = VB6.Format(IIf(Len(.Text) = 0, 0, .Text), "#,##0.00")
            End With
            CalcVlr_Dif()



        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtNQtd_Rea_F_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtNQtd_Rea_F.Enter

        Try

            With Me.txtNQtd_Rea_F
                .Text = Replace(.Text, ".", "")
                .SelectionStart = 0
                .SelectionLength = CInt(Len(.Text))
            End With





        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtNQtd_Rea_F_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtNQtd_Rea_F.KeyPress

        Dim KeyAscii As Short = Asc(eventArgs.KeyChar)


        Try


            If KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
                If KeyAscii = System.Windows.Forms.Keys.Delete Then
                    KeyAscii = System.Windows.Forms.Keys.Snapshot
                End If
                If KeyAscii <> System.Windows.Forms.Keys.Snapshot Then
                    KeyAscii = 0
                Else
                    If InStr(1, Me.txtNQtd_Rea_F.Text, ",") > 0 Then
                        KeyAscii = 0
                    End If
                End If
            End If

            eventArgs.KeyChar = Chr(KeyAscii)

            If KeyAscii = 0 Then
                eventArgs.Handled = True
            End If



        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtNQtd_Rea_F_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtNQtd_Rea_F.Leave


        Try


            With Me.txtNQtd_Rea_F
                .Text = VB6.Format(IIf(Len(.Text) = 0, 0, .Text), "#,##0.00")
            End With
            CalcVlr_Dif()



        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub cmdSalvar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSalvar.Click

        Dim lstrSql As String

        Dim objAtualizaBancoDados As New entidadeAtualizaBancoDados
        Dim repositorioAtualizaBancoDados As New repositorioAtualizaBancoDados


        Try

            If idblId > 0 Then
                lstrSql = "UPDATE "
            Else
                lstrSql = "INSERT INTO "
            End If
            lstrSql = lstrSql & "cobranca_devolucao_grupo_a SET "
            lstrSql = lstrSql & "zona = '" & Me.txtZona.Text & "', "
            lstrSql = lstrSql & "livro = '" & Me.txtLivro.Text & "', "
            lstrSql = lstrSql & "conta = '" & Me.txtConta.Text & "', "
            lstrSql = lstrSql & "consumo_p = " & Replace(CStr(CDbl(IIf(IsNumeric(Me.txtNQtd_Con_P.Text), Me.txtNQtd_Con_P.Text, 0))), ",", ".") & ", "
            lstrSql = lstrSql & "tar_con_p = " & Replace(CStr(CDbl(IIf(IsNumeric(Me.txtTar_N_Con_P.Text), Me.txtTar_N_Con_P.Text, 0))), ",", ".") & ", "
            lstrSql = lstrSql & "tar_ban_p = " & Replace(CStr(CDbl(IIf(IsNumeric(Me.txtTar_N_Ban_P.Text), Me.txtTar_N_Ban_P.Text, 0))), ",", ".") & ", "
            lstrSql = lstrSql & "consumo_f = " & Replace(CStr(CDbl(IIf(IsNumeric(Me.txtNQtd_Con_F.Text), Me.txtNQtd_Con_F.Text, 0))), ",", ".") & ", "
            lstrSql = lstrSql & "tar_con_f = " & Replace(CStr(CDbl(IIf(IsNumeric(Me.txtTar_N_Con_F.Text), Me.txtTar_N_Con_F.Text, 0))), ",", ".") & ", "
            lstrSql = lstrSql & "tar_ban_f = " & Replace(CStr(CDbl(IIf(IsNumeric(Me.txtTar_N_Ban_F.Text), Me.txtTar_N_Ban_F.Text, 0))), ",", ".") & ", "
            lstrSql = lstrSql & "demanda_p = " & Replace(CStr(CDbl(IIf(IsNumeric(Me.txtNQtd_Dem_P.Text), Me.txtNQtd_Dem_P.Text, 0))), ",", ".") & ", "
            lstrSql = lstrSql & "tar_dem_p = " & Replace(CStr(CDbl(IIf(IsNumeric(Me.txtTar_N_Dem_P.Text), Me.txtTar_N_Dem_P.Text, 0))), ",", ".") & ", "
            lstrSql = lstrSql & "demanda_f = " & Replace(CStr(CDbl(IIf(IsNumeric(Me.txtNQtd_Dem_F.Text), Me.txtNQtd_Dem_F.Text, 0))), ",", ".") & ", "
            lstrSql = lstrSql & "tar_dem_f = " & Replace(CStr(CDbl(IIf(IsNumeric(Me.txtTar_N_Dem_F.Text), Me.txtTar_N_Dem_F.Text, 0))), ",", ".") & ", "
            lstrSql = lstrSql & "reativo_p = " & Replace(CStr(CDbl(IIf(IsNumeric(Me.txtNQtd_Rea_P.Text), Me.txtNQtd_Rea_P.Text, 0))), ",", ".") & ", "
            lstrSql = lstrSql & "tar_rea_p = " & Replace(CStr(CDbl(IIf(IsNumeric(Me.txtTar_N_Rea_P.Text), Me.txtTar_N_Rea_P.Text, 0))), ",", ".") & ", "
            lstrSql = lstrSql & "reativo_f = " & Replace(CStr(CDbl(IIf(IsNumeric(Me.txtNQtd_Rea_F.Text), Me.txtNQtd_Rea_F.Text, 0))), ",", ".") & ", "
            lstrSql = lstrSql & "tar_rea_f = " & Replace(CStr(CDbl(IIf(IsNumeric(Me.txtTar_N_Rea_F.Text), Me.txtTar_N_Rea_F.Text, 0))), ",", ".") & ", "
            lstrSql = lstrSql & "numero_fiscal = " & Me.txtNumNf.Text & ", "
            lstrSql = lstrSql & "anomes_ref = " & Microsoft.VisualBasic.Right(Me.txtMesAno.Text, 4) & Microsoft.VisualBasic.Left(Me.txtMesAno.Text, 2) & ", "
            lstrSql = lstrSql & "anomes_fat = " & Microsoft.VisualBasic.Right(Me.txtMesAnoFat.Text, 4) & Microsoft.VisualBasic.Left(Me.txtMesAnoFat.Text, 2) & " "

            If idblId > 0 Then
                lstrSql = lstrSql & " WHERE id = " & idblId
            End If

            objAtualizaBancoDados.QUERY_NAME = lstrSql
            repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

            MessageBox.Show("Registro salvo com sucesso!", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information)



        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - 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


        Try

            lClose()

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try


    End Sub

    Private Sub cmdLocalizaFatura_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdLocalizaFatura.Click

        Dim ldteAtu As Date
        Dim ldteAnt As Date
        Dim lintPCat As Short
        Dim lintLVer As Short
        Dim lstrIte As String
        Dim lstrSql As String

        Dim dt As DataTable
        Dim dt_1 As DataTable


        Dim objAtualizaBancoDados As New entidadeAtualizaBancoDados
        Dim repositorioAtualizaBancoDados As New repositorioAtualizaBancoDados


        Try


            idblId = 0
            lstrSql = "SELECT * FROM `nf` "
            lstrSql = lstrSql & " WHERE `cons_id` = " & ilngConsId & " "
            'lstrSql = lstrSql & "   AND `unid_id` = " & ilngUnidId & " "
            'lstrSql = lstrSql & "   AND `zona` = '" & Me.txtZona.Text & "' "
            'lstrSql = lstrSql & "   AND `livro` = '" & Me.txtLivro.Text & "' "
            'lstrSql = lstrSql & "   AND `conta` = '" & Me.txtConta.Text & "' "
            lstrSql = lstrSql & "   AND `numnf` = " & Me.txtNumNf.Text & " "
            lstrSql = lstrSql & "   AND `mesano` = '" & Me.txtMesAno.Text & "' "

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


            If dt.Rows.Count <> 0 Then

                For Each row As DataRow In dt.Rows

                    lstrIte = IIf(IsDBNull(row("itensserv")), "", row("itensserv"))

                    ldteAtu = IIf(IsDBNull(row("dataleit")), "01/01/1900", row("dataleit"))

                    ldteAnt = IIf(IsDBNull(row("dataleitant")), "01/01/1900", row("dataleitant"))

                    lintPCat = IIf(IsDBNull(row("parcialmente_cativo")), 0, row("parcialmente_cativo"))

                    lintLVer = IIf(IsDBNull(row("livre_verde")), 0, row("livre_verde"))
                    'Quantidades
                    Me.txtQtd_Con_P.Text = VB6.Format(BuscaValorItem(lstrIte, "0302010010"), "#,##0.00")
                    Me.txtQtd_Con_F.Text = VB6.Format(BuscaValorItem(lstrIte, "0302010011"), "#,##0.00")
                    Me.txtQtd_Dem_P.Text = VB6.Format(BuscaValorItem(lstrIte, "0302010021"), "#,##0.00")
                    Me.txtQtd_Dem_F.Text = VB6.Format(BuscaValorItem(lstrIte, "0302010023"), "#,##0.00")
                    Me.txtQtd_Rea_P.Text = VB6.Format(BuscaValorItem(lstrIte, "0302010013"), "#,##0.00")
                    Me.txtQtd_Rea_F.Text = VB6.Format(BuscaValorItem(lstrIte, "0302010014"), "#,##0.00")
                    'Valores
                    Me.txtVlr_Con_P.Text = VB6.Format(BuscaValorItem(lstrIte, "0302020010"), "#,##0.00")
                    Me.txtVlr_Con_F.Text = VB6.Format(BuscaValorItem(lstrIte, "0302020011"), "#,##0.00")
                    Me.txtVlr_Ban_P.Text = VB6.Format(BuscaValorItem(lstrIte, "0302120010"), "#,##0.00")
                    Me.txtVlr_Ban_F.Text = VB6.Format(BuscaValorItem(lstrIte, "0302120011"), "#,##0.00")
                    Me.txtVlr_Dem_P.Text = VB6.Format(BuscaValorItem(lstrIte, "0302020021"), "#,##0.00")
                    Me.txtVlr_Dem_F.Text = VB6.Format(BuscaValorItem(lstrIte, "0302020023"), "#,##0.00")
                    Me.txtVlr_Rea_P.Text = VB6.Format(BuscaValorItem(lstrIte, "0302020013"), "#,##0.00")
                    Me.txtVlr_Rea_F.Text = VB6.Format(BuscaValorItem(lstrIte, "0302020014"), "#,##0.00")
                    'Tarifas
                    Me.txtTar_Con_P.Text = VB6.Format(BuscaValorItem(lstrIte, "01" & Me.txtTa.Text & "011101"), "#,#####0.00000") : If CDbl(Me.txtTar_Con_P.Text) = 0 Then Me.txtTar_Con_P.Text = VB6.Format(BuscaValorItem(lstrIte, "01" & Me.txtTa.Text & "011105"), "#,#####0.00000")
                    Me.txtTar_Con_F.Text = VB6.Format(BuscaValorItem(lstrIte, "01" & Me.txtTa.Text & "011102"), "#,#####0.00000") : If CDbl(Me.txtTar_Con_F.Text) = 0 Then Me.txtTar_Con_F.Text = VB6.Format(BuscaValorItem(lstrIte, "01" & Me.txtTa.Text & "011106"), "#,#####0.00000")
                    Me.txtTar_Ban_P.Text = VB6.Format(BuscaValorItem(lstrIte, "01" & Me.txtTa.Text & "011111"), "#,#####0.00000") : If CDbl(Me.txtTar_Ban_P.Text) = 0 Then Me.txtTar_Ban_P.Text = VB6.Format(BuscaValorItem(lstrIte, "01" & Me.txtTa.Text & "011115"), "#,#####0.00000")
                    Me.txtTar_Ban_F.Text = VB6.Format(BuscaValorItem(lstrIte, "01" & Me.txtTa.Text & "011112"), "#,#####0.00000") : If CDbl(Me.txtTar_Ban_F.Text) = 0 Then Me.txtTar_Ban_F.Text = VB6.Format(BuscaValorItem(lstrIte, "01" & Me.txtTa.Text & "011116"), "#,#####0.00000")
                    Me.txtTar_Dem_P.Text = VB6.Format(BuscaValorItem(lstrIte, "01" & Me.txtTa.Text & "012101"), "#,#####0.00000")
                    Me.txtTar_Dem_F.Text = VB6.Format(BuscaValorItem(lstrIte, "01" & Me.txtTa.Text & "012102"), "#,#####0.00000")
                    Me.txtTar_Rea_P.Text = VB6.Format(Microsoft.VisualBasic.Left(Microsoft.VisualBasic.Right(Replace(BuscaRefItem(lstrIte, "0302020013"), " ", ""), 8), 7), "#,#####0.00000")
                    Me.txtTar_Rea_F.Text = VB6.Format(Microsoft.VisualBasic.Left(Microsoft.VisualBasic.Right(Replace(BuscaRefItem(lstrIte, "0302020014"), " ", ""), 8), 7), "#,#####0.00000")


                    TarifaHorosazonal(ldteAtu, ldteAnt, False)

                    lstrSql = "SELECT * FROM cobranca_devolucao_grupo_a WHERE "
                    lstrSql = lstrSql & "zona = '" & Me.txtZona.Text & "' AND "
                    lstrSql = lstrSql & "livro = '" & Me.txtLivro.Text & "' AND "
                    lstrSql = lstrSql & "conta = '" & Me.txtConta.Text & "' AND "
                    lstrSql = lstrSql & "numero_fiscal = " & Me.txtNumNf.Text & " AND "
                    lstrSql = lstrSql & "anomes_ref = " & Microsoft.VisualBasic.Right(Me.txtMesAno.Text, 4) & Microsoft.VisualBasic.Left(Me.txtMesAno.Text, 2) & " "

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


                    If dt_1.Rows.Count <> 0 Then

                        For Each row_1 As DataRow In dt_1.Rows

                            idblId = IIf(IsDBNull(row_1("id")), 0, row_1("id"))

                            Me.txtNQtd_Con_P.Text = VB6.Format(IIf(IsDBNull(row_1("consumo_p")), 0, row_1("consumo_p")), "#,##0.00")

                            Me.txtNQtd_Con_F.Text = VB6.Format(IIf(IsDBNull(row_1("consumo_f")), 0, row_1("consumo_f")), "#,##0.00")

                            Me.txtNQtd_Dem_P.Text = VB6.Format(IIf(IsDBNull(row_1("demanda_p")), 0, row_1("demanda_p")), "#,##0.00")

                            Me.txtNQtd_Dem_F.Text = VB6.Format(IIf(IsDBNull(row_1("demanda_f")), 0, row_1("demanda_f")), "#,##0.00")

                            Me.txtNQtd_Rea_P.Text = VB6.Format(IIf(IsDBNull(row_1("reativo_p")), 0, row_1("reativo_p")), "#,##0.00")

                            Me.txtNQtd_Rea_F.Text = VB6.Format(IIf(IsDBNull(row_1("reativo_f")), 0, row_1("reativo_f")), "#,##0.00")

                            Me.txtMesAnoFat.Text = IIf(IsDBNull(row_1("anomes_fat")), 0, row_1("anomes_fat"))
                            Me.txtMesAnoFat.Text = Microsoft.VisualBasic.Right(Me.txtMesAnoFat.Text, 2) & "/" & Microsoft.VisualBasic.Left(Me.txtMesAnoFat.Text, 4)

                            CalcVlr_Dif()

                        Next

                    End If


                Next

            End If


        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub frmCadCobDevGrupoA_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed

        Try

            If Not vfrmOld Is Nothing Then
                vfrmOld.Enabled = True
            End If

            vfrmOld = Nothing

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub frmCadCobDevGrupoA_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress

        Dim KeyAscii As Short = Asc(eventArgs.KeyChar)


        Try



            If KeyAscii = System.Windows.Forms.Keys.Escape Then
                Me.Close()
            ElseIf KeyAscii = System.Windows.Forms.Keys.Return Then
                TabEnter(KeyAscii, eventArgs)
            End If
            eventArgs.KeyChar = Chr(KeyAscii)
            If KeyAscii = 0 Then
                eventArgs.Handled = True
            End If


        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub


#End Region

#Region "Métodos"

    Private Sub lClose()

        Try

            Close()

        Catch ex As Exception
            Exit Sub
        End Try

    End Sub

    Public Sub SetaParametros(ByRef afrmQuemChama As System.Windows.Forms.Form, ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String, ByVal alngUnidId As Integer, ByVal alngConsId As Object, ByVal astrGrupo As String, ByVal astrGrTar As String, ByVal astrNome As String, ByVal aintBanderiaVigente As Short, ByVal adteBandeira As Date)


        Try

            If Not vfrmOld Is Nothing Then

                vfrmOld = afrmQuemChama

                Me.txtZona.Text = astrZona
                Me.txtLivro.Text = astrLivro
                Me.txtConta.Text = astrConta
                Me.txtTa.Text = Mid(astrGrTar, 3, 2)
                Me.txtNome.Text = astrNome
                ilngUnidId = alngUnidId
                ilngConsId = alngConsId
                vfrmOld.Enabled = False
                iintBanderiaVigente = aintBanderiaVigente
                idteBandeira = adteBandeira

            End If

        Catch ex As Exception
            Exit Sub
        End Try

    End Sub

    Private Sub CalcVlr_Dif()

        Try

            If IsNumeric(Me.txtNQtd_Con_P.Text) Then
                If CDbl(Me.txtNQtd_Con_P.Text) > 0 Then
                    Me.txtNVlr_Con_P.Text = VB6.Format(Truncate(CDbl(Me.txtNQtd_Con_P.Text) * CDbl(Me.txtTar_N_Con_P.Text), 2), "#,##0.00")
                    Me.txtDVlr_Con_P.Text = VB6.Format(Truncate(CDbl(Me.txtNVlr_Con_P.Text) - CDbl(Me.txtVlr_Con_P.Text), 2), "#,##0.00")
                    Me.txtNVlr_Ban_P.Text = VB6.Format(Truncate(CDbl(Me.txtNQtd_Con_P.Text) * CDbl(Me.txtTar_N_Ban_P.Text), 2), "#,##0.00")
                    Me.txtDVlr_Ban_P.Text = VB6.Format(Truncate(CDbl(Me.txtNVlr_Ban_P.Text) - CDbl(Me.txtVlr_Ban_P.Text), 2), "#,##0.00")
                End If
            End If

            If IsNumeric(Me.txtNQtd_Con_F.Text) Then
                If CDbl(Me.txtNQtd_Con_F.Text) > 0 Then
                    Me.txtNVlr_Con_F.Text = VB6.Format(Truncate(CDbl(Me.txtNQtd_Con_F.Text) * CDbl(Me.txtTar_N_Con_F.Text), 2), "#,##0.00")
                    Me.txtDVlr_Con_F.Text = VB6.Format(Truncate(CDbl(Me.txtNVlr_Con_F.Text) - CDbl(Me.txtVlr_Con_F.Text), 2), "#,##0.00")
                    Me.txtNVlr_Ban_F.Text = VB6.Format(Truncate(CDbl(Me.txtNQtd_Con_F.Text) * CDbl(Me.txtTar_N_Ban_F.Text), 2), "#,##0.00")
                    Me.txtDVlr_Ban_F.Text = VB6.Format(Truncate(CDbl(Me.txtNVlr_Ban_F.Text) - CDbl(Me.txtVlr_Ban_F.Text), 2), "#,##0.00")
                End If
            End If

            If IsNumeric(Me.txtNQtd_Dem_P.Text) Then
                If CDbl(Me.txtNQtd_Dem_P.Text) > 0 Then
                    Me.txtNVlr_Dem_P.Text = VB6.Format(Truncate(CDbl(Me.txtNQtd_Dem_P.Text) * CDbl(Me.txtTar_N_Dem_P.Text), 2), "#,##0.00")
                    Me.txtDVlr_Dem_P.Text = VB6.Format(Truncate(CDbl(Me.txtNVlr_Dem_P.Text) - CDbl(Me.txtVlr_Dem_P.Text), 2), "#,##0.00")
                End If
            End If

            If IsNumeric(Me.txtNQtd_Dem_F.Text) Then
                If CDbl(Me.txtNQtd_Dem_F.Text) > 0 Then
                    Me.txtNVlr_Dem_F.Text = VB6.Format(Truncate(CDbl(Me.txtNQtd_Dem_F.Text) * CDbl(Me.txtTar_N_Dem_F.Text), 2), "#,##0.00")
                    Me.txtDVlr_Dem_F.Text = VB6.Format(Truncate(CDbl(Me.txtNVlr_Dem_F.Text) - CDbl(Me.txtVlr_Dem_F.Text), 2), "#,##0.00")
                End If
            End If

            If IsNumeric(Me.txtNQtd_Rea_P.Text) Then
                If CDbl(Me.txtNQtd_Rea_P.Text) > 0 Then
                    Me.txtNVlr_Rea_P.Text = VB6.Format(Truncate(CDbl(Me.txtNQtd_Rea_P.Text) * CDbl(Me.txtTar_N_Rea_P.Text), 2), "#,##0.00")
                    Me.txtDVlr_Rea_P.Text = VB6.Format(Truncate(CDbl(Me.txtNVlr_Rea_P.Text) - CDbl(Me.txtVlr_Rea_P.Text), 2), "#,##0.00")
                End If
            End If

            If IsNumeric(Me.txtNQtd_Rea_F.Text) Then
                If CDbl(Me.txtNQtd_Rea_F.Text) > 0 Then
                    Me.txtNVlr_Rea_F.Text = VB6.Format(Truncate(CDbl(Me.txtNQtd_Rea_F.Text) * CDbl(Me.txtTar_N_Rea_F.Text), 2), "#,##0.00")
                    Me.txtDVlr_Rea_F.Text = VB6.Format(Truncate(CDbl(Me.txtNVlr_Rea_F.Text) - CDbl(Me.txtVlr_Rea_F.Text), 2), "#,##0.00")
                End If
            End If

        Catch ex As Exception
            Exit Sub
        End Try

    End Sub

    Private Sub TarifaHorosazonal(ByVal adteLeitAtual As Date, ByVal adteLeitAnterior As Date, Optional ByVal ablnParCat As Boolean = False)

        'Monta as tarifas do HoroSazonal
        Dim lintMesLeitAtual As Short
        Dim lstrCodigo As String
        Dim lstrGrTar As String
        Dim ldblTarifa As Double
        Dim lblnPeriodo As Boolean

        Try

            lstrGrTar = "01" & Trim(Microsoft.VisualBasic.Left(Trim(Me.txtTa.Text), 4))

            lintMesLeitAtual = CShort(Month(adteLeitAtual))
            'Periodo seco / úmido
            lblnPeriodo = (lintMesLeitAtual >= iintMesIniPerSeco And lintMesLeitAtual <= iintMesFimPerSeco)
            '                      01                 6                  01                      12

            Me.txtTar_N_Rea_P.Text = CStr(TarifaProporcional(adteLeitAnterior, adteLeitAtual, "01B1011301", 3, "") / 1000)
            Me.txtTar_N_Rea_F.Text = Me.txtTar_N_Rea_P.Text

            '************************************************************
            '* Consumo na ponta                                         *
            '*               Período      Seco  ou  Úmido               *
            '************************************************************
            If ablnParCat Then 'Parc Cativo 'Implementando em 04/06/2014
                lstrCodigo = "01AA" & IIf(lblnPeriodo, "011101", "011105")
                Me.txtTar_N_Con_P.Text = CStr(TarifaProporcional(adteLeitAnterior, adteLeitAtual, lstrCodigo, 3) / 1000)
                'idblTarConsumoSemDesconto_p = 0 'idblTarConsumo_p
                If Microsoft.VisualBasic.Left(lstrCodigo, 4) = "01AX" Then
                    Me.txtTar_N_Ban_P.Text = CStr(0)
                Else
                    Me.txtTar_N_Ban_P.Text = CStr(TarifaProporcionalBandeira(adteLeitAnterior, adteLeitAtual, iintBanderiaVigente, idteBandeira) / 1000)
                End If
                'Item_Fatura = Trim(Item_Fatura & lstrCodigo & "?" & Replace(idblTarConsumo_p, ",", ".") & "$;")
                'Bandeira
                lstrCodigo = "01AA0111" & iintBanderiaVigente & IIf(lblnPeriodo, "1", "5")
                'Item_Fatura = Trim(Item_Fatura & lstrCodigo & "?" & Replace(idblTarConsumoBan_p, ",", ".") & "$;")
                '
                lstrCodigo = lstrGrTar & IIf(lblnPeriodo, "011101", "011105")
                'idblTarConsumoLiv_p = TarifaProporcional(adteLeitAnterior, adteLeitAtual, lstrCodigo, 3) / 1000
                'Item_Fatura = Trim(Item_Fatura & lstrCodigo & "?" & Replace(idblTarConsumoLiv_p, ",", ".") & "$;")
            Else
                lstrCodigo = lstrGrTar & IIf(lblnPeriodo, "011101", "011105")
                Me.txtTar_N_Con_P.Text = CStr(TarifaProporcional(adteLeitAnterior, adteLeitAtual, lstrCodigo, 3) / 1000)
                'If iintLivreVerde = 1 And lstrGrTar = "01AL" Then
                '  Me.txtTar_N_Con_P.Text = TarifaProporcional(adteLeitAnterior, adteLeitAtual, Strings.Replace(Strings.Replace(Strings.Replace(lstrCodigo, "01AL", "01AV"), "011101", "011201"), "011105", "011205"), 3) / 1000
                'End If
                'idblTarConsumoSemDesconto_p = 0 'idblTarConsumo_p
                If Microsoft.VisualBasic.Left(lstrCodigo, 4) = "01AX" Or Microsoft.VisualBasic.Left(lstrCodigo, 4) = "01AL" Then
                    Me.txtTar_N_Ban_P.Text = CStr(0)
                Else
                    Me.txtTar_N_Ban_P.Text = CStr(TarifaProporcionalBandeira(adteLeitAnterior, adteLeitAtual, iintBanderiaVigente, idteBandeira) / 1000)
                End If
                'Item_Fatura = Trim(Item_Fatura & lstrCodigo & "?" & Replace(idblTarConsumo_p, ",", ".") & "$;")
                'Bandeira
                lstrCodigo = lstrGrTar & "0111" & iintBanderiaVigente & IIf(lblnPeriodo, "1", "5")
                'Item_Fatura = Trim(Item_Fatura & lstrCodigo & "?" & Replace(idblTarConsumoBan_p, ",", ".") & "$;")
            End If
            '************************************************************
            '* Consumo fora da ponta                                    *
            '*               Período      Seco  ou  Úmido               *
            '************************************************************
            If ablnParCat Then 'Parc Cativo 'Implementando em 04/06/2014
                lstrCodigo = "01AA" & IIf(lblnPeriodo, "011102", "011106")
                Me.txtTar_N_Con_F.Text = CStr(TarifaProporcional(adteLeitAnterior, adteLeitAtual, lstrCodigo, 3) / 1000)
                'idblTarConsumoSemDesconto_fp = 0 'idblTarConsumo_fp
                If Microsoft.VisualBasic.Left(lstrCodigo, 4) = "01AX" Then
                    Me.txtTar_N_Ban_F.Text = CStr(0)
                Else
                    Me.txtTar_N_Ban_F.Text = CStr(TarifaProporcionalBandeira(adteLeitAnterior, adteLeitAtual, iintBanderiaVigente, idteBandeira) / 1000)
                End If
                'Item_Fatura = Trim(Item_Fatura & lstrCodigo & "?" & Replace(idblTarConsumo_fp, ",", ".") & "$;")
                'Bandeira
                lstrCodigo = "01AA0111" & iintBanderiaVigente & IIf(lblnPeriodo, "2", "6")
                'Item_Fatura = Trim(Item_Fatura & lstrCodigo & "?" & Replace(idblTarConsumoBan_fp, ",", ".") & "$;")
                '
                lstrCodigo = lstrGrTar & IIf(lblnPeriodo, "011102", "011106")
                'idblTarConsumoLiv_fp = TarifaProporcional(adteLeitAnterior, adteLeitAtual, lstrCodigo, 3) / 1000
                'Item_Fatura = Trim(Item_Fatura & lstrCodigo & "?" & Replace(idblTarConsumoLiv_fp, ",", ".") & "$;")
            Else
                lstrCodigo = lstrGrTar & IIf(lblnPeriodo, "011102", "011106")
                Me.txtTar_N_Con_F.Text = CStr(TarifaProporcional(adteLeitAnterior, adteLeitAtual, lstrCodigo, 3) / 1000)
                'If iintLivreVerde = 1 And lstrGrTar = "01AL" Then
                '  Me.txtTar_N_Con_F.Text = TarifaProporcional(adteLeitAnterior, adteLeitAtual, Strings.Replace(Strings.Replace(Strings.Replace(lstrCodigo, "01AL", "01AV"), "011102", "011202"), "011106", "011206"), 3) / 1000
                'End If
                'idblTarConsumoSemDesconto_fp = 0 'idblTarConsumo_fp
                If Microsoft.VisualBasic.Left(lstrCodigo, 4) = "01AX" Or Microsoft.VisualBasic.Left(lstrCodigo, 4) = "01AL" Then
                    Me.txtTar_N_Ban_F.Text = CStr(0)
                Else
                    Me.txtTar_N_Ban_F.Text = CStr(TarifaProporcionalBandeira(adteLeitAnterior, adteLeitAtual, iintBanderiaVigente, idteBandeira) / 1000)
                End If
                'Item_Fatura = Trim(Item_Fatura & lstrCodigo & "?" & Replace(idblTarConsumo_fp, ",", ".") & "$;")
                'Bandeira
                lstrCodigo = lstrGrTar & "0111" & iintBanderiaVigente & IIf(lblnPeriodo, "2", "6")
                'Item_Fatura = Trim(Item_Fatura & lstrCodigo & "?" & Replace(idblTarConsumoBan_fp, ",", ".") & "$;")
            End If
            '************************************************************
            '* Demanda na ponta                                         *
            '************************************************************
            lstrCodigo = lstrGrTar & "012101"
            Me.txtTar_N_Dem_P.Text = CStr(TarifaProporcional(adteLeitAnterior, adteLeitAtual, lstrCodigo, 3))
            'Item_Fatura = Trim(Item_Fatura & lstrCodigo & "?" & Replace(idblTarDemanda_p, ",", ".") & "$;")

            '************************************************************
            '* Demanda fora da ponta                                    *
            '************************************************************
            lstrCodigo = lstrGrTar & "012102"
            Me.txtTar_N_Dem_F.Text = CStr(TarifaProporcional(adteLeitAnterior, adteLeitAtual, lstrCodigo, 3))
            'Item_Fatura = Trim(Item_Fatura & lstrCodigo & "?" & Replace(idblTarDemanda_fp, ",", ".") & "$;")

            '************************************************************
            '* Demanda de ultrapassagem na ponta                        *
            '************************************************************
            lstrCodigo = lstrGrTar & "012103"
            'Se o art 93 da 414 estiver valendo entao o valor da tarifa da ultrapassagem é o valor da tarifa da demanda VEZES 2
            'If istrRes414_Art93 = "S" Then
            '  idblTarDemUltra_p = Arredondar(idblTarDemanda_p * 2, 5)
            'Else
            '  idblTarDemUltra_p = TarifaProporcional(adteLeitAnterior, adteLeitAtual, lstrCodigo, 3)
            'End If
            'Item_Fatura = Trim(Item_Fatura & lstrCodigo & "?" & Replace(idblTarDemUltra_p, ",", ".") & "$;")
            '************************************************************
            '* Demanda de ultrapassagem fora da ponta                   *
            '************************************************************
            lstrCodigo = lstrGrTar & "012104"
            'If istrRes414_Art93 = "S" Then
            '  idblTarDemUltra_fp = Arredondar(idblTarDemanda_fp * 2, 5)
            'Else
            '  idblTarDemUltra_fp = TarifaProporcional(adteLeitAnterior, adteLeitAtual, lstrCodigo, 3)
            'End If
            'Item_Fatura = Trim(Item_Fatura & lstrCodigo & "?" & Replace(idblTarDemUltra_fp, ",", ".") & "$;")


        Catch ex As Exception
            Exit Sub
        End Try

    End Sub

#End Region

End Class