LAMPIRAN A LISTING PROGRAM AdminControl.vb

  

LAMPIRAN A

LISTING PROGRAM

AdminControl.vb

  Imports MySql.Data.MySqlClient Public Class AdminControl

  Dim conn As MySqlConnection = New MySqlConnection( My .MySettings.Default.ConnStr)

  Dim table As String = "" Dim lbl As String = "" Dim id As Integer = 0 Private Sub setRegularFont()

  For Each lbl As Label In GroupBox1.Controls If lbl.Name.ToString().StartsWith( "lbl" ) Then lbl.Font = New Font(lbl.Font, FontStyle.Regular)

  End If Next

  End Sub Private Function getDataTable( ByVal table As String ) As DataTable

  Dim dt As DataTable = New DataTable() Dim sqlString As String = "" If table = "tbl_Artikel" Then sqlString = "Select * from " & table & " where Judul <> ''"

  Else sqlString = "Select * from " & table

  End If Dim Data As MySqlDataAdapter = New MySqlDataAdapter(sqlString, conn)

  Data.Fill(dt) Return dt

  End Function Private Function cekUser( ByVal value As String ) As Boolean

  Dim retValue As Boolean = False conn.Open()

  Dim sqlString As String = "Select * from tbl_User where Username =

  @Value"

  Dim cmd As MySqlCommand = New MySqlCommand(sqlString, conn) cmd.Parameters.AddWithValue( "@Value" , value)

  Dim dr As MySqlDataReader = Nothing Try dr = cmd.ExecuteReader()

  If (dr.HasRows) Then If (dr.Read()) Then retValue = True

  End If End If

  Catch ex As Exception Finally

  If (dr IsNot Nothing ) Then dr.Close() dr = Nothing

  End If End Try conn.Close() Return retValue

  End Function Private Function editUser( ByVal user As String , ByVal pass As String ) As

  If cmd.ExecuteNonQuery > 0 Then retValue = True

  Return retValue End Function Private Sub lblUser_Click( ByVal sender As System.Object, ByVal e As

  End If conn.Close()

  If cmd.ExecuteNonQuery() > 0 Then retValue = True

  Dim sqlString As String = "delete from tbl_User where Username = @User" Dim cmd As MySqlCommand = New MySqlCommand(sqlString, conn) cmd.Parameters.AddWithValue( "@User" , user)

  Dim retValue As Boolean = False conn.Open()

  Return retValue End Function Private Function deleteUser( ByVal user As String ) As Boolean

  End If conn.Close()

  Dim sqlString As String = "insert into tbl_User values(@User, @Pass)" Dim cmd As MySqlCommand = New MySqlCommand(sqlString, conn) cmd.Parameters.AddWithValue( "@User" , user) cmd.Parameters.AddWithValue( "@Pass" , pass)

  Boolean Dim retValue As Boolean = False conn.Open()

  Boolean Dim retValue As Boolean = False conn.Open()

  Return retValue End Function Private Function addUser( ByVal user As String , ByVal pass As String ) As

  End If conn.Close()

  If cmd.ExecuteNonQuery > 0 Then retValue = True

  Dim cmd As MySqlCommand = New MySqlCommand(sqlString, conn) cmd.Parameters.AddWithValue( "@User" , user) cmd.Parameters.AddWithValue( "@Pass" , pass)

  Username = @User"

  Dim sqlString As String = "update tbl_User set Password = @Pass where

  System.EventArgs) Handles lblUser.Click setRegularFont() lblUser.Font = New Font(lblUser.Font, FontStyle.Bold) table = "tbl_user" lbl = "lblUser" gbUser.Visible = True gbArtikel.Visible = False gbNutrisi.Visible = False gbKalori.Visible = False gbUser.BringToFront() Dim data As DataTable = getDataTable(table)

  DataGridView1.DataSource = data End Sub Private Sub DataGridView1_CellClick( ByVal sender As System.Object, ByVal e

  As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick

  If lbl = "lblUser" Then txtUser.Text = DataGridView1.SelectedRows(0).Cells(0).Value.ToString() txtPass.Text = DataGridView1.SelectedRows(0).Cells(1).Value.ToString()

  ElseIf lbl = "lblNutrisi" Then txtNama.Text = DataGridView1.SelectedRows(0).Cells(0).Value.ToString() txtUmur.Text = DataGridView1.SelectedRows(0).Cells(1).Value.ToString() txtJenis.Text = DataGridView1.SelectedRows(0).Cells(2).Value.ToString() txtBerat.Text = DataGridView1.SelectedRows(0).Cells(3).Value.ToString() txtTinggi.Text = DataGridView1.SelectedRows(0).Cells(4).Value.ToString() txtStatus.Text = DataGridView1.SelectedRows(0).Cells(5).Value.ToString() txtBBI.Text = DataGridView1.SelectedRows(0).Cells(6).Value.ToString() txtBMI.Text = DataGridView1.SelectedRows(0).Cells(7).Value.ToString()

  ElseIf lbl = "lblKalori" Then txtNamaKal.Text = DataGridView1.SelectedRows(0).Cells(0).Value.ToString() txtUmurKal.Text = DataGridView1.SelectedRows(0).Cells(1).Value.ToString() txtJenisKal.Text = DataGridView1.SelectedRows(0).Cells(2).Value.ToString() txtBeratKal.Text = DataGridView1.SelectedRows(0).Cells(3).Value.ToString() txtTinggiKal.Text = DataGridView1.SelectedRows(0).Cells(4).Value.ToString() txtStatusKal.Text = DataGridView1.SelectedRows(0).Cells(5).Value.ToString() txtKebutuhanKal.Text = DataGridView1.SelectedRows(0).Cells(6).Value.ToString()

  ElseIf lbl = "lblArtikel" Then id = DataGridView1.SelectedRows(0).Cells(0).Value.ToString() txtJudul.Text = DataGridView1.SelectedRows(0).Cells(1).Value.ToString() txtIsi.Text = DataGridView1.SelectedRows(0).Cells(2).Value.ToString()

  End If End Sub Private Sub LoadDataGrid()

  If lbl = "lblArtikel" Then lblArtikel_Click( Nothing , Nothing )

  ElseIf lbl = "lblUser" Then lblUser_Click( Nothing , Nothing )

  ElseIf lbl = "lblNutrisi" Then lblNutrisi_Click( Nothing , Nothing )

  ElseIf lbl = "lblKalori" Then lblKalori_Click( Nothing , Nothing )

  End If End Sub Private Sub AdminControl_Load( ByVal sender As System.Object, ByVal e As

  System.EventArgs) Handles MyBase .Load gbArtikel.Visible = False gbKalori.Visible = False gbNutrisi.Visible = False gbUser.Visible = False

  End Sub Private Sub btnBaruUser_Click( ByVal sender As System.Object, ByVal e As

  System.EventArgs) Handles btnBaruUser.Click txtUser.Text = "" txtPass.Text = ""

  End Sub Private Sub btnSimpanUser_Click( ByVal sender As System.Object, ByVal e As

  System.EventArgs) Handles btnSimpanUser.Click For Each ctrl In gbUser.Controls

  If ctrl.Text = "" Then MessageBox.Show( "Isi semua data" ) ctrl.Focus()

  Exit Sub End If

  Next If (cekUser(txtUser.Text)) Then

  If (MessageBox.Show( "Edit data " & txtUser.Text & "?" , "Update" , MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes) Then

  If (editUser(txtUser.Text, txtPass.Text)) Then MessageBox.Show( "Data berhasil diedit" , "Update" , MessageBoxButtons.OK, MessageBoxIcon.Information) LoadDataGrid()

  Else MessageBox.Show( "Data gagal diedit" , "Update" , MessageBoxButtons.OK, MessageBoxIcon.Information)

  End If btnBaruUser_Click( Nothing , Nothing )

  End If Else

  If (MessageBox.Show( "Tambah Data?" , "Simpan" , MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes) Then

  If (addUser(txtUser.Text, txtPass.Text)) Then MessageBox.Show( "Data berhasil ditambah" , "Simpan" , MessageBoxButtons.OK, MessageBoxIcon.Information) LoadDataGrid()

  Else MessageBox.Show( "Data gagal ditambah" , "Simpan" , MessageBoxButtons.OK, MessageBoxIcon.Information)

  End If btnBaruUser_Click( Nothing , Nothing )

  End If End If

  End Sub

  Private Sub btnHapusUser_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHapusUser.Click

  If (MessageBox.Show( "Hapus data " & txtUser.Text & "?" , "Hapus" , MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes) Then

  If (deleteUser(txtUser.Text)) Then MessageBox.Show( "Data berhasil dihapus" , "Hapus" , MessageBoxButtons.OK, MessageBoxIcon.Information) LoadDataGrid()

  Else MessageBox.Show( "Data gagal dihapus" , "Hapus" , MessageBoxButtons.OK, MessageBoxIcon.Information)

  End If End If

  End Sub Private Sub txtUser_TextChanged( ByVal sender As System.Object, ByVal e As

  System.EventArgs) Handles txtUser.TextChanged If (txtUser.Text = "" ) Then btnSimpanUser.Enabled = False btnHapusUser.Enabled = False

  Else btnSimpanUser.Enabled = True btnHapusUser.Enabled = True

  End If End Sub Private Sub lblNutrisi_Click( ByVal sender As System.Object, ByVal e As

  System.EventArgs) Handles lblNutrisi.Click setRegularFont() lblNutrisi.Font = New Font(lblNutrisi.Font, FontStyle.Bold) table = "tbl_Nutrisi" lbl = "lblNutrisi" gbUser.Visible = False gbArtikel.Visible = False gbNutrisi.Visible = True gbKalori.Visible = False gbNutrisi.BringToFront()

  Dim data As DataTable = getDataTable(table) DataGridView1.DataSource = data

  End Sub Private Sub lblKalori_Click( ByVal sender As System.Object, ByVal e As

  System.EventArgs) Handles lblKalori.Click setRegularFont() lblKalori.Font = New Font(lblKalori.Font, FontStyle.Bold) table = "tbl_Kalori" lbl = "lblKalori" gbUser.Visible = False gbArtikel.Visible = False gbNutrisi.Visible = False gbKalori.Visible = True gbKalori.BringToFront()

  Dim data As DataTable = getDataTable(table) DataGridView1.DataSource = data

  End Sub Private Sub lblArtikel_Click( ByVal sender As System.Object, ByVal e As

  System.EventArgs) Handles lblArtikel.Click setRegularFont() lblArtikel.Font = New Font(lblArtikel.Font, FontStyle.Bold) table = "tbl_Artikel" lbl = "lblArtikel" gbUser.Visible = False gbArtikel.Visible = True gbNutrisi.Visible = False gbKalori.Visible = False gbArtikel.BringToFront()

  Dim data As DataTable = getDataTable(table) DataGridView1.DataSource = data

  End Sub Private Sub btnBaruKal_Click( ByVal sender As System.Object, ByVal e As

  System.EventArgs) Handles btnBaruKal.Click For Each ctrl In gbKalori.Controls

  If ctrl.GetType() Is GetType (TextBox) Then ctrl.Text = ""

  End If Next

  End Sub Private Sub btnBaruNutrisi_Click( ByVal sender As System.Object, ByVal e As

  System.EventArgs) Handles btnBaruNutrisi.Click For Each ctrl In gbNutrisi.Controls

  If ctrl.GetType() Is GetType (TextBox) Then ctrl.Text = ""

  End If Next

  End Sub Private Sub btnBaruArtikel_Click( ByVal sender As System.Object, ByVal e As

  System.EventArgs) Handles btnBaruArtikel.Click txtJudul.Text = "" txtIsi.Text = "" id = 0

  End Sub Private Sub btnHapusArtikel_Click( ByVal sender As System.Object, ByVal e As

  System.EventArgs) Handles btnHapusArtikel.Click If (MessageBox.Show( "Hapus Data?" , "Hapus" , MessageBoxButtons.YesNo,

  MessageBoxIcon.Question) = DialogResult.Yes) Then conn.Open() Dim sqlString As String = "delete from tbl_Artikel where Id = @id" Dim cmd As MySqlCommand = New MySqlCommand(sqlString, conn) cmd.Parameters.AddWithValue( "@Id" , id) cmd.ExecuteNonQuery() conn.Close() MessageBox.Show( "Data berhasil dihapus" , "Hapus" , MessageBoxButtons.OK, MessageBoxIcon.Information) LoadDataGrid() btnBaruArtikel_Click( Nothing , Nothing )

  End If End Sub Private Sub btnUpdateArtikel_Click( ByVal sender As System.Object, ByVal e

  As System.EventArgs) Handles btnUpdateArtikel.Click conn.Open()

  Dim sqlString As String = "update tbl_Artikel set Judul = @Judul, Isi =

  @Isi where Id = @id"

  Dim cmd As MySqlCommand = New MySqlCommand(sqlString, conn) cmd.Parameters.AddWithValue( "@Judul" , txtJudul.Text) cmd.Parameters.AddWithValue( "@Isi" , txtIsi.Text) cmd.Parameters.AddWithValue( "@id" , id) cmd.ExecuteNonQuery() conn.Close() MessageBox.Show( "Data berhasil diupdate" , "Update" , MessageBoxButtons.OK, MessageBoxIcon.Information) LoadDataGrid()

  End Sub Private Sub btnUpdateKal_Click( ByVal sender As System.Object, ByVal e As

  System.EventArgs) Handles btnUpdateKal.Click conn.Open() Dim sqlString As String = "update tbl_Kalori set JenisKelamin = @Jenis,

  BeratBadan = @Berat, TinggiBadan = @Tinggi, " & _ "StatusKalori = @Status, KebutuhanKalori = @Kebutuhan where Nama = @Nama and Umur = @Umur"

  Dim cmd As MySqlCommand = New MySqlCommand(sqlString, conn) cmd.Parameters.AddWithValue( "@Nama" , txtNamaKal.Text) cmd.Parameters.AddWithValue( "@Umur" , txtUmurKal.Text) cmd.Parameters.AddWithValue( "@Jenis" , txtJenisKal.Text) cmd.Parameters.AddWithValue( "@Berat" , txtBeratKal.Text) cmd.Parameters.AddWithValue( "@Tinggi" , txtTinggiKal.Text) cmd.Parameters.AddWithValue( "@Status" , txtStatusKal.Text) cmd.Parameters.AddWithValue( "@Kebutuhan" , txtKebutuhanKal.Text) cmd.ExecuteNonQuery() conn.Close() MessageBox.Show( "Data berhasil diupdate" , "Update" , MessageBoxButtons.OK, MessageBoxIcon.Information) LoadDataGrid()

  End Sub Private Sub btnHapusKal_Click( ByVal sender As System.Object, ByVal e As

  System.EventArgs) Handles btnHapusKal.Click If (MessageBox.Show( "Hapus Data?" , "Hapus" , MessageBoxButtons.YesNo,

  MessageBoxIcon.Question) = DialogResult.Yes) Then conn.Open() Dim sqlString As String = "delete from tbl_Kalori where Nama =

  @Nama and Umur = @Umur"

  Dim cmd As MySqlCommand = New MySqlCommand(sqlString, conn) cmd.Parameters.AddWithValue( "@Nama" , txtNamaKal.Text) cmd.Parameters.AddWithValue( "@Umur" , txtUmurKal.Text) cmd.ExecuteNonQuery() conn.Close() MessageBox.Show( "Data berhasil dihapus" , "Hapus" , MessageBoxButtons.OK, MessageBoxIcon.Information) LoadDataGrid() btnBaruKal_Click( Nothing , Nothing )

  End If End Sub Private Sub btnUpdateNutrisi_Click( ByVal sender As System.Object, ByVal e

  As System.EventArgs) Handles btnUpdateNutrisi.Click conn.Open()

  Dim sqlString As String = "update tbl_Nutrisi set JenisKelamin =

  @Jenis, BeratBadan = @Berat, TinggiBadan = @Tinggi, " & _ "StatusGizi = @Status, BBI = @BBI, BMI = @BMI where Nama = @Nama and Umur = @Umur"

  Dim cmd As MySqlCommand = New MySqlCommand(sqlString, conn) cmd.Parameters.AddWithValue( "@Nama" , txtNama.Text) cmd.Parameters.AddWithValue( "@Umur" , txtUmur.Text) cmd.Parameters.AddWithValue( "@Jenis" , txtJenis.Text) cmd.Parameters.AddWithValue( "@Berat" , txtBerat.Text) cmd.Parameters.AddWithValue( "@Tinggi" , txtTinggi.Text) cmd.Parameters.AddWithValue( "@Status" , txtStatus.Text) cmd.Parameters.AddWithValue( "@BBI" , txtBBI.Text) cmd.Parameters.AddWithValue( "@BMI" , txtBMI.Text) cmd.ExecuteNonQuery() conn.Close() MessageBox.Show( "Data berhasil diupdate" , "Update" , MessageBoxButtons.OK, MessageBoxIcon.Information) LoadDataGrid()

  End Sub Private Sub btnHapusNutrisi_Click( ByVal sender As System.Object, ByVal e As

  System.EventArgs) Handles btnHapusNutrisi.Click If (MessageBox.Show( "Hapus Data?" , "Hapus" , MessageBoxButtons.YesNo,

  MessageBoxIcon.Question) = DialogResult.Yes) Then conn.Open() Dim sqlString As String = "delete from tbl_Nutrisi where Nama =

  @Nama and Umur = @Umur"

  Dim cmd As MySqlCommand = New MySqlCommand(sqlString, conn) cmd.Parameters.AddWithValue( "@Nama" , txtNama.Text) cmd.Parameters.AddWithValue( "@Umur" , txtUmur.Text) cmd.ExecuteNonQuery() conn.Close() MessageBox.Show( "Data berhasil dihapus" , "Hapus" , MessageBoxButtons.OK, MessageBoxIcon.Information) LoadDataGrid() btnBaruNutrisi_Click( Nothing , Nothing )

  End If End Sub

  End Class

CaloriesControl.vb

  Imports MySql.Data.MySqlClient Public Class CaloriesControl

  Dim conn As MySqlConnection = New MySqlConnection( My .MySettings.Default.ConnStr)

  Private Sub btnProses_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProses.Click

  Dim TEE As Double = 0 Dim Energi As Double = 0

  TEE = hitungKalori(txtUmur.Text, txtBerat.Text, txtTinggi.Text, cmbJenis.Text) Energi = Math.Round(TEE + (0.05 * TEE), 2) lblNama.Text = ": " & txtNama.Text lblBerat.Text = ": " & txtBerat.Text & " Kg" lblJenis.Text = ": " & cmbJenis.Text lblTinggi.Text = ": " & txtTinggi.Text & " cm" lblUmur.Text = ": " & txtUmur.Text & " bulan" lblStatus.Text = ": " & TEE.ToString() & " Kal" lblKalori.Text = ": " & Energi.ToString() & " Kal" conn.Open()

  Dim sqlString As String = "Insert into tbl_Kalori values(@Nama, @Umur,

  @Jenis, @Berat, @Tinggi, @Status, @Kebutuhan)"

  Dim cmd As MySqlCommand = New MySqlCommand(sqlString, conn) cmd.Parameters.AddWithValue( "@Nama" , txtNama.Text) cmd.Parameters.AddWithValue( "@Umur" , txtUmur.Text) cmd.Parameters.AddWithValue( "@Jenis" , cmbJenis.Text) cmd.Parameters.AddWithValue( "@Berat" , txtBerat.Text) cmd.Parameters.AddWithValue( "@Tinggi" , txtTinggi.Text) cmd.Parameters.AddWithValue( "@Status" , TEE) cmd.Parameters.AddWithValue( "@Kebutuhan" , Energi) cmd.ExecuteNonQuery() conn.Close() MessageBox.Show( "Data berhasil di proses" )

  End Sub Private Sub CaloriesControl_Load( ByVal sender As Object , ByVal e As

  System.EventArgs) Handles Me .Load lblNama.Text = ":" lblBerat.Text = ":" lblJenis.Text = ":" lblTinggi.Text = ":" lblUmur.Text = ":" lblStatus.Text = ":" lblKalori.Text = ":" txtBerat.Text = "" txtNama.Text = "" txtTinggi.Text = "" txtUmur.Text = "" cmbJenis.SelectedIndex = -1

  End Sub Private Function hitungKalori( ByVal umur As Integer , ByVal berat As Double ,

  ByVal tinggi As Double , ByVal jenis As String ) As Double Dim TEE As Double = 0 Dim Energi As Double = 0 Dim PA As Double = 0 If (umur < 4) Then

  TEE = (89 * berat - 100) + 175 ElseIf (umur < 7) Then

  TEE = (89 * berat - 100) + 56 ElseIf (umur < 13) Then

  TEE = (89 * berat - 100) + 22 ElseIf (umur < 36) Then

  TEE = (89 * berat - 100) + 20 Else

  If (jenis = "Laki-laki" ) Then PA = 1.26 TEE = (88.5 - (61.9 * (umur / 12)) + PA * (26.7 * berat + 903 * tinggi)) + 20

  Else PA = 1.16 TEE = (135.3 - (30.8 * (umur / 12)) + PA * (10.0 * berat + 934

  • tinggi)) + 20

  End If End If Return Math.Round(TEE, 2)

  End Function Private Sub btnCancel_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click CaloriesControl_Load( Nothing , Nothing )

  End Sub Private Sub txtUmur_Validating( ByVal sender As System.Object, ByVal e As

  System.ComponentModel.CancelEventArgs) Handles txtUmur.Validating Try

  If ( Integer .Parse(txtUmur.Text) > 60) Then MessageBox.Show( "Umur hanya dibawah 5 Tahun (60 Bulan)" ) e.Cancel = True

  End If Catch ex As Exception

  MessageBox.Show( "Umur Invalid" ) e.Cancel = True

  End Try End Sub Private Sub txtBerat_Validating( ByVal sender As System.Object, ByVal e As

  System.ComponentModel.CancelEventArgs) Handles txtBerat.Validating Try

  If ( Integer .Parse(txtBerat.Text) > 25) Then MessageBox.Show( "Berat Badan hanya dibawah 25 Kg" ) e.Cancel = True

  End If Catch ex As Exception

  MessageBox.Show( "Berat Badan Invalid" ) e.Cancel = True

  End Try End Sub Private Sub txtTinggi_Validating( ByVal sender As System.Object, ByVal e As

  System.ComponentModel.CancelEventArgs) Handles txtTinggi.Validating Try

  If ( Integer .Parse(txtTinggi.Text) > 130) Then MessageBox.Show( "Tinggi Badan hanya dibawah 130 cm" ) e.Cancel = True

  End If Catch ex As Exception

  MessageBox.Show( "Tinggi Badan Invalid" ) e.Cancel = True

  End Try End Sub

  End Class

Form1.vb

  Public Class Form1 Private Sub btnHome_Click( ByVal sender As System.Object, ByVal e As

  System.EventArgs) Handles btnHome.Click Dim ctrl As New HomeControl

  Panel1.Controls.Clear() Panel1.Controls.Add(ctrl) btnHome.BackColor = Color.DeepSkyBlue btnCalories.BackColor = Color.Transparent btnInfo.BackColor = Color.Transparent btnNutrition.BackColor = Color.Transparent btnSetting.BackColor = Color.Transparent

  End Sub Private Sub Form1_Load( ByVal sender As System.Object, ByVal e As

  System.EventArgs) Handles MyBase .Load btnHome_Click( Nothing , Nothing ) End Sub Private Sub btnNutrition_Click( ByVal sender As System.Object, ByVal e As

  System.EventArgs) Handles btnNutrition.Click Dim ctrl As New NutritionControl

  Panel1.Controls.Clear() Panel1.Controls.Add(ctrl) btnNutrition.BackColor = Color.DeepSkyBlue btnHome.BackColor = Color.Transparent btnCalories.BackColor = Color.Transparent btnInfo.BackColor = Color.Transparent btnSetting.BackColor = Color.Transparent

  End Sub Private Sub btnCalories_Click( ByVal sender As System.Object, ByVal e As

  System.EventArgs) Handles btnCalories.Click Dim ctrl As New CaloriesControl

  Panel1.Controls.Clear() Panel1.Controls.Add(ctrl) btnCalories.BackColor = Color.DeepSkyBlue btnHome.BackColor = Color.Transparent btnInfo.BackColor = Color.Transparent btnNutrition.BackColor = Color.Transparent btnSetting.BackColor = Color.Transparent

  End Sub Private Sub btnInfo_Click( ByVal sender As System.Object, ByVal e As

  System.EventArgs) Handles btnInfo.Click Dim ctrl As New InformationControl

  Panel1.Controls.Clear() Panel1.Controls.Add(ctrl) btnInfo.BackColor = Color.DeepSkyBlue btnHome.BackColor = Color.Transparent btnCalories.BackColor = Color.Transparent btnNutrition.BackColor = Color.Transparent btnSetting.BackColor = Color.Transparent

  End Sub Private Sub btnSetting_Click( ByVal sender As System.Object, ByVal e As

  System.EventArgs) Handles btnSetting.Click Dim ctrl As New SettingControl

  Panel1.Controls.Clear()

  Panel1.Controls.Add(ctrl) btnSetting.BackColor = Color.DeepSkyBlue btnHome.BackColor = Color.Transparent btnCalories.BackColor = Color.Transparent btnInfo.BackColor = Color.Transparent btnNutrition.BackColor = Color.Transparent

  End Sub Private Sub Form1_FormClosing( ByVal sender As System.Object, ByVal e As

  System.Windows.Forms.FormClosingEventArgs) Handles MyBase .FormClosing If Not (MessageBox.Show( "Keluar Aplikasi?" , "Keluar" ,

  MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes) Then e.Cancel = True

  End If End Sub Public Sub AdminForm()

  Dim ctrl As New AdminControl Panel1.Controls.Clear() Panel1.Controls.Add(ctrl)

  End Sub Private Sub Form1_Resize( ByVal sender As System.Object, ByVal e As

  System.EventArgs) Handles MyBase .Resize Dim x, y As Integer x = ( Me .Width - Panel1.Width) / 2 - 10 y = ( Me .Height - Panel1.Height) / 2 + 10 Panel1.Location = New System.Drawing.Point(x, y) btnHome.Location = New System.Drawing.Point(x + 25, y - 73) btnNutrition.Location = New System.Drawing.Point(btnHome.Location.X + 157, btnHome.Location.Y) btnCalories.Location = New System.Drawing.Point(btnNutrition.Location.X

  • 157, btnNutrition.Location.Y) btnInfo.Location = New System.Drawing.Point(btnCalories.Location.X + 157, btnCalories.Location.Y) btnSetting.Location = New System.Drawing.Point(btnInfo.Location.X + 157, btnInfo.Location.Y)

  End Sub End Class

FormAdmin.vb

  Public Class FormAdmin Private Sub FormAdmin_Load( ByVal sender As System.Object, ByVal e As

  System.EventArgs) Handles MyBase .Load Dim ctrl As New AdminControl

  Panel1.Controls.Clear() Panel1.Controls.Add(ctrl)

  End Sub End Class

FuzzyMamdani.vb

  Public Class FuzzyMamdani Public Function FuzzyBBRingan( ByVal berat As Double ) As Double

  Dim retValue As Double = 0 If (berat <= 7.8) Then retValue = 1

  ElseIf (berat >= 10.8) Then retValue = 0

  Else retValue = (10.8 - berat) / 3

  End If Return retValue

  End Function Public Function FuzzyBBNormal( ByVal berat As Double ) As Double

  Dim retValue As Double = 0 If (berat <= 7.8) Then retValue = 0

  ElseIf (berat >= 7.8 And berat <= 10.8) Then retValue = (berat - 7.8) / 3

  ElseIf (berat >= 10.8 And berat <= 14.3) Then retValue = (14.3 - berat) / 3

  Else retValue = 0

  End If Return retValue

  End Function Public Function FuzzyBBBerat( ByVal berat As Double ) As Double

  Dim retValue As Double = 0 If (berat <= 10.8) Then retValue = 0

  ElseIf (berat >= 13.8) Then retValue = 1

  Else retValue = (berat - 10.8) / 3

  End If Return retValue

  End Function Public Function FuzzyTBRendah( ByVal tinggi As Double ) As Double

  Dim retValue As Double = 0 If (tinggi <= 65) Then retValue = 1

  ElseIf (tinggi >= 80) Then retValue = 0

  Else retValue = (65 - tinggi) / 15

  End If Return retValue

  End Function

  Public Function FuzzyTBNormal( ByVal tinggi As Double ) As Double Dim retValue As Double = 0 If (tinggi <= 70) Then retValue = 0

  ElseIf (tinggi >= 70 And tinggi <= 80) Then retValue = (tinggi - 70) / 10

  ElseIf (tinggi >= 80 And tinggi <= 90) Then retValue = (90 - tinggi) / 10

  Else retValue = 0

  End If Return retValue

  End Function Public Function FuzzyTBTinggi( ByVal tinggi As Double ) As Double

  Dim retValue As Double = 0 If (tinggi <= 80) Then retValue = 0

  ElseIf (tinggi >= 95) Then retValue = 1

  Else retValue = (tinggi - 80) / 15

  End If Return retValue

  End Function Public Function FuzzyGiziBuruk( ByVal gizi As Double ) As Double

  Dim retValue As Double = 0 If (gizi <= -3.5) Then retValue = 1

  ElseIf (gizi >= -3) Then retValue = 0

  Else retValue = gizi + 3

  End If Return retValue

  End Function Public Function FuzzyGiziKurang( ByVal gizi As Double ) As Double

  Dim retValue As Double = 0 If (gizi <= -3) Then retValue = 0

  ElseIf (gizi >= -2.5) Then retValue = 1

  Else retValue = gizi + 2

  End If Return retValue

  End Function Public Function FuzzyGiziBaik( ByVal gizi As Double ) As Double

  Dim retValue As Double = 0

  If (gizi <= -2) Then retValue = 0

  ElseIf (gizi > 2) Then retValue = 1

  Else retValue = 2 - gizi

  End If Return retValue

  End Function Public Function FuzzyGiziLebih( ByVal gizi As Double ) As Double

  Dim retValue As Double = 0 If (gizi <= 2) Then retValue = 0

  ElseIf (gizi >= 3) Then retValue = 1

  Else retValue = 3 - gizi

  End If Return retValue

  End Function Public Function cekGizi( ByVal nilai As Double ) As String

  Dim retValue As String = "" If nilai <= -3 Then retValue = "Gizi Buruk"

  ElseIf (nilai >= -3 And nilai <= -2) Then retValue = "Gizi Kurang"

  ElseIf (nilai >= -2 And nilai <= 2) Then retValue = "Gizi Baik"

  ElseIf nilai >= 2 Then retValue = "Gizi Lebih"

  End If Return retValue

  End Function End Class

HomeControl.vb

  Public Class HomeControl End Class

InformationControl.vb

  Imports MySql.Data.MySqlClient Public Class InformationControl

  Dim lbl_Array As Label() = New Label(10) {} Dim conn As MySqlConnection = New

  MySqlConnection( My .MySettings.Default.ConnStr) Dim data As MySqlDataAdapter = Nothing Dim dt As DataTable = New DataTable() Private Sub InformationControl_Load( ByVal sender As System.Object, ByVal e

  As System.EventArgs) Handles MyBase .Load conn.Open()

  Dim sqlString As String = "select Judul from tbl_Artikel"

  'Dim cmd As MySqlCommand = New MySqlCommand(sqlString, conn)

  data = New MySqlDataAdapter(sqlString, conn) data.Fill(dt) create_label() conn.Close()

  End Sub Private Sub create_label()

  Dim Y = lbl_Master.Location.Y Dim H = lbl_Master.Height Dim W = lbl_Master.Width Dim pos As Integer = 1 Dim idx As Integer = 0 Dim X = lbl_Master.Location.X For i = 0 To

  9 lbl_Array(idx) = New Label Me .Controls.Add(lbl_Array(idx)) lbl_Array(idx).Parent = lbl_Master.Parent lbl_Array(idx).Location = New System.Drawing.Point(X, Y) lbl_Array(idx).Size = New System.Drawing.Size(W, H) lbl_Array(idx).AutoSize = lbl_Master.AutoSize lbl_Array(idx).Font = lbl_Master.Font lbl_Array(idx).TextAlign = lbl_Master.TextAlign lbl_Array(idx).Tag = idx.ToString()

  If (dt.Rows.Count > idx) Then lbl_Array(idx).Text = dt.Rows(idx)(0).ToString() lbl_Array(idx).Visible = True

  End If lbl_Array(idx).BringToFront() lbl_Array(idx).Cursor = lbl_Master.Cursor

  AddHandler lbl_Array(idx).Click, AddressOf lblArray_click lbl_Array(idx).Visible = True Y += 30 idx += 1

  Next End Sub Private Sub lblArray_click( ByVal sender As Object , ByVal e As EventArgs)

  Dim Lbl_tmp As Label = CType (sender, Label) Dim i As Integer = CInt (Lbl_tmp.Tag) clear_label() lbl_Array(i).Font = New Font(lbl_Array(i).Font, FontStyle.Underline Xor FontStyle.Bold) lbl_Array(i).ForeColor = Color.Blue lbl_Judul.Text = lbl_Array(i).Text conn.Open()

  Dim dr As MySqlDataReader = Nothing Dim sqlString As String = "select Isi from tbl_Artikel where Judul = '"

  Next End Sub

  System.EventArgs) Handles MyBase .Load lblNama.Text = ":" lblBerat.Text = ":" lblJenis.Text = ":" lblTinggi.Text = ":" lblUmur.Text = ":" lblStatus.Text = ":"

  X As Double = 0 Dim score As Double = 0 Dim status As String = "" Dim predikat As Double () Dim Rules As String () Dim rentang1, rentang2, rentang3, a As Double Dim fuzzy As New FuzzyMamdani() Private Sub NutritionControl_Load( ByVal sender As System.Object, ByVal e As

  Dim xBerat As Double () Dim xTinggi As Double () Dim statusBerat As String () Dim statusTinggi As String () Dim looping As Integer = 0 Dim

  Dim conn As MySqlConnection = New MySqlConnection( My .MySettings.Default.ConnStr)

  Imports MySql.Data.MySqlClient Public Class NutritionControl

  End Class

  9 lbl_Array(i).ForeColor = Color.Black lbl_Array(i).Font = New Font(lbl_Array(i).Font, FontStyle.Regular)

  & lbl_Array(i).Text & "'"

  For i = 0 To

  End Sub Private Sub clear_label()

  End If End If conn.Close()

  Else txtIsi.Text = ""

  If (dr.Read()) Then If Not dr.IsDBNull(0) Then txtIsi.Text = dr.GetString(0)

  Dim cmd As MySqlCommand = New MySqlCommand(sqlString, conn) dr = cmd.ExecuteReader()

  'Dim cmd As MySqlCommand = New MySqlCommand(sqlString, conn)

NutritionControl.vb

  lblBBI.Text = ":" lblBMI.Text = ":" txtBerat.Text = "" txtNama.Text = "" txtTinggi.Text = "" txtUmur.Text = "" cmbJenis.SelectedIndex = -1

  End Sub Private Sub HimpunanFuzzy()

  Dim berat As Integer = 0 Dim tinggi As Integer = 0 Dim ScoreBBBerat, ScoreBBNormal, ScoreBBRingan As Double Dim ScoreTBTinggi, ScoreTBNormal, ScoreTBRendah As Double

  ScoreBBBerat = fuzzy.FuzzyBBBerat(txtBerat.Text) ScoreBBNormal = fuzzy.FuzzyBBNormal(txtBerat.Text) ScoreBBRingan = fuzzy.FuzzyBBRingan(txtBerat.Text)

  If ScoreBBBerat <> 0 Then berat += 1

  End If If ScoreBBNormal <> 0 Then berat += 1

  End If If ScoreBBRingan <> 0 Then berat += 1

  End If ScoreTBTinggi = fuzzy.FuzzyTBTinggi(txtTinggi.Text) ScoreTBNormal = fuzzy.FuzzyTBNormal(txtTinggi.Text) ScoreTBRendah = fuzzy.FuzzyTBRendah(txtTinggi.Text)

  If ScoreTBTinggi <> 0 Then tinggi += 1

  End If If ScoreTBNormal <> 0 Then tinggi += 1

  End If If ScoreTBRendah <> 0 Then tinggi += 1

  End If xBerat = New Double (berat - 1) {} statusBerat = New String (berat - 1) {}

  For i = 0 To xBerat.Length - 1 If (ScoreBBBerat <> 0) Then xBerat(i) = ScoreBBBerat statusBerat(i) = "Berat"

  Continue For End If If (ScoreBBNormal <> 0) Then xBerat(i) = ScoreBBNormal statusBerat(i) = "Normal"

  Continue For End If If (ScoreBBRingan <> 0) Then xBerat(i) = ScoreBBRingan statusBerat(i) = "Ringan"

  Continue For End If

  Next xTinggi = New Double (tinggi - 1) {} statusTinggi = New String (tinggi - 1) {} For i = 0 To xTinggi.Length - 1

  If (ScoreTBTinggi <> 0) Then xTinggi(i) = ScoreTBTinggi statusTinggi(i) = "Tinggi"

  ElseIf (berat = "Berat" And tinggi = "Rendah" ) Then retValue = "Gizi Lebih"

  For j = 0 To xTinggi.Length - 1 predikat(idx) = Math.Round(Math.Min(xBerat(i), xTinggi(j)), 2) Rules(idx) = AturanImplikasi(statusBerat(i), statusTinggi(j)) idx += 1

  Dim idx = 0 For i = 0 To xBerat.Length - 1

  Dim retValue As Double = 0 predikat = New Double ((xBerat.Length * xTinggi.Length) - 1) {} Rules = New String ((xBerat.Length * xTinggi.Length) - 1) {} looping = Rules.Length

  End Function Private Sub Implikasi()

  End If Return retValue

  ElseIf (berat = "Berat" And tinggi = "Tinggi" ) Then retValue = "Gizi Baik"

  ElseIf (berat = "Berat" And tinggi = "Normal" ) Then retValue = "Gizi Lebih"

  ElseIf (berat = "Normal" And tinggi = "Tinggi" ) Then retValue = "Gizi Kurang"

  Continue For End If If (ScoreTBNormal <> 0) Then xTinggi(i) = ScoreTBNormal statusTinggi(i) = "Normal"

  ElseIf (berat = "Normal" And tinggi = "Normal" ) Then retValue = "Gizi Baik"

  ElseIf (berat = "Normal" And tinggi = "Rendah" ) Then retValue = "Gizi Lebih"

  ElseIf (berat = "Ringan" And tinggi = "Tinggi" ) Then retValue = "Gizi Buruk"

  ElseIf (berat = "Ringan" And tinggi = "Normal" ) Then retValue = "Gizi Kurang"

  String ) As String Dim retValue As String = "" If (berat = "Ringan" And tinggi = "Rendah" ) Then retValue = "Gizi Baik"

  Next End Sub Private Function AturanImplikasi( ByVal berat As String , ByVal tinggi As

  Continue For End If

  Continue For End If If (ScoreTBRendah <> 0) Then xTinggi(i) = ScoreTBRendah statusTinggi(i) = "Rendah"

  Next Next End Sub Private Sub KomposisiAturan( ByVal nilai As Double , ByVal aturan As String )

  If (aturan = "Gizi Buruk" ) Then score = fuzzy.FuzzyGiziBuruk(nilai)

  If (score <= -3.5) Then rentang1 = score rentang2 = -3.5 rentang3 = 0

  ElseIf (score >= -3) Then rentang1 = -3 rentang2 = score rentang3 = 0

  Else rentang1 = -3.5 rentang2 = score rentang3 = -3 a = 3

  End If ElseIf (aturan = "Gizi Kurang" ) Then score = fuzzy.FuzzyGiziKurang(nilai)

  If (score <= -3) Then rentang1 = score rentang2 = -3 rentang3 = 0

  ElseIf (score >= -2.5) Then rentang1 = -2 rentang2 = score rentang3 = 0

  Else rentang1 = -3 rentang2 = score rentang3 = -2 a = 2

  End If ElseIf (aturan = "Gizi Baik" ) Then score = fuzzy.FuzzyGiziBaik(nilai)

  If (score <= -2) Then rentang1 = score rentang2 = -2 rentang3 = 0

  ElseIf (score >= 2) Then rentang1 = 2 rentang2 = score rentang3 = 0

  Else rentang1 = -2 rentang2 = score rentang3 = 2 a = 2

  End If ElseIf (aturan = "Gizi Lebih" ) Then score = fuzzy.FuzzyGiziLebih(nilai)

  If (score <= 2) Then rentang1 = score rentang2 = 2 rentang3 = 0

  ElseIf (score >= 3) Then rentang1 = 3 rentang2 = score rentang3 = 0

  Else rentang1 = 2 rentang2 = score rentang3 = 3 a = 3

  End If End If

  End Sub Private Function Defuzzifikasi( ByVal nilai As Double , ByVal aturan As

  String ) As Double Dim retValue As Double = 0 If rentang3 = 0 Then retValue = hitungIntegral(rentang1, rentang2, nilai)

  Else retValue = hitungIntegral(rentang1, rentang2, rentang3, nilai, a, aturan)

  End If Return retValue

  End Function Private Function hitungIntegral( ByVal x As Double , ByVal y As Double , ByVal nilai As Double ) As Double

  Dim retValue As Double = 0 Dim hasil1, hasil2 As Double hasil1 = (nilai * (x ^ 2) / 2) - (nilai * (y ^ 2) / 2) hasil2 = (nilai * x) - (nilai * y) retValue = hasil1 / hasil2

  Return Math.Round(retValue, 3) End Function Private Function hitungIntegral( ByVal x As Double , ByVal y As Double , ByVal z As Double , ByVal nilai As Double , ByVal a As Double , ByVal aturan As String ) As Double

  Dim retValue As Double = 0 Dim hasil1, hasil2, hasil3, hasil4 As Double hasil1 = (nilai * (x ^ 2) / 2) - (nilai * (y ^ 2) / 2) hasil2 = (nilai * x) - (nilai * y)

  If (aturan = "Gizi Buruk" Or aturan = "Gizi Kurang" ) Then hasil3 = (((y ^ 3) / 3) + ((a * (y ^ 2)) / 2)) - (((z ^ 3) / 3) + ((a * (z ^ 2)) / 2)) hasil4 = (((y ^ 2) / 2) + (a * y)) - (((z ^ 2) / 2) + (a * z))

  Else hasil3 = (((a * (y ^ 2)) / 2) - ((y ^ 3) / 3)) - (((a * (z ^ 2)) / 2) - ((z ^ 3) / 3)) hasil4 = ((a * y) - ((y ^ 2) / 2)) - ((a * z) - ((z ^ 2) / 2))

  End If retValue = (hasil1 + hasil3) / hasil2 + hasil4

  Return Math.Round(retValue, 3) End Function Private Sub btnProses_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProses.Click Dim NilaiAturan As Double = 0 Dim statusGizi As String = ""

  X = 0 HimpunanFuzzy() Implikasi()

  For i = 0 To looping - 1 KomposisiAturan(predikat(i), Rules(i)) X += Defuzzifikasi(predikat(i), Rules(i))

  Next statusGizi = fuzzy.cekGizi(X) lblBBI.Text = ": " & Math.Round(hitungBBI(txtUmur.Text), 2) & " Kg" lblBMI.Text = ": " & Math.Round(hitungBMI(txtBerat.Text, txtTinggi.Text), 2) & " Kg/m2" lblNama.Text = ": " & txtNama.Text lblBerat.Text = ": " & txtBerat.Text & " Kg" lblJenis.Text = ": " & cmbJenis.Text lblTinggi.Text = ": " & txtTinggi.Text & " cm" lblUmur.Text = ": " & txtUmur.Text & " bulan" lblStatus.Text = ": " & statusGizi & " (" & X & ")" conn.Open()

  Dim sqlString As String = "Insert into tbl_Nutrisi values(@Nama, @Umur,

  @Jenis, @Berat, @Tinggi, @Status, @BBI, @BMI)"

  Dim cmd As MySqlCommand = New MySqlCommand(sqlString, conn) cmd.Parameters.AddWithValue( "@Nama" , txtNama.Text) cmd.Parameters.AddWithValue( "@Umur" , txtUmur.Text) cmd.Parameters.AddWithValue( "@Jenis" , cmbJenis.Text) cmd.Parameters.AddWithValue( "@Berat" , txtBerat.Text) cmd.Parameters.AddWithValue( "@Tinggi" , txtTinggi.Text) cmd.Parameters.AddWithValue( "@Status" , statusGizi) cmd.Parameters.AddWithValue( "@BBI" , lblBBI.Text.Substring(2, lblBBI.Text.Length - 3)) cmd.Parameters.AddWithValue( "@BMI" , lblBMI.Text.Substring(2, lblBMI.Text.Length - 5)) cmd.ExecuteNonQuery() conn.Close() MessageBox.Show( "Data berhasil di proses" )

  End Sub Private Function hitungBBI( ByVal umur As Integer ) As Double

  Dim BBI As Double = 0 If umur <= 12 Then

  BBI = (umur / 2) + 4 Else

  BBI = ((umur / 12) * 2) + 8 End If Return BBI

  End Function Private Function hitungBMI( ByVal berat As Double , ByVal tinggi As Double )

  As Double Dim BMI As Double = 0 tinggi /= 100 BMI = berat / (tinggi * tinggi)

  Return BMI End Function Private Sub btnCancel_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click NutritionControl_Load( Nothing , Nothing )

  End Sub Private Sub txtUmur_Validating( ByVal sender As System.Object, ByVal e As

  System.ComponentModel.CancelEventArgs) Handles txtUmur.Validating Try

  If ( Integer .Parse(txtUmur.Text) > 60) Then MessageBox.Show( "Umur hanya dibawah 5 Tahun (60 Bulan)" ) e.Cancel = True

  End If Catch ex As Exception

  MessageBox.Show( "Umur Invalid" ) e.Cancel = True

  End Try End Sub Private Sub txtBerat_Validating( ByVal sender As System.Object, ByVal e As

  System.ComponentModel.CancelEventArgs) Handles txtBerat.Validating Try

  If ( Integer .Parse(txtBerat.Text) > 25) Then MessageBox.Show( "Berat Badan hanya dibawah 25 Kg" ) e.Cancel = True

  End If Catch ex As Exception

  MessageBox.Show( "Berat Badan Invalid" ) e.Cancel = True

  End Try End Sub Private Sub txtTinggi_Validating( ByVal sender As System.Object, ByVal e As

  System.ComponentModel.CancelEventArgs) Handles txtTinggi.Validating Try

  If ( Integer .Parse(txtTinggi.Text) > 130) Then MessageBox.Show( "Tinggi Badan hanya dibawah 130 cm" ) e.Cancel = True

  End If Catch ex As Exception

  MessageBox.Show( "Tinggi Badan Invalid" ) e.Cancel = True

  End Try End Sub

  End Class

SettingControl.vb

  Imports MySql.Data.MySqlClient Public Class SettingControl

  Dim conn As MySqlConnection = New MySqlConnection( My .MySettings.Default.ConnStr)

  Private Function Login() As Boolean Dim ret As Boolean = False conn.Open()

  Dim sqlString As String = "SELECT * FROM tbl_User WHERE Username =

  @Username AND Password = @Password"

  Dim cmd As MySqlCommand = New MySqlCommand(sqlString, conn) cmd.Parameters.AddWithValue( "@Username" , txtUsername.Text) cmd.Parameters.AddWithValue( "@Password" , txtPassword.Text)

  Dim dr As MySqlDataReader = cmd.ExecuteReader() If (dr IsNot Nothing ) Then

  If (dr.Read) Then If (dr.HasRows) Then ret = True

  End If End If dr.Close() dr = Nothing

  End If conn.Close()

  Return ret End Function Private Sub btnLogin_Click( ByVal sender As System.Object, ByVal e As

  System.EventArgs) Handles btnLogin.Click If (Login()) Then txtPassword.Text = "" txtUsername.Text = ""

  Dim frm1 As New FormAdmin frm1.ShowDialog()

  Else MessageBox.Show( "Username atau Password salah" , "Login gagal" , MessageBoxButtons.OK, MessageBoxIcon.Error) txtPassword.Text = "" txtPassword.Focus()

  End If End Sub Private Sub btnCancel_Click( ByVal sender As System.Object, ByVal e As

  System.EventArgs) Handles btnCancel.Click txtPassword.Text = "" txtUsername.Text = "" txtUsername.Focus()

  End Sub Private Sub txtPassword_KeyDown( ByVal sender As System.Object, ByVal e As

  System.Windows.Forms.KeyEventArgs) Handles txtPassword.KeyDown If (e.KeyData = Keys.Enter) Then btnLogin_Click( Nothing , Nothing )

  End If End Sub

  End Class