Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Imports fatd_faturamento.ENTIDADE
Imports fatd_faturamento.BLL.Repositorio
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
	Private dt As DataTable
	Private objAtualizaDadosBanco As New entidadeAtualizaBancoDados
	Private repositorioAtualizaDadosBanco As New repositorioAtualizaBancoDados

	Private Sub txtBarra_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtBarra.TextChanged
		Try
			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
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtBarra_TextChanged" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtBarra_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtBarra.Enter
		Try
			With Me.txtBarra
				.SelectionStart = 0
				.SelectionLength = Len(.Text)
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtBarra_Enter" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	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()
		Try
			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()
					'TabEnter(System.Windows.Forms.Keys.Tab, EventArgs)
					'''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
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: VerificaBarras" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtConta_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtConta.TextChanged
		Try
			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
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtConta_TextChanged" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub
	Private Sub txtLivro_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLivro.TextChanged
		Try
			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
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLivro_TextChanged" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtZona_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtZona.TextChanged
		Try
			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
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtZona_TextChanged" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtZona_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtZona.Enter
		Try
			With Me.txtZona
				.SelectionStart = 0
				.SelectionLength = Len(.Text)
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtZona_Enter" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtZona_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtZona.Leave
		Try
			With Me.txtZona
				.Text = VB6.Format(.Text, "000")
				istrZona = .Text
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtZona_Leave" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLivro_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLivro.Enter
		Try
			With Me.txtLivro
				.SelectionStart = 0
				.SelectionLength = Len(.Text)
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLivro_Enter" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLivro_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLivro.Leave
		Try
			With Me.txtLivro
				.Text = VB6.Format(.Text, "00")
				istrLivro = .Text
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLivro_Leave" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtConta_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtConta.Enter
		Try
			With Me.txtConta
				.SelectionStart = 0
				.SelectionLength = Len(.Text)
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtConta_Enter" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtConta_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtConta.Leave
		Try
			With Me.txtConta
				.Text = VB6.Format(.Text, "000000")
				istrConta = .Text
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtConta_Leave" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub cmdBuscar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdBuscar.Click
		Try
			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
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmdBuscar_Click" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub BuscaUnidade()
		'Busca os dados da unidade consumidora
		Dim lstrSql As String
		Dim lstrCpfCnpj As String
		Dim lstrRgIe As String
		Try

			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`.`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 `uc_faturamento` AS `u` "
				lstrSql = lstrSql & " WHERE `u`.`zona`  = """ & istrZona & """ "
				lstrSql = lstrSql & "   AND `u`.`livro` = """ & istrLivro & """ "
				lstrSql = lstrSql & "   AND `u`.`conta` = """ & istrConta & """ "
				objAtualizaDadosBanco.QUERY_NAME = lstrSql
				dt = repositorioAtualizaDadosBanco.Consultar(objAtualizaDadosBanco)

				If dt.Rows.Count > 0 Then
					For Each row As DataRow In dt.Rows
						Me.lblNomeUC.Text = " " & IIf(IsDBNull(row.Item("nome")), "Nome em branco!!!", row.Item("nome"))
						Me.lblEndereco.Text = " " & IIf(IsDBNull(row.Item("end")), "", row.Item("end"))
						Me.lblNumero.Text = IIf(IsDBNull(row.Item("numero")), "", row.Item("numero"))
						Me.lblComplement.Text = " " & IIf(IsDBNull(row.Item("complement")), "", row.Item("complement"))
						Me.lblBairro.Text = " " & IIf(IsDBNull(row.Item("bairro")), "", row.Item("bairro"))
						Me.lblCidade.Text = " " & IIf(IsDBNull(row.Item("cidade")), "", row.Item("cidade"))
						Me.lblLote.Text = IIf(IsDBNull(row.Item("lote")), "", row.Item("lote"))
						Me.lblQuadra.Text = IIf(IsDBNull(row.Item("quadra")), "", row.Item("quadra"))
						Me.lblCep.Text = IIf(IsDBNull(row.Item("cep")), "", row.Item("cep"))
						Me.lblUf.Text = IIf(IsDBNull(row.Item("uf")), "", row.Item("uf"))
						Me.lblDistrito.Text = " " & IIf(IsDBNull(row.Item("distrito")), "", row.Item("distrito"))
						lstrCpfCnpj = IIf(IsDBNull(row.Item("cpf_cnpj")), "", row.Item("cpf_cnpj"))
						If Len(lstrCpfCnpj) <= 11 Then
							Me.lblCpf.Text = FormataCPF(lstrCpfCnpj)
							Me.lblRg.Text = IIf(IsDBNull(row.Item("rg")), "", row.Item("rg"))
						Else
							Me.lblCpf.Text = FormataCNPJ(lstrCpfCnpj)
							Me.lblRg.Text = IIf(IsDBNull(row.Item("insc")), "", row.Item("insc"))
						End If
						Me.lblSituacao.Text = IIf(IsDBNull(row.Item("situacao")), "LIGADO", row.Item("situacao"))
						ilngConsId = IIf(IsDBNull(row.Item("cons_id")), 0, row.Item("cons_id"))
						ilngUnidId = IIf(IsDBNull(row.Item("id")), 0, row.Item("id"))
						Call BuscaDadosReaviso()
					Next
				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

				dt = Nothing

			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

			Me.Cursor = System.Windows.Forms.Cursors.Default
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: BuscaUnidade" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub LimpaCamposConsumidor()
		Try
			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
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: LimpaCamposConsumidor" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub frmConfereReaviso_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
		Try
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			Select Case KeyAscii
				Case System.Windows.Forms.Keys.Return
					TabEnter(KeyAscii, eventArgs)
				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
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: frmConfereReaviso_KeyPress" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	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
		Try
			Call frmLocalizaUnidade.Show()
			Call frmLocalizaUnidade.SetaLocalizaUnidade("U", Me)
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmdProc_Click" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	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)
		Try
			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
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: SetaCodigo" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub BuscaDadosReaviso()
		Dim lstrSql As String
		Dim ldtePrazo As Date
		Dim llngConsId As Integer
		Dim lstrSituacao As String

		Try
			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 `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 "
				objAtualizaDadosBanco.QUERY_NAME = lstrSql
				dt = repositorioAtualizaDadosBanco.Consultar(objAtualizaDadosBanco)


				If dt.Rows.Count > 0 Then
					For Each row As DataRow In dt.Rows
						llngConsId = CInt(IIf(IsDBNull(row.Item("cons_id")), 0, row.Item("cons_id")))
						lstrSituacao = Trim(IIf(IsDBNull(row.Item("sit")), "", row.Item("sit")))
						ldtePrazo = CDate(IIf(IsDBNull(row.Item("prazoreav")), Date.Now, row.Item("prazoreav")))
						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
					Next
				Else
					Me.lblEstadoReaviso.Text = "NÃO EXISTE REAVISO"
				End If

				dt = Nothing

			Else
				Call MsgBox("Unidade consumidora não possue reaviso!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
			End If

		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: BuscaDadosReaviso" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try

	End Sub

	Private Sub txtMesAno_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtMesAno.Enter
		Try
			With Me.txtMesAno
				.SelectionStart = 0
				.SelectionLength = Len(.Text)
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtMesAno_Enter" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtMesAno_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtMesAno.Leave
		Try
			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
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtMesAno_Leave" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtMesAno_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtMesAno.KeyPress
		Try
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = System.Windows.Forms.Keys.Return Then
				TabEnter(KeyAscii, eventArgs)
			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
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtMesAno_KeyPress" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub frmConfereReaviso_Load(sender As Object, e As EventArgs) Handles MyBase.Load
		Try
			Me.txtMesAno.Text = Format(Month(Date.Now), "00") & "/" & Year(Date.Now)
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtMesAno_KeyPress" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
		Exit Sub
		End Try
	End Sub
End Class