Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmRecArq
	Inherits System.Windows.Forms.Form
	
	'Controle da chamada do form se vai ser de Débito ou vai ser de Guiche
	Public strTipoServ As String
	
	'Controle do relatorio em VSPrinter
	Private ifrmRelRecArq As FrmRelatorio
	
	Private istrTamCab As String
	Private istrTitulo1 As String
	Private istrTitulo2 As String
	'Controle da indentificação do banco selecionado na combo box
	Private iintBanID As Short
	Private istrBanNr As String
	Private istrBanNm As String
	
	'Controle para nome de arquivo e caminho do arquivo
	Private istrArqNome As String
	Private istrArqDire As String
	Private istrDtGer As String
	Private istrArqSeq As String
	Private strDataPagamento As String
	
	'Controle de mensagem da situação da fatura
	Private iblnTransicao As Boolean
	Private iblnCancelada As Boolean
	
	'Controle para puxar as informações das faturas da NF ou da NFTRANSICAO
	Private istrTabNf As String
	Private istrMesIni As String
	
	'UPGRADE_WARNING: Event cmbBanco.TextChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	'UPGRADE_WARNING: ComboBox event cmbBanco.Change was upgraded to cmbBanco.TextChanged which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'
	Private Sub cmbBanco_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmbBanco.TextChanged
		Call cmbBanco_SelectedIndexChanged(cmbBanco, New System.EventArgs())
	End Sub
	
	'UPGRADE_WARNING: Event cmbBanco.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 cmbBanco_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmbBanco.SelectedIndexChanged
		With Me.cmbBanco
			iintBanID = VB6.GetItemData(Me.cmbBanco, .SelectedIndex) 'Identificador do Banco
			istrBanNr = Mid(VB6.GetItemString(Me.cmbBanco, .SelectedIndex), 1, 3) 'Numero do Banco
			istrBanNm = Trim(Mid(VB6.GetItemString(Me.cmbBanco, .SelectedIndex), 6)) 'Nome do Banco
		End With
	End Sub
	
	Private Sub cmdBuscaDtArq_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdBuscaDtArq.Click
		Call CarregaComboSeqArq(0)
	End Sub
	
	Private Sub cmdBuscaDtPg_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdBuscaDtPg.Click
		Call CarregaComboSeqArq(1)
	End Sub
	
	Private Sub cmdFechar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFechar.Click
		Call Me.Close()
	End Sub
	
	Private Sub frmRecArq_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Dim lstrNrBco As String
		Dim lstrNmBco As String
		Dim lintIdBco As Short
		Dim lstrSql As String
		Dim lrstAux As New ADODB.Recordset
		lrstAux = New ADODB.Recordset
		ifrmRelRecArq = New FrmRelatorio
		'
		On Error GoTo ErroFormLoad
		'carrega a combobox de bancos
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM `bancos` "
		If Me.strTipoServ = "Guiche" Then
			lstrSql = lstrSql & " WHERE `tpmovto` <> 'D' "
			lstrSql = lstrSql & "   AND `grupo` <> 'D' "
		Else
			lstrSql = lstrSql & " WHERE `tpmovto` = 'D' "
		End If
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				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"'
						lstrNrBco = Trim(IIf(IsDbNull(.Fields("nrbco").value), "000", .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"'
						lstrNmBco = Trim(IIf(IsDbNull(.Fields("nmbco").value), "indefinido", .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"'
						lintIdBco = CShort(IIf(IsDbNull(.Fields("ban_id").value), 0, .Fields("ban_id").value))
						Call Me.cmbBanco.Items.Add(lstrNrBco & " - " & lstrNmBco)
						VB6.SetItemData(Me.cmbBanco, Me.cmbBanco.Items.Count - 1, lintIdBco)
						Call .MoveNext()
					End While
				Else
					Call Me.cmbBanco.Items.Add("000 - indefinido")
					VB6.SetItemData(Me.cmbBanco, Me.cmbBanco.Items.Count - 1, 0)
				End If
				Call .Close()
			End If
		End With
		Me.cmbBanco.SelectedIndex = 0
		iintBanID = VB6.GetItemData(cmbBanco, cmbBanco.SelectedIndex)
		istrBanNr = Mid(VB6.GetItemString(cmbBanco, cmbBanco.SelectedIndex), 1, 3)
		istrBanNm = Trim(Mid(VB6.GetItemString(cmbBanco, cmbBanco.SelectedIndex), 6))
		'Pega o Mes e Ano de faturamento da config e popula o objeto Text Box Mes e Ano
		Me.txtMesAno.Text = LeConfig("MESANOFATURAMENTO")
		Me.dtpArquivo.value = BuscaDataBD
		'UPGRADE_WARNING: Couldn't resolve default property of object Me.dtpArquivo.value. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
		Me.dtpPagto.value = Me.dtpArquivo.value
		
		'Verifica se é para receber débito automático ou para receber pagamentos feitos em guiche
		If Me.strTipoServ = "Guiche" Then
			Call MontaGrade(0)
			'Define quais frame de totalização serão mostrados
			Me.fmeDebitado.Visible = False
			Me.fmeNaoDebitado.Visible = False
			
			Me.fmeRecebido.Visible = True
			Me.fmeReserva.Visible = True
			'Muda o titulo do form
			Me.Text = "Recebimento Direto (Arrecadadores)"
			'
		Else
			Call MontaGrade(1)
			'Define quais frame de totalização serão mostrados
			Me.fmeDebitado.Visible = True
			Me.fmeNaoDebitado.Visible = True
			Me.fmeRecebido.Visible = False
			Me.fmeReserva.Visible = False
			'Muda o titulo do form
			Me.Text = "Recebimento de débito em CC"
		End If
		
		istrTabNf = "nf"
		istrMesIni = LeConfig("MES_INICIO_FATWIN")
		Call zeraFrames()
		'
		'Tabela que irá guardar as baixas dos arquivos para futura impressão ou auditoria
		lstrSql = ""
		lstrSql = lstrSql & "CREATE TABLE IF NOT EXISTS `bxarqbco_arr` (" & vbCrLf
		lstrSql = lstrSql & "  `banid`      int(11) NOT NULL default '0', " & vbCrLf
		lstrSql = lstrSql & "  `datarquivo` date default '0000-00-00', " & vbCrLf
		lstrSql = lstrSql & "  `seqarquivo` int(11) NOT NULL default '0', " & vbCrLf
		lstrSql = lstrSql & "  `arquivo`    varchar(255) default NULL, " & vbCrLf
		'previstos
		lstrSql = lstrSql & "  `pre_reg`   int(11) default '0', " & vbCrLf
		lstrSql = lstrSql & "  `pre_vlr`   decimal(14,2) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `pre_tax`   decimal(14,2) default NULL, " & vbCrLf
		'recebidos
		lstrSql = lstrSql & "  `rec_reg`   int(11) default '0', " & vbCrLf
		lstrSql = lstrSql & "  `rec_vlr`   decimal(14,2) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `rec_tax`   decimal(14,2) default NULL, " & vbCrLf
		'reserva/judice
		lstrSql = lstrSql & "  `res_reg`   int(11) default '0', " & vbCrLf
		lstrSql = lstrSql & "  `res_vlr`   decimal(14,2) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `res_tax`   decimal(14,2) default NULL, " & vbCrLf
		'duplicidades
		lstrSql = lstrSql & "  `dub_reg`   int(11) default '0', " & vbCrLf
		lstrSql = lstrSql & "  `dub_vlr`   decimal(14,2) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `dub_tax`   decimal(14,2) default NULL, " & vbCrLf
		'efetivos
		lstrSql = lstrSql & "  `efe_reg`   int(11) default '0', " & vbCrLf
		lstrSql = lstrSql & "  `efe_vlr`   decimal(14,2) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `efe_tax`   decimal(14,2) default NULL, " & vbCrLf
		'estado
		lstrSql = lstrSql & "  `est_nec`   int(11) default '0', " & vbCrLf
		lstrSql = lstrSql & "  `est_rec`   int(11) default '0', " & vbCrLf
		lstrSql = lstrSql & "  `est_dev`   int(11) default '0', " & vbCrLf
		'
		lstrSql = lstrSql & " PRIMARY KEY  (`banid`, `datarquivo`, `seqarquivo`) " & vbCrLf
		lstrSql = lstrSql & " ) ENGINE=InnoDB DEFAULT CHARSET=latin1 "
		Call Executar(lstrSql)
		lstrSql = ""
		lstrSql = lstrSql & "CREATE TABLE IF NOT EXISTS `bxarqbco_arr_itens` (" & vbCrLf
		lstrSql = lstrSql & "  `banid`      int(11) NOT NULL default '0', " & vbCrLf
		lstrSql = lstrSql & "  `datarquivo` date default '0000-00-00', " & vbCrLf
		lstrSql = lstrSql & "  `seqarquivo` int(11) NOT NULL default '0', " & vbCrLf
		lstrSql = lstrSql & "  `seqreg`     int(11) NOT NULL default '0', " & vbCrLf
		lstrSql = lstrSql & "  `zona`       char(3) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `livro`      char(2) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `conta`      char(6) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `numnf`      double NOT NULL default '0', " & vbCrLf
		lstrSql = lstrSql & "  `mesano`     varchar(7) NOT NULL default '', " & vbCrLf
		lstrSql = lstrSql & "  `datapgto`   date default '0000-00-00', " & vbCrLf
		lstrSql = lstrSql & "  `datacred`   date default '0000-00-00', " & vbCrLf
		lstrSql = lstrSql & "  `datavcto`   date default '0000-00-00', " & vbCrLf
		lstrSql = lstrSql & "  `recebido`   decimal(14,2) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `tarifa`     decimal(14,2) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `nrbco`      char(3) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `nrag`       varchar(7) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `formaarr`   varchar(255) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `avisos`     varchar(255) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `grupo`      char(1) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `diferenca`  double NOT NULL default '0.00', " & vbCrLf
		lstrSql = lstrSql & "  `unid_id`    int(11) NOT NULL default '0', " & vbCrLf
		lstrSql = lstrSql & "  `cons_id`    int(11) NOT NULL default '0', " & vbCrLf
		lstrSql = lstrSql & " PRIMARY KEY  (`banid`,`datarquivo`,`seqarquivo`,`seqreg`), " & vbCrLf
		lstrSql = lstrSql & " KEY `keyzona` (`zona`), " & vbCrLf
		lstrSql = lstrSql & " KEY `keylivro` (`livro`), " & vbCrLf
		lstrSql = lstrSql & " KEY `keyconta` (`conta`), " & vbCrLf
		lstrSql = lstrSql & " KEY `keygrupo` (`grupo`), " & vbCrLf
		lstrSql = lstrSql & " KEY `keynumnf` (`numnf`), " & vbCrLf
		lstrSql = lstrSql & " KEY `keymesano` (`mesano`), " & vbCrLf
		lstrSql = lstrSql & " CONSTRAINT `fk_itens_bxarqbco_arr` FOREIGN KEY (`banid`,`datarquivo`,`seqarquivo`) REFERENCES `bxarqbco_arr` (`banid`,`datarquivo`,`seqarquivo`) " & vbCrLf
		lstrSql = lstrSql & " ) ENGINE=InnoDB DEFAULT CHARSET=latin1 "
		Call Executar(lstrSql)
		'
		'Tabela que irá guardar as baixas dos arquivos para futura impressão ou auditoria
		lstrSql = ""
		lstrSql = lstrSql & "CREATE TABLE IF NOT EXISTS `bxarqbco_deb` (" & vbCrLf
		lstrSql = lstrSql & "  `banid`      int(11) NOT NULL default '0', " & vbCrLf
		lstrSql = lstrSql & "  `datarquivo` date default '0000-00-00', " & vbCrLf
		lstrSql = lstrSql & "  `seqarquivo` int(11) NOT NULL default '0', " & vbCrLf
		lstrSql = lstrSql & "  `arquivo`    varchar(255) default NULL, " & vbCrLf
		'previstos
		lstrSql = lstrSql & "  `pre_reg`   int(11) default '0', " & vbCrLf
		lstrSql = lstrSql & "  `pre_vlr`   decimal(14,2) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `pre_tax`   decimal(14,2) default NULL, " & vbCrLf
		'debitados
		lstrSql = lstrSql & "  `deb_reg`   int(11) default '0', " & vbCrLf
		lstrSql = lstrSql & "  `deb_vlr`   decimal(14,2) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `deb_tax`   decimal(14,2) default NULL, " & vbCrLf
		'não debitados
		lstrSql = lstrSql & "  `ndb_reg`   int(11) default '0', " & vbCrLf
		lstrSql = lstrSql & "  `ndb_vlr`   decimal(14,2) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `ndb_tax`   decimal(14,2) default NULL, " & vbCrLf
		'duplicidades
		lstrSql = lstrSql & "  `dub_reg`   int(11) default '0', " & vbCrLf
		lstrSql = lstrSql & "  `dub_vlr`   decimal(14,2) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `dub_tax`   decimal(14,2) default NULL, " & vbCrLf
		'efetivos
		lstrSql = lstrSql & "  `efe_reg`   int(11) default '0', " & vbCrLf
		lstrSql = lstrSql & "  `efe_vlr`   decimal(14,2) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `efe_tax`   decimal(14,2) default NULL, " & vbCrLf
		'estado
		lstrSql = lstrSql & "  `est_nec`   int(11) default '0', " & vbCrLf
		lstrSql = lstrSql & "  `est_rec`   int(11) default '0', " & vbCrLf
		lstrSql = lstrSql & "  `est_dev`   int(11) default '0', " & vbCrLf
		'
		lstrSql = lstrSql & " PRIMARY KEY  (`banid`, `datarquivo`, `seqarquivo`) " & vbCrLf
		lstrSql = lstrSql & " ) ENGINE=InnoDB DEFAULT CHARSET=latin1 "
		Call Executar(lstrSql)
		lstrSql = ""
		lstrSql = lstrSql & "CREATE TABLE IF NOT EXISTS `bxarqbco_deb_itens` (" & vbCrLf
		lstrSql = lstrSql & "  `banid`      int(11) NOT NULL default '0', " & vbCrLf
		lstrSql = lstrSql & "  `datarquivo` date default '0000-00-00', " & vbCrLf
		lstrSql = lstrSql & "  `seqarquivo` int(11) NOT NULL default '0', " & vbCrLf
		lstrSql = lstrSql & "  `seqreg`     int(11) NOT NULL default '0', " & vbCrLf
		lstrSql = lstrSql & "  `zona`       char(3) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `livro`      char(2) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `conta`      char(6) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `numnf`      double NOT NULL default '0', " & vbCrLf
		lstrSql = lstrSql & "  `mesano`     varchar(7) NOT NULL default '', " & vbCrLf
		lstrSql = lstrSql & "  `datadbto`   date default '0000-00-00', " & vbCrLf
		lstrSql = lstrSql & "  `datavcto`   date default '0000-00-00', " & vbCrLf
		lstrSql = lstrSql & "  `debitado`   decimal(14,2) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `tarifa`     decimal(14,2) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `nrbco`      char(3) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `nrag`       varchar(7) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `formadeb`   varchar(255) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `movimento`  varchar(255) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `avisos`     varchar(255) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `grupo`      char(1) default NULL, " & vbCrLf
		lstrSql = lstrSql & "  `diferenca`  double NOT NULL default '0.00', " & vbCrLf
		lstrSql = lstrSql & "  `unid_id`    int(11) NOT NULL default '0', " & vbCrLf
		lstrSql = lstrSql & "  `cons_id`    int(11) NOT NULL default '0', " & vbCrLf
		lstrSql = lstrSql & " PRIMARY KEY  (`banid`,`datarquivo`,`seqarquivo`,`seqreg`), " & vbCrLf
		lstrSql = lstrSql & " KEY `keyzona` (`zona`), " & vbCrLf
		lstrSql = lstrSql & " KEY `keylivro` (`livro`), " & vbCrLf
		lstrSql = lstrSql & " KEY `keyconta` (`conta`), " & vbCrLf
		lstrSql = lstrSql & " KEY `keygrupo` (`grupo`), " & vbCrLf
		lstrSql = lstrSql & " KEY `keynumnf` (`numnf`), " & vbCrLf
		lstrSql = lstrSql & " KEY `keymesano` (`mesano`), " & vbCrLf
		lstrSql = lstrSql & " CONSTRAINT `fk_itens_bxarqbco_deb` FOREIGN KEY (`banid`,`datarquivo`,`seqarquivo`) REFERENCES `bxarqbco_deb` (`banid`,`datarquivo`,`seqarquivo`) " & vbCrLf
		lstrSql = lstrSql & " ) ENGINE=InnoDB DEFAULT CHARSET=latin1 "
		Call Executar(lstrSql)
ErroFormLoad: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
		ElseIf myConC.Errors.Count > 0 Then 
			Call MsgBox("Código: " & myConC.Errors.Item(myConC.Errors.Count - 1).NativeError & vbCrLf & "Descrição:" & myConC.Errors.Item(myConC.Errors.Count - 1).Description)
		End If
	End Sub
	
	Private Sub MontaGrade(ByVal aintTipo As Short)
		With Me.mfgDados
			Call .Clear()
			.Rows = 1
			If aintTipo = 0 Then
				.set_ColAlignment(0, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
				.set_ColAlignment(1, MSFlexGridLib.AlignmentSettings.flexAlignLeftCenter)
				.set_ColAlignment(2, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
				.set_ColAlignment(3, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
				.set_ColAlignment(4, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
				.set_ColAlignment(5, MSFlexGridLib.AlignmentSettings.flexAlignRightCenter)
				.set_ColAlignment(6, MSFlexGridLib.AlignmentSettings.flexAlignRightCenter)
				.set_ColAlignment(7, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
				.set_ColAlignment(8, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
				.set_ColAlignment(9, MSFlexGridLib.AlignmentSettings.flexAlignLeftCenter)
				.set_ColAlignment(10, MSFlexGridLib.AlignmentSettings.flexAlignLeftCenter)
				.set_ColWidth(0, 1500)
				.set_ColWidth(1, 1800)
				.set_ColWidth(2, 1200)
				.set_ColWidth(3, 1200)
				.set_ColWidth(4, 1200)
				.set_ColWidth(5, 1200)
				.set_ColWidth(6, 1200)
				.set_ColWidth(7, 730)
				.set_ColWidth(8, 850)
				.set_ColWidth(9, 6520)
				.set_ColWidth(10, 2500)
				.set_ColWidth(11, 0)
				.set_ColWidth(12, 1000)
				.set_ColWidth(13, 0)
				.set_ColWidth(14, 0)
				.set_ColWidth(15, 0)
				.set_TextMatrix(0, 0, "Zona Livro Conta")
				.set_TextMatrix(0, 1, "Fatura - Mês/Ano")
				.set_TextMatrix(0, 2, "Pagamento")
				.set_TextMatrix(0, 3, "Crédito")
				.set_TextMatrix(0, 4, "Vencimento")
				.set_TextMatrix(0, 5, "Recebido")
				.set_TextMatrix(0, 6, "Tarifa")
				.set_TextMatrix(0, 7, "Banco")
				.set_TextMatrix(0, 8, "Agência")
				.set_TextMatrix(0, 9, "Forma de arrecadação/Forma Pagto")
				.set_TextMatrix(0, 10, "Avisos")
				.set_TextMatrix(0, 11, "Grupo")
				.set_TextMatrix(0, 12, "Diferença")
				.set_TextMatrix(0, 13, "Sequência")
				.set_TextMatrix(0, 14, "ConsId")
				.set_TextMatrix(0, 15, "UnidId")
			Else
				.set_ColAlignment(0, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
				.set_ColAlignment(1, MSFlexGridLib.AlignmentSettings.flexAlignLeftCenter)
				.set_ColAlignment(2, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
				.set_ColAlignment(3, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
				.set_ColAlignment(4, MSFlexGridLib.AlignmentSettings.flexAlignRightCenter)
				.set_ColAlignment(5, MSFlexGridLib.AlignmentSettings.flexAlignRightCenter)
				.set_ColAlignment(6, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
				.set_ColAlignment(7, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
				.set_ColAlignment(8, MSFlexGridLib.AlignmentSettings.flexAlignLeftCenter)
				.set_ColAlignment(9, MSFlexGridLib.AlignmentSettings.flexAlignLeftCenter)
				.set_ColAlignment(10, MSFlexGridLib.AlignmentSettings.flexAlignLeftCenter)
				.set_ColWidth(0, 1500)
				.set_ColWidth(1, 1800)
				.set_ColWidth(2, 1200)
				.set_ColWidth(3, 1200)
				.set_ColWidth(4, 1200)
				.set_ColWidth(5, 1200)
				.set_ColWidth(6, 730)
				.set_ColWidth(7, 850)
				.set_ColWidth(8, 6520)
				.set_ColWidth(9, 1400)
				.set_ColWidth(10, 2500)
				.set_ColWidth(11, 0)
				.set_ColWidth(12, 1000)
				.set_ColWidth(13, 0)
				.set_ColWidth(14, 0)
				.set_ColWidth(15, 0)
				.set_TextMatrix(0, 0, "Zona Livro Conta")
				.set_TextMatrix(0, 1, "Fatura - Mês/Ano")
				.set_TextMatrix(0, 2, "Débito")
				.set_TextMatrix(0, 3, "Vencimento")
				.set_TextMatrix(0, 4, "Debitado")
				.set_TextMatrix(0, 5, "Tarifa")
				.set_TextMatrix(0, 6, "Banco")
				.set_TextMatrix(0, 7, "Agência")
				.set_TextMatrix(0, 8, "Resultado da arrecadação")
				.set_TextMatrix(0, 9, "Movimento")
				.set_TextMatrix(0, 10, "Avisos")
				.set_TextMatrix(0, 11, "Grupo")
				.set_TextMatrix(0, 12, "Diferença")
				.set_TextMatrix(0, 13, "Sequência")
				.set_TextMatrix(0, 14, "ConsId")
				.set_TextMatrix(0, 15, "UnidId")
			End If
		End With
	End Sub
	
	Private Function EncheGrade(ByVal alngTotLin As Integer) As Boolean
		'Controle de faturas
		Dim ldblNumNf As Double
		Dim lstrMesAnoFat As String
		
		'Controle do arquivo
		Dim lstrArqLin As String
		Dim lstrArqTip As String
		Dim lstrAux As String
		Dim llngLinha As Integer
		Dim lblnSujeira As Boolean
		
		'Resgitro A
		Dim lintCdRemessa As Short
		Dim lstrCdEmpresa As String
		Dim lstrNmEmpresa As String
		Dim lstrNrBanco As String
		Dim lstrNmBanco As String
		Dim lstrArqVer As String
		Dim lstrArqIde As String
		Dim lstrGer As String
		
		'Registro F
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim lstrAgencia As String
		Dim lstrCtaCte As String
		Dim lstrVecto As String
		Dim ldteVecto As Date
		Dim ldblValor As Double
		Dim ldblTributo As Double
		Dim lstrCodRet As String
		Dim lstrUsoEmp As String
		Dim lstrReservado As String
		Dim lstrCodMovto As String
		
		'Registro G
		Dim lstrPgto As String
		Dim ldtePgto As Date
		Dim lstrCred As String
		Dim ldteCred As Date
		Dim lstrbarras As String
		Dim lstrSeqReg As String
		Dim lstrCodAge As String
		Dim lstrCodArr As String
		Dim lstrLixo As String
		Dim llngBarAux As Integer
		Dim lstrFormaPgto As String
		
		'Registro Z
		Dim lstrRegZTotReg As String
		Dim ldblRegZTotVlr As Double
		
		iblnTransicao = False
		iblnCancelada = False
		lblnSujeira = False
		On Error GoTo ErroEncheGrade
		
		Call zeraFrames()
		Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, alngTotLin, " (Leitura do Arquivo)")
		'
		'Abre arquivo externo
		FileOpen(1, Me.txtArq.Text, OpenMode.Input)
		For llngLinha = 0 To alngTotLin - 1
			Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " (Leitura do Arquivo)")
			Input(1, lstrArqLin)
			'
			'Pega dados do Arquivo externo
			lstrArqTip = Mid(lstrArqLin, 1, 1)
			
			Select Case lstrArqTip
				Case "A" 'Header
					lintCdRemessa = CShort(Mid(lstrArqLin, 2, 1)) 'Posição 002 a 002 Tamanho 001 Código da Remessa Valor 2 = Retorno 1 = Envio
					lstrCdEmpresa = Trim(Mid(lstrArqLin, 3, 20)) 'Posição 003 a 022 Tamanho 020 Código da empresa
					lstrNmEmpresa = Trim(Mid(lstrArqLin, 23, 20)) 'Posição 023 a 042 Tamanho 020 Nome da empresa
					lstrNrBanco = Trim(Mid(lstrArqLin, 43, 3)) 'Posição 043 a 045 Tamanho 003 Codigo do banco
					lstrNmBanco = Trim(Mid(lstrArqLin, 46, 20)) 'Posição 046 a 065 Tamanho 020 Nome do banco
					istrDtGer = Trim(Mid(lstrArqLin, 66, 8)) 'Posição 066 a 073 Tamanho 008 Data da geração
					istrArqSeq = Trim(Mid(lstrArqLin, 74, 6)) 'Posição 074 a 079 Tamanho 006 Sequencial do arquivo
					lstrArqVer = Trim(Mid(lstrArqLin, 80, 2)) 'Posição 080 a 081 Tamanho 002 Versão do Layout Valor 04
					lstrArqIde = Trim(Mid(lstrArqLin, 82, 17)) 'Posição 082 a 098 Tamanho 017 DÉBITO AUTOMÁTICO
					lstrGer = Mid(istrDtGer, 7, 2) & "/" & Mid(istrDtGer, 5, 2) & "/" & Mid(istrDtGer, 1, 4)
					If CInt(IIf(IsNumeric(istrArqSeq), istrArqSeq, 0)) + 0 = 0 Then
						istrArqSeq = (VB6.Format(CDate(IIf(IsDate(lstrGer), lstrGer, "01/01/1900")), "yyyymmdd"))
					End If
					'strBrancos = Trim(Mid(lstrArqLin, 99, 52))   'Posição 099 a 150 Tamanho 052 Brancos
					
					'Case "B"        'Cadastramento de Débito automático (DB)
					'Case "C"        'Ocorrências no cadastramento DB
					'Case "D"        'Alteração de controle pela empresa
					'Case "E"        'Débito em CC
				Case "F" 'Retorno do Débito em CC
					If Me.strTipoServ = "Debitos" Then
						lstrCodRet = Trim(Mid(lstrArqLin, 68, 2))
						lstrAgencia = Trim(Mid(lstrArqLin, 27, 4))
						lstrCtaCte = Trim(Mid(lstrArqLin, 31, 14))
						lstrVecto = Trim(Mid(lstrArqLin, 45, 8))
						lstrVecto = Mid(lstrVecto, 7, 2) & "/" & Mid(lstrVecto, 5, 2) & "/" & Mid(lstrVecto, 1, 4)
						ldteVecto = CDate(IIf(IsDate(lstrVecto), lstrVecto, "01/01/1900"))
						ldblValor = CDbl(Mid(lstrArqLin, 53, 15)) / 100
						ldblTributo = CDbl(Val(IIf(Len(Trim(Mid(lstrArqLin, 119, 10))) = 0, 0, Mid(lstrArqLin, 119, 10)))) / 100
						lstrUsoEmp = UCase(Trim(Mid(lstrArqLin, 70, 70)))
						lstrReservado = Trim(Mid(lstrArqLin, 140, 10))
						lstrCodMovto = Trim(Mid(lstrArqLin, 150, 1))
						lstrSeqReg = CStr(llngLinha)
						'Para pega o identificador da empresa ZLC
						lstrAux = VB.Right(VB6.Format(Replace(Mid(lstrArqLin, 2, 25), " ", ""), "0000000000000000000000000"), 12)
						Select Case istrBanNr
							Case "001" 'bb
								If gstrEmpresa_Sigla = "COORSEL" Then
									lstrAux = VB6.Format(VB.Left(lstrAux, 4), "000") & VB6.Format(Mid(lstrAux, 5, 2), "00") & VB6.Format(VB.Right(lstrAux, 6), "000000")
								ElseIf gstrEmpresa_Sigla = "CHESP" Then 
									lstrAux = VB6.Format(VB.Left(lstrAux, 6), "000") & VB6.Format(Mid(lstrAux, 7, 2), "00") & VB6.Format(VB.Right(lstrAux, 4), "0000000")
								Else
									lstrAux = "001" & VB6.Format(Mid(lstrAux, 7, 2), "00") & VB6.Format(VB.Right(lstrAux, 4), "0000000")
								End If
							Case "027" 'besc
								If gstrEmpresa_Sigla = "COORSEL" Then
									lstrAux = VB6.Format(VB.Left(lstrAux, 5), "000") & VB6.Format(Mid(lstrAux, 6, 2), "00") & VB6.Format(VB.Right(lstrAux, 5), "0000000")
								Else
									lstrAux = "001" & VB6.Format(Mid(lstrAux, 6, 2), "00") & VB6.Format(VB.Right(lstrAux, 5), "0000000")
								End If
							Case "237" 'bradesco
								If gstrEmpresa_Sigla = "COORSEL" Then
									lstrAux = VB6.Format(VB.Left(lstrAux, 5), "000") & VB6.Format(Mid(lstrAux, 6, 2), "00") & VB6.Format(VB.Right(lstrAux, 4), "0000000")
								ElseIf gstrEmpresa_Sigla = "CHESP" Then 
									lstrAux = VB6.Format(VB.Left(Replace(Mid(lstrArqLin, 2, 25), " ", ""), 3), "000") & VB6.Format(Mid(Replace(Mid(lstrArqLin, 2, 25), " ", ""), 4, 2), "00") & VB6.Format(Mid(Replace(Mid(lstrArqLin, 2, 25), " ", ""), 6), "0000000")
								Else
									lstrAux = "001" & VB6.Format(Mid(lstrAux, 7, 2), "00") & VB6.Format(VB.Right(lstrAux, 4), "0000000")
								End If
							Case "104" 'cef
								If gstrEmpresa_Sigla = "COORSEL" Then
									lstrAux = VB6.Format(VB.Left(lstrAux, 5), "000") & VB6.Format(Mid(lstrAux, 6, 2), "00") & VB6.Format(VB.Right(lstrAux, 4), "0000000")
								ElseIf gstrEmpresa_Sigla = "CHESP" Then 
									lstrAux = VB6.Format(VB.Left(lstrAux, 6), "000") & VB6.Format(Mid(lstrAux, 7, 2), "00") & VB6.Format(VB.Right(lstrAux, 4), "0000000")
								Else
									lstrAux = "001" & VB6.Format(Mid(lstrAux, 7, 2), "00") & VB6.Format(VB.Right(lstrAux, 4), "0000000")
								End If
							Case "756" 'sicoob
								If gstrEmpresa_Sigla = "EFLUL" Then
									lstrAux = VB.Left(VB.Right(lstrAux, 9), 3) & Mid(VB.Right(lstrAux, 9), 4, 2) & VB6.Format(VB.Right(lstrAux, 4), "0000000")
								Else
									lstrAux = ""
								End If
							Case "399" 'hsbc
								If gstrEmpresa_Sigla = "CHESP" Then
									lstrAux = VB6.Format(VB.Left(lstrAux, 6), "000") & VB6.Format(Mid(lstrAux, 7, 2), "00") & VB6.Format(VB.Right(lstrAux, 4), "0000000")
								Else
									lstrAux = "001" & VB6.Format(Mid(lstrAux, 7, 2), "00") & VB6.Format(VB.Right(lstrAux, 4), "0000000")
								End If
							Case "341" 'itau
								If gstrEmpresa_Sigla = "CHESP" Then
									lstrAux = VB6.Format(VB.Left(lstrAux, 6), "000") & VB6.Format(Mid(lstrAux, 7, 2), "00") & VB6.Format(VB.Right(lstrAux, 4), "0000000")
								Else
									lstrAux = "001" & VB6.Format(Mid(lstrAux, 7, 2), "00") & VB6.Format(VB.Right(lstrAux, 4), "0000000")
								End If
						End Select
						lstrZona = VB6.Format(Mid(lstrAux, 1, 3), "000")
						lstrLivro = VB6.Format(Mid(lstrAux, 4, 2), "00")
						lstrConta = VB6.Format(VB.Right(Mid(lstrAux, 6, 7), 6), "000000")
						If lstrUsoEmp = "DEBITOS AUTOMATICOS DE FATURAS DE ENERGIA ELETRICA" Then
							lstrMesAnoFat = Me.txtMesAno.Text
							ldblNumNf = 0
						Else
							lstrMesAnoFat = Trim(Mid(lstrUsoEmp, 1, 2) & "/" & Mid(lstrUsoEmp, 3, 4))
							ldblNumNf = CDbl(Val(Mid(lstrUsoEmp, 7, 9)))
						End If
						If lstrZona = "000" Then lstrZona = "001"
						'
						'Preenchendo a grade
						With Me.mfgDados
							.Rows = Me.mfgDados.Rows + 1
							.set_TextMatrix(.Rows - 1, 0, lstrZona & "." & lstrLivro & "." & lstrConta)
							.set_TextMatrix(.Rows - 1, 1, VB6.Format(CStr(ldblNumNf), "000000000") & " - " & lstrMesAnoFat)
							.set_TextMatrix(.Rows - 1, 2, ldteVecto)
							.set_TextMatrix(.Rows - 1, 3, ldteVecto)
							.set_TextMatrix(.Rows - 1, 4, VB6.Format(ldblValor, "Standard"))
							.set_TextMatrix(.Rows - 1, 5, VB6.Format(ldblTributo, "Standard"))
							.set_TextMatrix(.Rows - 1, 6, lstrNrBanco)
							.set_TextMatrix(.Rows - 1, 7, lstrAgencia)
							.set_TextMatrix(.Rows - 1, 8, lstrCodRet & " - " & DbCodToDescri(lstrCodRet))
							.set_TextMatrix(.Rows - 1, 9, lstrCodMovto & " - " & IIf(lstrCodMovto = "0", "Normal", "Cancelado"))
							.set_TextMatrix(.Rows - 1, 10, "")
							.set_TextMatrix(.Rows - 1, 11, "")
							.set_TextMatrix(.Rows - 1, 12, "")
							.set_TextMatrix(.Rows - 1, 13, lstrSeqReg)
							.set_TextMatrix(.Rows - 1, 14, "")
							.set_TextMatrix(.Rows - 1, 15, "")
						End With
						'
						'Totalizando os valores
						'--Efetivados
						Me.txtEfReg.Text = CStr(CInt(Me.txtEfReg.Text) + 1) 'Qtde
						Me.txtEfVlr.Text = VB6.Format(CDbl(txtEfVlr.Text) + ldblValor, "Standard") 'Valor
						Me.txtEfTax.Text = VB6.Format(CDbl(Me.txtEfTax.Text) + ldblTributo, "Standard") 'Taxas
						'
						'--Debitados
						If lstrCodRet = "00" Or lstrCodRet = "31" Then
							Me.txtDbReg.Text = CStr(CInt(Me.txtDbReg.Text) + 1) 'Qtde
							Me.txtDbVlr.Text = VB6.Format(CDbl(Me.txtDbVlr.Text) + ldblValor, "Standard") 'Valor
							Me.txtDbTax.Text = VB6.Format(CDbl(Me.txtDbTax.Text) + ldblTributo, "Standard") 'tributo
						Else
							'--Não Debitados
							Me.txtNdReg.Text = CStr(CInt(Me.txtNdReg.Text) + 1) ' Qtde
							Me.txtNdVlr.Text = VB6.Format(CDbl(Me.txtNdVlr.Text) + ldblValor, "Standard") 'Valor
							Me.txtNdTax.Text = VB6.Format(CDbl(Me.txtNdTax.Text) + ldblTributo, "Standard") 'tributo
						End If
					End If
				Case "G" 'Retorno das arrec. identif. c/ codigo de barras
					If Me.strTipoServ = "Guiche" Then
						lstrAux = RTrim(Mid(lstrArqLin, 2, 20))
						lstrPgto = Trim(Mid(lstrArqLin, 22, 8))
						lstrPgto = Mid(lstrPgto, 7, 2) & "/" & Mid(lstrPgto, 5, 2) & "/" & Mid(lstrPgto, 1, 4)
						ldtePgto = CDate(IIf(IsDate(lstrPgto), lstrPgto, "01/01/1900"))
						lstrCred = Trim(Mid(lstrArqLin, 30, 8))
						lstrCred = Mid(lstrCred, 7, 2) & "/" & Mid(lstrCred, 5, 2) & "/" & Mid(lstrCred, 1, 4)
						ldteCred = CDate(IIf(IsDate(lstrCred), lstrCred, "01/01/1900"))
						lstrbarras = Trim(Mid(lstrArqLin, 38, 44))
						ldblValor = CDbl(Mid(lstrArqLin, 82, 12)) / 100
						ldblTributo = CDbl(Mid(lstrArqLin, 94, 7)) / 100
						lstrSeqReg = Trim(Mid(lstrArqLin, 101, 8))
						lstrCodAge = Trim(Mid(lstrArqLin, 109, 8))
						If VB.Left(lstrCodAge, 3) = lstrNrBanco Then
							lstrCodAge = VB.Right(lstrCodAge, Len(lstrCodAge) - 3)
						End If
						lstrCodArr = Trim(Mid(lstrArqLin, 117, 1))
						lstrLixo = Trim(Mid(lstrArqLin, 118, 32))
						lstrFormaPgto = Trim(Mid(lstrArqLin, 141, 1))
						'
						'Pega posição da string do cod de barras para validar a Zona Livro Conta do DOS e do WINDOWS
						lstrAux = Mid(lstrbarras, 33, 12)
						llngBarAux = Val(VB.Left(VB.Right(Mid(lstrbarras, 20, 13), 4), 2))
						'
						'Pega identificadores ZLC, Numero fatura e MesAno
						If gstrEmpresa_Sigla = "EFLUL" Then
							If llngBarAux <= 12 Then 'É Windows'
								ldblNumNf = CDbl(Val(Mid(lstrbarras, 20, 9)))
								lstrMesAnoFat = Trim(Mid(lstrbarras, 29, 2) & "/" & IIf(Val(Mid(lstrbarras, 31, 2)) < 50, "20" & Mid(lstrbarras, 31, 2), "19" & Mid(lstrbarras, 31, 2)))
								lstrZona = Mid(Trim(lstrbarras), 33, 3)
								lstrLivro = Mid(Trim(lstrbarras), 36, 2)
								lstrConta = Mid(Trim(lstrbarras), 38, 7)
							Else
								ldblNumNf = CDbl(Val(Mid(lstrbarras, 20, 5)))
								lstrMesAnoFat = Trim(Mid(lstrbarras, 27, 2) & "/" & Mid(lstrbarras, 29, 4))
								lstrZona = Mid(Trim(lstrbarras), 33, 3)
								lstrLivro = Mid(Trim(lstrbarras), 36, 2)
								lstrConta = Mid(Trim(lstrbarras), 38, 6)
							End If
						ElseIf gstrEmpresa_Sigla = "COORSEL" Or gstrEmpresa_Sigla = "CERGAL" Then 
							ldblNumNf = CDbl(Val(Mid(lstrbarras, 20, 5)))
							lstrMesAnoFat = Trim(Mid(lstrbarras, 27, 2) & "/" & Mid(lstrbarras, 29, 4))
							lstrZona = Mid(Trim(lstrbarras), 33, 3)
							lstrLivro = Mid(Trim(lstrbarras), 36, 2)
							lstrConta = Mid(Trim(lstrbarras), 38, 6)
						ElseIf gstrEmpresa_Sigla = "CHESP" Then 
							ldblNumNf = CDbl(Val(Mid(lstrbarras, 20, 7)))
							lstrMesAnoFat = Trim(Mid(lstrbarras, 28, 2) & "/" & Mid(lstrbarras, 30, 4))
							lstrZona = Mid(Trim(lstrbarras), 34, 3)
							lstrLivro = Mid(Trim(lstrbarras), 37, 2)
							lstrConta = Mid(Trim(lstrbarras), 39, 6)
						ElseIf gstrEmpresa_Sigla = "EFLJCL" Then 
							If llngBarAux = 20 Then 'DOS
								ldblNumNf = CDbl(Val(Mid(lstrbarras, 20, 5)))
								lstrMesAnoFat = Trim(Mid(lstrbarras, 27, 2) & "/" & Mid(lstrbarras, 29, 4))
								lstrZona = Mid(Trim(lstrbarras), 33, 3)
								lstrLivro = Mid(Trim(lstrbarras), 36, 2)
								If VB.Right(lstrMesAnoFat, 4) & "/" & VB.Left(lstrMesAnoFat, 2) < VB.Right(istrMesIni, 4) & "/" & VB.Left(istrMesIni, 2) Then Call trocaZonaLivro(lstrZona, lstrLivro)
								lstrConta = Mid(Trim(lstrbarras), 38, 6)
							Else
								ldblNumNf = CDbl(Val(Mid(lstrbarras, 20, 7)))
								lstrMesAnoFat = Trim(Mid(lstrbarras, 28, 2) & "/" & Mid(lstrbarras, 30, 4))
								lstrZona = Mid(Trim(lstrbarras), 34, 3)
								lstrLivro = Mid(Trim(lstrbarras), 37, 2)
								lstrConta = Mid(Trim(lstrbarras), 39, 6)
							End If
						End If
						'
						'Zona Livro e Conta
						If lstrZona = "000" Then lstrZona = "001"
						With Me.mfgDados
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, lstrZona & "." & lstrLivro & "." & lstrConta)
							.set_TextMatrix(.Rows - 1, 1, VB6.Format(CStr(ldblNumNf), "000000000") & " - " & lstrMesAnoFat)
							.set_TextMatrix(.Rows - 1, 2, ldtePgto)
							.set_TextMatrix(.Rows - 1, 3, ldteCred)
							'.TextMatrix(.Rows - 1, 4) = ldteVecto
							.set_TextMatrix(.Rows - 1, 5, VB6.Format(ldblValor, "Standard"))
							.set_TextMatrix(.Rows - 1, 6, VB6.Format(ldblTributo, "Standard"))
							.set_TextMatrix(.Rows - 1, 7, lstrNrBanco)
							.set_TextMatrix(.Rows - 1, 8, lstrCodAge)
							.set_TextMatrix(.Rows - 1, 9, lstrCodArr & " - " & ArCodToDescri(lstrCodArr) & " / " & IIf(lstrFormaPgto = "1", "Dinheiro", IIf(lstrFormaPgto = "2", "Cheque", "Não Identificado")))
							.set_TextMatrix(.Rows - 1, 10, "")
							.set_TextMatrix(.Rows - 1, 11, "")
							.set_TextMatrix(.Rows - 1, 12, "")
							.set_TextMatrix(.Rows - 1, 13, lstrSeqReg)
							.set_TextMatrix(.Rows - 1, 14, "")
							.set_TextMatrix(.Rows - 1, 15, "")
						End With
						Me.txtEfReg.Text = CStr(CInt(Me.txtEfReg.Text) + 1)
						Me.txtEfVlr.Text = VB6.Format(CDbl(txtEfVlr.Text) + ldblValor, "Standard")
						Me.txtEfTax.Text = VB6.Format(CDbl(Me.txtEfTax.Text) + ldblTributo, "Standard")
						'ldblRegZTotVlr = ldblRegZTotVlr + ldblValor
					End If
					lblnSujeira = True
					'Case "H"        'Ocorrência em Alt. de control da empresa
					'Case "I"        'Incentivo de débito automático
					'Case "J"        'Confirma o proc. de arquivos
					'Case "L"        'Cronograma de faturamento de tributos
					'Case "T"        'Total de clientes debitados
					'Case "X"        'Relação de Agências
				Case "Z" 'Trailler
					lstrRegZTotReg = Mid(lstrArqLin, 2, 6)
					If Len(Trim(CStr(ldblRegZTotVlr))) = 0 Then
						ldblRegZTotVlr = CDbl(Mid(lstrArqLin, 8, 17)) / 100
					End If
					'Me.txtPrReg.Text = Val(lstrRegZTotReg) - 2 'Total de Registros Previstos
					'Me.txtPrVlr.Text = Format(ldblRegZTotVlr, "Standard") 'Total de Valores Previstos
					Me.txtDbVlr.Text = VB6.Format(Me.txtDbVlr.Text, "Standard")
					Me.txtNdVlr.Text = VB6.Format(Me.txtNdVlr.Text, "Standard")
					Me.txtEfVlr.Text = VB6.Format(Me.txtEfVlr.Text, "Standard")
					Me.txtEfTax.Text = VB6.Format(Me.txtEfTax.Text, "Standard")
					Me.txtReVlr.Text = VB6.Format(Me.txtReVlr.Text, "Standard")
					Me.txtReTax.Text = VB6.Format(Me.txtReTax.Text, "Standard")
					Me.txtDpVlr.Text = VB6.Format(Me.txtDpVlr.Text, "Standard")
					Me.txtDpTax.Text = VB6.Format(Me.txtDpTax.Text, "Standard")
					lblnSujeira = False
			End Select
		Next llngLinha
ErroEncheGrade: 
		FileClose(1)
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
		End If
		EncheGrade = lblnSujeira
		Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 2)
	End Function
	
	Private Function AnalizaGrade() As Boolean
		Dim llngRow As Integer
		Dim llngConsId As Integer
		Dim llngUnidId As Integer
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim ldblNumNf As Double
		Dim lstrMesAnoFat As String
		Dim lblnFatNaoLoc As Boolean
		Dim lblnEmFat As Boolean
		Dim ldblValor As Double
		Dim lstrFlagSt As String
		Dim lstrCodRet As String
		Dim ldteVecto As Date
		Dim lstrGrTar As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		
		'
		On Error GoTo ErrorAnalizaGrade
		'
		iblnTransicao = False
		iblnCancelada = False
		'
		With Me.mfgDados
			Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .Rows - 1, " (Análise do Arquivo)")
			For llngRow = 1 To .Rows - 1
				lblnEmFat = False
				Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " (Análise do Arquivo)")
				If Me.strTipoServ = "Debitos" And Len(Trim(Me.txtMesAno.Text)) > 0 Then
					lstrZona = Mid(.get_TextMatrix(llngRow, 0), 1, 3)
					lstrLivro = Mid(.get_TextMatrix(llngRow, 0), 5, 2)
					lstrConta = Mid(.get_TextMatrix(llngRow, 0), 8, 6)
					lstrCodRet = VB.Left(.get_TextMatrix(llngRow, 8), 2)
					If InStr(1, .get_TextMatrix(llngRow, 1), "-") > 0 Then
						ldblNumNf = CDbl(Trim(VB.Left(.get_TextMatrix(llngRow, 1), InStr(1, .get_TextMatrix(llngRow, 1), "-") - 1)))
						lstrMesAnoFat = Trim(Mid(.get_TextMatrix(llngRow, 1), InStr(1, .get_TextMatrix(llngRow, 1), "-") + 1))
					Else
						lstrMesAnoFat = Me.txtMesAno.Text
						ldblNumNf = 0
					End If
					lstrSql = ""
					lstrSql = lstrSql & "SELECT * "
					lstrSql = lstrSql & "  FROM `nf` "
					lstrSql = lstrSql & " WHERE `zona`  ='" & lstrZona & "'"
					lstrSql = lstrSql & "   AND `livro` ='" & lstrLivro & "'"
					lstrSql = lstrSql & "   AND `conta` ='" & lstrConta & "'"
					lstrSql = lstrSql & "   AND `mesano_ref` =" & CInt(VB.Right(lstrMesAnoFat, 4) & VB.Left(lstrMesAnoFat, 2)) & " "
					If ldblNumNf > 0 Then
						lstrSql = lstrSql & "   AND `numnf` = " & ldblNumNf & " "
					End If
					Call Conectar(lstrSql, lrstAux)
					With lrstAux
						If .State = ADODB.ObjectStateEnum.adStateOpen Then
							If .RecordCount > 0 Then
								istrTabNf = "nf"
								'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"'
								ldblNumNf = CDbl(IIf(IsDbNull(.Fields("numnf").value), 0, .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"'
								lstrMesAnoFat = Trim(IIf(IsDbNull(.Fields("mesano").value), "00/0000", .Fields("mesano").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"'
								lstrFlagSt = Trim(IIf(IsDbNull(.Fields("flgst").value), "", .Fields("flgst").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"'
								ldteVecto = CDate(IIf(IsDbNull(.Fields("datavenc").value), "01/01/1900", .Fields("datavenc").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"'
								lstrGrTar = Trim(IIf(IsDbNull(.Fields("ta").value), "01B100", .Fields("ta").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"'
								ldblValor = CDbl(IIf(IsDbNull(.Fields("valorliq").value), IIf(IsDbNull(.Fields("valortot").value), 0, .Fields("valortot").value), .Fields("valorliq").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"'
								llngConsId = CInt(IIf(IsDbNull(.Fields("cons_id").value), 0, .Fields("cons_id").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"'
								llngUnidId = CInt(IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").value))
							Else
								Call .Close()
								lstrSql = ""
								lstrSql = lstrSql & "SELECT * "
								lstrSql = lstrSql & "  FROM `nftransicao` "
								lstrSql = lstrSql & " WHERE `zona`  ='" & lstrZona & "'"
								lstrSql = lstrSql & "   AND `livro` ='" & lstrLivro & "'"
								lstrSql = lstrSql & "   AND `conta` ='" & lstrConta & "'"
								lstrSql = lstrSql & "   AND `mesano_ref` =" & CInt(VB.Right(lstrMesAnoFat, 4) & VB.Left(lstrMesAnoFat, 2)) & " "
								If ldblNumNf > 0 Then
									lstrSql = lstrSql & "   AND `numnf` = " & ldblNumNf & " "
								End If
								Call Conectar(lstrSql, lrstAux)
								With lrstAux
									If .State = ADODB.ObjectStateEnum.adStateOpen Then
										If .RecordCount > 0 Then
											istrTabNf = "nftransicao"
											iblnTransicao = True
											lblnEmFat = True
											'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"'
											ldblNumNf = CDbl(IIf(IsDbNull(.Fields("numnf").value), 0, .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"'
											lstrMesAnoFat = Trim(IIf(IsDbNull(.Fields("mesano").value), "00/0000", .Fields("mesano").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"'
											lstrFlagSt = Trim(IIf(IsDbNull(.Fields("flgst").value), "", .Fields("flgst").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"'
											ldteVecto = CDate(IIf(IsDbNull(.Fields("datavenc").value), "01/01/1900", .Fields("datavenc").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"'
											lstrGrTar = Trim(IIf(IsDbNull(.Fields("ta").value), "01B100", .Fields("ta").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"'
											ldblValor = CDbl(IIf(IsDbNull(.Fields("valorliq").value), IIf(IsDbNull(.Fields("valortot").value), 0, .Fields("valortot").value), .Fields("valorliq").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"'
											llngConsId = CInt(IIf(IsDbNull(.Fields("cons_id").value), 0, .Fields("cons_id").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"'
											llngUnidId = CInt(IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").value))
										Else
											ldblNumNf = 0
											lstrMesAnoFat = ""
											lstrFlagSt = ""
											ldteVecto = CDate("01/01/1900")
											lstrGrTar = "01B100"
											ldblValor = 0
											llngConsId = 0
											llngUnidId = 0
										End If
									End If
								End With
							End If
							Call .Close()
						End If
					End With
					If lstrFlagSt = "C" Then
						.set_TextMatrix(llngRow, 1, "              ")
						.set_TextMatrix(llngRow, 10, "Fatura Cancelada")
						.set_TextMatrix(llngRow, 11, "B")
						.set_TextMatrix(llngRow, 12, VB6.Format(0, "Standard"))
						.set_TextMatrix(llngRow, 14, "0")
						.set_TextMatrix(llngRow, 15, "0")
						'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
						.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillRepeat
						.Row = llngRow
						.Col = 0
						.ColSel = .Cols - 1
						.CellForeColor = System.Drawing.Color.Blue
						'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
						.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillSingle
						Me.txtEsNecon.Text = CStr(CInt(txtEsNecon.Text) + 1)
						iblnCancelada = True
					Else
						If ldblNumNf > 0 Then
							.set_TextMatrix(llngRow, 1, VB6.Format(CStr(ldblNumNf), "000000000") & " - " & lstrMesAnoFat)
							.set_TextMatrix(llngRow, 3, IIf(ldteVecto <> CDate("01/01/1900"), ldteVecto, "00/00/0000"))
							.set_TextMatrix(llngRow, 10, IIf(lstrFlagSt = "P", "Paga", IIf(lstrFlagSt = "R", "em Reserva", IIf(lstrFlagSt = "J", "em Judice", IIf(lblnEmFat, "em Faturamento", "em Aberta")))))
							.set_TextMatrix(llngRow, 11, Mid(lstrGrTar, 3, 1))
							.set_TextMatrix(llngRow, 12, VB6.Format(ldblValor - CDbl(.get_TextMatrix(llngRow, 4)), "Standard"))
							.set_TextMatrix(llngRow, 14, llngConsId)
							.set_TextMatrix(llngRow, 15, llngUnidId)
							If .get_TextMatrix(llngRow, 10) = "Paga" Then
								If CDbl(.get_TextMatrix(llngRow, 12)) <> 0 Then
									'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
									.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillRepeat
									.Row = llngRow
									.Col = 0
									.ColSel = .Cols - 1
									.CellForeColor = System.Drawing.Color.Magenta
									'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
									.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillSingle
								Else
									'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
									.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillRepeat
									.Row = llngRow
									.Col = 0
									.ColSel = .Cols - 1
									.CellForeColor = System.Drawing.Color.Red
									'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
									.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillSingle
								End If
								If lstrCodRet = "00" Or lstrCodRet = "31" Then
									Me.txtEsDevol.Text = CStr(CInt(Me.txtEsDevol.Text) + 1)
									Me.txtDpReg.Text = CStr(CInt(Me.txtDpReg.Text) + 1)
									Me.txtDpVlr.Text = VB6.Format(CDbl(Me.txtDpVlr.Text) + CDbl(.get_TextMatrix(llngRow, 4)), "Standard")
									Me.txtDpTax.Text = VB6.Format(CDbl(Me.txtDpTax.Text) + CDbl(.get_TextMatrix(llngRow, 5)), "Standard")
								End If
							Else
								If CDbl(.get_TextMatrix(llngRow, 12)) <> 0 Then
									'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
									.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillRepeat
									.Row = llngRow
									.Col = 0
									.ColSel = .Cols - 1
									.CellForeColor = System.Drawing.Color.Magenta
									'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
									.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillSingle
								Else
									'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
									.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillRepeat
									.Row = llngRow
									.Col = 0
									.ColSel = .Cols - 1
									.CellForeColor = System.Drawing.ColorTranslator.FromOle(&H80000008) 'Normal
									'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
									.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillSingle
								End If
								Me.txtEsReceb.Text = CStr(CInt(Me.txtEsReceb.Text) + 1)
							End If
						Else
							.set_TextMatrix(llngRow, 1, "              ")
							.set_TextMatrix(llngRow, 10, "Não Encontrada")
							.set_TextMatrix(llngRow, 11, "B")
							.set_TextMatrix(llngRow, 12, VB6.Format(0, "Standard"))
							.set_TextMatrix(llngRow, 14, "0")
							.set_TextMatrix(llngRow, 15, "0")
							'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
							.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillRepeat
							.Row = llngRow
							.Col = 0
							.ColSel = .Cols - 1
							.CellForeColor = System.Drawing.Color.Lime
							'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
							.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillSingle
							Me.txtEsNecon.Text = CStr(CInt(txtEsNecon.Text) + 1)
							lblnFatNaoLoc = True
						End If
					End If
				ElseIf Me.strTipoServ = "Guiche" And Len(Trim(Me.txtMesAno.Text)) > 0 Then 
					lstrZona = Mid(.get_TextMatrix(llngRow, 0), 1, 3)
					lstrLivro = Mid(.get_TextMatrix(llngRow, 0), 5, 2)
					lstrConta = VB.Right(Mid(.get_TextMatrix(llngRow, 0), 8, 7), 6)
					If InStr(1, .get_TextMatrix(llngRow, 1), "-") > 0 Then
						ldblNumNf = CDbl(Trim(VB.Left(.get_TextMatrix(llngRow, 1), InStr(1, .get_TextMatrix(llngRow, 1), "-") - 1)))
						lstrMesAnoFat = Trim(Mid(.get_TextMatrix(llngRow, 1), InStr(1, .get_TextMatrix(llngRow, 1), "-") + 1))
					Else
						lstrMesAnoFat = Me.txtMesAno.Text
					End If
					If gstrEmpresa_Sigla = "EFLJCL" And CInt(VB.Right(lstrMesAnoFat, 4) & VB.Left(lstrMesAnoFat, 2)) <= CInt(VB.Right(istrMesIni, 4) & VB.Left(istrMesIni, 2)) Then
						lstrSql = ""
						lstrSql = lstrSql & "SELECT * "
						lstrSql = lstrSql & "  FROM `nf` "
						lstrSql = lstrSql & " WHERE conta ='" & lstrConta & "'"
						lstrSql = lstrSql & "   AND mesano_ref=" & CInt(VB.Right(lstrMesAnoFat, 4) & VB.Left(lstrMesAnoFat, 2)) & " "
						If ldblNumNf > 0 Then
							lstrSql = lstrSql & "   AND numnf = " & ldblNumNf & " "
						End If
					Else
						lstrSql = ""
						lstrSql = lstrSql & "SELECT * "
						lstrSql = lstrSql & "  FROM `nf` "
						lstrSql = lstrSql & " WHERE zona='" & lstrZona & "'"
						lstrSql = lstrSql & "   AND livro='" & lstrLivro & "'"
						lstrSql = lstrSql & "   AND conta ='" & lstrConta & "'"
						lstrSql = lstrSql & "   AND mesano_ref=" & CInt(VB.Right(lstrMesAnoFat, 4) & VB.Left(lstrMesAnoFat, 2)) & " "
						If ldblNumNf > 0 Then
							lstrSql = lstrSql & "   AND numnf = " & ldblNumNf & " "
						End If
					End If
					Call Conectar(lstrSql, lrstAux)
					With lrstAux
						If .State = ADODB.ObjectStateEnum.adStateOpen Then
							If .RecordCount > 0 Then
								istrTabNf = "nf"
								'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"'
								ldblNumNf = CDbl(IIf(IsDbNull(.Fields("numnf").value), 0, .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"'
								lstrMesAnoFat = Trim(IIf(IsDbNull(.Fields("mesano").value), "00/0000", .Fields("mesano").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"'
								lstrFlagSt = Trim(IIf(IsDbNull(.Fields("flgst").value), "", .Fields("flgst").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"'
								ldteVecto = CDate(IIf(IsDbNull(.Fields("datavenc").value), "01/01/1900", .Fields("datavenc").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"'
								lstrGrTar = Trim(IIf(IsDbNull(.Fields("ta").value), "01B100", .Fields("ta").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"'
								ldblValor = CDbl(IIf(IsDbNull(.Fields("valorliq").value), IIf(IsDbNull(.Fields("valortot").value), 0, .Fields("valortot").value), .Fields("valorliq").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"'
								llngConsId = CInt(IIf(IsDbNull(.Fields("cons_id").value), 0, .Fields("cons_id").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"'
								llngUnidId = CInt(IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").value))
							Else
								Call .Close()
								lstrSql = ""
								lstrSql = lstrSql & "SELECT * "
								lstrSql = lstrSql & "  FROM `nftransicao` "
								lstrSql = lstrSql & " WHERE zona='" & lstrZona & "'"
								lstrSql = lstrSql & "   AND livro='" & lstrLivro & "'"
								lstrSql = lstrSql & "   AND conta ='" & lstrConta & "'"
								lstrSql = lstrSql & "   AND mesano_ref=" & CInt(VB.Right(lstrMesAnoFat, 4) & VB.Left(lstrMesAnoFat, 2)) & " "
								If ldblNumNf > 0 Then
									lstrSql = lstrSql & "   AND numnf = " & ldblNumNf & " "
								End If
								Call Conectar(lstrSql, lrstAux)
								With lrstAux
									If .State = ADODB.ObjectStateEnum.adStateOpen Then
										If .RecordCount > 0 Then
											istrTabNf = "nftransicao"
											iblnTransicao = True
											lblnEmFat = True
											'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"'
											ldblNumNf = CDbl(IIf(IsDbNull(.Fields("numnf").value), 0, .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"'
											lstrMesAnoFat = Trim(IIf(IsDbNull(.Fields("mesano").value), "00/0000", .Fields("mesano").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"'
											lstrFlagSt = Trim(IIf(IsDbNull(.Fields("flgst").value), "", .Fields("flgst").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"'
											ldteVecto = CDate(IIf(IsDbNull(.Fields("datavenc").value), "01/01/1900", .Fields("datavenc").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"'
											lstrGrTar = Trim(IIf(IsDbNull(.Fields("ta").value), "01B100", .Fields("ta").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"'
											ldblValor = CDbl(IIf(IsDbNull(.Fields("valorliq").value), IIf(IsDbNull(.Fields("valortot").value), 0, .Fields("valortot").value), .Fields("valorliq").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"'
											llngConsId = CInt(IIf(IsDbNull(.Fields("cons_id").value), 0, .Fields("cons_id").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"'
											llngUnidId = CInt(IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").value))
										Else
											ldblNumNf = 0
											lstrMesAnoFat = ""
											lstrFlagSt = ""
											ldteVecto = CDate("01/01/1900")
											lstrGrTar = "01B100"
											ldblValor = 0
											llngConsId = 0
											llngUnidId = 0
										End If
									End If
								End With
							End If
							Call .Close()
						End If
					End With
					If lstrFlagSt = "C" Then
						.set_TextMatrix(llngRow, 1, "              ")
						.set_TextMatrix(llngRow, 4, "00/00/0000")
						.set_TextMatrix(llngRow, 10, "Fatura Cancelada")
						.set_TextMatrix(llngRow, 11, "B")
						.set_TextMatrix(llngRow, 12, VB6.Format(0, "Standard"))
						.set_TextMatrix(llngRow, 14, "0")
						.set_TextMatrix(llngRow, 15, "0")
						'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
						.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillRepeat
						.Row = llngRow
						.Col = 0
						.ColSel = .Cols - 1
						.CellForeColor = System.Drawing.Color.Blue
						'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
						.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillSingle
						Me.txtEsNecon.Text = CStr(CInt(Me.txtEsNecon.Text) + 1)
						iblnCancelada = True
					Else
						If ldblNumNf > 0 Then
							.set_TextMatrix(llngRow, 1, VB6.Format(CStr(ldblNumNf), "000000000") & " - " & lstrMesAnoFat)
							.set_TextMatrix(llngRow, 4, IIf(ldteVecto <> CDate("01/01/1900"), ldteVecto, "00/00/0000"))
							.set_TextMatrix(llngRow, 10, IIf(lstrFlagSt = "P", "Paga", IIf(lstrFlagSt = "R", "em Reserva", IIf(lstrFlagSt = "J", "em Judice", IIf(lblnEmFat, "em Faturamento", "em Aberta")))))
							.set_TextMatrix(llngRow, 11, Mid(lstrGrTar, 3, 1))
							.set_TextMatrix(llngRow, 12, VB6.Format(ldblValor - CDbl(.get_TextMatrix(llngRow, 5)), "Standard"))
							.set_TextMatrix(llngRow, 14, llngConsId)
							.set_TextMatrix(llngRow, 15, llngUnidId)
							'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
							.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillRepeat
							.Row = llngRow
							.Col = 0
							.ColSel = .Cols - 1
							.CellForeColor = System.Drawing.ColorTranslator.FromOle(&H80000008) 'Normal
							'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
							.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillSingle
							If .get_TextMatrix(llngRow, 10) = "Paga" Then
								If CDbl(.get_TextMatrix(llngRow, 12)) <> 0 Then
									'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
									.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillRepeat
									.Row = llngRow
									.Col = 0
									.ColSel = .Cols - 1
									.CellForeColor = System.Drawing.Color.Magenta
									'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
									.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillSingle
								Else
									'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
									.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillRepeat
									.Row = llngRow
									.Col = 0
									.ColSel = .Cols - 1
									.CellForeColor = System.Drawing.Color.Red
									'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
									.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillSingle
								End If
								Me.txtEsDevol.Text = CStr(CInt(Me.txtEsDevol.Text) + 1)
								Me.txtDpReg.Text = CStr(CInt(Me.txtDpReg.Text) + 1)
								Me.txtDpVlr.Text = VB6.Format(CDbl(Me.txtDpVlr.Text) + CDbl(.get_TextMatrix(llngRow, 5)), "Standard")
								Me.txtDpTax.Text = VB6.Format(CDbl(Me.txtDpTax.Text) + CDbl(.get_TextMatrix(llngRow, 6)), "Standard")
							ElseIf .get_TextMatrix(llngRow, 10) = "em Aberta" Then 
								Me.txtEsReceb.Text = CStr(CInt(Me.txtEsReceb.Text) + 1)
								Me.txtReReg.Text = CStr(CInt(Me.txtReReg.Text) + 1)
								Me.txtReVlr.Text = VB6.Format(CDbl(Me.txtReVlr.Text) + CDbl(.get_TextMatrix(llngRow, 5)), "Standard")
								Me.txtReTax.Text = VB6.Format(CDbl(Me.txtReTax.Text) + CDbl(.get_TextMatrix(llngRow, 6)), "Standard")
							ElseIf .get_TextMatrix(llngRow, 10) = "em Reserva" Or .get_TextMatrix(llngRow, 10) = "em Judice" Then 
								Me.txtEsReceb.Text = CStr(CInt(Me.txtEsReceb.Text) + 1)
								Me.txtResReg.Text = CStr(CInt(Me.txtResReg.Text) + 1)
								Me.txtResVlr.Text = VB6.Format(CDbl(Me.txtResVlr.Text) + CDbl(.get_TextMatrix(llngRow, 5)), "Standard")
								Me.txtResTax.Text = VB6.Format(CDbl(Me.txtResTax.Text) + CDbl(.get_TextMatrix(llngRow, 6)), "Standard")
							End If
						Else
							.set_TextMatrix(llngRow, 1, "              ")
							.set_TextMatrix(llngRow, 4, "00/00/0000")
							.set_TextMatrix(llngRow, 10, "Não Encontrada")
							.set_TextMatrix(llngRow, 11, "B")
							.set_TextMatrix(llngRow, 12, VB6.Format(0, "Standard"))
							.set_TextMatrix(llngRow, 14, "0")
							.set_TextMatrix(llngRow, 15, "0")
							'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
							.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillRepeat
							.Row = llngRow
							.Col = 0
							.ColSel = .Cols - 1
							.CellForeColor = System.Drawing.Color.Lime
							'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
							.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillSingle
							Me.txtEsNecon.Text = CStr(CDbl(txtEsNecon.Text) + 1)
							lblnFatNaoLoc = True
						End If
					End If
				End If
			Next llngRow
		End With
		'Analiza se tem alguma duplicidade de pagamento no mesmo arquivo
		Call AnalizaGradeDuplicidade()
		Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 2)
ErrorAnalizaGrade: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
		End If
	End Function
	
	Private Sub AnalizaGradeDuplicidade()
		Dim llngRow1 As Integer
		Dim llngRow2 As Integer
		Dim ldblNumNf1 As Double
		Dim lstrMesAno1 As String
		Dim lstrZona1 As String
		Dim lstrLivro1 As String
		Dim lstrConta1 As String
		Dim ldblNumNf2 As Double
		Dim lstrMesAno2 As String
		Dim lstrZona2 As String
		Dim lstrLivro2 As String
		Dim lstrConta2 As String
		Dim lblnContinua As Boolean
		'
		On Error GoTo ErroAnalizaGradeDuplicidade
		'
		With Me.mfgDados
			Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .Rows - 1, " (Análise de Duplicidade)")
			For llngRow1 = 1 To .Rows - 1
				lblnContinua = True
				Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " (Análise de Duplicidade)")
				If .get_TextMatrix(0, 4) = "Debitado" Then
					lblnContinua = (VB.Left(.get_TextMatrix(llngRow1, 8), 2) = "00" Or VB.Left(.get_TextMatrix(llngRow1, 8), 2) = "31")
				End If
				If lblnContinua Then
					lstrZona1 = Mid(.get_TextMatrix(llngRow1, 0), 1, 3)
					lstrLivro1 = Mid(.get_TextMatrix(llngRow1, 0), 5, 2)
					lstrConta1 = Mid(.get_TextMatrix(llngRow1, 0), 8, 7)
					If InStr(1, .get_TextMatrix(llngRow1, 1), "-") > 0 Then
						ldblNumNf1 = CDbl(Trim(VB.Left(.get_TextMatrix(llngRow1, 1), InStr(1, .get_TextMatrix(llngRow1, 1), "-") - 1)))
						lstrMesAno1 = Trim(Mid(.get_TextMatrix(llngRow1, 1), InStr(1, .get_TextMatrix(llngRow1, 1), "-") + 1))
					Else
						lstrMesAno1 = Me.txtMesAno.Text
						ldblNumNf1 = 0
					End If
					If llngRow1 < .Rows - 1 Then
						For llngRow2 = llngRow1 + 1 To .Rows - 1
							lblnContinua = True
							If .get_TextMatrix(0, 4) = "Debitado" Then
								lblnContinua = (VB.Left(.get_TextMatrix(llngRow2, 8), 2) = "00" Or VB.Left(.get_TextMatrix(llngRow2, 8), 2) = "31")
							End If
							If lblnContinua Then
								lstrZona2 = Mid(.get_TextMatrix(llngRow2, 0), 1, 3)
								lstrLivro2 = Mid(.get_TextMatrix(llngRow2, 0), 5, 2)
								lstrConta2 = Mid(.get_TextMatrix(llngRow2, 0), 8, 7)
								If InStr(1, .get_TextMatrix(llngRow2, 1), "-") > 0 Then
									ldblNumNf2 = CDbl(Trim(VB.Left(.get_TextMatrix(llngRow2, 1), InStr(1, .get_TextMatrix(llngRow2, 1), "-") - 1)))
									lstrMesAno2 = Trim(Mid(.get_TextMatrix(llngRow2, 1), InStr(1, .get_TextMatrix(llngRow2, 1), "-") + 1))
								Else
									lstrMesAno2 = Me.txtMesAno.Text
									ldblNumNf2 = 0
								End If
								If ldblNumNf1 > 0 Then
									If ldblNumNf1 = ldblNumNf2 And lstrMesAno1 = lstrMesAno2 And lstrZona1 = lstrZona2 And lstrLivro1 = lstrLivro2 And lstrConta1 = lstrConta2 Then
										'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
										.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillRepeat
										.Row = llngRow2
										.Col = 0
										.ColSel = .Cols - 1
										.CellForeColor = System.Drawing.Color.Red
										'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
										.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillSingle
										.set_TextMatrix(llngRow2, 10, "Paga")
										Me.txtEsDevol.Text = CStr(CInt(Me.txtEsDevol.Text) + 1)
										Me.txtDpReg.Text = CStr(CInt(Me.txtDpReg.Text) + 1)
										Me.txtDpVlr.Text = VB6.Format(CDbl(Me.txtDpVlr.Text) + CDbl(.get_TextMatrix(llngRow2, 5)), "Standard")
										Me.txtDpTax.Text = VB6.Format(CDbl(Me.txtDpTax.Text) + CDbl(.get_TextMatrix(llngRow2, 6)), "Standard")
										Me.txtEsReceb.Text = CStr(CInt(Me.txtEsReceb.Text) - 1)
										Me.txtReReg.Text = CStr(CInt(Me.txtReReg.Text) - 1)
										Me.txtReVlr.Text = VB6.Format(CDbl(Me.txtReVlr.Text) - CDbl(.get_TextMatrix(llngRow2, 5)), "Standard")
										Me.txtReTax.Text = VB6.Format(CDbl(Me.txtReTax.Text) - CDbl(.get_TextMatrix(llngRow2, 6)), "Standard")
									End If
								End If
							End If
						Next llngRow2
					End If
				End If
			Next llngRow1
		End With
ErroAnalizaGradeDuplicidade: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
		End If
	End Sub
	
	Private Function AnalizaGradeDiferenca() As Boolean
		Dim ldblVlrDif As Double
		Dim llngRow As Integer
		Dim lblnRet As Boolean
		Dim lblnContinua As Boolean
		lblnRet = False
		'
		On Error GoTo ErroAnalizaGradeDiferenca
		'
		With Me.mfgDados
			Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .Rows - 1, " (Análise de Diferença)")
			For llngRow = 1 To .Rows - 1
				lblnContinua = True
				Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " (Análise de Diferença)")
				ldblVlrDif = CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, 12)), .get_TextMatrix(llngRow, 12), 0))
				If .get_TextMatrix(0, 4) = "Debitado" Then
					lblnContinua = (VB.Left(.get_TextMatrix(llngRow, 8), 2) = "00" Or VB.Left(.get_TextMatrix(llngRow, 8), 2) = "31")
				End If
				If lblnContinua Then
					If ldblVlrDif <> 0 Then
						Me.txtEsDif.Text = CStr(CInt(IIf(IsNumeric(Me.txtEsDif.Text), Me.txtEsDif.Text, 0)) + 1)
						Me.txtPrDif.Text = CStr(CInt(IIf(IsNumeric(Me.txtPrDif.Text), Me.txtPrDif.Text, 0)) + ldblVlrDif)
						lblnRet = True
					End If
				End If
			Next llngRow
		End With
ErroAnalizaGradeDiferenca: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
		End If
		AnalizaGradeDiferenca = lblnRet
	End Function
	
	Private Sub cmdAnalis_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdAnalis.Click
		Dim lstrTxtErr As String
		Dim lstrTxtCadDeb As String
		Dim llngTotLin As Integer
		Dim lblnSujeira As Boolean
		Dim lblnFatNaoLoc As Boolean
		Dim lblnFatDiferenca As Boolean
		'
		On Error GoTo ErrorcmdAnalis
		'
		lstrTxtCadDeb = ""
		lblnSujeira = False
		If Len(Trim(Me.txtArq.Text)) = 0 Then
			Call MsgBox("Informe o nome do arquivo.", MsgBoxStyle.Information, gstrTituloMensagem)
			Call Me.txtArq.Focus()
		Else
			If Len(Trim(Me.txtMesAno.Text)) = 0 Then
				Call MsgBox("Informe o mês e ano do faturamento para baixar o arquivo.", MsgBoxStyle.Information, gstrTituloMensagem)
				Call Me.txtMesAno.Focus()
			Else
				llngTotLin = ValidaArquivo(lstrTxtErr, lstrTxtCadDeb)
				If Len(lstrTxtErr) > 0 Then
					Call MsgBox(lstrTxtErr, MsgBoxStyle.Information, gstrTituloMensagem)
				Else
					If Len(lstrTxtCadDeb) > 0 Then
						Call MsgBox(lstrTxtCadDeb, MsgBoxStyle.Information, gstrTituloMensagem)
					End If
					Call LigDes(False)
					lblnSujeira = EncheGrade(llngTotLin)
					lblnFatNaoLoc = AnalizaGrade
					If lblnSujeira Then
						Call MsgBox("Existe sujeiras no arquivo, favor verificar antes de registrar!", MsgBoxStyle.Critical, gstrTituloMensagem)
					End If
					If lblnFatNaoLoc Then
						Call MsgBox("Algumas faturas não foram localizadas, favor verificar antes de registrar!", MsgBoxStyle.Critical, gstrTituloMensagem)
					End If
					'Analiza se teve alguma diferença entre o valor da fatura e o valor enviado pelo agente.
					lblnFatDiferenca = AnalizaGradeDiferenca
					If lblnFatDiferenca Then
						Call MsgBox("Algumas faturas estão com diferença no valor, favor verificar antes de registrar!", MsgBoxStyle.Critical, gstrTituloMensagem)
					End If
					Call LigDes(True)
				End If
			End If
		End If
ErrorcmdAnalis: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
		End If
	End Sub
	
	Private Function ValidaArquivo(ByRef astrTxtErr As String, ByRef astrTxtCadastroDebito As String) As Integer
		Dim lblnRegB As Boolean
		Dim llngTotLin As Integer
		Dim llngTotAux As Integer
		Dim lstrArqLin As String
		Dim lstrArqTip As String
		Dim lstrTxtErr As String
		Dim lintCdReme As Short
		Dim lstrNrBanco As String
		Dim lstrNmBanco As String
		Dim ldblValor As Double
		Dim ldblTributo As Double
		Dim lblnRegZ As Boolean
		'
		On Error GoTo ErrorValidaArquivo
		lstrTxtErr = ""
		llngTotLin = 0
		ldblValor = 0
		ldblTributo = 0
		llngTotAux = 0
		lblnRegZ = False
		lblnRegB = False
		'
		'fmePrevisto
		Me.txtPrReg.Text = CStr(0)
		Me.txtPrVlr.Text = "0,00"
		Me.txtPrTax.Text = "0,00"
		Me.txtPrDif.Text = "0,00"
		'
		'Conta quantidade de linhas do arquivo
		FileOpen(1, Me.txtArq.Text, OpenMode.Input)
		While Not EOF(1)
			Input(1, lstrArqLin)
			lstrArqTip = Mid(lstrArqLin, 1, 1)
			If lstrArqTip = "Z" Then
				lblnRegZ = True
			End If
			If Len(Trim(lstrArqLin)) <> 0 Then llngTotAux = llngTotAux + 1
			If lblnRegZ Then
				If Len(Trim(lstrArqLin)) <> 0 Then llngTotLin = llngTotLin + 1
			Else
				llngTotLin = llngTotLin + 1
			End If
			If Me.strTipoServ = "Debitos" And lstrArqTip = "G" Then
				lstrTxtErr = "Este não é um arquivo de débito!"
			ElseIf Me.strTipoServ = "Guiche" And lstrArqTip = "F" Then 
				lstrTxtErr = "Este não é um arquivo de cobrança direta!"
			ElseIf lstrArqTip = "A" Then 
				lintCdReme = CShort(Mid(lstrArqLin, 2, 1)) 'Posição 002 a 002 Tamanho 001 Código da Remessa Valor 2 = Retorno 1 = Envio
				lstrNrBanco = Trim(Mid(lstrArqLin, 43, 3)) 'Posição 043 a 045 Tamanho 003 Codigo do banco
				lstrNmBanco = Trim(Mid(lstrArqLin, 46, 20)) 'Posição 046 a 065 Tamanho 020 Nome do banco
				If Me.strTipoServ = "Debitos" And lintCdReme <> 2 Then
					lstrTxtErr = "Este não é um arquivo de retorno de débito!"
				End If
				If lstrNrBanco <> istrBanNr Then
					lstrTxtErr = "O arquivo aberto do banco " & lstrNrBanco & " - " & lstrNmBanco & ", não pertence ao banco selecionado " & istrBanNr & " - " & istrBanNm & "!"
				End If
			End If
			If lstrArqTip = "B" Then 'Cadastramento de Débito automático (DB)
				lblnRegB = True
			End If
			If lstrArqTip = "F" Then
				ldblValor = ldblValor + CDbl(Mid(lstrArqLin, 53, 15)) / 100
				ldblTributo = ldblTributo + CDbl(IIf(Len(Trim(Mid(lstrArqLin, 119, 10))) = 0, 0, Mid(lstrArqLin, 119, 10))) / 100
			End If
			If lstrArqTip = "G" Then
				ldblValor = ldblValor + CDbl(Mid(lstrArqLin, 82, 12)) / 100
				ldblTributo = ldblTributo + CDbl(Mid(lstrArqLin, 94, 7)) / 100
			End If
			If lstrArqTip = "Z" Then
				'      lstrRegZTotReg = Mid(lstrArqLin, 2, 6)
				'        If Len(Trim(ldblRegZTotVlr)) = 0 Then
				'          ldblRegZTotVlr = CDbl(Mid(lstrArqLin, 8, 17)) / 100
			End If
			
			System.Windows.Forms.Application.DoEvents()
		End While
		If lblnRegB Then
			astrTxtCadastroDebito = "Este arquivo possui registro de cadastro de débito. Favor verifique."
		Else
			astrTxtCadastroDebito = ""
		End If
ErrorValidaArquivo: 
		FileClose(1)
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
		End If
		astrTxtErr = lstrTxtErr
		ValidaArquivo = llngTotLin
		Me.txtPrReg.Text = FormatNumber(llngTotAux - 2, 0)
		Me.txtPrVlr.Text = VB6.Format(ldblValor, "Standard")
		Me.txtPrTax.Text = VB6.Format(ldblTributo, "Standard")
	End Function
	
	Private Sub cmdExec_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExec.Click
		Dim lblnFaturas As Boolean
		Dim lblnNaoEnco As Boolean
		'
		'Controle do indice para percorrer a grid
		Dim lstrCopiaArq As String
		Dim lstrNovoArq As String
		Dim llngRow As Integer
		Dim llngSeqArq As Integer
		'
		'Controla a indetificação do consumidor
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim llngUnidId As Integer
		Dim llngConsId As Integer
		Dim lstrGrupo As String
		'
		'Controla a fatura
		Dim ldblNumNf As Double
		Dim lstrMesAnoFat As String
		Dim ldteVecto As Date
		Dim ldtePgto As Date
		Dim ldteCred As Date
		Dim ldblValor As Double
		Dim ldblTributo As Double
		Dim lstrNrBco As String
		Dim lstrAgencia As String
		Dim lstrSituacao As String
		'
		'Código de Retorno
		Dim lstrCodRet As String
		Dim lstrNmCodRet As String
		'
		'Código do Movimento
		Dim lstrCodMovto As String
		'
		'controle de datas para inserir na tabela de convenios qdo há devolucao de D.P.
		Dim ldteIni As Date
		Dim ldteFim As Date
		Dim lstrBaixaPorFatura As String
		'
		On Error GoTo ErrorExec
		'
		lstrBaixaPorFatura = LeConfig("BAIXAPORNUMNF")
		Call LigDes(False)
		lblnNaoEnco = (CDbl(IIf(IsNumeric(Me.txtEsNecon.Text), Me.txtEsNecon.Text, 0)) <> 0)
		lblnFaturas = True
		If iblnTransicao Or iblnCancelada Then
			lblnFaturas = (MsgBox("Existe faturas " & IIf(iblnTransicao And iblnCancelada, "em faturamento e canceladas", IIf(iblnTransicao, "em faturamento", "canceladas")) & "! Deseja continuar?", MsgBoxStyle.Question + MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2, gstrTituloMensagem) = MsgBoxResult.Yes)
		End If
		If lblnNaoEnco Then
			lblnFaturas = (MsgBox("Existe faturas que não foram encontradas! Deseja continuar?", MsgBoxStyle.Question + MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2, gstrTituloMensagem) = MsgBoxResult.Yes)
		End If
		If lblnFaturas Then
			If MsgBox("Confirma esta operação ?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Confirma") = MsgBoxResult.Yes Then
				'
				'define as datas que serao usadas no insert da tabela de convenios
				'estas datas pegam a data atual do banco de dados e passam para o proximo mes
				ldteIni = BuscaDataBD
				ldteIni = System.Date.FromOADate(CDate(UltimoDiaMes(Month(ldteIni), Year(ldteIni)) & "/" & VB6.Format(ldteIni, "mm/yyyy")).ToOADate + 1)
				ldteFim = CDate(UltimoDiaMes(Month(ldteIni), Year(ldteIni)) & "/" & VB6.Format(ldteIni, "mm/yyyy"))
				'
				With Me.mfgDados
					Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .Rows - 1, " (baixas)")
					For llngRow = 1 To .Rows - 1
						If Me.strTipoServ = "Guiche" Then
							Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " (baixas)")
							lstrZona = Mid(.get_TextMatrix(llngRow, 0), 1, 3)
							lstrLivro = Mid(.get_TextMatrix(llngRow, 0), 5, 2)
							lstrConta = VB.Right(Mid(.get_TextMatrix(llngRow, 0), 8, 7), 6)
							If InStr(1, Trim(.get_TextMatrix(llngRow, 1)), "-") > 0 Then
								ldblNumNf = CDbl(Trim(VB.Left(.get_TextMatrix(llngRow, 1), InStr(1, .get_TextMatrix(llngRow, 1), "-") - 1)))
								lstrMesAnoFat = Trim(Mid(.get_TextMatrix(llngRow, 1), InStr(1, .get_TextMatrix(llngRow, 1), "-") + 1))
							Else
								lstrMesAnoFat = Me.txtMesAno.Text
								ldblNumNf = 0
							End If
							'Paga,em Reserva,em Judice,em Faturamento,em Aberta,Fatura Cancelada,Não Encontrada
							If ldblNumNf > 0 Then
								ldtePgto = CDate(.get_TextMatrix(llngRow, 2))
								ldteCred = CDate(.get_TextMatrix(llngRow, 3))
								ldteVecto = CDate(.get_TextMatrix(llngRow, 4))
								ldblValor = CDbl(.get_TextMatrix(llngRow, 5))
								ldblTributo = CDbl(.get_TextMatrix(llngRow, 6))
								lstrNrBco = Trim(.get_TextMatrix(llngRow, 7))
								lstrAgencia = Trim(.get_TextMatrix(llngRow, 8))
								lstrCodMovto = Trim(Mid(.get_TextMatrix(llngRow, 9), 1, 1))
								lstrSituacao = Trim(.get_TextMatrix(llngRow, 10))
								llngConsId = CInt(.get_TextMatrix(llngRow, 14))
								llngUnidId = CInt(.get_TextMatrix(llngRow, 15))
								If lstrSituacao = "Paga" Then
									If ValidaDevolucao(ldblNumNf, lstrMesAnoFat) = False Then
										Call InsereDevolucao(ldblNumNf, lstrMesAnoFat, lstrZona, lstrLivro, lstrConta, llngConsId, llngUnidId, ldtePgto, ldblValor, ldteIni, ldteFim)
									End If
									.set_TextMatrix(llngRow, 10, "Devolução")
								ElseIf lstrSituacao = "em Aberta" Or lstrSituacao = "em Judice" Then 
									'Processa a baixa da NF
									Call BaixaFatura(ldblNumNf, lstrMesAnoFat, lstrZona, lstrLivro, lstrConta, ldtePgto, lstrBaixaPorFatura)
									'
									' ----- Atualiza os consumos
									Call AtualConsumos(lstrZona, lstrLivro, lstrConta, lstrMesAnoFat, ldtePgto, ldblValor)
									'Call AtualizaConsumos(lstrZona, lstrLivro, lstrConta, lstrMesAnoFat, ldblNumNF)
									'
									.set_TextMatrix(llngRow, 10, "Baixada")
								ElseIf lstrSituacao = "em Reserva" Then 
									'
									Call InsereReserva(ldblNumNf, lstrMesAnoFat)
									'Processa a baixa da NF
									Call BaixaFatura(ldblNumNf, lstrMesAnoFat, lstrZona, lstrLivro, lstrConta, ldtePgto, lstrBaixaPorFatura)
									'
									' ----- Atualiza os consumos
									Call AtualConsumos(lstrZona, lstrLivro, lstrConta, lstrMesAnoFat, ldtePgto, ldblValor)
									'Call AtualizaConsumos(lstrZona, lstrLivro, lstrConta, lstrMesAnoFat, ldblNumNF)
									.set_TextMatrix(llngRow, 10, "Baixada")
								End If
							End If
						ElseIf Me.strTipoServ = "Debitos" Then 
							Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " (baixas)")
							lstrZona = Mid(.get_TextMatrix(llngRow, 0), 1, 3)
							lstrLivro = Mid(.get_TextMatrix(llngRow, 0), 5, 2)
							lstrConta = VB.Right(Mid(.get_TextMatrix(llngRow, 0), 8, 7), 6)
							If InStr(1, .get_TextMatrix(llngRow, 1), "-") > 0 Then
								ldblNumNf = CDbl(Trim(VB.Left(.get_TextMatrix(llngRow, 1), InStr(1, .get_TextMatrix(llngRow, 1), "-") - 1)))
								lstrMesAnoFat = Trim(Mid(.get_TextMatrix(llngRow, 1), InStr(1, .get_TextMatrix(llngRow, 1), "-") + 1))
							Else
								lstrMesAnoFat = Me.txtMesAno.Text
								ldblNumNf = 0
							End If
							If ldblNumNf > 0 Then
								ldtePgto = CDate(.get_TextMatrix(llngRow, 2))
								ldteVecto = CDate(.get_TextMatrix(llngRow, 3))
								ldblValor = CDbl(.get_TextMatrix(llngRow, 4))
								ldblTributo = CDbl(.get_TextMatrix(llngRow, 5))
								lstrNrBco = Trim(.get_TextMatrix(llngRow, 6))
								lstrAgencia = Trim(.get_TextMatrix(llngRow, 7))
								lstrCodRet = Trim(Mid(.get_TextMatrix(llngRow, 8), 1, 2))
								lstrNmCodRet = .get_TextMatrix(llngRow, 8)
								lstrCodMovto = Mid(.get_TextMatrix(llngRow, 9), 1, 1)
								lstrSituacao = Trim(.get_TextMatrix(llngRow, 10))
								lstrGrupo = .get_TextMatrix(llngRow, 11)
								llngConsId = CInt(.get_TextMatrix(llngRow, 14))
								llngUnidId = CInt(.get_TextMatrix(llngRow, 15))
								'Paga,em Reserva,em Judice,em Faturamento,em Aberta,Fatura Cancelada,Não Encontrada
								If ldblNumNf > 0 And (lstrCodRet = "00" Or lstrCodRet = "31") Then
									If lstrSituacao = "Paga" Then
										If ValidaDevolucao(ldblNumNf, lstrMesAnoFat) = False Then
											Call InsereDevolucao(ldblNumNf, lstrMesAnoFat, lstrZona, lstrLivro, lstrConta, llngConsId, llngUnidId, ldtePgto, ldblValor, ldteIni, ldteFim)
										End If
										.set_TextMatrix(llngRow, 10, "Devolução")
									ElseIf lstrSituacao = "em Aberta" Or lstrSituacao = "em Judice" Then 
										'Processa a baixa da NF
										Call BaixaFatura(ldblNumNf, lstrMesAnoFat, lstrZona, lstrLivro, lstrConta, ldtePgto, lstrBaixaPorFatura)
										'
										' ----- Atualiza os consumos
										Call AtualConsumos(lstrZona, lstrLivro, lstrConta, lstrMesAnoFat, ldtePgto, ldblValor)
										'Call AtualizaConsumos(lstrZona, lstrLivro, lstrConta, lstrMesAnoFat, ldblNumNF)
										'
										.set_TextMatrix(llngRow, 10, "Baixada")
									End If
								Else
									If llngUnidId > 0 Then
										Call AtualizaHistoricoUnidade(llngUnidId, lstrGrupo, lstrNmCodRet & " R$ " & ldblValor & " Bco: " & lstrNrBco & " Em: " & ldtePgto)
									End If
								End If
							End If
						End If
					Next llngRow
				End With
				Call GravaRegistroArquivo()
				If MsgBox("Deseja Mover o Arquivo ?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Confirma") = MsgBoxResult.Yes Then
					'UPGRADE_WARNING: Dir has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
					If Dir(txtArq.Text) <> "" Then
						If Me.strTipoServ = "Debitos" Then
							lstrNovoArq = "D" & VB6.Format(istrBanNr, "000") & Replace(Replace(istrDtGer, "-", ""), "/", "") & ".RET"
						Else
							If CDbl(istrBanNr) = 300 Then
								lstrNovoArq = istrArqNome
							Else
								lstrNovoArq = "C" & VB6.Format(istrBanNr, "000") & istrDtGer & ".RET"
							End If
						End If
						'
						'Copiando o arquivo para sub diretorio baixados
						'UPGRADE_WARNING: Dir has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
						lstrCopiaArq = Dir(istrArqDire & "baixados\" & lstrNovoArq)
						'UPGRADE_WARNING: Dir has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
						If Dir(istrArqDire & "baixados\" & lstrNovoArq) = "" Then
							Call FileCopy(txtArq.Text, istrArqDire & "baixados\" & lstrNovoArq)
							If MsgBox("O arquivo " & istrArqNome & " foi gravado na pasta baixados como " & lstrNovoArq & ".Deseja Excluir o Arquivo " & istrArqNome & " ?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Confirma") = MsgBoxResult.Yes Then
								Call Kill(txtArq.Text)
							End If
						Else
							Call MsgBox("Caminho " & istrArqDire & "baixados\" & lstrNovoArq & " não encontrado!", MsgBoxStyle.Information, gstrTituloMensagem)
						End If
					Else
						Call MsgBox("O arquivo não existe mais para mover!", MsgBoxStyle.Information, gstrTituloMensagem)
					End If
				End If
				If MsgBox("Deseja Imprimir a Listagem Geral ?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Confirma") = MsgBoxResult.Yes Then
					Call ImprimeGeral(CDate(IIf(IsDate(Mid(istrDtGer, 7, 2) & "/" & Mid(istrDtGer, 5, 2) & "/" & Mid(istrDtGer, 1, 4)), Mid(istrDtGer, 7, 2) & "/" & Mid(istrDtGer, 5, 2) & "/" & Mid(istrDtGer, 1, 4), "01/01/1900")), iintBanID, CInt(IIf(IsNumeric(istrArqSeq), istrArqSeq, 0)))
				End If
				If Me.strTipoServ = "Guiche" Then
					Call MontaGrade(0)
				Else
					Call MontaGrade(1)
				End If
			End If
		End If
ErrorExec: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
		End If
		Call LigDes(True)
		Me.cmdExec.Enabled = False
	End Sub
	
	Private Sub GravaRegistroArquivo()
		Dim lstrSql As String
		Dim lstrGer As String
		Dim ldteGer As Date
		Dim llngSeq As Integer
		Dim llngSeqReg As Integer
		Dim llngSeqAux As Integer
		Dim llngRow As Integer
		Dim llngReg As Integer
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		
		On Error GoTo ErrorGravaRegistroArquivo
		
		lstrGer = Mid(istrDtGer, 7, 2) & "/" & Mid(istrDtGer, 5, 2) & "/" & Mid(istrDtGer, 1, 4)
		ldteGer = CDate(IIf(IsDate(lstrGer), lstrGer, "01/01/1900"))
		llngSeq = CInt(IIf(IsNumeric(istrArqSeq), istrArqSeq, 0))
		If llngSeq = 0 Then
			llngSeq = CInt(VB6.Format(ldteGer, "yyyymmdd"))
		End If
		lstrSql = ""
		If Me.strTipoServ = "Guiche" Then
			lstrSql = ""
			lstrSql = lstrSql & "DELETE FROM `bxarqbco_arr_itens` "
			lstrSql = lstrSql & " WHERE `banid`      =  " & iintBanID & " "
			lstrSql = lstrSql & "   AND `datarquivo` = '" & VB6.Format(ldteGer, "yyyy-MM-dd") & "' "
			lstrSql = lstrSql & "   AND `seqarquivo` =  " & llngSeq & " "
			Call Executar(lstrSql)
			lstrSql = ""
			lstrSql = lstrSql & "DELETE FROM `bxarqbco_arr` "
			lstrSql = lstrSql & " WHERE `banid`      =  " & iintBanID & " "
			lstrSql = lstrSql & "   AND `datarquivo` = '" & VB6.Format(ldteGer, "yyyy-MM-dd") & "' "
			lstrSql = lstrSql & "   AND `seqarquivo` =  " & llngSeq & " "
			Call Executar(lstrSql)
			lstrSql = ""
			lstrSql = lstrSql & "INSERT INTO `bxarqbco_arr` SET "
			lstrSql = lstrSql & "      `banid`      =  " & iintBanID & ", "
			lstrSql = lstrSql & "      `datarquivo` = '" & VB6.Format(ldteGer, "yyyy-MM-dd") & "', "
			lstrSql = lstrSql & "      `seqarquivo` =  " & llngSeq & ", "
			lstrSql = lstrSql & "      `arquivo`    =  '" & istrArqNome & "', "
			'previstos
			lstrSql = lstrSql & "      `pre_reg`=" & CInt(Me.txtPrReg.Text) & ", "
			lstrSql = lstrSql & "      `pre_vlr`=" & Replace(CStr(CDbl(Me.txtPrVlr.Text)), ",", ".") & ", "
			lstrSql = lstrSql & "      `pre_tax`=" & Replace(CStr(CDbl(Me.txtPrTax.Text)), ",", ".") & ", "
			'recebidos
			lstrSql = lstrSql & "      `rec_reg`=" & CInt(Me.txtReReg.Text) & ", "
			lstrSql = lstrSql & "      `rec_vlr`=" & Replace(CStr(CDbl(Me.txtReVlr.Text)), ",", ".") & ", "
			lstrSql = lstrSql & "      `rec_tax`=" & Replace(CStr(CDbl(Me.txtReTax.Text)), ",", ".") & ", "
			'reserva/judice
			lstrSql = lstrSql & "      `res_reg`=" & CInt(Me.txtResReg.Text) & ", "
			lstrSql = lstrSql & "      `res_vlr`=" & Replace(CStr(CDbl(Me.txtResVlr.Text)), ",", ".") & ", "
			lstrSql = lstrSql & "      `res_tax`=" & Replace(CStr(CDbl(Me.txtResTax.Text)), ",", ".") & ", "
			'duplicidades
			lstrSql = lstrSql & "      `dub_reg`=" & CInt(Me.txtDpReg.Text) & ", "
			lstrSql = lstrSql & "      `dub_vlr`=" & Replace(CStr(CDbl(Me.txtDpVlr.Text)), ",", ".") & ", "
			lstrSql = lstrSql & "      `dub_tax`=" & Replace(CStr(CDbl(Me.txtDpTax.Text)), ",", ".") & ", "
			'efetivos
			lstrSql = lstrSql & "      `efe_reg`=" & CInt(Me.txtEfReg.Text) & ", "
			lstrSql = lstrSql & "      `efe_vlr`=" & Replace(CStr(CDbl(Me.txtEfVlr.Text)), ",", ".") & ", "
			lstrSql = lstrSql & "      `efe_tax`=" & Replace(CStr(CDbl(Me.txtEfTax.Text)), ",", ".") & ", "
			'estado
			lstrSql = lstrSql & "      `est_nec`=" & CInt(Me.txtEsNecon.Text) & ", "
			lstrSql = lstrSql & "      `est_rec`=" & CInt(Me.txtEsReceb.Text) & ", "
			lstrSql = lstrSql & "      `est_dev`=" & CInt(Me.txtEsDevol.Text) & " "
		Else
			lstrSql = ""
			lstrSql = lstrSql & "DELETE FROM `bxarqbco_deb_itens` "
			lstrSql = lstrSql & " WHERE `banid`      =  " & iintBanID & " "
			lstrSql = lstrSql & "   AND `datarquivo` = '" & VB6.Format(ldteGer, "yyyy-MM-dd") & "' "
			lstrSql = lstrSql & "   AND `seqarquivo` =  " & llngSeq & " "
			Call Executar(lstrSql)
			lstrSql = ""
			lstrSql = lstrSql & "DELETE FROM `bxarqbco_deb` "
			lstrSql = lstrSql & " WHERE `banid`      =  " & iintBanID & " "
			lstrSql = lstrSql & "   AND `datarquivo` = '" & VB6.Format(ldteGer, "yyyy-MM-dd") & "' "
			lstrSql = lstrSql & "   AND `seqarquivo` =  " & llngSeq & " "
			Call Executar(lstrSql)
			lstrSql = ""
			lstrSql = lstrSql & "INSERT INTO `bxarqbco_deb` SET "
			lstrSql = lstrSql & "      `banid`      =  " & iintBanID & ", "
			lstrSql = lstrSql & "      `datarquivo` = '" & VB6.Format(ldteGer, "yyyy-MM-dd") & "', "
			lstrSql = lstrSql & "      `seqarquivo` =  " & llngSeq & ", "
			lstrSql = lstrSql & "      `arquivo`    =  '" & istrArqNome & "', "
			'previstos
			lstrSql = lstrSql & "      `pre_reg`=" & CInt(Me.txtPrReg.Text) & ", "
			lstrSql = lstrSql & "      `pre_vlr`=" & Replace(CStr(CDbl(Me.txtPrVlr.Text)), ",", ".") & ", "
			lstrSql = lstrSql & "      `pre_tax`=" & Replace(CStr(CDbl(Me.txtPrTax.Text)), ",", ".") & ", "
			'debitados
			lstrSql = lstrSql & "      `deb_reg`=" & CInt(Me.txtDbReg.Text) & ", "
			lstrSql = lstrSql & "      `deb_vlr`=" & Replace(CStr(CDbl(Me.txtDbVlr.Text)), ",", ".") & ", "
			lstrSql = lstrSql & "      `deb_tax`=" & Replace(CStr(CDbl(Me.txtDbTax.Text)), ",", ".") & ", "
			'não debitados
			lstrSql = lstrSql & "      `ndb_reg`=" & CInt(Me.txtNdReg.Text) & ", "
			lstrSql = lstrSql & "      `ndb_vlr`=" & Replace(CStr(CDbl(Me.txtNdVlr.Text)), ",", ".") & ", "
			lstrSql = lstrSql & "      `ndb_tax`=" & Replace(CStr(CDbl(Me.txtNdTax.Text)), ",", ".") & ", "
			'duplicidades
			lstrSql = lstrSql & "      `dub_reg`=" & CInt(Me.txtDpReg.Text) & ", "
			lstrSql = lstrSql & "      `dub_vlr`=" & Replace(CStr(CDbl(Me.txtDpVlr.Text)), ",", ".") & ", "
			lstrSql = lstrSql & "      `dub_tax`=" & Replace(CStr(CDbl(Me.txtDpTax.Text)), ",", ".") & ", "
			'efetivos
			lstrSql = lstrSql & "      `efe_reg`=" & CInt(Me.txtEfReg.Text) & ", "
			lstrSql = lstrSql & "      `efe_vlr`=" & Replace(CStr(CDbl(Me.txtEfVlr.Text)), ",", ".") & ", "
			lstrSql = lstrSql & "      `efe_tax`=" & Replace(CStr(CDbl(Me.txtEfTax.Text)), ",", ".") & ", "
			'estado
			lstrSql = lstrSql & "      `est_nec`=" & CInt(Me.txtEsNecon.Text) & ", "
			lstrSql = lstrSql & "      `est_rec`=" & CInt(Me.txtEsReceb.Text) & ", "
			lstrSql = lstrSql & "      `est_dev`=" & CInt(Me.txtEsDevol.Text) & " "
		End If
		Call Executar(lstrSql)
		llngSeqReg = 0
		llngSeqAux = 0
		With Me.mfgDados
			For llngRow = 1 To .Rows - 1
				Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, llngRow)
				llngSeqReg = CInt(Trim(.get_TextMatrix(llngRow, 13)))
				If llngSeqReg = 0 Then
					llngSeqAux = llngSeqAux + 1
				Else
					llngSeqAux = llngSeqReg
				End If
				lstrSql = ""
				If Me.strTipoServ = "Guiche" Then
					lstrSql = lstrSql & "INSERT INTO `bxarqbco_arr_itens` SET "
					lstrSql = lstrSql & "  `banid`      =  " & iintBanID & ", "
					lstrSql = lstrSql & "  `datarquivo` = '" & VB6.Format(ldteGer, "yyyy-MM-dd") & "', "
					lstrSql = lstrSql & "  `seqarquivo` =  " & llngSeq & ", "
					lstrSql = lstrSql & "  `seqreg`     =  " & llngSeqAux & ", "
					lstrSql = lstrSql & "  `zona`       = '" & Mid(.get_TextMatrix(llngRow, 0), 1, 3) & "', "
					lstrSql = lstrSql & "  `livro`      = '" & Mid(.get_TextMatrix(llngRow, 0), 5, 2) & "', "
					lstrSql = lstrSql & "  `conta`      = '" & VB.Right(Mid(.get_TextMatrix(llngRow, 0), 8, 7), 6) & "', "
					If InStr(1, .get_TextMatrix(llngRow, 1), "-") > 0 Then
						lstrSql = lstrSql & "  `numnf`      =  " & CDbl(Trim(VB.Left(.get_TextMatrix(llngRow, 1), InStr(1, .get_TextMatrix(llngRow, 1), "-") - 1))) & ", "
						lstrSql = lstrSql & "  `mesano`     = '" & Trim(Mid(.get_TextMatrix(llngRow, 1), InStr(1, .get_TextMatrix(llngRow, 1), "-") + 1)) & "', "
					Else
						lstrSql = lstrSql & "  `numnf`      =  0, "
						lstrSql = lstrSql & "  `mesano`     = '" & Me.txtMesAno.Text & "', "
					End If
					lstrSql = lstrSql & "  `datapgto`   = '" & VB6.Format(CDate(IIf(IsDate(.get_TextMatrix(llngRow, 2)), .get_TextMatrix(llngRow, 2), "01/01/1900")), "yyyy-MM-dd") & "', "
					lstrSql = lstrSql & "  `datacred`   = '" & VB6.Format(CDate(IIf(IsDate(.get_TextMatrix(llngRow, 3)), .get_TextMatrix(llngRow, 3), "01/01/1900")), "yyyy-MM-dd") & "', "
					lstrSql = lstrSql & "  `datavcto`   = '" & VB6.Format(CDate(IIf(IsDate(.get_TextMatrix(llngRow, 4)), .get_TextMatrix(llngRow, 4), "01/01/1900")), "yyyy-MM-dd") & "', "
					lstrSql = lstrSql & "  `recebido`   =  " & Replace(CStr(CDbl(.get_TextMatrix(llngRow, 5))), ",", ".") & ", "
					lstrSql = lstrSql & "  `tarifa`     =  " & Replace(CStr(CDbl(.get_TextMatrix(llngRow, 6))), ",", ".") & ", "
					lstrSql = lstrSql & "  `nrbco`      = '" & Trim(.get_TextMatrix(llngRow, 7)) & "', "
					lstrSql = lstrSql & "  `nrag`       = '" & Trim(.get_TextMatrix(llngRow, 8)) & "', "
					lstrSql = lstrSql & "  `formaarr`   = '" & Trim(.get_TextMatrix(llngRow, 9)) & "', "
					lstrSql = lstrSql & "  `avisos`     = '" & Trim(.get_TextMatrix(llngRow, 10)) & "', "
					lstrSql = lstrSql & "  `grupo`      = '" & Trim(.get_TextMatrix(llngRow, 11)) & "', "
					lstrSql = lstrSql & "  `diferenca`  =  " & Replace(CStr(CDbl(.get_TextMatrix(llngRow, 12))), ",", ".") & ", "
					lstrSql = lstrSql & "  `cons_id`    =  " & CInt(.get_TextMatrix(llngRow, 14)) & ", "
					lstrSql = lstrSql & "  `unid_id`    =  " & CInt(.get_TextMatrix(llngRow, 15)) & " "
				Else
					lstrSql = lstrSql & "INSERT INTO `bxarqbco_deb_itens` SET "
					lstrSql = lstrSql & "  `banid`      =  " & iintBanID & ", "
					lstrSql = lstrSql & "  `datarquivo` = '" & VB6.Format(ldteGer, "yyyy-MM-dd") & "', "
					lstrSql = lstrSql & "  `seqarquivo` =  " & llngSeq & ", "
					lstrSql = lstrSql & "  `seqreg`     =  " & CInt(Trim(.get_TextMatrix(llngRow, 13))) & ", "
					lstrSql = lstrSql & "  `zona`       = '" & Mid(.get_TextMatrix(llngRow, 0), 1, 3) & "', "
					lstrSql = lstrSql & "  `livro`      = '" & Mid(.get_TextMatrix(llngRow, 0), 5, 2) & "', "
					lstrSql = lstrSql & "  `conta`      = '" & VB.Right(Mid(.get_TextMatrix(llngRow, 0), 8, 7), 6) & "', "
					If InStr(1, .get_TextMatrix(llngRow, 1), "-") > 0 Then
						lstrSql = lstrSql & "  `numnf`      = " & CDbl(IIf(InStr(1, .get_TextMatrix(llngRow, 1), "-") > 0, Trim(VB.Left(.get_TextMatrix(llngRow, 1), InStr(1, .get_TextMatrix(llngRow, 1), "-") - 1)), 0)) & ", "
						lstrSql = lstrSql & "  `mesano`     = '" & Trim(Mid(.get_TextMatrix(llngRow, 1), InStr(1, .get_TextMatrix(llngRow, 1), "-") + 1)) & "', "
					Else
						lstrSql = lstrSql & "  `numnf`      = 0, "
						lstrSql = lstrSql & "  `mesano`     = '" & Me.txtMesAno.Text & "', "
					End If
					lstrSql = lstrSql & "  `datadbto`   = '" & VB6.Format(CDate(IIf(IsDate(.get_TextMatrix(llngRow, 2)), .get_TextMatrix(llngRow, 2), "01/01/1900")), "yyyy-MM-dd") & "', "
					lstrSql = lstrSql & "  `datavcto`   = '" & VB6.Format(CDate(IIf(IsDate(.get_TextMatrix(llngRow, 3)), .get_TextMatrix(llngRow, 3), "01/01/1900")), "yyyy-MM-dd") & "', "
					lstrSql = lstrSql & "  `debitado`   =  " & Replace(CStr(CDbl(.get_TextMatrix(llngRow, 4))), ",", ".") & ", "
					lstrSql = lstrSql & "  `tarifa`     =  " & Replace(CStr(CDbl(.get_TextMatrix(llngRow, 5))), ",", ".") & ", "
					lstrSql = lstrSql & "  `nrbco`      = '" & Trim(.get_TextMatrix(llngRow, 6)) & "', "
					lstrSql = lstrSql & "  `nrag`       = '" & Trim(.get_TextMatrix(llngRow, 7)) & "', "
					lstrSql = lstrSql & "  `formadeb`   = '" & Trim(.get_TextMatrix(llngRow, 8)) & "', "
					lstrSql = lstrSql & "  `movimento`  = '" & Trim(.get_TextMatrix(llngRow, 9)) & "', "
					lstrSql = lstrSql & "  `avisos`     = '" & Trim(.get_TextMatrix(llngRow, 10)) & "', "
					lstrSql = lstrSql & "  `grupo`      = '" & Trim(.get_TextMatrix(llngRow, 11)) & "', "
					lstrSql = lstrSql & "  `diferenca`  =  " & Replace(CStr(CDbl(.get_TextMatrix(llngRow, 12))), ",", ".") & ", "
					lstrSql = lstrSql & "  `cons_id`    =  " & CInt(.get_TextMatrix(llngRow, 14)) & ", "
					lstrSql = lstrSql & "  `unid_id`    =  " & CInt(.get_TextMatrix(llngRow, 15)) & " "
				End If
				Call Executar(lstrSql)
				Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
			Next llngRow
		End With
ErrorGravaRegistroArquivo: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
		ElseIf myConC.Errors.Count > 0 Then 
			Call MsgBox("Código: " & myConC.Errors.Item(myConC.Errors.Count - 1).NativeError & vbCrLf & "Descrição:" & myConC.Errors.Item(myConC.Errors.Count - 1).Description)
		End If
	End Sub
	
	Private Sub InsereReserva(ByVal adblNumNf As Double, ByVal astrMesAno As String)
		Dim lstrSql As String
		On Error GoTo ErrorInsereReserva
		'Joga a informacao para a tabela reserva para garantir um historico para saber se este cara realmente
		'esteve na reserva algum dia
		lstrSql = ""
		lstrSql = lstrSql & "INSERT INTO `reserva` (`numnf`, `mesano`, `zona`, `livro`, `conta`, `flgst`, `banarrec`, `datares`, `valortot`, `valorliq`) ("
		lstrSql = lstrSql & "SELECT `numnf`, "
		lstrSql = lstrSql & "       `mesano`, "
		lstrSql = lstrSql & "       `zona`, "
		lstrSql = lstrSql & "       `livro`, "
		lstrSql = lstrSql & "       `conta`, "
		lstrSql = lstrSql & "       `flgst`, "
		lstrSql = lstrSql & "       `banarrec`, "
		lstrSql = lstrSql & "       `datapag`, "
		lstrSql = lstrSql & "       `valortot`, "
		lstrSql = lstrSql & "       `valorliq` "
		lstrSql = lstrSql & "  FROM `nf` "
		lstrSql = lstrSql & " WHERE `numnf`      = " & adblNumNf & " "
		lstrSql = lstrSql & "   AND `mesano_ref` =" & CInt(VB.Right(astrMesAno, 4) & VB.Left(astrMesAno, 2)) & " "
		lstrSql = lstrSql & ")"
		Call Executar(lstrSql)
ErrorInsereReserva: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
		ElseIf myConC.Errors.Count > 0 Then 
			Call MsgBox("Código: " & myConC.Errors.Item(myConC.Errors.Count - 1).NativeError & vbCrLf & "Descrição:" & myConC.Errors.Item(myConC.Errors.Count - 1).Description)
		End If
	End Sub
	
	Private Sub InsereDevolucao(ByVal adblNumNf As Double, ByVal astrMesAno As String, ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String, ByVal alngConsId As Integer, ByVal alngUnidId As Integer, ByVal adtePgto As Date, ByVal adblValor As Double, ByVal adteIni As Date, ByVal adteFim As Date)
		Dim lstrSql As String
		On Error GoTo ErrorInsereDevolucao
		
		lstrSql = ""
		lstrSql = lstrSql & "INSERT INTO `devolucao` SET "
		lstrSql = lstrSql & "            `nf`        = " & adblNumNf & ", "
		lstrSql = lstrSql & "            `mesano`    = '" & astrMesAno & "', "
		lstrSql = lstrSql & "            `dataemis`  = '" & VB6.Format(adtePgto, "yyyy-MM-dd") & "', "
		lstrSql = lstrSql & "            `valor`     =  " & Replace(CStr(adblValor), ",", ".") & ", "
		lstrSql = lstrSql & "            `banarrec`  =  " & iintBanID & ", "
		lstrSql = lstrSql & "            `zona`     = '" & astrZona & "', "
		lstrSql = lstrSql & "            `livro`    = '" & astrLivro & "', "
		lstrSql = lstrSql & "            `conta`    = '" & astrConta & "', "
		lstrSql = lstrSql & "            `pagto`    = '" & VB6.Format(adtePgto, "yyyy-MM-dd") & "', "
		If gstrEmpresa_DevDuplPgtoAuto = "S" Then
			lstrSql = lstrSql & "            `datadevol` = '" & VB6.Format(BuscaDataBD, "yyyy-MM-dd") & "', "
			lstrSql = lstrSql & "            `estado`    = 'D' "
		Else
			lstrSql = lstrSql & "            `datadevol` = '" & "0000-00-00" & "', "
			lstrSql = lstrSql & "            `estado`    = NULL "
		End If
		Call Executar(lstrSql)
		'
		'Insere a devolução na tabela de convênios
		If gstrEmpresa_DevDuplPgtoAuto = "S" Then
			lstrSql = ""
			lstrSql = lstrSql & "INSERT INTO `convenios` SET "
			lstrSql = lstrSql & "            `zona`     = '" & astrZona & "', "
			lstrSql = lstrSql & "            `livro`    = '" & astrLivro & "', "
			lstrSql = lstrSql & "            `conta`    = '" & astrConta & "', "
			lstrSql = lstrSql & "            `cons_id`  =  " & alngConsId & ", "
			lstrSql = lstrSql & "            `unid_id`  =  " & alngUnidId & ", "
			lstrSql = lstrSql & "            `convenio` = '9070000082', "
			lstrSql = lstrSql & "            `sit` = 'Novo', "
			lstrSql = lstrSql & "            `dt_cadastro` = '" & VB6.Format(BuscaDataBD, "yyyy-MM-dd") & "', "
			lstrSql = lstrSql & "            `valor`    = " & Replace(CStr(adblValor), ",", ".") & ", "
			lstrSql = lstrSql & "            `dt_ini`   = '" & VB6.Format(adteIni, "yyyy-MM-dd") & "', "
			lstrSql = lstrSql & "            `dt_fim`   = '" & VB6.Format(adteFim, "yyyy-MM-dd") & "', "
			lstrSql = lstrSql & "            `ref`      = '" & "Fatura " & adblNumNf & " " & astrMesAno & "' "
			Call Executar(lstrSql)
		End If
ErrorInsereDevolucao: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
		ElseIf myConC.Errors.Count > 0 Then 
			Call MsgBox("Código: " & myConC.Errors.Item(myConC.Errors.Count - 1).NativeError & vbCrLf & "Descrição:" & myConC.Errors.Item(myConC.Errors.Count - 1).Description)
		End If
	End Sub
	
	Private Function ValidaDevolucao(ByVal adblNumNf As Double, ByVal astrMesAno As String) As Boolean
		Dim lblnRet As Boolean
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		'
		On Error GoTo ErrorValidaDevolucao
		'
		lblnRet = False
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM `devolucao` "
		lstrSql = lstrSql & " WHERE `nf` = " & adblNumNf & " "
		lstrSql = lstrSql & "   AND `mesano` = '" & astrMesAno & "'"
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				lblnRet = (.RecordCount > 0)
				Call .Close()
			End If
		End With
		ValidaDevolucao = lblnRet
ErrorValidaDevolucao: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
		End If
	End Function
	
	Private Sub BaixaFatura(ByVal adblNumNf As Double, ByVal astrMesAno As String, ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String, ByVal adtePgto As Date, ByVal astrBaixaPorFatura As String)
		Dim lstrSql As String
		On Error GoTo ErrorBaixaFatura
		lstrSql = ""
		lstrSql = lstrSql & "UPDATE `nf` "
		lstrSql = lstrSql & "   SET `flgst`      = 'P', "
		lstrSql = lstrSql & "       `datapag`    = '" & VB6.Format(adtePgto, "yyyy-MM-dd") & "', "
		lstrSql = lstrSql & "       `banarrec`   = '" & iintBanID & "', "
		lstrSql = lstrSql & "       `banident`   = '" & istrBanNm & "' "
		lstrSql = lstrSql & " WHERE `numnf`      =  " & adblNumNf
		lstrSql = lstrSql & "   AND `mesano_ref` =  " & CInt(VB.Right(astrMesAno, 4) & VB.Left(astrMesAno, 2)) & " "
		If astrBaixaPorFatura <> "S" Then
			lstrSql = lstrSql & "   AND `zona`       = '" & astrZona & "' "
			lstrSql = lstrSql & "   AND `livro`      = '" & astrLivro & "' "
			lstrSql = lstrSql & "   AND `conta`      = '" & astrConta & "' "
		End If
		Call Executar(lstrSql)
		'
		'Atualiza NF´s que estavam na lista de corte e/ou cortadas
		lstrSql = ""
		lstrSql = lstrSql & "UPDATE `concorte` "
		lstrSql = lstrSql & "   SET `sit`     = 'P', "
		lstrSql = lstrSql & "       `datapag` = '" & VB6.Format(adtePgto, "yyyy-MM-dd") & "' "
		lstrSql = lstrSql & " WHERE `numnf`   =  " & adblNumNf & " "
		lstrSql = lstrSql & "   AND `mesano`  = '" & astrMesAno & "' "
		If astrBaixaPorFatura <> "S" Then
			lstrSql = lstrSql & "   AND `zona`    = '" & astrZona & "' "
			lstrSql = lstrSql & "   AND `livro`   = '" & astrLivro & "' "
			lstrSql = lstrSql & "   AND `conta`   = '" & astrConta & "' "
		End If
		Call Executar(lstrSql)
		'
ErrorBaixaFatura: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
		ElseIf myConC.Errors.Count > 0 Then 
			Call MsgBox("Código: " & myConC.Errors.Item(myConC.Errors.Count - 1).NativeError & vbCrLf & "Descrição:" & myConC.Errors.Item(myConC.Errors.Count - 1).Description)
		End If
	End Sub
	
	Private Sub cmdProcura_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdProcura.Click
		On Error GoTo ErrocmdProcura
		'UPGRADE_WARNING: CommonDialog variable was not upgraded Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="671167DC-EA81-475D-B690-7A40C7BF4A23"'
		With Me.dialArq
			Call .ShowDialog()
			Me.txtArq.Text = .FileName
			'UPGRADE_WARNING: CommonDialog property Me.dialArq.FileTitle was upgraded to Me.dialArq.FileName which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'
			istrArqNome = (New System.IO.DirectoryInfo(.FileName)).Name
			If Len(Trim(Me.txtArq.Text)) > 0 Then
				istrArqDire = VB.Left(Me.txtArq.Text, InStr(1, Me.txtArq.Text, istrArqNome) - 1)
			Else
				istrArqDire = ""
			End If
		End With
ErrocmdProcura: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
		End If
	End Sub
	
	Private Sub frmRecArq_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.Escape Then
			Call Me.Close()
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
	
	Private Function zeraFrames() As Object
		'fmeDebitado
		Me.txtDbReg.Text = CStr(0)
		Me.txtDbVlr.Text = "0,00"
		Me.txtDbTax.Text = "0,00"
		
		'fmeNaoDebitado
		Me.txtNdReg.Text = CStr(0)
		Me.txtNdVlr.Text = "0,00"
		Me.txtNdTax.Text = "0,00"
		
		'fmeEfetivo
		Me.txtEfReg.Text = CStr(0)
		Me.txtEfVlr.Text = "0,00"
		Me.txtEfTax.Text = "0,00"
		
		'fmeEstado
		Me.txtEsDevol.Text = CStr(0)
		Me.txtEsNecon.Text = CStr(0)
		Me.txtEsReceb.Text = CStr(0)
		Me.txtEsDif.Text = CStr(0)
		
		'fmeRecebido
		Me.txtReReg.Text = CStr(0)
		Me.txtReTax.Text = "0,00"
		Me.txtReVlr.Text = "0,00"
		
		'fmeDuplicidade
		Me.txtDpReg.Text = CStr(0)
		Me.txtDpTax.Text = "0,00"
		Me.txtDpVlr.Text = "0,00"
		
		'fmeReserva
		Me.txtResReg.Text = CStr(0)
		Me.txtResVlr.Text = "0,00"
		Me.txtResTax.Text = "0,00"
		
		If Me.strTipoServ = "Debitos" Then
			Call MontaGrade(1)
		Else
			Call MontaGrade(0)
		End If
	End Function
	
	Private Sub mfgDados_DblClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mfgDados.DblClick
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim ldblValor As Double
		Dim lstrMesAno As String
		Dim lstrTexto As String
		Dim ldblNumNf As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		
		On Error GoTo ErrormfgDados
		If Me.mfgDados.Rows > 1 Then
			With Me.fmeAguarde
				.Top = VB6.TwipsToPixelsY(2595)
				.Visible = True
			End With
			Me.lblAviso.Text = " Aguarde buscando fatura do consumidor...."
			Me.lblAviso.Refresh()
			System.Windows.Forms.Application.DoEvents()
			With Me.mfgDados
				If Me.strTipoServ = "Debitos" Then
					ldblNumNf = VB.Left(.get_TextMatrix(.RowSel, 1), 9)
					lstrMesAno = ""
					lstrMesAno = VB.Right(.get_TextMatrix(.RowSel, 1), 7)
					ldblValor = CDbl(.get_TextMatrix(.RowSel, 4))
				Else
					If InStr(1, .get_TextMatrix(.RowSel, 1), "-") > 0 Then
						ldblNumNf = CStr(CDbl(Replace(Mid(.get_TextMatrix(.RowSel, 1), 1, InStr(.get_TextMatrix(.RowSel, 1), "-") - 1), " ", "")))
						lstrMesAno = Trim(Mid(.get_TextMatrix(.RowSel, 1), InStr(.get_TextMatrix(.RowSel, 1), "-") + 1))
					Else
						ldblNumNf = CStr(0)
						lstrMesAno = Me.txtMesAno.Text
					End If
					ldblValor = CDbl(.get_TextMatrix(.RowSel, 5))
				End If
			End With
			lstrTexto = ""
			lstrSql = ""
			lstrSql = lstrSql & "SELECT zona, "
			lstrSql = lstrSql & "       livro, "
			lstrSql = lstrSql & "       conta, "
			lstrSql = lstrSql & "       numnf, "
			lstrSql = lstrSql & "       mesano_ref, "
			lstrSql = lstrSql & "       valortot, "
			lstrSql = lstrSql & "       valorliq "
			lstrSql = lstrSql & "  FROM " & istrTabNf & " "
			lstrSql = lstrSql & " WHERE mesano_ref = " & CInt(VB.Right(lstrMesAno, 4) & VB.Left(lstrMesAno, 2)) & " "
			lstrSql = lstrSql & "   AND numnf  = " & ldblNumNf & " "
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 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"'
						lstrZona = Trim(IIf(IsDbNull(.Fields("zona").value), "", .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"'
						lstrLivro = Trim(IIf(IsDbNull(.Fields("livro").value), "", .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"'
						lstrConta = Trim(IIf(IsDbNull(.Fields("conta").value), "", .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"'
						ldblNumNf = CStr(CDbl(IIf(IsDbNull(.Fields("numnf").value), 0, .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"'
						ldblValor = CDbl(IIf(IsDbNull(.Fields("valorliq").value), 0, .Fields("valorliq").value))
						If ldblValor = 0 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"'
							ldblValor = CDbl(IIf(IsDbNull(.Fields("valortot").value), 0, .Fields("valortot").value))
						End If
						lstrTexto = "U.C.: " & lstrZona & "." & lstrLivro & "." & lstrConta & vbCrLf
						lstrTexto = lstrTexto & "Fatura: " & ldblNumNf & " Mes/Ano: " & lstrMesAno
					End If
					Call .Close()
				End If
			End With
			System.Windows.Forms.Application.DoEvents()
			If lstrTexto = "" Then
				lstrSql = ""
				lstrSql = lstrSql & "SELECT zona, "
				lstrSql = lstrSql & "       livro, "
				lstrSql = lstrSql & "       conta, "
				lstrSql = lstrSql & "       numnf, "
				lstrSql = lstrSql & "       mesano_ref, "
				lstrSql = lstrSql & "       valortot, "
				lstrSql = lstrSql & "       valorliq "
				lstrSql = lstrSql & "  FROM " & istrTabNf & " "
				lstrSql = lstrSql & " WHERE flgst = '' "
				lstrSql = lstrSql & "   AND (valortot = " & Replace(CStr(ldblValor), ",", ".") & " OR "
				lstrSql = lstrSql & "        valorliq = " & Replace(CStr(ldblValor), ",", ".") & ") "
				Call Conectar(lstrSql, lrstAux)
				With lrstAux
					If .State = ADODB.ObjectStateEnum.adStateOpen Then
						If .RecordCount > 0 Then
							lstrTexto = "Possíveis faturas em aberto com o valor " & VB6.Format(ldblValor, "Standard") & vbCrLf
							While Not .EOF
								lstrTexto = lstrTexto & vbCrLf
								'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"'
								lstrZona = Trim(IIf(IsDbNull(.Fields("zona").value), "", .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"'
								lstrLivro = Trim(IIf(IsDbNull(.Fields("livro").value), "", .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"'
								lstrConta = Trim(IIf(IsDbNull(.Fields("conta").value), "", .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"'
								ldblNumNf = CStr(CDbl(IIf(IsDbNull(.Fields("numnf").value), 0, .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"'
								lstrMesAno = Trim(IIf(IsDbNull(.Fields("mesano_ref").value), "", .Fields("mesano_ref").value))
								lstrMesAno = VB.Right(lstrMesAno, 2) & "/" & VB.Left(lstrMesAno, 4)
								lstrTexto = lstrTexto & "U.C.: " & lstrZona & "." & lstrLivro & "." & lstrConta & " Fat.: " & ldblNumNf & " - " & lstrMesAno
								Call .MoveNext()
							End While
						End If
						Call .Close()
					End If
				End With
			End If
			System.Windows.Forms.Application.DoEvents()
			With Me.fmeAguarde
				.Top = VB6.TwipsToPixelsY(2595)
				.Visible = False
			End With
			System.Windows.Forms.Application.DoEvents()
			If lstrTexto <> "" Then
				Call MsgBox(lstrTexto, MsgBoxStyle.Information, gstrTituloMensagem)
			Else
				Call MsgBox("NF não encontrada: " & Str(CDbl(ldblNumNf)) & " - " & lstrMesAno)
			End If
		End If
ErrormfgDados: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
		End If
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
	End Sub
	
	Private Sub ImprimeGeral(ByVal adteGeracao As Date, ByVal aintBanId As Short, ByVal alngSeqArq As Integer)
		'Nome do Arquivo
		Dim lstrNomArq As String
		'Previstos
		Dim llngPreReg As Integer
		Dim ldblPreVlr As Double
		Dim ldblPreTax As Double
		Dim ldblPreDif As Double
		'Recebitos
		Dim llngRecReg As Integer
		Dim ldblRecVlr As Double
		Dim ldblRecTax As Double
		'Reserva/Judice
		Dim llngResReg As Integer
		Dim ldblResVlr As Double
		Dim ldblResTax As Double
		'Debitados
		Dim llngDebReg As Integer
		Dim ldblDebVlr As Double
		Dim ldblDebTax As Double
		'Não Debitados
		Dim llngNDbReg As Integer
		Dim ldblNDbVlr As Double
		Dim ldblNDbTax As Double
		'Duplicidades
		Dim llngDupReg As Integer
		Dim ldblDupVlr As Double
		Dim ldblDupTax As Double
		'Efetivos
		Dim llngEfeReg As Integer
		Dim ldblEfeVlr As Double
		Dim ldblEfeTax As Double
		'Estado
		Dim llngEstNEc As Integer
		Dim llngEstRec As Integer
		Dim llngEstDev As Integer
		Dim llngEstDif As Integer
		'Itens
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim ldblNumNf As Double
		Dim lstrMesAno As String
		Dim ldtePagto As Date
		Dim ldteCredi As Date
		Dim ldteVecto As Date
		Dim ldteDebit As Date
		Dim ldblVlrDeb As Double
		Dim ldblVlrRec As Double
		Dim ldblVlrTax As Double
		Dim lstrNrBco As String
		Dim lstrNrAge As String
		Dim lstrTxtDeb As String
		Dim lstrTxtMov As String
		Dim lstrTxtArr As String
		Dim lstrTxtAvi As String
		Dim lstrGrupo As String
		Dim ldblVlrDif As Double
		Dim llngUnidId As Integer
		Dim llngConsId As Integer
		'Controle de query
		Dim lintAux As Short
		Dim lstrTab As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		Dim lrstIte As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lrstIte = New ADODB.Recordset
		
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		If Me.strTipoServ = "Guiche" Then
			lstrSql = lstrSql & "  FROM `bxarqbco_arr` "
		Else
			lstrSql = lstrSql & "  FROM `bxarqbco_deb` "
		End If
		lstrSql = lstrSql & " WHERE `banid`      =  " & aintBanId & " "
		lstrSql = lstrSql & "   AND `datarquivo` = '" & VB6.Format(adteGeracao, "yyyy-MM-dd") & "' "
		lstrSql = lstrSql & "   AND `seqarquivo` =  " & alngSeqArq & " "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					'Nome do Arquivo
					'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"'
					lstrNomArq = Trim(IIf(IsDbNull(.Fields("arquivo").value), "", .Fields("arquivo").value))
					'Previstos
					'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"'
					llngPreReg = CInt(IIf(IsDbNull(.Fields("pre_reg").value), 0, .Fields("pre_reg").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"'
					ldblPreVlr = CDbl(IIf(IsDbNull(.Fields("pre_vlr").value), 0, .Fields("pre_vlr").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"'
					ldblPreTax = CDbl(IIf(IsDbNull(.Fields("pre_tax").value), 0, .Fields("pre_tax").value))
					If Me.strTipoServ = "Guiche" Then
						'Recebitos
						'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"'
						llngRecReg = CInt(IIf(IsDbNull(.Fields("rec_reg").value), 0, .Fields("rec_reg").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"'
						ldblRecVlr = CDbl(IIf(IsDbNull(.Fields("rec_vlr").value), 0, .Fields("rec_vlr").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"'
						ldblRecTax = CDbl(IIf(IsDbNull(.Fields("rec_tax").value), 0, .Fields("rec_tax").value))
						'Reserva/Judice
						'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"'
						llngResReg = CInt(IIf(IsDbNull(.Fields("res_reg").value), 0, .Fields("res_reg").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"'
						ldblResVlr = CDbl(IIf(IsDbNull(.Fields("res_vlr").value), 0, .Fields("res_vlr").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"'
						ldblResTax = CDbl(IIf(IsDbNull(.Fields("res_tax").value), 0, .Fields("res_tax").value))
						istrTitulo1 = "Recebimentos diretos (" & istrBanNm & ")"
						istrTitulo2 = IIf(CInt(Len(Trim(istrArqNome))) > 0, istrArqNome, lstrNomArq) & " - " & adteGeracao
					Else
						'Debitados
						'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"'
						llngDebReg = CInt(IIf(IsDbNull(.Fields("deb_reg").value), 0, .Fields("deb_reg").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"'
						ldblDebVlr = CDbl(IIf(IsDbNull(.Fields("deb_vlr").value), 0, .Fields("deb_vlr").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"'
						ldblDebTax = CDbl(IIf(IsDbNull(.Fields("deb_tax").value), 0, .Fields("deb_tax").value))
						'Não Debitados
						'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"'
						llngNDbReg = CInt(IIf(IsDbNull(.Fields("ndb_reg").value), 0, .Fields("ndb_reg").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"'
						ldblNDbVlr = CDbl(IIf(IsDbNull(.Fields("ndb_vlr").value), 0, .Fields("ndb_vlr").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"'
						ldblNDbTax = CDbl(IIf(IsDbNull(.Fields("ndb_tax").value), 0, .Fields("ndb_tax").value))
						istrTitulo1 = "Recebimentos de Debitados em CC (" & istrBanNm & ")"
						istrTitulo2 = IIf(CInt(Len(Trim(istrArqNome))) > 0, istrArqNome, lstrNomArq) & " - " & adteGeracao
					End If
					'Duplicidades
					'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"'
					llngDupReg = CInt(IIf(IsDbNull(.Fields("dub_reg").value), 0, .Fields("dub_reg").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"'
					ldblDupVlr = CDbl(IIf(IsDbNull(.Fields("dub_vlr").value), 0, .Fields("dub_vlr").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"'
					ldblDupTax = CDbl(IIf(IsDbNull(.Fields("dub_tax").value), 0, .Fields("dub_tax").value))
					'Efetivos
					'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"'
					llngEfeReg = CInt(IIf(IsDbNull(.Fields("efe_reg").value), 0, .Fields("efe_reg").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"'
					ldblEfeVlr = CDbl(IIf(IsDbNull(.Fields("efe_vlr").value), 0, .Fields("efe_vlr").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"'
					ldblEfeTax = CDbl(IIf(IsDbNull(.Fields("efe_tax").value), 0, .Fields("efe_tax").value))
					'Estado
					'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"'
					llngEstNEc = CInt(IIf(IsDbNull(.Fields("est_nec").value), 0, .Fields("est_nec").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"'
					llngEstRec = CInt(IIf(IsDbNull(.Fields("est_rec").value), 0, .Fields("est_rec").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"'
					llngEstDev = CInt(IIf(IsDbNull(.Fields("est_dev").value), 0, .Fields("est_dev").value))
					'
					'Abre a vizualização do relatório
					With ifrmRelRecArq
						.quem_chama = Me
						.VS.Font = VB6.FontChangeName(.VS.Font, "Arial")
						.VS.Font = VB6.FontChangeSize(.VS.Font, 5)
						.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
						.VS.PageBorder = VSVIEW6.TableBorderSettings.tbNone
						.VS.Orientation = VSVIEW6.OrientationSettings.orLandscape
						.VS.PhysicalPage = True
						.VS.PaperSize = VSVIEW6.PaperSizeSettings.pprA4
						.VS.MarginTop = "7mm"
						.VS.MarginRight = "7mm"
						.VS.MarginLeft = "7mm"
						.VS.MarginBottom = "5mm"
						.VS.TextColor = System.Drawing.Color.Black
						.VS.BrushStyle = VSVIEW6.BrushStyleSettings.bsSolid
						.VS.MarginFooter = "0mm"
						.VS.MarginHeader = "0mm"
						.VS.Font = VB6.FontChangeBold(.VS.Font, False)
						Call .VS.StartDoc()
					End With
					lstrSql = ""
					lstrSql = lstrSql & "SELECT * "
					If Me.strTipoServ = "Guiche" Then
						lstrSql = lstrSql & "  FROM `bxarqbco_arr_itens` "
					Else
						lstrSql = lstrSql & "  FROM `bxarqbco_deb_itens` "
					End If
					lstrSql = lstrSql & " WHERE `banid`      =  " & aintBanId & " "
					lstrSql = lstrSql & "   AND `datarquivo` = '" & VB6.Format(adteGeracao, "yyyy-MM-dd") & "' "
					lstrSql = lstrSql & "   AND `seqarquivo` =  " & alngSeqArq & " "
					'lstrSql = lstrSql & "   AND `arquivo`    = '" & lstrNomArq & "' "
					lstrSql = lstrSql & "ORDER BY `seqreg` ASC"
					Call Conectar(lstrSql, lrstIte)
					With lrstIte
						If .State = ADODB.ObjectStateEnum.adStateOpen Then
							If .RecordCount > 0 Then
								While Not .EOF
									'Itens
									'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"'
									lstrZona = Trim(IIf(IsDbNull(.Fields("zona").value), "", .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"'
									lstrLivro = Trim(IIf(IsDbNull(.Fields("livro").value), "", .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"'
									lstrConta = Trim(IIf(IsDbNull(.Fields("conta").value), "", .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"'
									ldblNumNf = CDbl(IIf(IsDbNull(.Fields("numnf").value), 0, .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"'
									lstrMesAno = Trim(IIf(IsDbNull(.Fields("mesano").value), "", .Fields("mesano").value))
									If strTipoServ = "Guiche" 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"'
										ldtePagto = CDate(IIf(IsDbNull(.Fields("datapgto").value), "1900-01-01", .Fields("datapgto").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"'
										ldteCredi = CDate(IIf(IsDbNull(.Fields("datacred").value), "1900-01-01", .Fields("datacred").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"'
										ldblVlrRec = CDbl(IIf(IsDbNull(.Fields("recebido").value), 0, .Fields("recebido").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"'
										lstrTxtArr = Trim(IIf(IsDbNull(.Fields("formaarr").value), "", .Fields("formaarr").value))
									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"'
										ldteDebit = CDate(IIf(IsDbNull(.Fields("datadbto").value), "1900-01-01", .Fields("datadbto").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"'
										ldblVlrDeb = CDbl(IIf(IsDbNull(.Fields("debitado").value), 0, .Fields("debitado").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"'
										lstrTxtDeb = Trim(IIf(IsDbNull(.Fields("formadeb").value), "", .Fields("formadeb").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"'
										lstrTxtMov = Trim(IIf(IsDbNull(.Fields("movimento").value), "", .Fields("movimento").value))
									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"'
									ldteVecto = CDate(IIf(IsDbNull(.Fields("datavcto").value), "1900-01-01", .Fields("datavcto").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"'
									ldblVlrTax = CDbl(IIf(IsDbNull(.Fields("tarifa").value), 0, .Fields("tarifa").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"'
									lstrNrBco = Trim(IIf(IsDbNull(.Fields("nrbco").value), "", .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"'
									lstrNrAge = Trim(IIf(IsDbNull(.Fields("nrag").value), "", .Fields("nrag").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"'
									lstrTxtAvi = Trim(IIf(IsDbNull(.Fields("avisos").value), "", .Fields("avisos").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"'
									lstrGrupo = Trim(IIf(IsDbNull(.Fields("grupo").value), "", .Fields("grupo").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"'
									ldblVlrDif = CDbl(IIf(IsDbNull(.Fields("diferenca").value), 0, .Fields("diferenca").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"'
									llngUnidId = CInt(IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").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"'
									llngConsId = CInt(IIf(IsDbNull(.Fields("cons_id").value), 0, .Fields("cons_id").value))
									lstrTab = ""
									lstrTab = lstrTab & lstrZona & "." & lstrLivro & "." & lstrConta & "|"
									lstrTab = lstrTab & VB6.Format(Str(ldblNumNf), "000000000") & "|"
									lstrTab = lstrTab & lstrMesAno & "|"
									If strTipoServ = "Guiche" Then
										lstrTab = lstrTab & ldtePagto & "|"
										lstrTab = lstrTab & VB6.Format(ldblVlrRec, "Standard") & "|"
										lstrTab = lstrTab & VB6.Format(ldblVlrTax, "Standard") & "|"
										lstrTab = lstrTab & lstrNrBco & "|"
										lstrTab = lstrTab & lstrNrAge & "|"
										lstrTab = lstrTab & lstrTxtArr & "|"
										lstrTab = lstrTab & ldteVecto & "|"
										lstrTab = lstrTab & ldteCredi & "|"
									Else
										lstrTab = lstrTab & ldteDebit & "|"
										lstrTab = lstrTab & VB6.Format(ldblVlrDeb, "Standard") & "|"
										lstrTab = lstrTab & VB6.Format(ldblVlrTax, "Standard") & "|"
										lstrTab = lstrTab & lstrNrBco & "|"
										lstrTab = lstrTab & lstrNrAge & "|"
										lstrTab = lstrTab & lstrTxtDeb & "|"
										lstrTab = lstrTab & lstrTxtMov & "|"
									End If
									lstrTab = lstrTab & lstrTxtAvi
									If ldblVlrDif <> 0 Then
										lstrTab = lstrTab & " - Com diferença (" & VB6.Format(ldblVlrDif, "#,##0.00") & ")"
									End If
									ifrmRelRecArq.VS.Table = istrTamCab & lstrTab
									Call .MoveNext()
								End While
							End If
							Call .Close()
						End If
					End With
					
					With ifrmRelRecArq.VS
						If .CurrentLine > 836 Then .NewPage()
						.MarginLeft = "10mm"
						.StartTable()
						'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						.let_TableCell(VSVIEW6.TableCellSettings.tcCols,  ,  ,  ,  , 6)
						'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						.let_TableCell(VSVIEW6.TableCellSettings.tcRows,  ,  ,  ,  , 4)
						.TableBorder = VSVIEW6.TableBorderSettings.tbAll
						'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						.let_TableCell(VSVIEW6.TableCellSettings.tcColWidth,  , 1,  ,  , "20mm")
						'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						.let_TableCell(VSVIEW6.TableCellSettings.tcAlign,  , 1,  ,  , VSVIEW6.TextAlignSettings.taCenterMiddle)
						For lintAux = 2 To 6
							'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							.let_TableCell(VSVIEW6.TableCellSettings.tcColWidth,  , lintAux,  ,  , "48mm")
							'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							.let_TableCell(VSVIEW6.TableCellSettings.tcAlign,  , lintAux,  ,  , VSVIEW6.TextAlignSettings.taCenterMiddle)
						Next lintAux
						For lintAux = 1 To 6
							'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							.let_TableCell(VSVIEW6.TableCellSettings.tcBackColor, 1, lintAux,  ,  , &H8000000F)
							'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							.let_TableCell(VSVIEW6.TableCellSettings.tcFontBold, 1, lintAux,  ,  , True)
						Next 
						For lintAux = 1 To 4
							'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							.let_TableCell(VSVIEW6.TableCellSettings.tcBackColor, lintAux, 1,  ,  , &H8000000F)
							'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							.let_TableCell(VSVIEW6.TableCellSettings.tcFontBold, lintAux, 1,  ,  , True)
						Next 
						'Linha 1
						'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						.let_TableCell(VSVIEW6.TableCellSettings.tcText, 1, 1,  ,  , "")
						'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						.let_TableCell(VSVIEW6.TableCellSettings.tcText, 1, 2,  ,  , "PREVISTOS")
						If strTipoServ = "Guiche" Then
							'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							.let_TableCell(VSVIEW6.TableCellSettings.tcText, 1, 3,  ,  , "RECEBIMENTOS")
						Else
							'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							.let_TableCell(VSVIEW6.TableCellSettings.tcText, 1, 3,  ,  , "DEBITADOS")
						End If
						If strTipoServ = "Guiche" Then
							'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							.let_TableCell(VSVIEW6.TableCellSettings.tcText, 1, 4,  ,  , "EM RESERVA/JUDICE")
						Else
							'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							.let_TableCell(VSVIEW6.TableCellSettings.tcText, 1, 4,  ,  , "NÃO DEBITADOS")
						End If
						'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						.let_TableCell(VSVIEW6.TableCellSettings.tcText, 1, 5,  ,  , "DUPLICIDADES")
						'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						.let_TableCell(VSVIEW6.TableCellSettings.tcText, 1, 6,  ,  , "EFETIVOS")
						'
						'Linha 2
						'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						.let_TableCell(VSVIEW6.TableCellSettings.tcText, 2, 1,  ,  , "Registros")
						'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						.let_TableCell(VSVIEW6.TableCellSettings.tcText, 2, 2,  ,  , FormatNumber(llngPreReg, 0))
						If strTipoServ = "Guiche" Then
							'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							.let_TableCell(VSVIEW6.TableCellSettings.tcText, 2, 3,  ,  , FormatNumber(llngRecReg, 0))
							'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							.let_TableCell(VSVIEW6.TableCellSettings.tcText, 2, 4,  ,  , FormatNumber(llngResReg, 0))
						Else
							'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							.let_TableCell(VSVIEW6.TableCellSettings.tcText, 2, 3,  ,  , FormatNumber(llngDebReg, 0))
							'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							.let_TableCell(VSVIEW6.TableCellSettings.tcText, 2, 4,  ,  , FormatNumber(llngNDbReg, 0))
						End If
						'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						.let_TableCell(VSVIEW6.TableCellSettings.tcText, 2, 5,  ,  , FormatNumber(llngDupReg, 0))
						'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						.let_TableCell(VSVIEW6.TableCellSettings.tcText, 2, 6,  ,  , FormatNumber(llngEfeReg, 0))
						'
						'Linha 3
						'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						.let_TableCell(VSVIEW6.TableCellSettings.tcText, 3, 1,  ,  , "TOTAL")
						'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						.let_TableCell(VSVIEW6.TableCellSettings.tcText, 3, 2,  ,  , VB6.Format(ldblPreVlr, "Standard"))
						If strTipoServ = "Guiche" Then
							'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							.let_TableCell(VSVIEW6.TableCellSettings.tcText, 3, 3,  ,  , VB6.Format(ldblRecVlr, "Standard"))
							'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							.let_TableCell(VSVIEW6.TableCellSettings.tcText, 3, 4,  ,  , VB6.Format(ldblResVlr, "Standard"))
						Else
							'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							.let_TableCell(VSVIEW6.TableCellSettings.tcText, 3, 3,  ,  , VB6.Format(ldblDebVlr, "Standard"))
							'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							.let_TableCell(VSVIEW6.TableCellSettings.tcText, 3, 4,  ,  , VB6.Format(ldblNDbVlr, "Standard"))
						End If
						'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						.let_TableCell(VSVIEW6.TableCellSettings.tcText, 3, 5,  ,  , VB6.Format(ldblDupVlr, "Standard"))
						'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						.let_TableCell(VSVIEW6.TableCellSettings.tcText, 3, 6,  ,  , VB6.Format(ldblEfeVlr, "Standard"))
						'
						'Linha 4
						'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						.let_TableCell(VSVIEW6.TableCellSettings.tcText, 4, 1,  ,  , "TAXAS")
						'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						.let_TableCell(VSVIEW6.TableCellSettings.tcText, 4, 2,  ,  , VB6.Format(ldblPreTax, "Standard"))
						If strTipoServ = "Guiche" Then
							'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							.let_TableCell(VSVIEW6.TableCellSettings.tcText, 4, 3,  ,  , VB6.Format(ldblRecTax, "Standard"))
							'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							.let_TableCell(VSVIEW6.TableCellSettings.tcText, 4, 4,  ,  , VB6.Format(ldblResTax, "Standard"))
						Else
							'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							.let_TableCell(VSVIEW6.TableCellSettings.tcText, 4, 3,  ,  , VB6.Format(ldblDebTax, "Standard"))
							'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							.let_TableCell(VSVIEW6.TableCellSettings.tcText, 4, 4,  ,  , VB6.Format(ldblNDbTax, "Standard"))
						End If
						'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						.let_TableCell(VSVIEW6.TableCellSettings.tcText, 4, 5,  ,  , VB6.Format(ldblDupTax, "Standard"))
						'UPGRADE_WARNING: Couldn't resolve default property of object ifrmRelRecArq.VS.TableCell(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						.let_TableCell(VSVIEW6.TableCellSettings.tcText, 4, 6,  ,  , VB6.Format(ldblEfeTax, "Standard"))
						Call .EndTable()
						.MarginLeft = "7mm"
					End With
					With ifrmRelRecArq
						Call .VS.EndDoc()
						Call .Show()
						Call .VS.KillDoc()
					End With
				End If
				Call .Close()
			End If
		End With
		Call LigDes(True)
	End Sub
	
	Public Sub CabecaRel()
		With ifrmRelRecArq
			.VS.CurrentLine = 1
			Call Cabecalho_Relatorio(.VS, "Recebimentos automáticos", istrTitulo1, CStr(3), False, istrTitulo2)
			Call LineFeed(.VS, 2)
			.VS.Font = VB6.FontChangeBold(.VS.Font, True)
			If Me.strTipoServ = "Guiche" Then
				istrTamCab = "^19mm|^15mm |<13mm  |<15mm |>18mm |>16mm|^8mm |<10mm  |<75mm    |<20mm    |<20mm    |<35mm;"
				.VS.Table = istrTamCab & "ZLC    |Fatura|Mês/Ano|Data Pgto|Valor|Tarifa|Bco  |Ag.    |Forma de Arrecadação|Data Vcto|Data Cred|Avisos"
			Else
				istrTamCab = "^19mm|^15mm |<13mm  |<15mm |>18mm |>16mm|^8mm |<10mm  |<95mm    |<20mm    |<35mm;"
				.VS.Table = istrTamCab & "ZLC    |Fatura|Mês/Ano|Débito|Valor|Tarifa|Bco  |Ag.    |Resultado|Movimento|Avisos"
			End If
			.VS.Font = VB6.FontChangeBold(.VS.Font, False)
		End With
	End Sub
	
	Private Sub cmdImpGeral_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdImpGeral.Click
		If Trim(VB6.GetItemString(Me.cmbSeqArq, Me.cmbSeqArq.SelectedIndex)) <> "" Then
			Call ImprimeGeral(Me.dtpArquivo.value, iintBanID, CInt(VB6.GetItemString(Me.cmbSeqArq, Me.cmbSeqArq.SelectedIndex)))
		Else
			Call MsgBox("Você deve selecionar um sequencial de arquivo para poder imprimir!", MsgBoxStyle.Information, gstrTituloMensagem)
		End If
	End Sub
	
	Private Function DbCodToDescri(ByVal astrDbCod As String) As String
		Select Case astrDbCod
			Case "00"
				DbCodToDescri = "Débito efetuado"
			Case "01"
				DbCodToDescri = "Débito não efetuado - Insuficiência de fundos"
			Case "02"
				DbCodToDescri = "Débito não efetuado - Conta corrente não cadastrada"
			Case "04"
				DbCodToDescri = "Débito não efetuado - Outras restrições"
			Case "05"
				DbCodToDescri = "Débito não efetuado - Valor excedente"
			Case "10"
				DbCodToDescri = "Débito não efetuado - Agência em encerramento"
			Case "12"
				DbCodToDescri = "Débito não efetuado - Valor inválido"
			Case "13"
				DbCodToDescri = "Débito não efetuado - Data de lançamento inválida"
			Case "14"
				DbCodToDescri = "Débito não efetuado - Agência inválida"
			Case "15"
				DbCodToDescri = "Débito não efetuado - Conta corrente inválida"
			Case "18"
				DbCodToDescri = "Débito não efetuado - Data do débito anterior à do processamento"
			Case "30"
				DbCodToDescri = "Débito não efetuado - Sem contrato de débito automático"
			Case "31"
				DbCodToDescri = "Débito efetuado em data diferente da data informada - feriado na praça de débito"
			Case "96"
				DbCodToDescri = "Manutenção no cadastro"
			Case "97"
				DbCodToDescri = "Cancelamento - Não encontrado"
			Case "98"
				DbCodToDescri = "Cancelamento - Não efetuado, fora de tempo hábil"
			Case "99"
				DbCodToDescri = "Cancelamento - Cancelado conforme solicitação"
		End Select
	End Function
	
	Private Function ArCodToDescri(ByVal astrArCod As String) As String
		Select Case astrArCod
			Case "1"
				ArCodToDescri = "Guichê de Caixa c/fatura"
			Case "2"
				ArCodToDescri = "Arrec. Eletrônica c/fatura"
			Case "3"
				ArCodToDescri = "Internet c/fatura"
			Case "4"
				ArCodToDescri = "Outros meios c/fatura"
			Case "5"
				ArCodToDescri = "Lotérica/Ag. Arrecadador c/fatura"
			Case "6"
				ArCodToDescri = "Telefone c/fatura"
			Case "a"
				ArCodToDescri = "Guichê de Caixa s/fatura"
			Case "b"
				ArCodToDescri = "Arrec. Eletrônica s/fatura "
			Case "c"
				ArCodToDescri = "Internet s/fatura"
			Case "d"
				ArCodToDescri = "Lotérica/Ag. Arrecadador s/fatura"
			Case "e"
				ArCodToDescri = "Telefone s/fatura"
			Case "f"
				ArCodToDescri = "Outros meios s/fatura"
		End Select
	End Function
	
	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 txtMesAno_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtMesAno.Leave
		txtMesAno.Text = FormataData(txtMesAno, 1)
	End Sub
	
	Private Sub LigDes(ByVal ablnModo As Boolean)
		Me.mfgDados.Redraw = ablnModo
		Me.cmdAnalis.Enabled = ablnModo
		Me.cmdExec.Enabled = IIf(Me.mfgDados.Rows > 1, ablnModo, False)
		Me.cmdImpGeral.Enabled = ablnModo
		Me.cmdProcura.Enabled = ablnModo
		Me.cmdBuscaDtArq.Enabled = ablnModo
		Me.cmdFechar.Enabled = ablnModo
		Me.txtArq.Enabled = ablnModo
		Me.cmbBanco.Enabled = ablnModo
		Me.txtMesAno.Enabled = ablnModo
		Me.cmbSeqArq.Enabled = ablnModo
		Me.dtpArquivo.Enabled = ablnModo
		Me.dtpPagto.Enabled = ablnModo
		'UPGRADE_ISSUE: Form property frmRecArq.MousePointer does not support custom mousepointers. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="45116EAB-7060-405E-8ABE-9DBB40DC2E86"'
		Me.Cursor = IIf(ablnModo, System.Windows.Forms.Cursors.Default, System.Windows.Forms.Cursors.WaitCursor)
		System.Windows.Forms.Application.DoEvents()
	End Sub
	
	Private Sub CarregaComboSeqArq(ByVal aintTipo As Short)
		Dim llngSeq As Integer
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		On Error GoTo ErroCarregaComboSeqArq
		Me.cmbSeqArq.Items.Clear()
		lstrSql = ""
		lstrSql = lstrSql & "SELECT distinct(seqarquivo)  "
		If Me.strTipoServ = "Guiche" Then
			If aintTipo = 0 Then
				lstrSql = lstrSql & "  FROM `bxarqbco_arr` "
				lstrSql = lstrSql & " WHERE `datarquivo` = '" & VB6.Format(Me.dtpArquivo.value, "yyyy-MM-dd") & "' "
			Else
				lstrSql = lstrSql & "  FROM `bxarqbco_arr_itens` "
				lstrSql = lstrSql & " WHERE `datapgto` = '" & VB6.Format(Me.dtpPagto.value, "yyyy-MM-dd") & "' "
			End If
		Else
			If aintTipo = 0 Then
				lstrSql = lstrSql & "  FROM `bxarqbco_deb` "
				lstrSql = lstrSql & " WHERE `datarquivo` = '" & VB6.Format(Me.dtpArquivo._Value, "yyyy-MM-dd") & "' "
			Else
				lstrSql = lstrSql & "  FROM `bxarqbco_deb_itens` "
				lstrSql = lstrSql & " WHERE `datadbto` = '" & VB6.Format(Me.dtpPagto.value, "yyyy-MM-dd") & "' "
			End If
		End If
		lstrSql = lstrSql & "   AND `banid`      =  " & iintBanID & " "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				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"'
						llngSeq = CInt(IIf(IsDbNull(.Fields("seqarquivo").value), 0, .Fields("seqarquivo").value))
						Call Me.cmbSeqArq.Items.Add(CStr(llngSeq))
						Call .MoveNext()
					End While
					Me.cmbSeqArq.SelectedIndex = 0
				End If
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
ErroCarregaComboSeqArq: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
		End If
	End Sub
	
	Private Sub AtualConsumos(ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String, ByVal astrMesAno As String, ByVal adtePagto As Date, ByVal adblValor As Double)
		Dim lintMes As Short
		Dim lintAux As Short
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		
		On Error GoTo ErroAtualConsumos
		lintAux = 12
		For lintMes = 11 To 0 Step -1
			lstrSql = ""
			lstrSql = lstrSql & "SELECT * "
			lstrSql = lstrSql & "  FROM `consumos`  "
			lstrSql = lstrSql & " WHERE mesano" & lintMes & " = '" & astrMesAno & "' "
			lstrSql = lstrSql & "   AND zona = '" & astrZona & "' "
			lstrSql = lstrSql & "   AND livro = '" & astrLivro & "' "
			lstrSql = lstrSql & "   AND conta = '" & astrConta & "' "
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						lintAux = lintMes
						lintMes = 0
					End If
					Call .Close()
				End If
			End With
		Next lintMes
		If lintAux < 12 Then
			lstrSql = ""
			lstrSql = lstrSql & "UPDATE `consumos` SET "
			lstrSql = lstrSql & "       datapag" & lintAux & " = '" & VB6.Format(adtePagto, "yyyy-MM-dd") & "', "
			lstrSql = lstrSql & "       valor" & lintAux & " = " & Replace(CStr(adblValor), ",", ".") & " "
			lstrSql = lstrSql & " WHERE consumos.mesano" & lintAux & " = '" & astrMesAno & "' "
			lstrSql = lstrSql & "   AND consumos.zona = '" & astrZona & "' "
			lstrSql = lstrSql & "   AND consumos.livro = '" & astrLivro & "' "
			lstrSql = lstrSql & "   AND consumos.conta = '" & astrConta & "' "
			Call Executar(lstrSql)
		End If
ErroAtualConsumos: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrTituloMensagem)
		ElseIf myConC.Errors.Count > 0 Then 
			Call MsgBox("Código: " & myConC.Errors.Item(myConC.Errors.Count - 1).NativeError & vbCrLf & "Descrição:" & myConC.Errors.Item(myConC.Errors.Count - 1).Description)
		End If
	End Sub
End Class