Option Strict Off
Option Explicit On

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

    Private mItem As System.Windows.Forms.ListViewItem ' Objeto que controla a linha do listview
    Dim vCodigo As String
    Dim vMascaraContaDebito As String
    Dim vMascaraCep As String
    Dim vresultDebito As Boolean
    Dim vresultCredito As Boolean
    Dim vResp As Short
    Dim vNew As Boolean

#Region "Propriedades"

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

        Try

            lAtualizaList()

            LigDesFrame(True)

            vMascaraContaDebito = GetConfig("conta.mascara")
            mskContaDebito.Mask = vMascaraContaDebito
            mskContaCredito.Mask = vMascaraContaDebito
            vMascaraCep = GetConfig("cep.mascara")
            mskcep.Mask = vMascaraCep

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

    End Sub

    Private Sub lvwBancos_ColumnClick(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.ColumnClickEventArgs) Handles lvwBancos.ColumnClick

        Dim ColumnHeader As System.Windows.Forms.ColumnHeader = lvwBancos.Columns(eventArgs.Column)

        Try
            lvwBancos.ListViewItemSorter = New ListViewItemComparer(eventArgs.Column)
            lvwBancos.Sort()
        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: lvwBancos_ColumnClick" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub lvwBancos_DoubleClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles lvwBancos.DoubleClick

        Try
            If lvwBancos.Items.Count > 0 Then
                lEdit(lvwBancos.FocusedItem.Name.Trim())
                LigDesFrame(False)
            End If
        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: lvwBancos_DoubleClick" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub chkDebito_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkDebito.CheckStateChanged

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

    End Sub

    Private Sub txtB04_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtB04.TextChanged

        Dim Index As Short = txtB04.GetIndex(eventSender)

        Try
            With txtB04(Index)
                If Len(Trim(.Text)) = .MaxLength Then
                    FrmCadBancos_KeyPress(Me, New System.Windows.Forms.KeyPressEventArgs(Chr(System.Windows.Forms.Keys.Return)))
                End If
            End With
        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtB04_TextChanged" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtcoddeb_KeyDown(sender As Object, e As KeyEventArgs) Handles txtcoddeb.KeyDown

        Try

            If IsNumeric(txtcoddeb.Text) And e.KeyCode = Keys.Enter Then
                LocalizarContaDeb(txtcoddeb.Text)
            ElseIf Trim(txtcoddeb.Text) = "" Then
                mskContaDebito.Text = String.Empty
            ElseIf e.KeyCode = Keys.F3 Then

                vresultDebito = True
                vresultCredito = False
                frmPesquisaSimples.SetParametros("PLANO_CONTAS", "Plano Conta", Me, String.Empty, "GRAU = 7 AND TIPO = 'A'", "ID DESC", String.Empty)
                frmPesquisaSimples.Show()

            End If

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

    End Sub

    Private Sub txtcodcred_KeyDown(sender As Object, e As KeyEventArgs) Handles txtcodcred.KeyDown

        Try

            If IsNumeric(txtcodcred.Text) And e.KeyCode = Keys.Enter And Trim(txtcodcred.Text) <> "" Then
                LocalizarContaCred(txtcodcred.Text)
            ElseIf Trim(txtcodcred.Text) = "" Then
                mskContaCredito.Text = String.Empty
            ElseIf e.KeyCode = Keys.F3 Then
                vresultDebito = False
                vresultCredito = True
                frmPesquisaSimples.SetParametros("PLANO_CONTAS", "Plano Conta", Me, String.Empty, "GRAU = 7 AND TIPO = 'A'", "ID DESC", String.Empty)
                frmPesquisaSimples.Show()

            End If

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

    End Sub

    Private Sub cmdLimpardeb_Click(sender As Object, e As EventArgs) Handles cmdLimpardeb.Click

        Try
            txtcoddeb.Text = String.Empty
            mskContaDebito.Text = String.Empty
        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmdLimpardeb_Click" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub cmdLimparcred_Click(sender As Object, e As EventArgs) Handles cmdLimparcred.Click

        Try

            txtcodcred.Text = String.Empty
            mskContaCredito.Text = String.Empty

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

    End Sub

    Private Sub cmdLocdeb_Click(sender As Object, e As EventArgs) Handles cmdLocdeb.Click

        Try

            vresultDebito = True
            vresultCredito = False
            frmPesquisaSimples.SetParametros("PLANO_CONTAS", "Plano Conta", Me, String.Empty, "GRAU = 7 AND TIPO = 'A'", "ID DESC", String.Empty)
            frmPesquisaSimples.Show()

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

    End Sub

    Private Sub cmdLocCred_Click(sender As Object, e As EventArgs) Handles cmdLocCred.Click
        Try

            vresultDebito = False
            vresultCredito = True
            frmPesquisaSimples.SetParametros("PLANO_CONTAS", "Plano Conta", Me, String.Empty, "GRAU = 7 AND TIPO = 'A'", "ID DESC", String.Empty)
            frmPesquisaSimples.Show()

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

    End Sub

    Private Sub cmdLocalizar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdLocalizar.Click

        Try

            lLocalize()

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

    End Sub

    Private Sub cmdNovo_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdNovo.Click

        Try

            lNew()

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

    End Sub

    Private Sub cmdSair_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSair.Click

        Try

            lClose()

        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmdSair_Click" & "", "Aviso de 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

        Try

            cmdSair.Text = "&Fechar"

            If Len(Trim(txtNrBco.Text)) > 0 And Len(Trim(txtNmBco.Text)) > 0 Then

                If vNew = True Then

                    If lInsert() Then
                        MessageBox.Show("Banco criado com sucesso!", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information)
                        lAtualizaList()
                        LigDesFrame(True)
                    Else
                        MessageBox.Show("Banco não pode ser criado!", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information)
                        Exit Sub
                    End If

                Else

                    If lUpdate() Then
                        MessageBox.Show("Banco atualizado com sucesso!", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information)
                        lAtualizaList()
                        LigDesFrame(True)
                    Else
                        MessageBox.Show("Banco não pode ser atualizado!", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information)
                        Exit Sub
                    End If

                End If

            Else
                MessageBox.Show("Faltou informar dados do banco! Favor preenchea-os.", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Sub
            End If

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


    End Sub

    Private Sub cmdExcluir_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExcluir.Click

        Dim objBanco As New entidadeBanco


        Try

            vResp = MessageBox.Show("Deseja Realmente Excluir Este Banco ?", "Confirmação de Exclusão", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)

            If vResp = DialogResult.Yes Then

                objBanco.BAN_ID = Convert.ToInt32(txtBanId.Text)

                If Not lDelete(objBanco) Then
                    MessageBox.Show("Banco não pode ser excluído!", "Confirmação de Exclusão", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    Exit Sub
                Else
                    MessageBox.Show("Banco excluído com sucesso!", "Confirmação de Exclusão", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    lAtualizaList()
                    LigDesFrame(True)
                End If


            ElseIf vResp = DialogResult.Cancel Then
                Exit Sub
            End If


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

    End Sub

    Private Sub FrmCadBancos_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
                Call cmdSair_Click(cmdSair, New System.EventArgs())
            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 o Erro: " & Err.Description & " - Rotina: FrmCadBancos_KeyPress" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

#End Region

#Region "Métodos"

    Private Sub lAtualizaList()

        Dim objBanco As entidadeBanco

        Try
            CarregarGrid(objBanco)

            If lvwBancos.Items.Count <> 0 Then

                lvwBancos.Focus()
                lvwBancos.Items.Item(0).Selected = True
                lvwBancos.FocusedItem = lvwBancos.Items.Item(0)
                lvwBancos.Items.Item(0).EnsureVisible()

            End If

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

    End Sub

    Public Sub PrepararListView()

        Try

            lvwBancos.Items.Clear()
            lvwBancos.Columns.Clear()
            lvwBancos.Columns.Add(String.Empty, "Nr.", 50)
            lvwBancos.Columns.Add(String.Empty, "Nome", 400)

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

    End Sub

    Public Sub CarregarGrid(ByRef objBanco As entidadeBanco)

        Try
            PrepararListView()
            For Each objBancoFor As entidadeBanco In New repositorioBanco().Select(objBanco)
                AddListItem(mItem, objBancoFor)
            Next
        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: CarregarGrid" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub AddListItem(ByRef xItem As System.Windows.Forms.ListViewItem, ByRef objBanco As entidadeBanco)

        Try

            xItem = lvwBancos.Items.Add(objBanco.BAN_ID.ToString(), objBanco.NRBCO, String.Empty)

            If (String.IsNullOrEmpty(objBanco.NMBCO)) Then
                xItem.SubItems.Add(Space(1))
            Else
                xItem.SubItems.Add(objBanco.NMBCO & IIf(objBanco.TPMOVTO = "D", " (Débito)", ""))
            End If

            If (String.IsNullOrEmpty(objBanco.NRAG)) Then
                xItem.SubItems.Add(Space(1))
            Else
                xItem.SubItems.Add(objBanco.NRAG)
            End If

            If (String.IsNullOrEmpty(objBanco.ENDER)) Then
                xItem.SubItems.Add(Space(1))
            Else
                xItem.SubItems.Add(objBanco.ENDER)
            End If

            If (String.IsNullOrEmpty(objBanco.BAIRRO)) Then
                xItem.SubItems.Add(Space(1))
            Else
                xItem.SubItems.Add(objBanco.BAIRRO)
            End If

            If (String.IsNullOrEmpty(objBanco.CIDADE)) Then
                xItem.SubItems.Add(Space(1))
            Else
                xItem.SubItems.Add(objBanco.CIDADE)
            End If

            If (String.IsNullOrEmpty(objBanco.UF)) Then
                xItem.SubItems.Add(Space(1))
            Else
                xItem.SubItems.Add(objBanco.UF)
            End If

            If (String.IsNullOrEmpty(objBanco.CEP)) Then
                xItem.SubItems.Add(Space(1))
            Else
                xItem.SubItems.Add(objBanco.CEP)
            End If

            If (String.IsNullOrEmpty(objBanco.DDDTEL)) Then
                xItem.SubItems.Add(Space(1))
            Else
                xItem.SubItems.Add(objBanco.DDDTEL)
            End If

            If (String.IsNullOrEmpty(objBanco.TEL)) Then
                xItem.SubItems.Add(Space(1))
            Else
                xItem.SubItems.Add(objBanco.TEL)
            End If

            If (String.IsNullOrEmpty(objBanco.TIPO)) Then
                xItem.SubItems.Add(Space(1))
            Else
                xItem.SubItems.Add(objBanco.TIPO)
            End If

            If (String.IsNullOrEmpty(objBanco.CONVENIO)) Then
                xItem.SubItems.Add(Space(1))
            Else
                xItem.SubItems.Add(objBanco.CONVENIO)
            End If

            If (String.IsNullOrEmpty(objBanco.SEQUENCIAL)) Then
                xItem.SubItems.Add(Space(1))
            Else
                xItem.SubItems.Add(objBanco.SEQUENCIAL)
            End If

            If (String.IsNullOrEmpty(objBanco.NMARQUIVO)) Then
                xItem.SubItems.Add(Space(1))
            Else
                xItem.SubItems.Add(objBanco.NMARQUIVO)
            End If

            If (String.IsNullOrEmpty(objBanco.NMARQEXTESAO)) Then
                xItem.SubItems.Add(Space(1))
            Else
                xItem.SubItems.Add(objBanco.NMARQEXTESAO)
            End If

            If (String.IsNullOrEmpty(objBanco.TPMOVTO)) Then
                xItem.SubItems.Add(Space(1))
            Else
                xItem.SubItems.Add(objBanco.TPMOVTO)
            End If

            If (String.IsNullOrEmpty(objBanco.GRUPO)) Then
                xItem.SubItems.Add(Space(1))
            Else
                xItem.SubItems.Add(objBanco.GRUPO)
            End If

            If (String.IsNullOrEmpty(objBanco.MASC_CONTA)) Then
                xItem.SubItems.Add(Space(1))
            Else
                xItem.SubItems.Add(objBanco.MASC_CONTA)
            End If
            '***
            If (String.IsNullOrEmpty(objBanco.CONTA_DEBITO)) Then
                xItem.SubItems.Add(Space(1))
            Else
                xItem.SubItems.Add(objBanco.CONTA_DEBITO)
            End If

            If (String.IsNullOrEmpty(objBanco.CONTA_CREDITO)) Then
                xItem.SubItems.Add(Space(1))
            Else
                xItem.SubItems.Add(objBanco.CONTA_CREDITO)
            End If

            If (String.IsNullOrEmpty(objBanco.ATIVO)) Then
                xItem.SubItems.Add(Space(1))
            Else
                xItem.SubItems.Add(objBanco.ATIVO)
            End If

            If (String.IsNullOrEmpty(objBanco.COMERCIO)) Then
                xItem.SubItems.Add(Space(1))
            Else
                xItem.SubItems.Add(objBanco.COMERCIO)
            End If

            If (String.IsNullOrEmpty(objBanco.CONTABILIZA)) Then
                xItem.SubItems.Add(Space(1))
            Else
                xItem.SubItems.Add(objBanco.CONTABILIZA)
            End If

            If (String.IsNullOrEmpty(objBanco.ID_CONTA_DEBITO)) Then
                xItem.SubItems.Add(Space(1))
            Else
                xItem.SubItems.Add(objBanco.ID_CONTA_DEBITO)
            End If

            If (String.IsNullOrEmpty(objBanco.ID_CONTA_CREDITO)) Then
                xItem.SubItems.Add(Space(1))
            Else
                xItem.SubItems.Add(objBanco.ID_CONTA_CREDITO)
            End If

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

    End Sub

    Private Sub PreencherValoresList(ByRef Items As String)

        vCodigo = Items

        Dim Item As ListViewItem

        Dim lstrTpMov As String
        Dim lstrMcCon As String
        Dim lintParte As Integer
        Dim lstrAtivo As String
        Dim lstrcomercio As String
        Dim lstrcontabiliza As String
        Dim lstrcredito As String
        Dim lstrdebito As String
        Dim lstrcep As String

        Try

            For Each Item In lvwBancos.Items

                If Item.Name = vCodigo Then

                    'Pega a Coluna 0
                    txtBanId.Text = IIf(String.IsNullOrEmpty((Item.Name)), "0", (Item.Name))

                    'Para pegar os SubItems e so fazer o seguinte
                    txtNrBco.Text = Format(Convert.ToInt64(Trim(IIf(String.IsNullOrEmpty((Item.Text)), "0", (Item.Text)))), "000")
                    txtAgencia.Text = Trim(IIf(String.IsNullOrEmpty((Item.SubItems(2).Text)), "0", (Item.SubItems(2).Text)))
                    txtNmBco.Text = Trim(IIf(String.IsNullOrEmpty((Item.SubItems(1).Text)), "", (Item.SubItems(1).Text)))
                    txtEndereco.Text = Trim(IIf(String.IsNullOrEmpty((Item.SubItems(3).Text)), "", (Item.SubItems(3).Text)))
                    txtBairro.Text = Trim(IIf(String.IsNullOrEmpty((Item.SubItems(4).Text)), "", (Item.SubItems(4).Text)))
                    txtCidade.Text = Trim(IIf(String.IsNullOrEmpty((Item.SubItems(5).Text)), "", (Item.SubItems(5).Text)))
                    txtUf.Text = Trim(IIf(String.IsNullOrEmpty((Item.SubItems(6).Text)), "", (Item.SubItems(6).Text)))

                    lstrcep = IIf(String.IsNullOrEmpty(Item.SubItems(7).Text), "", Item.SubItems(7).Text)
                    lstrcep = Replace(lstrcep, "-", "")
                    mskcep.Text = lstrcep

                    txtDddTel.Text = VB6.Format(Trim(IIf(String.IsNullOrEmpty((Item.SubItems(8).Text)), "0", (Item.SubItems(8).Text))), "00")
                    txtTelefone.Text = VB6.Format(Trim(IIf(String.IsNullOrEmpty((Item.SubItems(9).Text)), "0", (Item.SubItems(9).Text))), "00000000")

                    txtConvenio.Text = Trim(IIf(String.IsNullOrEmpty((Item.SubItems(11).Text)), "", (Item.SubItems(11).Text)))
                    txtSequencial.Text = IIf(String.IsNullOrEmpty((Item.SubItems(12).Text)), "", (Item.SubItems(12).Text))
                    txtNmArquivo.Text = Trim(IIf(String.IsNullOrEmpty((Item.SubItems(13).Text)), "", (Item.SubItems(13).Text)))
                    txtNmArqExtensao.Text = Trim(IIf(String.IsNullOrEmpty((Item.SubItems(14).Text)), "", (Item.SubItems(14).Text)))

                    lstrTpMov = Trim(IIf(String.IsNullOrEmpty((Item.SubItems(15).Text)), "N", (Item.SubItems(15).Text)))
                    lstrMcCon = Trim(IIf(String.IsNullOrEmpty((Item.SubItems(17).Text)), "", (Item.SubItems(17).Text)))
                    lstrAtivo = Trim(IIf(String.IsNullOrEmpty((Item.SubItems(20).Text)), "N", (Item.SubItems(20).Text)))
                    lstrcomercio = Trim(IIf(String.IsNullOrEmpty((Item.SubItems(21).Text)), "N", (Item.SubItems(21).Text)))
                    lstrcontabiliza = Trim(IIf(String.IsNullOrEmpty((Item.SubItems(22).Text)), "N", (Item.SubItems(22).Text)))
                    txtcoddeb.Text = IIf(String.IsNullOrEmpty((Item.SubItems(23).Text)), "", (Item.SubItems(23).Text))
                    txtcodcred.Text = IIf(String.IsNullOrEmpty((Item.SubItems(24).Text)), "", (Item.SubItems(24).Text))

                    For lintParte = 1 To Len(lstrMcCon)
                        txtB04(lintParte - 1).Text = Mid(lstrMcCon, lintParte, 1)
                    Next lintParte

                    lstrcredito = IIf(String.IsNullOrEmpty(Item.SubItems(19).Text), "", Item.SubItems(19).Text)
                    lstrcredito = Replace(lstrcredito, ".", "")
                    mskContaCredito.Text = lstrcredito

                    lstrdebito = IIf(String.IsNullOrEmpty(Item.SubItems(18).Text), "", Item.SubItems(18).Text)
                    lstrdebito = Replace(lstrdebito, ".", "")
                    mskContaDebito.Text = lstrdebito

                    If txtcoddeb.Text = "0" And Trim(lstrdebito) <> "" Then
                        txtcoddeb.Text = RetornaConta(lstrdebito)
                    End If

                    If txtcodcred.Text = "0" And Trim(lstrcredito) <> "" Then
                        txtcodcred.Text = RetornaConta(lstrcredito)
                    End If

                    'mskContaCredito.Text = Format(Convert.ToString(Trim(IIf(String.IsNullOrEmpty((Item.SubItems(18).Text)), "", (Item.SubItems(18).Text)))), "####.#.##.##.###.#.###")
                    'mskContaDebito.Text = Format(Trim(IIf(String.IsNullOrEmpty((Item.SubItems(19).Text)), "", (Item.SubItems(19).Text))), "####.#.##.##.###.#.###")

                    chkDebito.Checked = IIf(lstrTpMov = "D", 1, 0)

                    chkAtivo.Checked = IIf(lstrAtivo = "S", 1, 0)
                    chkComercio.Checked = IIf(lstrcomercio = "S", 1, 0)
                    chkContabiliza.Checked = IIf(lstrcontabiliza = "S", 1, 0)

                    vNew = False
                End If


            Next

            Item = Nothing


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

    End Sub

    Private Sub lEdit(ByRef Item As String)

        vCodigo = Item

        Try

            PreencherValoresList(vCodigo)

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

    End Sub

    Private Sub lLocalize()

        Try

            LigDesFrame(True)
            lAtualizaList()

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

    End Sub

    Private Sub lNew()

        Try

            vNew = True
            cmdSair.Text = "&Cancelar"
            lClear()


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

    End Sub

    Private Sub lClear()

        Dim lintIndice As Short

        Try

            txtBanId.Text = "0"
            txtNrBco.Text = String.Empty
            txtAgencia.Text = String.Empty
            txtNmBco.Text = String.Empty
            txtEndereco.Text = String.Empty
            txtBairro.Text = String.Empty
            mskcep.Text = String.Empty
            txtCidade.Text = String.Empty
            txtUf.Text = String.Empty
            txtConvenio.Text = String.Empty
            txtDddTel.Text = String.Empty
            txtTelefone.Text = String.Empty
            chkDebito.Checked = False
            txtSequencial.Text = String.Empty
            txtNmArquivo.Text = String.Empty
            txtNmArqExtensao.Text = String.Empty
            For lintIndice = 0 To txtB04.UBound
                txtB04(lintIndice).Text = String.Empty
            Next lintIndice

            mskContaCredito.Text = String.Empty
            mskContaDebito.Text = String.Empty
            txtcoddeb.Text = String.Empty
            txtcodcred.Text = String.Empty
            chkAtivo.Checked = False
            chkComercio.Checked = False
            chkContabiliza.Checked = False

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

    End Sub

    Private Sub lClose()

        Try

            Close()

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

    End Sub

    Public Sub SetaParametros(ByRef frmOld As System.Windows.Forms.Form)

        Try

            vfrmOld = frmOld
            vfrmOld.Enabled = False

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

    End Sub

    Public Sub SetaCodigo(ByVal astrTabela As String, ByVal alngId_A As Integer, Optional ByVal alngId_B As Integer = 0, Optional ByVal alngId_C As Integer = 0, Optional ByVal alngId_D As Integer = 0)

        Dim lstrresult As String

        Dim vlist

        Dim objPlanoContas As New entidadePlanoContas
        Dim repositorioPlanoContas As New repositorioPlanoContas

        Try

            If astrTabela.ToUpper() = "PLANO_CONTAS" Then

                objPlanoContas.ID = alngId_A
                objPlanoContas.CONTA = String.Empty
                objPlanoContas.ATIVO = 0

                vlist = repositorioPlanoContas.Select(objPlanoContas)

                If vlist.Count > 0 Then

                    For Each objPlanoContasFor As entidadePlanoContas In vlist

                        If vresultCredito = True Then

                            txtcodcred.Text = Convert.ToInt64(IIf(IsDBNull(objPlanoContasFor.ID), 0, objPlanoContasFor.ID))
                            lstrresult = Trim(IIf(IsDBNull(objPlanoContasFor.CONTA), String.Empty, objPlanoContasFor.CONTA))
                            lstrresult = Replace(lstrresult, ".", "")
                            mskContaCredito.Text = lstrresult

                        ElseIf vresultDebito = True Then

                            txtcoddeb.Text = Convert.ToInt64(IIf(IsDBNull(objPlanoContasFor.ID), 0, objPlanoContasFor.ID))
                            lstrresult = Trim(IIf(IsDBNull(objPlanoContasFor.CONTA), String.Empty, objPlanoContasFor.CONTA))
                            lstrresult = Replace(lstrresult, ".", "")
                            mskContaDebito.Text = lstrresult

                        End If

                    Next

                Else
                    MessageBox.Show("Não foi possível encontrar o registro!", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information)
                End If

                vresultCredito = False
                vresultDebito = False

            End If

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

    End Sub

    Private Sub LigDes(ByVal ablnModo As Boolean)

        Dim lintIndice As Short

        Try

            txtBanId.Enabled = ablnModo
            txtBanId.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(ablnModo, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
            txtNrBco.Enabled = ablnModo
            txtNrBco.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(ablnModo, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
            txtAgencia.Enabled = ablnModo
            txtAgencia.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(ablnModo, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
            txtNmBco.Enabled = ablnModo
            txtNmBco.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(ablnModo, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
            txtEndereco.Enabled = ablnModo
            txtEndereco.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(ablnModo, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
            txtBairro.Enabled = ablnModo
            txtBairro.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(ablnModo, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
            'txtCep.Enabled = ablnModo
            'txtCep.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(ablnModo, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
            txtCidade.Enabled = ablnModo
            txtCidade.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(ablnModo, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
            txtUf.Enabled = ablnModo
            txtUf.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(ablnModo, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
            txtConvenio.Enabled = ablnModo
            txtConvenio.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(ablnModo, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
            txtDddTel.Enabled = ablnModo
            txtDddTel.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(ablnModo, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
            txtTelefone.Enabled = ablnModo
            txtTelefone.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(ablnModo, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
            chkDebito.Enabled = ablnModo
            txtSequencial.Enabled = (chkDebito.CheckState = 1)
            txtSequencial.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(chkDebito.CheckState = 1, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
            txtNmArquivo.Enabled = (chkDebito.CheckState = 1)
            txtNmArquivo.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(chkDebito.CheckState = 1, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
            txtNmArqExtensao.Enabled = (chkDebito.CheckState = 1)
            txtNmArqExtensao.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(chkDebito.CheckState = 1, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))

            For lintIndice = 0 To 13
                txtB04(lintIndice).Enabled = (chkDebito.CheckState = 1)
                txtB04(lintIndice).BackColor = System.Drawing.ColorTranslator.FromOle(IIf(chkDebito.CheckState = 1, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
            Next lintIndice

            mskContaCredito.Enabled = ablnModo
            mskContaDebito.Enabled = ablnModo
            txtcoddeb.Enabled = ablnModo
            txtcodcred.Enabled = ablnModo
            chkAtivo.Enabled = ablnModo
            chkComercio.Enabled = ablnModo
            chkContabiliza.Enabled = ablnModo

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

    End Sub

    Private Sub LigDesFrame(ByVal ablnModo As Boolean)

        Try
            fmePesquisa.Visible = ablnModo
            fmePesquisa.Enabled = ablnModo
            fmeCadastro.Enabled = (Not ablnModo)
        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: LigDesFrame" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Public Sub LocalizarContaCred(ByVal id As Double)

        Dim lstrcredito As String

        Dim vlist

        Dim objPlanoContas As New entidadePlanoContas
        Dim repositorioPlanoContas As New repositorioPlanoContas

        Try

            objPlanoContas.CONTA = String.Empty
            objPlanoContas.ID = id
            objPlanoContas.ATIVO = 1

            vlist = repositorioPlanoContas.Select(objPlanoContas)

            If vlist.Count > 0 Then
                For Each objPlanoContasFor As entidadePlanoContas In vlist

                    txtcodcred.Text = id
                    lstrcredito = Trim(IIf(IsDBNull(objPlanoContasFor.CONTA), String.Empty, objPlanoContasFor.CONTA))
                    lstrcredito = Replace(lstrcredito, ".", "")
                    mskContaCredito.Text = lstrcredito

                Next
            Else
                mskContaCredito.Text = ""
            End If

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

    End Sub

    Public Sub LocalizarContaDeb(ByVal id As Double)

        Dim lstrdebito As String

        Dim vlist

        Dim objPlanoContas As New entidadePlanoContas
        Dim repositorioPlanoContas As New repositorioPlanoContas

        Try

            objPlanoContas.CONTA = String.Empty
            objPlanoContas.ID = id
            objPlanoContas.ATIVO = 1

            vlist = repositorioPlanoContas.Select(objPlanoContas)

            If vlist.Count > 0 Then
                For Each objPlanoContasFor As entidadePlanoContas In vlist

                    txtcoddeb.Text = id
                    lstrdebito = Trim(IIf(IsDBNull(objPlanoContasFor.CONTA), String.Empty, objPlanoContasFor.CONTA))
                    lstrdebito = Replace(lstrdebito, ".", "")
                    mskContaDebito.Text = lstrdebito

                Next

            Else
                mskContaDebito.Text = ""
            End If

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

    End Sub



    Private Function lInsert() As Boolean

        Dim objBanco As New entidadeBanco
        Dim repositorioBanco As New repositorioBanco

        Dim lstrB04 As String
        Dim lintIdx As Short
        lstrB04 = ""

        Try

            For lintIdx = 0 To txtB04.UBound
                lstrB04 = lstrB04 & UCase(txtB04(lintIdx).Text)
            Next lintIdx

            objBanco.BAN_ID = Convert.ToInt32(Trim(IIf(String.IsNullOrEmpty((txtBanId.Text)), "0", txtBanId.Text)))
            objBanco.NRBCO = Format(Convert.ToInt64(Trim(IIf(String.IsNullOrEmpty((txtNrBco.Text)), "0", txtNrBco.Text))), "000")
            objBanco.NRAG = Trim(IIf(String.IsNullOrEmpty((txtAgencia.Text)), " ", txtAgencia.Text))
            objBanco.NMBCO = Trim(IIf(String.IsNullOrEmpty((txtNmBco.Text)), " ", txtNmBco.Text))
            objBanco.ENDER = Trim(IIf(String.IsNullOrEmpty((txtEndereco.Text)), " ", txtEndereco.Text))
            objBanco.BAIRRO = Trim(IIf(String.IsNullOrEmpty((txtBairro.Text)), " ", txtBairro.Text))
            objBanco.CIDADE = Trim(IIf(String.IsNullOrEmpty((txtCidade.Text)), " ", txtCidade.Text))
            objBanco.UF = Trim(IIf(String.IsNullOrEmpty((txtUf.Text)), " ", txtUf.Text))
            objBanco.CEP = Replace(Replace(IIf(String.IsNullOrEmpty((mskcep.Text)), " ", mskcep.Text), ".", ""), "-", "")
            objBanco.DDDTEL = Format(Convert.ToInt64(Trim(IIf(String.IsNullOrEmpty((txtDddTel.Text)), "0", txtDddTel.Text))), "00")
            objBanco.TEL = Format(Convert.ToInt64(Replace(Trim(IIf(String.IsNullOrEmpty((txtTelefone.Text)), "0", txtTelefone.Text)), " - ", "")), "00000000")
            objBanco.CONVENIO = Trim(IIf(String.IsNullOrEmpty((txtConvenio.Text)), " ", txtConvenio.Text))
            objBanco.SEQUENCIAL = Convert.ToInt64(Trim(IIf(String.IsNullOrEmpty((txtSequencial.Text)), "0", txtSequencial.Text)))
            objBanco.NMARQUIVO = Trim(IIf(String.IsNullOrEmpty((txtNmArquivo.Text)), " ", txtNmArquivo.Text))
            objBanco.NMARQEXTESAO = Trim(IIf(String.IsNullOrEmpty((txtNmArqExtensao.Text)), " ", txtNmArqExtensao.Text))
            objBanco.TPMOVTO = IIf(chkDebito.CheckState = 1, "D", "N")
            objBanco.GRUPO = IIf(chkDebito.CheckState = 1, "C", "G")
            objBanco.MASC_CONTA = lstrB04

            objBanco.CONTA_DEBITO = Trim(IIf(String.IsNullOrEmpty((mskContaDebito.Text)), " ", Replace(mskContaDebito.Text, ",", ".")))
            objBanco.CONTA_CREDITO = Trim(IIf(String.IsNullOrEmpty((mskContaCredito.Text)), " ", Replace(mskContaCredito.Text, ",", ".")))
            objBanco.ATIVO = IIf(chkAtivo.CheckState = 1, "S", "N")
            objBanco.COMERCIO = IIf(chkComercio.CheckState = 1, "S", "N")
            objBanco.CONTABILIZA = IIf(chkContabiliza.CheckState = 1, "S", "N")

            objBanco.ID_CONTA_DEBITO = Convert.ToInt64(Trim(IIf(String.IsNullOrEmpty((txtcoddeb.Text)), "0", txtcoddeb.Text)))
            objBanco.ID_CONTA_CREDITO = Convert.ToInt64(Trim(IIf(String.IsNullOrEmpty((txtcodcred.Text)), "0", txtcodcred.Text)))

            repositorioBanco.Insert(objBanco)

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

    End Function

    Private Function lUpdate() As Boolean

        Dim objBanco As New entidadeBanco
        Dim repositorioBanco As New repositorioBanco

        Dim lstrB04 As String
        Dim lintIdx As Short
        lstrB04 = ""

        Try

            For lintIdx = 0 To txtB04.UBound
                lstrB04 = lstrB04 & UCase(txtB04(lintIdx).Text)
            Next lintIdx

            objBanco.BAN_ID = Convert.ToInt32(Trim(IIf(String.IsNullOrEmpty((txtBanId.Text)), "0", txtBanId.Text)))
            objBanco.NRBCO = Format(Convert.ToInt64(Trim(IIf(String.IsNullOrEmpty((txtNrBco.Text)), "0", txtNrBco.Text))), "000")
            objBanco.NRAG = Trim(IIf(String.IsNullOrEmpty((txtAgencia.Text)), " ", txtAgencia.Text))
            objBanco.NMBCO = Trim(IIf(String.IsNullOrEmpty((txtNmBco.Text)), " ", txtNmBco.Text))
            objBanco.ENDER = Trim(IIf(String.IsNullOrEmpty((txtEndereco.Text)), " ", txtEndereco.Text))
            objBanco.BAIRRO = Trim(IIf(String.IsNullOrEmpty((txtBairro.Text)), " ", txtBairro.Text))
            objBanco.CIDADE = Trim(IIf(String.IsNullOrEmpty((txtCidade.Text)), " ", txtCidade.Text))
            objBanco.UF = Trim(IIf(String.IsNullOrEmpty((txtUf.Text)), " ", txtUf.Text))
            objBanco.CEP = Replace(Replace(IIf(String.IsNullOrEmpty((mskcep.Text)), " ", mskcep.Text), ".", ""), "-", "")
            objBanco.DDDTEL = Format(Convert.ToInt64(Trim(IIf(String.IsNullOrEmpty((txtDddTel.Text)), "0", txtDddTel.Text))), "00")
            objBanco.TEL = Format(Convert.ToInt64(Replace(Trim(IIf(String.IsNullOrEmpty((txtTelefone.Text)), "0", txtTelefone.Text)), " - ", "")), "00000000")
            objBanco.CONVENIO = Trim(IIf(String.IsNullOrEmpty((txtConvenio.Text)), " ", txtConvenio.Text))
            objBanco.SEQUENCIAL = Convert.ToInt64(Trim(IIf(String.IsNullOrEmpty((txtSequencial.Text)), "0", txtSequencial.Text)))
            objBanco.NMARQUIVO = Trim(IIf(String.IsNullOrEmpty((txtNmArquivo.Text)), " ", txtNmArquivo.Text))
            objBanco.NMARQEXTESAO = Trim(IIf(String.IsNullOrEmpty((txtNmArqExtensao.Text)), " ", txtNmArqExtensao.Text))
            objBanco.TPMOVTO = IIf(chkDebito.CheckState = 1, "D", "N")
            objBanco.GRUPO = IIf(chkDebito.CheckState = 1, "C", "G")
            objBanco.MASC_CONTA = lstrB04

            objBanco.CONTA_DEBITO = Trim(IIf(String.IsNullOrEmpty((mskContaDebito.Text)), " ", Replace(mskContaDebito.Text, ",", ".")))
            objBanco.CONTA_CREDITO = Trim(IIf(String.IsNullOrEmpty((mskContaCredito.Text)), " ", Replace(mskContaCredito.Text, ",", ".")))
            objBanco.ATIVO = IIf(chkAtivo.CheckState = 1, "S", "N")
            objBanco.COMERCIO = IIf(chkComercio.CheckState = 1, "S", "N")
            objBanco.CONTABILIZA = IIf(chkContabiliza.CheckState = 1, "S", "N")
            objBanco.ID_CONTA_DEBITO = Convert.ToInt64(Trim(IIf(String.IsNullOrEmpty((txtcoddeb.Text)), "0", txtcoddeb.Text)))
            objBanco.ID_CONTA_CREDITO = Convert.ToInt64(Trim(IIf(String.IsNullOrEmpty((txtcodcred.Text)), "0", txtcodcred.Text)))

            repositorioBanco.Update(objBanco)

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

    End Function

    Private Function lDelete(ByRef objBanco As entidadeBanco) As Boolean
        Dim repositorioBanco As New repositorioBanco
        Try

            repositorioBanco.Delete(objBanco)

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

    Private Sub txtcoddeb_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtcoddeb.KeyPress
        Try
            If e.KeyChar = Chr(Keys.Enter) Then
                e.KeyChar = Nothing
                'cmbtipo.Focus()
                SendKeys.Send("{TAB}")
            Else
                SomenteInteger(e.KeyChar, txtcoddeb, False)
            End If
        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtcoddeb_KeyPress" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try
    End Sub

    Private Sub txtcodcred_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtcodcred.KeyPress
        Try
            If e.KeyChar = Chr(Keys.Enter) Then
                e.KeyChar = Nothing
                'cmbtipo.Focus()
                SendKeys.Send("{TAB}")
            Else
                SomenteInteger(e.KeyChar, txtcodcred, False)
            End If
        Catch ex As Exception
            MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtcodcred_KeyPress" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try
    End Sub





#End Region

End Class