Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmAcertaConsumidor
	Inherits System.Windows.Forms.Form
	Private istrTamCab As String
	Private istrTamCol As String
	Private istrCabecA As String
	Private istrCabecB As String
	Private ifrmAuxiliar As FrmRelatorio
	
	Private Sub CabecaRel(ByVal astrRotaAux As String)
		Dim lstrTable As String
		
		With ifrmAuxiliar
			.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
			'Retangulo de fora BRANCO
			.VS.BrushColor = System.Drawing.Color.White
			.VS.DrawRectangle("7mm", "10mm", "292mm", "30mm", "1mm")
			'Retangulo de dentro Cinza
			.VS.BrushColor = System.Drawing.ColorTranslator.FromOle(&HE0E0E0)
			.VS.DrawRectangle("37mm", "10mm", "265mm", "30mm")
			.VS.DrawPicture(System.Drawing.Image.FromFile(My.Application.Info.DirectoryPath & "\" & LeConfig("ARQUIVO_LOGOTIPO")), "10mm", "11mm", "22mm", "18mm")
			.VS.Font = VB6.FontChangeSize(.VS.Font, 10)
			.VS.Font = VB6.FontChangeBold(.VS.Font, True)
			'UPGRADE_ISSUE: VBControlExtender method ifrmAuxiliar.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
			.VS.CurrentY = "11mm"
			.VS.Table = "<30mm|^220mm|>35mm;|" & gstrEmpresa_Nome & "|" & VB6.Format(Today, "dd/mm/yyyy")
			.VS.Font = VB6.FontChangeBold(.VS.Font, False)
			.VS.Table = "<30mm|^220mm|>35mm;|" & "ALGUMA COISA AQUI" & "|" & VB6.Format(TimeOfDay, "HH:mm")
			.VS.Table = "<30mm|^220mm|>35mm;|Fone: " & "OUTRA COISA AQUI" & "|" & "Pag.:" & VB6.Format(.VS.PageCount, "000")
			.VS.Font = VB6.FontChangeBold(.VS.Font, True)
			.VS.Font = VB6.FontChangeSize(.VS.Font, 9)
			
			'TituCab
			.VS.Table = "<30mm|^220mm;|" & "MAIS UMA COISA AQUI"
			.VS.Font = VB6.FontChangeBold(.VS.Font, False)
			.VS.Font = VB6.FontChangeSize(.VS.Font, 8)
			.VS.Table = "<30mm|^220mm;|"
			
			Call LineFeed(.VS, 1)
			
			.VS.TableBorder = VSVIEW6.TableBorderSettings.tbAll
			lstrTable = ""
			lstrTable = lstrTable & "Nome" & Chr(13) & "Endereço|"
			lstrTable = lstrTable & "Rota" & Chr(13) & "Identificação" & Chr(13) & "Ap.Saúde|"
			lstrTable = lstrTable & "C.P.F./C.N.P.J." & Chr(13) & "I.E./R.G.|"
			lstrTable = lstrTable & "C.P.F./C.N.P.J." & Chr(13) & "I.E./R.G.|"
			lstrTable = lstrTable & "Medidor" & Chr(13) & "Constante" & Chr(13) & "Marca|"
			lstrTable = lstrTable & "Fase" & Chr(13) & "Tensão" & Chr(13) & "Ligação|"
			lstrTable = lstrTable & "Situação" & Chr(13) & "Região" & Chr(13) & "Tipo Lig.|"
			lstrTable = lstrTable & "Classe"
			.VS.Table = istrTamCab & lstrTable
		End With
	End Sub
	
	Private Sub cmdOK_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdOK.Click
		Dim lstrAux As String
		Dim lstrSql As String
		Dim lblnAux As Boolean
		
		Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
		istrTamCab = "<75mm|^25mm|^35mm|^35mm|^35mm|^15mm|^30mm|^35mm;"
		istrTamCol = "<75mm|^25mm|^35mm|^35mm|>35mm|^15mm|^30mm|<35mm;"
		istrCabecA = "Listagem de CPF e CNPJ inválidos / em brancos "
		istrCabecB = "CPF/CNPJ"
		With ifrmAuxiliar
			Call .VS.KillDoc()
			.quem_chama = Me
			.VS.Font = VB6.FontChangeName(.VS.Font, "Tahoma")
			.VS.Font = VB6.FontChangeSize(.VS.Font, 8)
			.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
			.VS.PageBorder = VSVIEW6.TableBorderSettings.tbNone
			.VS.Orientation = VSVIEW6.OrientationSettings.orLandscape
			.VS.PhysicalPage = True
			.VS.PaperSize = VSVIEW6.PaperSizeSettings.pprA4
			.VS.MarginTop = "7mm"
			.VS.MarginRight = "7mm"
			.VS.MarginLeft = "7mm"
			.VS.MarginBottom = "5mm"
			.VS.TextColor = System.Drawing.Color.Black
			.VS.BrushStyle = VSVIEW6.BrushStyleSettings.bsSolid
			.VS.Font = VB6.FontChangeBold(.VS.Font, False)
			lstrSql = ""
			If Me.OpbC.Checked = True Then
				lstrSql = lstrSql & "SELECT `consum`.`consreg`, "
				lstrSql = lstrSql & "       `consum`.`nome`, "
				lstrSql = lstrSql & "       `consum`.`cgc` AS `cpf_cnpj`, "
				lstrSql = lstrSql & "       `consum`.`insc`, "
				lstrSql = lstrSql & "       `consum`.`rg`, "
				lstrSql = lstrSql & "       `consum`.`end`, "
				lstrSql = lstrSql & "       `consum`.`numero`, "
				lstrSql = lstrSql & "       `consum`.`complement`, "
				lstrSql = lstrSql & "       `consum`.`quadra`, "
				lstrSql = lstrSql & "       `consum`.`lote`, "
				lstrSql = lstrSql & "       `consum`.`bairro` "
				lstrSql = lstrSql & "  FROM `consum` "
				lstrSql = lstrSql & " ORDER BY `consum`.`nome` ASC "
			ElseIf Me.opbUc.Checked = True Then 
				lstrSql = lstrSql & "SELECT `unidb`.`zona`,"
				lstrSql = lstrSql & "       `unidb`.`livro`,"
				lstrSql = lstrSql & "       `unidb`.`conta`, "
				lstrSql = lstrSql & "       `unidb`.`situacao`, "
				lstrSql = lstrSql & "       `unidb`.`nome`, "
				lstrSql = lstrSql & "       `unidb`.`cpf_cnpj`, "
				lstrSql = lstrSql & "       `unidb`.`insc`, "
				lstrSql = lstrSql & "       `unidb`.`rg`, "
				lstrSql = lstrSql & "       `unidb`.`end`, "
				lstrSql = lstrSql & "       `unidb`.`numero`, "
				lstrSql = lstrSql & "       `unidb`.`complement`, "
				lstrSql = lstrSql & "       `unidb`.`quadra`, "
				lstrSql = lstrSql & "       `unidb`.`lote`, "
				lstrSql = lstrSql & "       `unidb`.`bairro`, "
				lstrSql = lstrSql & "       `unidb`.`rota`, "
				lstrSql = lstrSql & "       `unidb`.`clas`, "
				lstrSql = lstrSql & "       `unidb`.`ap_saude`, "
				lstrSql = lstrSql & "       `unidb`.`regiao`, "
				lstrSql = lstrSql & "       `unidb`.`num`, "
				lstrSql = lstrSql & "       `unidb`.`const`, "
				lstrSql = lstrSql & "       `unidb`.`marca`, "
				lstrSql = lstrSql & "       `unidb`.`fase`, "
				lstrSql = lstrSql & "       `unidb`.`tensao`, "
				lstrSql = lstrSql & "       `unidb`.`faselig`, "
				lstrSql = lstrSql & "       `unidb`.`tp_ligacao` "
				lstrSql = lstrSql & "  FROM `unidb` "
				lstrSql = lstrSql & " WHERE LEFT(`unidb`.`rota`, 4) BETWEEN '" & VB6.GetItemString(Me.cmbRotaIni, Me.cmbRotaIni.SelectedIndex) & "' AND '" & VB6.GetItemString(Me.cmbRotaFim, Me.cmbRotaFim.SelectedIndex) & "' "
				lstrSql = lstrSql & " ORDER BY `unidb`.`rota` ASC, `unidb`.`nome` ASC "
			End If
			Call .VS.StartDoc()
			lblnAux = ImprimeRelatorio(lstrSql)
			Call .VS.EndDoc()
			If lblnAux Then
				Call .Show()
			Else
				Call MsgBox("Não foi encontrado nenhum dado para imprimir, favor verifique as opções!", MsgBoxStyle.Information, gstrTituloMensagem)
				Call .VS.KillDoc()
			End If
		End With
		Me.Cursor = System.Windows.Forms.Cursors.Default
	End Sub
	
	Private Function ImprimeRelatorio(ByVal astrSql As String) As Boolean
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim llngConsId As Integer
		Dim lstrSituacao As String
		Dim lstrNome As String
		Dim lstrCpfCnpj As String
		Dim lstrIE As String
		Dim lstrRg As String
		Dim lstrEndereco As String
		Dim lstrNumero As String
		Dim lstrComplemento As String
		Dim lstrQuadra As String
		Dim lstrLote As String
		Dim lstrBairro As String
		Dim lstrRota As String
		Dim lstrClasse As String
		Dim lstrNmClasse As String
		Dim lstrApSaude As String
		Dim lstrRegiao As String
		Dim lstrMedidor As String
		Dim ldblConstante As Double
		Dim lstrMarca As String
		Dim lstrFase As String
		Dim lstrTensao As String
		Dim lstrFaseLigacao As String
		Dim lstrTipoLigacao As String
		
		Dim lstrAuxA As String
		Dim lstrAuxB As String
		Dim lstrTab As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		
		Call Conectar(astrSql, lrstAux)
		With lrstAux
			If .State > 0 Then
				If .RecordCount > 0 Then
					ImprimeRelatorio = True
					'Chama Cabeçalho do Relatório
					'strRotaAux = Left(IIf(IsNull(rsUnidade.Fields("rota").Value), "0000", rsUnidade.Fields("rota").Value), 4)
					Call CabecaRel("2016")
					While Not .EOF
						If Me.opbUc.Checked = True Then
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							lstrZona = VB6.Format(Trim(IIf(IsDbNull(.Fields("zona").value), "0", .Fields("zona").value)), "000")
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							lstrLivro = VB6.Format(Trim(IIf(IsDbNull(.Fields("livro").value), "0", .Fields("livro").value)), "00")
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							lstrConta = VB6.Format(Trim(IIf(IsDbNull(.Fields("conta").value), "0", .Fields("conta").value)), "000000")
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							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"'
							lstrRota = VB6.Format(Trim(IIf(IsDbNull(.Fields("rota").value), "0", .Fields("rota").value)), "00000000")
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							lstrClasse = Trim(IIf(IsDbNull(.Fields("clas").value), "", .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"'
							lstrApSaude = UCase(Trim(IIf(IsDbNull(.Fields("ap_saude").value), "N", .Fields("ap_saude").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 = UCase(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"'
							lstrMedidor = Trim(IIf(IsDbNull(.Fields("num").value), "0", .Fields("num").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"'
							ldblConstante = CDbl(IIf(IsDbNull(.Fields("const").value), 0, .Fields("const").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"'
							lstrMarca = UCase(Trim(IIf(IsDbNull(.Fields("marca").value), "", .Fields("marca").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 = UCase(Trim(IIf(IsDbNull(.Fields("fase").value), "M", .Fields("fase").value)))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							lstrTensao = Trim(IIf(IsDbNull(.Fields("tensao").value), "", .Fields("tensao").value))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							lstrFaseLigacao = UCase(Trim(IIf(IsDbNull(.Fields("faselig").value), "", .Fields("faselig").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"'
							lstrTipoLigacao = UCase(Trim(IIf(IsDbNull(.Fields("tp_ligacao").value), "", .Fields("tp_ligacao").value)))
							'UPGRADE_WARNING: Couldn't resolve default property of object Switch(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							lstrApSaude = VB.Switch(lstrApSaude = "N", "Não Possue", lstrApSaude = "S", "Possue")
							'UPGRADE_WARNING: Couldn't resolve default property of object Switch(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							lstrSituacao = VB.Switch(lstrSituacao = "D", "DESLIGADO", lstrSituacao = "C", "CORTADO", lstrSituacao = "I", "INATIVADO", lstrSituacao = "N", "NÃO LIGADO", lstrSituacao = "L", "LIGADO")
							'UPGRADE_WARNING: Couldn't resolve default property of object Switch(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							lstrRegiao = VB.Switch(lstrRegiao = "U", "Urbana", lstrRegiao = "R", "Rural")
							'UPGRADE_WARNING: Couldn't resolve default property of object Switch(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							lstrTipoLigacao = VB.Switch(lstrTipoLigacao = "A", "Aérea", lstrTipoLigacao = "S", "Subterrânea")
							Select Case VB.Left(lstrClasse, 1)
								Case Is < CStr(4)
									lstrNmClasse = "Industrial"
								Case Is = CStr(4)
									lstrNmClasse = "Comercial"
								Case Is = CStr(5)
									lstrNmClasse = "Rural"
								Case Is = CStr(6)
									If CDbl(VB.Left(lstrClasse, 2)) = 61 Then
										lstrNmClasse = "Poder Público Municipal"
									ElseIf CDbl(VB.Left(lstrClasse, 2)) = 62 Then 
										lstrNmClasse = "Poder Público Estadual"
									ElseIf CDbl(VB.Left(lstrClasse, 2)) = 63 Then 
										lstrNmClasse = "Poder Público Federal"
									ElseIf CDbl(VB.Left(lstrClasse, 2)) = 64 Then 
										lstrNmClasse = "Iluminação Pública"
									End If
								Case Is = CStr(7)
									lstrNmClasse = "Serviço Público"
								Case Is = CStr(8)
									lstrNmClasse = "Consumo Próprio"
								Case Is = CStr(9)
									lstrNmClasse = "Residencial"
							End Select
						Else
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							llngConsId = CInt(IIf(IsDbNull(.Fields("consreg").value), 0, .Fields("consreg").value))
						End If
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrNome = UCase(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"'
						lstrCpfCnpj = Trim(IIf(IsDbNull(.Fields("cpf_cnpj").value), "", .Fields("cpf_cnpj").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrIE = Trim(IIf(IsDbNull(.Fields("insc").value), "", .Fields("insc").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrRg = Trim(IIf(IsDbNull(.Fields("rg").value), "", .Fields("rg").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrEndereco = UCase(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"'
						lstrNumero = UCase(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"'
						lstrComplemento = UCase(Trim(IIf(IsDbNull(.Fields("complement").value), "", .Fields("complement").value)))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrQuadra = UCase(Trim(IIf(IsDbNull(.Fields("quadra").value), "", .Fields("quadra").value)))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrLote = UCase(Trim(IIf(IsDbNull(.Fields("lote").value), "", .Fields("lote").value)))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrBairro = UCase(Trim(IIf(IsDbNull(.Fields("bairro").value), "", .Fields("bairro").value)))
						'Personaliza Logradouro
						lstrAuxA = lstrEndereco
						If Len(lstrNumero) > 0 Then
							lstrAuxA = lstrAuxA & ", " & lstrNumero
						End If
						If Len(lstrQuadra) > 0 Then
							lstrAuxA = lstrAuxA & " QD: " & lstrQuadra
						End If
						If Len(lstrLote) > 0 Then
							lstrAuxA = lstrAuxA & " LT: " & lstrLote
						End If
						If Len(lstrComplemento) > 0 Then
							lstrAuxA = lstrAuxA & " - " & lstrComplemento
						End If
						
						lstrAuxB = Trim(Mid(lstrAuxA, 46))
						lstrAuxA = Trim(Mid(lstrAuxA, 1, 45))
						If Len(lstrBairro) > 0 Then
							If Len(lstrAuxB) > 0 Then
								lstrAuxB = lstrAuxB & " - "
							End If
							lstrAuxB = lstrAuxB & lstrBairro
						Else
							If Len(lstrAuxB) = 0 Then
								lstrAuxB = lstrAuxB & " "
							End If
						End If
						If Valida_CPF_CGC(lstrCpfCnpj) = False And ((Len(Trim(lstrCpfCnpj)) > 0 And Me.chkComCpf.CheckState = 1) Or Me.chkComCpf.CheckState = 0) Then
							lstrTab = ""
							lstrTab = lstrTab & lstrNome & Chr(13) & lstrAuxA & Chr(13) & lstrAuxB & "|"
							If Me.opbUc.Checked = True Then
								lstrTab = lstrTab & lstrRota & Chr(13) & (lstrZona & "." & lstrLivro & "." & lstrConta) & Chr(13) & lstrApSaude & "|"
							Else
								lstrTab = lstrTab & llngConsId & Chr(13) & "" & Chr(13) & "" & "|"
							End If
							lstrTab = lstrTab & lstrCpfCnpj & Chr(13) & IIf(Len(lstrIE) = 0, lstrRg, lstrIE) & Chr(13) & " " & "|"
							lstrTab = lstrTab & " " & Chr(13) & " " & Chr(13) & " " & "|"
							If Me.opbUc.Checked = True Then
								lstrTab = lstrTab & lstrMedidor & Chr(13) & VB6.Format(ldblConstante, "#,#####0.00000") & Chr(13) & lstrMarca & "|"
								lstrTab = lstrTab & lstrFase & Chr(13) & lstrTensao & Chr(13) & lstrFaseLigacao & "|"
								lstrTab = lstrTab & lstrSituacao & Chr(13) & lstrRegiao & Chr(13) & lstrTipoLigacao & "|"
								lstrTab = lstrTab & lstrNmClasse & Chr(13) & " " & Chr(13) & " " & "|"
							Else
								lstrTab = lstrTab & "" & Chr(13) & "" & Chr(13) & "" & "|"
								lstrTab = lstrTab & "" & Chr(13) & "" & Chr(13) & "" & "|"
								lstrTab = lstrTab & "" & Chr(13) & "" & Chr(13) & "" & "|"
								lstrTab = lstrTab & "" & Chr(13) & " " & Chr(13) & " " & "|"
							End If
							With ifrmAuxiliar
								.VS.Font = VB6.FontChangeSize(.VS.Font, 7)
								.VS.Table = istrTamCol & lstrTab
								.VS.Font = VB6.FontChangeSize(.VS.Font, 8)
								If .VS.CurrentLine > 372 Then
									.VS.Font = VB6.FontChangeSize(.VS.Font, 8)
									.VS.NewPage()
									.VS.CurrentLine = 1
									Call CabecaRel("2016")
								End If
							End With
						End If
						Call .MoveNext()
					End While
				End If
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
	End Function
	
	Private Sub cmdSair_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSair.Click
		Call Me.Close()
	End Sub
	
	Private Sub BuscaTabelas()
		Dim lstrTabela As String
		Dim lstrColuna As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		
		Me.mfgTabelas.set_ColWidth(0, 2000)
		Me.mfgTabelas.set_ColWidth(1, 950)
		Me.mfgTabelas.set_ColWidth(2, 300)
		Call Me.mfgTabelas.Clear()
		Me.mfgTabelas.Rows = 0
		lstrSql = ""
		lstrSql = lstrSql & "SELECT DISTINCT table_name, column_name "
		lstrSql = lstrSql & "  FROM information_schema.Columns "
		lstrSql = lstrSql & " WHERE information_schema.columns.TABLE_SCHEMA = 'fatwin' "
		lstrSql = lstrSql & "   AND information_schema.columns.COLUMN_NAME IN('cons_id','cons_id_new','cons_id_old','id_consumidor','consid') "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State > 0 Then
				If .RecordCount > 0 Then
					Me.mfgTabelas.Redraw = False
					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"'
						lstrTabela = IIf(IsDbNull(.Fields("table_name").value), "", .Fields("table_name").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"'
						lstrColuna = IIf(IsDbNull(.Fields("column_name").value), "", .Fields("column_name").value)
						If VB.Left(lstrTabela, 2) <> "vw" Then
							With Me.mfgTabelas
								.Rows = .Rows + 1
								.set_TextMatrix(.Rows - 1, 0, lstrTabela)
								.set_TextMatrix(.Rows - 1, 1, lstrColuna)
							End With
						End If
						Call .MoveNext()
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
					End While
					Me.mfgTabelas.Redraw = True
				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
		System.Windows.Forms.Application.DoEvents()
	End Sub
	
	Private Sub cmdTransferir_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdTransferir.Click
		Dim lstrSql As String
		Dim lstrAux As String
		Dim llngRow As Integer
		Dim lstrTab As String
		Dim lstrCol As String
		
		If Len(Trim(Me.txtConsumOld.Text)) = 0 Then
			Call MsgBox("Favor informar o consumidor de Origem para transferencia", MsgBoxStyle.Information, gstrTituloMensagem)
			Call Me.txtConsumOld.Focus()
		ElseIf Len(Trim(txtConsumNew.Text)) = 0 Then 
			Call MsgBox("Favor informar o consumidor de Destinho para receber a transferencia", MsgBoxStyle.Information, gstrTituloMensagem)
			Call Me.txtConsumNew.Focus()
		Else
			Me.lblInfo.Text = " Aguarde buscando as tabelas..."
			Call Me.lblInfo.Refresh()
			Call BuscaQtdeUc(CInt(Me.txtConsumOld.Text), (Me.lblNmConsumOld), (Me.lblQtdeUCOld))
			Call BuscaQtdeUc(CInt(Me.txtConsumNew.Text), (Me.lblNmConsumNew), (Me.lblQtdeUCNew))
			If MsgBox("Tem certeza que deseja juntar " & vbCrLf & vbCrLf & Me.lblNmConsumOld.Text & vbCrLf & vbCrLf & " com o " & vbCrLf & vbCrLf & Me.lblNmConsumNew.Text & "?", MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2, gstrTituloMensagem) = MsgBoxResult.Yes Then
				With Me.mfgTabelas
					Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .Rows)
					For llngRow = 0 To .Rows - 1
						lstrTab = .get_TextMatrix(llngRow, 0)
						lstrCol = .get_TextMatrix(llngRow, 1)
						lstrSql = "UPDATE " & lstrTab & " SET " & lstrCol & " = " & CInt(Me.txtConsumNew.Text) & " WHERE " & lstrCol & " = " & CInt(Me.txtConsumOld.Text)
						Call ExecutaSQL(lstrSql)
						.set_TextMatrix(llngRow, 2, "X")
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
					Next llngRow
				End With
				Call ExecutaSQL("DELETE FROM consum WHERE consreg = " & Me.txtConsumOld.Text)
				Call MsgBox("Transferencia completada", MsgBoxStyle.Information, gstrTituloMensagem)
			Else
				Call MsgBox("Cancelado pelo usuário!", MsgBoxStyle.Information, gstrTituloMensagem)
			End If
			Call Me.txtConsumOld.Focus()
		End If
	End Sub
	
	Private Sub ExecutaSQL(ByRef astrAux As String)
		On Error GoTo ErroExecucao
		
		Call Executar(astrAux)
		Exit Sub
		
ErroExecucao: 
		MsgBox(Err.Number & " - " & Err.Description)
	End Sub
	
	Private Sub frmAcertaConsumidor_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Dim llngAux As Integer
		Call CenterForm(Me)
		Call BuscaTabelas()
		Call CarregaTabelaComboBox((Me.cmbRotaIni), "unidb", "DISTINCT LEFT(rota,4) rota_quatro",  , "LEFT(rota,4) ASC ")
		For llngAux = 0 To Me.cmbRotaIni.Items.Count - 1
			Call Me.cmbRotaFim.Items.Add(VB6.GetItemString(Me.cmbRotaIni, llngAux))
			VB6.SetItemData(Me.cmbRotaFim, Me.cmbRotaFim.Items.Count - 1, VB6.GetItemData(Me.cmbRotaIni, llngAux))
		Next llngAux
		ifrmAuxiliar = New FrmRelatorio
		
	End Sub
	
	Private Sub frmAcertaConsumidor_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		If KeyAscii = System.Windows.Forms.Keys.Escape Then
			Call cmdSair_Click(cmdSair, New System.EventArgs())
		ElseIf KeyAscii = System.Windows.Forms.Keys.Return Then 
			Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
	
	Private Sub frmAcertaConsumidor_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
		'UPGRADE_NOTE: Object ifrmAuxiliar 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"'
		ifrmAuxiliar = Nothing
	End Sub
	
	Private Sub txtConsumNew_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtConsumNew.Enter
		With txtConsumNew
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtConsumOld_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtConsumOld.Enter
		With txtConsumOld
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub cmdCancelImp_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCancelImp.Click
		Me.txtConsumOld.Enabled = True
		Me.txtConsumNew.Enabled = True
		Me.cmdTransferir.Enabled = True
		Me.cmdCpfCNPJ.Enabled = True
		Me.cmdSair.Enabled = True
		Me.fmeFaixa.Left = VB6.TwipsToPixelsX(4830)
		Me.fmeFaixa.Visible = False
		Me.fmeFaixa.Enabled = False
		Call cmdCpfCNPJ.Focus()
	End Sub
	
	Private Sub cmdCpfCNPJ_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCpfCNPJ.Click
		Me.fmeFaixa.Left = VB6.TwipsToPixelsX(120)
		Me.fmeFaixa.Visible = True
		Me.fmeFaixa.Enabled = True
		Me.txtConsumOld.Enabled = False
		Me.txtConsumNew.Enabled = False
		Me.cmdTransferir.Enabled = False
		Me.cmdCpfCNPJ.Enabled = False
		Me.cmdSair.Enabled = False
	End Sub
	
	Private Sub BuscaQtdeUc(ByVal alngConsId As Integer, ByRef alblNome As System.Windows.Forms.Label, ByRef alblQtde As System.Windows.Forms.Label)
		Dim llngQtd As Integer
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		alblNome.Text = ""
		alblQtde.Text = CStr(0)
		If Len(alngConsId) > 0 Then
			lstrSql = ""
			lstrSql = lstrSql & "SELECT `consum`.`nome` "
			lstrSql = lstrSql & "  FROM `consum` "
			lstrSql = lstrSql & " WHERE `consum`.`consreg` = " & alngConsId
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State > 0 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"'
						alblNome.Text = IIf(IsDbNull(.Fields("nome").value), "", .Fields("nome").value)
					End If
					Call .Close()
				End If
			End With
			lstrSql = ""
			lstrSql = lstrSql & "SELECT COUNT(*) AS `qtde` "
			lstrSql = lstrSql & "  FROM `unidb` "
			lstrSql = lstrSql & " WHERE `unidb`.`cons_id` = " & alngConsId
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State > 0 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"'
						alblQtde.Text = CStr(CInt(IIf(IsDbNull(.Fields("qtde").value), 0, .Fields("qtde").value)))
					End If
					Call .Close()
				End If
			End With
			lstrSql = ""
			lstrSql = lstrSql & "SELECT COUNT(*) AS `qtde` "
			lstrSql = lstrSql & "  FROM `unida` "
			lstrSql = lstrSql & " WHERE `unida`.`cons_id` = " & alngConsId
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State > 0 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"'
						alblQtde.Text = CStr(CDbl(alblQtde.Text) + CInt(IIf(IsDbNull(.Fields("qtde").value), 0, .Fields("qtde").value)))
					End If
					Call .Close()
				End If
			End With
		End If
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
	End Sub
End Class