- Instal XAMPP
- Instal Crystal Report 8.5
- Instal Mysql-Connector NET
- Instal Mysql-Connector ODBC
Buat Database Sebagai Berikut
Dan Desain Form Program Sebagai Berikut :
Dan Desain Juga Form Laporan Sebagai Berikut :
Lalu Buat Modul Koneksi Dengan Cara Sebagai Berikut :
Dengan Source Code
Module Moduleku
Public CONN
As String = "Server=localhost;user
id=root;database=data_mahasiswa"
End Module
Ket: Saya Disini Memberi Nama Modul Saya Dengan Nama : Moduleku
Setelah Menulis Code Di Atas Lalu Buat ODBC Dengan Cara Membuka
Control Panel - AdministrativeTools - ODBC Lalu ADD
Kemudian Pilih MySQL ODBC 5.1 Driver
Dan Finish
Setelah Itu Isi Data Data Seperti Di Gambar
Lalu Klik Test Maka Akan Muncul Connection Succesful
Langkah Selanjutnya Buatlah Sebuah Format Seperti Gambar Dibawah ini:
Lalu Simpan Dengan Nama Laporan.rpt
Dan Sekarang Saatnya Menulisnya Source Code Untuk Programnya
Maka Tujuan Mata Berpindah Ke VBNET
Selanjutnya Isilah Source Code Programnya
Public Class menuutama
Private Sub TAMPILDATA()
Try
Using
KONEKSI As New
MySqlConnection(CONN)
Using
CMD As New
MySqlCommand("SELECT * FROM pendaftaran ",
KONEKSI)
KONEKSI.Open()
Using
DATA As MySqlDataReader = CMD.ExecuteReader
ListView1.Items.Clear()
Dim ListItem As ListViewItem
While DATA.Read
ListItem = New ListViewItem()
ListItem =
ListView1.Items.Add(DATA("no_pendaftaran"))
ListItem.SubItems.Add(DATA("nama_mahasiswa"))
ListItem.SubItems.Add(DATA("tempat_lahir"))
ListItem.SubItems.Add(DATA("tanggal_lahir"))
ListItem.SubItems.Add(DATA("jenkel"))
ListItem.SubItems.Add(DATA("agama"))
ListItem.SubItems.Add(DATA("asal_sekolah"))
ListItem.SubItems.Add(DATA("jurusan"))
ListItem.SubItems.Add(DATA("alamat"))
ListItem.SubItems.Add(DATA("no_hp"))
End While
End
Using
End
Using
End
Using
Catch
ex As Exception
MsgBox(ex.Message())
End Try
End Sub
Private Sub cetak()
FormLaporan.CrystalReportViewer1.ReportSource = "laporan.rpt"
FormLaporan.CrystalReportViewer1.SelectionFormula = "{pendaftaran.no_pendaftaran}='" &
TextBox1.Text & "'"
FormLaporan.CrystalReportViewer1.RefreshReport()
FormLaporan.CrystalReportViewer1.Zoom(85)
FormLaporan.ShowDialog()
End Sub
Private Sub nootomatis()
Try
Using
KONEKSI As New
MySqlConnection(CONN)
Using
CMD As New
MySqlCommand("SELECT MAX
(RIGHT(pendaftaran.no_pendaftaran,3))AS NO FROM pendaftaran",
KONEKSI)
KONEKSI.Open()
Dim
jumlahdata As String
Using
Data As MySqlDataReader = CMD.ExecuteReader
If Data.Read = True Then
If IsDBNull(Data("NO"))
Then
TextBox1.Text =
"REG" & "001"
Else
jumlahdata = Data("NO") + 1
If Len(jumlahdata) = 1 Then
TextBox1.Text = "REG" &
"00" & jumlahdata
ElseIf Len(jumlahdata) = 2 Then
TextBox1.Text = "REG" &
"0" & jumlahdata
Else
TextBox1.Text = "REG" &
jumlahdata
End If
End If
End If
End
Using
End
Using
End
Using
Catch
ex As Exception
End Try
End Sub
Private Sub BERSIH()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
DateTimePicker1.Text = ""
ComboBox1.Text = "-Pilih-"
ComboBox2.Text = "-Pilih-"
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox2.Focus()
End Sub
Private Sub menuutama_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TAMPILDATA()
BERSIH()
nootomatis()
End Sub
Private Sub ListView1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
ListView1.SelectedIndexChanged
Try
TextBox1.Text =
ListView1.SelectedItems(0).Text
TextBox2.Text =
ListView1.SelectedItems(0).SubItems(1).Text.ToString
TextBox3.Text =
ListView1.SelectedItems(0).SubItems(2).Text.ToString
DateTimePicker1.Text =
ListView1.SelectedItems(0).SubItems(3).Text.ToString
ComboBox1.Text =
ListView1.SelectedItems(0).SubItems(4).Text.ToString
ComboBox2.Text =
ListView1.SelectedItems(0).SubItems(5).Text.ToString
TextBox4.Text =
ListView1.SelectedItems(0).SubItems(6).Text.ToString
TextBox5.Text =
ListView1.SelectedItems(0).SubItems(7).Text.ToString
TextBox6.Text =
ListView1.SelectedItems(0).SubItems(8).Text.ToString
TextBox7.Text =
ListView1.SelectedItems(0).SubItems(9).Text.ToString
Catch
ex As Exception
End Try
End Sub
Private Sub Button1_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim
tanggal As Date
tanggal = DateTimePicker1.Value
If
TextBox1.Text = "" Then
MsgBox("No
Pendaftaran Tidak Boleh Kosong ...!", MsgBoxStyle.Information, "Lengkapi Data")
TextBox1.Focus()
ElseIf
TextBox2.Text = "" Then
MsgBox("Nama
Mahasiswa Tidak Boleh Kosong ...!", MsgBoxStyle.Information, "Lengkapi Data")
TextBox2.Focus()
ElseIf
TextBox3.Text = "" Then
MsgBox("Tempat
Lahir Tidak Boleh Kosong ...!", MsgBoxStyle.Information, "Lengkapi Data")
TextBox3.Focus()
ElseIf
DateTimePicker1.Text = "" Then
MsgBox("Tanggal
Lahir Tidak Boleh Kosong ...!", MsgBoxStyle.Information, "Lengkapi Data")
DateTimePicker1.Focus()
ElseIf
ComboBox1.Text = "-Pilih-" Then
MsgBox("Jenis
Kelamin Tidak Boleh Kosong ...!", MsgBoxStyle.Information, "Lengkapi Data")
ComboBox1.Focus()
ElseIf
ComboBox2.Text = "-Pilih-" Then
MsgBox("Agama
Tidak Boleh Kosong ...!", MsgBoxStyle.Information, "Lengkapi Data")
ComboBox2.Focus()
ElseIf
TextBox4.Text = "" Then
MsgBox("Asal
Sekolah Tidak Boleh Kosong ...!", MsgBoxStyle.Information, "Lengkapi Data")
TextBox4.Focus()
ElseIf
TextBox5.Text = "" Then
MsgBox("Jurusan
Tidak Boleh Kosong ...!", MsgBoxStyle.Information, "Lengkapi Data")
TextBox5.Focus()
ElseIf
TextBox6.Text = "" Then
MsgBox("Alamat
Tidak Boleh Kosong ...!", MsgBoxStyle.Information, "Lengkapi Data")
TextBox6.Focus()
ElseIf
TextBox7.Text = "" Then
MsgBox("No
HP Tidak Boleh Kosong ...!", MsgBoxStyle.Information, "Lengkapi Data")
TextBox7.Focus()
Else
If
MsgBox("Yakin Data Ingin Disimpan !",
MsgBoxStyle.YesNo, "Simpan Data")
= MsgBoxResult.Yes Then
Try
Using
KONEKSI As New
MySqlConnection(CONN)
Using CMD As New MySqlCommand("INSERT
INTO pendaftaran VALUES ('"
& TextBox1.Text & _
"','" & TextBox2.Text
& "','" & TextBox3.Text
& "','" &
DateTimePicker1.Text & "','"
& ComboBox1.Text & "','"
& ComboBox2.Text & "','"
& TextBox4.Text & "','"
& TextBox5.Text & "','"
& TextBox6.Text & "','"
& TextBox7.Text & "')",
KONEKSI)
KONEKSI.Open()
Using Data As
MySqlDataReader = CMD.ExecuteReader
End Using
End Using
End
Using
MsgBox("Data Sudah Berhasil Disimpan",
MsgBoxStyle.Information, "Pesan")
cetak()
Catch ex As Exception
MsgBox(ex.Message())
End
Try
Else
TAMPILDATA()
BERSIH()
End
If
End If
End Sub
Private Sub Button2_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If
MsgBox("Yakin Data Ingin Diubah !",
MsgBoxStyle.YesNo, "Ubah Data !!!")
= MsgBoxResult.Yes Then
Try
Using
KONEKSI As New
MySqlConnection(CONN)
Using
CMD As New
MySqlCommand("UPDATE pendaftaran SET
nama_mahasiswa= '" & TextBox2.Text & _
"', tempat_lahir= '" &
TextBox3.Text & _
"', tanggal_lahir= '" &
DateTimePicker1.Text & _
"', jenkel= '" &
ComboBox1.Text & _
"', agama= '" &
ComboBox2.Text & _
"',
asal_sekolah= '" & TextBox4.Text & _
"', jurusan= '" &
TextBox5.Text & _
"', alamat= '" &
TextBox6.Text & _
"',
no_hp= '" & TextBox7.Text & _
"' where no_pendaftaran= '"
& TextBox1.Text & "' ",
KONEKSI)
KONEKSI.Open()
Using Data As MySqlDataReader =
CMD.ExecuteReader
End Using
End
Using
End
Using
MsgBox("Data
Sudah Berhasil Diubah", MsgBoxStyle.Information, "Pesan")
TAMPILDATA()
BERSIH()
Catch ex
As Exception
MsgBox(ex.Message())
End
Try
Else
BERSIH()
End If
End Sub
Private Sub Button3_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
If
TextBox1.Text = "" Then
MsgBox("Pilih
Datanya Dulu Coy....", MsgBoxStyle.Information, "Pilih Data")
Else
Using
KONEKSI As New
MySqlConnection(CONN)
Using
CMD As New
MySqlCommand("DELETE FROM pendaftaran WHERE
no_pendaftaran='" & _
TextBox1.Text & "'",
KONEKSI)
KONEKSI.Open()
Using
Data As MySqlDataReader = CMD.ExecuteReader
End
Using
End
Using
End
Using
MsgBox("Data
Sudah Berhasil Dihapus", MsgBoxStyle.Information, "Hapus Data User")
TAMPILDATA()
End If
End Sub
Private Sub DateTimePicker1_KeyDown(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyEventArgs) Handles
DateTimePicker1.KeyDown
If
e.KeyCode = 13 Then
ComboBox1.Focus()
End If
End Sub
Private Sub TextBox1_KeyDown(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyEventArgs) Handles
TextBox1.KeyDown
If
e.KeyCode = 13 Then
TextBox2.Focus()
End If
End Sub
Private Sub TextBox2_KeyDown(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyEventArgs) Handles
TextBox2.KeyDown
If
e.KeyCode = 13 Then
TextBox3.Focus()
End If
End Sub
Private Sub TextBox3_KeyDown(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyEventArgs) Handles
TextBox3.KeyDown
If e.KeyCode
= 13 Then
DateTimePicker1.Focus()
End If
End Sub
Private Sub ComboBox1_KeyDown(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyEventArgs) Handles
ComboBox1.KeyDown
If
e.KeyCode = 13 Then
ComboBox2.Focus()
End If
End Sub
Private Sub ComboBox2_KeyDown(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyEventArgs) Handles
ComboBox2.KeyDown
If
e.KeyCode = 13 Then
TextBox4.Focus()
End If
End Sub
Private Sub TextBox4_KeyDown(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyEventArgs) Handles
TextBox4.KeyDown
If
e.KeyCode = 13 Then
TextBox5.Focus()
End If
End Sub
Private Sub TextBox5_KeyDown(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyEventArgs) Handles
TextBox5.KeyDown
If
e.KeyCode = 13 Then
TextBox6.Focus()
End If
End Sub
Private Sub TextBox6_KeyDown(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyEventArgs) Handles
TextBox6.KeyDown
If
e.KeyCode = 13 Then
TextBox7.Focus()
End If
End Sub
Private Sub TextBox7_KeyDown(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyEventArgs) Handles
TextBox7.KeyDown
If
e.KeyCode = 13 Then
Button1.Focus()
End If
End Sub
Private Sub Button4_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
BERSIH()
End Sub
Private Sub Button5_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
frmAbout.Show()
End Sub
Private Sub Button6_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button6.Click
Shell("calc",
AppWinStyle.NormalFocus)
End Sub
Private Sub Button7_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button7.Click
Shell("notepad",
AppWinStyle.NormalFocus)
End Sub
Private Sub Button8_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button8.Click
frmSystemInfo.Show()
End Sub
Private Sub TextBox1_TextChanged(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button9_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button9.Click
Me.Close()
LoginForm1.Show()
End Sub
End Class