Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class FrmEnviarBcos
	Inherits System.Windows.Forms.Form
	'Dim intBcoId       As Integer
	
	Dim strsql As String
	Dim istrMesAnoAnt As String
	Dim strBanco As String
	
	Dim strPath As String
	Dim strTabela As String
	Dim intBanID As Short
	Dim lngSequencial As Integer
	Dim strNomeArquivo As String
	Dim strExtensaoArq As String
	Dim strConvenio As String
	Dim strNrBco As String
	Dim strNmBco As String
	Dim rsBanco As New ADODB.Recordset
	
	'UPGRADE_WARNING: Event chkTrans.CheckStateChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub chkTrans_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkTrans.CheckStateChanged
		Call pegaDatasVencimento()
	End Sub
	
	Private Sub FrmEnviarBcos_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		CenterForm(Me)
		strTabela = "nf"
		strPath = LeConfig("DIR_GERACAO_BANCO")
		txtMesAno.Text = LeConfig("MESANOFATURAMENTO")
		istrMesAnoAnt = txtMesAno.Text
		txtDir.Text = strPath
		Call EnchecbxBanco()
		pgb.Value = 0
		System.Windows.Forms.Application.DoEvents()
		Call pegaDatasVencimento()
	End Sub
	
	Private Sub EnchecbxBanco()
		Dim intControl As Short
		
		intControl = 1
		cbxBanco.Items.Clear()
		
		Call CarregaDadosBanco()
		
		If rsBanco.RecordCount > 0 Then
			rsBanco.MoveFirst()
			While Not rsBanco.EOF
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				cbxBanco.Items.Add(IIf(IsDbNull(rsBanco.Fields("Nrbco").Value), "000", rsBanco.Fields("Nrbco").Value) & " - " & Trim(IIf(IsDbNull(rsBanco.Fields("nmbco").Value), "indefinido", rsBanco.Fields("nmbco").Value)))
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				VB6.SetItemData(cbxBanco, cbxBanco.Items.Count - 1, CShort(IIf(IsDbNull(rsBanco.Fields("ban_id").Value), 0, rsBanco.Fields("ban_id").Value)))
				rsBanco.MoveNext()
			End While
		Else
			cbxBanco.Items.Add("(nenhum banco)")
			VB6.SetItemData(cbxBanco, cbxBanco.Items.Count - 1, 0)
		End If
		cbxBanco.SelectedIndex = 0
		intBanID = VB6.GetItemData(cbxBanco, cbxBanco.SelectedIndex)
		Call BuscaDados()
	End Sub
	
	Private Sub CarregaDadosBanco()
		strsql = "SELECT ban_id, nrbco, nmbco, sequencial, nmarquivo, nmarqextesao, convenio FROM bancos WHERE tpmovto = 'D'  "
		Call Conectar(strsql, rsBanco)
	End Sub
	
	'UPGRADE_WARNING: Event cbxBanco.SelectedIndexChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub cbxBanco_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cbxBanco.SelectedIndexChanged
		'intBcoId = cbxBanco.ItemData(cbxBanco.ListIndex)
		intBanID = VB6.GetItemData(cbxBanco, cbxBanco.SelectedIndex)
		Call BuscaDados()
		txtSequencial.Text = Trim(Str(lngSequencial))
		txtDir.Text = strPath & strNomeArquivo
	End Sub
	
	Private Function BuscaDados() As Object
		Dim strCriterio As String
		Dim varMarcador As Object
		
		'Define o criterio para busca
		strCriterio = "ban_id = " & intBanID
		'Inicia busca no recordset
		rsBanco.Find(strCriterio, 0, ADODB.SearchDirectionEnum.adSearchForward)
		rsBanco.MoveFirst()
		'percorre o recordset ate o seu final
		While Not rsBanco.EOF
			'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
			lngSequencial = IIf(IsDbNull(rsBanco.Fields("sequencial").Value), 1, rsBanco.Fields("sequencial").Value)
			
			'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
			strConvenio = IIf(IsDbNull(rsBanco.Fields("convenio").Value), "", rsBanco.Fields("convenio").Value)
			'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
			strNrBco = IIf(IsDbNull(rsBanco.Fields("Nrbco").Value), "000", rsBanco.Fields("Nrbco").Value)
			'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
			strNmBco = UCase(Replace(IIf(IsDbNull(rsBanco.Fields("nmbco").Value), "indefinido", rsBanco.Fields("nmbco").Value), "(Débito)", ""))
			
			'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
			strNomeArquivo = IIf(IsDbNull(rsBanco.Fields("nmarquivo").Value), "????????", rsBanco.Fields("nmarquivo").Value)
			'formata o nome do arquivo
			If strNmBco = "SICREDI" Then
				strNomeArquivo = Replace(strNomeArquivo, "%cv", VB6.Format(strConvenio, "000"))
			End If
			If InStr(strNomeArquivo, "%dd%mm%aaaa") > 0 Then
				strNomeArquivo = Replace(strNomeArquivo, "%dd%mm%aaaa", Mid(CStr(Today), 1, 2) & Mid(CStr(Today), 4, 2) & Mid(CStr(Today), 7, 4))
				If gstrEmpresa_Sigla = "EFLUL" Then strNomeArquivo = strNomeArquivo
			Else
				If InStr(strNomeArquivo, "%dd") > 0 Then
					strNomeArquivo = Replace(strNomeArquivo, "%dd", Mid(CStr(Today), 1, 2))
				End If
				If InStr(strNomeArquivo, "%mm") > 0 Then
					strNomeArquivo = Replace(strNomeArquivo, "%mm", Mid(CStr(Today), 4, 2))
					If strNmBco <> "SICREDI" Then
						If gstrEmpresa_Sigla = "EFLUL" Then strNomeArquivo = strNomeArquivo & "0"
					End If
				End If
				If InStr(strNomeArquivo, "%aa") > 0 Then
					strNomeArquivo = Replace(strNomeArquivo, "%aa", Mid(CStr(Today), 9, 2))
					If gstrEmpresa_Sigla = "EFLUL" Then strNomeArquivo = strNomeArquivo & "0"
				End If
			End If
			If InStr(strNomeArquivo, "%cv") > 0 Then
				strNomeArquivo = Replace(strNomeArquivo, "%cv", VB6.Format(strConvenio, "000000"))
			End If
			'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
			strExtensaoArq = IIf(IsDbNull(rsBanco.Fields("nmarqextesao").Value), "???", rsBanco.Fields("nmarqextesao").Value)
			strNomeArquivo = strNomeArquivo & "." & strExtensaoArq
			
			'UPGRADE_WARNING: Couldn't resolve default property of object rsBanco.Bookmark. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			'UPGRADE_WARNING: Couldn't resolve default property of object varMarcador. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			varMarcador = rsBanco.Bookmark
			rsBanco.Find(strCriterio, 1, ADODB.SearchDirectionEnum.adSearchForward, varMarcador)
		End While
	End Function
	
	Private Sub cbProcessar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cbProcessar.Click
		If chkTrans.CheckState Then
			strTabela = "nftransicao"
		Else
			strTabela = "nf"
		End If
		If Len(txtMesAno.Text) > 0 Then
			Call BuscaRota()
		End If
	End Sub
	
	Private Sub BuscaRota()
		Dim LCItens As System.Windows.Forms.ListViewItem
		Dim rsRota As New ADODB.Recordset
		
		Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
		
		LVRota.Items.Clear()
		strsql = "   SELECT DISTINCT LEFT(f.rota,4) rotagrupo , SUM(f.valortot) total, COUNT(*) qtde " & "     FROM " & strTabela & " f USE INDEX (keyrota) " & "    WHERE f.banarrec = " & intBanID & "      AND f.mesano = '" & Me.txtMesAno.Text & "' "
		If VB6.GetItemString(Me.cmbDiaVenc, Me.cmbDiaVenc.SelectedIndex) <> "" Then
			strsql = strsql & "  AND DAY(f.datavenc) = """ & VB6.Format(VB6.GetItemString(Me.cmbDiaVenc, Me.cmbDiaVenc.SelectedIndex), "00") & """ "
		End If
		If Len(Trim(Me.txtZona.Text)) > 0 Then
			strsql = strsql & "  AND f.zona = '" & Me.txtZona.Text & "' "
		End If
		If Len(Trim(Me.txtLivro.Text)) > 0 Then
			strsql = strsql & "  AND f.livro = '" & Me.txtLivro.Text & "' "
		End If
		If Len(Trim(Me.txtConta.Text)) > 0 Then
			strsql = strsql & "  AND f.conta = '" & Me.txtConta.Text & "' "
		End If
		'strsql = strsql & "  AND f.codclas = '9105' "
		strsql = strsql & " GROUP BY LEFT(f.rota,4) ORDER BY LEFT(f.rota,4) ASC"
		Call Conectar(strsql, rsRota)
		If rsRota.RecordCount > 0 Then
			LCItens = LVRota.Items.Add("Todas as rotas")
			While Not rsRota.EOF
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				If Not IsDbNull(rsRota.Fields("rotagrupo").Value) Then
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					LCItens = LVRota.Items.Add(IIf(IsDbNull(rsRota.Fields("rotagrupo").Value), "", rsRota.Fields("rotagrupo").Value & " - " & VB6.Format(rsRota.Fields("total").Value, "standard") & " / " & rsRota.Fields("qtde").Value))
				End If
				rsRota.MoveNext()
			End While
			LVRota.Enabled = True
			cmdGerar.Enabled = True
		Else
			MsgBox("Não há rotas a serem processadas!", MsgBoxStyle.OKOnly, "Fatwin")
			LVRota.Enabled = False
			cmdGerar.Enabled = False
		End If
		rsRota.Close()
		Me.Cursor = System.Windows.Forms.Cursors.Default
		
	End Sub
	
	Private Sub cbSalvarArq_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cbSalvarArq.Click
		Me.dialArqOpen.DefaultExt = strExtensaoArq
		'UPGRADE_WARNING: Filter has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
		Me.dialArqOpen.Filter = "*." & Me.dialArqOpen.DefaultExt
		Me.dialArqOpen.FileName = strNomeArquivo
		Me.dialArqOpen.Title = "Arquivos de remessa para os bancos"
		Me.dialArqOpen.ShowDialog()
		Me.txtDir.Text = Me.dialArqOpen.FileName
	End Sub
	
	Private Sub FrmEnviarBcos_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		If KeyAscii = System.Windows.Forms.Keys.Return Then
			Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
	
	Private Sub FrmEnviarBcos_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
		If rsBanco.State = 1 Then rsBanco.Close()
	End Sub
	
	Private Sub txtDir_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtDir.Enter
		txtDir.SelectionStart = 0
		txtDir.SelectionLength = Len(txtDir.Text)
	End Sub
	
	Private Sub txtMesAno_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtMesAno.Leave
		txtMesAno.Text = FormataData(txtMesAno, 1)
		If Len(Trim(txtMesAno.Text)) < 1 Then
			MsgBox("Mês/ano inválidos!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
			txtMesAno.Focus()
		ElseIf Len(Trim(txtMesAno.Text)) > 0 Then 
			intBanID = VB6.GetItemData(cbxBanco, cbxBanco.SelectedIndex)
			Call BuscaDados()
			txtSequencial.Text = Trim(Str(lngSequencial))
			If istrMesAnoAnt <> Me.txtMesAno.Text Then
				istrMesAnoAnt = Me.txtMesAno.Text
				Call pegaDatasVencimento()
			End If
		End If
	End Sub
	
	Private Sub txtMesAno_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtMesAno.Enter
		txtMesAno.SelectionStart = 0
		txtMesAno.SelectionLength = Len(txtMesAno.Text)
	End Sub
	
	Private Sub txtSequencial_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtSequencial.Enter
		txtSequencial.SelectionStart = 0
		txtSequencial.SelectionLength = Len(txtSequencial.Text)
	End Sub
	
	Private Sub txtSequencial_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtSequencial.Leave
		lngSequencial = CInt(Trim(txtSequencial.Text))
	End Sub
	
	Private Sub LVRota_ItemCheck(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.ItemCheckEventArgs) Handles LVRota.ItemCheck
		Dim Item As System.Windows.Forms.ListViewItem = LVRota.Items(eventArgs.Index)
		Dim intConta As Short
		
		If Item.Text = "Todas as rotas" Then
			'UPGRADE_WARNING: Lower bound of collection LVRota.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
			If LVRota.Items.Item(1).Checked = True Then
				For intConta = 1 To LVRota.Items.Count
					'UPGRADE_WARNING: Lower bound of collection LVRota.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
					LVRota.Items.Item(intConta).Checked = True
				Next 
				'UPGRADE_WARNING: Lower bound of collection LVRota.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
			ElseIf LVRota.Items.Item(1).Checked = False Then 
				For intConta = 1 To LVRota.Items.Count
					'UPGRADE_WARNING: Lower bound of collection LVRota.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
					LVRota.Items.Item(intConta).Checked = False
				Next intConta
			End If
		Else
			If Item.Checked = False Then
				'UPGRADE_WARNING: Lower bound of collection LVRota.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
				LVRota.Items.Item(1).Checked = False
			End If
		End If
		Call TotalizaRota()
	End Sub
	
	Private Function TotalizaRota() As Object
		Dim strValor As String
		Dim dblValor As Double
		Dim lngQuant As Integer
		Dim intConta As Short
		
		dblValor = 0
		lngQuant = 0
		For intConta = 2 To LVRota.Items.Count
			'UPGRADE_WARNING: Lower bound of collection LVRota.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
			If LVRota.Items.Item(intConta).Checked = True Then
				'UPGRADE_WARNING: Lower bound of collection LVRota.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
				strValor = LVRota.Items.Item(intConta).Text
				dblValor = dblValor + CDbl(Mid(strValor, InStr(1, strValor, "-") + 1, (InStr(1, strValor, "/")) - (InStr(1, strValor, "-") + 1)))
				lngQuant = lngQuant + CInt(Mid(strValor, InStr(1, strValor, "/") + 1))
			End If
		Next intConta
		lblValorTotal.Text = CStr(VB6.Format(dblValor, "standard"))
		lblQtde.Text = CStr(VB6.Format(lngQuant, "00000"))
	End Function
	
	Private Sub cmdGerar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdGerar.Click
		Call GerarArquivo()
	End Sub
	
	Private Sub cmdFechar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFechar.Click
		Me.Close()
	End Sub
	
	Private Sub GerarArquivo()
		'Controle do Filtro da Rota
		Dim lngContZLC As Integer
		Dim lngConta As Integer
		Dim strFiltroZL As String
		
		'Controle do Arquivo externo
		Dim strArquivo As String
		Dim intARQ As Short
		Dim strLinha As String
		
		'Tipo do Registro
		Dim strTipo As String
		
		'REGISTRO A - HEADER
		Dim strEmpresa As String
		Dim strSequencial As String
		Dim strDtGeracao As String
		
		'REGISTRO E - DEBITO EM CONTA
		Dim strIDCons As String
		Dim strIDConsAnt As String
		Dim strAgencia As String
		Dim strCC As String
		Dim strDtDebito As String
		Dim strValor As String
		Dim strNome As String
		Dim strUsoEmpresa As String
		Dim strZona As String
		Dim strLivro As String
		Dim strConta As String
		Dim dblNumNf As Double
		Dim lstrAvisoDeb As String
		Dim lstrMensagem As String
		
		'REGISTRO Z - TRAILER
		Dim intQtde As Short
		Dim dblVlrTotal As Double
		
		'Controle dos dados na base de dados
		Dim rsArquivo As New ADODB.Recordset
		
		lstrMensagem = ""
		'checa e abre o arquivo
		If Len(Trim(txtDir.Text)) = 0 Then
			MsgBox("Arquivo de destino não foi informado!", MsgBoxStyle.Information, gstrTituloMensagem)
			txtDir.Focus()
			Exit Sub
		End If
		strArquivo = Trim(txtDir.Text)
		
		Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
		
		intARQ = FreeFile
		FileOpen(intARQ, strArquivo, OpenMode.Output)
		
		dblVlrTotal = 0
		
		'REGISTRO A - HEADER
		'Prepara os dados
		intQtde = 1
		strTipo = "A"
		strEmpresa = PreencheCampo(Mid(gstrEmpresa_Sigla, 1, 20), 20, " ", "D")
		strDtGeracao = VB6.Format(Today, "yyyymmdd")
		strConvenio = PreparaCampo(strConvenio, ALFANUMERICO, 20, " ")
		strNrBco = PreparaCampo(strNrBco, NUMERICO, 3, "0")
		strNmBco = PreparaCampo(strNmBco, ALFANUMERICO, 20, " ")
		strSequencial = PreparaCampo(CStr(lngSequencial), NUMERICO, 6, "0")
		
		'Monta Linha
		'Código do Registro Posição de 001 a 001 Tamanho 001 Valor A
		strLinha = strTipo
		'Código da Remessa Posição de 002 a 002 Tamanho 001 Valor 1 = Enviado pela Empresa, 2 = Enviada pelo Banco
		strLinha = strLinha & "1"
		'Código do Convênio Posição 003 a 022 Tamanho 020
		strLinha = strLinha & strConvenio
		'Nome da Empresa Posição 023 a 042 Tamanho 020
		strLinha = strLinha & strEmpresa
		'Código do Banco Posição 043 a 045 Tamanho 003
		strLinha = strLinha & strNrBco
		'Nome do Banco Posição 046 a 065 Tamanho 020
		strLinha = strLinha & strNmBco
		'Data da Geração do Arquivo (AAAAMMDD) Posição 066 a 073 Tamanho 008
		strLinha = strLinha & strDtGeracao
		'Número sequencial do arquivo (NSA)  Posição 074 a 079 Tamanho 006
		strLinha = strLinha & strSequencial
		'Versão do Lay-Out Posição 080 a 081 Tamanho 002
		If CDbl(strNrBco) = 748 Then
			strLinha = strLinha & "05"
		Else
			strLinha = strLinha & "04"
		End If
		'Identificação do Serviço Posição 082 a 098 Tamanho 017
		strLinha = strLinha & "DEBITO AUTOMATICO"
		'Reservado para o futuro Posição 099 a 150 Tamanho 052 Valor BRANCOS
		If CDbl(strNrBco) = 748 Then
			strLinha = strLinha & New String(" ", 51)
		Else
			strLinha = strLinha & New String(" ", 52)
		End If
		'Grava Linha Arquivo externo
		PrintLine(intARQ, strLinha)
		
		'Filtro do select Por Rota
		'UPGRADE_WARNING: Lower bound of collection LVRota.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		If LVRota.Items.Item(1).Checked = False Then
			strFiltroZL = strFiltroZL & "    AND mid(f.rota,1,4) IN ( "
			For lngConta = 2 To LVRota.Items.Count
				'UPGRADE_WARNING: Lower bound of collection LVRota.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
				If LVRota.Items.Item(lngConta).Checked = True Then
					'UPGRADE_WARNING: Lower bound of collection LVRota.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
					strFiltroZL = strFiltroZL & "'" & VB.Left(LVRota.Items.Item(lngConta).Text, 4) & "',"
					lngContZLC = lngContZLC + 1
				End If
			Next 
			If lngContZLC > 0 Then
				strFiltroZL = VB.Left(strFiltroZL, Len(strFiltroZL) - 1) & ") "
			Else
				strFiltroZL = " "
			End If
		End If
		If Len(Trim(Me.txtZona.Text)) > 0 Then
			strFiltroZL = strFiltroZL & "  AND f.zona = '" & Me.txtZona.Text & "' "
		End If
		If Len(Trim(Me.txtLivro.Text)) > 0 Then
			strFiltroZL = strFiltroZL & "  AND f.livro = '" & Me.txtLivro.Text & "' "
		End If
		If Len(Trim(Me.txtConta.Text)) > 0 Then
			strFiltroZL = strFiltroZL & "  AND f.conta = '" & Me.txtConta.Text & "' "
		End If
		strsql = "          SELECT ub.zona, ub.livro, ub.conta, ub.agenc, ub.cc, ub.nome, f.datavenc, f.valortot, f.unid_id, f.cons_id, f.numnf, ub.flg_aviso_debito "
		strsql = strsql & "   FROM unidb ub, " & strTabela & " f "
		strsql = strsql & "  WHERE 1=1 " 'ub.cons_id = f.cons_id"
		strsql = strsql & "    AND ub.unid_id = f.unid_id"
		strsql = strsql & "    AND f.mesano = '" & txtMesAno.Text & "'"
		strsql = strsql & "    AND f.banco_fatur = " & VB6.Format(intBanID, "000")
		strsql = strsql & "    AND f.grupo = 'B' "
		strsql = strsql & "    AND f.flgst = '' "
		If VB6.GetItemString(Me.cmbDiaVenc, Me.cmbDiaVenc.SelectedIndex) <> "" Then
			strsql = strsql & "  AND DAY(f.datavenc) = """ & VB6.Format(VB6.GetItemString(Me.cmbDiaVenc, Me.cmbDiaVenc.SelectedIndex), "00") & """ "
		End If
		strsql = strsql & strFiltroZL
		'strsql = strsql & " AND f.codclas = '9105'"
		strsql = strsql & "  UNION "
		strsql = strsql & " SELECT ua.zona, ua.livro, ua.conta, ua.agenc, ua.cc, ua.nome, f.datavenc, f.valortot, f.unid_id, f.cons_id, f.numnf, ua.flg_aviso_debito "
		strsql = strsql & "   FROM unida ua, " & strTabela & " f "
		strsql = strsql & "  WHERE ua.cons_id = f.cons_id"
		strsql = strsql & "    AND ua.unid_id = f.unid_id"
		strsql = strsql & "    AND f.mesano = '" & txtMesAno.Text & "'"
		strsql = strsql & "    AND f.banco_fatur = " & VB6.Format(intBanID, "000")
		strsql = strsql & "    AND f.grupo = 'A' "
		strsql = strsql & "    AND f.flgst = '' "
		If VB6.GetItemString(Me.cmbDiaVenc, Me.cmbDiaVenc.SelectedIndex) <> "" Then
			strsql = strsql & "  AND DAY(f.datavenc) = """ & VB6.Format(VB6.GetItemString(Me.cmbDiaVenc, Me.cmbDiaVenc.SelectedIndex), "00") & """ "
		End If
		strsql = strsql & strFiltroZL
		'strsql = strsql & " AND f.codclas = '9105'"
		Call Conectar(strsql, rsArquivo)
		Me.Cursor = System.Windows.Forms.Cursors.Default
		If rsArquivo.RecordCount > 0 Then
			pgb.Value = 0
			pgb.Minimum = 0
			pgb.Maximum = rsArquivo.RecordCount
			While Not rsArquivo.EOF
				'REGISTRO E - Débito em Conta Corrente
				intQtde = intQtde + 1
				'Prepara os dados
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				strZona = Str(IIf(IsDbNull(rsArquivo.Fields("Zona").Value), "000", rsArquivo.Fields("Zona").Value))
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				strLivro = Str(IIf(IsDbNull(rsArquivo.Fields("Livro").Value), "00", rsArquivo.Fields("Livro").Value))
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				strConta = Str(IIf(IsDbNull(rsArquivo.Fields("Conta").Value), "000000", rsArquivo.Fields("Conta").Value))
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				strNome = IIf(IsDbNull(rsArquivo.Fields("nome").Value), "", rsArquivo.Fields("nome").Value)
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				dblNumNf = IIf(IsDbNull(rsArquivo.Fields("numNf").Value), 0, rsArquivo.Fields("numNf").Value)
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				lstrAvisoDeb = IIf(IsDbNull(rsArquivo.Fields("flg_aviso_debito").Value), "N", rsArquivo.Fields("flg_aviso_debito").Value)
				If lstrAvisoDeb = "S" Then
					lstrMensagem = lstrMensagem & VB.Right("000" & Trim(strZona), 3) & "." & VB.Right("00" & Trim(strLivro), 2) & "." & VB.Right("000000" & Trim(strConta), 6) & ","
				End If
				'Identificador ZONA LIVRO CONTA & DV
				If strNrBco = "027" Then
					strIDCons = VB6.Format(strZona, "000") & VB6.Format(strLivro, "00") & VB6.Format(strConta, "00000")
					strIDCons = VB6.Format(Trim(strIDCons), "0000000000000000000000000")
				ElseIf CDbl(strNrBco) = 237 Then 
					strIDCons = VB6.Format(strZona, "000") & VB6.Format(strLivro, "00") & VB6.Format(strConta, "0000")
					strIDCons = strIDCons & "                "
				ElseIf CDbl(strNrBco) = 104 Then 
					strIDCons = VB6.Format(strZona, "000") & " " & VB6.Format(strLivro, "00") & " " & VB6.Format(strConta, "0000")
					strIDCons = strIDCons & "              "
				ElseIf CDbl(strNrBco) = 756 Then 
					strIDCons = VB6.Format(strZona, "000") & VB6.Format(strLivro, "00") & VB6.Format(VB.Right(strConta, 4), "0000")
					strIDCons = strIDCons & "                "
				ElseIf CDbl(strNrBco) = 748 Then 
					strIDCons = VB6.Format(strZona, "000") & VB6.Format(strLivro, "00") & VB6.Format(VB.Right(strConta, 4), "0000")
					strIDCons = strIDCons & "                "
					
				ElseIf strNrBco = "001" Then 
					strIDCons = VB6.Format(strZona, "000") & VB6.Format(strLivro, "00") & VB6.Format(VB.Right(strConta, 4), "0000")
					strIDCons = strIDCons & "                "
				Else
					If gstrEmpresa_Sigla = "COORSEL" Then
						strIDCons = VB6.Format(strZona, "000") & VB6.Format(strLivro, "00") & VB6.Format(strConta, "00000")
						strIDCons = VB6.Format(Trim(strIDCons), "000000000000000000") & "       "
					Else
						'strIDCons = Format(strZona, "000") & Format(strLivro, "00") & Format(strConta, "000000")
						strIDCons = "000000000000" & VB6.Format(strLivro, "00") & VB6.Format(strConta, "0000") & "       "
						'strIDCons = Format(strIDCons & LTrim(CalculaDVCons(strIDCons)), "0000000000000000000000000")
						'strIDCons = PreparaCampo(strIDCons, ALFANUMERICO, 25, " ")
					End If
				End If
				'Agencia do Banco
				If gstrEmpresa_Sigla = "COORSEL" Then
					If strNrBco = "001" Then
						strAgencia = "    "
					Else
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						strAgencia = IIf(IsDbNull(rsArquivo.Fields("agenc").Value), "0000", rsArquivo.Fields("agenc").Value)
						strAgencia = PreparaCampo(strAgencia, ALFANUMERICO, 4, " ")
					End If
				Else
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					strAgencia = IIf(IsDbNull(rsArquivo.Fields("agenc").Value), "0000", rsArquivo.Fields("agenc").Value)
					strAgencia = PreparaCampo(strAgencia, ALFANUMERICO, 4, " ")
				End If
				'Conta Corrente da Unidade Consumidora
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				strCC = Trim(IIf(IsDbNull(rsArquivo.Fields("cc").Value), "", rsArquivo.Fields("cc").Value))
				If strNrBco = "027" Then
					strCC = Replace(Replace(Replace(strCC, "-", ""), ".", ""), "/", "")
					strCC = PreparaCampo(strCC, NUMERICO, 14, "0")
					strCC = VB.Right(strCC, 13) & " "
				ElseIf CDbl(strNrBco) = 237 Then 
					strCC = Replace(Replace(Replace(strCC, "-", ""), ".", ""), "/", "")
					strCC = PreparaCampo(strCC, NUMERICO, 14, "0")
					strCC = VB.Right(strCC, 8) & "      "
				ElseIf CDbl(strNrBco) = 104 Then 
					strCC = Replace(Replace(Replace(strCC, "-", ""), ".", ""), "/", "")
					strCC = PreparaCampo(strCC, NUMERICO, 14, "0")
					strCC = VB.Right(strCC, 12) & "  "
				ElseIf CDbl(strNrBco) = 756 Then 
					strCC = Replace(Replace(Replace(strCC, "-", ""), ".", ""), "/", "")
					strCC = PreparaCampo(strCC, ALFANUMERICO, 14, " ")
				ElseIf CDbl(strNrBco) = 748 Then 
					strCC = Replace(Replace(Replace(strCC, "-", ""), ".", ""), "/", "")
					strCC = PreparaCampo(strCC, ALFANUMERICO, 14, " ")
					
				Else
					
					If gstrEmpresa_Sigla = "COORSEL" Then
						strCC = VB.Left(strCC, Len(strCC) - 1)
						strCC = Replace(Replace(Replace(strCC, "-", ""), ".", ""), "/", "")
						strCC = PreparaCampo(strCC, NUMERICO, 14, "0")
					Else
						strCC = VB.Left(strCC, Len(strCC) - 2)
						strCC = Replace(Replace(Replace(strCC, "-", ""), ".", ""), "/", "")
						strCC = PreparaCampo(strCC, NUMERICO, 14, "0")
					End If
				End If
				'Data para Débito do valor da fatura
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				strDtDebito = VB6.Format(IIf(IsDbNull(rsArquivo.Fields("datavenc").Value), "00000000", rsArquivo.Fields("datavenc").Value), "yyyymmdd")
				strDtDebito = PreparaCampo(strDtDebito, NUMERICO, 8, "0")
				'Valor da Fatura formatado sem caracteres especiais(,.)
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				strValor = PreparaCampo(Str(IIf(IsDbNull(rsArquivo.Fields("ValorTot").Value), 0, rsArquivo.Fields("ValorTot").Value) * 100), NUMERICO, 15, "0")
				'strUsoEmpresa = PreparaCampo(Replace(txtMesAno.Text, "/", "") & "DEBITOS AUTOMATICOS DE FATURAS DE ENERGIA ELETRICA", ALFANUMERICO, 60, " ")
				strUsoEmpresa = VB6.Format(Replace(txtMesAno.Text, "/", ""), "000000") & VB6.Format(Str(dblNumNf), "000000000") & RetiraAcentuacao(VB.Left(Trim(strNome), 34))
				strUsoEmpresa = PreparaCampo(strUsoEmpresa, ALFANUMERICO, 60, " ")
				'If ChkRegistroD.Value = 1 Then
				'  strIDConsAnt = PreencheCampo(rsArquivo!Zona, 6, "0", "E") & rsArquivo!Livro & PreencheCampo(Str(rsArquivo!Conta), 4, "0", "E") & Space(13)
				'  strLinha = "D" & strIDConsAnt & strAgencia & strCC & strIDCons & PreencheCampo("NOVA VERSAO DO SISTEMA, MUDANCA NA IDENTIFICACAO", 60, " ", "D") & Space(20) & "0"
				'Else
				'Código do Registro Posição 001 a 001 Tamanho 001 Valor E
				strTipo = "E"
				strLinha = strTipo
				'Identificação do Cliente na Empresa Posição 002 a 026 Tamanho 025
				strLinha = strLinha & strIDCons
				'Agencia para Débito Posição 027 a 030 Tamanho 004
				strLinha = strLinha & strAgencia
				'Identificação do Cliente no Banco Posição 031 a 044 Tamanho 014
				strLinha = strLinha & strCC
				'Data do Vencimento Posição 045 a 052 Tamanho 008 Valor AAAAMMDD
				strLinha = strLinha & strDtDebito
				'Valor do Débito Posição 053 a 067 Tamanho 015
				strLinha = strLinha & strValor
				'Código da Moeda Posição 068 a 069 Tamanho 002 Valor 01 = UFIR e 03 = REAL
				strLinha = strLinha & "03"
				'Uso da empresa Posição 070 a 118 Tamanho 49 Valor NOSSO, Posição 119 a 129 Tamanho 11 Lei 10.833 Preencher com Brancos
				strLinha = strLinha & strUsoEmpresa
				'Reservado para o futuro Posição 130 a 149 Tamanho 20 Valor Brancos
				If CDbl(strNrBco) = 748 Then
					strLinha = strLinha & New String(" ", 19)
				Else
					strLinha = strLinha & New String(" ", 20)
				End If
				'Código do Movimento Posição 150 a 150 Tamanho 001 Valor 0 = Débito Normal e 1 = Cancelamento do Movimento
				If chkMovtoExclui.CheckState Then
					strLinha = strLinha & "1"
				Else
					strLinha = strLinha & "0"
				End If
				'End If
				
				'Grava Linha Arquivo externo
				PrintLine(intARQ, strLinha)
				
				'If ChkRegistroD.Value <> 1 Then
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				dblVlrTotal = dblVlrTotal + IIf(IsDbNull(rsArquivo.Fields("ValorTot").Value), 0, rsArquivo.Fields("ValorTot").Value)
				'End If
				
				pgb.Value = pgb.Value + 1
				rsArquivo.MoveNext()
				System.Windows.Forms.Application.DoEvents()
			End While
		End If
		
		'REGISTRO Z - TRAILER
		intQtde = intQtde + 1
		
		'strLinha = "Z" _
		'& PreparaCampo(intQtde + 2, NUMERICO, 6, "0") _
		'& PreparaCampo(Replace(dblVlrTotal, ",", ""), NUMERICO, 17, "0") _
		'& String$(126, " ")
		If CDbl(strNrBco) = 748 Then
			strLinha = "Z" & PreparaCampo(Str(intQtde), NUMERICO, 6, "0") & PreparaCampo(Str(dblVlrTotal * 100), NUMERICO, 17, "0") & New String(" ", 125)
		Else
			strLinha = "Z" & PreparaCampo(Str(intQtde), NUMERICO, 6, "0") & PreparaCampo(Str(dblVlrTotal * 100), NUMERICO, 17, "0") & New String(" ", 126)
		End If
		
		PrintLine(intARQ, strLinha)
		
		FileClose(intARQ)
		If rsArquivo.State = 1 Then rsArquivo.Close()
		If Len(lstrMensagem) > 0 Then
			lstrMensagem = VB.Left(lstrMensagem, Len(lstrMensagem) - 1)
			Call MsgBox("Este arquivo possui os identificadores (" & lstrMensagem & ") que devem ter sua atenção!!!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
		End If
		MsgBox("Processo Concluído! Arquivo gerado: " & Trim(txtDir.Text), MsgBoxStyle.Information, gstrTituloMensagem)
		'Atualiza o sequencial a inserir no arquivo
		strsql = "UPDATE bancos SET sequencial = " & lngSequencial & " " & "WHERE bancos.ban_id = " & intBanID
		Call Executar(strsql)
		
		If intQtde - 2 <> CShort(lblQtde.Text) Then
			Call MsgBox("Aviso!! A quantidade selecionada(" & CShort(Me.lblQtde.Text) & ") é diferente da quantidade gerada (" & intQtde - 2 & ")!!! ", MsgBoxStyle.Information, gstrTituloMensagem)
		End If
		
		
		
	End Sub
	
	'Private Function NomeArqBanco(nmbco As Integer) As String
	'  Dim rsBanco As New ADODB.Recordset
	'
	'  strSql = "SELECT nrbco " _
	''         & "FROM bancos " _
	''         & "WHERE ban_id = " & nmbco
	'  Call Conectar(strSql, rsBanco)
	'  strBanco = rsBanco!Nrbco
	'  rsBanco.Close
	'
	'  Select Case strBanco
	'    Case 1 'BB
	'      NomeArqBanco = "BB"
	'      Exit Function
	'    Case 41 'BANRISUL
	'      NomeArqBanco = "BANRISUL"
	'      Exit Function
	'    Case 104 'CEF
	'      NomeArqBanco = "CEF"
	'      Exit Function
	'    Case 237 'BRADESCO
	'      'NomeArqBanco = "BRADESCO"
	'      NomeArqBanco = "DA" & Mid(Date, 1, 2) & Mid(Date, 4, 2) & "0" & ".REM"
	'      Exit Function
	'    Case 353 'SANTANDER
	'      NomeArqBanco = "SANTANDER"
	'      Exit Function
	'    Case 399 'HSBC
	'      NomeArqBanco = "HSBC"
	'      Exit Function
	'    Case 748 'SICRED
	'      NomeArqBanco = "SICRED"
	'      Exit Function
	'  End Select
	'End Function
	
	Private Function CalculaDVCons(ByRef pstrCampo As String) As Short
		Dim strCampo As String
		
		Dim intN01 As Short
		Dim intN02 As Short
		Dim intN03 As Short
		Dim intN04 As Short
		Dim intN05 As Short
		Dim intN06 As Short
		Dim intN07 As Short
		Dim intN08 As Short
		Dim intN09 As Short
		Dim intN10 As Short
		Dim intN11 As Short
		Dim intN12 As Short
		
		Dim intBase As Short
		Dim intCalc As Short
		Dim intDigt As Short
		
		'FUNCAO PARA O CALCULO DO DIGITO VERIFICADOR
		'PARA O DV DO CONS_ID PARA ENVIAR PARA OS BANCOS
		
		strCampo = VB6.Format(VB.Left(Str(CDbl(pstrCampo)), 12), "000000000000")
		
		intN01 = Val(Mid(strCampo, 1, 1)) * 5
		intN02 = Val(Mid(strCampo, 2, 1)) * 4
		intN03 = Val(Mid(strCampo, 3, 1)) * 3
		intN04 = Val(Mid(strCampo, 4, 1)) * 2
		intN05 = Val(Mid(strCampo, 5, 1)) * 9
		intN06 = Val(Mid(strCampo, 6, 1)) * 8
		intN07 = Val(Mid(strCampo, 7, 1)) * 7
		intN08 = Val(Mid(strCampo, 8, 1)) * 6
		intN09 = Val(Mid(strCampo, 9, 1)) * 5
		intN10 = Val(Mid(strCampo, 10, 1)) * 4
		intN11 = Val(Mid(strCampo, 11, 1)) * 3
		intN12 = Val(Mid(strCampo, 12, 1)) * 2
		
		intBase = intN01 + intN02 + intN03 + intN04 + intN05 + intN06 + intN07 + intN08 + intN09 + intN10 + intN11 + intN12
		intCalc = Fix(intBase / 11)
		intDigt = intBase - (intCalc * 11)
		
		If intDigt <= 0 Or intDigt >= 10 Then intDigt = 0
		CalculaDVCons = intDigt
	End Function
	
	Private Sub pegaDatasVencimento()
		'  Dim lstrDatas As String
		'  Dim lstrAux As String
		'  Dim lintPos As Integer
		'  lstrAux = ""
		'  lintPos = 1
		'  lstrDatas = LeConfig("DATAS_VENCIMENTO")
		'
		'  With Me.cmbDiaVenc
		'    Call .Clear
		'    Call .AddItem("")
		'    While lintPos <= Len(lstrDatas)
		'      If Mid(lstrDatas, lintPos, 1) <> ";" Then
		'        lstrAux = lstrAux + Mid(lstrDatas, lintPos, 1)
		'      ElseIf Mid(lstrDatas, lintPos, 1) = ";" Then
		'        Call .AddItem(lstrAux)
		'        lstrAux = ""
		'      End If
		'      lintPos = lintPos + 1
		'    Wend
		'  End With
		
		Dim lstrSql As String
		Dim lrstConsulta As ADODB.Recordset
		Dim lstrAux As String
		
		lstrAux = ""
		Call cmbDiaVenc.Items.Clear()
		Call cmbDiaVenc.Items.Add("")
		lrstConsulta = New ADODB.Recordset
		lstrSql = ""
		lstrSql = lstrSql & "SELECT DISTINCT DAY(datavenc) as diavcto "
		If Me.chkTrans.CheckState = 1 Then
			lstrSql = lstrSql & "  FROM nftransicao USE INDEX(keyvenc, keymesano) "
		Else
			lstrSql = lstrSql & "  FROM nf USE INDEX(keyvenc, keymesano) "
		End If
		lstrSql = lstrSql & " WHERE mesano = """ & istrMesAnoAnt & """ "
		lstrSql = lstrSql & " ORDER BY datavenc ASC "
		Call Conectar(lstrSql, lrstConsulta)
		With lrstConsulta
			If .RecordCount > 0 Then
				While Not .EOF
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					lstrAux = VB6.Format(IIf(IsDbNull(.Fields("diavcto").value), "0", .Fields("diavcto").value), "00")
					Call cmbDiaVenc.Items.Add(lstrAux)
					Call .MoveNext()
				End While
			End If
			If .State = 1 Then Call .Close()
		End With
		'UPGRADE_NOTE: Object lrstConsulta may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstConsulta = Nothing
	End Sub
	
	Private Sub txtZona_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtZona.Enter
		With Me.txtZona
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtZona_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtZona.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		If KeyAscii <> 8 And (KeyAscii < 48 Or KeyAscii > 57) Then
			KeyAscii = 0
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
	
	Private Sub txtZona_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtZona.Leave
		With Me.txtZona
			.Text = VB6.Format(.Text, "000")
		End With
	End Sub
	
	Private Sub txtConta_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtConta.Enter
		With Me.txtConta
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtConta_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtConta.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		If KeyAscii <> 8 And (KeyAscii < 48 Or KeyAscii > 57) Then
			KeyAscii = 0
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
	
	Private Sub txtConta_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtConta.Leave
		With Me.txtConta
			.Text = VB6.Format(.Text, "000000")
		End With
	End Sub
	
	Private Sub txtLivro_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLivro.Enter
		With Me.txtLivro
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtLivro_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtLivro.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		If KeyAscii <> 8 And (KeyAscii < 48 Or KeyAscii > 57) Then
			KeyAscii = 0
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
	
	Private Sub txtLivro_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLivro.Leave
		With Me.txtLivro
			.Text = VB6.Format(.Text, "00")
		End With
	End Sub
End Class