Sei sulla pagina 1di 7

LAPORAN UJIAN PRAKTIKUM

Mata Kuliah : Pemrograman Dasar


Semester : II (Dua)
Dosen Pengampu : Yuni Anita, S.Kom., M.Kom.,

Oleh
Tamia Salsabila Namira Lesmana
181336300013

PROGRAM STUDI DIV MANAJEMEN INFORMASI KESEHATAN


FAKULTAS ILMU KESEHATAN
UNIVERSITAS MUHAMMADIYAH SIDOARJO
TAHUN AJARAN 2018/2019
1. Membuat Database melalui Ms. Access

2. Membuat Form Di Visual Basic

3. Membuat Module
Imports System.Data.OleDb
Module Ujian

Public conn As OleDbConnection


Public daData As New OleDbDataAdapter
Public dsData As New DataSet
Public query As String

Public Sub Rekap()


conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data
Source=D:\Nilai\Nilai\bin\Debug\UAS.accdb;")
conn.Open()
End Sub

End Module

4. Melakukan Koding
Imports System.Data.OleDb
Public Class Form1
Private Sub PosisiList()
Try
With ListView1.Columns
.Add("NIM", 100)
.Add("Nama", 100)
.Add("Nilai UTS", 100)
.Add("Nilai UAS", 100)
.Add("Tugas", 100)
.Add("Total", 100)
End With
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Private Sub IsiList()

Try
query = "SELECT * FROM DBNilai ORDER BY NIM"
daData = New OleDbDataAdapter(query, conn)
dsData = New DataSet
daData.Fill(dsData)
ListView1.Items.Clear()

For a = 0 To dsData.Tables(0).Rows.Count - 1
With ListView1
.Items.Add(dsData.Tables(0).Rows(a).Item(0))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(1))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(2))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(3))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(4))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(5))
End With
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Private Sub AmbilDataListView()


With ListView1.SelectedItems
Try
txtNIM.Text = .Item(0).SubItems(0).Text
txtNama.Text = .Item(0).SubItems(1).Text
txtNUts.Text = .Item(0).SubItems(2).Text
txtNUas.Text = .Item(0).SubItems(3).Text
txtTugas.Text = .Item(0).SubItems(4).Text
txtTotal.Text = .Item(0).SubItems(5).Text
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End With
End Sub

Private Sub bersih()


IsiList()
txtNIM.Text = ""
txtNama.Text = ""
txtNUts.Text = ""
txtNUas.Text = ""
txtTugas.Text = ""
txtTotal.Text = ""
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
txtNIM.Focus()
btnEdit.Enabled = False
btnHapus.Enabled = False

Try
Rekap()
PosisiList()
IsiList()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Private Sub btnSimpan_Click(sender As Object, e As EventArgs) Handles btnSimpan.Click


Dim x As Object = MessageBox.Show("Data TERSIMPAN", "SIMPAN",
MessageBoxButtons.OKCancel, MessageBoxIcon.Question)

Try
query = "INSERT INTO DBNilai VALUES ('" & txtNIM.Text & "', '" & txtNama.Text
& "', '" & txtNUts.Text & _
"', '" & txtNUas.Text & "', '" & txtTugas.Text & "', '" & txtTotal.Text &
"')"
daData = New OleDbDataAdapter(query, conn)
dsData = New DataSet
daData.Fill(dsData)

IsiList()

bersih()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles


ListView1.SelectedIndexChanged
btnEdit.Enabled = True
btnHapus.Enabled = True
btnSimpan.Enabled = False
txtNIM.Focus()

Try
AmbilDataListView()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Private Sub btnEdit_Click(sender As Object, e As EventArgs) Handles btnEdit.Click


Dim x As Object = MessageBox.Show("Data Berhasil di EDIT", "EDIT",
MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk)

Try
query = "UPDATE DBNilai SET NIM = '" & txtNIM.Text & "', Nama = '" &
txtNama.Text & "', NilaiUts= '" & txtNUts.Text & "', NilaiUas= '" & txtNUas.Text & _
"', Tugas= '" & txtTugas.Text & "', Total= '" & txtTotal.Text & "' WHERE
NIM='" & txtNIM.Text & "'"
daData = New OleDbDataAdapter(query, conn)
dsData = New DataSet
daData.Fill(dsData)
IsiList()

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Private Sub btnHapus_Click(sender As Object, e As EventArgs) Handles btnHapus.Click


Dim x As Object = MessageBox.Show("Apakah Data Akan DIHAPUS?", "HAPUS",
MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk)

If x = Windows.Forms.DialogResult.OK Then
query = "DELETE FROM DBNilai WHERE NIM='" & txtNIM.Text & "'"

daData = New OleDbDataAdapter(query, conn)


dsData = New DataSet
daData.Fill(dsData)
MsgBox("DATA BERHASIL DIHAPUS", MsgBoxStyle.Information, "HAPUS")
IsiList()

bersih()

txtNIM.Focus()
ElseIf x = Windows.Forms.DialogResult.Cancel Then
bersih()
btnEdit.Enabled = False
btnHapus.Enabled = False
txtNIM.Enabled = True
txtNIM.Focus()
btnSimpan.Enabled = True
End If
End Sub

Private Sub btnBersih_Click(sender As Object, e As EventArgs) Handles btnBersih.Click


txtNIM.Enabled = True
txtNIM.Focus()

bersih()
End Sub

Private Sub txtTugas_KeyPress(sender As Object, e As KeyPressEventArgs) Handles


txtTugas.KeyPress
If e.KeyChar = Chr(13) Then
txtTotal.Focus()
End If

If Not (e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack Then
e.Handled = True
End If
End Sub

Private Sub txtNUts_KeyPress(sender As Object, e As KeyPressEventArgs) Handles


txtNUts.KeyPress
If e.KeyChar = Chr(13) Then
txtNUas.Focus()
End If

If Not (e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack Then
e.Handled = True
End If
End Sub

Private Sub txtNUas_KeyPress(sender As Object, e As KeyPressEventArgs) Handles


txtNUas.KeyPress
If e.KeyChar = Chr(13) Then
txtTugas.Focus()
End If

If Not (e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack Then
e.Handled = True
End If
End Sub

Private Sub btnTotal_Click(sender As Object, e As EventArgs) Handles btnTotal.Click


txtTotal.Text = (0.4 * txtTugas.Text) + (0.3 * txtNUts.Text) + (0.3 *
txtNUas.Text)
End Sub
End Class

5. Halaman depan ketika dijalankan

Potrebbero piacerti anche