Batista15 Posted April 21, 2009 at 09:05 PM Report #258062 Posted April 21, 2009 at 09:05 PM 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
Guest PauloR Posted April 21, 2009 at 10:07 PM Report #258088 Posted April 21, 2009 at 10:07 PM 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
Batista15 Posted April 21, 2009 at 10:13 PM Author Report #258089 Posted April 21, 2009 at 10:13 PM 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
Guest PauloR Posted April 21, 2009 at 10:35 PM Report #258093 Posted April 21, 2009 at 10:35 PM 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()
Batista15 Posted April 22, 2009 at 07:23 AM Author Report #258127 Posted April 22, 2009 at 07:23 AM 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" 😛
jpaulino Posted April 22, 2009 at 08:22 AM Report #258137 Posted April 22, 2009 at 08:22 AM 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
Batista15 Posted April 22, 2009 at 08:25 AM Author Report #258140 Posted April 22, 2009 at 08:25 AM 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!
jpaulino Posted April 22, 2009 at 08:31 AM Report #258146 Posted April 22, 2009 at 08:31 AM 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()
Batista15 Posted April 22, 2009 at 08:33 AM Author Report #258147 Posted April 22, 2009 at 08:33 AM Como estás a abrir o form ? myForm.Show ou Dim frm As New myForm frm.Show() ShowDialog()
jpaulino Posted April 22, 2009 at 09:28 AM Report #258167 Posted April 22, 2009 at 09:28 AM ShowDialog() Mostra lá o código
Batista15 Posted April 22, 2009 at 09:39 AM Author Report #258176 Posted April 22, 2009 at 09:39 AM Mostra lá o código Já consegui resolver! Brigado a quem ajudou!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now