Imports System.Data.SqlClient



Public Class frmCadastroContato

    Dim _operacao As clsFuncoesGerais.Operacao
    Public Property Operacao() As clsFuncoesGerais.Operacao
        Get
            Return _operacao
        End Get
        Set(ByVal value As clsFuncoesGerais.Operacao)
            _operacao = value
        End Set
    End Property

    Dim _Codigo As Long
    Public Property Codigo() As Long
        Get
            Return _Codigo
        End Get
        Set(ByVal value As Long)
            _Codigo = value
        End Set
    End Property

    Private Sub frmCadastroContato_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


        If Operacao = clsFuncoesGerais.Operacao.Alteracao Then

            Dim clsContato As New clsContato
            Dim dr As SqlDataReader = clsContato.SelectCONTATO()
            If dr.Read() Then
                txtNome_cont.Text = CStr(dr("NOME_CONT"))
                txtDepartamento_Cont.Text = CStr(dr("DEPARTAMENTO_CONT"))
                txtCargo_cont.Text = CStr(dr("CARGO_CONT"))
                txtEmail_Cont.Text = CStr(dr("EMAIL_CONT"))
                mskTelefone_CONT.Text = CStr(dr("TELEFONE_CONT"))
                mskTelefax_Cont.Text = CStr(dr("TELEFAX_CONT"))
                mskCelular_CONT.Text = CStr(dr("CELULAR_CONT"))
            End If
        End If


    End Sub
    Private Sub btnGravar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGravar.Click
        If txtNome_cont.Text <> "" Then
            Dim clsContato As New clsContato
            With clsContato
                .CODIGO_EMP = CLng(txtCODIGO_EMP.Text)

                .NOME_CONT = txtNome_cont.Text
                .DEPARTAMENTO_CONT = txtDepartamento_Cont.Text
                .CARGO_CONT = txtCargo_cont.Text
                .EMAIL_CONT = txtEmail_Cont.Text
                .TELEFONE_CONT = mskTelefone_CONT.Text
                .TELEFAX_CONT = mskTelefax_Cont.Text
                .CELULAR_CONT = mskCelular_CONT.Text
                If Operacao = clsFuncoesGerais.Operacao.Inclusao Then
                    .CODIGO_CONT = clsFuncoesGerais.GetCodigo()
                    .InsertCONTATO()
                    MessageBox.Show("Registro gravado com sucesso!", "Aviso")
               Else
                    .CODIGO_CONT = Codigo
                    .UpdateCONTATO(CLng(Codigo))
                    MessageBox.Show("Registro alterado com sucesso!", "Aviso")
                End If
                Me.Close()
                Me.Dispose()
            End With
        End If
    End Sub

End Class
