Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmRelPeePeriodo
	Inherits System.Windows.Forms.Form
	Private iintMeses As Short
	
	Private Sub cmdArquivo_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdArquivo.Click
		Me.dialArqOpen.DefaultExt = "CSV"
		'UPGRADE_WARNING: Filter has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
		Me.dialArqOpen.Filter = "*." & Me.dialArqOpen.DefaultExt
		Me.dialArqOpen.FileName = My.Application.Info.DirectoryPath & "\PEE_" & VB6.Format(BuscaDataBD, "yyyymmddHHMMSS") & "." & Me.dialArqOpen.DefaultExt
		Me.dialArqOpen.Title = "Arquivo de exportação de P.E.E."
		Me.dialArqOpen.ShowDialog()
		Me.txtArquivo.Text = Me.dialArqOpen.FileName
	End Sub
	
	Private Sub cmdExporta_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExporta.Click
		Dim lstrLin As String
		Dim lintARQ As Short
		Dim llngRow As Integer
		Dim llngCol As Integer
		If Trim(Me.txtArquivo.Text) <> "" Then
			lintARQ = FreeFile
			FileOpen(lintARQ, Me.txtArquivo.Text, OpenMode.Output)
			With Me.mfgDados
				For llngRow = 0 To .Rows - 1
					lstrLin = ""
					For llngCol = 0 To .Cols - 1
						lstrLin = lstrLin & .get_TextMatrix(llngRow, llngCol) & ";"
					Next llngCol
					PrintLine(lintARQ, lstrLin)
				Next llngRow
			End With
			FileClose(lintARQ)
			Call MsgBox("Arquivo gerado com sucesso!", MsgBoxStyle.Information, gstrTituloMensagem)
		Else
			Call MsgBox("Você precisa selecionar o caminho e o arquivo para exportação!", MsgBoxStyle.Information, gstrTituloMensagem)
		End If
	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 cmdImprimir_Click()
		Call ImprimirPee()
	End Sub
	
	Private Sub cmdProcessar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdProcessar.Click
		' Me.mfgDados.Redraw = False
		Call EncheGrade()
		' Me.mfgDados.Redraw = True
	End Sub
	
	Private Sub frmRelPeePeriodo_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Dim lstrSql As String
		Call CenterForm(Me)
		Call CarregaClasses((Me.lsvClasses))
		Me.dtpIni.value = BuscaDataBD
		Me.dtpIni.value = CDate("01/" & VB6.Format(Me.dtpIni.value, "mm/yyyy"))
		Me.dtpFim.value = System.Date.FromOADate(CDate(UltimoDiaMes((Me.dtpIni.Month), (Me.dtpIni.Year)) & "/" & VB6.Format(Me.dtpIni.value, "mm/yyyy")).ToOADate + 1)
		Call MontaGrade()
	End Sub
	
	Private Sub EncheGrade()
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim lstrRota As String
		Dim lstrRegiao As String
		Dim lstrFase As String
		Dim lstrSituacao As String
		Dim lstrGrupo As String
		Dim lstrClas As String
		Dim lstrClasNf As String
		Dim lstrNome As String
		Dim lstrEndCid As String
		Dim lstrEndDis As String
		Dim lstrEndBai As String
		Dim lstrEndLog As String
		Dim lstrEndNum As String
		Dim lstrEndCom As String
		Dim lstrMedidor As String
		Dim llngConsId As Integer
		Dim llngCoIdNf As Integer
		Dim llngUnidId As Integer
		Dim ldblNumNF As Double
		Dim llngMesano As Integer
		Dim lstrItens As String
		Dim lstrNrCpf As String
		Dim lstrNrNis As String
		Dim ldteNis As Date
		Dim ldteNovoNis As Date
		Dim llngKwhFat As Integer
		Dim lintAux As Short
		Dim llngPosRow As Integer
		Dim llngPosCol As Integer
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		Dim lrstFat As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lrstFat = New ADODB.Recordset
		'
		ldteNovoNis = CDate(LeConfig("DATANOVOBXRENDA"))
		Call MontaGrade()
		Me.lblInfo.Text = " Buscando os dados aguarde... "
		Call Me.lblInfo.Refresh()
		lstrSql = ""
		lstrSql = lstrSql & "SELECT " & vbCrLf
		lstrSql = lstrSql & "       nf.numnf, " & vbCrLf
		lstrSql = lstrSql & "       nf.mesano, " & vbCrLf
		lstrSql = lstrSql & "       nf.mesano_ref, " & vbCrLf
		lstrSql = lstrSql & "       nf.cons_id, " & vbCrLf
		lstrSql = lstrSql & "       nf.unid_id, " & vbCrLf
		lstrSql = lstrSql & "       nf.zona, " & vbCrLf
		lstrSql = lstrSql & "       nf.livro, " & vbCrLf
		lstrSql = lstrSql & "       nf.conta, " & vbCrLf
		lstrSql = lstrSql & "       nf.grupo, " & vbCrLf
		lstrSql = lstrSql & "       nf.codclas, " & vbCrLf
		lstrSql = lstrSql & "       nf.itensserv " & vbCrLf
		lstrSql = lstrSql & "  FROM nf " & vbCrLf
		lstrSql = lstrSql & " WHERE nf.mesano_ref BETWEEN " & CInt(VB6.Format(Me.dtpIni.value, "yyyymm")) & " AND " & CInt(VB6.Format(Me.dtpFim.value, "yyyymm")) & " " & vbCrLf
		lstrSql = lstrSql & MontaFiltroClasse & vbCrLf
		lstrSql = lstrSql & " ORDER BY nf.mesano_ref DESC "
		Call Conectar(lstrSql, lrstFat)
		With lrstFat
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount)
					While Not .EOF
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldblNumNF = CDbl(IIf(IsDbNull(.Fields("numnf").value), 0, .Fields("numnf").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						llngMesano = CInt(IIf(IsDbNull(.Fields("mesano_ref").value), 0, .Fields("mesano_ref").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"'
						lstrItens = Trim(IIf(IsDbNull(.Fields("itensserv").value), "", .Fields("itensserv").value))
						llngKwhFat = BuscaVlrItem(lstrItens, "030201009")
						'UPGRADE_WARNING: 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"'
						llngCoIdNf = CInt(IIf(IsDbNull(.Fields("cons_id").value), 0, .Fields("cons_id").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						llngUnidId = CInt(IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrGrupo = Trim(IIf(IsDbNull(.Fields("grupo").value), "B", .Fields("grupo").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrClasNf = Trim(IIf(IsDbNull(.Fields("codclas").value), "0000", .Fields("codclas").value))
						If lstrGrupo = "B" Then
							lstrSql = ""
							lstrSql = lstrSql & "SELECT " & vbCrLf
							lstrSql = lstrSql & "       `cons_id`, " & vbCrLf
							lstrSql = lstrSql & "       `unid_id`, " & vbCrLf
							lstrSql = lstrSql & "       `zona`, " & vbCrLf
							lstrSql = lstrSql & "       `livro`, " & vbCrLf
							lstrSql = lstrSql & "       `conta`, " & vbCrLf
							lstrSql = lstrSql & "       `rota`, " & vbCrLf
							lstrSql = lstrSql & "       `regiao`, " & vbCrLf
							lstrSql = lstrSql & "       `fase`, " & vbCrLf
							lstrSql = lstrSql & "       `situacao`, " & vbCrLf
							lstrSql = lstrSql & "       `clas`, " & vbCrLf
							lstrSql = lstrSql & "       `nome`, " & vbCrLf
							lstrSql = lstrSql & "       `cidade`, " & vbCrLf
							lstrSql = lstrSql & "       `distrito`, " & vbCrLf
							lstrSql = lstrSql & "       `bairro`, " & vbCrLf
							lstrSql = lstrSql & "       `end`, " & vbCrLf
							lstrSql = lstrSql & "       `numero`, " & vbCrLf
							lstrSql = lstrSql & "       `complement`, " & vbCrLf
							lstrSql = lstrSql & "       `num` AS `medidor`, " & vbCrLf
							lstrSql = lstrSql & "       `cpf_cnpj` " & vbCrLf
							lstrSql = lstrSql & "  FROM `unidb` " & vbCrLf
							lstrSql = lstrSql & " WHERE `unidb`.`unid_id` = " & llngUnidId
							'lstrSql = lstrSql & "   AND `unidb`.`cons_id` = " & llngCoIdNf
							lstrSql = lstrSql & "   AND `unidb`.`zona` = " & lstrZona
							lstrSql = lstrSql & "   AND `unidb`.`livro` = " & lstrLivro
							lstrSql = lstrSql & "   AND `unidb`.`conta` = " & lstrConta
						Else
							lstrSql = ""
							lstrSql = lstrSql & "SELECT " & vbCrLf
							lstrSql = lstrSql & "       `cons_id`, " & vbCrLf
							lstrSql = lstrSql & "       `unid_id`, " & vbCrLf
							lstrSql = lstrSql & "       `zona`, " & vbCrLf
							lstrSql = lstrSql & "       `livro`, " & vbCrLf
							lstrSql = lstrSql & "       `conta`, " & vbCrLf
							lstrSql = lstrSql & "       `rota`, " & vbCrLf
							lstrSql = lstrSql & "       `regiao`, " & vbCrLf
							lstrSql = lstrSql & "       `fase`, " & vbCrLf
							lstrSql = lstrSql & "       `situacao`, " & vbCrLf
							lstrSql = lstrSql & "       `clas`, " & vbCrLf
							lstrSql = lstrSql & "       `nome`, " & vbCrLf
							lstrSql = lstrSql & "       `cidade`, " & vbCrLf
							lstrSql = lstrSql & "       `distrito`, " & vbCrLf
							lstrSql = lstrSql & "       `bairro`, " & vbCrLf
							lstrSql = lstrSql & "       `end`, " & vbCrLf
							lstrSql = lstrSql & "       `numero`, " & vbCrLf
							lstrSql = lstrSql & "       `complement`, " & vbCrLf
							lstrSql = lstrSql & "       `eletr` AS `medidor`, " & vbCrLf
							lstrSql = lstrSql & "       `cpf_cnpj` " & vbCrLf
							lstrSql = lstrSql & "  FROM `unida` " & vbCrLf
							lstrSql = lstrSql & " WHERE `unida`.`unid_id` = " & llngUnidId
							'lstrSql = lstrSql & "   AND `unida`.`cons_id` = " & llngCoIdNf
							lstrSql = lstrSql & "   AND `unida`.`zona` = " & lstrZona
							lstrSql = lstrSql & "   AND `unida`.`livro` = " & lstrLivro
							lstrSql = lstrSql & "   AND `unida`.`conta` = " & lstrConta
						End If
						Call Conectar(lstrSql, lrstAux)
						With lrstAux
							If .State = ADODB.ObjectStateEnum.adStateOpen Then
								If .RecordCount > 0 Then
									While Not .EOF
										'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
										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"'
										lstrRegiao = Trim(IIf(IsDbNull(.Fields("regiao").value), "U", .Fields("regiao").value))
										'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
										lstrFase = Trim(IIf(IsDbNull(.Fields("fase").value), "M", .Fields("fase").value))
										'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
										lstrSituacao = Trim(IIf(IsDbNull(.Fields("situacao").value), "L", .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"'
										lstrClas = Trim(IIf(IsDbNull(.Fields("clas").value), "0000", .Fields("clas").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"'
										lstrEndCid = 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"'
										lstrEndDis = 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"'
										lstrEndBai = 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"'
										lstrEndLog = Trim(IIf(IsDbNull(.Fields("end").value), "", .Fields("end").value))
										'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
										lstrEndNum = 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"'
										lstrEndCom = Trim(IIf(IsDbNull(.Fields("complement").value), "", .Fields("complement").value))
										'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
										lstrMedidor = Trim(IIf(IsDbNull(.Fields("medidor").value), "", .Fields("medidor").value))
										'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
										llngConsId = CInt(IIf(IsDbNull(.Fields("cons_id").value), 0, .Fields("cons_id").value))
										'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
										llngUnidId = CInt(IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").value))
										'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
										lstrNrCpf = Trim(IIf(IsDbNull(.Fields("cpf_cnpj").value), "", .Fields("cpf_cnpj").value))
										If llngCoIdNf <> llngConsId Then
											lstrNrCpf = BuscaCpfCnpjConsumidor(llngCoIdNf)
											lstrNome = BuscaNomeConsumidor(llngCoIdNf)
										End If
										If VB.Left(lstrGrupo, 1) = "B" Then
											lstrNrNis = BuscaNis(lstrZona, lstrLivro, lstrConta, llngUnidId, lstrNrCpf)
											ldteNis = BuscaDataNis(lstrNrNis)
										Else
											lstrNrNis = ""
										End If
										llngPosRow = PegaLinGrade(lstrZona & "." & lstrLivro & "." & lstrConta, lstrClasNf, lstrNome)
										llngPosCol = PegaColGrade(llngMesano)
										With Me.mfgDados
											If llngPosRow = 0 Then
												.Rows = .Rows + 1
												llngPosRow = .Rows - 1
												.set_TextMatrix(llngPosRow, 0, lstrEndBai)
												.set_TextMatrix(llngPosRow, 1, lstrZona & "." & lstrLivro & "." & lstrConta)
												.set_TextMatrix(llngPosRow, 2, VB.Left(lstrRota, 4))
												.set_TextMatrix(llngPosRow, 3, VB.Right(lstrRota, 4))
												.set_TextMatrix(llngPosRow, 4, lstrClasNf)
												.set_TextMatrix(llngPosRow, 5, BuscaClasse(lstrClasNf))
												.set_TextMatrix(llngPosRow, 6, lstrNome)
												.set_TextMatrix(llngPosRow, 7, lstrEndLog)
												.set_TextMatrix(llngPosRow, 8, lstrEndNum)
												.set_TextMatrix(llngPosRow, 9, lstrEndCom)
												.set_TextMatrix(llngPosRow, 10, lstrEndCid)
												.set_TextMatrix(llngPosRow, 11, lstrEndDis)
												.set_TextMatrix(llngPosRow, 12, lstrMedidor)
												.set_TextMatrix(llngPosRow, 13, IIf(lstrRegiao = "R", "Rural", "Urbana"))
												.set_TextMatrix(llngPosRow, 14, IIf(lstrFase = "M", "Monofásico", IIf(lstrFase = "B", "Bifásico", "Trifásico")))
												.set_TextMatrix(llngPosRow, 15, IIf(lstrSituacao = "L", "Ligado", IIf(lstrSituacao = "D", "Desligado", IIf(lstrSituacao = "C", "Suspenso", IIf(lstrSituacao = "I", "Desativado", "Não Ligado")))))
												.set_TextMatrix(llngPosRow, 16, lstrGrupo)
												.set_TextMatrix(llngPosRow, 17, lstrNrNis)
												.set_TextMatrix(llngPosRow, 18, IIf(lstrClasNf = "9105", IIf(ldteNis >= ldteNovoNis, "TSEE", ""), ""))
											End If
											'.TextMatrix(llngPosRow, llngPosCol) = llngKwhFat
											.set_TextMatrix(llngPosRow, llngPosCol, "X")
										End With
										Call .MoveNext()
									End While
								End If
								Call .Close()
							End If
						End With
						Call .MoveNext()
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
					End While
				End If
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
		'UPGRADE_NOTE: Object lrstFat may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstFat = Nothing
	End Sub
	
	Private Function PegaLinGrade(ByVal astrZLC As String, ByVal astrCla As String, ByVal astrNome As String) As Integer
		Dim llngPos As Integer
		Dim llngRow As Integer
		llngPos = 0
		With Me.mfgDados
			If .Rows > 1 Then
				'Busca a linha da grid que tem a informacao
				For llngRow = 1 To .Rows - 1
					If .get_TextMatrix(llngRow, 1) = astrZLC And .get_TextMatrix(llngRow, 4) = astrCla And .get_TextMatrix(llngRow, 6) = astrNome Then
						llngPos = llngRow
						llngRow = .Rows - 1
					End If
				Next llngRow
			End If
		End With
		PegaLinGrade = llngPos
	End Function
	
	Private Function PegaColGrade(ByVal alngMesAno As Integer) As Integer
		Dim llngPos As Integer
		Dim llngCol As Integer
		llngPos = 0
		With Me.mfgDados
			If .Cols > 1 Then
				'Busca a linha da grid que tem a informacao
				For llngCol = (.Cols - iintMeses) To .Cols - 1
					If .get_TextMatrix(0, llngCol) = CStr(alngMesAno) Then
						llngPos = llngCol
						llngCol = .Cols - 1
					End If
				Next llngCol
			End If
		End With
		PegaColGrade = llngPos
	End Function
	
	
	Private Sub CarregaClasses(ByRef alsvAuxiliar As System.Windows.Forms.ListView)
		Dim lstrNome As String
		Dim lstrZona As String
		With Me.lsvClasses
			Call .Items.Clear()
			If .Columns.Count <= 1 Then
				Call .Columns.Add("", "Descrição", CInt(VB6.TwipsToPixelsX(5490)))
				Call .Columns.Add("", "Condição", CInt(VB6.TwipsToPixelsX(0)))
			End If
			Call .Items.Add("Marcar Todas")
			'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.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"'
			Call .Items.Item(.Items.Count).SubItems.Add(" ")
			Call .Items.Add("Residencial")
			'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.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"'
			Call .Items.Item(.Items.Count).SubItems.Add(" `codclas` = '9101'")
			Call .Items.Add("Residencial Bx.Renda")
			'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.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"'
			Call .Items.Item(.Items.Count).SubItems.Add(" `codclas` IN('9102', '9104', '9105', '9106')")
			Call .Items.Add("Industrial")
			'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.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"'
			Call .Items.Item(.Items.Count).SubItems.Add(" `codclas` BETWEEN 0 AND 3999 AND `codclas`<> '0100'")
			Call .Items.Add("Livre")
			'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.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"'
			Call .Items.Item(.Items.Count).SubItems.Add(" `codclas` = '0100'")
			Call .Items.Add("Comercial")
			'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.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"'
			Call .Items.Item(.Items.Count).SubItems.Add(" `codclas` BETWEEN 4000 AND 4999")
			Call .Items.Add("Rural")
			'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.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"'
			Call .Items.Item(.Items.Count).SubItems.Add(" `codclas` BETWEEN 5000 AND 5999")
			Call .Items.Add("Poder Público Municipal")
			'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.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"'
			Call .Items.Item(.Items.Count).SubItems.Add(" `codclas` BETWEEN 6100 AND 6199")
			Call .Items.Add("Poder Público Estadual")
			'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.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"'
			Call .Items.Item(.Items.Count).SubItems.Add(" `codclas` BETWEEN 6200 AND 6299")
			Call .Items.Add("Poder Público Federal")
			'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.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"'
			Call .Items.Item(.Items.Count).SubItems.Add(" `codclas` BETWEEN 6300 AND 6399")
			Call .Items.Add("Iluminação Pública")
			'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.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"'
			Call .Items.Item(.Items.Count).SubItems.Add(" `codclas` BETWEEN 6400 AND 6499")
			Call .Items.Add("Serviço Púplico")
			'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.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"'
			Call .Items.Item(.Items.Count).SubItems.Add(" `codclas` BETWEEN 7000 AND 7999")
			Call .Items.Add("Consumo Próprio")
			'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.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"'
			Call .Items.Item(.Items.Count).SubItems.Add(" `codclas` BETWEEN 8000 AND 8999")
			'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.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).Font = VB6.FontChangeBold(.Items.Item(1).Font, True)
			'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.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 = True
			'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.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"'
			Call lsvClasses_ItemCheck(lsvClasses, New System.Windows.Forms.ItemCheckEventArgs(.Items.Item(1).Index, System.Windows.Forms.CheckState.Indeterminate, .Items.Item(1).Checked))
		End With
		System.Windows.Forms.Application.DoEvents()
	End Sub
	
	Private Sub lsvClasses_ItemCheck(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.ItemCheckEventArgs) Handles lsvClasses.ItemCheck
		Dim aItem As System.Windows.Forms.ListViewItem = lsvClasses.Items(eventArgs.Index)
		Dim lintIdx As Short
		With Me.lsvClasses
			If aItem.Text = "Marcar Todas" Then
				For lintIdx = 1 To .Items.Count
					'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.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(lintIdx).Checked = .Items.Item(1).Checked
				Next lintIdx
			Else
				If aItem.Checked = False Then
					'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.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 Function MontaFiltroClasse() As String
		Dim lstrAux1 As String
		Dim lintIdx As Short
		lstrAux1 = ""
		With Me.lsvClasses
			'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.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
				lstrAux1 = " AND ("
				For lintIdx = 2 To .Items.Count
					'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.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(lintIdx).Checked = True Then
						'UPGRADE_WARNING: Lower bound of collection Me.lsvClasses.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.lsvClasses.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"'
						lstrAux1 = lstrAux1 & " " & .Items.Item(lintIdx).SubItems(1).Text & " OR "
					End If
				Next lintIdx
				If lstrAux1 = " AND (" Then
					lstrAux1 = ""
				Else
					lstrAux1 = VB.Left(lstrAux1, Len(lstrAux1) - 3) & ") "
				End If
			End If
		End With
		MontaFiltroClasse = lstrAux1
	End Function
	
	Private Sub MontaGrade()
		Dim lintAux As Short
		Dim llngAux As Integer
		Dim ldteLoop As Date
		Dim ldteAux As Date
		iintMeses = Fix(DateDiff(Microsoft.VisualBasic.DateInterval.Month, Me.dtpIni.value, Me.dtpFim.value)) + 1
		With Me.mfgDados
			.Clear()
			.Rows = 1
			.Cols = 19
			.Cols = .Cols + iintMeses
			.set_ColWidth(0, 2000)
			.set_ColWidth(1, 1200)
			.set_ColWidth(2, 700)
			.set_ColWidth(3, 750)
			.set_ColWidth(4, 1200)
			.set_ColWidth(5, 1200)
			.set_ColWidth(6, 2000)
			.set_ColWidth(7, 2000)
			.set_ColWidth(8, 900)
			.set_ColWidth(9, 2000)
			.set_ColWidth(10, 1200)
			.set_ColWidth(11, 1200)
			.set_ColWidth(12, 1200)
			.set_ColWidth(13, 900)
			.set_ColWidth(14, 1000)
			.set_ColWidth(15, 1000)
			.set_ColWidth(16, 600)
			.set_ColWidth(17, 1000)
			.set_ColWidth(18, 1000)
			'
			For lintAux = 1 To iintMeses
				.set_ColWidth(18 + lintAux, 1000)
			Next lintAux
			'
			.set_TextMatrix(0, 0, "Bairro")
			.set_TextMatrix(0, 1, "Identificação")
			.set_TextMatrix(0, 2, "Caderno")
			.set_TextMatrix(0, 3, "Sequência")
			.set_TextMatrix(0, 4, "Classe")
			.set_TextMatrix(0, 5, "Des.Classe")
			.set_TextMatrix(0, 6, "Nome")
			.set_TextMatrix(0, 7, "Endereço")
			.set_TextMatrix(0, 8, "Número")
			.set_TextMatrix(0, 9, "Complemento")
			.set_TextMatrix(0, 10, "Cidade")
			.set_TextMatrix(0, 11, "Distrito")
			.set_TextMatrix(0, 12, "Medidor")
			.set_TextMatrix(0, 13, "Região")
			.set_TextMatrix(0, 14, "Fase")
			.set_TextMatrix(0, 15, "Situação")
			.set_TextMatrix(0, 16, "Grupo")
			.set_TextMatrix(0, 17, "NIS")
			.set_TextMatrix(0, 18, "Tipo NIS")
			
			lintAux = 1
			ldteLoop = CDate("01/" & VB6.Format(Me.dtpIni.value, "mm/yyyy"))
			ldteAux = System.Date.FromOADate(ldteLoop.ToOADate - 1)
			While ldteLoop <= Me.dtpFim.value
				If CInt(VB6.Format(ldteAux, "yyyymm")) < CInt(VB6.Format(ldteLoop, "yyyymm")) Then
					.set_TextMatrix(0, 18 + lintAux, CInt(VB6.Format(ldteLoop, "yyyymm")))
					lintAux = lintAux + 1
					ldteAux = ldteLoop
				End If
				ldteLoop = System.Date.FromOADate(CDate(UltimoDiaMes(Month(ldteLoop), Year(ldteLoop)) & "/" & VB6.Format(ldteLoop, "mm/yyyy")).ToOADate + 1)
			End While
		End With
	End Sub
	
	Private Function BuscaClasse(ByVal astrClasse As String) As String
		Dim llngCodClas As Integer
		Dim lstrRet As String
		'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
		llngCodClas = CInt(IIf(IsNumeric(astrClasse), astrClasse, 0))
		If llngCodClas <= 3999 Then
			lstrRet = "Industrial"
			If llngCodClas = 100 Then lstrRet = "Livre"
		ElseIf llngCodClas >= 4000 And llngCodClas <= 4999 Then 
			lstrRet = "Comercial"
		ElseIf llngCodClas >= 5000 And llngCodClas <= 5999 Then 
			lstrRet = "Rural"
		ElseIf llngCodClas >= 6100 And llngCodClas <= 6199 Then 
			lstrRet = "Poder Público Municipal"
		ElseIf llngCodClas >= 6200 And llngCodClas <= 6299 Then 
			lstrRet = "Poder Público Estadual"
		ElseIf llngCodClas >= 6300 And llngCodClas <= 6399 Then 
			lstrRet = "Poder Público Federal"
		ElseIf llngCodClas >= 6400 And llngCodClas <= 6499 Then 
			lstrRet = "Iluminação Pública"
		ElseIf llngCodClas >= 7000 And llngCodClas <= 7999 Then 
			lstrRet = "Serviço Púplico"
		ElseIf llngCodClas >= 8000 And llngCodClas <= 8999 Then 
			lstrRet = "Consumo Próprio"
		ElseIf llngCodClas >= 9000 And llngCodClas <= 9999 Then 
			lstrRet = "Residencial"
			If llngCodClas = 9104 Then
				lstrRet = lstrRet & " bx.renda (res.246)"
			ElseIf llngCodClas = 9105 Then 
				lstrRet = lstrRet & " bx.renda (res.485)"
			ElseIf llngCodClas = 9106 Then 
				lstrRet = lstrRet & " bx.renda (res.694)"
			End If
		End If
		BuscaClasse = lstrRet
	End Function
	
	Private Sub ImprimirPee()
		'  Dim lstrSql As String
		'  Dim llngRow As Long
		'  Dim lstrAux As String
		'  Dim lstrCri As String
		'  '
		'  Call Executar("DELETE FROM `temp_relpee` WHERE `nomemaquina`   = """ & gstrNmEstacao & """ ")
		'  With Me.mfgDados
		'    Call BarraProgresso(Me.ProgressBar, Me.lblPerc, Me.lblInfo, 0, .Rows - 1)
		'    For llngRow = 1 To .Rows - 1
		'      lstrSql = ""
		'      lstrSql = lstrSql & "INSERT INTO `temp_relpee` SET " & vbCrLf
		'      lstrSql = lstrSql & "  `nomemaquina`   = """ & gstrNmEstacao & """," & vbCrLf
		'      lstrSql = lstrSql & "  `bairro`        = """ & .TextMatrix(llngRow, 0) & """," & vbCrLf
		'      lstrSql = lstrSql & "  `identificacao` = """ & .TextMatrix(llngRow, 1) & """," & vbCrLf
		'      lstrSql = lstrSql & "  `caderno`       = """ & .TextMatrix(llngRow, 2) & """," & vbCrLf
		'      lstrSql = lstrSql & "  `sequencia`     = """ & .TextMatrix(llngRow, 3) & """," & vbCrLf
		'      lstrSql = lstrSql & "  `classe`        = """ & .TextMatrix(llngRow, 4) & """," & vbCrLf
		'      lstrSql = lstrSql & "  `nome`          = """ & .TextMatrix(llngRow, 5) & """," & vbCrLf
		'      lstrSql = lstrSql & "  `end_log`       = """ & .TextMatrix(llngRow, 6) & """," & vbCrLf
		'      lstrSql = lstrSql & "  `end_num`       = """ & .TextMatrix(llngRow, 7) & """," & vbCrLf
		'      lstrSql = lstrSql & "  `end_com`       = """ & .TextMatrix(llngRow, 8) & """," & vbCrLf
		'      lstrSql = lstrSql & "  `end_cid`       = """ & .TextMatrix(llngRow, 9) & """," & vbCrLf
		'      lstrSql = lstrSql & "  `end_dis`       = """ & .TextMatrix(llngRow, 10) & """," & vbCrLf
		'      lstrSql = lstrSql & "  `medidor`       = """ & .TextMatrix(llngRow, 11) & """," & vbCrLf
		'      lstrSql = lstrSql & "  `regiao`        = """ & .TextMatrix(llngRow, 12) & """," & vbCrLf
		'      lstrSql = lstrSql & "  `fase`          = """ & .TextMatrix(llngRow, 13) & """," & vbCrLf
		'      lstrSql = lstrSql & "  `situacao`      = """ & .TextMatrix(llngRow, 14) & """," & vbCrLf
		'      lstrSql = lstrSql & "  `grupo`         = """ & .TextMatrix(llngRow, 15) & """," & vbCrLf
		'      lstrSql = lstrSql & "  `nis`           = """ & .TextMatrix(llngRow, 16) & """," & vbCrLf
		'      lstrSql = lstrSql & "  `mes_01`        = " & Replace(IIf(IsNumeric(.TextMatrix(llngRow, 17)), .TextMatrix(llngRow, 17), 0), ",", ".") & "," & vbCrLf
		'      lstrSql = lstrSql & "  `mes_02`        = " & Replace(IIf(IsNumeric(.TextMatrix(llngRow, 18)), .TextMatrix(llngRow, 18), 0), ",", ".") & "," & vbCrLf
		'      lstrSql = lstrSql & "  `mes_03`        = " & Replace(IIf(IsNumeric(.TextMatrix(llngRow, 19)), .TextMatrix(llngRow, 19), 0), ",", ".") & "," & vbCrLf
		'      lstrSql = lstrSql & "  `mes_04`        = " & Replace(IIf(IsNumeric(.TextMatrix(llngRow, 20)), .TextMatrix(llngRow, 20), 0), ",", ".") & "," & vbCrLf
		'      lstrSql = lstrSql & "  `mes_05`        = " & Replace(IIf(IsNumeric(.TextMatrix(llngRow, 21)), .TextMatrix(llngRow, 21), 0), ",", ".") & "," & vbCrLf
		'      lstrSql = lstrSql & "  `mes_06`        = " & Replace(IIf(IsNumeric(.TextMatrix(llngRow, 22)), .TextMatrix(llngRow, 22), 0), ",", ".") & "," & vbCrLf
		'      lstrSql = lstrSql & "  `mes_07`        = " & Replace(IIf(IsNumeric(.TextMatrix(llngRow, 23)), .TextMatrix(llngRow, 23), 0), ",", ".") & "," & vbCrLf
		'      lstrSql = lstrSql & "  `mes_08`        = " & Replace(IIf(IsNumeric(.TextMatrix(llngRow, 24)), .TextMatrix(llngRow, 24), 0), ",", ".") & "," & vbCrLf
		'      lstrSql = lstrSql & "  `mes_09`        = " & Replace(IIf(IsNumeric(.TextMatrix(llngRow, 25)), .TextMatrix(llngRow, 25), 0), ",", ".") & "," & vbCrLf
		'      lstrSql = lstrSql & "  `mes_10`        = " & Replace(IIf(IsNumeric(.TextMatrix(llngRow, 26)), .TextMatrix(llngRow, 26), 0), ",", ".") & "," & vbCrLf
		'      lstrSql = lstrSql & "  `mes_11`        = " & Replace(IIf(IsNumeric(.TextMatrix(llngRow, 27)), .TextMatrix(llngRow, 27), 0), ",", ".") & "," & vbCrLf
		'      lstrSql = lstrSql & "  `mes_12`        = " & Replace(IIf(IsNumeric(.TextMatrix(llngRow, 28)), .TextMatrix(llngRow, 28), 0), ",", ".") & "; "
		'      Call Executar(lstrSql)
		'      Call BarraProgresso(Me.ProgressBar, Me.lblPerc, Me.lblInfo, 1)
		'    Next llngRow
		'  End With
		'  '
		'  lstrCri = "{temp_relpee.nomemaquina} = """ & gstrNmEstacao & """ "
		'  lstrAux = " Grupo ("
		'  If Me.chkGrupoA.Value = 1 Then
		'    lstrAux = lstrAux & "A"
		'  End If
		'  If Me.chkGrupoB.Value = 1 Then
		'    lstrAux = lstrAux & "B"
		'  End If
		'  lstrAux = lstrAux & ") - Situação ("
		'  If Me.chkLigados.Value = 1 Then
		'    lstrAux = lstrAux & "L,"
		'  End If
		'  If Me.chkCortados.Value = 1 Then
		'    lstrAux = lstrAux & "C,"
		'  End If
		'  If Me.chkDesligados.Value = 1 Then
		'    lstrAux = lstrAux & "D,"
		'  End If
		'  If Me.chkDesativados.Value = 1 Then
		'    lstrAux = lstrAux & "I,"
		'  End If
		'  lstrAux = Left(lstrAux, Len(lstrAux) - 1) & ")"
		'  With Me.crpAux
		'    .ReportFileName = App.Path & "\" & LeConfig("DIR_RPT") & "RelPee.rpt"
		'    .DiscardSavedData = True
		'    .WindowState = crptMaximized
		'    .WindowControlBox = True
		'    .WindowControls = True
		'    .WindowShowPrintSetupBtn = True
		'    .WindowShowCloseBtn = True
		'    .WindowShowSearchBtn = True
		'    .SelectionFormula = lstrCri
		'    .WindowTitle = "Relatório dos em Aberto"
		'    .Destination = crptToWindow
		'    .Formulas(1) = "fn_titulo = """ & lstrAux & """ "
		'    .Action = 0
		'  End With
	End Sub
	
	Private Function BuscaNis(ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String, ByVal alngUnidId As Integer, ByVal astrCpf As String) As String
		Dim lstrRet As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrRet = ""
		lstrSql = ""
		lstrSql = lstrSql & "SELECT " & vbCrLf
		lstrSql = lstrSql & "       `nis`.`cpf`, " & vbCrLf
		lstrSql = lstrSql & "       `nis`.`zona`, " & vbCrLf
		lstrSql = lstrSql & "       `nis`.`livro`, " & vbCrLf
		lstrSql = lstrSql & "       `nis`.`conta`, " & vbCrLf
		lstrSql = lstrSql & "       `nis`.`unid_id`, " & vbCrLf
		lstrSql = lstrSql & "       `nis`.`nis`, " & vbCrLf
		lstrSql = lstrSql & "       `nis`.`evento` " & vbCrLf
		lstrSql = lstrSql & "  FROM `nis` " & vbCrLf
		lstrSql = lstrSql & " WHERE `nis`.`cpf`     = '" & astrCpf & "' " & vbCrLf
		lstrSql = lstrSql & "   AND `nis`.`zona`    = '" & astrZona & "' " & vbCrLf
		lstrSql = lstrSql & "   AND `nis`.`livro`   = '" & astrLivro & "' " & vbCrLf
		lstrSql = lstrSql & "   AND `nis`.`conta`   = '" & astrConta & "' " & vbCrLf
		lstrSql = lstrSql & "   AND `nis`.`unid_id` = " & alngUnidId & vbCrLf
		lstrSql = lstrSql & "   AND `nis`.`evento` <> 'D' " & vbCrLf
		lstrSql = lstrSql & "   AND `nis`.`nis` <> '' " & vbCrLf
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					lstrRet = Trim(IIf(IsDbNull(.Fields("nis").value), "", .Fields("nis").value))
				End If
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
		BuscaNis = lstrRet
	End Function
	
	Private Function BuscaDataNis(ByVal astrNrNis As String) As Date
		Dim ldteCad As Date
		Dim ldteAlt As Date
		Dim ldteRet As Date
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		ldteRet = CDate("01/01/1900")
		lstrSql = ""
		lstrSql = lstrSql & "SELECT " & vbCrLf
		lstrSql = lstrSql & "       `nis`.`cpf`, " & vbCrLf
		lstrSql = lstrSql & "       `nis`.`zona`, " & vbCrLf
		lstrSql = lstrSql & "       `nis`.`livro`, " & vbCrLf
		lstrSql = lstrSql & "       `nis`.`conta`, " & vbCrLf
		lstrSql = lstrSql & "       `nis`.`unid_id`, " & vbCrLf
		lstrSql = lstrSql & "       `nis`.`nis`, " & vbCrLf
		lstrSql = lstrSql & "       `nis`.`evento`, " & vbCrLf
		lstrSql = lstrSql & "       `nis`.`data_cadastro`, " & vbCrLf
		lstrSql = lstrSql & "       `nis`.`data_alteracao` " & vbCrLf
		lstrSql = lstrSql & "  FROM `nis` " & vbCrLf
		lstrSql = lstrSql & " WHERE `nis`.`nis` = '" & astrNrNis & "' " & vbCrLf
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					ldteCad = CDate(IIf(IsDbNull(.Fields("data_cadastro").value), "1900-01-01", .Fields("data_cadastro").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"'
					'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					ldteAlt = CDate(IIf(IsDbNull(.Fields("data_alteracao").value), "1900-01-01", .Fields("data_alteracao").value))
					If ldteAlt > ldteCad Then
						ldteRet = ldteAlt
					Else
						ldteRet = ldteCad
					End If
				End If
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
		BuscaDataNis = ldteRet
	End Function
	
	Private Function BuscaNomeConsumidor(ByVal alngConsId As Integer) As String
		Dim lstrRet As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrRet = "NOME NÃO ENCONTRADO"
		lstrSql = ""
		lstrSql = lstrSql & "SELECT " & vbCrLf
		lstrSql = lstrSql & "       `consreg`, " & vbCrLf
		lstrSql = lstrSql & "       `nome` " & vbCrLf
		lstrSql = lstrSql & "  FROM `consum` " & vbCrLf
		lstrSql = lstrSql & " WHERE `consum`.`consreg` = " & alngConsId & " " & vbCrLf
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					lstrRet = Trim(IIf(IsDbNull(.Fields("nome").value), "NOME EM BRANCO", .Fields("nome").value))
				End If
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
		BuscaNomeConsumidor = lstrRet
	End Function
	
	Private Function BuscaCpfCnpjConsumidor(ByVal alngConsId As Integer) As String
		Dim lstrRet As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrRet = "0"
		lstrSql = ""
		lstrSql = lstrSql & "SELECT " & vbCrLf
		lstrSql = lstrSql & "       `consreg`, " & vbCrLf
		lstrSql = lstrSql & "       `cgc` " & vbCrLf
		lstrSql = lstrSql & "  FROM `consum` " & vbCrLf
		lstrSql = lstrSql & " WHERE `consum`.`consreg` = " & alngConsId & " " & vbCrLf
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					lstrRet = Trim(IIf(IsDbNull(.Fields("cgc").value), "0", .Fields("cgc").value))
				End If
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
		BuscaCpfCnpjConsumidor = lstrRet
	End Function
End Class