Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmAtualizaSite
	Inherits System.Windows.Forms.Form
	
	'UPGRADE_WARNING: Event chkClientes.CheckStateChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub chkClientes_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkClientes.CheckStateChanged
		If Me.chkNovasFaturas.CheckState = System.Windows.Forms.CheckState.Unchecked And Me.chkPagamentos.CheckState = System.Windows.Forms.CheckState.Unchecked Then
			Me.chkClientes.CheckState = System.Windows.Forms.CheckState.Checked
		End If
	End Sub
	
	'UPGRADE_WARNING: Event chkNovasFaturas.CheckStateChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub chkNovasFaturas_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkNovasFaturas.CheckStateChanged
		If Me.chkPagamentos.CheckState = System.Windows.Forms.CheckState.Unchecked And Me.chkClientes.CheckState = System.Windows.Forms.CheckState.Unchecked Then
			Me.chkNovasFaturas.CheckState = System.Windows.Forms.CheckState.Checked
		End If
	End Sub
	
	'UPGRADE_WARNING: Event chkPagamentos.CheckStateChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub chkPagamentos_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkPagamentos.CheckStateChanged
		If Me.chkNovasFaturas.CheckState = System.Windows.Forms.CheckState.Unchecked And Me.chkClientes.CheckState = System.Windows.Forms.CheckState.Unchecked Then
			Me.chkPagamentos.CheckState = System.Windows.Forms.CheckState.Checked
		End If
	End Sub
	
	Private Sub cmdEnviar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdEnviar.Click
		Dim lstrErroConexao As String
		Dim lstrErroCriacao As String
		Dim lstrErroCliente As String
		Dim lstrErroFatPgto As String
		Dim lstrErroFaturas As String
		Call Me.lsbLog.Items.Clear()
		lstrErroConexao = ""
		lstrErroCriacao = ""
		lstrErroCliente = ""
		lstrErroFatPgto = ""
		lstrErroFaturas = ""
		Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
		Me.cmdEnviar.Enabled = False
		Me.cmdFechar.Enabled = False
		Me.dtpMesAno.Enabled = False
		Me.lblSituacao.Text = " Conectando na base de dados do site, aguarde..."
		Call Me.lblSituacao.Refresh()
		'If Carrega_Banco_site(lstrErroConexao) Then
		Me.lblSituacao.Text = " Criando tabelas, aguarde..."
		Call Me.lblSituacao.Refresh()
		Call CriaTabelaFaturasNet(lstrErroCriacao)
		If Me.chkClientes.CheckState = System.Windows.Forms.CheckState.Checked Then
			Me.lblSituacao.Text = " Criando dados dos clientes, aguarde..."
			Call Me.lblSituacao.Refresh()
			Call CarregaClientesSite(lstrErroCliente)
		End If
		If Me.chkPagamentos.CheckState = System.Windows.Forms.CheckState.Checked Then
			Me.lblSituacao.Text = " Atualizando as faturas pagas, aguarde..."
			Call Me.lblSituacao.Refresh()
			Call VerificaNFs(lstrErroFatPgto)
		End If
		If Me.chkNovasFaturas.CheckState = System.Windows.Forms.CheckState.Checked Then
			Me.lblSituacao.Text = " Enviando as faturas do mês selecionado, aguarde..."
			Call Me.lblSituacao.Refresh()
			Call InsereDadosFaturasNet(lstrErroFaturas)
		End If
		'End If
		If Trim(lstrErroConexao) <> "" Then
			Call Seta_Log(lstrErroConexao)
		End If
		If Trim(lstrErroCriacao) <> "" Then
			Call Seta_Log(lstrErroCriacao)
		End If
		If Trim(lstrErroCliente) <> "" Then
			Call Seta_Log(lstrErroCliente)
		End If
		If Trim(lstrErroFatPgto) <> "" Then
			Call Seta_Log(lstrErroFatPgto)
		End If
		If Trim(lstrErroFaturas) <> "" Then
			Call Seta_Log(lstrErroFaturas)
		End If
		'If MyConCSite.State = adodb.ObjectStateEnum.adStateOpen Then MyConCSite.Close
		Me.lblSituacao.Text = " Processo encerrado."
		Call Me.lblSituacao.Refresh()
		Me.cmdEnviar.Enabled = True
		Me.cmdFechar.Enabled = True
		Me.dtpMesAno.Enabled = True
		Me.Cursor = System.Windows.Forms.Cursors.Default
	End Sub
	
	Private Sub CarregaClientesSite(ByRef astrRetErro As String)
		Dim lstrSql As String
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim lstrIdentificacao As String
		Dim lstrCpfCnpj As String
		Dim lstrNome As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM " & gstrDataBase & ".`unidb` "
		Call Conectar(lstrSql, lrstAux, False)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					Call BarraProgresso(ProgressBar, lblPerc, lblInfo, 0, .RecordCount, " Atualizando consumidores...")
					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"'
						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"'
						lstrCpfCnpj = Trim(IIf(IsDbNull(.Fields("cpf_cnpj").value), "", .Fields("cpf_cnpj").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"'
						lstrNome = Trim(IIf(IsDbNull(.Fields("nome").value), "", .Fields("nome").value))
						lstrIdentificacao = lstrZona & "." & lstrLivro & "." & lstrConta
						If VerificaUnidades(lstrZona, lstrLivro, lstrConta, lstrNome, lstrCpfCnpj, astrRetErro) Then
							If Not InsereClientes(lstrZona, lstrLivro, lstrConta, lstrNome, lstrCpfCnpj, lstrIdentificacao, astrRetErro) Then
								If Trim(astrRetErro) <> "" Then
									Call Seta_Log(astrRetErro)
								End If
							End If
						End If
						Call .MoveNext()
						Call BarraProgresso(ProgressBar, lblPerc, lblInfo, 1,  , " Atualizando consumidores...")
					End While
				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
	End Sub
	
	Private Function VerificaUnidades(ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String, ByVal astrNome As String, ByVal astrCpfCnpj As String, ByRef astrRetErro As String) As Boolean
		Dim lstrNome As String
		Dim lstrCpfCnpj As String
		Dim lblnRet As Boolean
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lblnRet = False
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM " & gstrDataBaseSite & ".`nss_clientesnet` "
		lstrSql = lstrSql & " WHERE `zona` = '" & astrZona & "' "
		lstrSql = lstrSql & "   AND `livro`= '" & astrLivro & "' "
		lstrSql = lstrSql & "   AND `conta`= '" & astrConta & "' "
		lstrSql = lstrSql & " LIMIT 0, 1 "
		'If ConectarSite(lstrSql, lrstAux, False, astrRetErro) Then
		If Conectar(lstrSql, lrstAux, False) Then
			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"'
						lstrCpfCnpj = Trim(IIf(IsDbNull(.Fields("cpf_cnpj").value), "", .Fields("cpf_cnpj").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"'
						lstrNome = Trim(IIf(IsDbNull(.Fields("nome").value), "", .Fields("nome").value))
						If lstrNome <> astrNome Or lstrCpfCnpj <> astrCpfCnpj Then
							lblnRet = ApagaClientes(astrZona, astrLivro, astrConta, astrRetErro)
						End If
					Else
						lblnRet = True
					End If
					Call .Close()
				End If
			End With
		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
		VerificaUnidades = lblnRet
	End Function
	
	Private Function ApagaClientes(ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String, ByRef astrRetErro As String) As Boolean
		Dim ldblRegAfetados As Double
		Dim lblnRet As Boolean
		Dim lstrSql As String
		lblnRet = False
		lstrSql = ""
		lstrSql = lstrSql & "DELETE FROM " & gstrDataBaseSite & ".`nss_clientesnet`"
		lstrSql = lstrSql & " WHERE `zona` = '" & astrZona & "' "
		lstrSql = lstrSql & "   AND `livro`= '" & astrLivro & "' "
		lstrSql = lstrSql & "   AND `conta`= '" & astrConta & "' "
		'lblnRet = ExecutarSite(lstrSql, False, ldblRegAfetados, astrRetErro)
		lblnRet = Executar(lstrSql, False, ldblRegAfetados)
		If ldblRegAfetados > 0 Then
			Call Seta_Log("Excluido cliente " & astrZona & "." & astrLivro & "." & astrConta)
		Else
			lblnRet = False
		End If
		ApagaClientes = lblnRet
	End Function
	
	Private Function InsereClientes(ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String, ByVal astrNome As String, ByVal astrCpfCnpj As String, ByVal astrIdentificacao As String, ByRef astrRetErro As String) As Boolean
		Dim ldblRegAfetados As Double
		Dim lblnRet As Boolean
		Dim lstrSql As String
		lblnRet = False
		lstrSql = ""
		lstrSql = lstrSql & "INSERT INTO " & gstrDataBaseSite & ".`nss_clientesnet` "
		lstrSql = lstrSql & " (`nome`,`zona`,`livro`,`conta`,`identificacao`,`cpf_cnpj`) "
		lstrSql = lstrSql & " VALUES('" & Replace(astrNome, "'", "\'") & "', '" & astrZona & "','" & astrLivro & "','" & astrConta & "', '" & astrIdentificacao & "','" & astrCpfCnpj & "')"
		'lblnRet = ExecutarSite(lstrSql, False, ldblRegAfetados, astrRetErro)
		lblnRet = Executar(lstrSql, False, ldblRegAfetados)
		If ldblRegAfetados > 0 Then
			Call Seta_Log("Enviado cliente " & astrZona & "." & astrLivro & "." & astrConta)
		End If
		InsereClientes = lblnRet
	End Function
	
	Private Sub VerificaNFs(ByRef astrRetErro As String)
		Dim lstrSql As String
		Dim lstrMesAno As String
		Dim ldblNumNf As Double
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM " & gstrDataBaseSite & ".`nss_faturasnet` "
		'If ConectarSite(lstrSql, lrstAux, False, astrRetErro) Then
		If Conectar(lstrSql, lrstAux, False) Then
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						Call BarraProgresso(ProgressBar, lblPerc, lblInfo, 0, .RecordCount, " Atualizando faturas pagas")
						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"'
							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), "00/0000", .Fields("mesano").value))
							If VerificaPagas(ldblNumNf, lstrMesAno) Then
								Call ApagaNfs(ldblNumNf, lstrMesAno, astrRetErro)
							End If
							Call .MoveNext()
							Call BarraProgresso(ProgressBar, lblPerc, lblInfo, 1,  , " Atualizando faturas pagas")
						End While
					End If
					Call .Close()
				End If
			End With
		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 Function VerificaPagas(ByRef adblNumNf As Double, ByRef astrMesAno As String) As Boolean
		Dim lblnRet As Boolean
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lblnRet = False
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM " & gstrDataBase & ".`nf`"
		lstrSql = lstrSql & " WHERE `numnf` = " & adblNumNf & ""
		lstrSql = lstrSql & "   AND `mesano`= '" & astrMesAno & "' "
		lstrSql = lstrSql & "   AND `flgst` IN('P','C') "
		lstrSql = lstrSql & "   AND `grupo` = 'B' "
		lstrSql = lstrSql & " LIMIT 0, 1 "
		Call Conectar(lstrSql, lrstAux, False)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				lblnRet = (.RecordCount > 0)
				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
		VerificaPagas = lblnRet
	End Function
	
	Private Function ApagaNfs(ByVal ldblNumNf As Double, ByVal lstrMesAno As String, ByRef astrRetErro As String) As Boolean
		Dim ldblRegAfetados As Double
		Dim lblnRet As Boolean
		Dim lstrSql As String
		lblnRet = False
		lstrSql = ""
		lstrSql = lstrSql & "DELETE FROM " & gstrDataBaseSite & ".`nss_faturasnet`"
		lstrSql = lstrSql & " WHERE `numnf` = " & ldblNumNf & " "
		lstrSql = lstrSql & "   AND `mesano` = '" & lstrMesAno & "' "
		'lblnRet = ExecutarSite(lstrSql, False, ldblRegAfetados, astrRetErro)
		lblnRet = Executar(lstrSql, False, ldblRegAfetados)
		If ldblRegAfetados > 0 Then
			Call Seta_Log("Excluida fatura " & VB6.Format(ldblNumNf, "#0") & " - " & lstrMesAno)
		Else
			lblnRet = False
		End If
		ApagaNfs = lblnRet
	End Function
	
	Private Sub CriaTabelaFaturasNet(ByRef astrRetErro As String)
		Dim ldblRegAfetados As Double
		Dim lstrSql As String
		lstrSql = ""
		lstrSql = lstrSql & "CREATE TABLE IF NOT EXISTS `nss_clientesnet` ("
		lstrSql = lstrSql & "  `nome`   varchar(500) NOT NULL default '', "
		lstrSql = lstrSql & "  `zona`  char(3) default NULL, "
		lstrSql = lstrSql & "  `livro` char(2) default NULL, "
		lstrSql = lstrSql & "  `conta` varchar(8) default NULL, "
		lstrSql = lstrSql & "  `identificacao` varchar(13) default NULL, "
		lstrSql = lstrSql & "  `cpf_cnpj` varchar(18) default NULL, "
		lstrSql = lstrSql & " KEY `keyzona` (`zona`), "
		lstrSql = lstrSql & " KEY `keylivro` (`livro`), "
		lstrSql = lstrSql & " KEY `keyconta` (`conta`), "
		lstrSql = lstrSql & " KEY `keycpf_cnpj` (`cpf_cnpj`) "
		lstrSql = lstrSql & " ) ENGINE=InnoDB DEFAULT CHARSET=latin1 "
		Call Executar(lstrSql, False)
		'Call ExecutarSite(lstrSql, False, ldblRegAfetados, astrRetErro)
		Call Seta_Log("Tabela clientes " & IIf(ldblRegAfetados = 0, "OK", "Criada"))
		lstrSql = ""
		lstrSql = lstrSql & "CREATE TABLE IF NOT EXISTS " & gstrDataBaseSite & ".`nss_faturasnet` ("
		lstrSql = lstrSql & "  `numnf`   double NOT NULL default '0', "
		lstrSql = lstrSql & "  `mesano`  varchar(7) NOT NULL default '', "
		lstrSql = lstrSql & "  `cfop`    double(4, 3) default NULL, "
		lstrSql = lstrSql & "  `codclas` varchar(4) default NULL, "
		lstrSql = lstrSql & "  `ta` varchar(6) default NULL, "
		lstrSql = lstrSql & "  `zona`  char(3) default NULL, "
		lstrSql = lstrSql & "  `livro` char(2) default NULL, "
		lstrSql = lstrSql & "  `conta` varchar(8) default NULL, "
		lstrSql = lstrSql & "  `rota`  varchar(10) default NULL, "
		lstrSql = lstrSql & "  `banco_fatur` varchar(40) default NULL, "
		lstrSql = lstrSql & "  `banident` varchar(40) default NULL, "
		lstrSql = lstrSql & "  `agenc` varchar(4) default NULL, "
		lstrSql = lstrSql & "  `cc` varchar(12) default NULL, "
		lstrSql = lstrSql & "  `pagto_governo` char(1) NOT NULL default 'N', "
		lstrSql = lstrSql & "  `cpf_cnpj` varchar(18) default NULL, "
		lstrSql = lstrSql & "  `insc` varchar(25) default NULL, "
		lstrSql = lstrSql & "  `rg` varchar(35) default NULL, "
		lstrSql = lstrSql & "  `nomecons` varchar(85) default NULL, "
		lstrSql = lstrSql & "  `refcons` varchar(60) default NULL, "
		lstrSql = lstrSql & "  `uf` char(2) default NULL, "
		lstrSql = lstrSql & "  `cidade` varchar(60) default NULL, "
		lstrSql = lstrSql & "  `distrito` varchar(60) default NULL, "
		lstrSql = lstrSql & "  `bairro` varchar(60) default NULL, "
		lstrSql = lstrSql & "  `logradouro` varchar(60) default NULL, "
		lstrSql = lstrSql & "  `complemento` varchar(140) default NULL, "
		lstrSql = lstrSql & "  `cep` varchar(10) default NULL, "
		lstrSql = lstrSql & "  `entrega` int(11) default NULL, "
		lstrSql = lstrSql & "  `uf_entrega` varchar(2) default NULL, "
		lstrSql = lstrSql & "  `cid_entrega` varchar(60) default NULL, "
		lstrSql = lstrSql & "  `dis_entrega` varchar(60) default NULL, "
		lstrSql = lstrSql & "  `bai_entrega` varchar(60) default NULL, "
		lstrSql = lstrSql & "  `log_entrega` varchar(60) default NULL, "
		lstrSql = lstrSql & "  `com_entrega` varchar(100) NOT NULL default '', "
		lstrSql = lstrSql & "  `cep_entrega` varchar(10) default NULL, "
		lstrSql = lstrSql & "  `valortot` decimal(14, 2) default NULL, "
		lstrSql = lstrSql & "  `valorliq` decimal(14, 2) default NULL, "
		lstrSql = lstrSql & "  `vlrconsutrib` decimal(10, 2) default NULL, "
		lstrSql = lstrSql & "  `datavenc` date default '0000-00-00', "
		lstrSql = lstrSql & "  `dataapr` date default '0000-00-00', "
		lstrSql = lstrSql & "  `dataemissao` date default '0000-00-00', "
		lstrSql = lstrSql & "  `dataproxleit` date default '0000-00-00', "
		lstrSql = lstrSql & "  `dataleit` date default '0000-00-00', "
		lstrSql = lstrSql & "  `dataleitant` date default '0000-00-00', "
		lstrSql = lstrSql & "  `datapag` date default '0000-00-00', "
		lstrSql = lstrSql & "  `num_med` varchar(18) default NULL, "
		lstrSql = lstrSql & "  `const_med` double default NULL, "
		lstrSql = lstrSql & "  `fase` char(1) default NULL, "
		lstrSql = lstrSql & "  `tensao` varchar(10) default NULL, "
		lstrSql = lstrSql & "  `codhash` varchar(50) default NULL, "
		lstrSql = lstrSql & "  `codbarra` varchar(50) default NULL, "
		lstrSql = lstrSql & "  `dvcodbarra` varchar(4) default NULL, "
		lstrSql = lstrSql & "  `leit` double default NULL, "
		lstrSql = lstrSql & "  `leituraant` varchar(10) default NULL, "
		lstrSql = lstrSql & "  `consfaturado` double default NULL, "
		lstrSql = lstrSql & "  `conslido` double default NULL, "
		lstrSql = lstrSql & "  `valorconsumo` double default NULL, "
		lstrSql = lstrSql & "  `leitura_kvarh_atual` double default NULL, "
		lstrSql = lstrSql & "  `leitura_kvarh_anterior` double default NULL, "
		lstrSql = lstrSql & "  `consumo_kvarh` double default NULL, "
		lstrSql = lstrSql & "  `LeitReservadoAtu` double default '0', "
		lstrSql = lstrSql & "  `LeitReservadoAnt` double default '0', "
		lstrSql = lstrSql & "  `consumoreservado` double default NULL, "
		lstrSql = lstrSql & "  `vlrConsumoReservado` double default NULL, "
		lstrSql = lstrSql & "  `saldo_arred` double default '0', "
		lstrSql = lstrSql & "  `diasconsumo` varchar(2) default NULL, "
		lstrSql = lstrSql & "  `vlrdiario` double default NULL, "
		lstrSql = lstrSql & "  `mediaconsumodiario` double default NULL, "
		lstrSql = lstrSql & "  `mesmaiorconsumo` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `mesmenorconsumo` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `maiorconsumo` double default NULL, "
		lstrSql = lstrSql & "  `menorconsumo` double default NULL, "
		lstrSql = lstrSql & "  `mediaconsumo3meses` double default NULL, "
		lstrSql = lstrSql & "  `ocorrencia` varchar(5) default NULL, "
		lstrSql = lstrSql & "  `descocorrencia` varchar(25) default NULL, "
		lstrSql = lstrSql & "  `valorpend` double default '0', "
		lstrSql = lstrSql & "  `totalpend` int(11) default '0', "
		lstrSql = lstrSql & "  `descclasse` varchar(100) default NULL, "
		lstrSql = lstrSql & "  `fp` double(3, 2) default NULL, "
		lstrSql = lstrSql & "  `baseicms` double default NULL, "
		lstrSql = lstrSql & "  `aliqicms` double default NULL, "
		lstrSql = lstrSql & "  `vlricms` double default NULL, "
		lstrSql = lstrSql & "  `baseicms1` double default NULL, "
		lstrSql = lstrSql & "  `aliqicms1` double default NULL, "
		lstrSql = lstrSql & "  `vlricms1` double default NULL, "
		lstrSql = lstrSql & "  `baseicmstotal` double default '0', "
		lstrSql = lstrSql & "  `vlricmstotal` double default '0', "
		lstrSql = lstrSql & "  `basepis` double default NULL, "
		lstrSql = lstrSql & "  `aliqpis` double default NULL, "
		lstrSql = lstrSql & "  `vlrpis` double default NULL, "
		lstrSql = lstrSql & "  `basecofins` double default NULL, "
		lstrSql = lstrSql & "  `aliqcofins` double default NULL, "
		lstrSql = lstrSql & "  `vlrcofins` double default NULL, "
		lstrSql = lstrSql & "  `mensagem` varchar(255) default NULL, "
		lstrSql = lstrSql & "  `dec_meta` double default NULL, "
		lstrSql = lstrSql & "  `dec_rea` double default NULL, "
		lstrSql = lstrSql & "  `fec_meta` double default NULL, "
		lstrSql = lstrSql & "  `fec_rea` double default NULL, "
		lstrSql = lstrSql & "  `dic_meta` double default NULL, "
		lstrSql = lstrSql & "  `dic_rea` double default NULL, "
		lstrSql = lstrSql & "  `fic_meta` double default NULL, "
		lstrSql = lstrSql & "  `fic_rea` double default NULL, "
		lstrSql = lstrSql & "  `dmic` double default NULL, "
		lstrSql = lstrSql & "  `dmicM` double default NULL, "
		lstrSql = lstrSql & "  `refindicador` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `conjunto` varchar(255) default NULL, "
		lstrSql = lstrSql & "  `ret_irpj` double default '0', "
		lstrSql = lstrSql & "  `ret_pis` double default '0', "
		lstrSql = lstrSql & "  `ret_csll` double default '0', "
		lstrSql = lstrSql & "  `ret_cofins` double default '0', "
		lstrSql = lstrSql & "  `comp_energia` double default NULL, "
		lstrSql = lstrSql & "  `comp_transmissao` double default NULL, "
		lstrSql = lstrSql & "  `comp_distribuicao` double default NULL, "
		lstrSql = lstrSql & "  `comp_encargos_setoriais` double default NULL, "
		lstrSql = lstrSql & "  `comp_outros` double default NULL, "
		lstrSql = lstrSql & "  `itens_fatura` text default NULL, "
		lstrSql = lstrSql & "  `hist_mes_ano01` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `hist_diascon01` int default NULL, "
		lstrSql = lstrSql & "  `hist_datpgto01` date default NULL, "
		lstrSql = lstrSql & "  `hist_consumo01` double default NULL, "
		lstrSql = lstrSql & "  `hist_leitura01` double default NULL, "
		lstrSql = lstrSql & "  `hist_vlrfatu01` double default NULL, "
		lstrSql = lstrSql & "  `hist_ocorren01` int default NULL, "
		lstrSql = lstrSql & "  `hist_mes_ano02` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `hist_diascon02` int default NULL, "
		lstrSql = lstrSql & "  `hist_datpgto02` date default NULL, "
		lstrSql = lstrSql & "  `hist_consumo02` double default NULL, "
		lstrSql = lstrSql & "  `hist_leitura02` double default NULL, "
		lstrSql = lstrSql & "  `hist_vlrfatu02` double default NULL, "
		lstrSql = lstrSql & "  `hist_ocorren02` int default NULL, "
		lstrSql = lstrSql & "  `hist_mes_ano03` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `hist_diascon03` int default NULL, "
		lstrSql = lstrSql & "  `hist_datpgto03` date default NULL, "
		lstrSql = lstrSql & "  `hist_consumo03` double default NULL, "
		lstrSql = lstrSql & "  `hist_leitura03` double default NULL, "
		lstrSql = lstrSql & "  `hist_vlrfatu03` double default NULL, "
		lstrSql = lstrSql & "  `hist_ocorren03` int default NULL, "
		lstrSql = lstrSql & "  `hist_mes_ano04` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `hist_diascon04` int default NULL, "
		lstrSql = lstrSql & "  `hist_datpgto04` date default NULL, "
		lstrSql = lstrSql & "  `hist_consumo04` double default NULL, "
		lstrSql = lstrSql & "  `hist_leitura04` double default NULL, "
		lstrSql = lstrSql & "  `hist_vlrfatu04` double default NULL, "
		lstrSql = lstrSql & "  `hist_ocorren04` int default NULL, "
		lstrSql = lstrSql & "  `hist_mes_ano05` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `hist_diascon05` int default NULL, "
		lstrSql = lstrSql & "  `hist_datpgto05` date default NULL, "
		lstrSql = lstrSql & "  `hist_consumo05` double default NULL, "
		lstrSql = lstrSql & "  `hist_leitura05` double default NULL, "
		lstrSql = lstrSql & "  `hist_vlrfatu05` double default NULL, "
		lstrSql = lstrSql & "  `hist_ocorren05` int default NULL, "
		lstrSql = lstrSql & "  `hist_mes_ano06` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `hist_diascon06` int default NULL, "
		lstrSql = lstrSql & "  `hist_datpgto06` date default NULL, "
		lstrSql = lstrSql & "  `hist_consumo06` double default NULL, "
		lstrSql = lstrSql & "  `hist_leitura06` double default NULL, "
		lstrSql = lstrSql & "  `hist_vlrfatu06` double default NULL, "
		lstrSql = lstrSql & "  `hist_ocorren06` int default NULL, "
		lstrSql = lstrSql & "  `hist_mes_ano07` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `hist_diascon07` int default NULL, "
		lstrSql = lstrSql & "  `hist_datpgto07` date default NULL, "
		lstrSql = lstrSql & "  `hist_consumo07` double default NULL, "
		lstrSql = lstrSql & "  `hist_leitura07` double default NULL, "
		lstrSql = lstrSql & "  `hist_vlrfatu07` double default NULL, "
		lstrSql = lstrSql & "  `hist_ocorren07` int default NULL, "
		lstrSql = lstrSql & "  `hist_mes_ano08` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `hist_diascon08` int default NULL, "
		lstrSql = lstrSql & "  `hist_datpgto08` date default NULL, "
		lstrSql = lstrSql & "  `hist_consumo08` double default NULL, "
		lstrSql = lstrSql & "  `hist_leitura08` double default NULL, "
		lstrSql = lstrSql & "  `hist_vlrfatu08` double default NULL, "
		lstrSql = lstrSql & "  `hist_ocorren08` int default NULL, "
		lstrSql = lstrSql & "  `hist_mes_ano09` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `hist_diascon09` int default NULL, "
		lstrSql = lstrSql & "  `hist_datpgto09` date default NULL, "
		lstrSql = lstrSql & "  `hist_consumo09` double default NULL, "
		lstrSql = lstrSql & "  `hist_leitura09` double default NULL, "
		lstrSql = lstrSql & "  `hist_vlrfatu09` double default NULL, "
		lstrSql = lstrSql & "  `hist_ocorren09` int default NULL, "
		lstrSql = lstrSql & "  `hist_mes_ano10` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `hist_diascon10` int default NULL, "
		lstrSql = lstrSql & "  `hist_datpgto10` date default NULL, "
		lstrSql = lstrSql & "  `hist_consumo10` double default NULL, "
		lstrSql = lstrSql & "  `hist_leitura10` double default NULL, "
		lstrSql = lstrSql & "  `hist_vlrfatu10` double default NULL, "
		lstrSql = lstrSql & "  `hist_ocorren10` int default NULL, "
		lstrSql = lstrSql & "  `hist_mes_ano11` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `hist_diascon11` int default NULL, "
		lstrSql = lstrSql & "  `hist_datpgto11` date default NULL, "
		lstrSql = lstrSql & "  `hist_consumo11` double default NULL, "
		lstrSql = lstrSql & "  `hist_leitura11` double default NULL, "
		lstrSql = lstrSql & "  `hist_vlrfatu11` double default NULL, "
		lstrSql = lstrSql & "  `hist_ocorren11` int default NULL, "
		lstrSql = lstrSql & "  `hist_mes_ano12` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `hist_diascon12` int default NULL, "
		lstrSql = lstrSql & "  `hist_datpgto12` date default NULL, "
		lstrSql = lstrSql & "  `hist_consumo12` double default NULL, "
		lstrSql = lstrSql & "  `hist_leitura12` double default NULL, "
		lstrSql = lstrSql & "  `hist_vlrfatu12` double default NULL, "
		lstrSql = lstrSql & "  `hist_ocorren12` int default NULL, "
		lstrSql = lstrSql & " PRIMARY KEY  (`numnf`, `mesano`), "
		lstrSql = lstrSql & " KEY `keyzona` (`zona`), "
		lstrSql = lstrSql & " KEY `keylivro` (`livro`), "
		lstrSql = lstrSql & " KEY `keyconta` (`conta`), "
		lstrSql = lstrSql & " KEY `keyrota` (`rota`), "
		lstrSql = lstrSql & " KEY `keyvalortot` (`valortot`), "
		lstrSql = lstrSql & " KEY `keycpf_cnpj` (`cpf_cnpj`) "
		lstrSql = lstrSql & " ) ENGINE=InnoDB DEFAULT CHARSET=latin1 "
		'Call ExecutarSite(lstrSql, False, ldblRegAfetados, astrRetErro)
		Call Executar(lstrSql, False)
		Call Seta_Log("Tabela faturas " & IIf(ldblRegAfetados = 0, "OK", "Criada"))
	End Sub
	
	Private Function VerificaSite(ByVal adblNumNf As Double, ByVal astrMesAno As String, ByVal adblVlrTot As Double, ByRef adblVlrLiq As Double, ByRef astrRetErro As String) As Boolean
		Dim ldblTot As Double
		Dim ldblLiq As Double
		Dim lblnRet As Boolean
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lblnRet = False
		astrRetErro = ""
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM " & gstrDataBaseSite & ".`nss_faturasnet` "
		lstrSql = lstrSql & " WHERE `numnf` = " & adblNumNf & " "
		lstrSql = lstrSql & "   AND `mesano`= '" & astrMesAno & "' "
		lstrSql = lstrSql & " LIMIT 0, 1 "
		'If ConectarSite(lstrSql, lrstAux, False, astrRetErro) Then
		If Conectar(lstrSql, lrstAux, False) Then
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						lblnRet = 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"'
						ldblTot = CDbl(IIf(IsDbNull(.Fields("valortot").value), 0, .Fields("valortot").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"'
						ldblLiq = CDbl(IIf(IsDbNull(.Fields("valorliq").value), 0, .Fields("valorliq").value))
						If ldblTot <> adblVlrTot Or ldblLiq <> adblVlrLiq Then
							If ApagaNfs(adblNumNf, astrMesAno, astrRetErro) Then
								lblnRet = False
							Else
								lblnRet = True
							End If
						End If
					End If
					Call .Close()
				End If
			End With
		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
		VerificaSite = lblnRet
	End Function
	
	Private Sub InsereDadosFaturasNet(ByRef astrRetErro As String)
		'dados da fatura
		Dim lstrMesAno As String
		Dim ldblNumNf As Double
		Dim lstrItens As String
		Dim lstrIteImp As String
		Dim lstrIteRef As String
		Dim lstrIteImpCon As String
		Dim lstrIteImpPis As String
		Dim lstrIteImpCof As String
		Dim lstrIteImpIcm As String
		Dim lstrIteImpIlu As String
		Dim lstrIteImpDiv As String
		Dim ldblCfop As Double
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim llngUnidId As Integer
		Dim lstrRota As String
		Dim lstrBancoFatur As String
		Dim lstrBanIdent As String
		Dim lstrCpfCnpj As String
		Dim lstrNumMedidor As String
		Dim ldblConstMedid As Double
		Dim lstrFase As String
		Dim lstrTa As String
		Dim lstrTensao As String
		Dim lstrCodHash As String
		Dim ldblValorTot As Double
		Dim ldblValorLiq As Double
		Dim lstrCodBarra As String
		Dim lstrDvCodBar As String
		Dim lstrCodClas As String
		Dim lintDias As Short
		'dados da tabela de classe
		Dim lstrDsClas As String
		'datas da fatura
		Dim ldteVcto As Date
		Dim ldteEmissao As Date
		Dim ldteApreset As Date
		Dim ldteProxLeit As Date
		Dim ldteLeitAtu As Date
		Dim ldteLeitAnt As Date
		'dados de leitura
		Dim ldblLeituraAnt As Double
		Dim ldblLeituraAtu As Double
		Dim ldblLeituraKvarhAnt As Double
		Dim ldblLeituraKvarhAtu As Double
		Dim ldblConsumoKvarh As Double
		Dim ldblFp As Double
		Dim lintMedOcorrencia As Short
		Dim lstrDesOcorrencia As String
		Dim ldblLeitReservadoAtu As Double
		Dim ldblLeitReservadoAnt As Double
		Dim ldblVlrConsumoReserv As Double
		'dados de consumo
		Dim ldblConsumo As Double
		Dim ldblReservado As Double
		Dim ldblConsumFat As Double
		Dim ldblVlrConFat As Double
		'Dados da unidade consumidora
		Dim lstrAgenc As String
		Dim lstrCc As String
		Dim lstrPagtoGov As String
		Dim lstrNome As String
		Dim lstrInsc As String
		Dim lstrRg As String
		Dim lstrRgOrgao As String
		Dim lstrRgUf As String
		Dim ldblSldArred As Double
		'dados do logradouro
		Dim lstrUf As String
		Dim lstrCidade As String
		Dim lstrDistrito As String
		Dim lstrBairro As String
		Dim lstrEnd As String
		Dim lstrCompl As String
		Dim lstrQuadra As String
		Dim lstrLote As String
		Dim lstrNumero As String
		Dim lstrCep As String
		Dim lintEntrega As Short
		Dim lstrUfEnt As String
		Dim lstrCidEnt As String
		Dim lstrDisEnt As String
		Dim lstrBaiEnt As String
		Dim lstrEndEnt As String
		Dim lstrComEnt As String
		Dim lstrQuaEnt As String
		Dim lstrLotEnt As String
		Dim lstrNumEnt As String
		Dim lstrCepEnt As String
		'dados de tributação
		Dim ldblVlrCofins As Double
		Dim ldblVlrPis As Double
		Dim ldblVlrIcms As Double
		Dim ldblVlrIcms1 As Double
		Dim ldblBaseIcms As Double
		Dim ldblAliqIcms As Double
		Dim ldblBaseIcms1 As Double
		Dim ldblAliqIcms1 As Double
		Dim ldblBasePis As Double
		Dim ldblAliqPis As Double
		Dim ldblBaseCofins As Double
		Dim ldblAliqCofins As Double
		Dim ldblBasIcmsTotal As Double
		Dim ldblVlrIcmsTotal As Double
		'dados de retenção
		Dim ldblRetIrpj As Double
		Dim ldblRetPis As Double
		Dim ldblRetCsll As Double
		Dim ldblRetCofins As Double
		'dados da composição da tarifa
		Dim ldblCompEnergia As Double
		Dim ldblCompTransmissao As Double
		Dim ldblCompDistribuicao As Double
		Dim ldblCompEncargosSetoriais As Double
		Dim ldblCompOutros As Double
		'dados dos indicadores
		Dim ldblDecMeta As Double
		Dim ldblDecReal As Double
		Dim ldblFecMeta As Double
		Dim ldblFecReal As Double
		Dim ldblDicMeta As Double
		Dim ldblDicReal As Double
		Dim ldblFicMeta As Double
		Dim ldblFicReal As Double
		Dim ldblDmicRea As Double
		Dim ldblDmicMet As Double
		Dim lstrRefIndi As String
		'Historico da unidade consumidora
		Dim ldblMaiorCons As Double
		Dim ldblMenorCons As Double
		Dim lstrMesMaiorC As String
		Dim lstrMesMenorC As String
		Dim ldblMed3Meses As Double
		Dim ldblValorPed As Double
		Dim lintCtrl As Short
		Dim lintQutdePed As Short
		Dim lintMed3Meses As Short
		Dim lstrMesAnoH As String
		Dim ldtePgentoH As Date
		Dim ldblVlrAuxH As Double
		Dim ldblVlrFatH As Double
		Dim lstrDiasCoH As String
		Dim lintDiasCoH As Short
		Dim ldblConsumH As Double
		Dim ldblLeiturH As Double
		Dim lintOcMediH As Short
		'UPGRADE_WARNING: Lower bound of array lstrHMesAno was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrHMesAno(12) As String
		'UPGRADE_WARNING: Lower bound of array lintHDiasCo was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lintHDiasCo(12) As Short
		'UPGRADE_WARNING: Lower bound of array lintHOMedia was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lintHOMedia(12) As Short
		'UPGRADE_WARNING: Lower bound of array ldteHPagame was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldteHPagame(12) As Date
		'UPGRADE_WARNING: Lower bound of array ldblHConsum was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblHConsum(12) As Double
		'UPGRADE_WARNING: Lower bound of array ldblHLeitur was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblHLeitur(12) As Double
		'UPGRADE_WARNING: Lower bound of array ldblHVlrFat was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblHVlrFat(12) As Double
		
		Dim lstrSql As String
		Dim lrstFat As ADODB.Recordset
		lrstFat = New ADODB.Recordset
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		Dim lblnContinua As Boolean
		Dim lblnErroConsulta As Boolean
		Dim lblnErroExecuta As Boolean
		Me.lblLimite.Text = CStr(0)
		lblnErroConsulta = True
		lblnErroExecuta = True
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM " & gstrDataBase & ".`nf` "
		lstrSql = lstrSql & " WHERE `flgst` NOT IN('P','C') "
		lstrSql = lstrSql & "   AND `grupo` = 'B' "
		lstrSql = lstrSql & "   AND `mesano` = '" & VB6.Format(Me.dtpMesAno.value, "MM/yyyy") & "' "
		'lstrSql = lstrSql & "   AND `numnf` = 109 "
		Call Conectar(lstrSql, lrstFat, False)
		With lrstFat
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					Call BarraProgresso(ProgressBar, lblPerc, lblInfo, 0, .RecordCount, " Enviando faturas para site")
					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"'
						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), "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"'
						ldblValorTot = CDbl(IIf(IsDbNull(.Fields("valortot").value), 0, .Fields("valortot").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"'
						ldblValorLiq = CDbl(IIf(IsDbNull(.Fields("valorliq").value), 0, .Fields("valorliq").value))
						Me.lblLimite.Text = CStr(ldblNumNf)
						Call Me.lblLimite.Refresh()
						If Not VerificaSite(ldblNumNf, lstrMesAno, ldblValorTot, ldblValorLiq, astrRetErro) Then
							If Trim(astrRetErro) = "" 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"'
								lstrItens = Trim(IIf(IsDbNull(.Fields("itensserv").value), "", .Fields("itensserv").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"'
								lstrTa = Trim(IIf(IsDbNull(.Fields("ta").value), "01B1", .Fields("ta").value))
								'Convenios, Diversos e Taxados
								lstrIteImp = ""
								lstrIteImpCon = ""
								lstrIteImpPis = ""
								lstrIteImpCof = ""
								lstrIteImpIcm = ""
								lstrIteImpIlu = ""
								lstrIteImpDiv = ""
								For IndCodServ = 1 To Len(Trim(lstrItens))
									Call BuscaCodItem(IndCodServ, lstrItens)
									lstrIteRef = Trim(RefCodServ)
									If Len(lstrIteRef) > 0 Then
										If InStr(1, lstrIteRef, ")") > 0 Then
											lstrIteRef = VB.Left(lstrIteRef, InStr(1, lstrIteRef, ")"))
										End If
									End If
									'Consumo ou Reativo
									If IsNumeric(VlrCodServ) Then
										If CDbl(VlrCodServ) <> 0 Then
											If VB.Left(codserv, 9) = "030202009" Or VB.Left(codserv, 10) = "0302020012" Then
												lstrIteImpCon = lstrIteImpCon & IIf(Len(lstrIteImpCon) > 0, ";", "")
												lstrIteImpCon = lstrIteImpCon & codTodescri(codserv) & ";"
												lstrIteImpCon = lstrIteImpCon & lstrIteRef & ";"
												lstrIteImpCon = lstrIteImpCon & FormatNumber(BuscaVlrItem(lstrItens, codserv), 2)
											End If
											'Pis
											If VB.Left(codserv, 10) = "0302020029" Then
												lstrIteImpPis = lstrIteImpPis & IIf(Len(lstrIteImpPis) > 0, ";", "")
												lstrIteImpPis = lstrIteImpPis & codTodescri(codserv) & ";"
												lstrIteImpPis = lstrIteImpPis & lstrIteRef & ";"
												lstrIteImpPis = lstrIteImpPis & FormatNumber(BuscaVlrItem(lstrItens, codserv), 2)
											End If
											'Cofins
											If VB.Left(codserv, 10) = "0302020030" Then
												lstrIteImpCof = lstrIteImpCof & IIf(Len(lstrIteImpCof) > 0, ";", "")
												lstrIteImpCof = lstrIteImpCof & codTodescri(codserv) & ";"
												lstrIteImpCof = lstrIteImpCof & lstrIteRef & ";"
												lstrIteImpCof = lstrIteImpCof & FormatNumber(BuscaVlrItem(lstrItens, codserv), 2)
											End If
											'Icms
											If VB.Left(codserv, 10) = "0302030014" Then
												lstrIteImpIcm = lstrIteImpIcm & IIf(Len(lstrIteImpIcm) > 0, ";", "")
												lstrIteImpIcm = lstrIteImpIcm & codTodescri(codserv) & ";"
												lstrIteImpIcm = lstrIteImpIcm & lstrIteRef & ";"
												lstrIteImpIcm = lstrIteImpIcm & FormatNumber(BuscaVlrItem(lstrItens, codserv), 2)
											End If
											'Iluminação
											If VB.Left(codserv, 10) = "0301000003" Then
												lstrIteImpIlu = lstrIteImpIlu & IIf(Len(lstrIteImpIlu) > 0, ";", "")
												lstrIteImpIlu = lstrIteImpIlu & codTodescri(codserv) & ";"
												lstrIteImpIlu = lstrIteImpIlu & lstrIteRef & ";"
												lstrIteImpIlu = lstrIteImpIlu & FormatNumber(BuscaVlrItem(lstrItens, codserv), 2)
											End If
											'Diversos, taxas e convênios
											If VB.Left(codserv, 4) = "9030" Or VB.Left(codserv, 4) = "9040" Or VB.Left(codserv, 4) = "9070" Or VB.Left(codserv, 4) = "9080" Then
												lstrIteImpDiv = lstrIteImpDiv & IIf(Len(lstrIteImpDiv) > 0, ";", "")
												lstrIteImpDiv = lstrIteImpDiv & codTodescri(codserv) & ";"
												lstrIteImpDiv = lstrIteImpDiv & lstrIteRef & ";"
												lstrIteImpDiv = lstrIteImpDiv & FormatNumber(CDbl(Replace(VlrCodServ, ".", ",")), 2)
											End If
										End If
									End If
								Next IndCodServ
								lstrIteImp = lstrIteImp & lstrIteImpCon
								lstrIteImp = lstrIteImp & IIf(Len(lstrIteImpPis) > 0, ";", "") & lstrIteImpPis
								lstrIteImp = lstrIteImp & IIf(Len(lstrIteImpCof) > 0, ";", "") & lstrIteImpCof
								lstrIteImp = lstrIteImp & IIf(Len(lstrIteImpIcm) > 0, ";", "") & lstrIteImpIcm
								lstrIteImp = lstrIteImp & IIf(Len(lstrIteImpIlu) > 0, ";", "") & lstrIteImpIlu
								lstrIteImp = lstrIteImp & IIf(Len(lstrIteImpDiv) > 0, ";", "") & lstrIteImpDiv
								lstrIteImp = lstrIteImp & ";"
								ldblConsumo = Arredondar(BuscaVlrItem(lstrItens, "030201008"), 2)
								ldblReservado = Arredondar(BuscaVlrItem(lstrItens, "0302010044"), 2)
								ldblConsumFat = Arredondar(BuscaVlrItem(lstrItens, "030201009"), 2)
								ldblVlrConFat = Arredondar(BuscaVlrItem(lstrItens, "030202009"), 2)
								'
								ldblLeituraAnt = Arredondar(BuscaVlrItem(lstrItens, "0302990040"), 2)
								ldblLeituraAtu = Arredondar(BuscaVlrItem(lstrItens, "0302990039"), 2)
								ldblLeituraKvarhAnt = Arredondar(BuscaVlrItem(lstrItens, "0302010046"), 2)
								ldblLeituraKvarhAtu = Arredondar(BuscaVlrItem(lstrItens, "0302010045"), 2)
								ldblConsumoKvarh = Arredondar(BuscaVlrItem(lstrItens, "0302010047"), 2)
								ldblFp = Arredondar(BuscaVlrItem(lstrItens, "0302030099"), 2)
								'
								ldblVlrCofins = Arredondar(BuscaVlrItem(lstrItens, "0302020030"), 2)
								ldblVlrPis = Arredondar(BuscaVlrItem(lstrItens, "0302020029"), 2)
								ldblVlrIcms = Arredondar(BuscaVlrItem(lstrItens, "0302030009"), 2)
								ldblVlrIcms1 = Arredondar(BuscaVlrItem(lstrItens, "0302030010"), 2)
								ldblBaseIcms = Arredondar(BuscaVlrItem(lstrItens, "0302030001"), 2)
								ldblAliqIcms = Arredondar(BuscaVlrItem(lstrItens, "0302030002"), 2)
								ldblBaseIcms1 = Arredondar(BuscaVlrItem(lstrItens, "0302030003"), 2)
								ldblAliqIcms1 = Arredondar(BuscaVlrItem(lstrItens, "0302030013"), 2)
								ldblBasePis = Arredondar(BuscaVlrItem(lstrItens, "0302020033"), 2)
								ldblAliqPis = Arredondar(BuscaVlrItem(lstrItens, "0302990303"), 2)
								ldblBaseCofins = Arredondar(BuscaVlrItem(lstrItens, "0302020034"), 2)
								ldblAliqCofins = Arredondar(BuscaVlrItem(lstrItens, "0302990304"), 2)
								ldblBasIcmsTotal = Arredondar(BuscaVlrItem(lstrItens, "0302030015"), 2)
								ldblVlrIcmsTotal = Arredondar(BuscaVlrItem(lstrItens, "0302030014"), 2)
								'
								lintMedOcorrencia = BuscaVlrItem(lstrItens, "90410000")
								lstrDesOcorrencia = BuscaRefItem(lstrItens, "90410000")
								ldblLeitReservadoAtu = Arredondar(BuscaVlrItem(lstrItens, "0302040019"), 2)
								ldblLeitReservadoAnt = Arredondar(BuscaVlrItem(lstrItens, "0302040020"), 2)
								ldblVlrConsumoReserv = Arredondar(BuscaVlrItem(lstrItens, "0302990044"), 2)
								'
								ldblRetIrpj = Arredondar(BuscaVlrItem(lstrItens, "9090000004"), 2)
								ldblRetPis = Arredondar(BuscaVlrItem(lstrItens, "9090000001"), 2)
								ldblRetCsll = Arredondar(BuscaVlrItem(lstrItens, "9090000003"), 2)
								ldblRetCofins = Arredondar(BuscaVlrItem(lstrItens, "9090000002"), 2)
								'
								ldblCompEnergia = Arredondar(BuscaVlrItem(lstrItens, "0302090001"), 2)
								ldblCompTransmissao = Arredondar(BuscaVlrItem(lstrItens, "0302090002"), 2)
								ldblCompDistribuicao = Arredondar(BuscaVlrItem(lstrItens, "0302090003"), 2)
								ldblCompEncargosSetoriais = Arredondar(BuscaVlrItem(lstrItens, "0302090004"), 2)
								ldblCompOutros = Arredondar(BuscaVlrItem(lstrItens, "0302090005"), 2)
								'
								ldblDecMeta = Arredondar(BuscaVlrItem(lstrItens, "0302080101"), 2)
								ldblDecReal = Arredondar(BuscaVlrItem(lstrItens, "0302080001"), 2)
								ldblFecMeta = Arredondar(BuscaVlrItem(lstrItens, "0302080102"), 2)
								ldblFecReal = Arredondar(BuscaVlrItem(lstrItens, "0302080002"), 2)
								ldblDicMeta = Arredondar(BuscaVlrItem(lstrItens, "0302080103"), 2)
								ldblDicReal = Arredondar(BuscaVlrItem(lstrItens, "0302080003"), 2)
								ldblFicMeta = Arredondar(BuscaVlrItem(lstrItens, "0302080104"), 2)
								ldblFicReal = Arredondar(BuscaVlrItem(lstrItens, "0302080004"), 2)
								ldblDmicRea = Arredondar(BuscaVlrItem(lstrItens, "0302080105"), 2)
								ldblDmicMet = Arredondar(BuscaVlrItem(lstrItens, "0302080005"), 2)
								lstrRefIndi = BuscaRefItem(lstrItens, "0302080099")
								'
								'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"'
								ldblCfop = CDbl(IIf(IsDbNull(.Fields("cfop").value), 0, .Fields("cfop").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"'
								lstrZona = VB6.Format(Trim(IIf(IsDbNull(.Fields("zona").value), "0", .Fields("zona").value)), "000")
								'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 = VB6.Format(Trim(IIf(IsDbNull(.Fields("livro").value), "0", .Fields("livro").value)), "00")
								'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 = VB6.Format(Trim(IIf(IsDbNull(.Fields("conta").value), "0", .Fields("conta").value)), "000000")
								'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"'
								lstrRota = VB6.Format(Trim(IIf(IsDbNull(.Fields("rota").value), "0", .Fields("rota").value)), "00000000")
								'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"'
								lstrCodClas = Trim(IIf(IsDbNull(.Fields("codclas").value), "0", .Fields("codclas").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"'
								lintDias = CShort(IIf(IsDbNull(.Fields("dias").value), 0, .Fields("dias").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"'
								ldteVcto = CDate(Trim(IIf(IsDbNull(.Fields("datavenc").value), "1900-01-01", .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"'
								ldteEmissao = CDate(Trim(IIf(IsDbNull(.Fields("dataem").value), "1900-01-01", .Fields("dataem").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"'
								ldteApreset = CDate(Trim(IIf(IsDbNull(.Fields("dataapr").value), "1900-01-01", .Fields("dataapr").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"'
								ldteProxLeit = CDate(Trim(IIf(IsDbNull(.Fields("dataproxleit").value), "1900-01-01", .Fields("dataproxleit").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"'
								ldteLeitAtu = CDate(Trim(IIf(IsDbNull(.Fields("dataleit").value), "1900-01-01", .Fields("dataleit").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"'
								ldteLeitAnt = CDate(Trim(IIf(IsDbNull(.Fields("dataleitant").value), "1900-01-01", .Fields("dataleitant").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"'
								lstrBancoFatur = Trim(IIf(IsDbNull(.Fields("banco_fatur").value), "0", .Fields("banco_fatur").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"'
								lstrBanIdent = Trim(IIf(IsDbNull(.Fields("banident").value), "0", .Fields("banident").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"'
								lstrCpfCnpj = Trim(IIf(IsDbNull(.Fields("cpf_cnpj").value), "", .Fields("cpf_cnpj").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"'
								lstrNumMedidor = Trim(IIf(IsDbNull(.Fields("num_med").value), "", .Fields("num_med").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"'
								ldblConstMedid = CDbl(IIf(IsDbNull(.Fields("const_med").value), 0, .Fields("const_med").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"'
								lstrFase = Trim(IIf(IsDbNull(.Fields("fase").value), "M", .Fields("fase").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"'
								lstrTensao = Trim(IIf(IsDbNull(.Fields("tensao").value), "220", .Fields("tensao").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"'
								lstrCodHash = Trim(IIf(IsDbNull(.Fields("codhash").value), "", .Fields("codhash").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"'
								lstrCodBarra = Trim(IIf(IsDbNull(.Fields("codbarra").value), "", .Fields("codbarra").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"'
								lstrDvCodBar = Trim(IIf(IsDbNull(.Fields("dvcodbarra").value), "", .Fields("dvcodbarra").value))
								'
								If lstrCodBarra = "" Then
									Call MontaCodBarras(ldblNumNf, lstrMesAno, ldblValorLiq, lstrZona, lstrLivro, lstrConta, lstrCodBarra, lstrDvCodBar)
								End If
								lstrSql = ""
								lstrSql = lstrSql & "SELECT * "
								lstrSql = lstrSql & "  FROM " & gstrDataBase & ".`unidb`"
								lstrSql = lstrSql & " WHERE `zona`  = '" & lstrZona & "' "
								lstrSql = lstrSql & "   AND `livro` = '" & lstrLivro & "' "
								lstrSql = lstrSql & "   AND `conta` = '" & lstrConta & "' "
								lstrSql = lstrSql & "   AND `unid_id` = " & llngUnidId & " "
								lstrSql = lstrSql & " LIMIT 0, 1 "
								Call Conectar(lstrSql, lrstAux, False)
								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"'
											lstrAgenc = Trim(IIf(IsDbNull(.Fields("agenc").value), "", .Fields("agenc").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"'
											lstrCc = Trim(IIf(IsDbNull(.Fields("cc").value), "", .Fields("cc").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"'
											lstrPagtoGov = Trim(IIf(IsDbNull(.Fields("pagto_governo").value), "N", .Fields("pagto_governo").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"'
											lstrNome = Trim(IIf(IsDbNull(.Fields("nome").value), "", .Fields("nome").value))
											'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
											lstrInsc = Trim(IIf(IsDbNull(.Fields("insc").value), "", .Fields("insc").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"'
											lstrRg = Trim(IIf(IsDbNull(.Fields("rg").value), "", .Fields("rg").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"'
											lstrRgOrgao = Trim(IIf(IsDbNull(.Fields("rg_orgao").value), "", .Fields("rg_orgao").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"'
											lstrRgUf = Trim(IIf(IsDbNull(.Fields("rg_uf").value), "", .Fields("rg_uf").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"'
											ldblSldArred = CDbl(IIf(IsDbNull(.Fields("arredonda_temp").value), 0, .Fields("arredonda_temp").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"'
											lstrUf = Trim(IIf(IsDbNull(.Fields("uf").value), "", .Fields("uf").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"'
											lstrCidade = Trim(IIf(IsDbNull(.Fields("cidade").value), "", .Fields("cidade").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"'
											lstrDistrito = Trim(IIf(IsDbNull(.Fields("distrito").value), "", .Fields("distrito").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"'
											lstrBairro = Trim(IIf(IsDbNull(.Fields("bairro").value), "", .Fields("bairro").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"'
											lstrEnd = Trim(IIf(IsDbNull(.Fields("end").value), "", .Fields("end").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"'
											lstrCompl = Trim(IIf(IsDbNull(.Fields("complement").value), "", .Fields("complement").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"'
											lstrQuadra = Trim(IIf(IsDbNull(.Fields("quadra").value), "", .Fields("quadra").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"'
											lstrLote = Trim(IIf(IsDbNull(.Fields("lote").value), "", .Fields("lote").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"'
											lstrNumero = Trim(IIf(IsDbNull(.Fields("numero").value), "", .Fields("numero").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"'
											lstrCep = Trim(IIf(IsDbNull(.Fields("cep").value), "", .Fields("cep").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"'
											lintEntrega = CShort(IIf(IsDbNull(.Fields("entrega").value), 0, .Fields("entrega").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"'
											lstrUfEnt = Trim(IIf(IsDbNull(.Fields("uf_entrega").value), "", .Fields("uf_entrega").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"'
											lstrCidEnt = Trim(IIf(IsDbNull(.Fields("cid_entrega").value), "", .Fields("cid_entrega").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"'
											lstrDisEnt = Trim(IIf(IsDbNull(.Fields("dis_entrega").value), "", .Fields("dis_entrega").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"'
											lstrBaiEnt = Trim(IIf(IsDbNull(.Fields("bai_entrega").value), "", .Fields("bai_entrega").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"'
											lstrEndEnt = Trim(IIf(IsDbNull(.Fields("end_entrega").value), "", .Fields("end_entrega").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"'
											lstrComEnt = Trim(IIf(IsDbNull(.Fields("compl_entrega").value), "", .Fields("compl_entrega").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"'
											lstrQuaEnt = Trim(IIf(IsDbNull(.Fields("qua_entrega").value), "", .Fields("qua_entrega").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"'
											lstrLotEnt = Trim(IIf(IsDbNull(.Fields("lot_entrega").value), "", .Fields("lot_entrega").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"'
											lstrNumEnt = Trim(IIf(IsDbNull(.Fields("num_entrega").value), "", .Fields("num_entrega").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"'
											lstrCepEnt = Trim(IIf(IsDbNull(.Fields("cep_entrega").value), "", .Fields("cep_entrega").value))
										End If
										Call .Close()
									End If
								End With
								lstrDsClas = BuscaDescricaoClasse(lstrCodClas)
								ldblMaiorCons = 0
								ldblMenorCons = 99999999
								ldblValorPed = 0
								lintQutdePed = 0
								ldblMed3Meses = 0
								lintMed3Meses = 0
								For lintCtrl = 1 To 12
									lstrHMesAno(lintCtrl) = "00/0000"
									lintHDiasCo(lintCtrl) = 0
									lintHOMedia(lintCtrl) = 0
									ldteHPagame(lintCtrl) = CDate("01/01/1900")
									ldblHConsum(lintCtrl) = 0
									ldblHLeitur(lintCtrl) = 0
									ldblHVlrFat(lintCtrl) = 0
								Next lintCtrl
								lintCtrl = 1
								lstrSql = ""
								lstrSql = lstrSql & "  SELECT * "
								lstrSql = lstrSql & "    FROM " & gstrDataBase & ".nf "
								lstrSql = lstrSql & "   WHERE `flgst` <> 'C'"
								lstrSql = lstrSql & "     AND `zona`  = '" & lstrZona & "' "
								lstrSql = lstrSql & "     AND `livro` = '" & lstrLivro & "' "
								lstrSql = lstrSql & "     AND `conta` = '" & lstrConta & "' "
								lstrSql = lstrSql & "     AND `unid_id` = " & llngUnidId & " "
								lstrSql = lstrSql & "     AND `mesano_ref` < " & CInt(VB.Right(lstrMesAno, 4) & VB.Left(lstrMesAno, 2)) & " "
								lstrSql = lstrSql & "ORDER BY `mesano_ref` DESC "
								lstrSql = lstrSql & "   LIMIT 0, 12"
								Call Conectar(lstrSql, lrstAux, False)
								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"'
												lstrMesAnoH = 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"'
												ldblVlrAuxH = CDbl(IIf(IsDbNull(.Fields("valorliq").value), 0, .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"'
												ldblVlrFatH = CDbl(IIf(IsDbNull(.Fields("valortot").value), 0, .Fields("valortot").value))
												ldblVlrFatH = IIf(ldblVlrAuxH <> 0, ldblVlrAuxH, ldblVlrFatH)
												'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"'
												ldtePgentoH = CDate(IIf(IsDbNull(.Fields("datapag").value Or .Fields("datapag").Value = "0000-00-00"), "1900-01-01", .Fields("datapag").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"'
												lstrDiasCoH = IIf(IsDbNull(.Fields("dias").value), 0, .Fields("dias").value)
												lintDiasCoH = CShort(IIf(IsNumeric(lstrDiasCoH), lstrDiasCoH, 0))
												'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"'
												lstrItens = Trim(IIf(IsDbNull(.Fields("itensserv").value), "", .Fields("itensserv").value))
												If lstrItens <> "" Then
													ldblConsumH = BuscaVlrItem(lstrItens, "030201008") + BuscaVlrItem(lstrItens, "0302010044")
													ldblLeiturH = BuscaVlrItem(lstrItens, "0302990039")
													lintOcMediH = BuscaVlrItem(lstrItens, "90410000")
													If ldblConsumH > ldblMaiorCons Then
														ldblMaiorCons = ldblConsumH
														lstrMesMaiorC = lstrMesAnoH
													End If
													If ldblConsumH < ldblMenorCons Then
														ldblMenorCons = ldblConsumH
														lstrMesMenorC = lstrMesAnoH
													End If
												Else
													ldblConsumH = 0
													ldblLeiturH = 0
													lintOcMediH = 0
												End If
												If ldtePgentoH = CDate("01/01/1900") Then
													ldblValorPed = ldblValorPed + ldblVlrFatH
													lintQutdePed = lintQutdePed + 1
												End If
												If lintCtrl <= 2 Then
													ldblMed3Meses = ldblMed3Meses + ldblConsumH
													lintMed3Meses = lintMed3Meses + 1
												End If
												lstrHMesAno(lintCtrl) = lstrMesAnoH
												lintHDiasCo(lintCtrl) = lintDiasCoH
												lintHOMedia(lintCtrl) = lintOcMediH
												ldteHPagame(lintCtrl) = ldtePgentoH
												ldblHConsum(lintCtrl) = ldblConsumH
												ldblHLeitur(lintCtrl) = ldblLeiturH
												ldblHVlrFat(lintCtrl) = ldblVlrFatH
												Call .MoveNext()
												lintCtrl = lintCtrl + 1
											End While
										End If
										Call .Close()
									End If
								End With
								If (ldblConsumo + ldblReservado) > ldblMaiorCons Then
									ldblMaiorCons = (ldblConsumo + ldblReservado)
								End If
								If (ldblConsumo + ldblReservado) < ldblMenorCons Then
									ldblMenorCons = (ldblConsumo + ldblReservado)
								End If
								ldblMed3Meses = ldblMed3Meses + (ldblConsumo + ldblReservado)
								lintMed3Meses = lintMed3Meses + 1
								'
								lstrSql = ""
								lstrSql = lstrSql & "INSERT INTO " & gstrDataBaseSite & ".nss_faturasnet SET " & vbCrLf
								lstrSql = lstrSql & "            numnf          = " & ldblNumNf & ", " & vbCrLf
								lstrSql = lstrSql & "            mesano         = '" & lstrMesAno & "', " & vbCrLf
								lstrSql = lstrSql & "            cfop           = " & Replace(CStr(ldblCfop), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            zona           = '" & lstrZona & "', " & vbCrLf
								lstrSql = lstrSql & "            livro          = '" & lstrLivro & "', " & vbCrLf
								lstrSql = lstrSql & "            conta          = '" & lstrConta & "', " & vbCrLf
								lstrSql = lstrSql & "            rota           = '" & lstrRota & "', " & vbCrLf
								lstrSql = lstrSql & "            codclas        = '" & lstrCodClas & "', " & vbCrLf
								lstrSql = lstrSql & "            datavenc       = '" & VB6.Format(IIf(ldteVcto = CDate("01/01/1900"), "0000-00-00", ldteVcto), "yyyy-MM-dd") & "', " & vbCrLf
								lstrSql = lstrSql & "            dataemissao    = '" & VB6.Format(IIf(ldteEmissao = CDate("01/01/1900"), "0000-00-00", ldteEmissao), "yyyy-MM-dd") & "', " & vbCrLf
								lstrSql = lstrSql & "            dataapr        = '" & VB6.Format(IIf(ldteApreset = CDate("01/01/1900"), "0000-00-00", ldteApreset), "yyyy-MM-dd") & "', " & vbCrLf
								lstrSql = lstrSql & "            dataproxleit   = '" & VB6.Format(IIf(ldteProxLeit = CDate("01/01/1900"), "0000-00-00", ldteProxLeit), "yyyy-MM-dd") & "', " & vbCrLf
								lstrSql = lstrSql & "            dataleit       = '" & VB6.Format(IIf(ldteLeitAtu = CDate("01/01/1900"), "0000-00-00", ldteLeitAtu), "yyyy-MM-dd") & "', " & vbCrLf
								lstrSql = lstrSql & "            dataleitant    = '" & VB6.Format(IIf(ldteLeitAnt = CDate("01/01/1900"), "0000-00-00", ldteLeitAnt), "yyyy-MM-dd") & "', " & vbCrLf
								lstrSql = lstrSql & "            banco_fatur    = '" & lstrBancoFatur & "', " & vbCrLf
								lstrSql = lstrSql & "            banident       = """ & lstrBanIdent & """, " & vbCrLf
								lstrSql = lstrSql & "            cpf_cnpj       = '" & lstrCpfCnpj & "', " & vbCrLf
								lstrSql = lstrSql & "            num_med        = '" & lstrNumMedidor & "', " & vbCrLf
								lstrSql = lstrSql & "            const_med      = " & Replace(CStr(ldblConstMedid), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            fase           = '" & lstrFase & "', " & vbCrLf
								lstrSql = lstrSql & "            ta             = '" & lstrTa & "', " & vbCrLf
								lstrSql = lstrSql & "            tensao         = '" & lstrTensao & "', " & vbCrLf
								lstrSql = lstrSql & "            codhash        = '" & lstrCodHash & "', " & vbCrLf
								lstrSql = lstrSql & "            valortot       = " & Replace(CStr(ldblValorTot), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            valorliq       = " & Replace(CStr(ldblValorLiq), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            codbarra       = '" & lstrCodBarra & "', " & vbCrLf
								lstrSql = lstrSql & "            dvcodbarra     = '" & lstrDvCodBar & "', " & vbCrLf
								lstrSql = lstrSql & "            diasconsumo        = " & lintDias & ", " & vbCrLf
								lstrSql = lstrSql & "            vlrdiario          = " & Replace(CStr(Arredondar(ldblVlrConFat / IIf(lintDias = 0, 1, lintDias), 2)), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            mediaconsumodiario = " & Replace(CStr(Arredondar(ldblConsumFat / IIf(lintDias = 0, 1, lintDias), 2)), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            maiorconsumo       = " & Replace(CStr(ldblMaiorCons), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            menorconsumo       = " & Replace(CStr(ldblMenorCons), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            mesmaiorconsumo    = '" & lstrMesMaiorC & "', " & vbCrLf
								lstrSql = lstrSql & "            mesmenorconsumo    = '" & lstrMesMenorC & "', " & vbCrLf
								lstrSql = lstrSql & "            valorpend          = " & Replace(CStr(ldblValorPed), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            totalpend          = " & lintQutdePed & ", " & vbCrLf
								lstrSql = lstrSql & "            mediaconsumo3meses = " & Replace(CStr(Arredondar(ldblMed3Meses / lintMed3Meses, 2)), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            ocorrencia         = " & lintMedOcorrencia & ", " & vbCrLf
								lstrSql = lstrSql & "            descocorrencia     = '" & lstrDesOcorrencia & "', " & vbCrLf
								lstrSql = lstrSql & "            consfaturado        = " & Replace(CStr(ldblConsumFat), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            conslido            = " & Replace(CStr(ldblConsumo), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            valorconsumo        = " & Replace(CStr(ldblVlrConFat), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            consumoreservado    = " & Replace(CStr(ldblReservado), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            LeitReservadoAtu    = " & Replace(CStr(ldblLeitReservadoAtu), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            LeitReservadoAnt    = " & Replace(CStr(ldblLeitReservadoAnt), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            vlrconsumoreservado = " & Replace(CStr(ldblVlrConsumoReserv), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            baseicms      = " & Replace(CStr(ldblBaseIcms), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            aliqicms      = " & Replace(CStr(ldblAliqIcms), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            vlricms       = " & Replace(CStr(ldblVlrIcms), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            baseicms1     = " & Replace(CStr(ldblBaseIcms1), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            aliqicms1     = " & Replace(CStr(ldblAliqIcms1), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            vlricms1      = " & Replace(CStr(ldblVlrIcms1), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            basepis       = " & Replace(CStr(ldblBasePis), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            aliqpis       = " & Replace(CStr(ldblAliqPis), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            vlrpis        = " & Replace(CStr(ldblVlrPis), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            basecofins    = " & Replace(CStr(ldblBaseCofins), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            aliqcofins    = " & Replace(CStr(ldblAliqCofins), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            vlrcofins     = " & Replace(CStr(ldblVlrCofins), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            vlrconsutrib  = " & Replace(CStr(ldblVlrIcms + ldblVlrIcms1 + ldblVlrPis + ldblVlrCofins + ldblVlrConFat), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            baseicmstotal = " & Replace(CStr(ldblBasIcmsTotal), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            vlricmstotal  = " & Replace(CStr(ldblVlrIcmsTotal), ",", ".") & ", " & vbCrLf
								'indicadodres de continuidade
								lstrSql = lstrSql & "            dec_meta     = " & Replace(CStr(ldblDecMeta), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            dec_rea      = " & Replace(CStr(ldblDecReal), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            fec_meta     = " & Replace(CStr(ldblFecMeta), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            fec_rea      = " & Replace(CStr(ldblFecReal), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            dic_meta     = " & Replace(CStr(ldblDicMeta), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            dic_rea      = " & Replace(CStr(ldblDicReal), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            fic_meta     = " & Replace(CStr(ldblFicMeta), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            fic_rea      = " & Replace(CStr(ldblFicReal), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            dmic         = " & Replace(CStr(ldblDmicMet), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            dmicM        = " & Replace(CStr(ldblDmicRea), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            refindicador = '" & lstrRefIndi & "', " & vbCrLf
								lstrSql = lstrSql & "            conjunto     = 'eflul'," & vbCrLf
								'rentenção
								lstrSql = lstrSql & "            ret_irpj   = " & Replace(CStr(ldblRetIrpj), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            ret_pis    = " & Replace(CStr(ldblRetPis), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            ret_csll   = " & Replace(CStr(ldblRetCsll), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            ret_cofins = " & Replace(CStr(ldblRetCofins), ",", ".") & ", " & vbCrLf
								'componentes da tarifa e da fatura
								lstrSql = lstrSql & "            comp_energia            = " & Replace(CStr(ldblCompEnergia), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            comp_transmissao        = " & Replace(CStr(ldblCompTransmissao), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            comp_distribuicao       = " & Replace(CStr(ldblCompDistribuicao), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            comp_encargos_setoriais = " & Replace(CStr(ldblCompEncargosSetoriais), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            comp_outros             = " & Replace(CStr(ldblCompOutros), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            leituraant             = " & Replace(CStr(ldblLeituraAnt), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            leit                   = " & Replace(CStr(ldblLeituraAtu), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            leitura_kvarh_anterior = " & Replace(CStr(ldblLeituraKvarhAnt), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            leitura_kvarh_atual    = " & Replace(CStr(ldblLeituraKvarhAtu), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            consumo_kvarh          = " & Replace(CStr(ldblConsumoKvarh), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            fp                     = " & Replace(CStr(ldblFp), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            agenc = '" & lstrAgenc & "', " & vbCrLf
								lstrSql = lstrSql & "            cc    = '" & lstrCc & "' , " & vbCrLf
								lstrSql = lstrSql & "            pagto_governo = '" & lstrPagtoGov & "', " & vbCrLf
								lstrSql = lstrSql & "            NomeCons    = """ & lstrNome & """, " & vbCrLf
								lstrSql = lstrSql & "            RefCons     = """ & lstrNome & """, " & vbCrLf
								lstrSql = lstrSql & "            insc        = '" & lstrInsc & "', " & vbCrLf
								lstrSql = lstrSql & "            rg          = '" & lstrRg & " " & lstrRgOrgao & " " & lstrRgUf & "', " & vbCrLf
								lstrSql = lstrSql & "            saldo_arred = " & Replace(CStr(ldblSldArred), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            uf          = '" & lstrUf & "', " & vbCrLf
								lstrSql = lstrSql & "            cidade      = """ & lstrCidade & """, " & vbCrLf
								lstrSql = lstrSql & "            distrito    = """ & lstrDistrito & """, " & vbCrLf
								lstrSql = lstrSql & "            Bairro      = """ & lstrBairro & """, " & vbCrLf
								lstrSql = lstrSql & "            logradouro  = """ & lstrEnd & """, " & vbCrLf
								lstrSql = lstrSql & "            complemento = """ & lstrCompl & IIf(Len(lstrQuadra) > 0, " Q- " & lstrQuadra, "") & IIf(Len(lstrLote) > 0, " L- " & lstrLote, "") & IIf(Len(lstrNumero) > 0, " Nº " & lstrNumero, "") & """, " & vbCrLf
								lstrSql = lstrSql & "            cep         = '" & lstrCep & "', " & vbCrLf
								lstrSql = lstrSql & "            entrega     = " & lintEntrega & ", " & vbCrLf
								lstrSql = lstrSql & "            uf_entrega  = '" & lstrUfEnt & "', " & vbCrLf
								lstrSql = lstrSql & "            cid_entrega = """ & lstrCidEnt & """, " & vbCrLf
								lstrSql = lstrSql & "            dis_entrega = """ & lstrDisEnt & """, " & vbCrLf
								lstrSql = lstrSql & "            bai_entrega = """ & lstrBaiEnt & """, " & vbCrLf
								lstrSql = lstrSql & "            log_entrega = """ & lstrEndEnt & """, " & vbCrLf
								lstrSql = lstrSql & "            com_entrega = """ & lstrComEnt & IIf(Len(lstrQuaEnt) > 0, " Q- " & lstrQuaEnt, "") & IIf(Len(lstrLotEnt) > 0, " L- " & lstrLotEnt, "") & IIf(Len(lstrNumEnt) > 0, " Nº " & lstrNumEnt, "") & """, " & vbCrLf
								lstrSql = lstrSql & "            cep_entrega = '" & lstrCepEnt & "', " & vbCrLf
								lstrSql = lstrSql & "            itens_fatura = '" & lstrIteImp & "', " & vbCrLf
								For lintCtrl = 1 To 12
									lstrSql = lstrSql & "            hist_mes_ano" & VB6.Format(lintCtrl, "00") & " = '" & lstrHMesAno(lintCtrl) & "', " & vbCrLf
									lstrSql = lstrSql & "            hist_diascon" & VB6.Format(lintCtrl, "00") & " = " & lintHDiasCo(lintCtrl) & ", " & vbCrLf
									lstrSql = lstrSql & "            hist_datpgto" & VB6.Format(lintCtrl, "00") & " = '" & VB6.Format(IIf(ldteHPagame(lintCtrl) = CDate("01/01/1900"), "0000-00-00", ldteHPagame(lintCtrl)), "yyyy-MM-dd") & "', " & vbCrLf
									lstrSql = lstrSql & "            hist_consumo" & VB6.Format(lintCtrl, "00") & " = " & Replace(CStr(ldblHConsum(lintCtrl)), ",", ".") & ", " & vbCrLf
									lstrSql = lstrSql & "            hist_leitura" & VB6.Format(lintCtrl, "00") & " = " & Replace(CStr(ldblHLeitur(lintCtrl)), ",", ".") & ", " & vbCrLf
									lstrSql = lstrSql & "            hist_vlrfatu" & VB6.Format(lintCtrl, "00") & " = " & Replace(CStr(ldblHVlrFat(lintCtrl)), ",", ".") & ", " & vbCrLf
									lstrSql = lstrSql & "            hist_ocorren" & VB6.Format(lintCtrl, "00") & " = " & lintHOMedia(lintCtrl) & ", " & vbCrLf
								Next lintCtrl
								lstrSql = lstrSql & "            descclasse  = """ & lstrDsClas & """ "
								lblnErroExecuta = Executar(lstrSql, False)
								'lblnErroExecuta = ExecutarSite(lstrSql)
							Else
								Call .MoveLast()
							End If
						End If ' Verifica se ja tem no site
						Call .MoveNext()
						Call BarraProgresso(ProgressBar, lblPerc, lblInfo, 1,  , " Enviando faturas para site")
					End While
				End If
				Call .Close()
			End If
			'Call MsgBox("As Faturas foram Importadas com sucesso.", vbInformation, gstrTituloMensagem)
		End With
		'UPGRADE_NOTE: Object lrstFat 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"'
		lrstFat = Nothing
		'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 cmdFechar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFechar.Click
		Call Me.Close()
	End Sub
	
	Private Sub frmAtualizaSite_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		'gstrDataBaseSite = gstrDataBase
		Me.dtpMesAno.value = BuscaDataBD
		Call Me.lsbLog.Items.Clear()
	End Sub
	
	Private Sub Seta_Log(ByVal astrTexto As String)
		Call Me.lsbLog.Items.Add(astrTexto)
		System.Windows.Forms.Application.DoEvents()
	End Sub
End Class