Assalamu'alaikum..
kali ini saya akan mendemo kan bagaimana caranya membuat program PENDAFTARAN SEKOLAH. cek disot gais
Pertama buatlah form login
source codenya adalah berikut ini :
Imports System.Data.OleDb
Public Class flogin
Private Sub jalankansql(ByVal sQl As String)
Koneksi()
Dim objcmd As New OleDb.OleDbCommand
Try
objcmd.Connection = conn
objcmd.CommandType = CommandType.Text
objcmd.CommandText = sQl
objcmd.ExecuteNonQuery()
objcmd.Dispose()
MsgBox("Data Sudah Disimpan", vbInformation)
Catch ex As Exception
MsgBox("Tidak Bisa Menyimpan Data ke Database" & ex.Message)
End Try
End Sub
Private Sub ok_Click(sender As Object, e As EventArgs) Handles ok.Click
If user.Text = "" Or pass.Text = "" Then
MsgBox("Data Login Belum Lengkap")
Exit Sub
Else
Koneksi()
CMD = New OleDbCommand("select * from tbl_Login where username='" & user.Text & "' and password='" & pass.Text & "'", conn)
RD = CMD.ExecuteReader
RD.Read()
If RD.HasRows Then
Me.Hide()
Utama.Show()
user.Text = ""
pass.Text = ""
Else
MsgBox("Kode Admin atau Password Salah !")
End If
End If
End Sub
End Class
lalu setelah proses login selesai. maka tampilannya akan seperti ini :
lalu kita masuk ke form pendaftaran :
source codenya adalah sebagai berikut :
Imports System.Data.OleDb
Public Class fdaftar
Sub Kosong()
txtdaftar.Clear()
txtnama.Clear()
cmbjk.Text = ""
cmbagama.Text = ""
txtalamat.Clear()
txtlahir.Clear()
DateTimePicker1.Text = ""
txtsekolah.Clear()
txtdaftar.Focus()
End Sub
Sub TampilData()
DA = New OleDbDataAdapter("SELECT * FROM tbl_Daftar", conn)
DS = New DataSet
DS.Clear()
DA.Fill(DS, "tbl_Daftar")
DataGridView1.DataSource = DS.Tables("tbl_Daftar")
DataGridView1.Refresh()
End Sub
Sub AturGrid()
DataGridView1.Columns(0).Width = 200
DataGridView1.Columns(1).Width = 200
DataGridView1.Columns(2).Width = 200
DataGridView1.Columns(3).Width = 200
DataGridView1.Columns(4).Width = 200
DataGridView1.Columns(5).Width = 200
DataGridView1.Columns(6).Width = 200
DataGridView1.Columns(7).Width = 200
DataGridView1.Columns(0).HeaderText = "ID PENDAFTARAN"
DataGridView1.Columns(1).HeaderText = "NAMA"
DataGridView1.Columns(2).HeaderText = "JENIS KELAMIN"
DataGridView1.Columns(3).HeaderText = "AGAMA"
DataGridView1.Columns(4).HeaderText = "ALAMAT"
DataGridView1.Columns(5).HeaderText = "TEMPAT LAHIR"
DataGridView1.Columns(6).HeaderText = "TANGGAL LAHIR"
DataGridView1.Columns(7).HeaderText = "ASAL SEKOLAH"
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Call Kosong()
End Sub
Private Sub fdaftar_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Call Koneksi()
Call TampilData()
Call Kosong()
Call AturGrid()
End Sub
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
Dim i As Integer
i = Me.DataGridView1.CurrentRow.Index
With DataGridView1.Rows.Item(i)
Me.txtdaftar.Text = .Cells(0).Value
txtnama.Text = .Cells(1).Value
cmbjk.Text = .Cells(2).Value
cmbagama.Text = .Cells(3).Value
txtalamat.Text = .Cells(4).Value
txtlahir.Text = .Cells(5).Value
DateTimePicker1.Text = .Cells(6).Value
txtsekolah.Text = .Cells(7).Value
End With
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If txtdaftar.Text = "" Or txtnama.Text = "" Or cmbjk.Text = "" Or cmbagama.Text = "" Or txtalamat.Text = "" Or txtlahir.Text = "" Or DateTimePicker1.Text = "" Or txtsekolah.Text = "" Then
MsgBox("DATA BELUM LENGKAP!")
txtdaftar.Focus()
Exit Sub
Else
CMD = New OleDbCommand("SELECT * FROM tbl_Daftar where id_pendaftaran='" & txtdaftar.Text & "'", conn)
RD = CMD.ExecuteReader
RD.Read()
If Not RD.HasRows Then
Dim Simpan As String = "INSERT INTO tbl_daftar(ID_PENDAFTARAN, NAMA, JENIS_KELAMIN, AGAMA, ALAMAT, TEMPAT_LAHIR, TANGGAL_LAHIR, ASAL_SEKOLAH) values " & "('" & txtdaftar.Text & "','" & txtnama.Text & "','" & cmbjk.Text & "','" & cmbagama.Text & "','" & txtalamat.Text & "','" & txtlahir.Text & "','" & DateTimePicker1.Text & "','" & txtsekolah.Text & "')"
CMD = New OleDbCommand(Simpan, conn)
CMD.ExecuteNonQuery()
MsgBox("SIMPAN DATA SUKSES", MsgBoxStyle.Information, "INFORMASI")
End If
Call TampilData()
Call Kosong()
txtdaftar.Focus()
End If
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
If txtdaftar.Text = "" Then
MsgBox("ID PENDAFTARAN BELUM DIISI")
txtdaftar.Focus()
Exit Sub
Else
Dim Ubah As String = "UPDATE tbl_Daftar set " & "NAMA='" & txtnama.Text & "'," & "JENIS_KELAMIN='" & cmbjk.Text & "'," & "AGAMA='" & cmbagama.Text & "'," & "ALAMAT='" & txtalamat.Text & "'," & "TEMPAT_LAHIR='" & txtlahir.Text & "'," & "TANGGAL_LAHIR='" & DateTimePicker1.Text & "'," & "ASAL_SEKOLAH='" & txtsekolah.Text & "'" & "where ID_PENDAFTARAN='" & txtdaftar.Text & "'"
CMD = New OleDbCommand(Ubah, conn)
CMD.ExecuteNonQuery()
MsgBox("UBAH DATA SUKSES", MsgBoxStyle.Information, "INFORMASI")
Call TampilData()
Call Kosong()
txtdaftar.Focus()
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
If txtdaftar.Text = "" Then
MsgBox("KODE BUKU BELUM DIISI")
txtdaftar.Focus()
Exit Sub
Else
If MessageBox.Show("YAKIN INGIN MENGHAPUS DATA? " & txtdaftar.Text & " ?", "", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
CMD = New OleDbCommand("DELETE * FROM tbl_Daftar where ID_PENDAFTARAN='" & txtdaftar.Text & "'", conn)
CMD.ExecuteNonQuery()
Call Kosong()
Call TampilData()
Else
Call Kosong()
End If
End If
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles txtcari.TextChanged
CMD = New OleDbCommand("SELECT * FROM tbl_Daftar where ID_PENDAFTARAN like '%" & txtcari.Text & "%'", conn)
RD = CMD.ExecuteReader
RD.Read()
If RD.HasRows Then
DA = New OleDbDataAdapter("SELECT * FROM tbl_Daftar where ID_PENDAFTARAN like '%" & txtcari.Text & "%'", conn)
DS = New DataSet
DA.Fill(DS, "DAPAT")
DataGridView1.DataSource = DS.Tables("DAPAT")
DataGridView1.ReadOnly = True
Else
MsgBox("DATA TIDAK DITEMUKAN")
End If
End Sub
End Class
setelah semua pengisian selesai. kita cek di bagian laporan :
nah data yang disimpan sudah masuk :D
Berhasil.....
Tidak ada komentar:
Posting Komentar