Listing Program Module1
Imports MySql.Data.MySqlClient
Module Module1
Public SQL, SQL1 As String
Public db As New MySql.Data.MySqlClient.MySqlConnection
Public cmd As MySqlCommand
Public rs As MySqlDataReader
Public ADP As MySqlDataAdapter
Public DS As New DataSet
Sub OpenDB()
SQL = "server=localhost;uid=root;pwd=;database=dbst"
Try
db.ConnectionString = SQL
db.Open()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Module
Form Login
Listing Programnya
Public Class frmLogin
Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Username.Text = ""
Password.Text = ""
Password.PasswordChar = "*"
End Sub
Private Sub btnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSimpan.Click
Me.Close()
End Sub
Private Sub btnBaru_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBaru.Click
If Username.Text = "1" And Password.Text = "1" Then
Me.Hide()
menuutama.Show()
Else
MsgBox("Password dan Username salah !")
Username.Focus()
End If
End Sub
End Class
Form Mahasiswa
Listing program
Imports MySql.Data.MySqlClient
Public Class frmMahasiswa
Sub Hapus()
NPM.Text = ""
Nama.Text = ""
Jenjang.Text = ""
Jurusan.Text = ""
Tahun.Text = ""
DosenWali.Text = ""
Call RubahButton(0)
EnabledForm(True)
End Sub
Sub EnabledForm(ByVal log As Boolean)
NPM.Enabled = log
Nama.Enabled = Not log
Jenjang.Enabled = Not log
Jurusan.Enabled = Not log
Tahun.Enabled = Not log
DosenWali.Enabled = Not log
End Sub
Sub RubahButton(ByVal log As Byte)
Select Case log
Case 0
btnBaru.Enabled = True
btnSimpan.Enabled = False
btnSimpan.Text = "Simpan"
btnBatal.Enabled = False
btnKeluar.Enabled = True
btnHapus.Enabled = False
Case 1
btnBaru.Enabled = False
btnSimpan.Enabled = True
btnBatal.Enabled = True
btnKeluar.Enabled = False
btnHapus.Enabled = False
Case 2
btnSimpan.Text = "Edit"
btnBaru.Enabled = False
btnSimpan.Enabled = True
btnBatal.Enabled = True
btnKeluar.Enabled = False
btnHapus.Enabled = True
End Select
End Sub
Sub ProsesDB(ByVal log As Byte)
Select Case log
Case 0
SQL = "INSERT INTO MAHASISWA(NPM,Nama,JENJANG,JURUSAN,TAHUN,WALI) VALUES('" & _
NPM.Text & "','" & _
Nama.Text & "','" & _
Jenjang.Text & "')"
Case 1
SQL = "UPDATE MAHASISWA SET NAMA='" & Nama.Text & "', " & _
" JENJANG='" & Jenjang.Text & "', " & _
" JURUSAN='" & Jurusan.Text & "', " & _
" TAHUN='" & Tahun.Text & "', " & _
" WALI='" & DosenWali.Text & "' " & _
" WHERE npm='" & NPM.Text & "'"
Case 2
SQL = "DELETE FROM MAHASISWA WHERE npm='" & NPM.Text & "'"
End Select
Try
cmd = New MySqlCommand(SQL, db)
cmd.ExecuteNonQuery()
Call Hapus()
NPM.Focus()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Sub TampilMahasiswa()
ADP = New MySqlDataAdapter("SELECT * FROM MAHASISWA", db)
DS = New DataSet
ADP.Fill(DS, "MAHASISWA")
DataGridView1.DataSource = DS.Tables("MAHASISWA")
End Sub
Private Sub frmMahasiswa_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TampilMahasiswa()
Call Hapus()
End Sub
Private Sub btnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSimpan.Click
Dim x As String = MsgBox("YAKIN akan disimpan?", MsgBoxStyle.Information + MsgBoxStyle.OkCancel, "Konfirmasi")
If x = vbOK Then
If btnSimpan.Text = "Simpan" Then
ProsesDB(0)
Else
ProsesDB(1)
End If
End If
End Sub
Private Sub btnHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHapus.Click
Dim x As String = MsgBox("YAKIN akan dihapus?", MsgBoxStyle.Information + MsgBoxStyle.OkCancel, "Konfirmasi")
If x = vbOK Then
ProsesDB(2)
End If
End Sub
Private Sub btnBatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBatal.Click
Call Hapus()
NPM.Focus()
End Sub
Private Sub btnBaru_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBaru.Click
Call Hapus()
NPM.Focus()
End Sub
Private Sub btnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKeluar.Click
Me.Close()
End Sub
Private Sub NPM_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles NPM.KeyPress
Dim x As String
If Asc(e.KeyChar) = 13 Then
If NPM.Text = "" Then Exit Sub
SQL = "select * from MAHASISWA where NPM='" & NPM.Text & "'"
cmd = New MySqlCommand(SQL, db)
rs = cmd.ExecuteReader
Try
If rs.HasRows Then
rs.Read()
Nama.Text = rs("Nama")
Jenjang.Text = rs("Jenjang")
Jurusan.Text = rs("Jurusan")
Tahun.Text = rs("Tahun")
DosenWali.Text = rs("Wali")
Call RubahButton(2)
Else
x = NPM.Text
Call Hapus()
NPM.Text = x
Call RubahButton(1)
End If
Catch ex As Exception
End Try
EnabledForm(False)
Nama.Focus()
rs.Close()
End If
End Sub
Private Sub SearchNama_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchNama.TextChanged
ADP = New MySqlDataAdapter("SELECT * FROM MAHASISWA WHERE NAMA like'%" & SearchNama.Text & "%'", db)
DS = New DataSet
ADP.Fill(DS, "MAHASISWA")
DataGridView1.DataSource = DS.Tables("MAHASISWA")
End Sub
End Class
Form Dosen
Listing Programnya
Imports MySql.Data.MySqlClient
Public Class frmDosen
Sub Hapus()
KdDosen.Text = ""
Nama.Text = ""
Pendidikan.Text = ""
Call RubahButton(0)
EnabledForm(True)
End Sub
Sub EnabledForm(ByVal log As Boolean)
KdDosen.Enabled = log
Nama.Enabled = Not log
Pendidikan.Enabled = Not log
End Sub
Sub RubahButton(ByVal log As Byte)
Select Case log
Case 0
btnBaru.Enabled = True
btnSimpan.Enabled = False
btnSimpan.Text = "Simpan"
btnBatal.Enabled = False
btnKeluar.Enabled = True
btnHapus.Enabled = False
Case 1
btnBaru.Enabled = False
btnSimpan.Enabled = True
btnBatal.Enabled = True
btnKeluar.Enabled = False
btnHapus.Enabled = False
Case 2
btnSimpan.Text = "Edit"
btnBaru.Enabled = False
btnSimpan.Enabled = True
btnBatal.Enabled = True
btnKeluar.Enabled = False
btnHapus.Enabled = True
End Select
End Sub
Sub ProsesDB(ByVal log As Byte)
Select Case log
Case 0
SQL = "INSERT INTO DOSEN(KDDOSEN,NAMA,PENDIDIKAN) VALUES('" & _
KdDosen.Text & "','" & _
Nama.Text & "','" & _
Pendidikan.Text & "')"
Case 1
SQL = "UPDATE DOSEN SET NAMA='" & Nama.Text & "', " & _
" PENDIDIKAN='" & Pendidikan.Text & "' " & _
" WHERE KDDOSEN='" & KdDosen.Text & "'"
Case 2
SQL = "DELETE FROM DOSEN WHERE KDDOSEN='" & KdDosen.Text & "'"
End Select
Try
cmd = New MySqlCommand(SQL, db)
cmd.ExecuteNonQuery()
Call Hapus()
KdDosen.Focus()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Sub TampilDosen()
ADP = New MySqlDataAdapter("SELECT * FROM Dosen", db)
DS = New DataSet
ADP.Fill(DS, "Dosen")
DataGridView1.DataSource = DS.Tables("Dosen")
End Sub
Private Sub btnBaru_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBaru.Click
Call Hapus()
KdDosen.Focus()
End Sub
Private Sub btnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSimpan.Click
Dim x As String = MsgBox("YAKIN akan disimpan?", MsgBoxStyle.Information + MsgBoxStyle.OkCancel, "Konfirmasi")
If x = vbOK Then
If btnSimpan.Text = "Simpan" Then
ProsesDB(0)
Else
ProsesDB(1)
End If
End If
End Sub
Private Sub btnHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHapus.Click
Dim x As String = MsgBox("YAKIN akan dihapus?", MsgBoxStyle.Information + MsgBoxStyle.OkCancel, "Konfirmasi")
If x = vbOK Then
ProsesDB(2)
End If
End Sub
Private Sub btnBatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBatal.Click
Call Hapus()
KdDosen.Focus()
End Sub
Private Sub btnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKeluar.Click
Me.Close()
End Sub
Private Sub frmDosen_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TampilDosen()
Call Hapus()
End Sub
Private Sub KdDosen_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles KdDosen.KeyPress
Dim x As String
If Asc(e.KeyChar) = 13 Then
If KdDosen.Text = "" Then Exit Sub
SQL = "select * from Dosen where KdDosen='" & KdDosen.Text & "'"
cmd = New MySqlCommand(SQL, db)
rs = cmd.ExecuteReader
Try
If rs.HasRows Then
rs.Read()
Nama.Text = rs("Nama")
Pendidikan.Text = rs("Pendidikan")
Call RubahButton(2)
Else
x = KdDosen.Text
Call Hapus()
KdDosen.Text = x
Call RubahButton(1)
End If
Catch ex As Exception
End Try
EnabledForm(False)
Nama.Focus()
rs.Close()
End If
End Sub
End Class
Form Menu
Listing Programnya
Public Class menuutama
Private Sub FormMahasiswaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FormMahasiswaToolStripMenuItem.Click
frmMahasiswa.MdiParent = Me
frmMahasiswa.Show()
End Sub
Private Sub LapMahasiswaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LapMahasiswaToolStripMenuItem.Click
frmLaporan.MdiParent = Me
frmLaporan.Text = "LAPORAN MAHASISWA"
frmLaporan.Show()
frmLaporan.WindowState = FormWindowState.Maximized
End Sub
Private Sub LaporanDosenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LaporanDosenToolStripMenuItem.Click
frmLaporan.MdiParent = Me
frmLaporan.Text = "LAPORAN DOSEN"
frmLaporan.Show()
frmLaporan.WindowState = FormWindowState.Maximized
End Sub
Private Sub FormDosenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FormDosenToolStripMenuItem.Click
frmDosen.MdiParent = Me
frmDosen.Show()
End Sub
Private Sub menuutama_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call OpenDB()
End Sub
End Class
Hasil Laporan Dosen
Hasil Laporan Mahasiswa
Terima kasih banyak..sangat membantu, semoga bermanfaat dan mendapat balasan dari-NYA.
ReplyDeleteTerima kasih banyak pak, sangat membantu dan semoga dibalas kebaikan oleh-NYA
ReplyDelete