
Programando Botão Gravar Parte 1 em VB.net
Neste episódio vamos dar início a programação do botão gravar fazendo a parte de inclusão do cliente.
Veja o vídeo passo a passo abaixo:
Código do botão gravar:
Private Sub tsbGravar_Click(sender As Object, e As EventArgs) Handles tsbGravar.Click
Dim cliente As New CAD_CLIENTE
Dim par As New List(Of SqlParameter)
Dim SQL As String
Dim blnEndereco As Boolean = False
Dim blnNumero As Boolean = False
Dim blnTelefone As Boolean = False
Try
Select Case intOpcao
Case Opcao.Incluir
SQL = "INSERT INTO CAD_CLIENTE ("
If txtNome.TextLength = 0 Then
epValida.SetError(txtNome, "Nome do cliente é obrigatório.")
txtNome.Focus()
Exit Sub
Else
par.Add(New SqlParameter("@NOME", txtNome.Text))
SQL = SQL & "NOME"
epValida.SetError(txtNome, "")
End If
If txtEndereco.TextLength > 0 Then
par.Add(New SqlParameter("@ENDERECO", txtEndereco.Text))
SQL = SQL & ", ENDERECO"
blnEndereco = True
End If
If txtNumero.TextLength > 0 Then
par.Add(New SqlParameter("@NUMERO", txtNumero.Text))
SQL = SQL & ", NUMERO"
blnNumero = True
End If
If txtTelefone.TextLength > 0 Then
par.Add(New SqlParameter("@TELEFONE", txtTelefone.Text))
SQL = SQL & ", TELEFONE"
blnTelefone = True
End If
SQL = SQL & ") VALUES (@NOME"
If blnEndereco = True Then
SQL = SQL & ", @ENDERECO"
End If
If blnNumero = True Then
SQL = SQL & ", @NUMERO"
End If
If blnTelefone = True Then
SQL = SQL & ", @TELEFONE"
End If
SQL = SQL & ")"
If cliente.NovoCliente(SQL, par) = True Then
MessageBox.Show("Cliente adicionado com sucesso!")
intOpcao = Opcao.Cancelar
tsbCancelar_Click(Nothing, Nothing)
Else
MessageBox.Show("Problema ao tentar adicionar o cliente!")
End If
Case Opcao.Editar
End Select
Catch ex As Exception
End Try
End Sub


