Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 16.57 KB | None | 0 0
  1. Imports System.Data.SqlClient
  2.  
  3. Public Class Faith
  4.  
  5.     Public Property stringpass As String
  6.  
  7.  
  8.  
  9.     Dim conn As New SqlConnection("Data Source=LAPTOP-AVEPA34K;Initial Catalog=User RegistrationKH; Integrated Security = True")
  10.  
  11.  
  12.     Private Sub load_datagrid()
  13.         Dim cmd As New SqlCommand
  14.         Dim adapter As New SqlDataAdapter
  15.         Dim table As New DataTable
  16.         Dim bindingsource As New BindingSource
  17.         Dim cmd1 As New SqlCommand
  18.         Dim adapter1 As New SqlDataAdapter
  19.         Dim table1 As New DataTable
  20.         Dim bindingsource1 As New BindingSource
  21.         Try
  22.             conn.Open()
  23.             cmd = New SqlCommand("SELECT ID,Lastname,Firstname,Birthday,Weight,Height,Sex,Age,BodyMassIndex,NutritionalStatus,HeightforAge FROM kinder", conn)
  24.             adapter = New SqlDataAdapter(cmd)
  25.             adapter.Fill(table)
  26.             bindingsource.DataSource = table
  27.             DataGridView1.DataSource = bindingsource
  28.             adapter.Update(table)
  29.             DataGridView1.Refresh()
  30.         Catch ex As Exception
  31.             MessageBox.Show(ex.Message)
  32.         Finally
  33.             conn.Close()
  34.         End Try
  35.     End Sub
  36.     Private Sub Addbtn_Click(sender As Object, e As EventArgs) Handles Addbtn.Click
  37.         'Body Mass Index Computation'
  38.         Dim body As Double
  39.         Dim bmiRounded As Double
  40.  
  41.         body = (Weight.Text * 703) / (Heightm.Text * Heightm.Text)
  42.         bmiRounded = Math.Round(bmiRounded, 1)
  43.         BMI.Text = bmiRounded
  44.         Select Case BMI.Text
  45.             Case 0.0 To 18.5
  46.                 BMI.Text = "Severeley Stunted"
  47.                 Nutritional.Text = "Severeley Stunted"
  48.                 HeightAge.Text = "Severeley Stunted"
  49.             Case 18.6 To 24.9
  50.                 BMI.Text = "Stunted"
  51.                 Nutritional.Text = "Stunted"
  52.                 HeightAge.Text = "Stunted"
  53.             Case 25.0 To 29.9
  54.                 BMI.Text = "Normal"
  55.                 Nutritional.Text = "Normal"
  56.                 HeightAge.Text = "Normal"
  57.  
  58.             Case Is >= 30.0
  59.                 BMI.Text = "Above Normal"
  60.                 Nutritional.Text = "Above Normal"
  61.                 HeightAge.Text = "Above Normal"
  62.         End Select
  63.         'Messag for Incomplete data'
  64.         If LastName.Text = "" Then
  65.             MessageBox.Show("Please fill the blanks", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
  66.         ElseIf FirstName.Text = "" Then
  67.             MessageBox.Show("Please fill the blanks", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
  68.         ElseIf Weight.Text = "" Then
  69.             MessageBox.Show("Please fill the blanks", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
  70.         ElseIf Weight2.SelectedIndex <> 0 And Weight2.SelectedIndex <> 1 And Weight2.SelectedIndex <> 2 And Weight2.SelectedIndex <> 3 Then
  71.             MessageBox.Show("Invalid data", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
  72.         ElseIf Sex.SelectedIndex <> 0 And Sex.SelectedIndex <> 1 Then
  73.             MessageBox.Show("Invalid data", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
  74.         ElseIf Heightm.Text = "" Then
  75.             MessageBox.Show("Please fill the blanks", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
  76.         ElseIf Height2.SelectedIndex <> 0 And Height2.SelectedIndex <> 1 And Height2.SelectedIndex <> 2 And Height2.SelectedIndex <> 3 Then
  77.             MessageBox.Show("Invalid data", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
  78.         ElseIf Age.Text = "" Then
  79.             MessageBox.Show("Please fill the blanks", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
  80.         ElseIf Nutritional.Text = "" Then
  81.             MessageBox.Show("Please fill the blanks", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
  82.         ElseIf HeightAge.Text = "" Then
  83.             MessageBox.Show("Please fill the blanks", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
  84.         ElseIf BMI.Text = "" Then
  85.             MessageBox.Show("Please fill the blanks", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
  86.         ElseIf cHeight.Text = "" Then
  87.             MessageBox.Show("Please fill the blanks", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
  88.         ElseIf cWeight.Text = "" Then
  89.             MessageBox.Show("Please fill the blanks", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Error)
  90.         Else
  91.             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)"
  92.             executequery(insertquery)
  93.  
  94.             MessageBox.Show("Registered Successfully", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information)
  95.             id.Clear()
  96.             LastName.Clear()
  97.             FirstName.Clear()
  98.             Sex.Text = ""
  99.             Age.Clear()
  100.             Nutritional.Clear()
  101.             HeightAge.Clear()
  102.             BMI.Clear()
  103.             Weight.Clear()
  104.             Heightm.Clear()
  105.             cWeight.Clear()
  106.             cHeight.Clear()
  107.             Height2.Text = ""
  108.             Weight2.Text = ""
  109.         End If
  110.  
  111.     End Sub
  112.     Public Sub executequery(ByVal query As String)
  113.         Dim cmd As New SqlCommand(query, conn)
  114.         cmd.Parameters.AddWithValue("@Lastname", LastName.Text)
  115.         cmd.Parameters.AddWithValue("@Firstname", FirstName.Text)
  116.         cmd.Parameters.Add("@Birthday", SqlDbType.Date).Value = Birthdate.Text
  117.         cmd.Parameters.AddWithValue("@Weight", Weight.Text)
  118.         cmd.Parameters.AddWithValue("@Height", Heightm.Text)
  119.         cmd.Parameters.AddWithValue("@Sex", Sex.SelectedItem)
  120.         cmd.Parameters.AddWithValue("@Age", Age.Text)
  121.         cmd.Parameters.AddWithValue("@BodyMassIndex", BMI.Text)
  122.         cmd.Parameters.AddWithValue("@NutritionalStatus", Nutritional.Text)
  123.         cmd.Parameters.AddWithValue("@HeightforAge", HeightAge.Text)
  124.  
  125.  
  126.         conn.Open()
  127.         cmd.ExecuteNonQuery()
  128.         conn.Close()
  129.         load_datagrid()
  130.     End Sub
  131.  
  132.     Private Sub Deletebtn_Click(sender As Object, e As EventArgs) Handles Deletebtn.Click
  133.         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"
  134.         executequery(deletequery)
  135.         MessageBox.Show("Data Deleted")
  136.     End Sub
  137.  
  138.     Private Sub Updatebtn_Click(sender As Object, e As EventArgs) Handles Updatebtn.Click
  139.         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 & ""
  140.         executequery(updatequery)
  141.  
  142.  
  143.  
  144.         MessageBox.Show("Your data was successfully Updated", "K-Health")
  145.     End Sub
  146.  
  147.     Private Sub Nutritional_TextChanged(sender As Object, e As EventArgs) Handles Nutritional.TextChanged
  148.  
  149.     End Sub
  150.  
  151.     Private Sub HeightAge_TextChanged(sender As Object, e As EventArgs) Handles HeightAge.TextChanged
  152.  
  153.     End Sub
  154.  
  155.     Private Sub BMI_TextChanged(sender As Object, e As EventArgs) Handles BMI.TextChanged
  156.  
  157.     End Sub
  158.  
  159.     Private Sub Student_Form_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  160.         'TODO: This line of code loads data into the 'User_RegistrationKHDataSet3.Faith' table. You can move, or remove it, as needed.
  161.         passingtxt.Text = stringpass
  162.         Me.FaithTableAdapter.Fill(Me.User_RegistrationKHDataSet3.Faith)
  163.  
  164.  
  165.     End Sub
  166.  
  167.     Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
  168.         If e.RowIndex >= 0 Then
  169.             Dim index As Integer
  170.             index = e.RowIndex
  171.             Dim selectedrow As DataGridViewRow
  172.             selectedrow = DataGridView1.Rows(index)
  173.             id.Text = selectedrow.Cells(0).Value.ToString
  174.             LastName.Text = selectedrow.Cells(0).Value.ToString
  175.             FirstName.Text = selectedrow.Cells(1).Value.ToString
  176.             Birthdate.Text = selectedrow.Cells(2).Value.ToString
  177.             Weight.Text = selectedrow.Cells(3).Value.ToString
  178.             Heightm.Text = selectedrow.Cells(4).Value.ToString
  179.             Sex.Text = selectedrow.Cells(5).Value.ToString
  180.             Age.Text = selectedrow.Cells(6).Value.ToString
  181.             BMI.Text = selectedrow.Cells(7).Value.ToString
  182.             Nutritional.Text = selectedrow.Cells(8).Value.ToString
  183.             HeightAge.Text = selectedrow.Cells(9).Value.ToString
  184.         End If
  185.     End Sub
  186.  
  187.     Private Sub Weight2_Click(sender As Object, e As EventArgs)
  188.  
  189.     End Sub
  190.  
  191.     Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Weight2.SelectedIndexChanged
  192.  
  193.     End Sub
  194.  
  195.     Private Sub Weight2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Weight2.KeyPress
  196.         If Not (Asc(e.KeyChar) = 15) Then
  197.             Dim allowchar As String = ""
  198.             If Not allowchar.Contains(e.KeyChar.ToString) Then
  199.                 e.KeyChar = ChrW(0)
  200.                 e.Handled = True
  201.             End If
  202.         End If
  203.     End Sub
  204.  
  205.     Private Sub Height2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Height2.KeyPress
  206.         If Not (Asc(e.KeyChar) = 15) Then
  207.             Dim allowchar As String = ""
  208.             If Not allowchar.Contains(e.KeyChar.ToString) Then
  209.                 e.KeyChar = ChrW(0)
  210.                 e.Handled = True
  211.             End If
  212.         End If
  213.     End Sub
  214.  
  215.     Private Sub Sex_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Sex.KeyPress
  216.         If Not (Asc(e.KeyChar) = 8) Then
  217.             Dim allowchar As String = ""
  218.             If Not allowchar.Contains(e.KeyChar.ToString) Then
  219.                 e.KeyChar = ChrW(0)
  220.                 e.Handled = True
  221.             End If
  222.         End If
  223.     End Sub
  224.  
  225.     Private Sub Weight_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Weight.KeyPress, Heightm.KeyPress, Age.KeyPress
  226.         If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
  227.             e.Handled = True
  228.             MessageBox.Show("You can only input number.", "K-Health", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  229.  
  230.  
  231.         End If
  232.     End Sub
  233.  
  234.     Private Sub button2_Click(sender As Object, e As EventArgs) Handles button2.Click
  235.         Dim message As String = "Do you really want to exit?"
  236.         Dim caption As String = "K-Health"
  237.         Dim icon As String = MessageBoxIcon.Warning
  238.         Dim button As String = MessageBoxButtons.YesNo
  239.  
  240.         Dim result As DialogResult
  241.         result = MessageBox.Show(Me, message, caption, button, icon)
  242.  
  243.         If result = DialogResult.No Then
  244.             Me.Refresh()
  245.         Else
  246.             Me.Close()
  247.  
  248.         End If
  249.     End Sub
  250.  
  251.     Private Sub button3_Click(sender As Object, e As EventArgs) Handles button3.Click
  252.         Me.WindowState = FormWindowState.Minimized
  253.     End Sub
  254.  
  255.     Private Sub Button1_Click(sender As Object, e As EventArgs)
  256.  
  257.         Me.WindowState = FormWindowState.Maximized
  258.     End Sub
  259.  
  260.     Private Sub Weight_TextChanged(sender As Object, e As EventArgs) Handles Weight.TextChanged
  261.         BtnWeight.Enabled = True
  262.     End Sub
  263.  
  264.     Private Sub Heightm_TextChanged(sender As Object, e As EventArgs) Handles Heightm.TextChanged
  265.         BtnHeight.Enabled = True
  266.     End Sub
  267.  
  268.     Private Sub BtnWeight_Click(sender As Object, e As EventArgs) Handles BtnWeight.Click
  269.         Dim kg As Double
  270.         Dim convert As Double
  271.  
  272.         kg = CSng(Weight.Text)
  273.  
  274.         If (Weight2.Text = "Gram(g)") Then
  275.             convert = (kg * 1000)
  276.             cWeight.Text = Str(convert)
  277.         ElseIf (Weight2.Text = "Miligram(mg)") Then
  278.             convert = (kg * 100000)
  279.             cWeight.Text = Str(convert)
  280.         ElseIf (Weight2.Text = "Pound(lb)") Then
  281.             convert = (kg / 0.45359237)
  282.             cWeight.Text = Str(convert)
  283.         ElseIf (Weight2.Text = "Ounce(oz)") Then
  284.             convert = (kg / 0.02834952)
  285.             cWeight.Text = Str(convert)
  286.         Else
  287.             MessageBox.Show("Please select an item for conversion", "k-Health", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  288.  
  289.         End If
  290.  
  291.  
  292.     End Sub
  293.  
  294.     Private Sub BtnHeight_Click(sender As Object, e As EventArgs) Handles BtnHeight.Click
  295.         Dim m2 As Double
  296.         Dim convert As Double
  297.  
  298.         m2 = CSng(Heightm.Text)
  299.  
  300.         If (Height2.Text = "Centimetre(cm)") Then
  301.             convert = (m2 / 0.01)
  302.             cHeight.Text = Str(convert)
  303.         ElseIf (Height2.Text = "Milimetre(mm)") Then
  304.             convert = (m2 / 0.001)
  305.             cHeight.Text = Str(convert)
  306.         ElseIf (Height2.Text = "Foot(ft)") Then
  307.             convert = (m2 / 0.3048)
  308.             cHeight.Text = Str(convert)
  309.         ElseIf (Height2.Text = "Inch(in)") Then
  310.             convert = (m2 / 0.0254)
  311.             cHeight.Text = Str(convert)
  312.         Else
  313.             MessageBox.Show("Please select an item for conversion", "K-Health", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  314.  
  315.         End If
  316.     End Sub
  317.  
  318.     Private Sub Cancelbtn_Click(sender As Object, e As EventArgs) Handles Cancelbtn.Click
  319.         Dim message As String = "Do you really want to exit?"
  320.         Dim caption As String = "K-Health"
  321.         Dim icon As String = MessageBoxIcon.Warning
  322.         Dim button As String = MessageBoxButtons.YesNo
  323.  
  324.         Dim result As DialogResult
  325.         result = MessageBox.Show(Me, message, caption, button, icon)
  326.  
  327.         If result = DialogResult.No Then
  328.             id.Clear()
  329.             LastName.Clear()
  330.             FirstName.Clear()
  331.             Sex.Text = ""
  332.             Age.Clear()
  333.             Nutritional.Clear()
  334.             HeightAge.Clear()
  335.             BMI.Clear()
  336.             Weight.Clear()
  337.             Heightm.Clear()
  338.             cWeight.Clear()
  339.             cHeight.Clear()
  340.             Height2.Text = ""
  341.             Weight2.Text = ""
  342.  
  343.  
  344.  
  345.         Else
  346.  
  347.         End If
  348.  
  349.     End Sub
  350.  
  351.     Private Sub Label12_Click(sender As Object, e As EventArgs)
  352.  
  353.     End Sub
  354.  
  355.     Private Sub id_TextChanged(sender As Object, e As EventArgs)
  356.  
  357.     End Sub
  358.  
  359.     Private Sub Label7_Click(sender As Object, e As EventArgs)
  360.  
  361.     End Sub
  362.  
  363.     Private Sub Sex_SelectedIndexChanged(sender As Object, e As EventArgs)
  364.  
  365.     End Sub
  366.  
  367.     Private Sub Label8_Click(sender As Object, e As EventArgs)
  368.  
  369.     End Sub
  370.  
  371.     Private Sub Age_TextChanged(sender As Object, e As EventArgs)
  372.  
  373.     End Sub
  374.  
  375.     Private Sub Label9_Click(sender As Object, e As EventArgs)
  376.  
  377.     End Sub
  378.  
  379.     Private Sub Birthdate_ValueChanged(sender As Object, e As EventArgs)
  380.  
  381.     End Sub
  382.  
  383.     Private Sub Label17_Click(sender As Object, e As EventArgs)
  384.  
  385.     End Sub
  386.  
  387.     Private Sub LastName_TextChanged(sender As Object, e As EventArgs)
  388.  
  389.     End Sub
  390.  
  391.     Private Sub Label1_Click(sender As Object, e As EventArgs)
  392.  
  393.     End Sub
  394.  
  395.     Private Sub Label2_Click(sender As Object, e As EventArgs)
  396.  
  397.     End Sub
  398.  
  399.     Private Sub FirstName_TextChanged(sender As Object, e As EventArgs)
  400.  
  401.     End Sub
  402.  
  403.     Private Sub Label10_Click(sender As Object, e As EventArgs)
  404.  
  405.     End Sub
  406.  
  407.     Private Sub Label11_Click(sender As Object, e As EventArgs)
  408.  
  409.     End Sub
  410.  
  411.     Private Sub Button5_Click(sender As Object, e As EventArgs)
  412.  
  413.     End Sub
  414.  
  415.     Private Sub Button4_Click(sender As Object, e As EventArgs)
  416.  
  417.     End Sub
  418.  
  419.     Private Sub Button1_Click_1(sender As Object, e As EventArgs)
  420.  
  421.     End Sub
  422.  
  423.     Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint
  424.  
  425.     End Sub
  426.  
  427.     Private Sub Button1_Click_2(sender As Object, e As EventArgs) Handles Button1.Click
  428.         Dim message As String = "Are you sure you want to submit your data to Coordinator?"
  429.         Dim caption As String = "K-Health"
  430.         Dim icon As String = MessageBoxIcon.Question
  431.         Dim button As String = MessageBoxButtons.YesNo
  432.  
  433.         Dim result As DialogResult
  434.         result = MessageBox.Show(Me, message, caption, button, icon)
  435.  
  436.         If result = DialogResult.Yes Then
  437.             MessageBox.Show("Your data was successfully submitted to Coordinator.", "K-Health", MessageBoxButtons.OK, MessageBoxIcon.Information)
  438.             Me.Refresh()
  439.         Else
  440.             Me.Close()
  441.  
  442.  
  443.  
  444.         End If
  445.     End Sub
  446. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement