Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmConfereReaviso
	Inherits System.Windows.Forms.Form
	
	Private ilngConsId As Integer
	Private ilngUnidId As Integer
	Private istrGrupo As String
	Private istrZona As String
	Private istrLivro As String
	Private istrConta As String
	Private idblNumNf As Double
	Private istrMesAno As String
	
	'UPGRADE_WARNING: Event txtBarra.TextChanged 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 txtBarra_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtBarra.TextChanged
		With Me.txtBarra
			If Len(.Text) = 0 Then
				Me.txtZona.Enabled = True
				Me.txtLivro.Enabled = True
				Me.txtConta.Enabled = True
				Me.txtMesAno.Enabled = True
				Me.txtZona.BackColor = System.Drawing.ColorTranslator.FromOle(&H80000005)
				Me.txtLivro.BackColor = System.Drawing.ColorTranslator.FromOle(&H80000005)
				Me.txtConta.BackColor = System.Drawing.ColorTranslator.FromOle(&H80000005)
				Me.txtMesAno.BackColor = System.Drawing.ColorTranslator.FromOle(&H80000005)
				Me.opbGrupoA.Enabled = True
				Me.opbGrupoB.Enabled = True
				Me.cmdBuscar.Enabled = True
				System.Windows.Forms.Application.DoEvents()
			Else
				Me.txtZona.Enabled = False
				Me.txtLivro.Enabled = False
				Me.txtConta.Enabled = False
				Me.txtMesAno.Enabled = False
				Me.txtZona.BackColor = System.Drawing.ColorTranslator.FromOle(&H8000000F)
				Me.txtLivro.BackColor = System.Drawing.ColorTranslator.FromOle(&H8000000F)
				Me.txtConta.BackColor = System.Drawing.ColorTranslator.FromOle(&H8000000F)
				Me.txtMesAno.BackColor = System.Drawing.ColorTranslator.FromOle(&H8000000F)
				Me.opbGrupoA.Enabled = False
				Me.opbGrupoB.Enabled = False
				Me.cmdBuscar.Enabled = False
				System.Windows.Forms.Application.DoEvents()
				If Len(Trim(.Text)) = 28 Then
					Call VerificaBarras()
				End If
			End If
		End With
	End Sub
	
	Private Sub txtBarra_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtBarra.Enter
		With Me.txtBarra
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtBarra_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtBarra.Leave
		Call VerificaBarras()
	End Sub
	
	Private Sub VerificaBarras()
		With Me.txtBarra
			If Len(Trim(.Text)) = 28 Then
				.Text = Trim(.Text)
				istrZona = Mid(.Text, 1, 3)
				istrLivro = Mid(.Text, 4, 2)
				istrConta = Mid(.Text, 6, 6)
				idblNumNf = CDbl(Mid(.Text, 12, 9))
				istrMesAno = Mid(.Text, 21, 6)
				istrMesAno = VB.Right(istrMesAno, 2) & "/" & VB.Left(istrMesAno, 4)
				istrGrupo = IIf(CDbl(Mid(.Text, 27, 2)) = 65, "A", "B")
				Me.opbGrupoB.Checked = (istrGrupo = "B")
				Me.opbGrupoA.Checked = (istrGrupo = "A")
				Call BuscaUnidade()
				Call SendKeysA(System.Windows.Forms.Keys.Tab, False)
				Call txtBarra_Enter(txtBarra, New System.EventArgs())
			ElseIf Len(Trim(.Text)) > 0 Then 
				Call MsgBox("Código de barra inválido!", MsgBoxStyle.Information, gstrTituloMensagem)
				Call .Focus()
			Else
				istrZona = ""
				istrLivro = ""
				istrConta = ""
				idblNumNf = 0
				istrMesAno = ""
				istrGrupo = ""
			End If
		End With
	End Sub
	
	'UPGRADE_WARNING: Event txtConta.TextChanged 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 txtConta_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtConta.TextChanged
		With Me.txtConta
			If Len(.Text) = 0 Then
				Me.txtBarra.Enabled = True
				Me.txtBarra.BackColor = System.Drawing.ColorTranslator.FromOle(&H80000005)
				System.Windows.Forms.Application.DoEvents()
			Else
				Me.txtBarra.Enabled = False
				Me.txtBarra.BackColor = System.Drawing.ColorTranslator.FromOle(&H8000000F)
			End If
		End With
	End Sub
	
	'UPGRADE_WARNING: Event txtLivro.TextChanged 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 txtLivro_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLivro.TextChanged
		With Me.txtLivro
			If Len(.Text) = 0 Then
				Me.txtBarra.Enabled = True
				Me.txtBarra.BackColor = System.Drawing.ColorTranslator.FromOle(&H80000005)
				System.Windows.Forms.Application.DoEvents()
			Else
				Me.txtBarra.Enabled = False
				Me.txtBarra.BackColor = System.Drawing.ColorTranslator.FromOle(&H8000000F)
			End If
		End With
	End Sub
	
	'UPGRADE_WARNING: Event txtZona.TextChanged 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 txtZona_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtZona.TextChanged
		With Me.txtZona
			If Len(.Text) = 0 Then
				Me.txtBarra.Enabled = True
				Me.txtBarra.BackColor = System.Drawing.ColorTranslator.FromOle(&H80000005)
				System.Windows.Forms.Application.DoEvents()
			Else
				Me.txtBarra.Enabled = False
				Me.txtBarra.BackColor = System.Drawing.ColorTranslator.FromOle(&H8000000F)
			End If
		End With
	End Sub
	
	Private Sub txtZona_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtZona.Enter
		With Me.txtZona
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtZona_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtZona.Leave
		With Me.txtZona
			.Text = VB6.Format(.Text, "000")
			istrZona = .Text
		End With
	End Sub
	
	Private Sub txtLivro_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLivro.Enter
		With Me.txtLivro
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtLivro_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLivro.Leave
		With Me.txtLivro
			.Text = VB6.Format(.Text, "00")
			istrLivro = .Text
		End With
	End Sub
	
	Private Sub txtConta_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtConta.Enter
		With Me.txtConta
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtConta_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtConta.Leave
		With Me.txtConta
			.Text = VB6.Format(.Text, "000000")
			istrConta = .Text
		End With
	End Sub
	
	Private Sub cmdBuscar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdBuscar.Click
		Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
		Me.cmdBuscar.Enabled = False
		System.Windows.Forms.Application.DoEvents()
		Call BuscaUnidade()
		Me.cmdBuscar.Enabled = True
		'Call Me.cmdBuscar.SetFocus
		Me.Cursor = System.Windows.Forms.Cursors.Default
		If Me.txtZona.Enabled Then
			Me.txtLivro.Text = ""
			Me.txtConta.Text = ""
			Call Me.txtZona.Focus()
		Else
			Me.txtBarra.Text = ""
			Call Me.txtBarra.Focus()
		End If
	End Sub
	
	Private Sub BuscaUnidade()
		'Busca os dados da unidade consumidora
		Dim lstrSql As String
		Dim lstrCpfCnpj As String
		Dim lstrRgIe As String
		Dim lrstConsulta As ADODB.Recordset
		
		lrstConsulta = New ADODB.Recordset
		If Me.opbGrupoB.Checked Then
			istrGrupo = "B"
		Else
			istrGrupo = "A"
		End If
		Call LimpaCamposConsumidor()
		If Len(Trim(istrZona)) > 0 And Len(Trim(istrLivro)) > 0 And Len(Trim(istrConta)) > 0 Then
			lstrSql = ""
			lstrSql = lstrSql & "SELECT `u`.`nome`, "
			lstrSql = lstrSql & "       `u`.`end`, "
			lstrSql = lstrSql & "       `u`.`numero`, "
			lstrSql = lstrSql & "       `u`.`complement`, "
			lstrSql = lstrSql & "       `u`.`bairro`, "
			lstrSql = lstrSql & "       `u`.`cidade`, "
			lstrSql = lstrSql & "       `u`.`cep`, "
			lstrSql = lstrSql & "       `u`.`uf`, "
			lstrSql = lstrSql & "       `u`.`distrito`, "
			lstrSql = lstrSql & "       `u`.`lote`, "
			lstrSql = lstrSql & "       `u`.`quadra`, "
			lstrSql = lstrSql & "       `u`.`cons_id` , "
			lstrSql = lstrSql & "       `u`.`unid_id`, "
			lstrSql = lstrSql & "       `u`.`cpf_cnpj`, "
			lstrSql = lstrSql & "       `u`.`rg`, "
			lstrSql = lstrSql & "       `u`.`insc`, "
			lstrSql = lstrSql & "       if(`u`.`situacao`=""L"",""LIGADO"", "
			lstrSql = lstrSql & "         if(`u`.`situacao`=""D"",""DESLIGADO"", "
			lstrSql = lstrSql & "           if(`u`.`situacao`=""C"",""CORTADO"", "
			lstrSql = lstrSql & "             if(`u`.`situacao`=""I"",""DESATIVADO"", "
			lstrSql = lstrSql & "               if(`u`.`situacao`=""N"",""NÃO LIGADO"",""INDEFINIDO""))))) AS `situacao` "
			lstrSql = lstrSql & "  FROM `" & gstrDataBase & "`.`unid" & LCase(istrGrupo) & "` AS `u` "
			lstrSql = lstrSql & " WHERE `u`.`zona`  = """ & istrZona & """ "
			lstrSql = lstrSql & "   AND `u`.`livro` = """ & istrLivro & """ "
			lstrSql = lstrSql & "   AND `u`.`conta` = """ & istrConta & """ "
			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"'
					Me.lblNomeUc.Text = " " & IIf(IsDbNull(.Fields("nome").value), "Nome em branco!!!", .Fields("nome").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					Me.lblEndereco.Text = " " & 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"'
					Me.lblNumero.Text = 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.lblComplement.Text = " " & 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.lblBairro.Text = " " & 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.lblCidade.Text = " " & 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.lblLote.Text = 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.lblQuadra.Text = 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.lblCep.Text = IIf(IsDbNull(.Fields("cep").value), "", .Fields("cep").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					Me.lblUf.Text = 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.lblDistrito.Text = " " & 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"'
					lstrCpfCnpj = IIf(IsDbNull(.Fields("cpf_cnpj").value), "", .Fields("cpf_cnpj").value)
					If Len(lstrCpfCnpj) <= 11 Then
						Me.lblCpf.Text = FormataCPF(lstrCpfCnpj)
						'UPGRADE_WARNING: 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.lblRg.Text = IIf(IsDbNull(.Fields("rg").value), "", .Fields("rg").value)
					Else
						Me.lblCpf.Text = FormataCNPJ(lstrCpfCnpj)
						'UPGRADE_WARNING: 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.lblRg.Text = IIf(IsDbNull(.Fields("insc").value), "", .Fields("insc").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"'
					Me.lblSituacao.Text = IIf(IsDbNull(.Fields("situacao").value), "LIGADO", .Fields("situacao").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					ilngConsId = 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"'
					ilngUnidId = IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").value)
					Call BuscaDadosReaviso()
				Else
					Call MsgBox("O identificar " & istrZona & "." & istrLivro & "." & istrConta & ", não foi encontrado", MsgBoxStyle.Information, gstrTituloMensagem)
					Call LimpaCamposConsumidor()
					If Me.txtZona.Enabled = True Then
						Me.txtZona.Focus()
					Else
						Me.txtBarra.Focus()
					End If
				End If
				If .State = 1 Then Call .Close()
			End With
		Else
			Call MsgBox("Faltou informar o identificador!!!", MsgBoxStyle.Information, gstrTituloMensagem)
			Call LimpaCamposConsumidor()
			If Me.txtZona.Enabled = True Then
				Me.txtZona.Focus()
			Else
				Me.txtBarra.Focus()
			End If
		End If
		'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
		Me.Cursor = System.Windows.Forms.Cursors.Default
	End Sub
	
	Private Sub LimpaCamposConsumidor()
		Me.lblNomeUc.Text = ""
		Me.lblEndereco.Text = ""
		Me.lblNumero.Text = ""
		Me.lblComplement.Text = ""
		Me.lblBairro.Text = ""
		Me.lblCidade.Text = ""
		Me.lblUf.Text = ""
		Me.lblLote.Text = ""
		Me.lblQuadra.Text = ""
		Me.lblCep.Text = ""
		Me.lblDistrito.Text = ""
		Me.lblCpf.Text = ""
		Me.lblRg.Text = ""
		Me.lblSituacao.Text = ""
		Me.lblEstadoReaviso.Text = ""
		ilngConsId = 0
		ilngUnidId = 0
	End Sub
	
	Private Sub frmConfereReaviso_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		Select Case KeyAscii
			Case System.Windows.Forms.Keys.Return
				Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
			Case System.Windows.Forms.Keys.Escape
				Call cmdFechar_Click(cmdFechar, New System.EventArgs())
		End Select
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
	
	Private Sub cmdFechar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFechar.Click
		Call Me.Close()
	End Sub
	
	Private Sub cmdProc_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdProc.Click
		Call frmLocalizaUnidade.Show()
		Call frmLocalizaUnidade.SetaLocalizaUnidade("U", Me)
	End Sub
	
	Public Sub SetaCodigo(ByVal alngUnidId As Integer, ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String, ByVal astrGrupo As String)
		Me.txtZona.Text = astrZona
		Me.txtLivro.Text = astrLivro
		Me.txtConta.Text = astrConta
		istrZona = astrZona
		istrLivro = astrLivro
		istrConta = astrConta
		'ilngConsId = alngConsId
		ilngUnidId = alngUnidId
		istrGrupo = astrGrupo
		Call cmdBuscar_Click(cmdBuscar, New System.EventArgs())
		If astrGrupo = "A" Then
			Me.opbGrupoA.Checked = True
		ElseIf astrGrupo = "B" Then 
			Me.opbGrupoB.Checked = True
		End If
	End Sub
	
	Private Sub BuscaDadosReaviso()
		Dim lstrSql As String
		Dim ldtePrazo As Date
		Dim llngConsId As Integer
		Dim lstrSituacao As String
		Dim lrstReaviso As ADODB.Recordset
		lrstReaviso = New ADODB.Recordset
		
		Me.lblEstadoReaviso.ForeColor = System.Drawing.ColorTranslator.FromOle(&H80000012)
		If ilngConsId > 0 And ilngUnidId > 0 Then
			lstrSql = ""
			lstrSql = lstrSql & "SELECT `concorte`.`cons_id`, "
			lstrSql = lstrSql & "       `concorte`.`prazoreav`, "
			lstrSql = lstrSql & "       `concorte`.`sit` "
			lstrSql = lstrSql & "  FROM `" & gstrDataBase & "`.`concorte` "
			lstrSql = lstrSql & " WHERE `concorte`.`zona`    = """ & istrZona & """ "
			lstrSql = lstrSql & "   AND `concorte`.`livro`   = """ & istrLivro & """ "
			lstrSql = lstrSql & "   AND `concorte`.`conta`   = """ & istrConta & """ "
			lstrSql = lstrSql & "   AND `concorte`.`unid_id` = """ & ilngUnidId & """ "
			If idblNumNf > 0 Then
				lstrSql = lstrSql & "   AND `concorte`.`numnf` = """ & idblNumNf & """ "
				lstrSql = lstrSql & "   AND `concorte`.`mesano` = """ & istrMesAno & """ "
			Else
				If Len(Me.txtMesAno.Text) > 0 Then
					lstrSql = lstrSql & "   AND `concorte`.`mesano` = """ & Me.txtMesAno.Text & """ "
				End If
			End If
			lstrSql = lstrSql & " ORDER BY `concorte`.`datapag` ASC, "
			lstrSql = lstrSql & "          CONCAT(RIGHT(`concorte`.`mesano`,4),LEFT(`concorte`.`mesano`,2)) DESC "
			Call Conectar(lstrSql, lrstReaviso)
			With lrstReaviso
				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"'
						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"'
						lstrSituacao = Trim(IIf(IsDbNull(.Fields("sit").value), "", .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"'
						ldtePrazo = CDate(IIf(IsDbNull(.Fields("prazoreav").value), BuscaDataBD, .Fields("prazoreav").value))
						Select Case lstrSituacao
							Case Is = "E"
								Me.lblEstadoReaviso.Text = "FATURA EM ABERTO" & vbCrLf & "ENTREGUE"
							Case Is = "R"
								Me.lblEstadoReaviso.Text = "FATURA EM ABERTO" & vbCrLf & "NÃO ENTREGUE"
								Me.lblEstadoReaviso.ForeColor = System.Drawing.ColorTranslator.FromOle(&HFF)
							Case Is = "P"
								Me.lblEstadoReaviso.Text = "PAGO"
								Me.lblEstadoReaviso.ForeColor = System.Drawing.ColorTranslator.FromOle(&HC000)
							Case Is = "C"
								Me.lblEstadoReaviso.Text = "FATURA EM ABERTO" & vbCrLf & "UNIDADE CORTADA"
						End Select
						If ldtePrazo < BuscaDataBD And lstrSituacao <> "P" Then
							Me.lblEstadoReaviso.Text = Me.lblEstadoReaviso.Text & vbCrLf & "REAVISO VENCIDO"
						End If
						If llngConsId <> ilngConsId Then
							Me.lblEstadoReaviso.Text = Me.lblEstadoReaviso.Text & vbCrLf & "TRANSFERIDO U.C."
						End If
					Else
						Me.lblEstadoReaviso.Text = "NÃO EXISTE REAVISO"
					End If
					Call .Close()
				End If
			End With
		Else
			Call MsgBox("Unidade consumidora não possue reaviso!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
		End If
		'UPGRADE_NOTE: Object lrstReaviso 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"'
		lrstReaviso = Nothing
	End Sub
	
	Private Sub txtMesAno_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtMesAno.Enter
		With Me.txtMesAno
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtMesAno_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtMesAno.Leave
		With Me.txtMesAno
			
			.Text = Replace(.Text, "_", "0")
			If CDbl(VB.Left(.Text, 2)) < 1 Or CDbl(VB.Left(.Text, 2)) > 12 Then
				Call MsgBox("Mês inválido!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
				Call txtMesAno.Focus()
				.SelectionStart = 0
				.SelectionLength = Len(.Text)
				System.Windows.Forms.Application.DoEvents()
			ElseIf VB.Right(.Text, 4) < "1951" Then 
				Call MsgBox("Ano inválido!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
				.Focus()
				.SelectionStart = 0
				.SelectionLength = Len(.Text)
				System.Windows.Forms.Application.DoEvents()
			Else
				If Len(Trim(Me.txtMesAno.Text)) > 0 And Len(Trim(istrZona)) > 0 And Len(Trim(istrLivro)) > 0 And Len(Trim(istrConta)) > 0 Then
					istrMesAno = Me.txtMesAno.Text
					Call cmdBuscar_Click(cmdBuscar, New System.EventArgs())
				End If
			End If
		End With
	End Sub
	
	Private Sub txtMesAno_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtMesAno.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 <> 8 And (KeyAscii < 48 Or KeyAscii > 57) Then 
			KeyAscii = 0
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
End Class