Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Data.SqlClient
- Public Class Faith
- Public Property stringpass As String
- Dim conn As New SqlConnection("Data Source=LAPTOP-AVEPA34K;Initial Catalog=User RegistrationKH; Integrated Security = True")
- Private Sub load_datagrid()
- Dim cmd As New SqlCommand
- Dim adapter As New SqlDataAdapter
- Dim table As New DataTable
- Dim bindingsource As New BindingSource
- Dim cmd1 As New SqlCommand
- Dim adapter1 As New SqlDataAdapter
- Dim table1 As New DataTable
- Dim bindingsource1 As New BindingSource
- Try
- conn.Open()
- cmd = New SqlCommand("SELECT ID,Lastname,Firstname,Birthday,Weight,Height,Sex,Age,BodyMassIndex,NutritionalStatus,HeightforAge FROM kinder", conn)
- adapter = New SqlDataAdapter(cmd)
- adapter.Fill(table)
- bindingsource.DataSource = table
- DataGridView1.DataSource = bindingsource
- adapter.Update(table)
- DataGridView1.Refresh()
- Catch ex As Exception
- MessageBox.Show(ex.Message)
- Finally
- conn.Close()
- End Try
- End Sub
- Private Sub Addbtn_Click(sender As Object, e As EventArgs) Handles Addbtn.Click
- 'Body Mass Index Computation'
- Dim body As Double
- Dim bmiRounded As Double
- body = (Weight.Text * 703) / (Heightm.Text * Heightm.Text)
- bmiRounded = Math.Round(bmiRounded, 1)
- BMI.Text = bmiRounded
- Select Case BMI.Text
- Case 0.0 To 18.5
- BMI.Text = "Severeley Stunted"
- Nutritional.Text = "Severeley Stunted"
- HeightAge.Text = "Severeley Stunted"
- Case 18.6 To 24.9
- BMI.Text = "Stunted"
- Nutritional.Text = "Stunted"
- HeightAge.Text = "Stunted"
- Case 25.0 To 29.9
- BMI.Text = "Normal"
- Nutritional.Text = "Normal"
- HeightAge.Text = "Normal"
- Case Is >= 30.0
- BMI.Text = "Above Normal"
- Nutritional.Text = "Above Normal"
- HeightAge.Text = "Above Normal"
- End Select
- 'Messag for Incomplete data'
- If LastName.Text = "" Then
- MessageBox.Show("Please fill the blanks", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
- ElseIf FirstName.Text = "" Then
- MessageBox.Show("Please fill the blanks", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
- ElseIf Weight.Text = "" Then
- MessageBox.Show("Please fill the blanks", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
- ElseIf Weight2.SelectedIndex <> 0 And Weight2.SelectedIndex <> 1 And Weight2.SelectedIndex <> 2 And Weight2.SelectedIndex <> 3 Then
- MessageBox.Show("Invalid data", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
- ElseIf Sex.SelectedIndex <> 0 And Sex.SelectedIndex <> 1 Then
- MessageBox.Show("Invalid data", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
- ElseIf Heightm.Text = "" Then
- MessageBox.Show("Please fill the blanks", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
- ElseIf Height2.SelectedIndex <> 0 And Height2.SelectedIndex <> 1 And Height2.SelectedIndex <> 2 And Height2.SelectedIndex <> 3 Then
- MessageBox.Show("Invalid data", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
- ElseIf Age.Text = "" Then
- MessageBox.Show("Please fill the blanks", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
- ElseIf Nutritional.Text = "" Then
- MessageBox.Show("Please fill the blanks", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
- ElseIf HeightAge.Text = "" Then
- MessageBox.Show("Please fill the blanks", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
- ElseIf BMI.Text = "" Then
- MessageBox.Show("Please fill the blanks", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
- ElseIf cHeight.Text = "" Then
- MessageBox.Show("Please fill the blanks", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
- ElseIf cWeight.Text = "" Then
- MessageBox.Show("Please fill the blanks", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
- Else
- Dim insertquery As String = "INSERT INTO Faith(Lastname,Firstname,Birthday,Weight,Height,Sex,Age,BodyMassIndex,NutritionalStatus,HeightforAge) VALUES(@Lastname,@Firstname,@Birthday,@Weight,@Height,@Sex,@Age,@BodyMassIndex,@NutritionalStatus,@HeightforAge)"
- executequery(insertquery)
- MessageBox.Show("Registered Successfully", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information)
- id.Clear()
- LastName.Clear()
- FirstName.Clear()
- Sex.Text = ""
- Age.Clear()
- Nutritional.Clear()
- HeightAge.Clear()
- BMI.Clear()
- Weight.Clear()
- Heightm.Clear()
- cWeight.Clear()
- cHeight.Clear()
- Height2.Text = ""
- Weight2.Text = ""
- End If
- End Sub
- Public Sub executequery(ByVal query As String)
- Dim cmd As New SqlCommand(query, conn)
- cmd.Parameters.AddWithValue("@Lastname", LastName.Text)
- cmd.Parameters.AddWithValue("@Firstname", FirstName.Text)
- cmd.Parameters.Add("@Birthday", SqlDbType.Date).Value = Birthdate.Text
- cmd.Parameters.AddWithValue("@Weight", Weight.Text)
- cmd.Parameters.AddWithValue("@Height", Heightm.Text)
- cmd.Parameters.AddWithValue("@Sex", Sex.SelectedItem)
- cmd.Parameters.AddWithValue("@Age", Age.Text)
- cmd.Parameters.AddWithValue("@BodyMassIndex", BMI.Text)
- cmd.Parameters.AddWithValue("@NutritionalStatus", Nutritional.Text)
- cmd.Parameters.AddWithValue("@HeightforAge", HeightAge.Text)
- conn.Open()
- cmd.ExecuteNonQuery()
- conn.Close()
- load_datagrid()
- End Sub
- Private Sub Deletebtn_Click(sender As Object, e As EventArgs) Handles Deletebtn.Click
- Dim deletequery As String = "DELETE from Faith WHERE LastName = @LastName, FirstName = @FirstName, Birthday = @Birthday, Weight = @Weight, Height = @Height, Sex = @Sex, Age = @Age, BMI = @BodyMassIndex, Nutritional = @NutritionalStatus, HeightAge = @HeightforAge"
- executequery(deletequery)
- MessageBox.Show("Data Deleted")
- End Sub
- Private Sub Updatebtn_Click(sender As Object, e As EventArgs) Handles Updatebtn.Click
- Dim updatequery As String = "UPDATE VBSQL Set LastName = '" & LastName.Text & "',FirstName ='" & FirstName.Text & "',Birthday ='" & Birthdate.Text & "',Weight ='" & Weight.Text & "',Height ='" & Heightm.Text & "',Sex ='" & Sex.SelectedItem & "',Age ='" & Age.Text & "',BMI='" & BMI.Text & "',NutritionalStatus='" & Nutritional.Text & "',HeightforAge='" & HeightAge.Text & "WHERE Id = " & id.Text & ""
- executequery(updatequery)
- MessageBox.Show("Your data was successfully Updated", "K-Health")
- End Sub
- Private Sub Nutritional_TextChanged(sender As Object, e As EventArgs) Handles Nutritional.TextChanged
- End Sub
- Private Sub HeightAge_TextChanged(sender As Object, e As EventArgs) Handles HeightAge.TextChanged
- End Sub
- Private Sub BMI_TextChanged(sender As Object, e As EventArgs) Handles BMI.TextChanged
- End Sub
- Private Sub Student_Form_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- 'TODO: This line of code loads data into the 'User_RegistrationKHDataSet3.Faith' table. You can move, or remove it, as needed.
- passingtxt.Text = stringpass
- Me.FaithTableAdapter.Fill(Me.User_RegistrationKHDataSet3.Faith)
- End Sub
- Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
- If e.RowIndex >= 0 Then
- Dim index As Integer
- index = e.RowIndex
- Dim selectedrow As DataGridViewRow
- selectedrow = DataGridView1.Rows(index)
- id.Text = selectedrow.Cells(0).Value.ToString
- LastName.Text = selectedrow.Cells(0).Value.ToString
- FirstName.Text = selectedrow.Cells(1).Value.ToString
- Birthdate.Text = selectedrow.Cells(2).Value.ToString
- Weight.Text = selectedrow.Cells(3).Value.ToString
- Heightm.Text = selectedrow.Cells(4).Value.ToString
- Sex.Text = selectedrow.Cells(5).Value.ToString
- Age.Text = selectedrow.Cells(6).Value.ToString
- BMI.Text = selectedrow.Cells(7).Value.ToString
- Nutritional.Text = selectedrow.Cells(8).Value.ToString
- HeightAge.Text = selectedrow.Cells(9).Value.ToString
- End If
- End Sub
- Private Sub Weight2_Click(sender As Object, e As EventArgs)
- End Sub
- Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Weight2.SelectedIndexChanged
- End Sub
- Private Sub Weight2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Weight2.KeyPress
- If Not (Asc(e.KeyChar) = 15) Then
- Dim allowchar As String = ""
- If Not allowchar.Contains(e.KeyChar.ToString) Then
- e.KeyChar = ChrW(0)
- e.Handled = True
- End If
- End If
- End Sub
- Private Sub Height2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Height2.KeyPress
- If Not (Asc(e.KeyChar) = 15) Then
- Dim allowchar As String = ""
- If Not allowchar.Contains(e.KeyChar.ToString) Then
- e.KeyChar = ChrW(0)
- e.Handled = True
- End If
- End If
- End Sub
- Private Sub Sex_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Sex.KeyPress
- If Not (Asc(e.KeyChar) = 8) Then
- Dim allowchar As String = ""
- If Not allowchar.Contains(e.KeyChar.ToString) Then
- e.KeyChar = ChrW(0)
- e.Handled = True
- End If
- End If
- End Sub
- Private Sub Weight_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Weight.KeyPress, Heightm.KeyPress, Age.KeyPress
- If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
- e.Handled = True
- MessageBox.Show("You can only input number.", "K-Health", MessageBoxButtons.OK, MessageBoxIcon.Warning)
- End If
- End Sub
- Private Sub button2_Click(sender As Object, e As EventArgs) Handles button2.Click
- Dim message As String = "Do you really want to exit?"
- Dim caption As String = "K-Health"
- Dim icon As String = MessageBoxIcon.Warning
- Dim button As String = MessageBoxButtons.YesNo
- Dim result As DialogResult
- result = MessageBox.Show(Me, message, caption, button, icon)
- If result = DialogResult.No Then
- Me.Refresh()
- Else
- Me.Close()
- End If
- End Sub
- Private Sub button3_Click(sender As Object, e As EventArgs) Handles button3.Click
- Me.WindowState = FormWindowState.Minimized
- End Sub
- Private Sub Button1_Click(sender As Object, e As EventArgs)
- Me.WindowState = FormWindowState.Maximized
- End Sub
- Private Sub Weight_TextChanged(sender As Object, e As EventArgs) Handles Weight.TextChanged
- BtnWeight.Enabled = True
- End Sub
- Private Sub Heightm_TextChanged(sender As Object, e As EventArgs) Handles Heightm.TextChanged
- BtnHeight.Enabled = True
- End Sub
- Private Sub BtnWeight_Click(sender As Object, e As EventArgs) Handles BtnWeight.Click
- Dim kg As Double
- Dim convert As Double
- kg = CSng(Weight.Text)
- If (Weight2.Text = "Gram(g)") Then
- convert = (kg * 1000)
- cWeight.Text = Str(convert)
- ElseIf (Weight2.Text = "Miligram(mg)") Then
- convert = (kg * 100000)
- cWeight.Text = Str(convert)
- ElseIf (Weight2.Text = "Pound(lb)") Then
- convert = (kg / 0.45359237)
- cWeight.Text = Str(convert)
- ElseIf (Weight2.Text = "Ounce(oz)") Then
- convert = (kg / 0.02834952)
- cWeight.Text = Str(convert)
- Else
- MessageBox.Show("Please select an item for conversion", "k-Health", MessageBoxButtons.OK, MessageBoxIcon.Warning)
- End If
- End Sub
- Private Sub BtnHeight_Click(sender As Object, e As EventArgs) Handles BtnHeight.Click
- Dim m2 As Double
- Dim convert As Double
- m2 = CSng(Heightm.Text)
- If (Height2.Text = "Centimetre(cm)") Then
- convert = (m2 / 0.01)
- cHeight.Text = Str(convert)
- ElseIf (Height2.Text = "Milimetre(mm)") Then
- convert = (m2 / 0.001)
- cHeight.Text = Str(convert)
- ElseIf (Height2.Text = "Foot(ft)") Then
- convert = (m2 / 0.3048)
- cHeight.Text = Str(convert)
- ElseIf (Height2.Text = "Inch(in)") Then
- convert = (m2 / 0.0254)
- cHeight.Text = Str(convert)
- Else
- MessageBox.Show("Please select an item for conversion", "K-Health", MessageBoxButtons.OK, MessageBoxIcon.Warning)
- End If
- End Sub
- Private Sub Cancelbtn_Click(sender As Object, e As EventArgs) Handles Cancelbtn.Click
- Dim message As String = "Do you really want to exit?"
- Dim caption As String = "K-Health"
- Dim icon As String = MessageBoxIcon.Warning
- Dim button As String = MessageBoxButtons.YesNo
- Dim result As DialogResult
- result = MessageBox.Show(Me, message, caption, button, icon)
- If result = DialogResult.No Then
- id.Clear()
- LastName.Clear()
- FirstName.Clear()
- Sex.Text = ""
- Age.Clear()
- Nutritional.Clear()
- HeightAge.Clear()
- BMI.Clear()
- Weight.Clear()
- Heightm.Clear()
- cWeight.Clear()
- cHeight.Clear()
- Height2.Text = ""
- Weight2.Text = ""
- Else
- End If
- End Sub
- Private Sub Label12_Click(sender As Object, e As EventArgs)
- End Sub
- Private Sub id_TextChanged(sender As Object, e As EventArgs)
- End Sub
- Private Sub Label7_Click(sender As Object, e As EventArgs)
- End Sub
- Private Sub Sex_SelectedIndexChanged(sender As Object, e As EventArgs)
- End Sub
- Private Sub Label8_Click(sender As Object, e As EventArgs)
- End Sub
- Private Sub Age_TextChanged(sender As Object, e As EventArgs)
- End Sub
- Private Sub Label9_Click(sender As Object, e As EventArgs)
- End Sub
- Private Sub Birthdate_ValueChanged(sender As Object, e As EventArgs)
- End Sub
- Private Sub Label17_Click(sender As Object, e As EventArgs)
- End Sub
- Private Sub LastName_TextChanged(sender As Object, e As EventArgs)
- End Sub
- Private Sub Label1_Click(sender As Object, e As EventArgs)
- End Sub
- Private Sub Label2_Click(sender As Object, e As EventArgs)
- End Sub
- Private Sub FirstName_TextChanged(sender As Object, e As EventArgs)
- End Sub
- Private Sub Label10_Click(sender As Object, e As EventArgs)
- End Sub
- Private Sub Label11_Click(sender As Object, e As EventArgs)
- End Sub
- Private Sub Button5_Click(sender As Object, e As EventArgs)
- End Sub
- Private Sub Button4_Click(sender As Object, e As EventArgs)
- End Sub
- Private Sub Button1_Click_1(sender As Object, e As EventArgs)
- End Sub
- Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint
- End Sub
- Private Sub Button1_Click_2(sender As Object, e As EventArgs) Handles Button1.Click
- Dim message As String = "Are you sure you want to submit your data to Coordinator?"
- Dim caption As String = "K-Health"
- Dim icon As String = MessageBoxIcon.Question
- Dim button As String = MessageBoxButtons.YesNo
- Dim result As DialogResult
- result = MessageBox.Show(Me, message, caption, button, icon)
- If result = DialogResult.Yes Then
- MessageBox.Show("Your data was successfully submitted to Coordinator.", "K-Health", MessageBoxButtons.OK, MessageBoxIcon.Information)
- Me.Refresh()
- Else
- Me.Close()
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement