Public Class frmConsultaFuncionario


    Private Sub btnPesquisa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPesquisa.Click
        Call Carregagrid()
    End Sub
    Public Sub Carregagrid()
        Try
            'Instancia o clsFuncionario
            Dim clsFuncionario As New clsFuncionario
            'Carrega a grid com os dados de Fucnionarios
            gvPesquisa.DataSource = clsFuncionario.SelectFUNCIONARIOFORgrid(txtPesquisa.Text).Tables(0)
            'gvEmpresa.Columns(0).HeaderText = "Código"
            gvPesquisa.Columns(1).HeaderText = "Cargo"
            gvPesquisa.Columns(2).HeaderText = "Funcionário"
            gvPesquisa.Columns(3).HeaderText = "Cidade"
            gvPesquisa.Columns(4).HeaderText = "Estado"
            gvPesquisa.Columns(0).Visible = False
            gvPesquisa.Focus()
        Catch ex As Exception
            MsgBox("Descrição do Erro : " & Err.Description & vbCrLf & "Erro Nr." & Err.Number, MsgBoxStyle.Information, "Aviso")
        End Try
    End Sub
    Private Sub btnNovo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNovo.Click
        Dim frmCadastroFuncionario As New frmCadastroFuncionario
        With frmCadastroFuncionario
            .Operacao = clsFuncoesGerais.Operacao.Inclusao
            .MdiParent = MdiParent
            .Show()
        End With
    End Sub
    Private Sub frmConsultaFuncionario_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.AcceptButton = btnPesquisa
    End Sub

    Private Sub btnAlterar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAlterar.Click

        Call Alterar()

    End Sub
    Private Sub btnExcluir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExcluir.Click
        If gvPesquisa.RowCount >= 1 Then
            Dim intCodigo As Long = CLng(gvPesquisa.CurrentRow.Cells(0).Value)
            Dim clsFuncionario As New clsFuncionario
            With clsFuncionario
                .DeleteFUNCIONARIO(intCodigo)
                MessageBox.Show("Registro excluído!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly)
                Call Carregagrid()
            End With
        End If
    End Sub

    Private Sub gdPesquisa_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles gvPesquisa.CellClick
        Call Alterar()
    End Sub

    Private Sub Alterar()
        If gvPesquisa.RowCount >= 1 Then
            Dim intCodigo As Long = CLng(gvPesquisa.CurrentRow.Cells(0).Value)
            Dim frmCadastroFuncionario As New frmCadastroFuncionario
            With frmCadastroFuncionario
                .Operacao = clsFuncoesGerais.Operacao.Alteracao
                .Codigo = CLng(intCodigo)
                .MdiParent = MdiParent
                .Show()
            End With
        End If
    End Sub



End Class
