Jump to content

Recommended Posts

Posted

Boas Pessoal! A minha duvida e o seguinte, eu tenho 3 if's em que se as 3 textboxs nao tiverem com dados aparece um erro, e logo de seguida pergunta se quer guardar o registo! E queria tipo meter um "stop" para enquanto nao estiver tudo preenchido nao passa para a mensagem do querer guardar! Obrigado

Try



            Dim lm2 As String = "INSERT INTO `avaliacao` (`Id_Cliente`, `Data`, `Valor_Glicemia`, `Tensao_Arterial_Sistolica`, `Tensao_Arterial_Diastolica`) VALUES (@Id_Cliente, @Data, @Valor_Glicemia, @Tensao_Arterial_Sistolica, @Tensao_Arterial_Diastolica)"

            'Inicia uma ligação à base de dados
            Using connection As New OleDbConnection(My.Settings.ligacao)

                'Define o comando e os parâmetros
                Dim command As New OleDbCommand(lm2, connection)


                If Valor_GlicemiaTextBox.Text = Nothing Then
                    MsgBox("Preencha o Valor de Glicemia!", MsgBoxStyle.Information, "Valor Glicemia")

                End If
                If Tensao_ArterialTextBox.Text = Nothing Then

                    MsgBox("Preencha a Tensão Arterial Sistolica!", MsgBoxStyle.Information, "Tensão Arterial  Sistolica")

                End If
                If TextBox2.Text = Nothing Then

                    MsgBox("Preencha a Tensão Arterial Diastolica!", MsgBoxStyle.Information, "Tensão Arterial  Diastolica")

                End If



                Dim msg = MsgBox("Pretende guardar o registo? ", MsgBoxStyle.YesNo)
                If msg = MsgBoxResult.Yes Then

                    


                    command.Parameters.Add("@Id_Cliente", OleDbType.Numeric).Value = TextBox1.Text


                    If DataDateTimePicker.Text.Trim <> String.Empty Then

                        command.Parameters.Add("@Data", OleDbType.DBDate).Value = DataDateTimePicker.Text
                    Else
                        command.Parameters.Add("@Data", OleDbType.DBDate).Value = 0
                    End If


                    If Valor_GlicemiaTextBox.Text.Trim <> String.Empty Then

                        command.Parameters.Add("@Valor_Glicemia", OleDbType.Integer).Value = Valor_GlicemiaTextBox.Text
                    Else
                        command.Parameters.Add("@Valor_Glicemia", OleDbType.Integer).Value = 0
                    End If

                    If Tensao_ArterialTextBox.Text.Trim <> String.Empty Then

                        command.Parameters.Add("@Tensao_Arterial_Sistolica", OleDbType.Integer).Value = Tensao_ArterialTextBox.Text
                    Else
                        command.Parameters.Add("@Tensao_Arterial_Sistolica", OleDbType.Integer).Value = 0
                    End If

                    If TextBox2.Text.Trim <> String.Empty Then

                        command.Parameters.Add("@Tensao_Arterial_Diastolica", OleDbType.Integer).Value = TextBox2.Text
                    Else
                        command.Parameters.Add("@Tensao_Arterial_Diastolica", OleDbType.Integer).Value = 0
                    End If



                    If Valor_GlicemiaTextBox.Text = " " Then
                        Me.Visible = False
                        Valor_GlicemiaTextBox.Clear()
                        Tensao_ArterialTextBox.Clear()
                        TextBox2.Clear()
                    End If



                    If Tensao_ArterialTextBox.Text = " " Then
                        Me.Visible = False
                        Valor_GlicemiaTextBox.Clear()
                        Tensao_ArterialTextBox.Clear()
                        TextBox2.Clear()
                    End If



                    If TextBox2.Text = " " Then
                        Me.Visible = False
                        Valor_GlicemiaTextBox.Clear()
                        Tensao_ArterialTextBox.Clear()
                        TextBox2.Clear()
                    End If



                ElseIf msg = MsgBoxResult.No Then

                End If




                'Abre a ligação e insere o registo
                connection.Open()
                Dim x As Integer = command.ExecuteNonQuery()
                If x <> 1 Then
                    Throw New ArgumentException("Não foi possível inserir o registo na base de dados!")

                End If

            End Using









        Catch ex As Exception
            MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)


        End Try


Posted

Coloca este  código antes do "try" que deve resolver o problema  😛

        If Valor_GlicemiaTextBox.Text = Nothing Then
            MsgBox("Preencha o Valor de Glicemia!", MsgBoxStyle.Information, "Valor Glicemia")
            Exit Sub
        ElseIf Tensao_ArterialTextBox.Text = Nothing Then
            MsgBox("Preencha a Tensão Arterial Sistolica!", MsgBoxStyle.Information, "Tensão Arterial  Sistolica")
            Exit Sub
        ElseIf TextBox2.Text = Nothing Then
            MsgBox("Preencha a Tensão Arterial Diastolica!", MsgBoxStyle.Information, "Tensão Arterial  Diastolica")
            Exit Sub
        End If
Posted

Coloca este  código antes do "try" que deve resolver o problema  🙂

        If Valor_GlicemiaTextBox.Text = Nothing Then
            MsgBox("Preencha o Valor de Glicemia!", MsgBoxStyle.Information, "Valor Glicemia")
            Exit Sub
        ElseIf Tensao_ArterialTextBox.Text = Nothing Then
            MsgBox("Preencha a Tensão Arterial Sistolica!", MsgBoxStyle.Information, "Tensão Arterial  Sistolica")
            Exit Sub
        ElseIf TextBox2.Text = Nothing Then
            MsgBox("Preencha a Tensão Arterial Diastolica!", MsgBoxStyle.Information, "Tensão Arterial  Diastolica")
            Exit Sub
        End If

Resolvidissimo muito obrigada 😛 agora o problema e esta parte:

If Valor_GlicemiaTextBox.Text = " " Then
                        Me.Visible = False
                        Valor_GlicemiaTextBox.Clear()
                        Tensao_ArterialTextBox.Clear()
                        TextBox2.Clear()
                    End If



                    If Tensao_ArterialTextBox.Text = " " Then
                        Me.Visible = False
                        Valor_GlicemiaTextBox.Clear()
                        Tensao_ArterialTextBox.Clear()
                        TextBox2.Clear()
                    End If



                    If TextBox2.Text = " " Then
                        Me.Visible = False
                        Valor_GlicemiaTextBox.Clear()
                        Tensao_ArterialTextBox.Clear()
                        TextBox2.Clear()
                    End If

Que é para fazer que quando tiver preenchido,a form fecha e as textboxs limpa, o que não está a fazer

Posted

Resolvidissimo muito obrigada 🙂 agora o problema e esta parte:

...

Que é para fazer que quando tiver preenchido,a form fecha e as textboxs limpa, o que não está a fazer

Não precebi  😛

Queres fechar o form depois de gravar? Não precisas de limpar os campos faz me.close()

Posted

Não precebi  🙂

Queres fechar o form depois de gravar? Não precisas de limpar os campos faz me.close()

Se fechar apenas o form e abrir novamente os dados que tinha inserido estão la a mesma, por isso o ".CLEAR"  😛

Posted

Se fechar apenas o form e abrir novamente os dados que tinha inserido estão la a mesma, por isso o ".CLEAR"  😛

Não entendi! Não estás a criar uma nova instância do form para o abri ?

Dim frm As New myForm

Posted

Não entendi! Não estás a criar uma nova instância do form para o abri ?

Dim frm As New myForm

Essa parte do código não esta a funcionar! Porque o que tenho no código e se estiver preenchido ( " ") Me.close e faz um clear as textboxs! e nao esta a fazer, nem fecha nem faz clear! Porque se não fizer clear, retroceder e abrir novamente a form estão la os últimos dados que inseri!

Posted

Essa parte do código não esta a funcionar! Porque o que tenho no código e se estiver preenchido ( " ") Me.close e faz um clear as textboxs! e nao esta a fazer, nem fecha nem faz clear! Porque se não fizer clear, retroceder e abrir novamente a form estão la os últimos dados que inseri!

Como estás a abrir o form ?

myForm.Show

ou

Dim frm As New myForm

frm.Show()

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.