Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmRelAbertos
	Inherits System.Windows.Forms.Form
	
	'UPGRADE_WARNING: Event chkCortados.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 chkCortados_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkCortados.CheckStateChanged
		If Me.chkLigados.CheckState = 0 And Me.chkDesligados.CheckState = 0 And Me.chkCortados.CheckState = 0 And Me.chkDesativados.CheckState = 0 Then
			Me.chkCortados.CheckState = System.Windows.Forms.CheckState.Checked
		End If
	End Sub
	
	'UPGRADE_WARNING: Event chkDesativados.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 chkDesativados_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkDesativados.CheckStateChanged
		If Me.chkLigados.CheckState = 0 And Me.chkDesligados.CheckState = 0 And Me.chkCortados.CheckState = 0 And Me.chkDesativados.CheckState = 0 Then
			Me.chkDesativados.CheckState = System.Windows.Forms.CheckState.Checked
		End If
	End Sub
	
	'UPGRADE_WARNING: Event chkDesligados.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 chkDesligados_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkDesligados.CheckStateChanged
		If Me.chkLigados.CheckState = 0 And Me.chkDesligados.CheckState = 0 And Me.chkCortados.CheckState = 0 And Me.chkDesativados.CheckState = 0 Then
			Me.chkDesligados.CheckState = System.Windows.Forms.CheckState.Checked
		End If
	End Sub
	
	'UPGRADE_WARNING: Event chkGrupoA.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 chkGrupoA_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkGrupoA.CheckStateChanged
		If Me.chkGrupoA.CheckState = 0 Then
			Me.chkGrupoB.CheckState = System.Windows.Forms.CheckState.Checked
		End If
	End Sub
	
	'UPGRADE_WARNING: Event chkGrupoB.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 chkGrupoB_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkGrupoB.CheckStateChanged
		If Me.chkGrupoB.CheckState = 0 Then
			Me.chkGrupoA.CheckState = System.Windows.Forms.CheckState.Checked
		End If
	End Sub
	
	'UPGRADE_WARNING: Event chkLigados.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 chkLigados_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkLigados.CheckStateChanged
		If Me.chkLigados.CheckState = 0 And Me.chkDesligados.CheckState = 0 And Me.chkCortados.CheckState = 0 And Me.chkDesativados.CheckState = 0 Then
			Me.chkLigados.CheckState = System.Windows.Forms.CheckState.Checked
		End If
	End Sub
	
	'UPGRADE_WARNING: Event chkSomenteTranTit.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 chkSomenteTranTit_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkSomenteTranTit.CheckStateChanged
		If Me.chkSomenteTranTit.CheckState = System.Windows.Forms.CheckState.Checked Then
			Me.chkTransfTit.CheckState = System.Windows.Forms.CheckState.Checked
			Me.chkTransfTit.Enabled = False
		Else
			Me.chkTransfTit.CheckState = System.Windows.Forms.CheckState.Unchecked
			Me.chkTransfTit.Enabled = True
		End If
	End Sub
	
	Private Sub cmdEmitir_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdEmitir.Click
		Dim lblnGravou As Boolean
		Dim lblnContinua As Boolean
		Dim lintConta As Short
		Dim lstrFiltro As String
		Dim lstrFiltro2 As String
		Dim lstrSql As String
		Dim lrstFaturas As ADODB.Recordset
		Dim lrstConsulta As ADODB.Recordset
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim lstrRota As String
		Dim lstrCdClasse As String
		Dim lstrNmClasse As String
		Dim lstrFase As String
		Dim ldblNumNf As Double
		Dim lstrMesAno As String
		Dim lstrGrTarifa As String
		Dim ldblValorTot As Double
		Dim ldblValorLiq As Double
		Dim llngConsId As Integer
		Dim llngConsId2 As Integer
		Dim llngUnidId As Integer
		Dim lstrNome As String
		Dim lstrLogradouro As String
		Dim lstrNumero As String
		Dim lstrBairro As String
		Dim lstrQuadra As String
		Dim lstrLote As String
		Dim lstrComplemento As String
		Dim lstrCidade As String
		Dim lstrDistrito As String
		Dim lstrCep As String
		Dim lstrUf As String
		Dim lstrSituacao As String
		Dim lstrMedidor As String
		Dim ldteVencimento As Date
		Dim lstrCriterio As String
		Dim lstrAuxiliar As String
		Dim lstrFlgSit As String
		
		lrstFaturas = New ADODB.Recordset
		lrstConsulta = New ADODB.Recordset
		Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
		lblnGravou = False
		Me.fmeAux(0).Enabled = False
		Me.cmdEmitir.Enabled = False
		Me.cmdFechar.Enabled = False
		lstrSql = ""
		lstrSql = lstrSql & "DELETE FROM temp_abertos "
		lstrSql = lstrSql & " WHERE nomemaquina = """ & gstrNmEstacao & """ "
		Call Executar(lstrSql)
		
		Me.lblInfo.Text = "Selecionando as faturas, aguarde....!"
		Call Me.lblInfo.Refresh()
		lstrSql = ""
		lstrSql = lstrSql & "SELECT `nf`.`zona`, " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`livro`, " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`conta`, " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`cons_id`, " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`unid_id`, " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`rota`, " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`codclas`, " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`fase`, " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`numnf`, " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`mesano`, " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`mesano_ref`, " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`valortot`, " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`valorliq`, " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`ta`, " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`datavenc`, " & vbCrLf
		lstrSql = lstrSql & "       `nf`.`flgst` " & vbCrLf
		lstrSql = lstrSql & "  FROM `nf` " & vbCrLf
		'Vencidos
		If Me.opbVencidos.Checked Then
			lstrSql = lstrSql & " WHERE `nf`.`datavenc` BETWEEN '" & VB6.Format(Me.dtpInicio.value, "yyyy-MM-dd") & "' AND '" & VB6.Format(Me.dtpFinal.value, "yyyy-MM-dd") & "' " & vbCrLf
			lstrSql = lstrSql & "   AND (`nf`.`flgst` <> 'C' OR (`nf`.`flgst` = 'C' AND `nf`.`datast` > '" & VB6.Format(Me.dtpFinal.value, "yyyy-MM-dd") & "')) "
			If Me.chkTipo.CheckState = 1 Then
				lstrSql = lstrSql & "   AND `nf`.`flgst` IN(''"
				If Me.chkJudice.CheckState = 1 Then
					lstrSql = lstrSql & ",'J'"
				End If
				If Me.chkReserva.CheckState = 1 Then
					lstrSql = lstrSql & ",'R'"
				End If
				lstrSql = lstrSql & ") " & vbCrLf
			Else
				lstrSql = lstrSql & " AND (`nf`.`datapag` > '" & VB6.Format(Me.dtpFinal.value, "yyyy-MM-dd") & "' OR `nf`.`datapag` = '0000-00-00') " & vbCrLf
			End If
		ElseIf Me.opbArrecadados.Checked Then 
			lstrSql = lstrSql & " WHERE (`nf`.`datapag` BETWEEN '" & VB6.Format(Me.dtpInicio.value, "yyyy-MM-dd") & "' AND '" & VB6.Format(Me.dtpFinal.value, "yyyy-MM-dd") & "') " & vbCrLf
			lstrSql = lstrSql & "   AND (`nf`.`flgst` <> 'C' OR (`nf`.`flgst` = 'C' AND `nf`.`datast` > '" & VB6.Format(Me.dtpFinal.value, "yyyy-MM-dd") & "')) "
			lstrSql = lstrSql & "   AND `nf`.`flgst` IN('P') " & vbCrLf
			If Me.chkMesAno.CheckState = 1 Then
				lstrSql = lstrSql & "   AND `nf`.`mesano_ref` = " & CInt(VB6.Format(Me.dtpMesAno.value, "yyyymm")) & " " & vbCrLf
			End If
		ElseIf Me.opbAbertos.Checked Then 
			lstrSql = lstrSql & " WHERE mesano_ref <= " & CInt(VB6.Format(Me.dtpFinal.value, "yyyymm")) & " " & vbCrLf
			lstrSql = lstrSql & "   AND (`nf`.`flgst` <> 'C' OR (`nf`.`flgst` = 'C' AND `nf`.`datast` > '" & VB6.Format(Me.dtpFinal.value, "yyyy-MM-dd") & "')) "
			lstrSql = lstrSql & "   AND NOT EXISTS(SELECT * FROM `reserva` "
			lstrSql = lstrSql & "                   WHERE `reserva`.`numnf`    = `nf`.`numnf` "
			lstrSql = lstrSql & "                     AND `reserva`.`mesano`   = `nf`.`mesano` "
			lstrSql = lstrSql & "                     AND `reserva`.`zona`     = `nf`.`zona` "
			lstrSql = lstrSql & "                     AND `reserva`.`livro`    = `nf`.`livro` "
			lstrSql = lstrSql & "                     AND `reserva`.`conta`    = `nf`.`conta` "
			lstrSql = lstrSql & "                     AND `reserva`.`datares` <= '" & VB6.Format(Me.dtpFinal.value, "yyyy-MM-dd") & "')"
			lstrSql = lstrSql & " AND (`nf`.`datapag` > '" & VB6.Format(Me.dtpFinal.value, "yyyy-MM-dd") & "' OR `nf`.`datapag` = '0000-00-00') " & vbCrLf
			If Me.chkMesAno.CheckState = 1 Then
				lstrSql = lstrSql & "   AND `nf`.`mesano_ref` <> " & CInt(VB6.Format(Me.dtpMesAno.value, "yyyymm")) & " " & vbCrLf
			End If
		End If
		If Me.chkGrupoA.CheckState = 1 Or Me.chkGrupoB.CheckState = 1 Then
			lstrSql = lstrSql & "   AND `nf`.`grupo` IN("
			If Me.chkGrupoA.CheckState = 1 Then
				lstrSql = lstrSql & "'A'"
			End If
			If Me.chkGrupoA.CheckState = 1 And Me.chkGrupoB.CheckState = 1 Then
				lstrSql = lstrSql & ","
			End If
			If Me.chkGrupoB.CheckState = 1 Then
				lstrSql = lstrSql & "'B'"
			End If
			lstrSql = lstrSql & ") " & vbCrLf
		End If
		If Me.chkJudice.CheckState = 0 And Me.chkReserva.CheckState = 0 Then
			lstrSql = lstrSql & "   AND `nf`.`flgst` NOT IN("
			If Me.chkJudice.CheckState = 0 Then
				lstrSql = lstrSql & "'J'"
			End If
			If Me.chkJudice.CheckState = 0 And Me.chkReserva.CheckState = 0 Then
				lstrSql = lstrSql & ","
			End If
			If Me.chkReserva.CheckState = 0 Then
				lstrSql = lstrSql & "'R'"
			End If
			lstrSql = lstrSql & ") " & vbCrLf
		End If
		
		If IsNumeric(txtValor.Text) Then
			lstrSql = lstrSql & " and nf.valorliq >= " & Replace(txtValor.Text, ",", ".")
		End If
		
		
		With Me.lvsClasses
			'UPGRADE_WARNING: Lower bound of collection Me.lvsClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
			If .Items.Item(1).Checked = False Then
				lstrFiltro = "   AND ("
				For lintConta = 2 To .Items.Count
					'UPGRADE_WARNING: Lower bound of collection Me.lvsClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
					If .Items.Item(lintConta).Checked = True Then
						'UPGRADE_WARNING: Lower bound of collection Me.lvsClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
						'UPGRADE_WARNING: Lower bound of collection Me.lvsClasses.ListItems.Item() has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
						lstrFiltro = lstrFiltro & " LEFT(`nf`.`codclas`," & Len(Trim(Str_Retira(.Items.Item(lintConta).SubItems(1).Text, "<="))) & ")" & .Items.Item(lintConta).SubItems(1).Text & " OR "
						'UPGRADE_WARNING: Lower bound of collection Me.lvsClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
						If Trim(.Items.Item(lintConta).Text) = "Industrial" And .Items.Item(4).Checked = False Then
							lstrFiltro2 = " AND `nf`.`codclas` <> ""0100"" AND"
						Else
							lstrFiltro2 = "    "
						End If
					End If
				Next lintConta
				If lstrFiltro = " (" Then
					lstrFiltro = ""
					lstrFiltro2 = "    "
				End If
				lstrFiltro = VB.Left(lstrFiltro, Len(lstrFiltro) - 3) & ") "
			Else
				lstrFiltro = ""
				lstrFiltro2 = "    "
			End If
		End With
		lstrSql = lstrSql & lstrFiltro & lstrFiltro2
		lstrSql = VB.Left(lstrSql, Len(lstrSql) - 4)
		Call Conectar(lstrSql, lrstFaturas)
		System.Windows.Forms.Application.DoEvents()
		If lrstFaturas.RecordCount > 0 Then
			Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, lrstFaturas.RecordCount)
			While Not lrstFaturas.EOF
				With lrstFaturas
					'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"'
					llngConsId = 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 = 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"'
					lstrRota = Trim(IIf(IsDbNull(.Fields("rota").value), "", .Fields("rota").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"'
					lstrCdClasse = Trim(IIf(IsDbNull(.Fields("codclas").value), "", .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"'
					lstrFase = Trim(IIf(IsDbNull(.Fields("fase").value), "", .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"'
					ldblNumNf = 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))
					'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 = 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 = 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"'
					lstrGrTarifa = Trim(IIf(IsDbNull(.Fields("ta").value), "", .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"'
					ldteVencimento = IIf(IsDbNull(.Fields("datavenc").value), "", .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"'
					lstrFlgSit = Trim(IIf(IsDbNull(.Fields("flgst").value), "", .Fields("flgst").value))
				End With
				If Len(lstrRota) > 0 Then
					lstrRota = VB.Left(lstrRota, 4) & "." & VB.Right(lstrRota, 4)
				End If
				If Len(lstrGrTarifa) > 0 Then
					lstrGrTarifa = Mid(lstrGrTarifa, 3, 2)
				End If
				Select Case VB.Left(lstrCdClasse, 1)
					Case Is < CStr(4)
						lstrNmClasse = "04 - Industrial"
					Case Is = CStr(4)
						lstrNmClasse = "03 - Comercial"
					Case Is = CStr(5)
						lstrNmClasse = "05 - Rural"
					Case Is = CStr(6)
						If CDbl(VB.Left(lstrCdClasse, 2)) = 64 Then
							lstrNmClasse = "07 - Ilum. Pública"
						Else
							lstrNmClasse = "06 - Poder Público"
						End If
					Case Is = CStr(7)
						lstrNmClasse = "08 - Serviço Público"
					Case Is = CStr(8)
						lstrNmClasse = "09 - Consumo Próprio"
					Case Is = CStr(9)
						If CDbl(VB.Right(lstrCdClasse, 1)) = 1 Then
							lstrNmClasse = "02 - Res. Normal"
						Else
							lstrNmClasse = "01 - Res. Bx.Renda"
						End If
				End Select
				llngConsId2 = 0
				lstrSql = "SELECT " & "       nome, " & "       end logradouro, " & "       numero, " & "       bairro, " & "       quadra, " & "       lote, " & "       complement complemento, " & "       cidade, " & "       distrito, " & "       cep, " & "       uf, " & "       situacao, " & "       cons_id, " & "       num medidor " & "  FROM unid" & LCase(VB.Left(lstrGrTarifa, 1)) & " WHERE unid_id = " & llngUnidId & " LIMIT 1 "
				Call Conectar(lstrSql, lrstConsulta)
				With lrstConsulta
					If .RecordCount > 0 Then
						While Not .EOF
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							llngConsId2 = 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"'
							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"'
							lstrLogradouro = Trim(IIf(IsDbNull(.Fields("logradouro").value), "", .Fields("logradouro").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"'
							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"'
							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"'
							lstrComplemento = Trim(IIf(IsDbNull(.Fields("complemento").value), "", .Fields("complemento").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"'
							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"'
							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"'
							lstrSituacao = Trim(IIf(IsDbNull(.Fields("situacao").value), "", .Fields("situacao").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"'
							lstrMedidor = Trim(IIf(IsDbNull(.Fields("medidor").value), "", .Fields("medidor").value))
							Call .MoveNext()
						End While
					End If
					If Me.chkSomenteTranTit.CheckState = System.Windows.Forms.CheckState.Checked Then
						If llngConsId <> llngConsId2 Then
							lblnContinua = True
						Else
							lblnContinua = False
						End If
					Else
						lblnContinua = True
					End If
					If llngConsId <> llngConsId2 Then
						If .State = 1 Then Call .Close()
						lstrSql = "SELECT " & "       nome, " & "       end logradouro, " & "       numero, " & "       bairro, " & "       quadra, " & "       lote, " & "       complement complemento, " & "       cidade, " & "       distrito, " & "       cep, " & "       uf " & "  FROM consum " & " WHERE consreg = " & llngConsId & " LIMIT 1 "
						Call Conectar(lstrSql, lrstConsulta)
						If .RecordCount > 0 Then
							While Not .EOF
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								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"'
								lstrLogradouro = Trim(IIf(IsDbNull(.Fields("logradouro").value), "", .Fields("logradouro").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"'
								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"'
								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"'
								lstrComplemento = Trim(IIf(IsDbNull(.Fields("complemento").value), "", .Fields("complemento").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"'
								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"'
								lstrUf = Trim(IIf(IsDbNull(.Fields("uf").value), "", .Fields("uf").value))
								'lstrSituacao = ""
								lstrMedidor = "TRANS.TIT."
								If Me.chkTransfTit.CheckState = System.Windows.Forms.CheckState.Checked Then
									lblnContinua = True
								Else
									lblnContinua = False
								End If
								Call .MoveNext()
							End While
						Else
							lstrNome = ""
							lstrLogradouro = ""
							lstrNumero = ""
							lstrBairro = ""
							lstrQuadra = ""
							lstrLote = ""
							lstrComplemento = ""
							lstrCidade = ""
							lstrDistrito = ""
							lstrCep = ""
							lstrUf = ""
							lstrSituacao = "D"
							lstrMedidor = ""
						End If
					End If
					If .State = 1 Then Call .Close()
				End With
				If lblnContinua Then
					lstrSql = ""
					lstrSql = lstrSql & "INSERT INTO temp_abertos SET "
					lstrSql = lstrSql & "             nomemaquina = """ & gstrNmEstacao & """, "
					lstrSql = lstrSql & "             zona        = """ & lstrZona & """, "
					lstrSql = lstrSql & "             livro       = """ & lstrLivro & """, "
					lstrSql = lstrSql & "             conta       = """ & lstrConta & """, "
					lstrSql = lstrSql & "             nome        = """ & lstrNome & """, "
					lstrSql = lstrSql & "             logradouro  = """ & lstrLogradouro & """, "
					lstrSql = lstrSql & "             numero      = """ & lstrNumero & """, "
					lstrSql = lstrSql & "             bairro      = """ & lstrBairro & """, "
					lstrSql = lstrSql & "             quadra      = """ & lstrQuadra & """, "
					lstrSql = lstrSql & "             lote        = """ & lstrLote & """, "
					lstrSql = lstrSql & "             complemento = """ & lstrComplemento & """, "
					lstrSql = lstrSql & "             cidade      = """ & lstrCidade & """, "
					lstrSql = lstrSql & "             distrito    = """ & lstrDistrito & """, "
					lstrSql = lstrSql & "             cep         = """ & lstrCep & """, "
					lstrSql = lstrSql & "             uf          = """ & lstrUf & """, "
					lstrSql = lstrSql & "             rota        = """ & lstrRota & """, "
					lstrSql = lstrSql & "             situacao    = """ & lstrSituacao & """, "
					lstrSql = lstrSql & "             medidor     = """ & lstrMedidor & """, "
					lstrSql = lstrSql & "             classe      = """ & lstrNmClasse & """, "
					lstrSql = lstrSql & "             fase        = """ & lstrFase & """, "
					lstrSql = lstrSql & "             numnf       = " & ldblNumNf & ", "
					lstrSql = lstrSql & "             mesano      = """ & lstrFlgSit & " " & lstrMesAno & """, "
					lstrSql = lstrSql & "             valortot    = " & Replace(CStr(ldblValorTot), ",", ".") & ", "
					lstrSql = lstrSql & "             valorliq    = " & Replace(CStr(ldblValorLiq), ",", ".") & ", "
					lstrSql = lstrSql & "             datavenc    = """ & VB6.Format(ldteVencimento, "yyyy-MM-dd") & """, "
					lstrSql = lstrSql & "             datasele    = """ & VB6.Format(Me.dtpInicio.value, "yyyy-MM-dd") & """, "
					lstrSql = lstrSql & "             dataselef   = """ & VB6.Format(Me.dtpFinal.value, "yyyy-MM-dd") & """, "
					lstrSql = lstrSql & "             grupo       = """ & lstrGrTarifa & """; "
					Call Executar(lstrSql)
				End If
				Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
				Call lrstFaturas.MoveNext()
				System.Windows.Forms.Application.DoEvents()
			End While
		End If
		If lrstFaturas.State = 1 Then Call lrstFaturas.Close()
		'UPGRADE_NOTE: Object lrstFaturas 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"'
		lrstFaturas = Nothing
		If lrstConsulta.State = 1 Then Call lrstConsulta.Close()
		'UPGRADE_NOTE: Object lrstConsulta may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstConsulta = Nothing
		
		lstrCriterio = "{temp_abertos.nomemaquina} = """ & gstrNmEstacao & """ "
		lstrAuxiliar = ""
		If Me.chkLigados.CheckState = 1 Then
			lstrAuxiliar = lstrAuxiliar & " {temp_abertos.situacao} = ""L"" OR"
		End If
		If Me.chkDesligados.CheckState = 1 Then
			lstrAuxiliar = lstrAuxiliar & " {temp_abertos.situacao} = ""D"" OR"
		End If
		If Me.chkCortados.CheckState = 1 Then
			lstrAuxiliar = lstrAuxiliar & " {temp_abertos.situacao} = ""C"" OR"
		End If
		If Me.chkDesativados.CheckState = 1 Then
			lstrAuxiliar = lstrAuxiliar & " {temp_abertos.situacao} = ""I"" OR"
		End If
		If Len(Trim(lstrAuxiliar)) > 0 Then
			lstrAuxiliar = " AND  (" & VB.Left(lstrAuxiliar, Len(lstrAuxiliar) - 2) & ") "
		Else
			lstrAuxiliar = ""
		End If
		lstrCriterio = lstrCriterio & lstrAuxiliar
		With Me.crpAux
			.ReportFileName = My.Application.Info.DirectoryPath & "\" & LeConfig("DIR_RPT") & "Abertos.rpt"
			.DiscardSavedData = True
			.WindowState = Crystal.WindowStateConstants.crptMaximized
			.WindowControlBox = True
			.WindowControls = True
			.WindowShowPrintSetupBtn = True
			.WindowShowCloseBtn = True
			.WindowShowSearchBtn = True
			.SelectionFormula = lstrCriterio
			.WindowTitle = "Relatório dos em Aberto"
			.Destination = Crystal.DestinationConstants.crptToWindow
			.set_Formulas(1, "SinteticoAnalitico = " & IIf(Me.opbSintetico.Checked, 1, 0))
			lstrAuxiliar = " Grupo ("
			If Me.chkGrupoA.CheckState = 1 Then
				lstrAuxiliar = lstrAuxiliar & "A"
			End If
			If Me.chkGrupoB.CheckState = 1 Then
				lstrAuxiliar = lstrAuxiliar & "B"
			End If
			lstrAuxiliar = lstrAuxiliar & ") - Situação ("
			
			If Me.chkLigados.CheckState = 1 Then
				lstrAuxiliar = lstrAuxiliar & "L,"
			End If
			If Me.chkCortados.CheckState = 1 Then
				lstrAuxiliar = lstrAuxiliar & "C,"
			End If
			If Me.chkDesligados.CheckState = 1 Then
				lstrAuxiliar = lstrAuxiliar & "D,"
			End If
			If Me.chkDesativados.CheckState = 1 Then
				lstrAuxiliar = lstrAuxiliar & "I,"
			End If
			lstrAuxiliar = VB.Left(lstrAuxiliar, Len(lstrAuxiliar) - 1) & ")"
			If Me.opbVencidos.Checked = True Then
				lstrAuxiliar = lstrAuxiliar & " - Desconsiderar pagas após o perído ("
				If Me.chkTipo.CheckState = 1 Then
					lstrAuxiliar = lstrAuxiliar & "Sim"
				Else
					lstrAuxiliar = lstrAuxiliar & "Não"
				End If
				lstrAuxiliar = lstrAuxiliar & ") "
			ElseIf Me.opbArrecadados.Checked = True Then 
				If Me.chkMesAno.CheckState = 1 Then
					lstrAuxiliar = lstrAuxiliar & " - Considerando somente faturamento ("
					lstrAuxiliar = lstrAuxiliar & VB6.Format(Me.dtpMesAno.value, "mm/yyyy")
					lstrAuxiliar = lstrAuxiliar & ") "
				End If
			ElseIf Me.opbAbertos.Checked = True Then 
				If Me.chkMesAno.CheckState = 1 Then
					lstrAuxiliar = lstrAuxiliar & " - Desconsiderando o faturamento ("
					lstrAuxiliar = lstrAuxiliar & VB6.Format(Me.dtpMesAno.value, "mm/yyyy")
					lstrAuxiliar = lstrAuxiliar & ") "
				End If
			End If
			If Me.chkJudice.CheckState = 1 Then
				lstrAuxiliar = lstrAuxiliar & " - em Júdice (Sim)"
			End If
			If Me.chkReserva.CheckState = 1 Then
				lstrAuxiliar = lstrAuxiliar & " - em Reserva (Sim)"
			End If
			If Me.opbVencidos.Checked Then
				.set_Formulas(2, "titulo = """ & "CONSUMIDORES VENCIDOS DE " & VB6.Format(Me.dtpInicio.value, "dd/mm/yyyy") & " ATÉ " & VB6.Format(Me.dtpFinal.value, "dd/mm/yyyy") & """ ")
			ElseIf Me.opbArrecadados.Checked Then 
				.set_Formulas(2, "titulo = """ & "CONSUMIDORES ARRECADADOS DE " & VB6.Format(Me.dtpInicio.value, "dd/mm/yyyy") & " ATÉ " & VB6.Format(Me.dtpFinal.value, "dd/mm/yyyy") & """ ")
			ElseIf Me.opbAbertos.Checked Then 
				.set_Formulas(2, "titulo = """ & "CONSUMIDORES EM ABERTOS ATÉ " & VB6.Format(Me.dtpFinal.value, "dd/mm/yyyy") & """ ")
			End If
			.set_Formulas(3, "titulo2 = """ & lstrAuxiliar & """ ")
			.Action = 0
		End With
		Me.cmdEmitir.Enabled = True
		Me.cmdFechar.Enabled = True
		Me.fmeAux(0).Enabled = True
		Me.Cursor = System.Windows.Forms.Cursors.Default
	End Sub
	
	Private Sub CarregaClasses(ByRef alsvAuxiliar As System.Windows.Forms.ListView)
		Dim lsiItens As System.Windows.Forms.ListViewItem
		Dim clhColunas As System.Windows.Forms.ColumnHeader
		Dim strNome As String
		Dim strZona As String
		Dim lngTamanho As Integer
		
		' ----- Limpa a List que carrega as cidades
		alsvAuxiliar.Items.Clear()
		
		If alsvAuxiliar.Columns.Count <= 1 Then
			clhColunas = alsvAuxiliar.Columns.Add("", "Classe", CInt(VB6.TwipsToPixelsX(2600)))
			clhColunas = alsvAuxiliar.Columns.Add("", "Condição", CInt(VB6.TwipsToPixelsX(0)))
		End If
		
		lsiItens = alsvAuxiliar.Items.Add("Marcar Todas")
		'UPGRADE_WARNING: Lower bound of collection lsiItens has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		If lsiItens.SubItems.Count > alsvAuxiliar.Items.Count Then
			lsiItens.SubItems(alsvAuxiliar.Items.Count).Text = " = 0"
		Else
			lsiItens.SubItems.Insert(alsvAuxiliar.Items.Count, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, " = 0"))
		End If
		'UPGRADE_WARNING: Lower bound of collection alsvAuxiliar.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		alsvAuxiliar.Items.Item(alsvAuxiliar.Items.Count).Checked = True
		'UPGRADE_WARNING: Lower bound of collection alsvAuxiliar.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		alsvAuxiliar.Items.Item(1).Font = VB6.FontChangeBold(alsvAuxiliar.Items.Item(1).Font, True)
		
		lsiItens = alsvAuxiliar.Items.Add("Residencial")
		'UPGRADE_WARNING: Lower bound of collection lsiItens has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		If lsiItens.SubItems.Count > 1 Then
			lsiItens.SubItems(1).Text = " = 9"
		Else
			lsiItens.SubItems.Insert(1, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, " = 9"))
		End If
		'UPGRADE_WARNING: Lower bound of collection alsvAuxiliar.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		alsvAuxiliar.Items.Item(alsvAuxiliar.Items.Count).Checked = True
		
		lsiItens = alsvAuxiliar.Items.Add("Industrial")
		'UPGRADE_WARNING: Lower bound of collection lsiItens has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		If lsiItens.SubItems.Count > 1 Then
			lsiItens.SubItems(1).Text = " < 4"
		Else
			lsiItens.SubItems.Insert(1, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, " < 4"))
		End If
		'UPGRADE_WARNING: Lower bound of collection alsvAuxiliar.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		alsvAuxiliar.Items.Item(alsvAuxiliar.Items.Count).Checked = True
		lsiItens = alsvAuxiliar.Items.Add("Livre")
		'UPGRADE_WARNING: Lower bound of collection lsiItens has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		If lsiItens.SubItems.Count > 1 Then
			lsiItens.SubItems(1).Text = " = 0100"
		Else
			lsiItens.SubItems.Insert(1, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, " = 0100"))
		End If
		'UPGRADE_WARNING: Lower bound of collection alsvAuxiliar.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		alsvAuxiliar.Items.Item(alsvAuxiliar.Items.Count).Checked = True
		lsiItens = alsvAuxiliar.Items.Add("Comercial")
		'UPGRADE_WARNING: Lower bound of collection lsiItens has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		If lsiItens.SubItems.Count > 1 Then
			lsiItens.SubItems(1).Text = " = 4"
		Else
			lsiItens.SubItems.Insert(1, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, " = 4"))
		End If
		'UPGRADE_WARNING: Lower bound of collection alsvAuxiliar.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		alsvAuxiliar.Items.Item(alsvAuxiliar.Items.Count).Checked = True
		lsiItens = alsvAuxiliar.Items.Add("Rural")
		'UPGRADE_WARNING: Lower bound of collection lsiItens has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		If lsiItens.SubItems.Count > 1 Then
			lsiItens.SubItems(1).Text = " = 5"
		Else
			lsiItens.SubItems.Insert(1, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, " = 5"))
		End If
		'UPGRADE_WARNING: Lower bound of collection alsvAuxiliar.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		alsvAuxiliar.Items.Item(alsvAuxiliar.Items.Count).Checked = True
		lsiItens = alsvAuxiliar.Items.Add("Poder Público Municipal")
		'UPGRADE_WARNING: Lower bound of collection lsiItens has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		If lsiItens.SubItems.Count > 1 Then
			lsiItens.SubItems(1).Text = " = 61"
		Else
			lsiItens.SubItems.Insert(1, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, " = 61"))
		End If
		'UPGRADE_WARNING: Lower bound of collection alsvAuxiliar.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		alsvAuxiliar.Items.Item(alsvAuxiliar.Items.Count).Checked = True
		lsiItens = alsvAuxiliar.Items.Add("Poder Público Estadual")
		'UPGRADE_WARNING: Lower bound of collection lsiItens has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		If lsiItens.SubItems.Count > 1 Then
			lsiItens.SubItems(1).Text = " = 62"
		Else
			lsiItens.SubItems.Insert(1, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, " = 62"))
		End If
		'UPGRADE_WARNING: Lower bound of collection alsvAuxiliar.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		alsvAuxiliar.Items.Item(alsvAuxiliar.Items.Count).Checked = True
		lsiItens = alsvAuxiliar.Items.Add("Poder Público Federal")
		'UPGRADE_WARNING: Lower bound of collection lsiItens has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		If lsiItens.SubItems.Count > 1 Then
			lsiItens.SubItems(1).Text = " = 63"
		Else
			lsiItens.SubItems.Insert(1, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, " = 63"))
		End If
		'UPGRADE_WARNING: Lower bound of collection alsvAuxiliar.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		alsvAuxiliar.Items.Item(alsvAuxiliar.Items.Count).Checked = True
		lsiItens = alsvAuxiliar.Items.Add("Iluminação Pública")
		'UPGRADE_WARNING: Lower bound of collection lsiItens has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		If lsiItens.SubItems.Count > 1 Then
			lsiItens.SubItems(1).Text = " = 64"
		Else
			lsiItens.SubItems.Insert(1, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, " = 64"))
		End If
		'UPGRADE_WARNING: Lower bound of collection alsvAuxiliar.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		alsvAuxiliar.Items.Item(alsvAuxiliar.Items.Count).Checked = True
		lsiItens = alsvAuxiliar.Items.Add("Serviço Púplico")
		'UPGRADE_WARNING: Lower bound of collection lsiItens has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		If lsiItens.SubItems.Count > 1 Then
			lsiItens.SubItems(1).Text = " = 7"
		Else
			lsiItens.SubItems.Insert(1, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, " = 7"))
		End If
		'UPGRADE_WARNING: Lower bound of collection alsvAuxiliar.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		alsvAuxiliar.Items.Item(alsvAuxiliar.Items.Count).Checked = True
		lsiItens = alsvAuxiliar.Items.Add("Consumo Próprio")
		'UPGRADE_WARNING: Lower bound of collection lsiItens has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		If lsiItens.SubItems.Count > 1 Then
			lsiItens.SubItems(1).Text = " = 8"
		Else
			lsiItens.SubItems.Insert(1, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, " = 8"))
		End If
		'UPGRADE_WARNING: Lower bound of collection alsvAuxiliar.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		alsvAuxiliar.Items.Item(alsvAuxiliar.Items.Count).Checked = True
	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 dtpFinal_Change(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles dtpFinal.Change
		Me.dtpMesAno.value = CDate("01/" & Me.dtpFinal.Month & "/" & Me.dtpFinal.Year)
	End Sub
	
	Private Sub dtpInicio_Change(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles dtpInicio.Change
		Me.dtpFinal.value = CDate(UltimoDiaMes((Me.dtpInicio.Month), (Me.dtpInicio.Year)) & "/" & Me.dtpInicio.Month & "/" & Me.dtpInicio.Year)
		Me.dtpMesAno.value = CDate("01/" & Me.dtpFinal.Month & "/" & Me.dtpFinal.Year)
	End Sub
	
	Private Sub frmRelAbertos_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Me.dtpInicio.value = gDtBcoDados
		'UPGRADE_WARNING: Couldn't resolve default property of object Me.dtpInicio.value. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
		Me.dtpFinal.value = Me.dtpInicio.value
		'UPGRADE_WARNING: Couldn't resolve default property of object Me.dtpFinal.value. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
		Me.dtpMesAno.value = Me.dtpFinal.value
		Call CarregaClasses((Me.lvsClasses))
		Me.chkMesAno.Enabled = False
		Me.dtpMesAno.Enabled = Me.chkMesAno.Enabled
	End Sub
	
	Private Sub frmRelAbertos_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
		Dim lstrSql As String
		lstrSql = "DELETE FROM temp_abertos WHERE nomemaquina = """ & gstrNmEstacao & """ "
		Call Executar(lstrSql)
	End Sub
	
	Private Sub lvsClasses_ItemCheck(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.ItemCheckEventArgs) Handles lvsClasses.ItemCheck
		Dim aItem As System.Windows.Forms.ListViewItem = lvsClasses.Items(eventArgs.Index)
		Dim intConta As Short
		
		With Me.lvsClasses
			' ----- Faz o controle para selecionar todas as cidades ou nenhuma
			If aItem.Text = "Marcar Todas" Then
				For intConta = 1 To .Items.Count
					'UPGRADE_WARNING: Lower bound of collection Me.lvsClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
					.Items.Item(intConta).Checked = .Items.Item(1).Checked
				Next intConta
			Else
				If aItem.Checked = False Then
					'UPGRADE_WARNING: Lower bound of collection Me.lvsClasses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
					.Items.Item(1).Checked = False
				End If
			End If
		End With
	End Sub
	
	'UPGRADE_WARNING: Event opbAbertos.CheckedChanged 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 opbAbertos_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbAbertos.CheckedChanged
		If eventSender.Checked Then
			Me.dtpInicio.Enabled = False
			Me.dtpFinal.Enabled = True
			Me.chkMesAno.Enabled = True
			Me.chkTipo.Enabled = False
			Me.dtpMesAno.Enabled = Me.chkMesAno.Enabled
			Me.chkMesAno.Text = "Desconsiderar somente faturamento:"
		End If
	End Sub
	
	'UPGRADE_WARNING: Event opbArrecadados.CheckedChanged 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 opbArrecadados_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbArrecadados.CheckedChanged
		If eventSender.Checked Then
			Me.dtpInicio.Enabled = True
			Me.dtpFinal.Enabled = True
			Me.chkMesAno.Enabled = True
			Me.chkTipo.Enabled = False
			Me.dtpMesAno.Enabled = Me.chkMesAno.Enabled
			Me.chkMesAno.Text = "Considerar somente faturamento:"
		End If
	End Sub
	
	'UPGRADE_WARNING: Event opbVencidos.CheckedChanged 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 opbVencidos_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbVencidos.CheckedChanged
		If eventSender.Checked Then
			Me.dtpInicio.Enabled = True
			Me.dtpFinal.Enabled = True
			Me.chkMesAno.Enabled = False
			Me.chkTipo.Enabled = True
			Me.dtpMesAno.Enabled = Me.chkMesAno.Enabled
		End If
	End Sub
	
	Private Sub txtValor_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtValor.Enter
		With Me.txtValor
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtValor_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtValor.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		If KeyAscii = System.Windows.Forms.Keys.Return Then
			Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
		ElseIf KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then 
			If KeyAscii = System.Windows.Forms.Keys.Delete Then
				KeyAscii = System.Windows.Forms.Keys.Snapshot
			End If
			If KeyAscii <> System.Windows.Forms.Keys.Snapshot Then
				KeyAscii = 0
			Else
				If InStr(1, Me.txtValor.Text, ",") > 0 Then
					KeyAscii = 0
				End If
			End If
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
End Class