Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmArrec
	Inherits System.Windows.Forms.Form
	Private irstRegUnid As ADODB.Recordset
	Private irstRegCons As ADODB.Recordset
	Private ilngLimite As Integer
	Private ilngQtdeReg As Integer
	Private istrModCoEnd As String
	Private istrEndCodC As String
	Private istrEndCodUC As String
	Private istrEndCodEn As String
	Private istrGrupo As String
	Private ilngUnidId As Integer
	Private ilngConsId As Integer
	Private ifrmExtrato As FrmRelatorio
	Private istrCabec As String
	Private istrTamCl As String
	Private istrSubCb As String
	Private istrIsRural As String
	Private istrLocaliza As String
	Private ifrmLocalizaUnidade As frmLocalizaUnidade
	Private ifrmCargaInstalada As frmCargaInstalada
	Private ifrmPreencherEnde As FrmPreencherEnde
	Private ifrmImpFaturas As frmImpFaturas
	Private ifrmCadNis As frmCadNis
	Private ifrmReclam As frmReclam
	
	Public Sub SetaGrupo(ByRef astrGrupo As String)
		istrGrupo = astrGrupo
		Me.Text = Me.Text & astrGrupo
	End Sub
	
	Private Sub cmdBuscasFaturasAbertasConsumidor_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdBuscasFaturasAbertasConsumidor.Click
		Dim lstrSql As String
		Dim lblnContinua As Boolean
		Dim ldteBase As Date
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim lstrMesAno As String
		Dim ldteVencto As Date
		Dim ldtePPrazo As Date
		Dim ldblValor As Double
		Dim ldblVlrAb As Double
		Dim ldblNumNf As Double
		Dim llngConsId As Integer
		Dim llngDiasA As Integer
		Dim llngFatPrazAbert As Integer
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		ldteBase = BuscaDataBD
		lblnContinua = True
		Me.txtQtdeAbertoConsumidor.Text = "0"
		Me.txtValorAbertoConsumidor.Text = "0,00"
		If gblnUsuario_Faturas_aberto_cortado And Not gblnUsuario_Faturas_todos_aberto Then
			lblnContinua = (VB.Left(Trim(Me.txtSituacao.Text), 1) = "C")
		End If
		If (gblnUsuario_Faturas_todos_aberto Or gblnUsuario_Faturas_aberto_cortado) And lblnContinua Then
			ldblVlrAb = 0
			'----- Enche Grid: Faturas em Aberto -------------------------------------------------------------------
			With Me.mfgAbertasConsumidor
				.Rows = 1
				.Redraw = False
			End With
			lstrSql = ""
			lstrSql = lstrSql & "  SELECT `nf`.`mesano_ref`, "
			lstrSql = lstrSql & "         `nf`.`datavenc`, "
			lstrSql = lstrSql & "         `nf`.`dataprazo`, "
			lstrSql = lstrSql & "         `nf`.`valortot`, "
			lstrSql = lstrSql & "         `nf`.`numnf`, "
			lstrSql = lstrSql & "         `nf`.`cons_id`, "
			lstrSql = lstrSql & "         `nf`.`unid_id`, "
			lstrSql = lstrSql & "         `nf`.`flgst`, "
			lstrSql = lstrSql & "         `nf`.`grupo`, "
			lstrSql = lstrSql & "         `nf`.`codclas`, "
			lstrSql = lstrSql & "         `nf`.`zona`, "
			lstrSql = lstrSql & "         `nf`.`livro`, "
			lstrSql = lstrSql & "         `nf`.`conta`, "
			lstrSql = lstrSql & "         `nf`.`datapag`, "
			lstrSql = lstrSql & "         `nf`.`datast`, "
			lstrSql = lstrSql & "         `nf`.`mesano`, "
			lstrSql = lstrSql & "         `nf`.`rota`, "
			lstrSql = lstrSql & "         `nf`.`ta` "
			lstrSql = lstrSql & "    FROM `nf` "
			lstrSql = lstrSql & "   WHERE `nf`.`cons_id`    = " & ilngConsId
			lstrSql = lstrSql & "     AND `nf`.`flgst`      NOT IN('P','C') "
			lstrSql = lstrSql & "     AND `nf`.`grupo`      = '" & UCase(istrGrupo) & "' "
			lstrSql = lstrSql & "     AND `nf`.`mesano_ref` <= " & VB6.Format(ldteBase, "yyyymm") & " "
			lstrSql = lstrSql & "ORDER BY `mesano_ref` DESC "
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State > 0 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"'
							lstrZona = Trim(IIf(IsDbNull(.Fields("zona").value), "000", .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), "00", .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), "000000", .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"'
							lstrMesAno = Trim(IIf(IsDbNull(.Fields("mesano_ref").value), "", .Fields("mesano_ref").value))
							lstrMesAno = VB.Right(lstrMesAno, 2) & "/" & VB.Left(lstrMesAno, 4)
							'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"'
							ldteVencto = CDate(IIf(IsDbNull(.Fields("datavenc").value), "1900-01-01", .Fields("datavenc").value))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							ldtePPrazo = CDate(IIf(IsDbNull(.Fields("dataprazo").value), "1900-01-01", .Fields("dataprazo").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"'
							ldblValor = CDbl(IIf(IsDbNull(.Fields("valortot").value), 0, .Fields("valortot").value))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							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"'
							llngConsId = CInt(IIf(IsDbNull(.Fields("cons_id").value), 0, .Fields("cons_id").value))
							'UPGRADE_WARNING: DateDiff behavior may be different. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6B38EC3F-686D-4B2E-B5A5-9E8E7A762E32"'
							llngDiasA = CInt(DateDiff(Microsoft.VisualBasic.DateInterval.Day, ldteVencto, ldteBase))
							If ldtePPrazo <> CDate("01/01/1900") Then
								llngFatPrazAbert = llngFatPrazAbert + 1
							End If
							If llngDiasA < 1 Then llngDiasA = 0
							With Me.mfgAbertasConsumidor
								.Rows = .Rows + 1
								'UPGRADE_ISSUE: VBControlExtender method mfgAbertasConsumidor.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
								.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillRepeat
								If ldtePPrazo > ldteBase Then
									.Row = .Rows - 1
									.Col = 0
									.ColSel = .Cols - 1
									.CellForeColor = System.Drawing.ColorTranslator.FromOle(&HFF0000) 'Azul
								ElseIf ldteVencto < ldteBase Then 
									.Row = .Rows - 1
									.Col = 0
									.ColSel = .Cols - 1
									.CellForeColor = System.Drawing.ColorTranslator.FromOle(&HFF) 'Vermelho
								Else
									.Row = .Rows - 1
									.Col = 0
									.ColSel = .Cols - 1
									.CellForeColor = System.Drawing.ColorTranslator.FromOle(&H80000008) 'Normal
								End If
								'UPGRADE_ISSUE: VBControlExtender method mfgAbertasConsumidor.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
								.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillSingle
								.set_TextMatrix(.Rows - 1, 0, lstrMesAno)
								.set_TextMatrix(.Rows - 1, 1, VB6.Format(ldteVencto, "dd/mm/yyyy"))
								.set_TextMatrix(.Rows - 1, 2, VB6.Format(ldblValor, "Standard"))
								.set_TextMatrix(.Rows - 1, 3, ldblNumNf)
								.set_TextMatrix(.Rows - 1, 4, llngDiasA)
								.set_TextMatrix(.Rows - 1, 5, BuscaSituacaoReaviso(lstrMesAno, ldblNumNf))
								.set_TextMatrix(.Rows - 1, 6, IIf(ldtePPrazo <> CDate("01/01/1900"), VB6.Format(ldtePPrazo, "dd/mm/yyyy"), "__/__/____"))
								.set_TextMatrix(.Rows - 1, 7, lstrZona & "." & lstrLivro & "." & lstrConta)
								ldblVlrAb = ldblVlrAb + ldblValor
							End With
							Call .MoveNext()
						End While
					End If
					Call .Close()
				End If
			End With
			Me.txtValorAberto.Text = VB6.Format(ldblVlrAb, "Standard")
			With Me.mfgAbertasConsumidor
				.HighLight = MSFlexGridLib.HighLightSettings.flexHighlightNever
				.Redraw = True
				Me.txtQtdeAbertoConsumidor.Text = CStr(.Rows - 1)
			End With
		Else
			Me.mfgAbertasConsumidor.Rows = 1
		End If
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
	End Sub
	
	Private Sub cmdCancelaMotivo_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCancelaMotivo.Click
		Me.fmeMotivo.Visible = False
		Me.fmeMotivo.Enabled = False
		Me.SSTab2.Enabled = True
		Me.fmeFaturas.Enabled = True
	End Sub
	
	Private Sub cmdGravaMotivo_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdGravaMotivo.Click
		Dim ldteAux As Date
		Dim lstrSql As String
		ldteAux = BuscaDataBD
		If Me.optVia2.Checked Then
			If Len(Trim(Me.txtMotivo.Text)) > 0 Then
				lstrSql = ""
				lstrSql = lstrSql & "UPDATE `nf` SET "
				lstrSql = lstrSql & "       `motivosegvia`  = '" & Me.txtMotivo.Text & "', "
				lstrSql = lstrSql & "       `usuariosegvia` = '" & gstrUsuario_Nome & "', "
				lstrSql = lstrSql & "       `datasegvia`    = '" & VB6.Format(ldteAux, "yyyy-MM-dd") & "' "
				lstrSql = lstrSql & " WHERE `numnf`  = " & CDbl(Me.lblMotNumNf.Text)
				lstrSql = lstrSql & "   AND `mesano` = '" & Me.lblMotMesAno.Text & "' "
				Call Executar(lstrSql)
				Me.fmeMotivo.Visible = False
				Me.fmeMotivo.Enabled = False
				Me.SSTab2.Enabled = True
				Me.fmeFaturas.Enabled = True
				Call ImpSegVia(CDbl(Me.lblMotNumNf.Text), Me.lblMotMesAno.Text)
			End If
		ElseIf Me.optEstornar.Checked Then 
			If Len(Trim(Me.txtMotivo.Text)) > 0 Then
				lstrSql = ""
				lstrSql = lstrSql & "UPDATE `nf` SET "
				lstrSql = lstrSql & "       `flgst` = ' ', "
				lstrSql = lstrSql & "       `datapag` = '0000-00-00', "
				lstrSql = lstrSql & "       `motivocanc`    = 'ESTORNO " & VB6.Format(ldteAux, "DD/MM/YYYY") & " - " & VB.Left(Me.txtMotivo.Text, 79) & "', "
				lstrSql = lstrSql & "       `usuariosegvia` = '" & gstrUsuario_Nome & "' "
				lstrSql = lstrSql & " WHERE `numnf`  = " & CDbl(Me.lblMotNumNf.Text)
				lstrSql = lstrSql & "   AND `mesano` = '" & Me.lblMotMesAno.Text & "' "
				Call Executar(lstrSql)
				Call AtualizaHistoricoUnidade(ilngUnidId, istrGrupo, "[" & VB6.Format(ldteAux, "DD/MM/YYYY") & "]: FATURA ESTORNADA: " & Me.lblMotNumNf.Text & " - " & Me.lblMotMesAno.Text & " " & VB.Left(Me.txtMotivo.Text, 79))
				Me.fmeMotivo.Visible = False
				Me.fmeMotivo.Enabled = False
				Me.SSTab2.Enabled = True
				Me.fmeFaturas.Enabled = True
				Call cmdFecharImp_Click(cmdFecharImp, New System.EventArgs())
				Call BuscaUnidadeConsumidora(ilngUnidId, 12)
			End If
		End If
		'UPGRADE_WARNING: TextBox property txtMotivo.MaxLength has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
		Me.txtMotivo.Maxlength = 0
	End Sub
	
	Private Sub cmdLimparAgrupamento_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdLimparAgrupamento.Click
		Me.txtAgrupaZona.Text = ""
		Me.txtAgrupaLivro.Text = ""
		Me.txtAgrupaConta.Text = ""
		Me.txtAgrupaRota.Text = ""
		Me.txtAgrupaNome.Text = ""
	End Sub
	
	Private Sub cmdLocZlcAgrupa_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdLocZlcAgrupa.Click
		Call ifrmLocalizaUnidade.Show()
		Call ifrmLocalizaUnidade.SetaLocalizaUnidade("U", Me, UCase(istrGrupo))
		istrLocaliza = "A"
	End Sub
	
	Private Sub frmArrec_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		ilngLimite = 0
		istrLocaliza = "U"
		ifrmLocalizaUnidade = New frmLocalizaUnidade
		ifrmCargaInstalada = New frmCargaInstalada
		ifrmCadNis = New frmCadNis
		ifrmPreencherEnde = New FrmPreencherEnde
		ifrmReclam = New frmReclam
		ifrmImpFaturas = New frmImpFaturas
		If UCase(istrGrupo) = "A" Then
			FrmAtPrincipal.mnuAtendimentoComercial_GrupoA.Enabled = False
		Else
			FrmAtPrincipal.mnuAtendimentoComercial_GrupoB.Enabled = False
		End If
		irstRegUnid = New ADODB.Recordset
		irstRegCons = New ADODB.Recordset
		Me.chkApSaude.Enabled = (UCase(istrGrupo) = "B")
		Call MontaGrids()
		Call CarregaTabelaComboBox((Me.cmbAgrupa), "`agrupa`", " `descricao` ", "`codigo`", "`codigo` ASC")
		Call pegaDatasVencimento()
		'Call BuscaUnidadeConsumidora(ilngUnidId, 12)
		Call desabilitaCampos()
		'Call Me.cmdLocalizar.SetFocus
	End Sub
	
	Private Sub frmArrec_KeyDown(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
		Dim KeyCode As Short = eventArgs.KeyCode
		Dim Shift As Short = eventArgs.KeyData \ &H10000
		If KeyCode = System.Windows.Forms.Keys.F1 Then
			Call cmdAnterior_Click(cmdAnterior, New System.EventArgs())
			Call txtNomeU.Focus()
		ElseIf KeyCode = System.Windows.Forms.Keys.F2 Then 
			Call cmdProximo_Click(cmdProximo, New System.EventArgs())
			Call txtNomeU.Focus()
		ElseIf KeyCode = System.Windows.Forms.Keys.F3 Then 
			Call cmdLocalizar_Click(cmdLocalizar, New System.EventArgs())
		ElseIf KeyCode = System.Windows.Forms.Keys.F4 Then 
			Call cmdSalvar_Click(cmdSalvar, New System.EventArgs())
			Call txtNomeU.Focus()
		ElseIf KeyCode = System.Windows.Forms.Keys.F5 Then 
			Call cmdServicos_Click(cmdServicos, New System.EventArgs())
		ElseIf KeyCode = System.Windows.Forms.Keys.F6 Then 
			Call cmdReclamacao_Click(cmdReclamacao, New System.EventArgs())
		ElseIf KeyCode = System.Windows.Forms.Keys.F7 Then 
			Call cmdHistorico_Click(cmdHistorico, New System.EventArgs())
		ElseIf KeyCode = System.Windows.Forms.Keys.F8 Then 
			Call cmdExtrato_Click(cmdExtrato, New System.EventArgs())
		ElseIf KeyCode = System.Windows.Forms.Keys.F9 Then 
			Call cmdNis_Click(cmdNis, New System.EventArgs())
		ElseIf KeyCode = System.Windows.Forms.Keys.F10 Then 
			Call cmdConvenios_Click(cmdConvenios, New System.EventArgs())
		ElseIf KeyCode = System.Windows.Forms.Keys.F11 Then 
			Call cmdFechar_Click(cmdFechar, New System.EventArgs())
		End If
	End Sub
	
	Private Sub frmArrec_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.Return Then
			Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
		ElseIf KeyAscii = System.Windows.Forms.Keys.Escape Then 
			If Me.fmeFaturas.Visible Then
				Call cmdFecharImp_Click(cmdFecharImp, New System.EventArgs())
			ElseIf Me.fmePedidoDePrazo.Visible Then 
				Call cmdFecharPedidoPrazo_Click(cmdFecharPedidoPrazo, New System.EventArgs())
			ElseIf Me.fmeMotivo.Visible Then 
				Call cmdCancelaMotivo_Click(cmdCancelaMotivo, New System.EventArgs())
			ElseIf MsgBox("Tem certeza de que deseja fechar a tela de atendimento?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, gstrTituloMensagem) = MsgBoxResult.Yes Then 
				Call Me.Close()
			Else
				Call txtNomeU.Focus()
			End If
			KeyAscii = 0
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
	
	'[ Rotina para navegar para traz os registros ]
	Private Sub cmdAnterior_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdAnterior.Click
		Dim llngUnidId As Integer
		If Not irstRegUnid Is Nothing Then
			With irstRegUnid
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If Not .BOF 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"'
							llngUnidId = IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").value)
						End If
						Call .MovePrevious()
						If Not .BOF Then
							Call .Resync(ADODB.AffectEnum.adAffectCurrent, ADODB.ResyncEnum.adResyncAllValues)
							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"'
								llngUnidId = IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").value)
							End If
						End If
					End If
					If Not .BOF Then
						If BuscaUnidadeConsumidora(llngUnidId, 12) = False Then
							ilngLimite = ilngLimite + 1
						End If
					Else
						Call .MoveNext()
					End If
				End If
			End With
		End If
	End Sub
	
	Private Sub cmdAnterior_MouseMove(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.MouseEventArgs) Handles cmdAnterior.MouseMove
		Dim Button As Short = eventArgs.Button \ &H100000
		Dim Shift As Short = System.Windows.Forms.Control.ModifierKeys \ &H10000
		Dim X As Single = VB6.PixelsToTwipsX(eventArgs.X)
		Dim Y As Single = VB6.PixelsToTwipsY(eventArgs.Y)
		labelStatus.Text = " Exibir o registro anterior (F1)"
	End Sub
	
	'[ Rotina para navegar para frente os registros ]
	Private Sub cmdProximo_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdProximo.Click
		Dim llngUnidId As Integer
		If Not irstRegUnid Is Nothing Then
			With irstRegUnid
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If Not .EOF Then
						If .RecordCount > 0 Then
							If Not .BOF 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"'
								llngUnidId = IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").value)
							End If
						End If
						Call .MoveNext()
						If Not .EOF Then
							Call .Resync(ADODB.AffectEnum.adAffectCurrent, ADODB.ResyncEnum.adResyncAllValues)
							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"'
								llngUnidId = IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").value)
							End If
						End If
					End If
					If BuscaUnidadeConsumidora(llngUnidId, 12) = False Then
						ilngLimite = ilngLimite - 1
					End If
				End If
			End With
		End If
	End Sub
	
	Private Sub cmdProximo_MouseMove(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.MouseEventArgs) Handles cmdProximo.MouseMove
		Dim Button As Short = eventArgs.Button \ &H100000
		Dim Shift As Short = System.Windows.Forms.Control.ModifierKeys \ &H10000
		Dim X As Single = VB6.PixelsToTwipsX(eventArgs.X)
		Dim Y As Single = VB6.PixelsToTwipsY(eventArgs.Y)
		labelStatus.Text = " Exibir o próximo registro (F2)"
	End Sub
	
	'[ Rotina para chamar o frmlocalizaunidade ]
	Private Sub cmdLocalizar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdLocalizar.Click
		Call ifrmLocalizaUnidade.Show()
		Call ifrmLocalizaUnidade.SetaLocalizaUnidade("U", Me, UCase(istrGrupo))
		istrLocaliza = "U"
	End Sub
	
	Private Sub cmdLocalizar_MouseMove(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.MouseEventArgs) Handles cmdLocalizar.MouseMove
		Dim Button As Short = eventArgs.Button \ &H100000
		Dim Shift As Short = System.Windows.Forms.Control.ModifierKeys \ &H10000
		Dim X As Single = VB6.PixelsToTwipsX(eventArgs.X)
		Dim Y As Single = VB6.PixelsToTwipsY(eventArgs.Y)
		labelStatus.Text = " Localizar consumidores e unidades consumidoras (F3)"
	End Sub
	
	'[ Rotina para chamar a rotina de salvar ]
	Private Sub cmdSalvar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSalvar.Click
		If gblnUsuario_Atendimento_comercial_salvar Then
			If Len(Trim(Me.txtIdent.Text)) > 0 Then
				If MsgBox("Tem certeza de que deseja alterar os dados deste consumidor?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Salvar") = MsgBoxResult.Yes Then
					Call GravaDados()
				End If
			End If
		Else
			Call MsgBox("Você não possue permissão para acessar esta opção!", MsgBoxStyle.Information, gstrTituloMensagem)
		End If
	End Sub
	
	Private Sub cmdSalvar_MouseMove(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.MouseEventArgs) Handles cmdSalvar.MouseMove
		Dim Button As Short = eventArgs.Button \ &H100000
		Dim Shift As Short = System.Windows.Forms.Control.ModifierKeys \ &H10000
		Dim X As Single = VB6.PixelsToTwipsX(eventArgs.X)
		Dim Y As Single = VB6.PixelsToTwipsY(eventArgs.Y)
		labelStatus.Text = " Salvar alterações (F4)"
	End Sub
	
	'[ Rotina para chamar a ordem de serviço interna ]
	Private Sub cmdServicos_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdServicos.Click
		If gblnUsuario_Servicos_ordem_servico Then
			If Len(Trim(Me.txtIdent.Text)) > 0 Then
				Call frmSolServ.SetaCodigo(ilngUnidId, Mid(Me.txtIdent.Text, 1, 3), Mid(Me.txtIdent.Text, 5, 2), Mid(Me.txtIdent.Text, 8), UCase(istrGrupo), Me, (Me.crpOs), (Me.crpCarga), (Me.crpCroqui), Me.txtSituacao.Text)
				Call CenterForm(frmSolServ)
				Call frmSolServ.Show()
			End If
		Else
			Call MsgBox("Você não possue permissão para acessar esta opção!", MsgBoxStyle.Information, gstrTituloMensagem)
		End If
	End Sub
	
	Private Sub cmdServicos_MouseMove(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.MouseEventArgs) Handles cmdServicos.MouseMove
		Dim Button As Short = eventArgs.Button \ &H100000
		Dim Shift As Short = System.Windows.Forms.Control.ModifierKeys \ &H10000
		Dim X As Single = VB6.PixelsToTwipsX(eventArgs.X)
		Dim Y As Single = VB6.PixelsToTwipsY(eventArgs.Y)
		labelStatus.Text = " Solicitação de serviços (F5)"
	End Sub
	
	'[ Rotina para chamar a reclamação ]
	Private Sub cmdReclamacao_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdReclamacao.Click
		If gblnUsuario_Servicos_reclamacao Then
			If Len(Trim(Me.txtIdent.Text)) > 0 Then
				Call ifrmReclam.Show()
				ifrmReclam.txtZona.Text = VB.Left(Me.txtIdent.Text, 3)
				ifrmReclam.txtLivro.Text = Mid(Me.txtIdent.Text, 5, 2)
				ifrmReclam.txtConta.Text = VB.Right(Me.txtIdent.Text, 6)
				If istrGrupo = "B" Then
					ifrmReclam.opbGrupoB.Checked = True
				Else
					ifrmReclam.opbGrupoA.Checked = True
				End If
			End If
		Else
			Call MsgBox("Você não possue permissão para acessar esta opção!", MsgBoxStyle.Information, gstrTituloMensagem)
		End If
	End Sub
	
	Private Sub cmdReclamacao_MouseMove(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.MouseEventArgs) Handles cmdReclamacao.MouseMove
		Dim Button As Short = eventArgs.Button \ &H100000
		Dim Shift As Short = System.Windows.Forms.Control.ModifierKeys \ &H10000
		Dim X As Single = VB6.PixelsToTwipsX(eventArgs.X)
		Dim Y As Single = VB6.PixelsToTwipsY(eventArgs.Y)
		labelStatus.Text = " Registrar reclamações (F6)"
	End Sub
	
	Private Sub cmdHistorico_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdHistorico.Click
		If gblnUsuario_Servicos_historico Then
			If Len(Trim(Me.txtIdent.Text)) > 0 Then
				Call frmHistorico.SetaDados(UCase(istrGrupo), ilngConsId, ilngUnidId)
				Call CenterForm(frmHistorico)
				Call frmHistorico.Show()
			End If
		Else
			Call MsgBox("Você não possue permissão para acessar esta opção!", MsgBoxStyle.Information, gstrTituloMensagem)
		End If
	End Sub
	
	Private Sub cmdHistorico_MouseMove(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.MouseEventArgs) Handles cmdHistorico.MouseMove
		Dim Button As Short = eventArgs.Button \ &H100000
		Dim Shift As Short = System.Windows.Forms.Control.ModifierKeys \ &H10000
		Dim X As Single = VB6.PixelsToTwipsX(eventArgs.X)
		Dim Y As Single = VB6.PixelsToTwipsY(eventArgs.Y)
		labelStatus.Text = " Exibir histórico do consumidor (F7)"
	End Sub
	
	Private Sub cmdExtrato_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExtrato.Click
		If gblnUsuario_Servicos_extrato Then
			If Len(Trim(Me.txtIdent.Text)) > 0 Then
				If mfgPagas.Rows < 1 And mfgAbertas.Rows < 1 Then
					Call MsgBox("Este consumidor não possui nenhum consumo!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
				Else
					If MsgBox("Deseja imprimir o extrato completo?", MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2, gstrTituloMensagem) = MsgBoxResult.Yes Then
						Call BuscaUnidadeConsumidora(ilngUnidId, 0)
						Me.cmbMeses.SelectedIndex = Me.cmbMeses.Items.Count - 1
						Call MontaExtrato(1)
					Else
						Call MontaExtrato(0)
					End If
				End If
			End If
		Else
			Call MsgBox("Você não possue permissão para acessar esta opção!", MsgBoxStyle.Information, gstrTituloMensagem)
		End If
	End Sub
	
	Private Sub cmdExtrato_MouseMove(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.MouseEventArgs) Handles cmdExtrato.MouseMove
		Dim Button As Short = eventArgs.Button \ &H100000
		Dim Shift As Short = System.Windows.Forms.Control.ModifierKeys \ &H10000
		Dim X As Single = VB6.PixelsToTwipsX(eventArgs.X)
		Dim Y As Single = VB6.PixelsToTwipsY(eventArgs.Y)
		labelStatus.Text = " Exibir extrato (F8)"
	End Sub
	
	Private Sub cmdNis_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdNis.Click
		If gblnUsuario_Servicos_nis Then
			If Len(Trim(Me.txtIdent.Text)) > 0 Then
				If CDbl(Trim(CStr(Len(Me.txtCpfCnpjU.Text)))) = 0 Then
					Call MsgBox("Você precisa cadastrar o CPF/CNPJ da unidade consumidora para ter acesso ao cadastro de NIS.", MsgBoxStyle.Information, gstrTituloMensagem)
					Me.SSTab1.SelectedIndex = 0
					Call Me.txtCpfCnpjU.Focus()
				Else
					Call ifrmCadNis.Show()
					Call ifrmCadNis.SetaNis(Me.txtCpfCnpjU.Text, Me.txtNomeU.Text, Me.txtRgU.Text, VB.Left(Me.txtIdent.Text, 3), Mid(Me.txtIdent.Text, 5, 2), VB.Right(Me.txtIdent.Text, 6), ilngUnidId, Me)
				End If
			End If
		Else
			Call MsgBox("Você não possue permissão para acessar esta opção!", MsgBoxStyle.Information, gstrTituloMensagem)
		End If
	End Sub
	
	Private Sub cmdNis_MouseMove(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.MouseEventArgs) Handles cmdNis.MouseMove
		Dim Button As Short = eventArgs.Button \ &H100000
		Dim Shift As Short = System.Windows.Forms.Control.ModifierKeys \ &H10000
		Dim X As Single = VB6.PixelsToTwipsX(eventArgs.X)
		Dim Y As Single = VB6.PixelsToTwipsY(eventArgs.Y)
		labelStatus.Text = " Cadastrar/alterar NIS (F9)"
	End Sub
	
	Private Sub cmdConvenios_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdConvenios.Click
		If gblnUsuario_Servicos_convenios Then
			If Len(Trim(Me.txtIdent.Text)) > 0 Then
				Call frmConvenios.SetaCodigo2(ilngConsId, ilngUnidId, VB.Left(Me.txtIdent.Text, 3), Mid(Me.txtIdent.Text, 5, 2), VB.Right(Me.txtIdent.Text, 6), UCase(istrGrupo))
				Call frmConvenios.Show()
			End If
		Else
			Call MsgBox("Você não possue permissão para acessar esta opção!", MsgBoxStyle.Information, gstrTituloMensagem)
		End If
	End Sub
	
	Private Sub cmdConvenios_MouseMove(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.MouseEventArgs) Handles cmdConvenios.MouseMove
		Dim Button As Short = eventArgs.Button \ &H100000
		Dim Shift As Short = System.Windows.Forms.Control.ModifierKeys \ &H10000
		Dim X As Single = VB6.PixelsToTwipsX(eventArgs.X)
		Dim Y As Single = VB6.PixelsToTwipsY(eventArgs.Y)
		labelStatus.Text = " Incluir/excluir convênios e diversos (F10)"
	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 cmdFechar_MouseMove(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.MouseEventArgs) Handles cmdFechar.MouseMove
		Dim Button As Short = eventArgs.Button \ &H100000
		Dim Shift As Short = System.Windows.Forms.Control.ModifierKeys \ &H10000
		Dim X As Single = VB6.PixelsToTwipsX(eventArgs.X)
		Dim Y As Single = VB6.PixelsToTwipsY(eventArgs.Y)
		labelStatus.Text = " Fechar tela de atendimento (F11)"
	End Sub
	
	Private Sub cmdFecharPedidoPrazo_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFecharPedidoPrazo.Click
		Me.fmePedidoDePrazo.Visible = False
		Me.fmePedidoDePrazo.Enabled = False
		Me.SSTab2.Enabled = True
		Me.fmeFaturas.Enabled = True
	End Sub
	
	Private Sub cmdGravaPrazo_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdGravaPrazo.Click
		Dim lstrSql As String
		Dim lstrCriterio As String
		'----- Atualiza a data de prazo na tabela NF -------------------------------------------------------------
		lstrSql = ""
		lstrSql = lstrSql & "UPDATE `nf` "
		lstrSql = lstrSql & "   SET `dataprazo`   = '" & VB6.Format(Me.dtpPrazo.value, "yyyy-MM-dd") & "' "
		lstrSql = lstrSql & " WHERE `nf`.`numnf`  = " & CDbl(Me.labelNumNf.Text) & " "
		lstrSql = lstrSql & "   AND `nf`.`mesano` = '" & Trim(Me.labelMesAno.Text) & "' "
		Call Executar(lstrSql)
		lstrSql = ""
		lstrSql = lstrSql & "UPDATE `concorte` "
		lstrSql = lstrSql & "   SET `dataprazo` = '" & VB6.Format(Me.dtpPrazo.value, "yyyy-MM-dd") & "' "
		lstrSql = lstrSql & " WHERE `concorte`.`numnf`  = " & CDbl(Me.labelNumNf.Text) & " "
		lstrSql = lstrSql & "   AND `concorte`.`mesano` = '" & Trim(Me.labelMesAno.Text) & "' "
		Call Executar(lstrSql)
		'---------------------------------------------------------------------------------------------------------
		'----- Atualiza histórico da unidade consumidora ---------------------------------------------------------
		Call AtualizaHistoricoUnidade(ilngUnidId, "B", "PRORROGADO PRAZO DA NOTA " & Me.labelNumNf.Text & " PARA " & VB6.Format(Me.dtpPrazo.value, "dd/mm/yyyy") & " EM " & VB6.Format(BuscaDataBD, "dd/mm/yyyy") & " POR " & UCase(Trim(Me.txtSolicitantePrazo.Text)) & ".")
		'---------------------------------------------------------------------------------------------------------
		Me.labelStatusPrazo.Text = "Status: Gravação concluída!"
		'----- Chamada do .rpt -----------------------------------------------------------------------------------
		lstrCriterio = "{unidb.unid_id} = " & ilngUnidId & " AND {nf.numnf} = " & Me.labelNumNf.Text & " AND {nf.mesano} = '" & Me.labelMesAno.Text & "'"
		With Me.crpPedidoPrazo
			.ReportFileName = My.Application.Info.DirectoryPath & "\" & LeConfig("DIR_RPT") & LeConfig("REL_PEDIDO_DE_PRAZO")
			.DiscardSavedData = True
			.WindowState = Crystal.WindowStateConstants.crptMaximized
			.WindowControlBox = True
			.WindowControls = True
			.SelectionFormula = lstrCriterio
			.set_Formulas(1, "NmSolicitante = """ & UCase(Me.txtSolicitantePrazo.Text) & """ ")
			.WindowShowPrintSetupBtn = True
			.WindowShowCloseBtn = True
			.WindowShowSearchBtn = True
			.WindowTitle = "Pedido de Prazo Para Pagamento de Conta de Energia Elétrica"
			.Destination = Crystal.DestinationConstants.crptToWindow
			.Action = 0
		End With
		Me.fmePedidoDePrazo.Visible = False
		Me.fmePedidoDePrazo.Enabled = False
		Me.SSTab2.Enabled = True
		Me.fmeFaturas.Enabled = True
	End Sub
	
	'UPGRADE_WARNING: Event cmbMeses.SelectedIndexChanged 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 cmbMeses_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmbMeses.SelectedIndexChanged
		Dim llngLinha As Integer
		Dim ldblMedia As Double
		Dim ldblMaior As Double
		Dim ldblMenor As Double
		
		With Me.mfgConsumos
			If .Rows > 1 Then
				ldblMaior = CDbl(.get_TextMatrix(1, 1))
				ldblMenor = ldblMaior
				If Me.cmbMeses.Items.Count > 0 Then
					For llngLinha = 1 To CInt(VB6.GetItemString(Me.cmbMeses, Me.cmbMeses.SelectedIndex))
						ldblMedia = ldblMedia + CDbl(.get_TextMatrix(llngLinha, 1))
						If CDbl(.get_TextMatrix(llngLinha, 1)) > ldblMaior Then ldblMaior = CDbl(.get_TextMatrix(llngLinha, 1))
						If CDbl(.get_TextMatrix(llngLinha, 1)) < ldblMenor Then ldblMenor = CDbl(.get_TextMatrix(llngLinha, 1))
					Next llngLinha
					If ldblMedia > 0 Then
						Me.txtMedia.Text = CStr(Arredondar(ldblMedia / CDbl(VB6.GetItemString(Me.cmbMeses, Me.cmbMeses.SelectedIndex)), 0))
					Else
						Me.txtMedia.Text = "0"
					End If
					Me.txtMaior.Text = CStr(Arredondar(ldblMaior, 0))
					Me.txtMenor.Text = CStr(Arredondar(ldblMenor, 0))
					
					'Parte do Grafico
					'        With Me.mscConsumo
					'          .Repaint = False
					'          llngLinha = (Me.cmbMeses.List(Me.cmbMeses.ListIndex))
					'          If UCase(istrGrupo) = "B" Then
					'            .ColumnCount = 1
					'          Else
					'            .ColumnCount = 2
					'          End If
					'          .RowCount = llngLinha
					'          .Row = 1
					'          While llngLinha >= 1
					'            .Column = 1
					'            .RowLabel = Left(mfgConsumos.TextMatrix(llngLinha, 0), 3) & Right(mfgConsumos.TextMatrix(llngLinha, 0), 2)
					'            If UCase(istrGrupo) = "B" Then
					'              .ColumnLabel = "Consumo"
					'              .data = (mfgConsumos.TextMatrix(llngLinha, 1))
					'            Else
					'              .ColumnLabel = "Ponta"
					'              .data = (mfgConsumos.TextMatrix(llngLinha, 1))
					'              .Column = 2
					'              .ColumnLabel = "Fora Ponta"
					'              .data = (mfgConsumos.TextMatrix(llngLinha, 2))
					'            End If
					'            llngLinha = llngLinha - 1
					'            If .Row < .RowCount Then .Row = .Row + 1
					'          Wend
					'          .Repaint = True
					'        End With
				End If
			End If
		End With
	End Sub
	
	Private Sub cmdExecutar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExecutar.Click
		Dim ldtePrazo As Date
		Dim lstrMesAn As String
		Dim ldblNumNf As Double
		Dim lblnAux As Boolean
		Dim lstrPPrazo As String
		lblnAux = True
		With Me.mfgFaturas
			ldblNumNf = CDbl(.get_TextMatrix(.Row, 15))
			lstrMesAn = .get_TextMatrix(.Row, 16)
			labelNumNf.Text = CStr(ldblNumNf)
			Me.labelMesAno.Text = lstrMesAn
			Me.labelVencimento.Text = .get_TextMatrix(.Row, 0)
			Me.labelValor.Text = .get_TextMatrix(.Row, 11)
			lstrPPrazo = IIf(IsDate(.get_TextMatrix(.Row, 17)), .get_TextMatrix(.Row, 17), "")
		End With
		Select Case Me.SSTab2.SelectedIndex
			Case 0, 2 'Guia em Abertos/Reserva Júdice
				If Me.optVia2.Checked Then 'Segunda Vida
					Call CobraSegundaVia(ldblNumNf, lstrMesAn)
				ElseIf Me.optDemon.Checked Then  'Demonstrativo
					If UCase(istrGrupo) = "B" Then
						Call ifrmImpFaturas.GeraFaturaGrupoB(2, lstrMesAn, ldblNumNf, 0, "nf")
					Else
						Call ifrmImpFaturas.GeraFaturaGrupoA(2, lstrMesAn, ldblNumNf, 0, "nf")
					End If
				ElseIf Me.optpPrz.Checked Then  'Pedido de Prazo
					If InStr(1, Me.txtAviso.Text, "*** +Inadimplente ***") > 0 Then
						lblnAux = (MsgBox("Este consumidor esta na lista dos mais *** INADIMPLENTES ***!" & vbCrLf & "Tem certeza que deseja dar prazo mesmo assim?", MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton1) = MsgBoxResult.Yes)
					End If
					If lstrPPrazo <> "" Then
						If IsDate(lstrPPrazo) Then
							lblnAux = (MsgBox("Já foi dado o prazo até " & VB6.Format(lstrPPrazo, "dd/mm/yyyy") & " para esta fatura" & vbCrLf & "Tem certeza que deseja dar outro prazo mesmo assim?", MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton1) = MsgBoxResult.Yes)
						End If
					End If
					If lblnAux Then
						Me.dtpPrazo.value = VB6.Format(BuscaDataBD, "dd/mm/yyyy")
						Me.txtSolicitantePrazo.Text = Me.txtNomeU.Text
						ldtePrazo = ChecaPrazoFatura(ldblNumNf, lstrMesAn)
						If ldtePrazo = CDate("01/01/1900") Then
							Me.labelStatusPrazo.Text = "Status: prazo não definido."
						Else
							Me.labelStatusPrazo.Text = "Status: o prazo para esta fatura já foi definido para " & VB6.Format(ldtePrazo, "dd/mm/yyyy") & "."
						End If
						With Me.fmePedidoDePrazo
							.Left = VB6.TwipsToPixelsX((VB6.PixelsToTwipsX(Me.Width) - VB6.PixelsToTwipsX(.Width)) / 2)
							.Top = VB6.TwipsToPixelsY((VB6.PixelsToTwipsY(Me.Height) - VB6.PixelsToTwipsY(.Height)) / 2)
							.Enabled = True
							.Visible = True
						End With
						Me.SSTab2.Enabled = False
						Me.fmeFaturas.Enabled = False
						Call Me.dtpPrazo.Focus()
					End If
				End If
			Case Is = 1 'Guia Pagas
				If Me.optDemon.Checked Then 'Demonstrativo
					If UCase(istrGrupo) = "B" Then
						Call ifrmImpFaturas.GeraFaturaGrupoB(2, lstrMesAn, ldblNumNf, 0, "nf")
					ElseIf UCase(istrGrupo) = "A" Then 
						Call ifrmImpFaturas.GeraFaturaGrupoA(2, lstrMesAn, ldblNumNf, 0, "nf")
					End If
				ElseIf Me.optEstornar.Checked Then 
					With Me.fmeMotivo
						.Left = VB6.TwipsToPixelsX((VB6.PixelsToTwipsX(Me.Width) - VB6.PixelsToTwipsX(.Width)) / 2)
						.Top = VB6.TwipsToPixelsY((VB6.PixelsToTwipsY(Me.Height) - VB6.PixelsToTwipsY(.Height)) / 2)
						.Enabled = True
						.Visible = True
					End With
					Me.SSTab2.Enabled = False
					Me.fmeFaturas.Enabled = False
					'UPGRADE_WARNING: TextBox property txtMotivo.MaxLength has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
					Me.txtMotivo.Maxlength = 79
					Call Me.txtMotivo.Focus()
					Me.lblMotNumNf.Text = CStr(ldblNumNf)
					Me.lblMotMesAno.Text = lstrMesAn
				End If
		End Select
	End Sub
	
	Private Sub cmdExpRet_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExpRet.Click
		'Vai servir para chamar o simulador de calculo
		'call frmCalculoGrupoBAvulso.SetaCalculoAvulsoB(ConsId,UnidId,
		'Call frmCalculoGrupoBAvulso.Show
	End Sub
	
	'[OK]
	Private Sub cmdFecharImp_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFecharImp.Click
		Me.fmeBotoes.Enabled = True
		Me.fmeFaturas.Visible = False
		Me.mfgAbertas.Enabled = (gblnUsuario_Faturas_todos_aberto Or gblnUsuario_Faturas_aberto_cortado)
		Me.mfgPagas.Enabled = gblnUsuario_Faturas_pagas
		Me.mfgReserva.Enabled = gblnUsuario_Faturas_reserva_judice
	End Sub
	
	
	Private Sub desabilitaCampos()
		'Campos da unidade consumidora que ficarão desabilitados
		
		'Campos do consumidor que ficarão desabilitados
		
		
		With Me.SSTab2
			Me.SSTab2.TabPages.Item(0).Enabled = (gblnUsuario_Faturas_todos_aberto Or gblnUsuario_Faturas_aberto_cortado)
			Me.SSTab2.TabPages.Item(0).Visible = (gblnUsuario_Faturas_todos_aberto Or gblnUsuario_Faturas_aberto_cortado)
			Me.mfgAbertas.Visible = (gblnUsuario_Faturas_todos_aberto Or gblnUsuario_Faturas_aberto_cortado)
			
			Me.SSTab2.TabPages.Item(1).Enabled = gblnUsuario_Faturas_pagas
			Me.SSTab2.TabPages.Item(1).Visible = gblnUsuario_Faturas_pagas
			
			Me.SSTab2.TabPages.Item(2).Enabled = gblnUsuario_Faturas_reserva_judice
			Me.SSTab2.TabPages.Item(2).Visible = gblnUsuario_Faturas_reserva_judice
			
			Me.SSTab2.TabPages.Item(3).Enabled = gblnUsuario_Faturas_ultimos_consumos
			Me.SSTab2.TabPages.Item(3).Visible = gblnUsuario_Faturas_ultimos_consumos
			
			Me.SSTab2.TabPages.Item(4).Enabled = False 'gblnUsuario_Faturas_ultimos_consumos
			Me.SSTab2.TabPages.Item(4).Visible = False 'gblnUsuario_Faturas_ultimos_consumos
			
			'.TabEnabled(5) = gblnUsuario_Servicos_ultimas_ordens_servicos
			'.TabEnabled(6) = gblnUsuario_Servicos_ultimas_reclamacoes
			Me.SSTab2.TabPages.Item(5).Enabled = False
			Me.SSTab2.TabPages.Item(6).Enabled = False
			Me.SSTab2.TabPages.Item(5).Visible = False
			Me.SSTab2.TabPages.Item(6).Visible = False
			
			
		End With
		Me.optDemon.Enabled = gblnUsuario_Faturas_demonstrativo
		Me.optVia2.Enabled = gblnUsuario_Faturas_segunda_via
		Me.optpPrz.Enabled = gblnUsuario_Faturas_pedido_prazo
		
		Me.fmeAux(8).Visible = (gblnUsuario_Faturas_todos_aberto Or gblnUsuario_Faturas_aberto_cortado)
		Me.fmeAux(9).Visible = gblnUsuario_Faturas_reserva_judice
		
		If gblnUsuario_Faturas_todos_aberto = False And gblnUsuario_Faturas_aberto_cortado = False And gblnUsuario_Faturas_pagas = False And gblnUsuario_Faturas_reserva_judice = False And gblnUsuario_Faturas_ultimos_consumos = False Then
			Me.SSTab2.Visible = False
			Me.labelStatus.Top = VB6.TwipsToPixelsY(5275)
			Me.Height = VB6.TwipsToPixelsY(5940)
		Else
			Me.SSTab2.Visible = True
			Me.labelStatus.Top = VB6.TwipsToPixelsY(7800)
			Me.Height = VB6.TwipsToPixelsY(8505)
		End If
	End Sub
	
	'[OK]
	Private Sub MontaGrids()
		'***** Grid: Faturas em Aberto ***************************************************************************
		With Me.mfgAbertas
			Call .Clear()
			.Rows = 1
			.set_ColWidth(0, 700)
			.set_ColWidth(1, 1000)
			.set_ColWidth(2, 1300)
			.set_ColWidth(3, 980)
			.set_ColWidth(4, 600)
			.set_ColWidth(5, 850)
			.set_ColWidth(6, 1000)
			.set_ColWidth(7, 10000)
			.set_TextMatrix(0, 0, "Mês/Ano")
			.set_TextMatrix(0, 1, "Vencimento")
			.set_TextMatrix(0, 2, "Valor (R$)")
			.set_TextMatrix(0, 3, "Fatura")
			.set_TextMatrix(0, 4, "Dias")
			.set_TextMatrix(0, 5, "Reaviso")
			.set_TextMatrix(0, 6, "Ped. Prazo")
			.set_TextMatrix(0, 7, "Nome")
		End With
		'***** Grid: Reserva *************************************************************************************
		With Me.mfgReserva
			.set_ColWidth(0, 700)
			.set_ColWidth(1, 1000)
			.set_ColWidth(2, 1300)
			.set_ColWidth(3, 980)
			.set_ColWidth(4, 600)
			.set_ColWidth(5, 850)
			.set_ColWidth(6, 1000)
			.set_ColWidth(7, 10000)
			.set_TextMatrix(0, 0, "Mês/Ano")
			.set_TextMatrix(0, 1, "Vencimento")
			.set_TextMatrix(0, 2, "Valor (R$)")
			.set_TextMatrix(0, 3, "Fatura")
			.set_TextMatrix(0, 4, "Dias")
			.set_TextMatrix(0, 5, "Reaviso")
			.set_TextMatrix(0, 6, "Ped. Prazo")
			.set_TextMatrix(0, 7, "Nome")
		End With
		'***** Grid: Últimas Faturas Pagas ***********************************************************************
		With Me.mfgPagas
			.set_ColWidth(0, 900)
			.set_ColWidth(1, 1000)
			.set_ColWidth(2, 1500)
			.set_ColWidth(3, 1100)
			.set_ColWidth(4, 1000)
			.set_ColWidth(5, 1500)
			.set_ColWidth(6, 1000)
			.set_ColWidth(7, 8500)
			.set_TextMatrix(0, 0, "Mês/Ano")
			.set_TextMatrix(0, 1, "Vencimento")
			.set_TextMatrix(0, 2, "Valor (R$)")
			.set_TextMatrix(0, 3, "Fatura")
			.set_TextMatrix(0, 4, "Pagamento")
			.set_TextMatrix(0, 5, "Banco")
			.set_TextMatrix(0, 6, "Ped. Prazo")
			.set_TextMatrix(0, 7, "Nome")
		End With
		'***** Grid: Últimos Consumos ****************************************************************************
		With Me.mfgConsumos
			If UCase(istrGrupo) = "A" Then
				.Cols = 12
				.ScrollBars = MSFlexGridLib.ScrollBarsSettings.flexScrollBarVertical
				.set_ColWidth(0, 750)
				.set_ColWidth(1, 1000)
				.set_ColWidth(2, 1000)
				.set_ColWidth(3, 1000)
				.set_ColWidth(4, 1000)
				.set_ColWidth(5, 1000)
				.set_ColWidth(6, 1000)
				.set_ColWidth(7, 1000)
				.set_ColWidth(8, 500)
				.set_ColWidth(9, 1000)
				.set_ColWidth(10, 1000)
				.set_ColWidth(11, 10000)
				.set_TextMatrix(0, 0, "Mês/Ano")
				.set_TextMatrix(0, 1, "Consumo P")
				.set_TextMatrix(0, 2, "Consumo FP")
				.set_TextMatrix(0, 3, "Demanda P")
				.set_TextMatrix(0, 4, "Demanda FP")
				.set_TextMatrix(0, 5, "Data Leitura")
				.set_TextMatrix(0, 6, "Leitura")
				.set_TextMatrix(0, 7, "Leitura Anterior")
				.set_TextMatrix(0, 8, "Dias")
				.set_TextMatrix(0, 9, "Fatura")
				.set_TextMatrix(0, 10, "kWh")
				.set_TextMatrix(0, 11, "")
			ElseIf UCase(istrGrupo) = "B" Then 
				.Cols = 11
				.ScrollBars = MSFlexGridLib.ScrollBarsSettings.flexScrollBarVertical
				.set_ColWidth(0, 1000)
				.set_ColWidth(1, 1000)
				.set_ColWidth(2, 1000)
				.set_ColWidth(3, 1000)
				.set_ColWidth(4, 1000)
				.set_ColWidth(5, 1000)
				.set_ColWidth(6, 1000)
				.set_ColWidth(7, 1000)
				.set_ColWidth(8, 0)
				.set_ColWidth(9, 0)
				.set_ColWidth(10, 10000)
				.set_TextMatrix(0, 0, "Mês/Ano")
				.set_TextMatrix(0, 1, "kWh Lido")
				.set_TextMatrix(0, 2, "kWh Fat.")
				.set_TextMatrix(0, 3, "Data Leitura")
				.set_TextMatrix(0, 4, "Leitura")
				.set_TextMatrix(0, 5, "Leitura Ant.")
				.set_TextMatrix(0, 6, "Dias")
				.set_TextMatrix(0, 7, "Fatura")
				.set_TextMatrix(0, 8, "") 'código ocorrência
				.set_TextMatrix(0, 9, "") 'descrição ocorrência
				.set_TextMatrix(0, 10, "")
			End If
		End With
		'***** Grid: Informações da Fatura ***********************************************************************
		With mfgFaturas
			.set_ColWidth(0, 1200)
			.set_ColWidth(1, 1200)
			.set_ColWidth(2, 1000)
			.set_ColWidth(3, 1000)
			.set_ColWidth(4, 1000)
			.set_ColWidth(5, 1000)
			.set_ColWidth(6, 1000)
			.set_ColWidth(7, 1000)
			.set_ColWidth(8, 1000)
			.set_ColWidth(9, 500)
			.set_ColWidth(10, 800)
			.set_ColWidth(11, 1000)
			.set_ColWidth(12, 1000)
			.set_ColWidth(13, 1200)
			.set_ColWidth(14, 1000)
			.set_ColWidth(15, 0)
			.set_ColWidth(16, 0)
			.set_ColWidth(17, 0)
			.set_TextMatrix(0, 0, "Vencimento")
			.set_TextMatrix(0, 1, "Apresentação")
			.set_TextMatrix(0, 2, "Leitura")
			.set_TextMatrix(0, 3, "Leitura Anterior")
			.set_TextMatrix(0, 4, "Base ICMS")
			.set_TextMatrix(0, 5, "Alíquota ICMS")
			.set_TextMatrix(0, 6, "Valor ICMS")
			.set_TextMatrix(0, 7, "Consumo")
			.set_TextMatrix(0, 8, "Arredondamento")
			.set_TextMatrix(0, 9, "CIP")
			.set_TextMatrix(0, 10, "Classe")
			.set_TextMatrix(0, 11, "Total (R$)")
			.set_TextMatrix(0, 12, "kWh Consumido")
			.set_TextMatrix(0, 13, "Data Pagamento")
			.set_TextMatrix(0, 14, "Arrecadador")
			.set_TextMatrix(0, 15, "NumNf")
			.set_TextMatrix(0, 16, "MesAno")
			.set_TextMatrix(0, 17, "Pedido Prazo")
		End With
		
		With msfgSolServ
			Call .Clear()
			.Rows = 1
			.set_ColWidth(0, 0)
			.set_ColWidth(1, 1000)
			.set_ColWidth(2, 1400)
			.set_ColWidth(3, 1000)
			.set_ColWidth(4, 3050)
			.set_ColWidth(5, 0)
			.set_ColWidth(6, 2900)
			.set_ColWidth(7, 0)
			.set_ColWidth(8, 0)
			.set_ColWidth(9, 1000)
			.set_ColWidth(10, 0)
			.set_ColWidth(11, 0)
			.set_ColWidth(12, 850)
			.set_ColWidth(13, 0)
			.set_ColWidth(14, 0)
			.set_ColWidth(15, 1000)
			.set_ColWidth(16, 0)
			.set_ColWidth(17, 0)
			.set_ColWidth(18, 0)
			.set_ColWidth(19, 0)
			.set_TextMatrix(0, 0, "Identificação")
			.set_TextMatrix(0, 1, "Código")
			.set_TextMatrix(0, 2, "Protocolo")
			.set_TextMatrix(0, 3, "Data Ped.")
			.set_TextMatrix(0, 4, "Descrição do Serviço")
			.set_TextMatrix(0, 5, "Valor (R$)")
			.set_TextMatrix(0, 6, "Solicitante")
			.set_TextMatrix(0, 7, "Unid_ID")
			.set_TextMatrix(0, 8, "Grupo")
			.set_TextMatrix(0, 9, "Data Concl.")
			.set_TextMatrix(0, 10, "Hora Solicitação")
			.set_TextMatrix(0, 11, "Hora Conclusão")
			.set_TextMatrix(0, 12, "Prioridade")
			.set_TextMatrix(0, 13, "Feito Por")
			.set_TextMatrix(0, 14, "Região")
			.set_TextMatrix(0, 15, "Situação")
			.set_TextMatrix(0, 16, "Descrição Serviço")
			.set_TextMatrix(0, 17, "Nome Unidade")
			.set_TextMatrix(0, 18, "Fase")
			.set_TextMatrix(0, 19, "Classe")
		End With
		
		With msfgReclam
			.Rows = 1
			.set_ColWidth(0, 1000)
			.set_ColWidth(1, 1400)
			.set_ColWidth(2, 940)
			.set_ColWidth(3, 510)
			.set_ColWidth(4, 940)
			.set_ColWidth(5, 510)
			.set_ColWidth(6, 0)
			.set_ColWidth(7, 0)
			.set_ColWidth(8, 0)
			.set_ColWidth(9, 0)
			.set_ColWidth(10, 0)
			.set_ColWidth(11, 3950)
			.set_ColWidth(12, 0)
			.set_ColWidth(13, 0)
			.set_ColWidth(14, 0)
			.set_ColWidth(15, 0)
			.set_ColWidth(16, 0)
			.set_ColWidth(17, 850)
			.set_ColWidth(18, 0)
			.set_ColWidth(19, 0)
			.set_ColWidth(20, 0)
			.set_ColWidth(21, 0)
			.set_ColWidth(22, 0)
			.set_ColWidth(23, 1000)
			.set_ColWidth(24, 950)
			.set_TextMatrix(0, 0, "Código")
			.set_TextMatrix(0, 1, "Protocolo")
			.set_TextMatrix(0, 2, "Pedido")
			.set_TextMatrix(0, 3, "Hora")
			.set_TextMatrix(0, 4, "Conclusão")
			.set_TextMatrix(0, 5, "Hora")
			.set_TextMatrix(0, 6, "Cancelado")
			.set_TextMatrix(0, 7, "Hora")
			.set_TextMatrix(0, 8, "Estorno")
			.set_TextMatrix(0, 9, "Hora")
			.set_TextMatrix(0, 10, "Código Tipo Reclamação")
			.set_TextMatrix(0, 11, "Tipo Reclamação")
			.set_TextMatrix(0, 12, "Texto da Reclamação")
			.set_TextMatrix(0, 13, "Texto da Conclusão")
			.set_TextMatrix(0, 14, "Texto do Cancelamento")
			.set_TextMatrix(0, 15, "Texto do Estorno")
			.set_TextMatrix(0, 16, "Código Prioridade")
			.set_TextMatrix(0, 17, "Prioridade")
			.set_TextMatrix(0, 18, "Código Origem")
			.set_TextMatrix(0, 19, "Origem")
			.set_TextMatrix(0, 20, "Código Região")
			.set_TextMatrix(0, 21, "Região")
			.set_TextMatrix(0, 22, "Código Situação")
			.set_TextMatrix(0, 23, "Situação")
			.set_TextMatrix(0, 24, "Procedente")
		End With
		'***** Grid: Faturas em Aberto ***************************************************************************
		With Me.mfgAbertasConsumidor
			Call .Clear()
			.Rows = 1
			.set_ColWidth(0, 700)
			.set_ColWidth(1, 1000)
			.set_ColWidth(2, 1300)
			.set_ColWidth(3, 980)
			.set_ColWidth(4, 600)
			.set_ColWidth(5, 850)
			.set_ColWidth(6, 1000)
			.set_ColWidth(7, 10000)
			.set_ColAlignment(7, MSFlexGridLib.AlignmentSettings.flexAlignLeftCenter)
			.set_TextMatrix(0, 0, "Mês/Ano")
			.set_TextMatrix(0, 1, "Vencimento")
			.set_TextMatrix(0, 2, "Valor (R$)")
			.set_TextMatrix(0, 3, "Fatura")
			.set_TextMatrix(0, 4, "Dias")
			.set_TextMatrix(0, 5, "Reaviso")
			.set_TextMatrix(0, 6, "Ped. Prazo")
			.set_TextMatrix(0, 7, "ZLC")
		End With
	End Sub
	
	Private Function BuscaUnidadeConsumidora(ByVal alngUnidId As Integer, ByVal aintQtdeHistorico As Short) As Boolean
		'--- Consumidor/UC
		Dim llngBanId As Integer
		Dim llngLinha As Integer
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim lstrRota As String
		Dim lstrCpfCnpj As String
		Dim lstrApSaude As String
		Dim lstrEstufa As String
		Dim lstrGrTar As String
		Dim lstrCep As String
		Dim lstrFase As String
		Dim lstrSituacao As String
		Dim lstrRegiao As String
		Dim lstrDiaVenc As String
		Dim lstrTelefone As String
		Dim lstrCelular As String
		Dim lstrFax As String
		Dim ldteMedFab As Date
		Dim ldteMedIns As Date
		Dim llngQtdSus As Integer
		'--- Faturas/Consumos
		Dim lstrMesAno As String
		Dim ldteVencto As Date
		Dim ldtePagnto As Date
		Dim ldteLeiAtu As Date
		Dim ldteLeiAnt As Date
		Dim ldtePPrazo As Date
		Dim ldblValor As Double
		Dim ldblNumNf As Double
		Dim llngConsId As Integer
		Dim ldblVlrAb As Double
		Dim ldblVlrRe As Double
		Dim lstrItens As String
		Dim ldblMedia As Double
		Dim llngDiasA As Integer
		Dim llngAgrupa As Integer
		Dim lstrFlgst As String
		Dim lstrFlgMedFat As String
		Dim lintFatFinal As Short
		'quantificação
		Dim llngFatPagAtrazo As Integer
		Dim llngFatPagVecto As Integer
		Dim llngFatPrazPagas As Integer
		Dim llngFatPrazAbert As Integer
		'
		Dim lblnContinua As Boolean
		'--- Comandos SQL
		Dim ldteBase As Date
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		Dim lrstAgr As ADODB.Recordset
		lrstAgr = New ADODB.Recordset
		Me.txtQtdeAberto.Text = "0"
		Me.txtValorAberto.Text = "0,00"
		Me.txtQtdeReserva.Text = "0"
		Me.txtValorReserva.Text = "0,00"
		Me.txtAgrupaZona.Text = ""
		Me.txtAgrupaLivro.Text = ""
		Me.txtAgrupaConta.Text = ""
		Me.txtAgrupaZona.Text = ""
		Me.txtAgrupaRota.Text = ""
		Me.txtAgrupaNome.Text = ""
		Me.cmbAgrupa.SelectedIndex = 0
		llngFatPagAtrazo = 0
		llngFatPagVecto = 0
		llngFatPrazPagas = 0
		llngFatPrazAbert = 0
		lblnContinua = True
		'----- Dados da Unidade Consumidora ----------------------------------------------------------------------
		With Me.fmeAguarde
			Call .SetBounds(VB6.TwipsToPixelsX(3480), VB6.TwipsToPixelsY(2400), 0, 0, Windows.Forms.BoundsSpecified.X Or Windows.Forms.BoundsSpecified.Y)
		End With
		Me.fmeAguarde.Enabled = True
		Me.fmeAguarde.Visible = True
		System.Windows.Forms.Application.DoEvents()
		ldteBase = BuscaDataBD
		Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
		ilngConsId = 0
		ilngUnidId = 0
		lstrSql = ""
		With irstRegUnid
			If .State = ADODB.ObjectStateEnum.adStateClosed Then
				'If .RecordCount = 0 Then
				'lstrSql = lstrSql & "   SELECT SQL_CALC_FOUND_ROWS * "
				lstrSql = lstrSql & "SELECT HIGH_PRIORITY * "
				lstrSql = lstrSql & "FROM `unid" & LCase(istrGrupo) & "` " 'FORCE INDEX (`keyrota`, `keyzona`, `keylivro`, `keyconta`) "
				lstrSql = lstrSql & "ORDER BY `caderno` ASC, `sequencia` ASC"
				'If alngUnidId > 0 Then
				'  lstrSql = lstrSql & " LIMIT " & ilngLimite & ", 1 "
				'End If
				Call Conectar(lstrSql, irstRegUnid)
				'        If .RecordCount > 0 Then
				'          Call Conectar("SELECT FOUND_ROWS() ", lrstAux)
				'          With lrstAux
				'            If .State > 0 Then
				'              If .RecordCount > 0 Then
				'                ilngQtdeReg = IIf(IsNull(.Fields(0).Value), 0, .Fields(0).Value)
				'              End If
				'              Call .Close
				'            End If
				'          End With
				'        End If
				'End If
			End If
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					If alngUnidId > 0 Then
						ilngLimite = 0
						ilngUnidId = 0
						If alngUnidId = 0 Then
							Call .MoveFirst()
						End If
						'          While Not .EOF And (alngUnidId <> ilngUnidId)
						'            ilngUnidId = CLng(IIf(IsNull(.Fields("unid_id").Value), 0, .Fields("unid_id").Value))
						'            If alngUnidId <> ilngUnidId Then
						'              ilngLimite = ilngLimite + 1
						'              Call .MoveNext
						'            End If
						'          Wend
						Call .Find("unid_id = " & alngUnidId,  , ADODB.SearchDirectionEnum.adSearchForward, 1)
						ilngLimite = .AbsolutePosition - 1
					End If
					Me.txtRegistros.Text = "Registro " & (ilngLimite + 1) & " de " & irstRegUnid.RecordCount
					'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"'
					istrIsRural = Trim(IIf(IsDbNull(.Fields("comprovante_rural").value), "N", .Fields("comprovante_rural").value))
					If istrIsRural = "S" Then
						Me.txtDescrClasse.ForeColor = System.Drawing.ColorTranslator.FromOle(&HC000)
						Me.txtDescrClasse.Font = VB6.FontChangeBold(Me.txtDescrClasse.Font, True)
					Else
						Me.txtDescrClasse.ForeColor = System.Drawing.ColorTranslator.FromOle(&H80000008)
						Me.txtDescrClasse.Font = VB6.FontChangeBold(Me.txtDescrClasse.Font, False)
					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"'
					ilngUnidId = 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"'
					ilngConsId = 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"'
					lstrGrTar = Trim(IIf(IsDbNull(.Fields("ta").value), "01B100", .Fields("ta").value))
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					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"'
					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"'
					lstrCpfCnpj = Trim(IIf(IsDbNull(.Fields("cpf_cnpj").value), "", .Fields("cpf_cnpj").value))
					If UCase(istrGrupo) = "B" 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"'
						lstrApSaude = Trim(IIf(IsDbNull(.Fields("ap_saude").value), "N", .Fields("ap_saude").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"'
					lstrEstufa = Trim(IIf(IsDbNull(.Fields("estufa").value), "N", .Fields("estufa").value))
					Me.txtIdent.Text = lstrZona & "." & lstrLivro & "." & lstrConta
					Me.txtRota.Text = VB.Left(lstrRota, 4) & "/" & VB.Right(lstrRota, 4)
					'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"'
					Me.txtClasse.Text = 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"'
					Me.txtNomeU.Text = Trim(IIf(IsDbNull(.Fields("nome").value), "", .Fields("nome").value))
					If Len(lstrCpfCnpj) > 0 Then
						Me.txtNis.Text = pegaNis(lstrCpfCnpj, lstrZona, lstrLivro, lstrConta, ilngUnidId)
					Else
						Me.txtNis.Text = ""
					End If
					If Len(lstrCpfCnpj) < 14 Then
						Me.txtCpfCnpjU.Text = FormataCPF(lstrCpfCnpj)
					Else
						Me.txtCpfCnpjU.Text = FormataCNPJ(lstrCpfCnpj)
					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"'
					Me.txtInscU.Text = 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"'
					Me.txtRgU.Text = Trim(IIf(IsDbNull(.Fields("rg").value), "", .Fields("rg").value))
					Me.fmeAuxB.Enabled = (Mid(lstrGrTar, 3, 1) = "B")
					Me.fmeAuxB.Visible = (Mid(lstrGrTar, 3, 1) = "B")
					Me.fmeAuxAC.Enabled = (Mid(lstrGrTar, 3, 2) = "A4" Or Mid(lstrGrTar, 3, 2) = "AS")
					Me.fmeAuxAC.Visible = (Mid(lstrGrTar, 3, 2) = "A4" Or Mid(lstrGrTar, 3, 2) = "AS")
					Me.fmeAuxAH.Enabled = (Mid(lstrGrTar, 3, 2) = "AA" Or Mid(lstrGrTar, 3, 2) = "AV" Or Mid(lstrGrTar, 3, 2) = "AL")
					Me.fmeAuxAH.Visible = (Mid(lstrGrTar, 3, 2) = "AA" Or Mid(lstrGrTar, 3, 2) = "AV" Or Mid(lstrGrTar, 3, 2) = "AL")
					If UCase(istrGrupo) = "B" Then
						Me.chkApSaude.CheckState = IIf(lstrApSaude = "S", 1, 0)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						Me.txtMedkWh.Text = Trim(IIf(IsDbNull(.Fields("num").value), "", .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"'
						Me.txtMedkVArh.Text = Trim(IIf(IsDbNull(.Fields("medkvarh").value), "", .Fields("medkvarh").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"'
						Me.txtGBConstante.Text = FormatNumber(CDbl(IIf(IsDbNull(.Fields("const").value), 0, .Fields("const").value)), 5)
						'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"'
						Me.txtGBConstKvarh.Text = FormatNumber(CDbl(IIf(IsDbNull(.Fields("constfp").value), 0, .Fields("constfp").value)), 5)
					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"'
						Me.txtMedkWh.Text = Trim(IIf(IsDbNull(.Fields("eletr").value), "", .Fields("eletr").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"'
						Me.txtMedkW.Text = Trim(IIf(IsDbNull(.Fields("medkw").value), "", .Fields("medkw").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"'
						Me.txtMedkVArh.Text = Trim(IIf(IsDbNull(.Fields("medkvark").value), "", .Fields("medkvark").value))
						If Mid(lstrGrTar, 3, 2) = "A4" Or Mid(lstrGrTar, 3, 2) = "AS" 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"'
							Me.txtGACConstkWh.Text = FormatNumber(CDbl(IIf(IsDbNull(.Fields("const_consumo").value), 0, .Fields("const_consumo").value)), 5)
							'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"'
							Me.txtGACConstkW.Text = FormatNumber(CDbl(IIf(IsDbNull(.Fields("const_demanda").value), 0, .Fields("const_demanda").value)), 5)
							'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"'
							Me.txtGACConstkVArh.Text = FormatNumber(CDbl(IIf(IsDbNull(.Fields("const_kvarh").value), 0, .Fields("const_kvarh").value)), 5)
						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"'
							Me.txtGAHConstkWhP.Text = FormatNumber(CDbl(IIf(IsDbNull(.Fields("const_cons_p").value), 0, .Fields("const_cons_p").value)), 5)
							'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"'
							Me.txtGAHConstkWhFP.Text = FormatNumber(CDbl(IIf(IsDbNull(.Fields("const_cons_fp").value), 0, .Fields("const_cons_fp").value)), 5)
							'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"'
							Me.txtGAHConstkWP.Text = FormatNumber(CDbl(IIf(IsDbNull(.Fields("const_demanda").value), 0, .Fields("const_demanda").value)), 5)
							'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"'
							Me.txtGAHConstkWFP.Text = FormatNumber(CDbl(IIf(IsDbNull(.Fields("const_demanda_fp").value), 0, .Fields("const_demanda_fp").value)), 5)
							'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"'
							Me.txtGAHConstkVArhP.Text = FormatNumber(CDbl(IIf(IsDbNull(.Fields("const_kvarh_p").value), 0, .Fields("const_kvarh_p").value)), 5)
							'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"'
							Me.txtGAHConstkVArhFP.Text = FormatNumber(CDbl(IIf(IsDbNull(.Fields("const_kvarh_fp").value), 0, .Fields("const_kvarh_fp").value)), 5)
						End If
					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"'
					istrEndCodUC = Trim(IIf(IsDbNull(.Fields("codend").value), "", .Fields("codend").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"'
					Me.txtEndU.Text = 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"'
					lstrCep = VB.Left(Trim(IIf(IsDbNull(.Fields("cep").value), "0", .Fields("cep").value)) & "00000000", 8)
					Me.txtCepU.Text = VB.Left(lstrCep, 5) & "-" & VB.Right(lstrCep, 3)
					'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"'
					Me.txtNumeroU.Text = 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"'
					Me.txtLoteU.Text = 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"'
					Me.txtQuadraU.Text = 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"'
					Me.txtBairroU.Text = 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"'
					Me.txtDistritoU.Text = 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"'
					Me.txtComplementoU.Text = 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"'
					Me.txtCidadeU.Text = 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"'
					Me.txtUfU.Text = Trim(IIf(IsDbNull(.Fields("uf").value), "", .Fields("uf").value))
					Me.txtTarifa.Text = Mid(lstrGrTar, 3, 2)
					'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))
					Select Case lstrFase
						Case Is = "M"
							Me.txtFase.Text = "MONOFÁSICO"
						Case Is = "B"
							Me.txtFase.Text = "BIFÁSICO"
						Case Is = "T"
							Me.txtFase.Text = "TRIFÁSICO"
						Case Else
							Me.txtFase.Text = ""
					End Select
					'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(IIf(IsDbNull(.Fields("regiao").value), "U", .Fields("regiao").value))
					Me.txtRegiao.Text = IIf(lstrRegiao = "U", "Urbano", "Rural")
					Me.txtFaseUc.Text = Me.txtFase.Text
					'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"'
					Me.txtTensao.Text = Trim(IIf(IsDbNull(.Fields("tensao").value), "", .Fields("tensao").value))
					If UCase(istrGrupo) = "B" 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"'
						Me.txtTrafo.Text = Trim(IIf(IsDbNull(.Fields("transf").value), "", .Fields("transf").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"'
						Me.txtDisjuntor.Text = Trim(IIf(IsDbNull(.Fields("disjuntor").value), "", .Fields("disjuntor").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"'
						Me.txtArea.Text = Trim(IIf(IsDbNull(.Fields("area").value), "", .Fields("area").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"'
						Me.txtFaseLig.Text = Trim(IIf(IsDbNull(.Fields("faselig").value), "", .Fields("faselig").value))
						Me.cmdLocZlcAgrupa.Enabled = True
						Me.txtAgrupaZona.Enabled = True
						Me.txtAgrupaConta.Enabled = True
						Me.txtAgrupaLivro.Enabled = True
						Me.cmbAgrupa.Enabled = True
						'Agrupa
						'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"'
						llngAgrupa = CInt(IIf(IsDbNull(.Fields("agrupa").value), 1, .Fields("agrupa").value))
						llngLinha = 0
						With Me.cmbAgrupa
							For llngLinha = 0 To .Items.Count
								If VB6.GetItemData(Me.cmbAgrupa, llngLinha) = llngAgrupa Then
									.SelectedIndex = llngLinha
									llngLinha = .Items.Count
								End If
							Next llngLinha
						End With
						'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"'
						Me.txtAgrupaZona.Text = VB6.Format(Trim(IIf(IsDbNull(.Fields("agrupa_zona").value), "", .Fields("agrupa_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"'
						Me.txtAgrupaLivro.Text = VB6.Format(Trim(IIf(IsDbNull(.Fields("agrupa_livro").value), "", .Fields("agrupa_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"'
						Me.txtAgrupaConta.Text = VB6.Format(Trim(IIf(IsDbNull(.Fields("agrupa_conta").value), "", .Fields("agrupa_conta").value)), "000000")
						If Len(Me.txtAgrupaZona.Text) > 0 Then
							lstrSql = ""
							lstrSql = lstrSql & "SELECT `zona`, `livro`, `conta`, `rota`, `nome`, `unid_id`, `cons_id` "
							lstrSql = lstrSql & "  FROM `unidb` "
							lstrSql = lstrSql & " WHERE `zona`  = '" & Me.txtAgrupaZona.Text & "' "
							lstrSql = lstrSql & "   AND `livro` = '" & Me.txtAgrupaLivro.Text & "' "
							lstrSql = lstrSql & "   AND `conta` = '" & Me.txtAgrupaConta.Text & "' "
							Call Conectar(lstrSql, lrstAgr)
							With lrstAgr
								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"'
										Me.txtAgrupaRota.Text = 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"'
										Me.txtAgrupaNome.Text = UCase(Trim(IIf(IsDbNull(.Fields("nome").value), "", .Fields("nome").value)))
									End If
									Call .Close()
								End If
							End With
						End If
					Else
						Me.cmdLocZlcAgrupa.Enabled = False
						Me.txtAgrupaZona.Enabled = False
						Me.txtAgrupaConta.Enabled = False
						Me.txtAgrupaLivro.Enabled = False
						Me.cmbAgrupa.Enabled = False
					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"'
					Me.txtTipoLig.Text = Trim(IIf(IsDbNull(.Fields("tp_ligacao").value), "", .Fields("tp_ligacao").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"'
					ldteMedFab = CDate(IIf(IsDbNull(.Fields("dtafabmedidor").value), "1900-01-01", .Fields("dtafabmedidor").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"'
					ldteMedIns = CDate(IIf(IsDbNull(.Fields("dtainstmedidor").value), "1900-01-01", .Fields("dtainstmedidor").value))
					If ldteMedFab <> CDate("01/01/1900") Then
						Me.txtDteFab.Text = VB6.Format(ldteMedFab, "dd/mm/yyyy")
					Else
						Me.txtDteFab.Text = ""
					End If
					If ldteMedIns <> CDate("01/01/1900") Then
						Me.txtDteInst.Text = VB6.Format(ldteMedIns, "dd/mm/yyyy")
					Else
						Me.txtDteInst.Text = ""
					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"'
					Me.txtMarca.Text = 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"'
					Me.txtLacre.Text = Trim(IIf(IsDbNull(.Fields("lacre").value), "", .Fields("lacre").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"'
					Me.txtObsUc.Text = Trim(IIf(IsDbNull(.Fields("itensesp").value), "", .Fields("itensesp").value))
					'Ligado;Desligado;Inativado;Cortado;Não Ligado
					'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))
					Select Case lstrSituacao
						Case Is = "L"
							Me.txtSituacao.Text = "LIGADO"
						Case Is = "D"
							Me.txtSituacao.Text = "DESLIGADO"
						Case Is = "C"
							Me.txtSituacao.Text = "CORTADO"
						Case Is = "N"
							Me.txtSituacao.Text = "NÃO LIGADO"
						Case Is = "I"
							Me.txtSituacao.Text = "INATIVADO" 'DESATIVADO"
						Case Else
							Me.txtSituacao.Text = ""
					End Select
					'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"'
					Me.txtCargaU.Text = Trim(IIf(IsDbNull(.Fields("carga").value), "", .Fields("carga").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"'
					lstrDiaVenc = VB6.Format(Trim(IIf(IsDbNull(.Fields("diavenc").value), "0", .Fields("diavenc").value)), "00")
					Call BuscaDiaVencimento(lstrDiaVenc)
					'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"'
					Me.txtIdCnae.Text = CStr(CInt(IIf(IsDbNull(.Fields("idcnae").value), 0, .Fields("idcnae").value)))
					Call BuscaNomeCNAE(IIf(IsNumeric(Me.txtIdCnae.Text), Me.txtIdCnae.Text, 0))
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					llngBanId = CInt(Trim(IIf(IsDbNull(.Fields("banco").value), 0, .Fields("banco").value)))
					llngLinha = 0
					Me.txtBanco.Text = BuscaNomeBancos(llngBanId)
					'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"'
					Me.txtAg.Text = Trim(IIf(IsDbNull(.Fields("agenc").value), "", .Fields("agenc").value))
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					Me.txtCC.Text = Trim(IIf(IsDbNull(.Fields("cc").value), "", .Fields("cc").value))
					Me.txtDescrClasse.Text = BuscaNomeClasse(Me.txtClasse.Text)
					'----- Dados do Endereço de Correspondência ------------------------------------------------------------
					'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"'
					istrEndCodEn = IIf(IsDbNull(.Fields("codend_entrega").value), "", .Fields("codend_entrega").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					txtEndE.Text = IIf(IsDbNull(.Fields("end_entrega").value), "", .Fields("end_entrega").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					lstrCep = VB.Left(Trim(IIf(IsDbNull(.Fields("cep_entrega").value), "0", .Fields("cep_entrega").value)) & "00000000", 8)
					Me.txtCepE.Text = VB.Left(lstrCep, 5) & "-" & VB.Right(lstrCep, 3)
					'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"'
					Me.txtNumeroE.Text = Trim(IIf(IsDbNull(.Fields("num_entrega").value), "", .Fields("num_entrega").value))
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					Me.txtBairroE.Text = Trim(IIf(IsDbNull(.Fields("bai_entrega").value), "", .Fields("bai_entrega").value))
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					Me.txtDistritoE.Text = Trim(IIf(IsDbNull(.Fields("dis_entrega").value), "", .Fields("dis_entrega").value))
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					Me.txtComplementE.Text = Trim(IIf(IsDbNull(.Fields("compl_entrega").value), "", .Fields("compl_entrega").value))
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					Me.txtLoteE.Text = Trim(IIf(IsDbNull(.Fields("lot_entrega").value), "", .Fields("lot_entrega").value))
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					Me.txtQuadraE.Text = Trim(IIf(IsDbNull(.Fields("qua_entrega").value), "", .Fields("qua_entrega").value))
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					Me.txtCidadeE.Text = Trim(IIf(IsDbNull(.Fields("cid_entrega").value), "", .Fields("cid_entrega").value))
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					Me.txtUfE.Text = Trim(IIf(IsDbNull(.Fields("uf_entrega").value), "", .Fields("uf_entrega").value))
				End If
			End If
		End With
		'----- Dados do Consumidor -----------------------------------------------------------------------------
		If ilngConsId > 0 Then
			If irstRegCons.State = ADODB.ObjectStateEnum.adStateOpen Then Call irstRegCons.Close()
			lstrSql = ""
			lstrSql = lstrSql & "SELECT * "
			lstrSql = lstrSql & "  FROM `consum` "
			lstrSql = lstrSql & " WHERE `consum`.`consreg` = " & ilngConsId
			Call Conectar(lstrSql, irstRegCons)
			With irstRegCons
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						'Call .Find("consreg = " & ilngConsId, , adSearchForward, 1)
						'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"'
						Me.txtNomeC.Text = Trim(IIf(IsDbNull(.Fields("nome").value), "", .Fields("nome").value))
						Me.txtConsId.Text = CStr(ilngConsId)
						'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("cgc").value), "", .Fields("cgc").value))
						If Len(lstrCpfCnpj) < 14 Then
							Me.txtCpfCnpjC.Text = FormataCPF(lstrCpfCnpj)
						Else
							Me.txtCpfCnpjC.Text = FormataCNPJ(lstrCpfCnpj)
						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"'
						Me.txtInscC.Text = 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"'
						Me.txtRgC.Text = 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"'
						istrEndCodC = Trim(IIf(IsDbNull(.Fields("codend").value), "", .Fields("codend").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"'
						Me.txtEndC.Text = 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"'
						lstrCep = VB.Left(Trim(IIf(IsDbNull(.Fields("cep").value), "0", .Fields("cep").value)) & "00000000", 8)
						Me.txtCepC.Text = VB.Left(lstrCep, 5) & "-" & VB.Right(lstrCep, 3)
						'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"'
						Me.txtNumeroC.Text = 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"'
						Me.txtLoteC.Text = 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"'
						Me.txtQuadraC.Text = 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"'
						Me.txtBairroC.Text = 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"'
						Me.txtDistritoC.Text = 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"'
						Me.txtComplementoC.Text = 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"'
						Me.txtCidadeC.Text = 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"'
						Me.txtUfC.Text = Trim(IIf(IsDbNull(.Fields("uf").value), "", .Fields("uf").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						Me.txtDddTel.Text = Trim(IIf(IsDbNull(.Fields("dddtel").value), "", .Fields("dddtel").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"'
						lstrTelefone = Trim(IIf(IsDbNull(.Fields("telefone").value), "", .Fields("telefone").value))
						Me.txtTEL.Text = IIf(Len(lstrTelefone) = 8, VB.Left(lstrTelefone, 4) & "-" & VB.Right(lstrTelefone, 4), lstrTelefone)
						'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"'
						Me.txtEmail.Text = Trim(IIf(IsDbNull(.Fields("email").value), "", .Fields("email").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"'
						Me.txtObsCons.Text = Trim(IIf(IsDbNull(.Fields("observacao").value), "", .Fields("observacao").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"'
						Me.txtDddCel.Text = Trim(IIf(IsDbNull(.Fields("dddcel").value), "", .Fields("dddcel").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"'
						lstrCelular = Trim(IIf(IsDbNull(.Fields("cel").value), "", .Fields("cel").value))
						Me.txtCel.Text = IIf(Len(lstrCelular) = 8, VB.Left(lstrCelular, 4) & "-" & VB.Right(lstrCelular, 4), lstrCelular)
						'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"'
						Me.txtDddFax.Text = Trim(IIf(IsDbNull(.Fields("dddfax").value), "", .Fields("dddfax").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"'
						lstrFax = Trim(IIf(IsDbNull(.Fields("fax").value), "", .Fields("fax").value))
						Me.txtFax.Text = IIf(Len(lstrFax) = 8, VB.Left(lstrFax, 4) & "-" & VB.Right(lstrFax, 4), lstrFax)
						'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"'
						Me.txtNomeMae.Text = Trim(IIf(IsDbNull(.Fields("nomemae").value), "", .Fields("nomemae").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"'
						Me.txtNomePai.Text = Trim(IIf(IsDbNull(.Fields("nomepai").value), "", .Fields("nomepai").value))
					End If
				End If
			End With
		End If
		'----- Verificação de CPF/CNPJ ---------------------------------------------------------------------
		If SSTab1.SelectedIndex = 0 Then 'Guia Unidade Consumidora
			If Len(Me.txtCpfCnpjU.Text) > 0 Then
				If Len(Trim(Str_Retira(Me.txtCpfCnpjU.Text, ".-/ "))) = 11 Then
					If Not CPFOk(Str_Retira(Me.txtCpfCnpjU.Text, ".-/ ")) Then
						Call MsgBox("ATENÇÃO! O CPF cadastrado não é válido!" & vbCrLf & vbCrLf & "Se possível, atualize o cadastro.", MsgBoxStyle.Exclamation, gstrTituloMensagem)
					End If
				ElseIf Len(Trim(Str_Retira(Me.txtCpfCnpjU.Text, ".-/ "))) = 14 Then 
					If Not Int_Valida_CNPJ(Str_Retira(Me.txtCpfCnpjU.Text, ".-/ ")) Then
						Call MsgBox("ATENÇÃO! O CNPJ cadastrado não é válido!" & vbCrLf & vbCrLf & "Se possível, atualize o cadastro.", MsgBoxStyle.Exclamation, gstrTituloMensagem)
					End If
				Else
					Call MsgBox("ATENÇÃO! O CPF/CNPJ do consumidor não é válido!" & vbCrLf & vbCrLf & "Se possível, atualize o cadastro.", MsgBoxStyle.Exclamation, gstrTituloMensagem)
				End If
			End If
		ElseIf SSTab1.SelectedIndex = 1 Then 
			If Len(Me.txtCpfCnpjC.Text) > 0 Then
				If Len(Trim(Str_Retira(Me.txtCpfCnpjC.Text, ".-/ "))) = 11 Then
					If Not CPFOk(Str_Retira(Me.txtCpfCnpjC.Text, ".-/ ")) Then
						Call MsgBox("ATENÇÃO! O CPF cadastrado não é válido!" & vbCrLf & vbCrLf & "Se possível, atualize o cadastro.", MsgBoxStyle.Exclamation, gstrTituloMensagem)
					End If
				ElseIf Len(Trim(Str_Retira(Me.txtCpfCnpjC.Text, ".-/ "))) = 14 Then 
					If Not Int_Valida_CNPJ(Str_Retira(Me.txtCpfCnpjC.Text, ".-/ ")) Then
						Call MsgBox("ATENÇÃO! O CNPJ cadastrado não é válido!" & vbCrLf & vbCrLf & "Se possível, atualize o cadastro.", MsgBoxStyle.Exclamation, gstrTituloMensagem)
					End If
				Else
					Call MsgBox("ATENÇÃO! O CPF/CNPJ do consumidor não é válido!" & vbCrLf & vbCrLf & "Se possível, atualize o cadastro.", MsgBoxStyle.Exclamation, gstrTituloMensagem)
				End If
			End If
		End If
		If ilngUnidId > 0 Then
			If gblnUsuario_Faturas_aberto_cortado And Not gblnUsuario_Faturas_todos_aberto Then
				lblnContinua = (lstrSituacao = "C")
			End If
			If (gblnUsuario_Faturas_todos_aberto Or gblnUsuario_Faturas_aberto_cortado) And lblnContinua Then
				ldblVlrAb = 0
				'----- Enche Grid: Faturas em Aberto -------------------------------------------------------------------
				With Me.mfgAbertas
					.Rows = 1
					.Redraw = False
				End With
				lstrSql = ""
				lstrSql = lstrSql & "  SELECT `nf`.`mesano_ref`, "
				lstrSql = lstrSql & "         `nf`.`datavenc`, "
				lstrSql = lstrSql & "         `nf`.`dataprazo`, "
				lstrSql = lstrSql & "         `nf`.`valortot`, "
				lstrSql = lstrSql & "         `nf`.`numnf`, "
				lstrSql = lstrSql & "         `nf`.`cons_id`, "
				lstrSql = lstrSql & "         `nf`.`unid_id`, "
				lstrSql = lstrSql & "         `nf`.`flgst`, "
				lstrSql = lstrSql & "         `nf`.`flgmedfat`, "
				lstrSql = lstrSql & "         `nf`.`fatura_final`, "
				lstrSql = lstrSql & "         `nf`.`grupo`, "
				lstrSql = lstrSql & "         `nf`.`codclas`, "
				lstrSql = lstrSql & "         `nf`.`zona`, "
				lstrSql = lstrSql & "         `nf`.`livro`, "
				lstrSql = lstrSql & "         `nf`.`conta`, "
				lstrSql = lstrSql & "         `nf`.`datapag`, "
				lstrSql = lstrSql & "         `nf`.`datast`, "
				lstrSql = lstrSql & "         `nf`.`mesano`, "
				lstrSql = lstrSql & "         `nf`.`rota`, "
				lstrSql = lstrSql & "         `nf`.`ta` "
				lstrSql = lstrSql & "    FROM `nf` "
				lstrSql = lstrSql & "   WHERE `nf`.`unid_id`    = " & ilngUnidId
				lstrSql = lstrSql & "     AND `nf`.`flgst`      = '' "
				lstrSql = lstrSql & "     AND `nf`.`grupo`      = '" & UCase(istrGrupo) & "' "
				lstrSql = lstrSql & "     AND `nf`.`mesano_ref` <= " & VB6.Format(ldteBase, "yyyyMM") & " "
				lstrSql = lstrSql & "ORDER BY `mesano_ref` DESC "
				If aintQtdeHistorico > 0 Then
					lstrSql = lstrSql & " LIMIT 0, " & aintQtdeHistorico
				End If
				Call Conectar(lstrSql, lrstAux)
				With lrstAux
					If .State > 0 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"'
								lstrMesAno = Trim(IIf(IsDbNull(.Fields("mesano_ref").value), "", .Fields("mesano_ref").value))
								lstrMesAno = VB.Right(lstrMesAno, 2) & "/" & VB.Left(lstrMesAno, 4)
								'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"'
								ldteVencto = CDate(IIf(IsDbNull(.Fields("datavenc").value), "1900-01-01", .Fields("datavenc").value))
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								ldtePPrazo = CDate(IIf(IsDbNull(.Fields("dataprazo").value), "1900-01-01", .Fields("dataprazo").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"'
								ldblValor = CDbl(IIf(IsDbNull(.Fields("valortot").value), 0, .Fields("valortot").value))
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								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"'
								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"'
								lstrFlgMedFat = Trim(IIf(IsDbNull(.Fields("flgmedfat").value), "N", .Fields("flgmedfat").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"'
								lintFatFinal = IIf(IsDbNull(.Fields("fatura_final").value), "0", .Fields("fatura_final").value)
								'UPGRADE_WARNING: DateDiff behavior may be different. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6B38EC3F-686D-4B2E-B5A5-9E8E7A762E32"'
								llngDiasA = CInt(DateDiff(Microsoft.VisualBasic.DateInterval.Day, ldteVencto, ldteBase))
								If ldtePPrazo <> CDate("01/01/1900") Then
									llngFatPrazAbert = llngFatPrazAbert + 1
								End If
								If llngDiasA < 1 Then llngDiasA = 0
								With Me.mfgAbertas
									.Rows = .Rows + 1
									'UPGRADE_ISSUE: VBControlExtender method mfgAbertas.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
									.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillRepeat
									If ldtePPrazo > ldteBase Then
										.Row = .Rows - 1
										.Col = 0
										.ColSel = .Cols - 1
										.CellForeColor = System.Drawing.ColorTranslator.FromOle(&HFF0000) 'Azul
									ElseIf ldteVencto < ldteBase Then 
										.Row = .Rows - 1
										.Col = 0
										.ColSel = .Cols - 1
										.CellForeColor = System.Drawing.ColorTranslator.FromOle(&HFF) 'Vermelho
									Else
										.Row = .Rows - 1
										.Col = 0
										.ColSel = .Cols - 1
										.CellForeColor = System.Drawing.ColorTranslator.FromOle(&H80000008) 'Normal
									End If
									'UPGRADE_ISSUE: VBControlExtender method mfgAbertas.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
									.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillSingle
									.set_TextMatrix(.Rows - 1, 0, lstrMesAno)
									.set_TextMatrix(.Rows - 1, 1, VB6.Format(ldteVencto, "dd/mm/yyyy"))
									.set_TextMatrix(.Rows - 1, 2, VB6.Format(ldblValor, "Standard"))
									.set_TextMatrix(.Rows - 1, 3, ldblNumNf)
									.set_TextMatrix(.Rows - 1, 4, llngDiasA)
									.set_TextMatrix(.Rows - 1, 5, BuscaSituacaoReaviso(lstrMesAno, ldblNumNf))
									.set_TextMatrix(.Rows - 1, 6, IIf(ldtePPrazo <> CDate("01/01/1900"), VB6.Format(ldtePPrazo, "dd/mm/yyyy"), "__/__/____"))
									.set_TextMatrix(.Rows - 1, 7, PegaNmConsumidor(llngConsId))
									ldblVlrAb = ldblVlrAb + ldblValor
								End With
								Call .MoveNext()
							End While
						End If
						Call .Close()
					End If
				End With
				Me.txtValorAberto.Text = VB6.Format(ldblVlrAb, "Standard")
				With Me.mfgAbertas
					.HighLight = MSFlexGridLib.HighLightSettings.flexHighlightNever
					.Redraw = True
					Me.txtQtdeAberto.Text = CStr(.Rows - 1)
				End With
			Else
				Me.mfgAbertas.Rows = 1
			End If
			'----- Enche Grid: Faturas em reserva ------------------------------------------------------------------
			If gblnUsuario_Faturas_reserva_judice Then
				ldblVlrRe = 0
				With Me.mfgReserva
					.Rows = 1
					.Redraw = False
				End With
				lstrSql = ""
				lstrSql = lstrSql & "  SELECT `nf`.`mesano_ref`, "
				lstrSql = lstrSql & "         `nf`.`datavenc`, "
				lstrSql = lstrSql & "         `nf`.`dataprazo`, "
				lstrSql = lstrSql & "         `nf`.`valortot`, "
				lstrSql = lstrSql & "         `nf`.`numnf`, "
				lstrSql = lstrSql & "         `nf`.`cons_id`, "
				lstrSql = lstrSql & "         `nf`.`unid_id`, "
				lstrSql = lstrSql & "         `nf`.`flgst`, "
				lstrSql = lstrSql & "         `nf`.`flgmedfat`, "
				lstrSql = lstrSql & "         `nf`.`fatura_final`, "
				lstrSql = lstrSql & "         `nf`.`grupo`, "
				lstrSql = lstrSql & "         `nf`.`codclas`, "
				lstrSql = lstrSql & "         `nf`.`zona`, "
				lstrSql = lstrSql & "         `nf`.`livro`, "
				lstrSql = lstrSql & "         `nf`.`conta`, "
				lstrSql = lstrSql & "         `nf`.`datapag`, "
				lstrSql = lstrSql & "         `nf`.`datast`, "
				lstrSql = lstrSql & "         `nf`.`mesano`, "
				lstrSql = lstrSql & "         `nf`.`rota`, "
				lstrSql = lstrSql & "         `nf`.`ta` "
				lstrSql = lstrSql & "    FROM `nf` "
				lstrSql = lstrSql & "   WHERE `nf`.`unid_id`    = " & ilngUnidId
				lstrSql = lstrSql & "     AND `nf`.`flgst`      IN ('R','J') "
				lstrSql = lstrSql & "     AND `nf`.`grupo`      = '" & UCase(istrGrupo) & "' "
				lstrSql = lstrSql & "     AND `nf`.`mesano_ref` <= " & VB6.Format(ldteBase, "yyyyMM") & " "
				lstrSql = lstrSql & "ORDER BY `mesano_ref` DESC "
				If aintQtdeHistorico > 0 Then
					lstrSql = lstrSql & " LIMIT 0, " & aintQtdeHistorico
				End If
				Call Conectar(lstrSql, lrstAux)
				With lrstAux
					If .State > 0 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"'
								lstrMesAno = Trim(IIf(IsDbNull(.Fields("mesano_ref").value), "", .Fields("mesano_ref").value))
								lstrMesAno = VB.Right(lstrMesAno, 2) & "/" & VB.Left(lstrMesAno, 4)
								'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"'
								ldteVencto = CDate(IIf(IsDbNull(.Fields("datavenc").value), "1900-01-01", .Fields("datavenc").value))
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								ldtePPrazo = CDate(IIf(IsDbNull(.Fields("dataprazo").value), "1900-01-01", .Fields("dataprazo").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"'
								ldblValor = CDbl(IIf(IsDbNull(.Fields("valortot").value), 0, .Fields("valortot").value))
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								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"'
								llngConsId = CInt(IIf(IsDbNull(.Fields("cons_id").value), 0, .Fields("cons_id").value))
								'UPGRADE_WARNING: DateDiff behavior may be different. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6B38EC3F-686D-4B2E-B5A5-9E8E7A762E32"'
								llngDiasA = CInt(DateDiff(Microsoft.VisualBasic.DateInterval.Day, ldteVencto, ldteBase))
								If ldtePPrazo <> CDate("01/01/1900") Then
									llngFatPrazAbert = llngFatPrazAbert + 1
								End If
								If llngDiasA < 1 Then llngDiasA = 0
								With Me.mfgReserva
									.Rows = .Rows + 1
									'UPGRADE_ISSUE: VBControlExtender method mfgReserva.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
									.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillRepeat
									If ldtePPrazo > ldteBase Then
										.Row = .Rows - 1
										.Col = 0
										.ColSel = .Cols - 1
										.CellForeColor = System.Drawing.ColorTranslator.FromOle(&HFF0000) 'Azul
									ElseIf ldteVencto < ldteBase Then 
										.Row = .Rows - 1
										.Col = 0
										.ColSel = .Cols - 1
										.CellForeColor = System.Drawing.ColorTranslator.FromOle(&HFF) 'Vermelho
									Else
										.Row = .Rows - 1
										.Col = 0
										.ColSel = .Cols - 1
										.CellForeColor = System.Drawing.ColorTranslator.FromOle(&H80000008) 'Normal
									End If
									'UPGRADE_ISSUE: VBControlExtender method mfgReserva.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
									.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillSingle
									.set_TextMatrix(.Rows - 1, 0, lstrMesAno)
									.set_TextMatrix(.Rows - 1, 1, VB6.Format(ldteVencto, "dd/mm/yyyy"))
									.set_TextMatrix(.Rows - 1, 2, VB6.Format(ldblValor, "Standard"))
									.set_TextMatrix(.Rows - 1, 3, ldblNumNf)
									.set_TextMatrix(.Rows - 1, 4, llngDiasA)
									.set_TextMatrix(.Rows - 1, 5, BuscaSituacaoReaviso(lstrMesAno, ldblNumNf))
									.set_TextMatrix(.Rows - 1, 6, IIf(ldtePPrazo <> CDate("01/01/1900"), VB6.Format(ldtePPrazo, "dd/mm/yyyy"), "__/__/____"))
									.set_TextMatrix(.Rows - 1, 7, PegaNmConsumidor(llngConsId))
									ldblVlrRe = ldblVlrRe + ldblValor
								End With
								Call .MoveNext()
							End While
						End If
						Call .Close()
					End If
				End With
				Me.txtValorReserva.Text = VB6.Format(ldblVlrRe, "Standard")
				With Me.mfgReserva
					.HighLight = MSFlexGridLib.HighLightSettings.flexHighlightNever
					.Redraw = True
					Me.txtQtdeReserva.Text = CStr(.Rows - 1)
				End With
			Else
				Me.mfgReserva.Rows = 1
			End If
			'----- Enche Grid: Últimas Faturas Pagas ---------------------------------------------------------------
			If gblnUsuario_Faturas_pagas Then
				With Me.mfgPagas
					.Rows = 1
					.Redraw = False
				End With
				lstrSql = ""
				lstrSql = lstrSql & "  SELECT `nf`.`mesano_ref`, "
				lstrSql = lstrSql & "         `nf`.`datavenc`, "
				lstrSql = lstrSql & "         `nf`.`dataprazo`, "
				lstrSql = lstrSql & "         `nf`.`banarrec`, "
				lstrSql = lstrSql & "         `nf`.`valortot`, "
				lstrSql = lstrSql & "         `nf`.`numnf`, "
				lstrSql = lstrSql & "         `nf`.`cons_id`, "
				lstrSql = lstrSql & "         `nf`.`unid_id`, "
				lstrSql = lstrSql & "         `nf`.`flgst`, "
				lstrSql = lstrSql & "         `nf`.`flgmedfat`, "
				lstrSql = lstrSql & "         `nf`.`fatura_final`, "
				lstrSql = lstrSql & "         `nf`.`grupo`, "
				lstrSql = lstrSql & "         `nf`.`codclas`, "
				lstrSql = lstrSql & "         `nf`.`zona`, "
				lstrSql = lstrSql & "         `nf`.`livro`, "
				lstrSql = lstrSql & "         `nf`.`conta`, "
				lstrSql = lstrSql & "         `nf`.`datapag`, "
				lstrSql = lstrSql & "         `nf`.`datast`, "
				lstrSql = lstrSql & "         `nf`.`mesano`, "
				lstrSql = lstrSql & "         `nf`.`rota`, "
				lstrSql = lstrSql & "         `nf`.`ta` "
				lstrSql = lstrSql & "    FROM `nf` "
				lstrSql = lstrSql & "   WHERE `nf`.`unid_id` = " & ilngUnidId
				lstrSql = lstrSql & "     AND `nf`.`flgst`   = 'P' "
				lstrSql = lstrSql & "     AND `nf`.`grupo`   = '" & UCase(istrGrupo) & "' "
				lstrSql = lstrSql & "     AND `nf`.`mesano_ref` <= " & VB6.Format(ldteBase, "yyyyMM") & " "
				lstrSql = lstrSql & "ORDER BY `mesano_ref` DESC "
				If aintQtdeHistorico > 0 Then
					lstrSql = lstrSql & " LIMIT 0, " & aintQtdeHistorico
				End If
				Call Conectar(lstrSql, lrstAux)
				With lrstAux
					If .State > 0 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"'
								lstrMesAno = Trim(IIf(IsDbNull(.Fields("mesano_ref").value), "", .Fields("mesano_ref").value))
								lstrMesAno = VB.Right(lstrMesAno, 2) & "/" & VB.Left(lstrMesAno, 4)
								'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"'
								ldteVencto = CDate(IIf(IsDbNull(.Fields("datavenc").value), "1900-01-01", .Fields("datavenc").value))
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								ldtePagnto = CDate(IIf(IsDbNull(.Fields("datapag").value), "1900-01-01", .Fields("datapag").value))
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								ldtePPrazo = CDate(IIf(IsDbNull(.Fields("dataprazo").value), "1900-01-01", .Fields("dataprazo").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"'
								ldblValor = CDbl(IIf(IsDbNull(.Fields("valortot").value), 0, .Fields("valortot").value))
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								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"'
								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"'
								llngBanId = CInt(IIf(IsDbNull(.Fields("banarrec").value), 0, .Fields("banarrec").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"'
								lstrFlgMedFat = Trim(IIf(IsDbNull(.Fields("flgmedfat").value), "N", .Fields("flgmedfat").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"'
								lintFatFinal = IIf(IsDbNull(.Fields("fatura_final").value), "0", .Fields("fatura_final").value)
								If ldtePPrazo <> CDate("01/01/1900") Then
									llngFatPrazPagas = llngFatPrazPagas + 1
								End If
								If ldtePagnto > ldteVencto Then
									llngFatPagAtrazo = llngFatPagAtrazo + 1
								Else
									llngFatPagVecto = llngFatPagVecto + 1
								End If
								With Me.mfgPagas
									.Rows = .Rows + 1
									.set_TextMatrix(.Rows - 1, 0, lstrMesAno)
									.set_TextMatrix(.Rows - 1, 1, VB6.Format(ldteVencto, "dd/mm/yyyy"))
									.set_TextMatrix(.Rows - 1, 2, VB6.Format(ldblValor, "Standard"))
									.set_TextMatrix(.Rows - 1, 3, ldblNumNf)
									.set_TextMatrix(.Rows - 1, 4, VB6.Format(ldtePagnto, "dd/mm/yyyy"))
									.set_TextMatrix(.Rows - 1, 5, BuscaNomeBancos(llngBanId))
									.set_TextMatrix(.Rows - 1, 6, IIf(ldtePPrazo <> CDate("01/01/1900"), VB6.Format(ldtePPrazo, "dd/mm/yyyy"), "__/__/____"))
									.set_TextMatrix(.Rows - 1, 7, PegaNmConsumidor(llngConsId))
								End With
								Call .MoveNext()
							End While
						End If
						Call .Close()
					End If
				End With
				With Me.mfgPagas
					.HighLight = MSFlexGridLib.HighLightSettings.flexHighlightNever
					.Redraw = True
				End With
			Else
				Me.mfgPagas.Rows = 1
			End If
			'----- Enche Grid: Últimos Consumos --------------------------------------------------------------------
			If gblnUsuario_Faturas_ultimos_consumos Then
				With Me.mfgConsumos
					.Rows = 1
					.Redraw = False
				End With
				lstrSql = ""
				lstrSql = lstrSql & "  SELECT `nf`.`mesano_ref`, "
				lstrSql = lstrSql & "         `nf`.`datavenc`, "
				lstrSql = lstrSql & "         `nf`.`dataprazo`, "
				lstrSql = lstrSql & "         `nf`.`dataleit`, "
				lstrSql = lstrSql & "         `nf`.`dataleitant`, "
				lstrSql = lstrSql & "         `nf`.`banarrec`, "
				lstrSql = lstrSql & "         `nf`.`valortot`, "
				lstrSql = lstrSql & "         `nf`.`numnf`, "
				lstrSql = lstrSql & "         `nf`.`cons_id`, "
				lstrSql = lstrSql & "         `nf`.`unid_id`, "
				lstrSql = lstrSql & "         `nf`.`flgst`, "
				lstrSql = lstrSql & "         `nf`.`flgmedfat`, "
				lstrSql = lstrSql & "         `nf`.`fatura_final`, "
				lstrSql = lstrSql & "         `nf`.`grupo`, "
				lstrSql = lstrSql & "         `nf`.`codclas`, "
				lstrSql = lstrSql & "         `nf`.`zona`, "
				lstrSql = lstrSql & "         `nf`.`livro`, "
				lstrSql = lstrSql & "         `nf`.`conta`, "
				lstrSql = lstrSql & "         `nf`.`datapag`, "
				lstrSql = lstrSql & "         `nf`.`datast`, "
				lstrSql = lstrSql & "         `nf`.`mesano`, "
				lstrSql = lstrSql & "         `nf`.`rota`, "
				lstrSql = lstrSql & "         `nf`.`itensserv`, "
				lstrSql = lstrSql & "         `nf`.`ta` "
				lstrSql = lstrSql & "     FROM `nf` "
				lstrSql = lstrSql & "    WHERE `nf`.`unid_id` = " & ilngUnidId
				lstrSql = lstrSql & "      AND `nf`.`grupo`   = '" & UCase(istrGrupo) & "' "
				lstrSql = lstrSql & "      AND `nf`.`mesano_ref` <= " & VB6.Format(ldteBase, "yyyymm") & " "
				lstrSql = lstrSql & " ORDER BY `mesano_ref` DESC "
				If aintQtdeHistorico > 0 Then
					lstrSql = lstrSql & " LIMIT 0, " & aintQtdeHistorico
				End If
				Call Conectar(lstrSql, lrstAux)
				With lrstAux
					If .State > 0 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"'
								lstrGrTar = Trim(IIf(IsDbNull(.Fields("ta").value), "01B100", .Fields("ta").value))
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								lstrMesAno = Trim(IIf(IsDbNull(.Fields("mesano_ref").value), "", .Fields("mesano_ref").value))
								lstrMesAno = VB.Right(lstrMesAno, 2) & "/" & VB.Left(lstrMesAno, 4)
								'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"'
								ldteLeiAtu = CDate(IIf(IsDbNull(.Fields("dataleit").value), "1900-01-01", .Fields("dataleit").value))
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								ldteLeiAnt = CDate(IIf(IsDbNull(.Fields("dataleitant").value), "1900-01-01", .Fields("dataleitant").value))
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								ldblValor = CDbl(IIf(IsDbNull(.Fields("valortot").value), 0, .Fields("valortot").value))
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								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"'
								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"'
								llngBanId = CInt(IIf(IsDbNull(.Fields("banarrec").value), 0, .Fields("banarrec").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))
								'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"'
								lstrFlgst = Trim(IIf(IsDbNull(.Fields("flgst").value), "", .Fields("flgst").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"'
								lstrFlgMedFat = Trim(IIf(IsDbNull(.Fields("flgmedfat").value), "N", .Fields("flgmedfat").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"'
								lintFatFinal = IIf(IsDbNull(.Fields("fatura_final").value), "0", .Fields("fatura_final").value)
								With Me.mfgConsumos
									.Rows = .Rows + 1
									.set_TextMatrix(.Rows - 1, 0, lstrMesAno)
									If UCase(istrGrupo) = "A" Then
										If (Mid(lstrGrTar, 3, 2) = "A4" Or Mid(lstrGrTar, 3, 2) = "AS") Then
											.set_TextMatrix(.Rows - 1, 1, BuscaValorItem(lstrItens, "0302010009"))
											.set_TextMatrix(.Rows - 1, 2, 0)
											.set_TextMatrix(.Rows - 1, 3, Arredondar(BuscaValorItem(lstrItens, "0302010017") + BuscaValorItem(lstrItens, "0302010018")))
											.set_TextMatrix(.Rows - 1, 4, 0)
										Else
											.set_TextMatrix(.Rows - 1, 1, BuscaValorItem(lstrItens, "0302010010"))
											.set_TextMatrix(.Rows - 1, 2, BuscaValorItem(lstrItens, "0302010011"))
											.set_TextMatrix(.Rows - 1, 3, Arredondar(BuscaValorItem(lstrItens, "0302010021") + BuscaValorItem(lstrItens, "0302010022")))
											.set_TextMatrix(.Rows - 1, 4, Arredondar(BuscaValorItem(lstrItens, "0302010025") + BuscaValorItem(lstrItens, "0302010026")))
										End If
										.set_TextMatrix(.Rows - 1, 5, VB6.Format(ldteLeiAtu, "dd/MM/yyyy"))
										.set_TextMatrix(.Rows - 1, 6, BuscaValorItem(lstrItens, "0302990039"))
										.set_TextMatrix(.Rows - 1, 7, BuscaValorItem(lstrItens, "0302990040"))
										If ldteLeiAnt <> CDate("1900-01-01") Then
											'UPGRADE_WARNING: DateDiff behavior may be different. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6B38EC3F-686D-4B2E-B5A5-9E8E7A762E32"'
											.set_TextMatrix(.Rows - 1, 8, DateDiff(Microsoft.VisualBasic.DateInterval.Day, ldteLeiAnt, ldteLeiAtu))
										Else
											.set_TextMatrix(.Rows - 1, 8, 0)
										End If
										.set_TextMatrix(.Rows - 1, 9, ldblNumNf)
										.set_TextMatrix(.Rows - 1, 10, BuscaVlrItem(lstrItens, "0302010009"))
									ElseIf UCase(istrGrupo) = "B" Then 
										.set_TextMatrix(.Rows - 1, 1, BuscaValorItem(lstrItens, "030201008") + BuscaValorItem(lstrItens, "030201018") + BuscaValorItem(lstrItens, "030201028") + BuscaValorItem(lstrItens, "030201038"))
										.set_TextMatrix(.Rows - 1, 2, BuscaValorItem(lstrItens, "030201009") + BuscaValorItem(lstrItens, "030201019") + BuscaValorItem(lstrItens, "030201029") + BuscaValorItem(lstrItens, "030201039"))
										.set_TextMatrix(.Rows - 1, 3, VB6.Format(ldteLeiAtu, "dd/MM/yyyy"))
										.set_TextMatrix(.Rows - 1, 4, BuscaValorItem(lstrItens, "0302990039"))
										.set_TextMatrix(.Rows - 1, 5, BuscaValorItem(lstrItens, "0302990040"))
										If ldteLeiAnt <> CDate("1900-01-01") Then
											'UPGRADE_WARNING: DateDiff behavior may be different. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6B38EC3F-686D-4B2E-B5A5-9E8E7A762E32"'
											.set_TextMatrix(.Rows - 1, 6, DateDiff(Microsoft.VisualBasic.DateInterval.Day, ldteLeiAnt, ldteLeiAtu))
										Else
											.set_TextMatrix(.Rows - 1, 6, 0)
										End If
										.set_TextMatrix(.Rows - 1, 7, ldblNumNf)
										If InStr(1, lstrItens, "90410000") > 0 Then
											.set_TextMatrix(.Rows - 1, 8, VB.Right(Mid(lstrItens, InStr(1, lstrItens, "90410000"), 10), 2))
											ldblMedia = BuscaVlrItem(lstrItens, "90410000")
											.set_TextMatrix(.Rows - 1, 9, BuscaRefItem(lstrItens, "90410000") & IIf(ldblMedia = 1, "(Gera Média)", "(Sem Média)"))
										Else
											.set_TextMatrix(.Rows - 1, 8, "")
											.set_TextMatrix(.Rows - 1, 9, "")
										End If
										.set_TextMatrix(.Rows - 1, 10, IIf(CDbl(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 1)), .get_TextMatrix(.Rows - 1, 1), 0)) < CDbl(IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 2)), .get_TextMatrix(.Rows - 1, 2), 0)), "Custo de disponibilidade", ""))
										If lstrFlgMedFat = "S" Then
											.set_TextMatrix(.Rows - 1, 10, "Re-Faturamento")
										ElseIf lintFatFinal = 1 Then 
											.set_TextMatrix(.Rows - 1, 10, "Fatura Final")
										ElseIf lstrFlgst = "C" Then 
											.set_TextMatrix(.Rows - 1, 10, "Fat.Cancelada")
										End If
									End If
								End With
								Call .MoveNext()
							End While
						End If
						Call .Close()
					End If
				End With
				Me.txtPagasAtrazo.Text = FormatNumber(llngFatPagAtrazo, 0)
				Me.txtPagasVecto.Text = FormatNumber(llngFatPagVecto, 0)
				Me.txtTotalPagas.Text = FormatNumber(llngFatPagAtrazo + llngFatPagVecto, 0)
				
				Me.txtPrazoAbertas.Text = FormatNumber(llngFatPrazAbert, 0)
				Me.txtPrazoPagas.Text = FormatNumber(llngFatPrazPagas, 0)
				Me.txtTotalPedPrazos.Text = FormatNumber(llngFatPrazAbert + llngFatPrazPagas, 0)
				
				With Me.mfgConsumos
					.HighLight = MSFlexGridLib.HighLightSettings.flexHighlightNever
					.Redraw = True
				End With
				With Me.cmbMeses
					If Me.mfgConsumos.Rows > 1 Then
						Call .Items.Clear()
						For llngLinha = 1 To Me.mfgConsumos.Rows - 1
							Call .Items.Add(CStr(llngLinha))
						Next llngLinha
						If .Items.Count > 12 Then
							.SelectedIndex = 11
						Else
							.SelectedIndex = .Items.Count - 1
						End If
						Call cmbMeses_SelectedIndexChanged(cmbMeses, New System.EventArgs())
					Else
						Call .Items.Add(CStr(1))
						.SelectedIndex = 0
					End If
				End With
			End If
		End If
		System.Windows.Forms.Application.DoEvents()
		'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 lrstAgr 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"'
		lrstAgr = Nothing
		'Call EncheGridSS(aintQtdeHistorico)
		'Call EncheGridRC(aintQtdeHistorico)
		
		Me.txtAviso.Text = IIf(Len(Trim(Me.txtObsUc.Text)) > 0, Me.txtObsUc.Text, Me.txtObsCons.Text)
		If lstrEstufa = "S" Then
			Me.txtAviso.Text = Me.txtAviso.Text & IIf(Len(Trim(Me.txtAviso.Text)) > 0, " - ", "") & "Possui ESTUFA"
		End If
		llngQtdSus = BuscaQtdeSuspensao(llngConsId, alngUnidId, 3)
		If llngQtdSus >= 3 Then
			Me.txtAviso.Text = Me.txtAviso.Text & IIf(Len(Trim(Me.txtAviso.Text)) > 0, " - ", "") & "*** +Inadimplente ***"
		End If
		Me.txtAviso.Visible = (Len(Trim(Me.txtAviso.Text)) > 0)
		Me.Cursor = System.Windows.Forms.Cursors.Default
		Me.fmeAguarde.Enabled = False
		Me.fmeAguarde.Visible = False
		
		BuscaUnidadeConsumidora = (ilngUnidId > 0)
	End Function
	
	'[ Função retornar o nome da classe ]
	Private Function BuscaNomeClasse(ByVal astrCodigo As String) As String
		Dim lstrDesc As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrSql = ""
		lstrSql = lstrSql & "SELECT `descricao` "
		lstrSql = lstrSql & "  FROM `classe` "
		lstrSql = lstrSql & " WHERE `codigo` = '" & astrCodigo & "' "
		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"'
					lstrDesc = IIf(IsDbNull(.Fields("descricao").value), "", .Fields("descricao").value)
				Else
					lstrDesc = "Classe não encontrada!"
				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
		BuscaNomeClasse = lstrDesc
	End Function
	
	Private Sub BuscaNomeCNAE(ByVal alndIdCnae As Integer)
		Dim lstrDes As String
		Dim lstrCod As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		If alndIdCnae > 0 Then
			lstrSql = ""
			lstrSql = lstrSql & "SELECT * "
			lstrSql = lstrSql & "  FROM `cnae` "
			lstrSql = lstrSql & " WHERE `id` = " & alndIdCnae & " "
			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"'
						lstrDes = Trim(IIf(IsDbNull(.Fields("descricao").value), "", .Fields("descricao").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"'
						lstrCod = Trim(IIf(IsDbNull(.Fields("codigo").value), "", .Fields("codigo").value))
						Me.txtCdCane.Text = lstrCod
						Me.txtDescrCnae.Text = lstrDes
					Else
						Me.txtCdCane.Text = ""
						Me.txtDescrCnae.Text = ""
					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
	
	'[OK]
	Private Sub cmdCarga_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCarga.Click
		If UCase(istrGrupo) = "A" Then
			Call MsgBox("Não se aplica às unidades consumidoras do grupo A.", MsgBoxStyle.Information, gstrTituloMensagem)
		ElseIf UCase(istrGrupo) = "B" Then 
			Call ifrmCargaInstalada.Show()
			Call ifrmCargaInstalada.SetaCarga(Mid(Me.txtIdent.Text, 1, 3), Mid(Me.txtIdent.Text, 5, 2), Mid(Me.txtIdent.Text, 8), Me.txtNomeU.Text, ilngUnidId, UCase(istrGrupo), Me)
		End If
	End Sub
	
	'[OK]
	Public Sub AtualizaCargaInstalada(ByVal alngUnidId As Integer, ByVal adblCarga As Double, ByVal ablnGravou As Boolean)
		Dim lstrSql As String
		If ablnGravou Then
			Me.txtCargaU.Text = CStr(adblCarga)
			lstrSql = ""
			lstrSql = lstrSql & "UPDATE `unid" & LCase(istrGrupo) & "` "
			lstrSql = lstrSql & "   SET `carga`   = " & adblCarga & " "
			lstrSql = lstrSql & " WHERE `unid_id` = " & alngUnidId & " "
			Call Executar(lstrSql)
		End If
	End Sub
	
	'UPGRADE_ISSUE: Frame event fmeBotoes.MouseMove was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="ABD9AF39-7E24-4AFF-AD8D-3675C1AA3054"'
	Private Sub fmeBotoes_MouseMove(ByRef Button As Short, ByRef Shift As Short, ByRef X As Single, ByRef Y As Single)
		labelStatus.Text = ""
	End Sub
	
	Private Sub frmArrec_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
		If UCase(istrGrupo) = "A" Then
			FrmAtPrincipal.mnuAtendimentoComercial_GrupoA.Enabled = True
		Else
			FrmAtPrincipal.mnuAtendimentoComercial_GrupoB.Enabled = True
		End If
		If irstRegUnid.State = ADODB.ObjectStateEnum.adStateOpen Then Call irstRegUnid.Close()
		If irstRegCons.State = ADODB.ObjectStateEnum.adStateOpen Then Call irstRegCons.Close()
		'UPGRADE_NOTE: Object irstRegUnid 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"'
		irstRegUnid = Nothing
		'UPGRADE_NOTE: Object irstRegCons 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"'
		irstRegCons = Nothing
		'UPGRADE_NOTE: Object ifrmLocalizaUnidade 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"'
		ifrmLocalizaUnidade = Nothing
		'UPGRADE_NOTE: Object ifrmCargaInstalada 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"'
		ifrmCargaInstalada = Nothing
		'UPGRADE_NOTE: Object ifrmCadNis 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"'
		ifrmCadNis = Nothing
		'UPGRADE_NOTE: Object ifrmPreencherEnde 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"'
		ifrmPreencherEnde = Nothing
		'UPGRADE_NOTE: Object ifrmReclam 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"'
		ifrmReclam = Nothing
		'UPGRADE_NOTE: Object ifrmImpFaturas 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"'
		ifrmImpFaturas = Nothing
	End Sub
	
	'[ OK ]
	Private Sub mfgConsumos_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mfgConsumos.ClickEvent
		If mfgConsumos.Rows > 1 Then mfgConsumos.HighLight = MSFlexGridLib.HighLightSettings.flexHighlightAlways
	End Sub
	
	'[ OK ]
	Private Sub mfgConsumos_SelChange(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mfgConsumos.SelChange
		If UCase(istrGrupo) = "B" Then
			If Len(Trim(mfgConsumos.get_TextMatrix(mfgConsumos.RowSel, 8))) > 0 Then
				Me.lblOcorrencia.Text = mfgConsumos.get_TextMatrix(mfgConsumos.RowSel, 8) & " - " & mfgConsumos.get_TextMatrix(mfgConsumos.RowSel, 9)
			Else
				Me.lblOcorrencia.Text = "Leitura Normal"
			End If
		End If
	End Sub
	
	'[ OK ]
	Private Sub mfgAbertas_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mfgAbertas.ClickEvent
		If mfgAbertas.Rows > 1 Then mfgAbertas.HighLight = MSFlexGridLib.HighLightSettings.flexHighlightAlways
	End Sub
	
	'[ OK ]
	Private Sub mfgAbertas_DblClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mfgAbertas.DblClick
		With Me.mfgAbertas
			If .Rows > 1 Then
				.Enabled = False
				Me.fmeBotoes.Enabled = False
				Me.fmeFaturas.Visible = (gblnUsuario_Faturas_demonstrativo Or gblnUsuario_Faturas_segunda_via Or gblnUsuario_Faturas_pedido_prazo)
				Me.optDemon.Enabled = gblnUsuario_Faturas_demonstrativo
				Me.optVia2.Enabled = gblnUsuario_Faturas_segunda_via
				Me.optpPrz.Enabled = gblnUsuario_Faturas_pedido_prazo
				Me.optEstornar.Enabled = False
				Me.cmdExecutar.Enabled = (gblnUsuario_Faturas_demonstrativo Or gblnUsuario_Faturas_segunda_via Or gblnUsuario_Faturas_pedido_prazo)
				Me.optVia2.Checked = True
				If Me.fmeFaturas.Visible Then Call encheInfosFat(.get_TextMatrix(.Row, 0), CDbl(.get_TextMatrix(.Row, 3)))
				If Not Me.fmeFaturas.Visible Then Call cmdFecharImp_Click(cmdFecharImp, New System.EventArgs())
			End If
		End With
	End Sub
	
	'[ OK ]
	Private Sub mfgReserva_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mfgReserva.ClickEvent
		If mfgReserva.Rows > 1 Then mfgReserva.HighLight = MSFlexGridLib.HighLightSettings.flexHighlightAlways
	End Sub
	
	'[ OK ]
	Private Sub mfgReserva_DblClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mfgReserva.DblClick
		With Me.mfgReserva
			If .Rows > 1 Then
				.Enabled = False
				Me.fmeBotoes.Enabled = False
				Me.fmeFaturas.Visible = (gblnUsuario_Faturas_demonstrativo Or gblnUsuario_Faturas_segunda_via Or gblnUsuario_Faturas_pedido_prazo)
				Me.optDemon.Enabled = gblnUsuario_Faturas_demonstrativo
				Me.optVia2.Enabled = gblnUsuario_Faturas_segunda_via
				Me.optpPrz.Enabled = gblnUsuario_Faturas_pedido_prazo
				Me.optEstornar.Enabled = False
				Me.cmdExecutar.Enabled = (gblnUsuario_Faturas_demonstrativo Or gblnUsuario_Faturas_segunda_via Or gblnUsuario_Faturas_pedido_prazo)
				Me.optVia2.Checked = True
				If Me.fmeFaturas.Visible Then Call encheInfosFat(.get_TextMatrix(.Row, 0), CDbl(.get_TextMatrix(.Row, 3)))
				If Not Me.fmeFaturas.Visible Then Call cmdFecharImp_Click(cmdFecharImp, New System.EventArgs())
			End If
		End With
	End Sub
	
	'[ OK ]
	Private Sub mfgPagas_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mfgPagas.ClickEvent
		If mfgPagas.Rows > 1 Then mfgPagas.HighLight = MSFlexGridLib.HighLightSettings.flexHighlightAlways
	End Sub
	
	'[ OK ]
	Private Sub mfgPagas_DblClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mfgPagas.DblClick
		With Me.mfgPagas
			If .Rows > 1 Then
				.Enabled = False
				Me.fmeBotoes.Enabled = False
				Me.fmeFaturas.Visible = (gblnUsuario_Faturas_demonstrativo Or gblnUsuario_Faturas_segunda_via Or gblnUsuario_Faturas_pedido_prazo)
				Me.optDemon.Enabled = gblnUsuario_Faturas_demonstrativo
				Me.optVia2.Enabled = False
				Me.optpPrz.Enabled = False
				Me.optEstornar.Enabled = True
				Me.cmdExecutar.Enabled = gblnUsuario_Faturas_demonstrativo
				Me.optDemon.Checked = True
				If Me.fmeFaturas.Visible Then Call encheInfosFat(.get_TextMatrix(.Row, 0), CDbl(.get_TextMatrix(.Row, 3)))
				If Not Me.fmeFaturas.Visible Then Call cmdFecharImp_Click(cmdFecharImp, New System.EventArgs())
			End If
		End With
	End Sub
	
	'[ OK ]
	Private Function encheInfosFat(ByVal astrMesAno As String, ByVal adblNumNf As Double) As Object
		Dim ldteVecto As Date
		Dim ldtePagto As Date
		Dim ldteApres As Date
		Dim ldtePPrazo As Date
		Dim lstrItens As String
		Dim lstrClass As String
		Dim ldblValor As Double
		Dim ldblVlrLq As Double
		Dim llngBanId As Integer
		
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		With Me.mfgFaturas
			.Rows = 1
			.Redraw = False
		End With
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM `nf` "
		lstrSql = lstrSql & " WHERE `nf`.`mesano` = '" & astrMesAno & "' "
		lstrSql = lstrSql & "   AND `nf`.`numnf`  = " & adblNumNf
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State > 0 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"'
						ldteVecto = CDate(IIf(IsDbNull(.Fields("datavenc").value), "1900-01-01", .Fields("datavenc").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldtePagto = CDate(IIf(IsDbNull(.Fields("datapag").value), "1900-01-01", .Fields("datapag").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldteApres = CDate(IIf(IsDbNull(.Fields("dataapr").value), "1900-01-01", .Fields("dataapr").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldtePPrazo = CDate(IIf(IsDbNull(.Fields("dataprazo").value), "1900-01-01", .Fields("dataprazo").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))
						'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"'
						lstrClass = Trim(IIf(IsDbNull(.Fields("codclas").value), "", .Fields("codclas").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldblValor = CDbl(IIf(IsDbNull(.Fields("valortot").value), 0, .Fields("valortot").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldblVlrLq = CDbl(IIf(IsDbNull(.Fields("valorliq").value), 0, .Fields("valorliq").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						llngBanId = CInt(IIf(IsDbNull(.Fields("banarrec").value), 0, .Fields("banarrec").value))
						If ldblVlrLq > 0 And ldblVlrLq <> ldblValor Then ldblValor = ldblVlrLq
						With Me.mfgFaturas
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, VB6.Format(ldteVecto, "dd/mm/yyyy"))
							.set_TextMatrix(.Rows - 1, 1, VB6.Format(ldteApres, "dd/mm/yyyy"))
							.set_TextMatrix(.Rows - 1, 2, BuscaVlrItem(lstrItens, "0302040005"))
							.set_TextMatrix(.Rows - 1, 3, BuscaVlrItem(lstrItens, "0302040004"))
							.set_TextMatrix(.Rows - 1, 4, BuscaVlrItem(lstrItens, "0302030009"))
							.set_TextMatrix(.Rows - 1, 5, BuscaVlrItem(lstrItens, "0302030002"))
							.set_TextMatrix(.Rows - 1, 6, BuscaVlrItem(lstrItens, "0302990011"))
							.set_TextMatrix(.Rows - 1, 7, BuscaVlrItem(lstrItens, "0302990007"))
							.set_TextMatrix(.Rows - 1, 8, BuscaVlrItem(lstrItens, "0302010006"))
							.set_TextMatrix(.Rows - 1, 9, BuscaVlrItem(lstrItens, "0302990006"))
							.set_TextMatrix(.Rows - 1, 10, lstrClass)
							.set_TextMatrix(.Rows - 1, 11, VB6.Format(ldblValor, "Standard"))
							.set_TextMatrix(.Rows - 1, 12, BuscaVlrItem(lstrItens, "0302990002"))
							.set_TextMatrix(.Rows - 1, 13, VB6.Format(ldtePagto, "dd/mm/yyyy"))
							.set_TextMatrix(.Rows - 1, 14, llngBanId)
							.set_TextMatrix(.Rows - 1, 15, adblNumNf)
							.set_TextMatrix(.Rows - 1, 16, astrMesAno)
							.set_TextMatrix(.Rows - 1, 17, IIf(ldtePPrazo <> CDate("01/01/1900"), VB6.Format(ldtePPrazo, "dd/mm/yyyy"), ""))
						End With
						Call .MoveNext()
					End While
				End If
				Call .Close()
			End If
		End With
		Me.mfgFaturas.Redraw = True
		'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
	
	'[ OK ]
	Public Function CabecaRel() As Object
		Dim lstrTable As String
		With ifrmExtrato
			.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
			.VS.BrushColor = System.Drawing.Color.White
			Call Cabecalho_Relatorio(.VS, "EXTRATO CONSUMIDOR", "", "2")
			.VS.ShowGuides = VSVIEW6.ShowGuideSettings.gdHide
			.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
			.VS.BrushColor = System.Drawing.Color.White
			.VS.Font = VB6.FontChangeSize(.VS.Font, 9)
			'.VS.BrushColor = &HFFFFFF
			Call .VS.DrawRectangle("10mm", "33mm", "195mm", "72mm")
			'UPGRADE_ISSUE: VBControlExtender method ifrmExtrato.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 = "35mm"
			lstrTable = ""
			lstrTable = lstrTable & ">5mm|<80mm|>40mm|>40mm;"
			lstrTable = lstrTable & "|Identificador: " & Me.txtIdent.Text
			lstrTable = lstrTable & "|Setor/Seq: " & Mid(Me.txtRota.Text, 1, 4) & "/" & Mid(Me.txtRota.Text, 6, 4)
			lstrTable = lstrTable & "|Situação: " & IIf(Len(Trim(Me.txtSituacao.Text)) = 0, "LIGADO", Me.txtSituacao.Text)
			.VS.Table = lstrTable
			lstrTable = ">5mm|<180mm;|Consumidor: " & VB.Left(Me.txtNomeU.Text, 85)
			.VS.Table = lstrTable
			lstrTable = ""
			lstrTable = lstrTable & ">5mm|<60mm|<60mm;"
			lstrTable = lstrTable & "|CPF/CNPJ: " & Me.txtCpfCnpjU.Text
			lstrTable = lstrTable & "|RG/IE.: " & IIf(Len(Trim(Me.txtRgU.Text)) > 0, Me.txtRgU.Text, Me.txtInscU.Text)
			.VS.Table = lstrTable
			lstrTable = ""
			lstrTable = lstrTable & ">5mm|<180mm;"
			lstrTable = lstrTable & "|Endereço: " & VB.Left(Trim(Me.txtEndU.Text), 60) & VB.Left(IIf(Len(Trim(Me.txtNumeroU.Text)) > 0, ", " & Me.txtNumeroU.Text, ""), 10)
			.VS.Table = lstrTable
			lstrTable = ""
			lstrTable = lstrTable & ">5mm|<200mm;"
			lstrTable = lstrTable & "|Complemento: " & VB.Left(Trim(Me.txtComplementoU.Text), 90)
			.VS.Table = lstrTable
			lstrTable = ""
			lstrTable = lstrTable & ">5mm|<200mm;"
			lstrTable = lstrTable & "|Bairro: " & VB.Left(Me.txtBairroU.Text, 60)
			.VS.Table = lstrTable
			lstrTable = ""
			lstrTable = lstrTable & ">5mm|<130mm|<28mm;"
			lstrTable = lstrTable & "|Cidade: " & VB.Left(Me.txtCidadeU.Text, 60)
			lstrTable = lstrTable & "|CEP: " & Me.txtCepU.Text
			.VS.Table = lstrTable
			lstrTable = ""
			lstrTable = lstrTable & ">5mm|<130mm|<28mm;"
			lstrTable = lstrTable & "|Distrito: " & VB.Left(Me.txtDistritoU.Text, 60)
			lstrTable = lstrTable & "|UF: " & Me.txtUfU.Text
			.VS.Table = lstrTable
			lstrTable = ""
			lstrTable = lstrTable & ">5mm|<90mm|<70mm;"
			lstrTable = lstrTable & "|Classe: " & VB.Left(Me.txtClasse.Text & " - " & Me.txtDescrClasse.Text, 38)
			lstrTable = lstrTable & "|Banco: " & Me.txtBanco.Text
			.VS.Table = lstrTable
			lstrTable = ""
			lstrTable = lstrTable & ">5mm|<40mm|<100mm|<40mm;"
			lstrTable = lstrTable & "|Medidor: " & Me.txtMedkWh.Text
			lstrTable = lstrTable & "|Constante: "
			If VB.Left(Me.txtTarifa.Text, 1) = "B" Then
				lstrTable = lstrTable & Me.txtGBConstante.Text
			Else
				If VB.Left(Me.txtTarifa.Text, 2) = "A4" Or VB.Left(Me.txtTarifa.Text, 2) = "AS" Then
					lstrTable = lstrTable & Me.txtGACConstkWh.Text
				ElseIf VB.Left(Me.txtTarifa.Text, 2) = "AA" Or VB.Left(Me.txtTarifa.Text, 2) = "AV" Or VB.Left(Me.txtTarifa.Text, 2) = "AL" Then 
					lstrTable = lstrTable & " ponta: " & Me.txtGAHConstkWhP.Text & " - fora ponta: " & Me.txtGAHConstkWhFP.Text
				End If
			End If
			lstrTable = lstrTable & "|Fase: " & Trim(Me.txtFase.Text)
			.VS.Table = lstrTable
			.VS.Font = VB6.FontChangeSize(.VS.Font, 7)
			Call LineFeed(.VS, 1)
			.VS.TableBorder = VSVIEW6.TableBorderSettings.tbAll
			If Len(istrCabec) > 0 Then
				.VS.Font = VB6.FontChangeBold(.VS.Font, True)
				.VS.Table = "^185mm;" & istrCabec
				.VS.Table = istrTamCl & istrSubCb
				.VS.Font = VB6.FontChangeBold(.VS.Font, False)
			End If
		End With
	End Function
	
	'[OK]
	Private Function MontaExtrato(ByVal aintCompleto As Short) As Object
		Dim llngLinha As Integer
		Dim llngLiTot As Integer
		Dim lstrTable As String
		Dim ldblTotFt As Double
		Dim llngPagin As Integer
		Dim lstrAbert As String
		Dim lstrReser As String
		Dim lstrFatPg As String
		Dim lstrConsu As String
		Dim lstrTamAb As String
		Dim lstrTamRe As String
		Dim lstrTamPg As String
		Dim lstrTamCo As String
		Dim lstrCabAb As String
		Dim lstrCabRe As String
		Dim lstrCabPg As String
		Dim lstrCabCo As String
		lstrAbert = "Faturas em Aberto"
		lstrReser = "Faturas em Reserva/Judice"
		lstrFatPg = "Ultimas Faturas Pagas"
		lstrConsu = "Ultimos Consumos Faturados"
		lstrTamAb = "^25mm|^30mm|>37mm|1mm|^25mm|^30mm|>37mm;"
		lstrTamRe = "^25mm|^30mm|>37mm|1mm|^25mm|^30mm|>37mm;"
		lstrTamPg = "^13mm|^15mm|^15mm|>15mm|<34mm|<1mm|^13mm|^15mm|^15mm|>15mm|<34mm;"
		lstrCabAb = "Mês/Ano|Vencimento|Valor (R$)||Mês/Ano|Vencimento|Valor (R$)"
		lstrCabRe = "Mês/Ano|Vencimento|Valor (R$)||Mês/Ano|Vencimento|Valor (R$)"
		lstrCabPg = "Mês/Ano|Pagto.|Vecto.|Valor (R$)|Banco||Mês/Ano|Pagto.|Vecto.|Valor (R$)|Banco"
		If UCase(istrGrupo) = "B" Then
			lstrTamCo = "^13mm|>15mm|>14mm|<50mm|<1mm|^13mm|>15mm|>14mm|<50mm;"
			lstrCabCo = "Mês/Ano|Leitura|Consumo|Ocorrência||Mês/Ano|Leitura|Consumo|Ocorrência"
		Else
			lstrTamCo = "^13mm|>20mm|>20mm|>20mm|>19mm|<1mm|^13mm|>20mm|>20mm|>20mm|>19mm;"
			lstrCabCo = "Mês/Ano|kWh p|kWh fp|kW p |kW fp||Mês/Ano|kWh p|kWh fp|kW p|kW fp"
		End If
		istrTamCl = lstrTamAb
		istrCabec = lstrAbert
		istrSubCb = lstrCabAb
		ifrmExtrato = New FrmRelatorio
		With ifrmExtrato
			.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.orPortrait
			.VS.PhysicalPage = True
			.VS.PaperSize = VSVIEW6.PaperSizeSettings.pprA4
			.VS.MarginTop = "7mm"
			.VS.MarginRight = "7mm"
			.VS.MarginLeft = "10mm"
			.VS.MarginBottom = "5mm"
			.VS.TextColor = System.Drawing.Color.Black
			.VS.BrushStyle = VSVIEW6.BrushStyleSettings.bsSolid
			.VS.Font = VB6.FontChangeBold(.VS.Font, False)
			.VS.StartDoc()
			llngPagin = .VS.PageCount
			.VS.Font = VB6.FontChangeSize(.VS.Font, 7)
			'###### FATURAS EM ABERTO ############
			If aintCompleto = 1 Then
				llngLiTot = (Me.mfgAbertas.Rows - 1)
			Else
				llngLiTot = IIf((Me.mfgAbertas.Rows - 1) > 36, 36, (Me.mfgAbertas.Rows - 1))
			End If
			If llngLiTot > 0 Then
				If llngPagin <> .VS.PageCount Or istrCabec <> lstrAbert Then
					istrCabec = lstrAbert
					.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
					Call LineFeed(.VS, 1)
					.VS.TableBorder = VSVIEW6.TableBorderSettings.tbAll
					.VS.Font = VB6.FontChangeBold(.VS.Font, True)
					.VS.Table = "^185mm;" & istrCabec
					istrTamCl = lstrTamAb
					istrSubCb = lstrCabAb
					.VS.Table = istrTamCl & istrSubCb
					.VS.Font = VB6.FontChangeBold(.VS.Font, False)
					llngPagin = .VS.PageCount
				End If
				ldblTotFt = 0
				With Me.mfgAbertas
					For llngLinha = 1 To llngLiTot Step 2
						lstrTable = ""
						lstrTable = lstrTable & .get_TextMatrix(llngLinha, 0) & "|" 'mesano
						lstrTable = lstrTable & VB6.Format(.get_TextMatrix(llngLinha, 1), "dd/mm/yyyy") & "|" 'data vencimento
						lstrTable = lstrTable & VB6.Format(.get_TextMatrix(llngLinha, 2), "Standard") 'valor
						ldblTotFt = ldblTotFt + CDbl(.get_TextMatrix(llngLinha, 2))
						If llngLinha < llngLiTot Then
							lstrTable = lstrTable & "||"
							lstrTable = lstrTable & .get_TextMatrix(llngLinha + 1, 0) & "|" 'mesano
							lstrTable = lstrTable & VB6.Format(.get_TextMatrix(llngLinha + 1, 1), "dd/mm/yyyy") & "|" 'data vencimento
							lstrTable = lstrTable & VB6.Format(.get_TextMatrix(llngLinha + 1, 2), "Standard") 'valor
							ldblTotFt = ldblTotFt + CDbl(.get_TextMatrix(llngLinha + 1, 2))
						End If
						ifrmExtrato.VS.Table = istrTamCl & lstrTable
					Next llngLinha
				End With
			End If
			.VS.Table = ">55mm|^63mm|<67mm;Total do Debito:|" & llngLiTot & " Fatura(s)|R$ " & VB6.Format(ldblTotFt, "Standard")
			'###### FATURAS EM RESEVA/JUDICE ############
			.VS.Font = VB6.FontChangeSize(.VS.Font, 7)
			If aintCompleto = 1 Then
				llngLiTot = (Me.mfgReserva.Rows - 1)
			Else
				llngLiTot = IIf((Me.mfgReserva.Rows - 1) > 36, 36, (Me.mfgReserva.Rows - 1))
			End If
			If llngLiTot > 0 Then
				If llngPagin <> .VS.PageCount Or istrCabec <> lstrReser Then
					istrCabec = lstrReser
					.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
					Call LineFeed(.VS, 1)
					.VS.TableBorder = VSVIEW6.TableBorderSettings.tbAll
					.VS.Font = VB6.FontChangeBold(.VS.Font, True)
					.VS.Table = "^185mm;" & istrCabec
					istrTamCl = lstrTamRe
					istrSubCb = lstrCabRe
					.VS.Table = istrTamCl & istrSubCb
					.VS.Font = VB6.FontChangeBold(.VS.Font, False)
					llngPagin = .VS.PageCount
				End If
				ldblTotFt = 0
				With Me.mfgReserva
					For llngLinha = 1 To llngLiTot Step 2
						lstrTable = ""
						lstrTable = lstrTable & .get_TextMatrix(llngLinha, 0) & "|" 'mesano
						lstrTable = lstrTable & VB6.Format(.get_TextMatrix(llngLinha, 1), "dd/mm/yyyy") & "|" 'data vencimento
						lstrTable = lstrTable & VB6.Format(.get_TextMatrix(llngLinha, 2), "Standard") 'valor
						ldblTotFt = ldblTotFt + CDbl(.get_TextMatrix(llngLinha, 2))
						If llngLinha < llngLiTot Then
							lstrTable = lstrTable & "||"
							lstrTable = lstrTable & .get_TextMatrix(llngLinha + 1, 0) & "|" 'mesano
							lstrTable = lstrTable & VB6.Format(.get_TextMatrix(llngLinha + 1, 1), "dd/mm/yyyy") & "|" 'data vencimento
							lstrTable = lstrTable & VB6.Format(.get_TextMatrix(llngLinha + 1, 2), "Standard") 'valor
							ldblTotFt = ldblTotFt + CDbl(.get_TextMatrix(llngLinha + 1, 2))
						End If
						ifrmExtrato.VS.Table = istrTamCl & lstrTable
					Next llngLinha
				End With
				.VS.Table = ">55mm|^63mm|<67mm;Total do Debito:|" & llngLiTot & " Fatura(s)|R$ " & VB6.Format(ldblTotFt, "Standard")
			End If
			.VS.Font = VB6.FontChangeSize(.VS.Font, 7)
			'##### FATURAS PAGAS #####################################################################################
			If aintCompleto = 1 Then
				llngLiTot = (Me.mfgPagas.Rows - 1)
			Else
				llngLiTot = IIf((Me.mfgPagas.Rows - 1) > 36, 36, (Me.mfgPagas.Rows - 1))
			End If
			If llngLiTot > 0 Then
				If llngPagin <> .VS.PageCount Or istrCabec <> lstrFatPg Then
					istrCabec = lstrFatPg
					.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
					Call LineFeed(.VS, 1)
					.VS.TableBorder = VSVIEW6.TableBorderSettings.tbAll
					.VS.Font = VB6.FontChangeBold(.VS.Font, True)
					.VS.Table = "^185mm;" & istrCabec
					istrTamCl = lstrTamPg
					istrSubCb = lstrCabPg
					.VS.Table = istrTamCl & istrSubCb
					.VS.Font = VB6.FontChangeBold(.VS.Font, False)
					llngPagin = .VS.PageCount
				End If
				ldblTotFt = 0
				With Me.mfgPagas
					For llngLinha = 1 To llngLiTot Step 2
						lstrTable = ""
						lstrTable = lstrTable & .get_TextMatrix(llngLinha, 0) & "|" 'mesano
						lstrTable = lstrTable & VB6.Format(.get_TextMatrix(llngLinha, 4), "dd/mm/yyyy") & "|" 'pagto
						lstrTable = lstrTable & VB6.Format(.get_TextMatrix(llngLinha, 1), "dd/mm/yyyy") & "|" 'vecto
						lstrTable = lstrTable & VB6.Format(.get_TextMatrix(llngLinha, 2), "Standard") & "|" 'valor
						lstrTable = lstrTable & VB.Left(.get_TextMatrix(llngLinha, 5), 22) 'banco
						If llngLinha < llngLiTot Then
							lstrTable = lstrTable & "||"
							lstrTable = lstrTable & .get_TextMatrix(llngLinha + 1, 0) & "|" 'mesano
							lstrTable = lstrTable & VB6.Format(.get_TextMatrix(llngLinha + 1, 4), "dd/mm/yyyy") & "|" 'pagto
							lstrTable = lstrTable & VB6.Format(.get_TextMatrix(llngLinha + 1, 1), "dd/mm/yyyy") & "|" 'vecto
							lstrTable = lstrTable & VB6.Format(.get_TextMatrix(llngLinha + 1, 2), "Standard") & "|" 'valor
							lstrTable = lstrTable & VB.Left(.get_TextMatrix(llngLinha + 1, 5), 22) 'banco
						End If
						ifrmExtrato.VS.Table = istrTamCl & lstrTable
					Next llngLinha
				End With
			End If
			.VS.Font = VB6.FontChangeSize(.VS.Font, 7)
			'##### ULTIMO CONSUMOS ###################################################################################
			If aintCompleto = 1 Then
				llngLiTot = (Me.mfgConsumos.Rows - 1)
			Else
				llngLiTot = IIf((Me.mfgConsumos.Rows - 1) > CDbl(VB6.GetItemString(Me.cmbMeses, Me.cmbMeses.SelectedIndex)), VB6.GetItemString(Me.cmbMeses, Me.cmbMeses.SelectedIndex), (Me.mfgConsumos.Rows - 1))
			End If
			If llngLiTot > 0 Then
				If llngPagin <> .VS.PageCount Or istrCabec <> lstrConsu Then
					istrCabec = lstrConsu
					.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
					Call LineFeed(.VS, 1)
					.VS.TableBorder = VSVIEW6.TableBorderSettings.tbAll
					.VS.Font = VB6.FontChangeBold(.VS.Font, True)
					.VS.Table = "^185mm;" & istrCabec
					istrTamCl = lstrTamCo
					istrSubCb = lstrCabCo
					.VS.Table = istrTamCl & istrSubCb
					.VS.Font = VB6.FontChangeBold(.VS.Font, False)
					llngPagin = .VS.PageCount
				End If
				With Me.mfgConsumos
					For llngLinha = 1 To llngLiTot Step 2
						lstrTable = ""
						lstrTable = lstrTable & .get_TextMatrix(llngLinha, 0) & "|" 'mesano
						If UCase(istrGrupo) = "B" Then
							lstrTable = lstrTable & .get_TextMatrix(llngLinha, 4) & "|" 'leitura
							lstrTable = lstrTable & .get_TextMatrix(llngLinha, 1) & "|" 'consumo
							lstrTable = lstrTable & .get_TextMatrix(llngLinha, 9) 'ocorrencia
						Else
							lstrTable = lstrTable & .get_TextMatrix(llngLinha, 1) & "|" 'kwh_P
							lstrTable = lstrTable & .get_TextMatrix(llngLinha, 2) & "|" 'kwh_FP
							lstrTable = lstrTable & .get_TextMatrix(llngLinha, 3) & "|" 'kw_P
							lstrTable = lstrTable & .get_TextMatrix(llngLinha, 4) 'kw_FP
						End If
						If llngLinha < llngLiTot Then
							lstrTable = lstrTable & "||"
							lstrTable = lstrTable & .get_TextMatrix(llngLinha + 1, 0) & "|" 'mesano
							If UCase(istrGrupo) = "B" Then
								lstrTable = lstrTable & .get_TextMatrix(llngLinha + 1, 4) & "|" 'leitura
								lstrTable = lstrTable & .get_TextMatrix(llngLinha + 1, 1) & "|" 'consumo
								lstrTable = lstrTable & .get_TextMatrix(llngLinha + 1, 9) 'ocorrencia
							Else
								lstrTable = lstrTable & .get_TextMatrix(llngLinha + 1, 1) & "|" 'kwh_P
								lstrTable = lstrTable & .get_TextMatrix(llngLinha + 1, 2) & "|" 'kwh_FP
								lstrTable = lstrTable & .get_TextMatrix(llngLinha + 1, 3) & "|" 'kw_P
								lstrTable = lstrTable & .get_TextMatrix(llngLinha + 1, 4) 'kw_FP
							End If
						End If
						ifrmExtrato.VS.Table = istrTamCl & lstrTable
					Next llngLinha
				End With
				.VS.Table = "^185mm;" & "Media Apurada(" & VB6.GetItemString(Me.cmbMeses, Me.cmbMeses.SelectedIndex) & "): " & VB6.Format(Me.txtMedia.Text, "#0.0") & " kWh"
			End If
			istrCabec = ""
			'UPGRADE_ISSUE: VBControlExtender method ifrmExtrato.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
			If .VS.CurrentY + 80 > 15000 Then
				.VS.NewPage()
			End If
			.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
			Call LineFeed(.VS, 1)
			.VS.Font = VB6.FontChangeBold(.VS.Font, True)
			.VS.Table = "^185mm;Gráfico do Consumo (kWh)"
			.VS.Font = VB6.FontChangeBold(.VS.Font, False)
			'Call Clipboard.Clear
			'Call mscConsumo.EditCopy
			'Call .VS.DrawPicture(Clipboard.GetData, "5mm", .VS.CurrentY + 80)
			Call .VS.EndDoc()
			Call .Show()
		End With
	End Function
	
	'[OK]
	Private Sub cmdBuscaEndUc_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdBuscaEndUc.Click
		istrModCoEnd = "UC"
		Call ifrmPreencherEnde.Show()
		Call ifrmPreencherEnde.SetaPreencherEnde(Me, False)
		'Set FrmPreencherEnde.quem_chama = Me
		'Me.Enabled = False
		'istrModCoEnd = "UC"
		'Call CenterForm(FrmPreencherEnde)
		'FrmPreencherEnde.Show
	End Sub
	
	'[OK]
	Private Sub cmdBuscaEndC_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdBuscaEndC.Click
		istrModCoEnd = "C"
		Call ifrmPreencherEnde.Show()
		Call ifrmPreencherEnde.SetaPreencherEnde(Me, False)
		'Set FrmPreencherEnde.quem_chama = Me
		'Me.Enabled = False
		'istrModCoEnd = "C"
		'Call CenterForm(FrmPreencherEnde)
		'FrmPreencherEnde.Show
	End Sub
	
	'[OK]
	Private Sub cmdBuscaEndCor_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdBuscaEndCor.Click
		istrModCoEnd = "CR"
		Call ifrmPreencherEnde.Show()
		Call ifrmPreencherEnde.SetaPreencherEnde(Me, False)
		'Set FrmPreencherEnde.quem_chama = Me
		'Me.Enabled = False
		'istrModCoEnd = "CR"
		'Call CenterForm(FrmPreencherEnde)
		'FrmPreencherEnde.Show
	End Sub
	
	'[OK]
	Public Sub SetaCamposEndereco(ByVal astrUf As String, ByVal astrCidade As String, ByVal astrDistrito As String, ByVal astrBairro As String, ByVal astrEnd As String, ByVal astrCep As String, ByVal astrCodigo As String)
		If istrModCoEnd = "C" Then
			Me.txtEndC.Text = astrEnd
			Me.txtCepC.Text = astrCep
			Me.txtBairroC.Text = astrBairro
			Me.txtDistritoC.Text = astrDistrito
			Me.txtCidadeC.Text = astrCidade
			Me.txtUfC.Text = astrUf
			istrEndCodC = astrCodigo
		ElseIf istrModCoEnd = "UC" Then 
			Me.txtEndU.Text = astrEnd
			Me.txtCepU.Text = astrCep
			Me.txtBairroU.Text = astrBairro
			Me.txtDistritoU.Text = astrDistrito
			Me.txtCidadeU.Text = astrCidade
			Me.txtUfU.Text = astrUf
			istrEndCodUC = astrCodigo
		ElseIf istrModCoEnd = "CR" Then 
			Me.txtEndE.Text = astrEnd
			Me.txtCepE.Text = astrCep
			Me.txtBairroE.Text = astrBairro
			Me.txtDistritoE.Text = astrDistrito
			Me.txtCidadeE.Text = astrCidade
			Me.txtUfE.Text = astrUf
			istrEndCodEn = astrCodigo
		End If
	End Sub
	
	Private Sub GravaDados()
		Dim lstrSql As String
		lstrSql = ""
		lstrSql = lstrSql & "UPDATE `unid" & LCase(istrGrupo) & "` SET "
		'lstrSql = lstrSql & "       `nome`           = '" & UCase(Trim(Me.txtNomeU.Text)) & "', "
		'lstrSql = lstrSql & "       `cpf_cnpj`       = '" & Str_Retira(Me.txtCpfCnpjU.Text, ".-/ ") & "', "
		'lstrSql = lstrSql & "       `insc`           = '" & Me.txtInscU.Text & "', "
		'lstrSql = lstrSql & "       `rg`             = '" & Me.txtRgU.Text & "', "
		lstrSql = lstrSql & "       `ap_saude`       = '" & IIf(Me.chkApSaude.CheckState, "S", "N") & "', "
		lstrSql = lstrSql & "       `agrupa`         = " & VB6.GetItemData(Me.cmbAgrupa, Me.cmbAgrupa.SelectedIndex) & ", "
		lstrSql = lstrSql & "       `agrupa_zona`    = '" & Me.txtAgrupaZona.Text & "', "
		lstrSql = lstrSql & "       `agrupa_livro`   = '" & Me.txtAgrupaLivro.Text & "', "
		lstrSql = lstrSql & "       `agrupa_conta`   = '" & Me.txtAgrupaConta.Text & "', "
		lstrSql = lstrSql & "       `itensesp`       = '" & Me.txtObsUc.Text & "', "
		lstrSql = lstrSql & "       `codend`         = '" & istrEndCodUC & "', "
		lstrSql = lstrSql & "       `uf`             = '" & Me.txtUfU.Text & "', "
		lstrSql = lstrSql & "       `cep`            = '" & Str_Retira(Me.txtCepU.Text, ".-/ ") & "', "
		lstrSql = lstrSql & "       `cidade`         = '" & Me.txtCidadeU.Text & "', "
		lstrSql = lstrSql & "       `distrito`       = '" & Me.txtDistritoU.Text & "', "
		lstrSql = lstrSql & "       `bairro`         = '" & Me.txtBairroU.Text & "', "
		lstrSql = lstrSql & "       `end`            = '" & Me.txtEndU.Text & "', "
		lstrSql = lstrSql & "       `numero`         = '" & Me.txtNumeroU.Text & "', "
		lstrSql = lstrSql & "       `lote`           = '" & Me.txtLoteU.Text & "', "
		lstrSql = lstrSql & "       `quadra`         = '" & Me.txtQuadraU.Text & "', "
		lstrSql = lstrSql & "       `complement`     = '" & Me.txtComplementoU.Text & "', "
		'lstrSql = lstrSql & "       `diavenc`        = '" & Me.cmbDiaVenc.List(Me.cmbDiaVenc.ListIndex) & "', "
		lstrSql = lstrSql & "       `codend_entrega` = '" & istrEndCodEn & "', "
		lstrSql = lstrSql & "       `uf_entrega`     = '" & UCase(Me.txtUfE.Text) & "', "
		lstrSql = lstrSql & "       `cep_entrega`    = '" & Str_Retira(Me.txtCepE.Text, ".-/ ") & "', "
		lstrSql = lstrSql & "       `cid_entrega`    = '" & UCase(Me.txtCidadeE.Text) & "', "
		lstrSql = lstrSql & "       `dis_entrega`    = '" & UCase(Me.txtDistritoE.Text) & "', "
		lstrSql = lstrSql & "       `bai_entrega`    = '" & UCase(Me.txtBairroE.Text) & "', "
		lstrSql = lstrSql & "       `end_entrega`    = '" & UCase(Me.txtEndE.Text) & "', "
		lstrSql = lstrSql & "       `num_entrega`    = '" & Me.txtNumeroE.Text & "', "
		lstrSql = lstrSql & "       `lot_entrega`    = '" & Me.txtLoteE.Text & "', "
		lstrSql = lstrSql & "       `qua_entrega`    = '" & Me.txtQuadraE.Text & "', "
		lstrSql = lstrSql & "       `compl_entrega`  = '" & UCase(Me.txtComplementE.Text) & "' "
		lstrSql = lstrSql & " WHERE `unid_id`        = " & ilngUnidId & " "
		Call Executar(lstrSql)
		lstrSql = ""
		lstrSql = lstrSql & "UPDATE `consum` SET "
		lstrSql = lstrSql & "       `nome`       = '" & UCase(Trim(Me.txtNomeC.Text)) & "', "
		'lstrSql = lstrSql & "       `cgc`        = '" & Str_Retira(Me.txtCpfCnpjC.Text, ".-/ ") & "', "
		'lstrSql = lstrSql & "       `insc`       = '" & Me.txtInscC.Text & "', "
		'lstrSql = lstrSql & "       `rg`         = '" & Me.txtRgC.Text & "', "
		lstrSql = lstrSql & "       `codend`     = '" & istrEndCodC & "', "
		lstrSql = lstrSql & "       `uf`         = '" & Me.txtUfC.Text & "', "
		lstrSql = lstrSql & "       `cep`        = '" & Str_Retira(Me.txtCepC.Text, ".-/ ") & "', "
		lstrSql = lstrSql & "       `cidade`     = '" & Me.txtCidadeC.Text & "', "
		lstrSql = lstrSql & "       `distrito`   = '" & Me.txtDistritoC.Text & "', "
		lstrSql = lstrSql & "       `bairro`     = '" & Me.txtBairroC.Text & "', "
		lstrSql = lstrSql & "       `end`        = '" & Me.txtEndC.Text & "', "
		lstrSql = lstrSql & "       `numero`     = '" & Me.txtNumeroC.Text & "', "
		lstrSql = lstrSql & "       `lote`       = '" & Me.txtLoteC.Text & "', "
		lstrSql = lstrSql & "       `quadra`     = '" & Me.txtQuadraC.Text & "', "
		lstrSql = lstrSql & "       `complement` = '" & Me.txtComplementoC.Text & "', "
		lstrSql = lstrSql & "       `dddtel`     = '" & Me.txtDddTel.Text & "', "
		lstrSql = lstrSql & "       `telefone`   = '" & Replace(Me.txtTEL.Text, "-", "") & "', "
		lstrSql = lstrSql & "       `email`      = '" & UCase(Trim(Me.txtEmail.Text)) & "', "
		lstrSql = lstrSql & "       `dddcel`     = '" & Me.txtDddCel.Text & "', "
		lstrSql = lstrSql & "       `cel`        = '" & Replace(Me.txtCel.Text, "-", "") & "', "
		lstrSql = lstrSql & "       `dddfax`     = '" & Me.txtDddFax.Text & "', "
		lstrSql = lstrSql & "       `fax`        = '" & Replace(Me.txtFax.Text, "-", "") & "', "
		lstrSql = lstrSql & "       `observacao` = '" & UCase(Trim(Me.txtObsCons.Text)) & "', "
		lstrSql = lstrSql & "       `nomepai`    = '" & UCase(Trim(Me.txtNomePai.Text)) & "', "
		lstrSql = lstrSql & "       `nomemae`    = '" & UCase(Trim(Me.txtNomeMae.Text)) & "' "
		lstrSql = lstrSql & " WHERE `consReg`    = " & ilngConsId & " "
		Call Executar(lstrSql)
		Me.fmeBotoes.Enabled = True
	End Sub
	
	'[ Função de retorno do frmlocalizaunidade ]
	Public Sub SetaCodigo(ByVal alngCodigo As Integer, ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String, ByVal astrGrupo As String)
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		If istrLocaliza = "U" Then
			Call BuscaUnidadeConsumidora(alngCodigo, 12)
			Call Me.cmdLocalizar.Focus()
		Else
			lstrSql = ""
			lstrSql = lstrSql & "SELECT `zona`, `livro`, `conta`, `rota`, `nome`, `unid_id` "
			lstrSql = lstrSql & "  FROM `unid" & LCase(istrGrupo) & "`  "
			lstrSql = lstrSql & " WHERE `unid_id` = " & alngCodigo
			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"'
						Me.txtAgrupaZona.Text = 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"'
						Me.txtAgrupaLivro.Text = 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"'
						Me.txtAgrupaConta.Text = 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"'
						Me.txtAgrupaRota.Text = 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"'
						Me.txtAgrupaNome.Text = UCase(Trim(IIf(IsDbNull(.Fields("nome").value), "", .Fields("nome").value)))
					End If
					Call .Close()
				End If
			End With
		End If
	End Sub
	
	'[ Função para retornar o número do NIS ]
	Private Function pegaNis(ByVal astrCpfCnpj As String, ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String, ByRef alngUnidId As Integer) As String
		Dim lstrNis As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM `nis` "
		lstrSql = lstrSql & " WHERE `nis`.`cpf` = '" & astrCpfCnpj & "'"
		lstrSql = lstrSql & "   AND `nis`.`zona` = '" & astrZona & "'"
		lstrSql = lstrSql & "   AND `nis`.`livro` = '" & astrLivro & "'"
		lstrSql = lstrSql & "   AND `nis`.`conta` = '" & astrConta & "'"
		lstrSql = lstrSql & "   AND `nis`.`unid_id` = " & alngUnidId & " "
		lstrSql = lstrSql & "   AND `nis`.`evento` IN('I','A') "
		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"'
					lstrNis = Trim(IIf(IsDbNull(.Fields("nis").value), "", .Fields("nis").value))
				End If
			End If
			Call .Close()
		End With
		pegaNis = lstrNis
		'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
	
	'[ Rotina para montar os valores de data de vencimento na combobox ]
	Private Sub pegaDatasVencimento()
		Dim lstrDatas As String
		Dim lstrAux As String
		Dim lintPos As Short
		lstrAux = ""
		lintPos = 1
		lstrDatas = LeConfig("DATAS_VENCIMENTO")
		With Me.cmbDiaVenc
			Call .Items.Clear()
			Call .Items.Add("")
			While lintPos <= Len(lstrDatas)
				If Mid(lstrDatas, lintPos, 1) <> ";" Then
					lstrAux = lstrAux & Mid(lstrDatas, lintPos, 1)
				ElseIf Mid(lstrDatas, lintPos, 1) = ";" Then 
					Call .Items.Add(lstrAux)
					lstrAux = ""
				End If
				lintPos = lintPos + 1
			End While
		End With
	End Sub
	
	'[ Rotina para achar o listindex da combo de vencimento de acordo com o parametro ]
	Private Sub BuscaDiaVencimento(ByVal astrDiaVenc As String)
		Dim lintLinha As Short
		With Me.cmbDiaVenc
			For lintLinha = 0 To .Items.Count
				If VB.Left(VB6.GetItemString(Me.cmbDiaVenc, lintLinha), 2) = VB6.Format(CStr(astrDiaVenc), "00") Then
					.SelectedIndex = lintLinha
					lintLinha = .Items.Count
				End If
			Next lintLinha
		End With
	End Sub
	
	Private Sub CobraSegundaVia(ByVal adblNumNf As Double, ByVal astrMesAno As String)
		Dim lstrZon As String
		Dim lstrLiv As String
		Dim lstrCon As String
		Dim lstrFas As String
		Dim lstrCod As String
		Dim ldblVlr As Double
		Dim ldteBas As Date
		Dim ldteIni As Date
		Dim ldteFin As Date
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		If MsgBox("Deseja cobrar segunda via", MsgBoxStyle.YesNo, gstrTituloMensagem) = MsgBoxResult.Yes Then
			lstrZon = Mid(Me.txtIdent.Text, 1, 3)
			lstrLiv = Mid(Me.txtIdent.Text, 5, 2)
			lstrCon = Mid(Me.txtIdent.Text, 8)
			ldteBas = CDate(VB6.Format(BuscaDataBD, "dd/mm/yyyy"))
			ldteIni = System.Date.FromOADate(DateSerial(Year(ldteBas), Month(ldteBas), UltimoDiaMes(Month(ldteBas), Year(ldteBas))).ToOADate + 1)
			ldteFin = DateSerial(Year(ldteIni), Month(ldteIni), UltimoDiaMes(Month(ldteIni), Year(ldteIni)))
			lstrFas = VB.Left(Me.txtFase.Text, 1)
			'Pega valor da Segunda Via
			lstrSql = ""
			lstrSql = lstrSql & "  SELECT `codigos`.`valor`, "
			lstrSql = lstrSql & "         `codigos`.`num` "
			lstrSql = lstrSql & "    FROM `codigos` "
			lstrSql = lstrSql & "   WHERE `codigos`.`num` = '904000006" & IIf(UCase(istrGrupo) = "A", 4, IIf(lstrFas = "M", 1, IIf(lstrFas = "B", 2, 3))) & "' "
			lstrSql = lstrSql & "     AND `codigos`.`datanova` <= '" & VB6.Format(BuscaDataBD, "yyyy-MM-dd") & "' "
			lstrSql = lstrSql & "ORDER BY `datanova` DESC "
			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"'
						ldblVlr = CDbl(Replace(IIf(IsDbNull(.Fields("valor").value), 0, .Fields("valor").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"'
						lstrCod = IIf(IsDbNull(.Fields("num").value), "", .Fields("num").value)
					End If
					Call .Close()
				End If
			End With
			lstrSql = ""
			lstrSql = lstrSql & "SELECT `id`,`zona`,`livro`,`conta`,`cons_id`,`unid_id`,`sit`,`codigo`,`dt_ini`,`dt_fim` "
			lstrSql = lstrSql & "  FROM `taxas` "
			lstrSql = lstrSql & " WHERE `zona`    = '" & lstrZon & "' "
			lstrSql = lstrSql & "   AND `livro`   = '" & lstrLiv & "' "
			lstrSql = lstrSql & "   AND `conta`   = '" & lstrCon & "' "
			lstrSql = lstrSql & "   AND `unid_id` = " & ilngUnidId & " "
			lstrSql = lstrSql & "   AND `cons_id` = " & ilngConsId & " "
			lstrSql = lstrSql & "   AND `codigo`  = '" & lstrCod & "' "
			lstrSql = lstrSql & "   AND `dt_ini` >= '" & VB6.Format(ldteIni, "yyyy-MM-dd") & "' "
			lstrSql = lstrSql & "   AND `dt_fim` <= '" & VB6.Format(ldteFin, "yyyy-MM-dd") & "' "
			lstrSql = lstrSql & "   AND TRIM(`ref`) = '" & astrMesAno & "' LIMIT 0, 1"
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State > 0 Then
					If .RecordCount > 0 Then
						Call MsgBox("Já existe uma taxa de segunda via para esta fatura! Não será cobrando novamente!", MsgBoxStyle.Information, gstrTituloMensagem)
					Else
						lstrSql = ""
						lstrSql = lstrSql & "INSERT INTO `taxas` SET " & vbCrLf
						lstrSql = lstrSql & "            `zona`    = '" & lstrZon & "', " & vbCrLf
						lstrSql = lstrSql & "            `livro`   = '" & lstrLiv & "', " & vbCrLf
						lstrSql = lstrSql & "            `conta`   = '" & lstrCon & "', " & vbCrLf
						lstrSql = lstrSql & "            `cons_id` = " & ilngConsId & ", " & vbCrLf
						lstrSql = lstrSql & "            `unid_id` = " & ilngUnidId & ", " & vbCrLf
						lstrSql = lstrSql & "            `codigo`  = '" & lstrCod & "', " & vbCrLf
						lstrSql = lstrSql & "            `valor`   = " & Replace(CStr(ldblVlr), ",", ".") & ", " & vbCrLf
						lstrSql = lstrSql & "            `dt_ini`  = '" & VB6.Format(ldteIni, "yyyy-MM-dd") & "', " & vbCrLf
						lstrSql = lstrSql & "            `dt_fim`  = '" & VB6.Format(ldteFin, "yyyy-MM-dd") & "', " & vbCrLf
						lstrSql = lstrSql & "            `ref`     = '" & astrMesAno & "' "
						Call Executar(lstrSql)
					End If
					Call .Close()
				End If
			End With
			Call ImpSegVia(adblNumNf, astrMesAno)
		Else
			With Me.fmeMotivo
				.Left = VB6.TwipsToPixelsX((VB6.PixelsToTwipsX(Me.Width) - VB6.PixelsToTwipsX(.Width)) / 2)
				.Top = VB6.TwipsToPixelsY((VB6.PixelsToTwipsY(Me.Height) - VB6.PixelsToTwipsY(.Height)) / 2)
				.Enabled = True
				.Visible = True
			End With
			Me.SSTab2.Enabled = False
			Me.fmeFaturas.Enabled = False
			'UPGRADE_WARNING: TextBox property txtMotivo.MaxLength has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
			Me.txtMotivo.Maxlength = 0
			Call Me.txtMotivo.Focus()
			Me.lblMotNumNf.Text = CStr(adblNumNf)
			Me.lblMotMesAno.Text = astrMesAno
		End If
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
	End Sub
	
	Private Sub ImpSegVia(ByVal adblNumNf As Double, ByVal astrMesAno As String)
		If UCase(istrGrupo) = "B" Then
			Call ifrmImpFaturas.GeraFaturaGrupoB(1, astrMesAno, adblNumNf, 0, "nf")
		Else
			Call ifrmImpFaturas.GeraFaturaGrupoA(1, astrMesAno, adblNumNf, 0, "nf")
		End If
	End Sub
	'[ Função para retornar o nome do banco ]
	Private Function BuscaNomeBancos(ByVal alngBanId As Integer) As String
		Dim lstrDes As String
		Dim lstrTip As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrSql = ""
		lstrSql = lstrSql & "SELECT `bancos`.`nmbco`, "
		lstrSql = lstrSql & "       `bancos`.`tpmovto` "
		lstrSql = lstrSql & "  FROM `bancos` "
		lstrSql = lstrSql & " WHERE `bancos`.`ban_id` = " & alngBanId
		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"'
					lstrDes = Trim(IIf(IsDbNull(.Fields("nmbco").value), "", .Fields("nmbco").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"'
					lstrTip = Trim(IIf(IsDbNull(.Fields("tpmovto").value), "N", .Fields("tpmovto").value))
					lstrDes = lstrDes & IIf(lstrTip = "D", " (D) ", "")
				End If
				Call .Close()
			End If
		End With
		BuscaNomeBancos = lstrDes
		'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
	
	'[ Funçao para retornar o nome do consumidor ]
	Private Function PegaNmConsumidor(ByVal alngConsId As Integer) As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		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"'
					PegaNmConsumidor = IIf(IsDbNull(.Fields("nome").value), "", .Fields("nome").value)
				Else
					PegaNmConsumidor = ""
				End If
				Call .Close()
			Else
				PegaNmConsumidor = ""
			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 Function BuscaSituacaoReaviso(ByVal astrMesAno As String, ByVal adblNumNf As Double) As String
		Dim lstrRet As String
		Dim lstrSit As String
		Dim ldtePra As Date
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrSql = ""
		lstrSql = lstrSql & "SELECT `concorte`.`sit`, "
		lstrSql = lstrSql & "       `concorte`.`prazoreav` "
		lstrSql = lstrSql & "  FROM `concorte` "
		lstrSql = lstrSql & " WHERE `concorte`.`numnf` = " & adblNumNf
		lstrSql = lstrSql & "   AND `concorte`.`mesano` = '" & astrMesAno & "' "
		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"'
					lstrSit = Trim(IIf(IsDbNull(.Fields("sit").value), "R", .Fields("sit").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"'
					ldtePra = CDate(IIf(IsDbNull(.Fields("PrazoReav").value), "1900-01-01", .Fields("PrazoReav").value))
					If lstrSit = "R" Then
						lstrRet = "Emitido"
					ElseIf lstrSit = "E" Then 
						lstrRet = "Entregue"
					ElseIf lstrSit = "C" Then 
						lstrRet = "Cortado"
					End If
					If ldtePra < BuscaDataBD Then
						'UPGRADE_WARNING: DateDiff behavior may be different. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6B38EC3F-686D-4B2E-B5A5-9E8E7A762E32"'
						lstrRet = "Venc(" & DateDiff(Microsoft.VisualBasic.DateInterval.Day, ldtePra, BuscaDataBD) & ")"
					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
		BuscaSituacaoReaviso = lstrRet
	End Function
	
	Private Sub msfgReclam_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles msfgReclam.ClickEvent
		Dim lstrCriterio As String
		With Me.msfgReclam
			If .Rows > 1 Then
				lstrCriterio = "trim({reclamacao.protocolo}) = """ & Trim(.get_TextMatrix(.RowSel, 1)) & """ AND {reclamacao.cod} = " & CInt(.get_TextMatrix(.RowSel, 0))
				With Me.crpReclamacao
					.ReportFileName = My.Application.Info.DirectoryPath & "\" & LeConfig("DIR_RPT") & LeConfig("REL_RECLAMACAO") '& "Reclamacao.rpt"
					.DiscardSavedData = True
					.WindowState = Crystal.WindowStateConstants.crptMaximized
					.WindowControlBox = True
					.WindowControls = True
					.WindowShowPrintSetupBtn = True
					.WindowShowCloseBtn = True
					.WindowShowSearchBtn = True
					.WindowTitle = "Impressão de Reclamação"
					.Destination = Crystal.DestinationConstants.crptToWindow
					.SelectionFormula = lstrCriterio
					.Action = 0
				End With
			End If
		End With
	End Sub
	
	Private Sub msfgSolServ_DblClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles msfgSolServ.DblClick
		With Me.msfgSolServ
			If .Rows > 1 Then
				Call ReimprimirOS(.get_TextMatrix(.RowSel, 2), (Me.crpOs), (Me.crpCarga), (Me.crpCroqui), CInt(.get_TextMatrix(.RowSel, 1)))
			End If
		End With
	End Sub
	
	Private Sub txtDescrClasse_DoubleClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtDescrClasse.DoubleClick
		Dim lstrSql As String
		Dim ldteBase As Date
		If CDbl(VB.Left(Me.txtClasse.Text, 1)) = 5 Then
			If istrIsRural = "N" Then
				If MsgBox("Emitir o comprovante de rural?", MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton1, gstrTituloMensagem) = MsgBoxResult.Yes Then
					ldteBase = BuscaDataBD
					lstrSql = ""
					lstrSql = lstrSql & "UPDATE `unid" & LCase(istrGrupo) & "` "
					lstrSql = lstrSql & "   SET `comprovante_rural` = 'S' "
					lstrSql = lstrSql & " WHERE `cons_id` = " & ilngConsId
					lstrSql = lstrSql & "   AND `unid_id` = " & ilngUnidId
					Call Executar(lstrSql)
					istrIsRural = "S"
					Me.txtDescrClasse.ForeColor = System.Drawing.ColorTranslator.FromOle(&HC000)
					Me.txtDescrClasse.Font = VB6.FontChangeBold(Me.txtDescrClasse.Font, True)
					'----- Chama o relatório em Crystal Reports
					With Me.crpComprovanteRural
						.ReportFileName = My.Application.Info.DirectoryPath & "\" & LeConfig("DIR_RPT") & "\comprovate_rural_eflul.rpt"
						.DiscardSavedData = True
						.WindowState = Crystal.WindowStateConstants.crptMaximized
						.WindowControlBox = True
						.WindowControls = True
						.WindowShowPrintSetupBtn = True
						.WindowShowCloseBtn = True
						.WindowShowSearchBtn = True
						.SelectionFormula = ""
						.set_Formulas(0, "ZonaLivroConta = '" & Me.txtIdent.Text & "' ")
						.set_Formulas(1, "Nome           = '" & Me.txtNomeU.Text & "' ")
						.set_Formulas(2, "Classe         = '" & Me.txtClasse.Text & " - " & Me.txtDescrClasse.Text & "' ")
						.set_Formulas(3, "Endereco       = '" & Me.txtEndU.Text & "' ")
						.set_Formulas(4, "Numero         = '" & Me.txtNumeroU.Text & "' ")
						.set_Formulas(5, "Complemento    = '" & Me.txtComplementoU.Text & "' ")
						.set_Formulas(6, "Lote           = '" & Me.txtLoteU.Text & "' ")
						.set_Formulas(7, "Quadra         = '" & Me.txtQuadraU.Text & "' ")
						.set_Formulas(8, "Bairro         = '" & Me.txtBairroU.Text & "' ")
						.set_Formulas(9, "Cep            = '" & Me.txtCepU.Text & "' ")
						.set_Formulas(10, "Cidade        = '" & Me.txtCidadeU.Text & "' ")
						.set_Formulas(11, "Estado        = '" & Me.txtUfU.Text & "' ")
						.set_Formulas(12, "Distrito      = '" & Me.txtDistritoU.Text & "' ")
						.set_Formulas(13, "CpfCnpj       = '" & Me.txtCpfCnpjU.Text & "' ")
						.set_Formulas(14, "RgIe          = '" & IIf(Len(Me.txtInscU.Text) = 0, Me.txtRgU.Text, Me.txtInscU.Text) & "' ")
						.set_Formulas(15, "DataBase      = '" & VB6.Format(ldteBase, "dd") & " de " & VB6.Format(ldteBase, "mmmm") & " de " & VB6.Format(ldteBase, "yyyy") & "' ")
						
						.WindowTitle = "Comprovate Rural"
						.Destination = Crystal.DestinationConstants.crptToWindow
						.Action = 0
					End With
					
				End If
			End If
		End If
	End Sub
	
	Private Sub txtMotivo_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtMotivo.Enter
		With Me.txtMotivo
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtAgrupaConta_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtAgrupaConta.Leave
		Me.txtAgrupaConta.Text = VB6.Format(Me.txtAgrupaConta.Text, "000000")
	End Sub
	
	Private Sub txtAgrupaLivro_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtAgrupaLivro.Leave
		Me.txtAgrupaLivro.Text = VB6.Format(Me.txtAgrupaLivro.Text, "00")
	End Sub
	
	Private Sub txtAgrupaZona_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtAgrupaZona.Leave
		Me.txtAgrupaZona.Text = VB6.Format(Me.txtAgrupaZona.Text, "000")
	End Sub
	
	Private Sub EncheGridSS(ByVal aintQtdeHistorico As Short)
		Dim lintIdx As Short
		Dim llngSeqProt As Integer
		Dim lstrProtocolo As String
		Dim lstrZLC As String
		Dim ldteSolicitacao As Date
		Dim lstrHoraSoli As String
		Dim lstrNomeSolicit As String
		Dim llngUnidId As Integer
		Dim lstrGrupo As String
		Dim ldteSolucao As Date
		Dim lstrHoraSolu As String
		Dim lstrPrioridade As String
		Dim lstrFeitoPor As String
		Dim lstrRegiao As String
		Dim lstrSituacao As String
		Dim lstrDescServ As String
		Dim lstrNomeUc As String
		Dim lstrFaseUc As String
		Dim lstrZonaUc As String
		Dim lstrLivroUc As String
		Dim lstrContaUc As String
		Dim lstrClasUc As String
		Dim lstrItensserv As String
		Dim lstrCodigo As String
		Dim ldblValor As Double
		Dim lintConta As Short
		Dim lstrSql As String
		Dim lrstConsulta As ADODB.Recordset
		Dim llngPosI As Integer
		Dim llngPosF As Integer
		
		With Me.msfgSolServ
			.Rows = 1
			.Redraw = False
		End With
		lrstConsulta = New ADODB.Recordset
		lstrSql = ""
		lstrSql = lstrSql & "   SELECT `solserv`.`cod`, " & vbCrLf
		lstrSql = lstrSql & "          `solserv`.`protocolo`, " & vbCrLf
		lstrSql = lstrSql & "          `solserv`.`zlc`, " & vbCrLf
		lstrSql = lstrSql & "          `solserv`.`data_soli`, " & vbCrLf
		lstrSql = lstrSql & "          `solserv`.`hora_soli`, " & vbCrLf
		lstrSql = lstrSql & "          `solserv`.`itensserv`, " & vbCrLf
		lstrSql = lstrSql & "          `solserv`.`nomesol`, " & vbCrLf
		lstrSql = lstrSql & "          `solserv`.`unid_id`, " & vbCrLf
		lstrSql = lstrSql & "          `solserv`.`unid`, " & vbCrLf
		lstrSql = lstrSql & "          `solserv`.`datasolu`, " & vbCrLf
		lstrSql = lstrSql & "          `solserv`.`horasolu`, " & vbCrLf
		lstrSql = lstrSql & "          `solserv`.`prioridade`, " & vbCrLf
		lstrSql = lstrSql & "          `solserv`.`solicit_meio`, " & vbCrLf
		lstrSql = lstrSql & "          `solserv`.`zona_solic`, " & vbCrLf
		lstrSql = lstrSql & "          `solserv`.`sit`, " & vbCrLf
		lstrSql = lstrSql & "          `solserv`.`descr_serv` " & vbCrLf
		lstrSql = lstrSql & "     FROM `solserv` " & vbCrLf
		lstrSql = lstrSql & " WHERE solserv.unid_id = " & ilngUnidId & " "
		lstrSql = lstrSql & "   AND solserv.unid = '" & istrGrupo & "' "
		lstrSql = lstrSql & " ORDER BY `solserv`.`data_soli` DESC, `solserv`.`hora_soli` DESC LIMIT 0, " & aintQtdeHistorico
		Call Conectar(lstrSql, lrstConsulta)
		With lrstConsulta
			If .RecordCount > 0 Then
				While Not .EOF
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					llngSeqProt = CInt(IIf(IsDbNull(.Fields("cod").value), 0, .Fields("cod").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"'
					lstrProtocolo = Trim(IIf(IsDbNull(.Fields("protocolo").value), "", .Fields("protocolo").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"'
					lstrZLC = IIf(IsDbNull(.Fields("zlc").value), "", .Fields("zlc").value)
					lstrZLC = VB.Left(lstrZLC, 3) & "." & Mid(lstrZLC, 4, 2) & "." & VB.Right(lstrZLC, 6)
					lstrZLC = Me.txtIdent.Text
					'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"'
					ldteSolicitacao = CDate(IIf(IsDbNull(.Fields("data_soli").value), "1900-01-01", .Fields("data_soli").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"'
					lstrHoraSoli = VB6.Format(IIf(IsDbNull(.Fields("hora_soli").value), "", .Fields("hora_soli").value), "HH:MM:SS")
					'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"'
					lstrNomeSolicit = Trim(IIf(IsDbNull(.Fields("nomesol").value), "", .Fields("nomesol").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("unid").value), "B", .Fields("unid").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"'
					ldteSolucao = CDate(IIf(IsDbNull(.Fields("datasolu").value), "1900-01-01", .Fields("datasolu").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"'
					lstrHoraSolu = VB6.Format(IIf(IsDbNull(.Fields("horasolu").value), "", .Fields("horasolu").value), "HH:MM:SS")
					If ldteSolucao = CDate("01/01/1900") Then lstrHoraSolu = ""
					'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"'
					lstrPrioridade = Trim(IIf(IsDbNull(.Fields("prioridade").value), "N", .Fields("prioridade").value))
					lstrPrioridade = IIf(lstrPrioridade = "N", "Normal", "Urgente")
					'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"'
					lstrFeitoPor = Trim(IIf(IsDbNull(.Fields("solicit_meio").value), "P", .Fields("solicit_meio").value))
					lstrFeitoPor = IIf(lstrFeitoPor = "P", "Pessoalmente", IIf(lstrFeitoPor = "F", "Fone", IIf(lstrFeitoPor = "E", "E-mail", IIf(lstrFeitoPor = "S", "Site", IIf(lstrFeitoPor = "O", "Outro", "--")))))
					'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("zona_solic").value), "U", .Fields("zona_solic").value))
					lstrRegiao = IIf(lstrRegiao = "U", "Urbana", "Rural")
					'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("sit").value), "A", .Fields("sit").value))
					If lstrSituacao = "A" Then
						lstrSituacao = "Aberta"
					ElseIf lstrSituacao = "C" Then 
						lstrSituacao = "Cancelada"
					ElseIf lstrSituacao = "F" Then 
						lstrSituacao = "Finalizada"
					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"'
					lstrDescServ = Trim(IIf(IsDbNull(.Fields("descr_serv").value), "", .Fields("descr_serv").value))
					lstrNomeUc = Me.txtNomeU.Text
					lstrFaseUc = Me.txtFaseUc.Text
					lstrClasUc = Me.txtClasse.Text
					If VB.Left(lstrClasUc, 1) = "9" Then
						lstrClasUc = "Residencial"
					ElseIf CDbl(VB.Left(lstrClasUc, 1)) + 0 < 4 Then 
						lstrClasUc = "Industrial"
					ElseIf VB.Left(lstrClasUc, 1) = "4" Then 
						lstrClasUc = "Comercial"
					ElseIf VB.Left(lstrClasUc, 1) = "5" Then 
						lstrClasUc = "Rural"
					ElseIf VB.Left(lstrClasUc, 1) = "7" Then 
						lstrClasUc = "Serviço Público"
					ElseIf VB.Left(lstrClasUc, 1) = "8" Then 
						lstrClasUc = "Consumo Próprio"
					ElseIf VB.Left(lstrClasUc, 2) = "61" Then 
						lstrClasUc = "Poder Público Municipal"
					ElseIf VB.Left(lstrClasUc, 2) = "62" Then 
						lstrClasUc = "Poder Público Estadual"
					ElseIf VB.Left(lstrClasUc, 2) = "63" Then 
						lstrClasUc = "Poder Público Federal"
					ElseIf VB.Left(lstrClasUc, 2) = "64" Then 
						lstrClasUc = "Iluminação Pública"
					Else
						lstrClasUc = "(nenhuma classe)"
					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"'
					lstrItensserv = Trim(IIf(IsDbNull(.Fields("itensserv").value), "", .Fields("itensserv").value))
					llngPosI = InStr(1, lstrItensserv, "?")
					llngPosF = InStr(1, lstrItensserv, ";")
					lstrCodigo = VB.Left(lstrItensserv, llngPosI - 1)
					ldblValor = CDbl(Mid(lstrItensserv, llngPosI + 1, (llngPosF - 1) - llngPosI))
					With Me.msfgSolServ
						.Rows = .Rows + 1
						'UPGRADE_ISSUE: VBControlExtender method msfgSolServ.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
						.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillRepeat
						If lstrSituacao = "Cancelada" Then
							.Row = .Rows - 1
							.Col = 0
							.ColSel = .Cols - 1
							.CellForeColor = System.Drawing.ColorTranslator.FromOle(&HFF0000) 'Azul
						ElseIf lstrSituacao = "Aberta" Then 
							.Row = .Rows - 1
							.Col = 0
							.ColSel = .Cols - 1
							.CellForeColor = System.Drawing.ColorTranslator.FromOle(&HFF) 'Vermelho
						Else
							.Row = .Rows - 1
							.Col = 0
							.ColSel = .Cols - 1
							.CellForeColor = System.Drawing.ColorTranslator.FromOle(&H80000008) 'Normal
						End If
						.set_TextMatrix(.Rows - 1, 0, lstrZLC)
						.set_TextMatrix(.Rows - 1, 1, llngSeqProt)
						.set_TextMatrix(.Rows - 1, 2, lstrProtocolo)
						.set_TextMatrix(.Rows - 1, 3, VB6.Format(ldteSolicitacao, "dd/mm/yyyy"))
						.set_TextMatrix(.Rows - 1, 6, lstrNomeSolicit)
						.set_TextMatrix(.Rows - 1, 4, BuscaDescriCod(lstrCodigo))
						.set_TextMatrix(.Rows - 1, 5, FormatNumber(ldblValor, 2))
						.set_TextMatrix(.Rows - 1, 7, llngUnidId)
						.set_TextMatrix(.Rows - 1, 8, lstrGrupo)
						If ldteSolucao <> CDate("01/01/1900") Then
							.set_TextMatrix(.Rows - 1, 9, VB6.Format(ldteSolucao, "dd/mm/yyyy"))
						Else
							.set_TextMatrix(.Rows - 1, 9, "")
						End If
						.set_TextMatrix(.Rows - 1, 10, lstrHoraSoli)
						.set_TextMatrix(.Rows - 1, 11, lstrHoraSolu)
						.set_TextMatrix(.Rows - 1, 12, lstrPrioridade)
						.set_TextMatrix(.Rows - 1, 13, lstrFeitoPor)
						.set_TextMatrix(.Rows - 1, 14, lstrRegiao)
						.set_TextMatrix(.Rows - 1, 15, lstrSituacao)
						.set_TextMatrix(.Rows - 1, 16, lstrDescServ)
						.set_TextMatrix(.Rows - 1, 17, lstrNomeUc)
						.set_TextMatrix(.Rows - 1, 18, lstrFaseUc)
						.set_TextMatrix(.Rows - 1, 19, lstrClasUc)
					End With
					Call .MoveNext()
				End While
			End If
			If .State = 1 Then Call .Close()
		End With
		'UPGRADE_NOTE: Object lrstConsulta may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstConsulta = Nothing
		With Me.msfgSolServ
			If .Rows > 1 Then .Row = 1
			.Redraw = True
		End With
	End Sub
	
	Private Sub EncheGridRC(ByVal aintQtdeHistorico As Short)
		Dim llngCodigo As Integer
		Dim lstrProtoc As String
		Dim ldteSolici As Date
		Dim lstrHSolic As String
		Dim ldteConclu As Date
		Dim lstrHConcl As String
		Dim ldteCancel As Date
		Dim lstrHCance As String
		Dim ldteEstorn As Date
		Dim lstrHEstor As String
		Dim llngTpRecl As Integer
		Dim lstrTpRecl As String
		Dim lstrTxtRec As String
		Dim lstrTxtCon As String
		Dim lstrTxtCan As String
		Dim lstrTxtEst As String
		Dim lintPriori As Short
		Dim lstrPriori As String
		Dim lintOrigem As Short
		Dim lstrOrigem As String
		Dim lintRegiao As Short
		Dim lstrRegiao As String
		Dim lintResolv As Short
		Dim lstrResolv As String
		Dim lstrProced As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		' ----- Monta o Filtro
		With Me.msfgReclam
			.Rows = 1
			.Redraw = False
		End With
		lstrSql = ""
		lstrSql = lstrSql & "   SELECT `reclamacao`.`cod`, " & vbCrLf
		lstrSql = lstrSql & "          `reclamacao`.`protocolo`, " & vbCrLf
		lstrSql = lstrSql & "          `reclamacao`.`dt_solicitacao`, " & vbCrLf
		lstrSql = lstrSql & "          `reclamacao`.`hr_solicitacao`, " & vbCrLf
		lstrSql = lstrSql & "          `reclamacao`.`dt_conclusao`, " & vbCrLf
		lstrSql = lstrSql & "          `reclamacao`.`hr_conclusao`, " & vbCrLf
		lstrSql = lstrSql & "          `reclamacao`.`dt_cancelada`, " & vbCrLf
		lstrSql = lstrSql & "          `reclamacao`.`hr_cancelada`, " & vbCrLf
		lstrSql = lstrSql & "          `reclamacao`.`dt_estorno`, " & vbCrLf
		lstrSql = lstrSql & "          `reclamacao`.`hr_estorno`, " & vbCrLf
		lstrSql = lstrSql & "          `reclamacao`.`tipo_reclamacao`, " & vbCrLf
		lstrSql = lstrSql & "          `reclamacao`.`txt_reclamacao`, " & vbCrLf
		lstrSql = lstrSql & "          `reclamacao`.`txt_conclusao`, " & vbCrLf
		lstrSql = lstrSql & "          `reclamacao`.`txt_cancelada`, " & vbCrLf
		lstrSql = lstrSql & "          `reclamacao`.`txt_estorno`, " & vbCrLf
		lstrSql = lstrSql & "          `reclamacao`.`unid_id`, " & vbCrLf
		lstrSql = lstrSql & "          `reclamacao`.`unid`, " & vbCrLf
		lstrSql = lstrSql & "          `reclamacao`.`prioridade`, " & vbCrLf
		lstrSql = lstrSql & "          `reclamacao`.`origem`, " & vbCrLf
		lstrSql = lstrSql & "          `reclamacao`.`regiao`, " & vbCrLf
		lstrSql = lstrSql & "          `reclamacao`.`resolvida`, " & vbCrLf
		lstrSql = lstrSql & "          `reclamacao`.`procedente` " & vbCrLf
		lstrSql = lstrSql & "     FROM `reclamacao` " & vbCrLf
		lstrSql = lstrSql & "    WHERE `reclamacao`.`unid_id` = " & ilngUnidId & " "
		lstrSql = lstrSql & "      AND `reclamacao`.`unid` = '" & istrGrupo & "' "
		lstrSql = lstrSql & " ORDER BY `reclamacao`.`dt_solicitacao` DESC, `reclamacao`.`hr_solicitacao` DESC LIMIT 0, " & aintQtdeHistorico
		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"'
						llngCodigo = CInt(IIf(IsDbNull(.Fields("cod").value), 0, .Fields("cod").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"'
						lstrProtoc = Trim(IIf(IsDbNull(.Fields("protocolo").value), "", .Fields("protocolo").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"'
						ldteSolici = CDate(IIf(IsDbNull(.Fields("dt_solicitacao").value), "1900-01-01", .Fields("dt_solicitacao").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"'
						lstrHSolic = Trim(IIf(IsDbNull(.Fields("hr_solicitacao").value), "", .Fields("hr_solicitacao").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"'
						ldteConclu = CDate(IIf(IsDbNull(.Fields("dt_conclusao").value), "1900-01-01", .Fields("dt_conclusao").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"'
						lstrHConcl = Trim(IIf(IsDbNull(.Fields("hr_conclusao").value), "", .Fields("hr_conclusao").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"'
						ldteCancel = CDate(IIf(IsDbNull(.Fields("dt_cancelada").value), "1900-01-01", .Fields("dt_cancelada").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"'
						lstrHCance = Trim(IIf(IsDbNull(.Fields("hr_cancelada").value), "", .Fields("hr_cancelada").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"'
						ldteEstorn = CDate(IIf(IsDbNull(.Fields("dt_estorno").value), "1900-01-01", .Fields("dt_estorno").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"'
						lstrHEstor = Trim(IIf(IsDbNull(.Fields("hr_estorno").value), "", .Fields("hr_estorno").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"'
						llngTpRecl = CInt(IIf(IsDbNull(.Fields("tipo_reclamacao").value), 0, .Fields("tipo_reclamacao").value))
						lstrTpRecl = BuscaDescriReclamacao(llngTpRecl)
						'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"'
						lstrTxtRec = Trim(IIf(IsDbNull(.Fields("txt_reclamacao").value), "", .Fields("txt_reclamacao").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"'
						lstrTxtCon = Trim(IIf(IsDbNull(.Fields("txt_conclusao").value), "", .Fields("txt_conclusao").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"'
						lstrTxtCan = Trim(IIf(IsDbNull(.Fields("txt_cancelada").value), "", .Fields("txt_cancelada").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"'
						lstrTxtEst = Trim(IIf(IsDbNull(.Fields("txt_estorno").value), "", .Fields("txt_estorno").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"'
						lintPriori = CShort(IIf(IsDbNull(.Fields("prioridade").value), 0, .Fields("prioridade").value))
						lstrPriori = IIf(lintPriori = 0, "Urgente", "Normal")
						'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"'
						lintOrigem = CShort(IIf(IsDbNull(.Fields("origem").value), 0, .Fields("origem").value))
						lstrOrigem = IIf(lintOrigem = 0, "Pessoalmente", IIf(lintOrigem = 1, "Fone", IIf(lintOrigem = 2, "E-mail", IIf(lintOrigem = 3, "Site", IIf(lintOrigem = 4, "Outro", "--")))))
						'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"'
						lintRegiao = CShort(IIf(IsDbNull(.Fields("regiao").value), 0, .Fields("regiao").value))
						lstrRegiao = IIf(lintRegiao = 0, "Urbana", "Rural")
						'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"'
						lintResolv = CShort(IIf(IsDbNull(.Fields("resolvida").value), 0, .Fields("resolvida").value))
						lstrResolv = IIf(lintResolv = 0, "Aberta", IIf(lintResolv = 1, "Finalizada", IIf(lintResolv = 2, "Cancelada", IIf(lintResolv = 3, "Estornada", "--"))))
						'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"'
						lstrProced = Trim(IIf(IsDbNull(.Fields("procedente").value), "N", .Fields("procedente").value))
						lstrProced = IIf(lstrProced = "S", "Sim", "Não")
						With Me.msfgReclam
							.Rows = .Rows + 1
							'UPGRADE_ISSUE: VBControlExtender method msfgReclam.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
							.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillRepeat
							If lstrResolv = "Cancelada" Then
								.Row = .Rows - 1
								.Col = 0
								.ColSel = .Cols - 1
								.CellForeColor = System.Drawing.ColorTranslator.FromOle(&HFF0000) 'Azul
							ElseIf lstrResolv = "Aberta" Then 
								.Row = .Rows - 1
								.Col = 0
								.ColSel = .Cols - 1
								.CellForeColor = System.Drawing.ColorTranslator.FromOle(&HFF) 'Vermelho
							Else
								.Row = .Rows - 1
								.Col = 0
								.ColSel = .Cols - 1
								.CellForeColor = System.Drawing.ColorTranslator.FromOle(&H80000008) 'Normal
							End If
							.set_TextMatrix(.Rows - 1, 0, llngCodigo)
							.set_TextMatrix(.Rows - 1, 1, lstrProtoc)
							If ldteSolici <> CDate("01/01/1900") Then
								.set_TextMatrix(.Rows - 1, 2, VB6.Format(ldteSolici, "dd/mm/yyyy"))
								.set_TextMatrix(.Rows - 1, 3, VB6.Format(lstrHSolic, "hh:mm"))
							Else
								.set_TextMatrix(.Rows - 1, 2, "")
								.set_TextMatrix(.Rows - 1, 3, "")
							End If
							If ldteConclu <> CDate("01/01/1900") Then
								.set_TextMatrix(.Rows - 1, 4, VB6.Format(ldteConclu, "dd/mm/yyyy"))
								.set_TextMatrix(.Rows - 1, 5, VB6.Format(lstrHConcl, "hh:mm"))
							Else
								.set_TextMatrix(.Rows - 1, 4, "")
								.set_TextMatrix(.Rows - 1, 5, "")
							End If
							If ldteCancel <> CDate("01/01/1900") Then
								.set_TextMatrix(.Rows - 1, 6, VB6.Format(ldteCancel, "dd/mm/yyyy"))
								.set_TextMatrix(.Rows - 1, 7, VB6.Format(lstrHCance, "hh:mm"))
							Else
								.set_TextMatrix(.Rows - 1, 6, "")
								.set_TextMatrix(.Rows - 1, 7, "")
							End If
							If ldteEstorn <> CDate("01/01/1900") Then
								.set_TextMatrix(.Rows - 1, 8, VB6.Format(ldteEstorn, "dd/mm/yyyy"))
								.set_TextMatrix(.Rows - 1, 9, VB6.Format(lstrHEstor, "hh:mm"))
							Else
								.set_TextMatrix(.Rows - 1, 8, "")
								.set_TextMatrix(.Rows - 1, 9, "")
							End If
							.set_TextMatrix(.Rows - 1, 10, llngTpRecl)
							.set_TextMatrix(.Rows - 1, 11, lstrTpRecl)
							.set_TextMatrix(.Rows - 1, 12, lstrTxtRec)
							.set_TextMatrix(.Rows - 1, 13, lstrTxtCon)
							.set_TextMatrix(.Rows - 1, 14, lstrTxtCan)
							.set_TextMatrix(.Rows - 1, 15, lstrTxtEst)
							.set_TextMatrix(.Rows - 1, 16, lintPriori)
							.set_TextMatrix(.Rows - 1, 17, lstrPriori)
							.set_TextMatrix(.Rows - 1, 18, lintOrigem)
							.set_TextMatrix(.Rows - 1, 19, lstrOrigem)
							.set_TextMatrix(.Rows - 1, 20, lintRegiao)
							.set_TextMatrix(.Rows - 1, 21, lstrRegiao)
							.set_TextMatrix(.Rows - 1, 22, lintResolv)
							.set_TextMatrix(.Rows - 1, 23, lstrResolv)
							.set_TextMatrix(.Rows - 1, 24, lstrProced)
						End With
						Call .MoveNext()
					End While
				End If
				Call .Close()
			End If
		End With
		With Me.msfgReclam
			If .Rows > 1 Then .Row = 1
			.Redraw = True
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
	End Sub
	
	Private Function BuscaDescriCod(ByVal astrCodigo As String) As String
		Dim lstrSql As String
		Dim lrstConsulta As ADODB.Recordset
		lrstConsulta = New ADODB.Recordset
		lstrSql = "SELECT * " & "  FROM `codigos` " & " WHERE `num` = """ & astrCodigo & """"
		Call Conectar(lstrSql, lrstConsulta)
		With lrstConsulta
			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"'
				BuscaDescriCod = IIf(IsDbNull(.Fields("descri").value), "", .Fields("descri").value)
			Else
				BuscaDescriCod = ""
			End If
			If .State = 1 Then Call .Close()
		End With
		'UPGRADE_NOTE: Object lrstConsulta may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstConsulta = Nothing
	End Function
	
	Private Function BuscaDescriReclamacao(ByVal alngCod As Integer) As String
		Dim lstrSql As String
		Dim lrstConsulta As ADODB.Recordset
		lrstConsulta = New ADODB.Recordset
		lstrSql = "SELECT * " & "  FROM `tipo_reclamacao` " & " WHERE `id` = " & alngCod & " "
		Call Conectar(lstrSql, lrstConsulta)
		With lrstConsulta
			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"'
				BuscaDescriReclamacao = IIf(IsDbNull(.Fields("nome").value), "", .Fields("nome").value)
			Else
				BuscaDescriReclamacao = ""
			End If
			If .State = 1 Then Call .Close()
		End With
		'UPGRADE_NOTE: Object lrstConsulta may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstConsulta = Nothing
	End Function
End Class