Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmRelEstOperacao
	Inherits System.Windows.Forms.Form
	
	Private strTabela As String
	Private istrSql As String
	Private fr As New FrmRelatorio
	Private strTamCol As String
	Private istrTitulo As String
	Private istrTitulo1 As String
	Private istrTitulo2 As String
	Private istrTitulo3 As String
	Private strClasseOld As String
	Private strClasse As String
	Private strNmClasse As String
	Private blnAnalitico As Boolean
	
	Private Sub frmRelEstOperacao_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Me.dtpInicial.value = Today
		Me.dtpFinal.value = Today
		Me.dtpMesAno.value = Today
		Call CarregaClasses((Me.lvsClasses))
		Call CarregaCidades((Me.lvsCidades))
		istrTitulo1 = gstrEmpresa_Nome
	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
	
	Private Sub lvsCidades_ItemCheck(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.ItemCheckEventArgs) Handles lvsCidades.ItemCheck
		Dim aItem As System.Windows.Forms.ListViewItem = lvsCidades.Items(eventArgs.Index)
		Dim intConta As Short
		
		With Me.lvsCidades
			' ----- 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.lvsCidades.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.lvsCidades.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 opbMesAno.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 opbMesAno_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbMesAno.CheckedChanged
		If eventSender.Checked Then
			Me.dtpMesAno.Enabled = Me.opbMesAno.Checked
			Me.dtpInicial.Enabled = Me.opbPeriodo.Checked
			Me.dtpFinal.Enabled = Me.opbPeriodo.Checked
			Me.Label1(0).Enabled = Me.opbPeriodo.Checked
		End If
	End Sub
	
	'UPGRADE_WARNING: Event opbPeriodo.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 opbPeriodo_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbPeriodo.CheckedChanged
		If eventSender.Checked Then
			Me.dtpMesAno.Enabled = Me.opbMesAno.Checked
			Me.dtpInicial.Enabled = Me.opbPeriodo.Checked
			Me.dtpFinal.Enabled = Me.opbPeriodo.Checked
			Me.Label1(0).Enabled = Me.opbPeriodo.Checked
		End If
	End Sub
	
	Private Sub cmdEmitir_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdEmitir.Click
		Call LigDesCampos(False)
		strTabela = "temprelestop_" & gstrNmEstacao
		istrSql = "DROP TABLE IF EXISTS " & strTabela & ""
		Call Executar(istrSql)
		
		If MontaTabela Then
			Call ImprimeRelatorio()
		End If
		'istrSql = "DROP TABLE IF EXISTS " & strTabela & ""
		'Call Executar(istrSql)
		Call LigDesCampos(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 Function MontaTabela() As Boolean
		Dim strfiltro As String
		Dim strfiltro2 As String
		Dim strFiltroCidade As String
		Dim strColuna As String
		Dim strItens As String
		Dim strZona As String
		Dim strLivro As String
		Dim strConta As String
		Dim lstrGrTar As String
		Dim strGrupo As String
		Dim strNome As String
		Dim lngUnidId As Integer
		Dim lngConsId As Integer
		Dim dblQkwhCon As Double
		Dim dblQKwhFat As Double
		Dim dblVEnergia As Double
		Dim dblVDemanda As Double
		Dim dblVReativo As Double
		
		Dim ldblQConsumoP As Double
		Dim ldblQConsumoFP As Double
		Dim ldblVConsumoP As Double
		Dim ldblVConsumoFP As Double
		
		Dim ldblQReversoP As Double
		Dim ldblQReversoFP As Double
		Dim ldblVReversoP As Double
		Dim ldblVReversoFP As Double
		Dim lintLivreEspecial As Short
		Dim lintParcialmenteCativo As Short
		Dim lintMicroGeracao As Short
		Dim lintMicroGeracaoDistribuida As Short
		Dim intConta As Short
		Dim rsFatura As ADODB.Recordset
		Dim rsConsulta As ADODB.Recordset
		
		rsFatura = New ADODB.Recordset
		rsConsulta = New ADODB.Recordset
		istrSql = "CREATE TABLE " & strTabela & "("
		istrSql = istrSql & "classe       VARCHAR(6), " 'Classe
		istrSql = istrSql & "nmclasse     VARCHAR(100), " 'NmClasse
		istrSql = istrSql & "qkwh_cons    DOUBLE, " 'Qtde Kwh CONSUMIDO (ENERGIA CONSUMIDA)
		istrSql = istrSql & "qkwh_fat     DOUBLE, " 'Qtde Kwh FATURADO
		istrSql = istrSql & "vkwh         DOUBLE, " 'Valor Kwh
		istrSql = istrSql & "vkw          DOUBLE, " 'Valor Kw
		istrSql = istrSql & "vkvarh       DOUBLE, " 'Valor Kvarh
		istrSql = istrSql & "nome         VARCHAR(85), "
		istrSql = istrSql & "zona         VARCHAR(3), "
		istrSql = istrSql & "livro        VARCHAR(2), "
		istrSql = istrSql & "conta        VARCHAR(6), "
		istrSql = istrSql & "grupo        VARCHAR(3)) "
		Call Executar(istrSql)
		
		MontaTabela = True
		istrSql = ""
		istrSql = istrSql & "SELECT codclas, itensserv, zona, livro, conta, cons_id, unid_id, ta, numnf, mesano, mesano_ref, livreespecial, parcialmente_cativo, micro_geracao, micro_geracao_distribuida "
		istrSql = istrSql & "  FROM nf "
		istrSql = istrSql & " WHERE "
		'Se for soment A ou se for somente B ou se for A e B
		If Me.chkGrupoA.CheckState And Not Me.chkGrupoB.CheckState Then
			istrSql = istrSql & " grupo = 'A' AND "
		ElseIf Me.chkGrupoB.CheckState And Not Me.chkGrupoA.CheckState Then 
			istrSql = istrSql & " grupo = 'B' AND "
		End If
		strfiltro = ""
		strfiltro2 = ""
		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
				strfiltro = "("
				For intConta = 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(intConta).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"'
						strfiltro = strfiltro & " LEFT(codclas," & Len(Trim(Str_Retira(.Items.Item(intConta).SubItems(1).Text, "<="))) & ")" & .Items.Item(intConta).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(intConta).Text) = "Industrial" And .Items.Item(4).Checked = False Then
							strfiltro2 = " codclas <> '0100' AND "
						Else
							strfiltro2 = ""
						End If
					End If
				Next intConta
				If strfiltro = "(" Then
					Call MsgBox("Faltou marcar ao menos uma classe!", MsgBoxStyle.Information, gstrTituloMensagem)
					Me.lvsClasses.Focus()
					MontaTabela = False
					Exit Function
				End If
				strfiltro = VB.Left(strfiltro, Len(strfiltro) - 3) & ") AND "
			Else
				strfiltro = ""
				strfiltro2 = ""
			End If
		End With
		istrSql = istrSql & strfiltro & strfiltro2
		
		If Me.opbMesAnoFat.Checked Then
			If Me.opbMesAno.Checked Then
				istrSql = istrSql & " mesano = ('" & VB6.Format(Me.dtpMesAno.Month, "00") & "/" & Me.dtpMesAno.Year & "') AND "
			Else
				istrSql = istrSql & " (mesano_ref >= " & Me.dtpInicial.Year & VB6.Format(Me.dtpInicial.Month, "00") & " AND "
				istrSql = istrSql & "  mesano_ref <= " & Me.dtpFinal.Year & VB6.Format(Me.dtpFinal.Month, "00") & ") AND "
			End If
		Else
			If Me.opbDtVencto.Checked Then
				strColuna = "datavenc"
			ElseIf Me.opbDtLeitAnt.Checked Then 
				strColuna = "dataleitant"
			ElseIf Me.opbDtLeitAtu.Checked Then 
				strColuna = "dataleit"
			ElseIf Me.opbDtApres.Checked Then 
				strColuna = "dataapr"
			ElseIf Me.opbDtEmissao.Checked Then 
				strColuna = "dataem"
			ElseIf Me.opbDtPagto.Checked Then 
				strColuna = "datapag"
			End If
			If Me.opbMesAno.Checked Then
				istrSql = istrSql & " CONCAT(MONTH(" & strColuna & "),""/"",YEAR(" & strColuna & ")) = (""" & VB6.Format(Me.dtpMesAno.Month, "00") & "/" & Me.dtpMesAno.Year & """) AND "
			Else
				istrSql = istrSql & " (" & strColuna & " >= '" & VB6.Format(Me.dtpInicial.value, "yyyy-MM-dd") & "' AND "
				istrSql = istrSql & " " & strColuna & " <= '" & VB6.Format(Me.dtpFinal.value, "yyyy-MM-dd") & "') AND "
			End If
		End If
		strFiltroCidade = MontaFiltro(Me.lvsCidades, 2)
		If Len(Trim(strFiltroCidade)) > 0 Then
			istrSql = istrSql & " zona IN " & strFiltroCidade & " AND "
		End If
		istrSql = VB.Left(istrSql, Len(istrSql) - 4)
		Me.lblStatus1.Text = "Buscando as faturas..."
		Me.lblStatus1.Refresh()
		Call Conectar(istrSql, rsFatura)
		If rsFatura.RecordCount > 0 Then
			Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, rsFatura.RecordCount)
			While Not rsFatura.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"'
				lintLivreEspecial = IIf(IsDbNull(rsFatura.Fields("livreespecial").value), 0, rsFatura.Fields("livreespecial").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"'
				lintParcialmenteCativo = IIf(IsDbNull(rsFatura.Fields("parcialmente_cativo").value), 0, rsFatura.Fields("parcialmente_cativo").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"'
				lintMicroGeracao = IIf(IsDbNull(rsFatura.Fields("micro_geracao").value), 0, rsFatura.Fields("micro_geracao").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"'
				lintMicroGeracaoDistribuida = IIf(IsDbNull(rsFatura.Fields("micro_geracao_distribuida").value), 0, rsFatura.Fields("micro_geracao_distribuida").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"'
				strClasse = IIf(IsDbNull(rsFatura.Fields("codclas").Value), "", rsFatura.Fields("codclas").Value)
				strNmClasse = Replace(PegaNomeClasse(strClasse), ";", ":")
				'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"'
				strItens = IIf(IsDbNull(rsFatura.Fields("itensserv").Value), "", rsFatura.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"'
				strZona = IIf(IsDbNull(rsFatura.Fields("zona").Value), "", rsFatura.Fields("zona").Value)
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				strLivro = IIf(IsDbNull(rsFatura.Fields("livro").Value), "", rsFatura.Fields("livro").Value)
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				strConta = IIf(IsDbNull(rsFatura.Fields("conta").Value), "", rsFatura.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"'
				lngConsId = IIf(IsDbNull(rsFatura.Fields("cons_id").Value), 0, rsFatura.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"'
				lngUnidId = IIf(IsDbNull(rsFatura.Fields("unid_id").Value), 0, rsFatura.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"'
				lstrGrTar = IIf(IsDbNull(rsFatura.Fields("ta").Value), "", rsFatura.Fields("ta").Value)
				strGrupo = IIf(Mid(lstrGrTar, 3, 1) = "A", Mid(lstrGrTar, 3, 2), Mid(lstrGrTar, 3, 1))
				dblQkwhCon = 0
				dblQKwhFat = 0
				dblVEnergia = 0
				dblVDemanda = 0
				dblVReativo = 0
				
				If strGrupo = "A4" Then
					dblQkwhCon = dblQkwhCon + BuscaVlrItem(strItens, "0302010008") 'Consumo lido
					dblQKwhFat = dblQKwhFat + BuscaVlrItem(strItens, "0302010009") 'Consumo faturado
					dblVEnergia = dblVEnergia + BuscaVlrItem(strItens, "0302020009") 'Valor Consumo faturado
					dblVReativo = dblVReativo + BuscaVlrItem(strItens, "0302020012") 'Valor Consumo Reativo
					dblVReativo = dblVReativo + BuscaVlrItem(strItens, "0302020031") 'Valor Demanda Reativo
					dblVDemanda = dblVDemanda + BuscaVlrItem(strItens, "0302020015") 'Valor Demanda
					dblVDemanda = dblVDemanda + BuscaVlrItem(strItens, "0302020018") 'Valor Demanda de Ultrapassagem
				ElseIf strGrupo = "B" Then 
					dblQkwhCon = dblQkwhCon + BuscaVlrItem(strItens, "030201008") + BuscaVlrItem(strItens, "030201018") + BuscaVlrItem(strItens, "030201028") + BuscaVlrItem(strItens, "030201038") 'Consumo lido
					dblQKwhFat = dblQKwhFat + BuscaVlrItem(strItens, "030201009") + BuscaVlrItem(strItens, "030201019") + BuscaVlrItem(strItens, "030201029") + BuscaVlrItem(strItens, "030201039") 'Consumo faturado
					dblVEnergia = dblVEnergia + BuscaVlrItem(strItens, "030202009") + BuscaVlrItem(strItens, "030202019") + BuscaVlrItem(strItens, "030202029") + BuscaVlrItem(strItens, "030202039") 'Valor Consumo faturado
					dblVReativo = dblVReativo + BuscaVlrItem(strItens, "0302020012") 'Valor Consumo Reativo
				Else
					ldblQReversoP = BuscaVlrItem(strItens, "0302012010")
					ldblQConsumoP = BuscaVlrItem(strItens, "0302010010")
					ldblQReversoFP = BuscaVlrItem(strItens, "0302012011")
					ldblQConsumoFP = BuscaVlrItem(strItens, "0302010011")
					
					If ldblQConsumoP <= ldblQReversoP Then
						ldblQReversoP = ldblQConsumoP
						ldblQConsumoP = 0
					Else
						ldblQConsumoP = ldblQConsumoP - ldblQReversoP
					End If
					
					If ldblQConsumoFP <= ldblQReversoFP Then
						ldblQReversoFP = ldblQConsumoFP
						ldblQConsumoFP = 0
					Else
						ldblQConsumoFP = ldblQConsumoFP - ldblQReversoFP
					End If
					
					
					dblQkwhCon = dblQkwhCon + ldblQConsumoP 'Consumo faturado p
					dblQkwhCon = dblQkwhCon + ldblQConsumoFP 'Consumo faturado fp
					dblQKwhFat = dblQKwhFat + ldblQConsumoP 'Consumo faturado p
					dblQKwhFat = dblQKwhFat + ldblQConsumoFP 'Consumo faturado fp
					
					dblVEnergia = dblVEnergia + BuscaVlrItem(strItens, "0302020010") 'Valor Consumo faturado p
					dblVEnergia = dblVEnergia + BuscaVlrItem(strItens, "0302020011") 'Valor Consumo faturado fp
					dblVDemanda = dblVDemanda + BuscaVlrItem(strItens, "0302020021") 'Valor Demanda p
					dblVDemanda = dblVDemanda + BuscaVlrItem(strItens, "0302020023") '+ BuscaVlrItem(strItens, "0302020072") 'Valor Demanda fp
					dblVDemanda = dblVDemanda + BuscaVlrItem(strItens, "0302020022") 'Valor Demanda de ultrapassagem p
					dblVDemanda = dblVDemanda + BuscaVlrItem(strItens, "0302020026") 'Valor Demanda de ultrapassagem fp
					dblVReativo = dblVReativo + BuscaVlrItem(strItens, "0302020013") 'Valor Consumo Reativo p
					dblVReativo = dblVReativo + BuscaVlrItem(strItens, "0302020014") 'Valor Consumo Reativo fp
					dblVReativo = dblVReativo + BuscaVlrItem(strItens, "0302020027") 'Valor Demanda Reativo p
					dblVReativo = dblVReativo + BuscaVlrItem(strItens, "0302020028") 'Valor Demanda Reativo fp
				End If
				
				'Busca o nome do cabra na unidade consumidora se existir senao entao tenta pega somente o nome do consumidor
				istrSql = "SELECT nome " & "  FROM unid" & LCase(Mid(lstrGrTar, 3, 1)) & " WHERE cons_id = " & lngConsId & "   AND unid_id = " & lngUnidId
				Call Conectar(istrSql, rsConsulta)
				
				If rsConsulta.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"'
					strNome = IIf(IsDbNull(rsConsulta.Fields("nome").Value), "NOME NÃO INFORMADO", rsConsulta.Fields("nome").Value)
				Else
					If rsConsulta.State = 1 Then Call rsConsulta.Close()
					
					istrSql = "SELECT nome " & "  FROM consum " & " WHERE consreg = " & lngConsId
					Call Conectar(istrSql, rsConsulta)
					
					If rsConsulta.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"'
						strNome = IIf(IsDbNull(rsConsulta.Fields("nome").Value), "NOME NÃO INFORMADO", rsConsulta.Fields("nome").Value)
					Else
						strNome = "UNIDADE CONSUMIDORA EXCLUIDA "
					End If
				End If
				If rsConsulta.State = 1 Then Call rsConsulta.Close()
				
				istrSql = "INSERT INTO " & strTabela & " (classe, nmclasse, qkwh_cons, qkwh_fat, vkwh, vkw, vkvarh, nome, zona, livro, conta, grupo) VALUES (""" & strClasse & """, """ & strNmClasse & """, " & Replace(CStr(dblQkwhCon), ",", ".") & ", " & Replace(CStr(dblQKwhFat), ",", ".") & ", " & Replace(CStr(dblVEnergia), ",", ".") & ", " & Replace(CStr(dblVDemanda), ",", ".") & ", " & Replace(CStr(dblVReativo), ",", ".") & ", """ & strNome & """, """ & strZona & """, """ & strLivro & """, """ & strConta & """, """ & IIf(strGrupo <> "AL", strGrupo, IIf(strGrupo = "AL", strGrupo & IIf(lintParcialmenteCativo = 1, "P", IIf(lintLivreEspecial = 1, "S", "")), "")) & """); "
				Call Executar(istrSql)
				Call rsFatura.MoveNext()
				Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
				System.Windows.Forms.Application.DoEvents()
			End While
		End If
		If rsFatura.State = 1 Then Call rsFatura.Close()
		Me.lblStatus1.Text = ""
		Me.lblStatus1.Refresh()
		'UPGRADE_NOTE: Object rsFatura 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"'
		rsFatura = Nothing
		'UPGRADE_NOTE: Object rsConsulta 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"'
		rsConsulta = Nothing
	End Function
	
	Private Sub ImprimeRelatorio()
		Dim rsConsulta As ADODB.Recordset
		Dim strTemp As String
		Dim lstrSql1 As String
		Dim lstrSql2 As String
		Dim lstrSql3 As String
		Dim lstrSql4 As String
		Dim lstrSql5 As String
		Dim lstrSql6 As String
		Dim lstrSql7 As String
		Dim lstrSql8 As String
		Dim strFiltro3 As String
		Dim blnStartDoc As Boolean
		Dim intConta As Short
		Dim intCidad As Short
		
		rsConsulta = New ADODB.Recordset
		fr.quem_chama = Me
		fr.VS.Font = VB6.FontChangeName(fr.VS.Font, "Arial")
		'fr.VS.TableBorder = tbBoxRows
		fr.VS.PageBorder = VSVIEW6.TableBorderSettings.tbNone
		fr.VS.Orientation = VSVIEW6.OrientationSettings.orPortrait
		fr.VS.PhysicalPage = True
		fr.VS.PaperSize = VSVIEW6.PaperSizeSettings.pprA4
		fr.VS.MarginTop = "7mm"
		fr.VS.MarginRight = "7mm"
		fr.VS.MarginLeft = "7mm"
		fr.VS.MarginBottom = "5mm"
		fr.VS.TextColor = System.Drawing.Color.Black
		fr.VS.BrushStyle = VSVIEW6.BrushStyleSettings.bsSolid
		'UPGRADE_ISSUE: VBControlExtender method fr.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
		fr.VS.CurrentY = 396
		strTamCol = "<60mm|<60mm|<60mm;"
		blnStartDoc = False
		If Me.opbMesAno.Checked Then
			If Me.opbMesAnoFat.Checked Then
				istrTitulo3 = "Faturamento"
			ElseIf Me.opbDtVencto.Checked Then 
				istrTitulo3 = "Data de Vencimento"
			ElseIf Me.opbDtLeitAnt.Checked Then 
				istrTitulo3 = "Data da Leitura Anterior"
			ElseIf Me.opbDtLeitAtu.Checked Then 
				istrTitulo3 = "Data da Leitura Atual"
			ElseIf Me.opbDtApres.Checked Then 
				istrTitulo3 = "Data da Apresentação"
			ElseIf Me.opbDtEmissao.Checked Then 
				istrTitulo3 = "Data da Emissão"
			ElseIf Me.opbDtPagto.Checked Then 
				istrTitulo3 = "Data do Pagamento"
			End If
			istrTitulo3 = istrTitulo3 & " do Mês/Ano: " & VB6.Format(Me.dtpMesAno.value, "MM/yyyy")
		ElseIf Me.opbPeriodo.Checked Then 
			If Me.opbMesAnoFat.Checked Then
				istrTitulo3 = "Faturamento"
			ElseIf Me.opbDtVencto.Checked Then 
				istrTitulo3 = "Data de Vencimento"
			ElseIf Me.opbDtLeitAnt.Checked Then 
				istrTitulo3 = "Data da Leitura Anterior"
			ElseIf Me.opbDtLeitAtu.Checked Then 
				istrTitulo3 = "Data da Leitura Atual"
			ElseIf Me.opbDtApres.Checked Then 
				istrTitulo3 = "Data da Apresentação"
			ElseIf Me.opbDtEmissao.Checked Then 
				istrTitulo3 = "Data da Emissão"
			ElseIf Me.opbDtPagto.Checked Then 
				istrTitulo3 = "Data do Pagamento"
			End If
			istrTitulo3 = istrTitulo3 & " do Período de: " & VB6.Format(Me.dtpInicial.value, "dd/mm/yyyy") & " até " & VB6.Format(Me.dtpFinal.value, "dd/mm/yyyy")
		End If
		Me.lblStatus1.Text = "Imprimindo..."
		Me.lblStatus1.Refresh()
		For intCidad = 2 To Me.lvsCidades.Items.Count
			'UPGRADE_WARNING: Lower bound of collection Me.lvsCidades.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 Me.lvsCidades.Items.Item(intCidad).Checked Then
				'UPGRADE_WARNING: Lower bound of collection Me.lvsCidades.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.lvsCidades.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"'
				lstrSql7 = " WHERE zona= """ & Me.lvsCidades.Items.Item(intCidad).SubItems(1).Text & """ AND "
				If Me.chkGrupoAB.CheckState Then
					lstrSql8 = " WHERE "
				End If
				For intConta = 2 To Me.lvsClasses.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 Me.lvsClasses.Items.Item(intConta).Checked 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"'
						istrTitulo2 = "Consumo de Energia do " & Me.lvsClasses.Items.Item(intConta).Text
						'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"'
						istrSql = " LEFT(classe," & Len(Trim(Str_Retira(Me.lvsClasses.Items.Item(intConta).SubItems(1).Text, "<="))) & ") " & Me.lvsClasses.Items.Item(intConta).SubItems(1).Text & " "
						'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(Me.lvsClasses.Items.Item(intConta).Text) = "Industrial" And Me.lvsClasses.Items.Item(4).Checked = False Then
							istrSql = istrSql & " AND TRIM(classe) <> '0100' "
						End If
						
						If Me.opbSintetico.Checked Then
							lstrSql1 = "SELECT count(*) qcons, SUM(qkwh_cons) qkwh_cons, SUM(qkwh_fat) qkwh_fat, SUM(vkwh) vkwh, SUM(vkw) vkw, SUM(vkvarh) vkvarh, classe, nmclasse, grupo "
							lstrSql3 = " GROUP BY grupo, classe ORDER BY grupo ASC, classe ASC"
							
							lstrSql2 = "SELECT count(*) qcons, SUM(qkwh_cons) qkwh_cons, SUM(qkwh_fat) qkwh_fat, SUM(vkwh) vkwh, SUM(vkw) vkw, SUM(vkvarh) vkvarh, classe, nmclasse "
							lstrSql4 = " GROUP BY classe ORDER BY classe ASC "
						End If
						If Me.opbAnalitico.Checked Then
							lstrSql5 = "SELECT 1 qcons, qkwh_cons, qkwh_fat, vkwh, vkw, vkvarh, classe, nmclasse, grupo, nome, zona, livro, conta "
							lstrSql6 = " ORDER BY classe ASC, grupo ASC, zona ASC, livro ASC, conta ASC "
						End If
						If Me.opbSintetico.Checked Then
							'Sintético A
							If Me.chkGrupoA.CheckState Then
								'Somente os Convencionais
								Call Conectar(lstrSql1 & "  FROM " & strTabela & lstrSql7 & istrSql & " AND grupo = 'A4'" & lstrSql3, rsConsulta)
								If rsConsulta.RecordCount > 0 Then
									'UPGRADE_WARNING: Lower bound of collection Me.lvsCidades.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"'
									istrTitulo = istrTitulo2 & " - Convencional / " & Me.lvsCidades.Items.Item(intCidad).Text
									blnAnalitico = False
									Call MontaDetalhe(rsConsulta, intConta, blnStartDoc)
								End If
								If rsConsulta.State = 1 Then Call rsConsulta.Close()
								'Somente os Horosazonais Verde
								Call Conectar(lstrSql1 & "  FROM " & strTabela & lstrSql7 & istrSql & " AND grupo = 'AV'" & lstrSql3, rsConsulta)
								If rsConsulta.RecordCount > 0 Then
									'UPGRADE_WARNING: Lower bound of collection Me.lvsCidades.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"'
									istrTitulo = istrTitulo2 & " - Horo Sazonal Verde / " & Me.lvsCidades.Items.Item(intCidad).Text
									blnAnalitico = False
									Call MontaDetalhe(rsConsulta, intConta, blnStartDoc)
								End If
								If rsConsulta.State = 1 Then Call rsConsulta.Close()
								'Somente os Horosazonais Azul
								Call Conectar(lstrSql1 & "  FROM " & strTabela & lstrSql7 & istrSql & " AND grupo = 'AA'" & lstrSql3, rsConsulta)
								If rsConsulta.RecordCount > 0 Then
									'UPGRADE_WARNING: Lower bound of collection Me.lvsCidades.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"'
									istrTitulo = istrTitulo2 & " - Horo Sazonal Azul / " & Me.lvsCidades.Items.Item(intCidad).Text
									blnAnalitico = False
									Call MontaDetalhe(rsConsulta, intConta, blnStartDoc)
								End If
								If rsConsulta.State = 1 Then Call rsConsulta.Close()
								'Somente os Auto Produtor
								Call Conectar(lstrSql1 & "  FROM " & strTabela & lstrSql7 & istrSql & " AND grupo = 'AP'" & lstrSql3, rsConsulta)
								If rsConsulta.RecordCount > 0 Then
									'UPGRADE_WARNING: Lower bound of collection Me.lvsCidades.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"'
									istrTitulo = istrTitulo2 & " - Produtor / " & Me.lvsCidades.Items.Item(intCidad).Text
									blnAnalitico = False
									Call MontaDetalhe(rsConsulta, intConta, blnStartDoc)
								End If
								If rsConsulta.State = 1 Then Call rsConsulta.Close()
								'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(Me.lvsClasses.Items.Item(intConta).Text) = "Livre" Then
									'Somente o Livre normal
									Call Conectar(lstrSql1 & "  FROM " & strTabela & lstrSql7 & istrSql & " AND grupo = 'AL'" & lstrSql3, rsConsulta)
									If rsConsulta.RecordCount > 0 Then
										'UPGRADE_WARNING: Lower bound of collection Me.lvsCidades.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"'
										istrTitulo = istrTitulo2 & " - Livre / " & Me.lvsCidades.Items.Item(intCidad).Text
										blnAnalitico = False
										Call MontaDetalhe(rsConsulta, intConta, blnStartDoc)
									End If
									If rsConsulta.State = 1 Then Call rsConsulta.Close()
									
									'Somente o Livre especial
									Call Conectar(lstrSql1 & "  FROM " & strTabela & lstrSql7 & istrSql & " AND grupo = 'ALS'" & lstrSql3, rsConsulta)
									If rsConsulta.RecordCount > 0 Then
										'UPGRADE_WARNING: Lower bound of collection Me.lvsCidades.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"'
										istrTitulo = istrTitulo2 & " - Livre Especial / " & Me.lvsCidades.Items.Item(intCidad).Text
										blnAnalitico = False
										Call MontaDetalhe(rsConsulta, intConta, blnStartDoc)
									End If
									If rsConsulta.State = 1 Then Call rsConsulta.Close()
									
									'Somente o Livre parcialmente cativo
									Call Conectar(lstrSql1 & "  FROM " & strTabela & lstrSql7 & istrSql & " AND grupo = 'ALP'" & lstrSql3, rsConsulta)
									If rsConsulta.RecordCount > 0 Then
										'UPGRADE_WARNING: Lower bound of collection Me.lvsCidades.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"'
										istrTitulo = istrTitulo2 & " - Livre Parc.Cat. / " & Me.lvsCidades.Items.Item(intCidad).Text
										blnAnalitico = False
										Call MontaDetalhe(rsConsulta, intConta, blnStartDoc)
									End If
									If rsConsulta.State = 1 Then Call rsConsulta.Close()
								End If
							End If
							'---------------
							'Sintético B
							If Me.chkGrupoB.CheckState Then
								Call Conectar(lstrSql1 & "  FROM " & strTabela & lstrSql7 & istrSql & "AND grupo = 'B'" & lstrSql3, rsConsulta)
								If rsConsulta.RecordCount > 0 Then
									'UPGRADE_WARNING: Lower bound of collection Me.lvsCidades.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"'
									istrTitulo = istrTitulo2 & " - Grupo B / " & Me.lvsCidades.Items.Item(intCidad).Text
									blnAnalitico = False
									Call MontaDetalhe(rsConsulta, intConta, blnStartDoc)
								End If
								If rsConsulta.State = 1 Then Call rsConsulta.Close()
							End If
							'--------------
							'Sintético A+B
							If Me.chkGrupoAB.CheckState Then
								Call Conectar(lstrSql2 & "  FROM " & strTabela & lstrSql8 & istrSql & lstrSql4, rsConsulta)
								If rsConsulta.RecordCount > 0 Then
									istrTitulo = istrTitulo2 & " - (A + B) " & IIf(Me.opbConsumo.Checked, Chr(13) & "pelo Consumido Lido ", Chr(13) & "pelo Consumido Faturado")
									blnAnalitico = False
									Call MontaDetalhe(rsConsulta, intConta, blnStartDoc)
								End If
								If rsConsulta.State = 1 Then Call rsConsulta.Close()
								intCidad = Me.lvsCidades.Items.Count
							End If
							'--------------
						End If
						'Análitico A+B
						If Me.opbAnalitico.Checked Then
							'Call Conectar(lstrSql5 & "  FROM " & strTabela & lstrSql8 & istrSql & lstrSql6, rsConsulta)
							Call Conectar(lstrSql5 & "  FROM " & strTabela & " WHERE " & istrSql & lstrSql6, rsConsulta)
							
							'Clipboard.Clear
							'Clipboard.SetText lstrSql5 & "  FROM " & strTabela & lstrSql8 & istrSql & lstrSql6
							
							If rsConsulta.RecordCount > 0 Then
								istrTitulo = istrTitulo2 & " - (A + B) " & IIf(Me.opbConsumo.Checked, Chr(13) & "pelo Consumido Lido", Chr(13) & "pelo Consumido Faturado")
								blnAnalitico = True
								Call MontaDetalhe(rsConsulta, intConta, blnStartDoc)
							End If
							If rsConsulta.State = 1 Then Call rsConsulta.Close()
							intCidad = Me.lvsCidades.Items.Count
						End If
						'--------------
					End If
				Next intConta
			End If
		Next intCidad
		If blnStartDoc Then
			fr.VS.EndDoc()
			fr.Show()
		End If
		'UPGRADE_NOTE: Object rsConsulta 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"'
		rsConsulta = Nothing
		Me.lblStatus1.Text = ""
		Me.lblStatus1.Refresh()
	End Sub
	
	Private Sub MontaDetalhe(ByRef arsConsulta As ADODB.Recordset, ByVal aintConta As Short, ByRef ablnStartDoc As Boolean)
		Dim dblQCons As Double
		Dim dblQKwhCons As Double
		Dim dblQKwhFat As Double
		Dim dblVKwhFat As Double
		Dim dblVKwFat As Double
		Dim dblVKvarhFat As Double
		Dim dblAuxiliar As Double
		
		'Total Geral
		Dim dblTQCons As Double
		Dim dblTQKwhCons As Double
		Dim dblTQKwhFat As Double
		Dim dblTVKwhFat As Double
		Dim dblTVKwFat As Double
		Dim dblTVKvarhFat As Double
		
		'Sub-Total de Cada Classe
		Dim dblSQCons As Double
		Dim dblSQKwhCons As Double
		Dim dblSQKwhFat As Double
		Dim dblSVKwhFat As Double
		Dim dblSVKwFat As Double
		Dim dblSVKvarhFat As Double
		
		Dim strGrupo As String
		Dim strNome As String
		Dim strZona As String
		Dim strLivro As String
		Dim strConta As String
		Dim strTemp As String
		Dim strClasseAnt As String
		
		Dim lngCrtlPag As Integer
		
		'If aintConta > 2 Then
		fr.VS.NewPage()
		'End If
		strClasseAnt = ""
		strClasseOld = ""
		
		dblTQCons = 0
		dblTQKwhCons = 0
		dblTQKwhFat = 0
		dblTVKwhFat = 0
		dblTVKwFat = 0
		dblTVKvarhFat = 0
		
		dblSQCons = 0
		dblSQKwhCons = 0
		dblSQKwhFat = 0
		dblSVKwhFat = 0
		dblSVKwFat = 0
		dblSVKvarhFat = 0
		
		While Not arsConsulta.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"'
			dblQCons = IIf(IsDbNull(arsConsulta.Fields("qcons").Value), 0, arsConsulta.Fields("qcons").Value) 'Quantidade de Consumidores
			'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"'
			dblQKwhCons = IIf(IsDbNull(arsConsulta.Fields("qkwh_cons").Value), 0, arsConsulta.Fields("qkwh_cons").Value) 'Consumo Lido
			'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"'
			dblQKwhFat = IIf(IsDbNull(arsConsulta.Fields("qkwh_fat").Value), 0, arsConsulta.Fields("qkwh_fat").Value) 'Consumo Faturado
			'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"'
			dblVKwhFat = IIf(IsDbNull(arsConsulta.Fields("vkwh").Value), 0, arsConsulta.Fields("vkwh").Value) 'Valor Consumo Faturado
			'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"'
			dblVKwFat = IIf(IsDbNull(arsConsulta.Fields("vkw").Value), 0, arsConsulta.Fields("vkw").Value) 'Valor Demanda
			'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"'
			dblVKvarhFat = IIf(IsDbNull(arsConsulta.Fields("vkvarh").Value), 0, arsConsulta.Fields("vkvarh").Value) 'Valor Reativo
			'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"'
			strClasse = IIf(IsDbNull(arsConsulta.Fields("classe").Value), 0, arsConsulta.Fields("classe").Value) 'Classe
			'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"'
			strNmClasse = IIf(IsDbNull(arsConsulta.Fields("nmclasse").Value), "", arsConsulta.Fields("nmclasse").Value) 'Nome da Classe
			dblTQCons = dblTQCons + dblQCons
			dblTQKwhCons = dblTQKwhCons + dblQKwhCons
			dblTQKwhFat = dblTQKwhFat + dblQKwhFat
			dblTVKwhFat = dblTVKwhFat + dblVKwhFat
			dblTVKwFat = dblTVKwFat + dblVKwFat
			dblTVKvarhFat = dblTVKvarhFat + dblVKvarhFat
			
			If ablnStartDoc = False Then
				fr.VS.StartDoc()
				ablnStartDoc = True
			End If
			If blnAnalitico 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"'
				strNome = IIf(IsDbNull(arsConsulta.Fields("nome").Value), "", arsConsulta.Fields("nome").Value) 'Nome da Unidade Consumidora
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				strGrupo = IIf(IsDbNull(arsConsulta.Fields("grupo").Value), "", arsConsulta.Fields("grupo").Value) 'Grupo
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				strZona = IIf(IsDbNull(arsConsulta.Fields("zona").Value), "", arsConsulta.Fields("zona").Value) 'Zona
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				strLivro = IIf(IsDbNull(arsConsulta.Fields("livro").Value), "", arsConsulta.Fields("livro").Value) 'Livro
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				strConta = IIf(IsDbNull(arsConsulta.Fields("conta").Value), "", arsConsulta.Fields("conta").Value) 'Conta
			End If
			If blnAnalitico Then
				If Trim(strClasseAnt) = "" Then strClasseAnt = strClasse
				If strClasseAnt <> strClasse Then
					'        fr.VS.TableBorder = tbBoxRows
					'total de cada classe
					dblAuxiliar = 0
					If Me.chkKwh.CheckState Then dblAuxiliar = dblAuxiliar + dblSVKwhFat
					If Me.chkKw.CheckState Then dblAuxiliar = dblAuxiliar + dblSVKwFat
					If Me.chkKvarh.CheckState Then dblAuxiliar = dblAuxiliar + dblSVKvarhFat
					fr.VS.TableBorder = VSVIEW6.TableBorderSettings.tbBoxRows
					strTemp = "<44mm|>20mm|<30mm|>23mm|<38mm|>25mm;No. de Consumidores:|" & FormatNumber(dblSQCons, 0) & "|" & "Consumo Kwh:|" & FormatNumber(IIf(Me.opbConsumo.Checked, dblSQKwhCons, dblSQKwhFat), 0) & "|" & "Energia distribuida:|" & VB6.Format(dblAuxiliar, "standard")
					'UPGRADE_ISSUE: VBControlExtender method fr.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
					fr.VS.DrawLine("79mm", fr.VS.CurrentY, "79mm", fr.VS.CurrentY + 140)
					'UPGRADE_ISSUE: VBControlExtender method fr.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
					fr.VS.DrawLine("132mm", fr.VS.CurrentY, "132mm", fr.VS.CurrentY + 140)
					fr.VS.Table = strTemp
					fr.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
					dblSQCons = 0
					dblSQKwhCons = 0
					dblSQKwhFat = 0
					dblSVKwhFat = 0
					dblSVKwFat = 0
					dblSVKvarhFat = 0
					strClasseAnt = strClasse
					fr.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
				End If
				If strClasseOld <> strClasse Then
					fr.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
					'UPGRADE_ISSUE: VBControlExtender method fr.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
					fr.VS.Table = "<10mm;" & "|" & fr.VS.CurrentY
					'        fr.VS.TableBorder = tbAll
					fr.VS.Font = VB6.FontChangeBold(fr.VS.Font, True)
					strTemp = VB.Left("CLASSE: (" & VB6.Format(strClasse, "0000") & ") - " & strNmClasse, 70)
					fr.VS.Table = "<180mm;" & strTemp
					fr.VS.Font = VB6.FontChangeBold(fr.VS.Font, False)
					strClasseOld = strClasse
					fr.VS.Font = VB6.FontChangeBold(fr.VS.Font, True)
					strTemp = "<30mm|<135mm|^15mm;Identificador|Nome|Grupo"
					fr.VS.Table = strTemp
					fr.VS.Font = VB6.FontChangeBold(fr.VS.Font, False)
				End If
			Else
				'      fr.VS.TableBorder = tbBoxRows
				fr.VS.Font = VB6.FontChangeBold(fr.VS.Font, True)
				strTemp = VB.Left("CLASSE: (" & VB6.Format(strClasse, "0000") & ") - " & strNmClasse, 70)
				fr.VS.Table = "<180mm;" & strTemp
				fr.VS.Font = VB6.FontChangeBold(fr.VS.Font, False)
			End If
			If Me.opbSintetico.Checked Then
				dblAuxiliar = 0
				If Me.chkKwh.CheckState Then dblAuxiliar = dblAuxiliar + dblVKwhFat
				If Me.chkKw.CheckState Then dblAuxiliar = dblAuxiliar + dblVKwFat
				If Me.chkKvarh.CheckState Then dblAuxiliar = dblAuxiliar + dblVKvarhFat
				fr.VS.TableBorder = VSVIEW6.TableBorderSettings.tbBoxRows
				strTemp = "<44mm|>20mm|<30mm|>23mm|<38mm|>25mm;No. de Consumidores:|" & FormatNumber(dblQCons, 0) & "|" & "Consumo Kwh:|" & FormatNumber(IIf(Me.opbConsumo.Checked, dblQKwhCons, dblQKwhFat), 0) & "|" & "Energia distribuida:|" & VB6.Format(dblAuxiliar, "standard")
				'UPGRADE_ISSUE: VBControlExtender method fr.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
				fr.VS.DrawLine("79mm", fr.VS.CurrentY, "79mm", fr.VS.CurrentY + 140)
				'UPGRADE_ISSUE: VBControlExtender method fr.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
				fr.VS.DrawLine("132mm", fr.VS.CurrentY, "132mm", fr.VS.CurrentY + 140)
			End If
			If blnAnalitico Then
				'      fr.VS.TableBorder = tbAll
				strTemp = "<30mm|<135mm|^15mm;"
				strTemp = strTemp & strZona & "." & strLivro & "." & strConta & "|"
				strTemp = strTemp & strNome & "|"
				strTemp = strTemp & IIf(VB.Left(strGrupo, 1) = "B", "B", IIf(VB.Left(strGrupo, 2) = "AV", "Verde", IIf(VB.Left(strGrupo, 2) = "AA", "Azul", IIf(VB.Left(strGrupo, 2) = "A4", "Conv.", IIf(VB.Left(strGrupo, 2) = "AP", "Prod.", IIf(VB.Left(strGrupo, 2) = "AL", "Livre", ""))))))
			End If
			fr.VS.Table = strTemp
			fr.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
			If Me.opbSintetico.Checked Then
				'      If fr.VS.CurrentLine <= 159 Then
				'UPGRADE_ISSUE: VBControlExtender method fr.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
				fr.VS.Table = "<10mm;" & "|" & fr.VS.CurrentY
				'      End If
			End If
			Call arsConsulta.MoveNext()
			dblSQCons = dblSQCons + dblQCons
			dblSQKwhCons = dblSQKwhCons + dblQKwhCons
			dblSQKwhFat = dblSQKwhFat + dblQKwhFat
			dblSVKwhFat = dblSVKwhFat + dblVKwhFat
			dblSVKwFat = dblSVKwFat + dblVKwFat
			dblSVKvarhFat = dblSVKvarhFat + dblVKvarhFat
		End While
		
		If blnAnalitico Then
			'    fr.VS.TableBorder = tbBoxRows
			dblAuxiliar = 0
			If Me.chkKwh.CheckState Then dblAuxiliar = dblAuxiliar + dblSVKwhFat
			If Me.chkKw.CheckState Then dblAuxiliar = dblAuxiliar + dblSVKwFat
			If Me.chkKvarh.CheckState Then dblAuxiliar = dblAuxiliar + dblSVKvarhFat
			fr.VS.TableBorder = VSVIEW6.TableBorderSettings.tbBoxRows
			strTemp = "<44mm|>20mm|<30mm|>23mm|<38mm|>25mm;No. de Consumidores:|" & FormatNumber(dblSQCons, 0) & "|" & "Consumo Kwh:|" & FormatNumber(IIf(Me.opbConsumo.Checked, dblSQKwhCons, dblSQKwhFat), 0) & "|" & "Energia distribuida:|" & VB6.Format(dblAuxiliar, "standard")
			'UPGRADE_ISSUE: VBControlExtender method fr.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
			fr.VS.DrawLine("79mm", fr.VS.CurrentY, "79mm", fr.VS.CurrentY + 140)
			'UPGRADE_ISSUE: VBControlExtender method fr.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
			fr.VS.DrawLine("132mm", fr.VS.CurrentY, "132mm", fr.VS.CurrentY + 140)
			fr.VS.Table = strTemp
			fr.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
			dblSQCons = 0
			dblSQKwhCons = 0
			dblSQKwhFat = 0
			dblSVKwhFat = 0
			fr.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
		End If
		fr.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
		fr.VS.Table = "<10mm;" & "|"
		'  fr.VS.TableBorder = tbBoxRows
		fr.VS.Font = VB6.FontChangeBold(fr.VS.Font, True)
		strTemp = "TOTAL GERAL"
		fr.VS.Table = "<180mm;" & strTemp
		fr.VS.Font = VB6.FontChangeBold(fr.VS.Font, False)
		'  fr.VS.TableBorder = tbBoxRows
		dblAuxiliar = 0
		If Me.chkKwh.CheckState Then dblAuxiliar = dblAuxiliar + dblTVKwhFat
		If Me.chkKw.CheckState Then dblAuxiliar = dblAuxiliar + dblTVKwFat
		If Me.chkKvarh.CheckState Then dblAuxiliar = dblAuxiliar + dblTVKvarhFat
		fr.VS.TableBorder = VSVIEW6.TableBorderSettings.tbBoxRows
		strTemp = "<44mm|>20mm|<30mm|>23mm|<38mm|>25mm;No. de Consumidores:|" & FormatNumber(dblTQCons, 0) & "|" & "Consumo Kwh:|" & FormatNumber(IIf(Me.opbConsumo.Checked, dblTQKwhCons, dblTQKwhFat), 0) & "|" & "Energia distribuida:|" & VB6.Format(dblAuxiliar, "standard")
		'UPGRADE_ISSUE: VBControlExtender method fr.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
		fr.VS.DrawLine("79mm", fr.VS.CurrentY, "79mm", fr.VS.CurrentY + 140)
		'UPGRADE_ISSUE: VBControlExtender method fr.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
		fr.VS.DrawLine("132mm", fr.VS.CurrentY, "132mm", fr.VS.CurrentY + 140)
		fr.VS.Table = strTemp
		fr.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
	End Sub
	
	Public Function CabecaRel() As Object
		fr.VS.CurrentLine = 1
		fr.VS.MarginLeft = "7mm"
		Call Cabecalho_Relatorio((fr.VS), istrTitulo1, istrTitulo3, "4", True, istrTitulo)
		'UPGRADE_ISSUE: VBControlExtender method fr.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
		fr.VS.CurrentY = 1900
		'  fr.VS.Table = "<10mm;" & "|"
		'  fr.VS.Table = "<10mm;" & "|"
		'  fr.VS.Table = "<10mm;" & "|"
		fr.VS.MarginLeft = "15mm"
		fr.VS.MarginRight = "15mm"
		fr.VS.Font = VB6.FontChangeSize(fr.VS.Font, 6)
		
		If blnAnalitico Then
			fr.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
			'UPGRADE_ISSUE: VBControlExtender method fr.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
			fr.VS.Table = "<10mm;" & "|" & fr.VS.CurrentY
			'    fr.VS.TableBorder = tbAll
			fr.VS.Font = VB6.FontChangeBold(fr.VS.Font, True)
			fr.VS.Table = "<180mm;" & VB.Left("CLASSE: (" & VB6.Format(strClasse, "0000") & ") - " & strNmClasse, 70)
			fr.VS.Font = VB6.FontChangeBold(fr.VS.Font, False)
			strClasseOld = strClasse
			fr.VS.Font = VB6.FontChangeBold(fr.VS.Font, True)
			fr.VS.Table = "<30mm|<135mm|^15mm;Identificador|Nome|Grupo"
			fr.VS.Font = VB6.FontChangeBold(fr.VS.Font, False)
		Else
			'    fr.VS.TableBorder = tbBoxRows
			'    fr.VS.Table = "<180mm;" & Left("CLASSE: (" & Format(strClasse, "0000") & ") - " & strNmClasse, 70)
		End If
		
	End Function
	
	Private Function PegaNomeClasse(ByVal astrClasse As String) As String
		Dim rsClasse As ADODB.Recordset
		
		rsClasse = New ADODB.Recordset
		
		Call Conectar("SELECT descricao FROM classe WHERE codigo = """ & astrClasse & """ ", rsClasse)
		If rsClasse.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"'
			PegaNomeClasse = IIf(IsDbNull(rsClasse.Fields("descricao").Value), "NOME DA CLASSE NAO DEFINIDA", rsClasse.Fields("descricao").Value)
		Else
			PegaNomeClasse = "CLASSE INEXISTENTE"
		End If
		If rsClasse.State = 1 Then Call rsClasse.Close()
		'UPGRADE_NOTE: Object rsClasse 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"'
		rsClasse = Nothing
	End Function
	
	'-------------------------------------------
	Private Function MontaFiltro(ByVal alsvAuxiliar As System.Windows.Forms.ListView, ByVal aintColuna As Short) As String
		Dim strfiltro As String
		Dim intConta As Short
		
		'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"'
		If alsvAuxiliar.Items.Item(1).Checked = False Then
			strfiltro = ""
			For intConta = 2 To alsvAuxiliar.Items.Count
				'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"'
				If alsvAuxiliar.Items.Item(intConta).Checked = True Then
					If aintColuna = 1 Then
						'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"'
						strfiltro = strfiltro & """" & alsvAuxiliar.Items.Item(intConta).Text & ""","
					Else
						'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"'
						'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"'
						strfiltro = strfiltro & """" & alsvAuxiliar.Items.Item(intConta).SubItems(aintColuna - 1).Text & ""","
					End If
				End If
			Next intConta
			If Len(Trim(strfiltro)) > 0 Then
				strfiltro = " (" & VB.Left(strfiltro, Len(strfiltro) - 1) & ") "
			End If
		End If
		MontaFiltro = strfiltro
	End Function
	
	Private Sub CarregaClasses(ByRef alsvAuxiliar As System.Windows.Forms.ListView)
		'Versão: 001 Desenvolvedor: Ricardo Inacio Data: 03/06/2008 Descrição: Função para carregar as classe em uma listview com checkbox
		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("", "Descrição", 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 = " = 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("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 = " = 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("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 CarregaCidades(ByRef alsvAuxiliar As System.Windows.Forms.ListView)
		'Versão: 001 Desenvolvedor: Ricardo Inacio Data: 03/06/2008 Descrição: Função para carregar as cidades em uma listview com checkbox
		Dim rsConsulta As ADODB.Recordset
		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
		
		rsConsulta = New ADODB.Recordset
		' ----- Limpa a List que carrega as cidades
		alsvAuxiliar.Items.Clear()
		
		If alsvAuxiliar.Columns.Count <= 1 Then
			clhColunas = alsvAuxiliar.Columns.Add("", "Cidades", CInt(VB6.TwipsToPixelsX(1600)))
			clhColunas = alsvAuxiliar.Columns.Add("", "Zona", CInt(VB6.TwipsToPixelsX(550)))
		End If
		' ----- Busca as Cidades
		istrSql = "SELECT DISTINCT zona, nome " & "  FROM munic " & " ORDER BY zona ASC, nome ASC"
		Call Conectar(istrSql, rsConsulta)
		
		' ----- Se Retornou alguma coisa, monta as cidades
		If rsConsulta.RecordCount > 0 Then
			lsiItens = alsvAuxiliar.Items.Add("Marcar Todas")
			'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).Checked = True
			While Not rsConsulta.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"'
				strNome = Trim(IIf(IsDbNull(rsConsulta.Fields("nome").Value), "", rsConsulta.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"'
				strZona = IIf(IsDbNull(rsConsulta.Fields("zona").Value), "", rsConsulta.Fields("zona").Value)
				lsiItens = alsvAuxiliar.Items.Add(strNome)
				'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 = strZona
				Else
					lsiItens.SubItems.Insert(1, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, strZona))
				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
				If lngTamanho < Len(strNome) Then lngTamanho = Len(strNome)
				Call rsConsulta.MoveNext()
			End While
		End If
		'UPGRADE_WARNING: Lower bound of collection alsvAuxiliar.ColumnHeaders 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.Columns.Item(1).Width = VB6.TwipsToPixelsX(lngTamanho * 300)
		If rsConsulta.State = 1 Then Call rsConsulta.Close()
		'UPGRADE_NOTE: Object rsConsulta 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"'
		rsConsulta = Nothing
	End Sub
	
	Private Sub LigDesCampos(ByVal ablnModo As Boolean)
		Me.FrameGrupo.Enabled = ablnModo
		Me.chkGrupoA.Enabled = ablnModo
		Me.chkGrupoB.Enabled = ablnModo
		Me.chkGrupoAB.Enabled = ablnModo
		Me.FrameTipo.Enabled = ablnModo
		Me.opbSintetico.Enabled = ablnModo
		Me.opbAnalitico.Enabled = ablnModo
		Me.FrameConsumo.Enabled = ablnModo
		Me.opbConsumo.Enabled = ablnModo
		Me.opbFaturado.Enabled = ablnModo
		Me.FrameValor.Enabled = ablnModo
		Me.chkKwh.Enabled = ablnModo
		Me.chkKw.Enabled = ablnModo
		Me.chkKvarh.Enabled = ablnModo
		Me.FrameSelecao.Enabled = ablnModo
		Me.opbMesAno.Enabled = ablnModo
		Me.opbPeriodo.Enabled = ablnModo
		Me.dtpMesAno.Enabled = ablnModo
		Me.dtpInicial.Enabled = ablnModo
		Me.dtpFinal.Enabled = ablnModo
		Me.FrameDatas.Enabled = ablnModo
		Me.opbMesAnoFat.Enabled = ablnModo
		Me.opbDtVencto.Enabled = ablnModo
		Me.opbDtLeitAnt.Enabled = ablnModo
		Me.opbDtLeitAtu.Enabled = ablnModo
		Me.opbDtApres.Enabled = ablnModo
		Me.opbDtEmissao.Enabled = ablnModo
		Me.opbDtPagto.Enabled = ablnModo
		Me.FrameClasses.Enabled = ablnModo
		Me.lvsClasses.Enabled = ablnModo
		Me.FrameCidades.Enabled = ablnModo
		Me.lvsCidades.Enabled = ablnModo
		Me.cmdEmitir.Enabled = ablnModo
		Me.cmdFechar.Enabled = ablnModo
		System.Windows.Forms.Application.DoEvents()
	End Sub
End Class