"A arte de programar consiste na arte de organizar e dominar a complexidade."

terça-feira, 1 de março de 2016

Ficha nº28

1.

Código:

Private Sub Bloquear()
    Text1.Enabled = False
    Text2.Enabled = False
    Text3.Enabled = False
    Text4.Enabled = False
End Sub

Private Sub Desbloquear()
    Text1.Enabled = True
    Text2.Enabled = True
    Text3.Enabled = True
    Text4.Enabled = True
End Sub

Private Sub Limpar()
    Text1.Text = ""
    Text2.Text = ""
    Text3.Text = ""
    Text4.Text = ""
End Sub

Private Sub Command1_Click()
    If Command1.Caption = "Novo" Then
        Data1.Recordset.AddNew
        Desbloquear
        Limpar
        Command2.Enabled = True
        Command3.Enabled = False
        Command4.Enabled = False
        Command5.Enabled = False
        Command6.Enabled = False
        Command7.Enabled = False
        Command8.Enabled = False
        Command9.Enabled = False
        Command1.Caption = "Cancelar"
    Else
        Data1.Recordset.CancelUpdate
        Bloquear
        Command2.Enabled = False
        Command3.Enabled = True
        Command5.Enabled = True
        Command4.Enabled = True
        Command6.Enabled = True
        Command7.Enabled = True
        Command8.Enabled = True
        Command9.Enabled = True
        Command1.Caption = "Novo"
    End If
End Sub

Private Sub Command2_Click()
    If Text1.Text = "" Then
        MsgBox "Preencha o nome", vbCritical, "Aviso"
        Text1.SetFocus
    ElseIf Text3.Text = "" Then
        MsgBox "Preencha o número de sócio", vbCritical, "Aviso"
        Text3.SetFocus
    ElseIf Text4.Text = "" Then
        MsgBox "Preencha a quota", vbCritical, "Aviso"
        Text4.SetFocus
    Else
        Data1.Recordset.Update
        Command1.Caption = "Novo"
        Command3.Caption = "Editar"
        Bloquear
        Command2.Enabled = False
        Command3.Enabled = True
        Command5.Enabled = True
        Command4.Enabled = True
        Command6.Enabled = True
        Command7.Enabled = True
        Command8.Enabled = True
        Command9.Enabled = True
        Command1.Enabled = True
    End If
End Sub

Private Sub Command3_Click()
    If Command3.Caption = "Editar" Then
        Data1.Recordset.Edit
        Desbloquear
        Command2.Enabled = True
        Command1.Enabled = False
        Command4.Enabled = False
        Command5.Enabled = False
        Command6.Enabled = False
        Command7.Enabled = False
        Command8.Enabled = False
        Command9.Enabled = False
        Command3.Caption = "Cancelar"
    Else
        Data1.Recordset.CancelUpdate
        Bloquear
        Command2.Enabled = False
        Command1.Enabled = True
        Command4.Enabled = True
        Command5.Enabled = True
        Command6.Enabled = True
        Command7.Enabled = True
        Command8.Enabled = True
        Command9.Enabled = True
        Command3.Caption = "Editar"
    End If
End Sub

Private Sub Command4_Click()
    Dim p As String, n As Integer
    
    n = 0
    
    p = UCase(InputBox("Que modalidade deseja procurar?", "Procura"))
    If Trim(p) <> "" Then
        Data1.Recordset.MoveFirst
        Do While Not Data1.Recordset.EOF
            If n = 0 Then
                Data1.Recordset.FindFirst "modalidade='" & p & "'"
                n = 1
                MsgBox "Registo encontrado", vbInformation, "Registo"
                If Data1.Recordset.NoMatch = True Then
                    MsgBox "Não existe esse registo", vbCritical, "Aviso"
                    Exit Do
                End If
            End If
            If n = 1 Then
                Data1.Recordset.FindNext "modalidade='" & p & "'"
                If Data1.Recordset.NoMatch = True Then
                    MsgBox "Não existem mais registos", vbCritical, "Aviso"
                    Exit Do
                End If
            End If
        Loop
    End If
End Sub

Private Sub Command5_Click()
    Data1.Recordset.MoveLast
End Sub

Private Sub Command6_Click()
    Data1.Recordset.MovePrevious
    If Data1.Recordset.BOF Then
        Data1.Recordset.MoveFirst
    End If
End Sub

Private Sub Command7_Click()
    Data1.Recordset.MoveNext
    If Data1.Recordset.EOF Then
        Data1.Recordset.MoveLast
    End If
End Sub

Private Sub Command8_Click()
    Data1.Recordset.MoveFirst
End Sub

Private Sub Command9_Click()
    Data1.Recordset.Delete
    MsgBox "Registo eliminado", vbInformation, "Eliminado"
    Data1.Recordset.MoveNext
    If Data1.Recordset.EOF Then
        Data1.Recordset.MovePrevious
        If Data1.Recordset.BOF Then
            MsgBox "Não há resgistos!", vbCritical, "Aviso"
            Command9.Enabled = False
        End If
    End If
End Sub

Private Sub Form_Load()
    Bloquear
    Command2.Enabled = False
End Sub

Sem comentários:

Enviar um comentário