Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

MODUL VB

CLASS KONEKSI
Imports System.Data.OleDb
Public Class clskoneksi
Protected tblLogin = New DataTable
Protected SQL As String
Protected database As OleDb.OleDbConnection
Protected Cmd As OleDb.OleDbCommand
Protected Da As OleDb.OleDbDataAdapter
Protected Ds As DataSet
Protected Dt As DataTable
Public Function OpenConn() As Boolean
database = New OleDbConnection("Provider=Microsoft.ACE.OleDb.12.0; Data
Source=tubes vb.mdb")
database.Open()
If database.State <> ConnectionState.Open Then
Return False
Else
Return True
End If
End Function
Public Sub CloseConn()
If Not IsNothing(database) Then
database.Close()
database = Nothing
End If
End Sub
Public Function ExecuteQuery(ByVal Query As String) As DataTable
If Not OpenConn() Then
MsgBox("Koneksi gagal!!", MsgBoxStyle.Critical, "Access Failed")
Return Nothing
Exit Function
End If

Cmd = New OleDb.OleDbCommand(Query, database)


Da = New Data.OleDb.OleDbDataAdapter
Da.SelectCommand = Cmd
Ds = New Data.DataSet
Da.Fill(Ds)
Dt = Ds.Tables(0)
Return Dt
Dt = Nothing
Ds = Nothing
Da = Nothing
Cmd = Nothing
End Function
End Class
Imports System.Data.OleDb
Public Class FormVerifikasiAdmin
Dim database As OleDbConnection
Dim tabel As OleDbDataAdapter
Dim data As DataSet
Dim record As New BindingSource
Dim tekan As Integer

Sub koneksi()
Try
database = New
OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=tubes vb.mdb")
database.Open()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub

Sub data_record()
Try
tabel = New Data.OleDb.OleDbDataAdapter("select * from
Pasien_Baru", database)
data = New DataSet
tabel.Fill(data)
record.DataSource = data
record.DataMember = data.Tables(0).ToString()
DataGridView1.DataSource = record
DataGridView1.Columns(0).Width = 200
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub

Sub bersih()
ComboBox1.Text = ""
TextBox1.Text = ""

Call koneksi()
Call data_record()

End Sub

Private Sub FormVerifikasiAdmin_Load(ByVal sender As System.Object, ByVal


e As System.EventArgs) Handles MyBase.Load
Call bersih()
End Sub
Private Sub kondisi()
Me.Button2.Enabled = True
Me.Button1.Enabled = False
End Sub
'delete
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
Dim dml As New OleDbCommand
dml.Connection = database
dml.CommandType = CommandType.Text
dml.CommandText = "delete from Pasien_Baru where Nama = '" &
TextBox1.Text & "'"
dml.ExecuteNonQuery()
MsgBox("Data dihapus..!")
Call bersih()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
'search
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Try
tabel = New Data.OleDb.OleDbDataAdapter("select * from
Pasien_Baru where No_Pasien like '%" & ComboBox1.Text & "%'", database)
data = New DataSet
tabel.Fill(data)
record.DataSource = data
record.DataMember = data.Tables(0).ToString()
DataGridView1.DataSource = record
DataGridView1.Columns(0).Width = 100
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Private Sub DataGridView1_CellContentDoubleClick(ByVal sender As Object,
ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles
DataGridView1.CellContentDoubleClick
Try

ComboBox1.Text = DataGridView1.SelectedCells(0).Value
TextBox1.Text = DataGridView1.SelectedCells(1).Value

Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
End Class

Imports System.Data
Imports System.Data.OleDb
Public Class FormObat
Dim database As OleDbConnection
Dim tabel As OleDbDataAdapter
Dim data As DataSet
Dim record As New BindingSource
Dim tekan As Integer

Sub koneksi()
Try
database = New
OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=tubes vb.mdb")
database.Open()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Sub data_record()
Try
tabel = New Data.OleDb.OleDbDataAdapter("select * from Obat",
database)
data = New DataSet
tabel.Fill(data)
record.DataSource = data
record.DataMember = data.Tables(0).ToString()
dgview.DataSource = record
dgview.Columns(0).Width = 100
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Sub bersih()

TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
Call koneksi()
Call data_record()
End Sub

Private Sub FormObat_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
Call bersih()
End Sub

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnSave.Click
Try
Dim dml As New OleDbCommand
dml.Connection = database
dml.CommandType = CommandType.Text
dml.CommandText = "insert into Obat values('" & TextBox1.Text &
"','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','"
& TextBox5.Text & "','" & TextBox6.Text & "')"
dml.ExecuteNonQuery()
MsgBox("Data telah disimpan")
Call bersih()
Catch ex As Exception
MsgBox("Maaf, terjadi kesalahan! Silahkan Isi Semua Data / Anda
memasukkan Data salah.")
End Try
'-------------

End Sub
Private Sub dgview_CellDoubleClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles
dgview.CellDoubleClick
Try
TextBox1.Text = dgview.SelectedCells(0).Value
TextBox2.Text = dgview.SelectedCells(1).Value
TextBox3.Text = dgview.SelectedCells(2).Value
TextBox4.Text = dgview.SelectedCells(3).Value
TextBox5.Text = dgview.SelectedCells(4).Value
TextBox6.Text = dgview.SelectedCells(5).Value

Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub

Private Sub TextBox7_TextChanged(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles TextBox7.TextChanged
Try
tabel = New Data.OleDb.OleDbDataAdapter("select * from Obat where
Kode_Obat like '%" & TextBox7.Text & "%'", database)
data = New DataSet
tabel.Fill(data)
record.DataSource = data
record.DataMember = data.Tables(0).ToString()
dgview.DataSource = record
dgview.Columns(0).Width = 100
Catch ex As Exception
MsgBox("Data tidak ditemukan...!")
End Try
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Dim total As String
Try
total = CStr(CDbl(TextBox5.Text)) * CStr(CDbl(TextBox4.Text))
TextBox6.Text = total
Catch ex As Exception
MsgBox("Silahkan isi data dulu..!")
End Try

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button4.Click
Try
Dim dml As New OleDbCommand
dml.Connection = database
dml.CommandType = CommandType.Text
dml.CommandText = "delete from Obat where Nama_obat = '" &
TextBox2.Text & "'"
dml.ExecuteNonQuery()
MsgBox("Data telah dihapus")
Call bersih()
Catch ex As Exception
MessageBox.Show("Tulis kode obat yang akan dihapus..!")
End Try
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
Report.Show()
End Sub
End Class

Imports System.Data
Imports System.Data.OleDb

Public Class FormLoginAdmin


Dim tblLogin As DataTable
Dim Proses As New clskoneksi

Sub Login()
If TextBox1.Text = "" Then TextBox1.Focus() : Exit Sub
If TextBox2.Text = "" Then TextBox2.Focus() : Exit Sub
tblLogin = Proses.ExecuteQuery("Select * From Admin Where Nama = '" &
TextBox1.Text & "' and Password='" & TextBox2.Text & "'")
If tblLogin.Rows.Count = 0 Then
MessageBox.Show("Login tidak berhasil..!!", "Informasi",
MessageBoxButtons.OK, MessageBoxIcon.Information)
TextBox1.Focus()
Else
FormIsiDataAdmin.Show()
Me.Hide()

End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Call Login()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
End Class

Imports System.Data
Imports System.Data.OleDb
Public Class FormIsiUSerBaru
Dim database As OleDbConnection
Dim tabel As OleDbDataAdapter
Dim data As DataSet
Dim record As New BindingSource
Dim tekan As Integer
Sub koneksi()
Try
database = New
OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source = tubes
vb.mdb")
database.Open()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Sub data_record()
Try
tabel = New Data.OleDb.OleDbDataAdapter("select * from
Pasien_Baru", database)
data = New DataSet
tabel.Fill(data)
record.DataSource = data
record.DataMember = data.Tables(0).ToString()

Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Sub bersih()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""

Call koneksi()
Call data_record()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Try
Dim dml As New OleDbCommand
dml.Connection = database
dml.CommandType = CommandType.Text
dml.CommandText = "insert into Pasien_Baru values('" &
TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" &
TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" &
TextBox7.Text & "','" & TextBox8.Text & "','" & TextBox9.Text & "')"
dml.ExecuteNonQuery()
MsgBox("Data masuk")
Call bersih()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub

Private Sub FormIsiUSerBaru_Load(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles MyBase.Load
Call bersih()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
Dim bukaGambar As New Windows.Forms.OpenFileDialog
bukaGambar.Filter = "File Gambar(*.bmp;
*.jpg;*.GIF)|*.BMP;*.JPG;*.GIF|All files(*.*)|*.*"
'tampilkan file yang berformat .jpg .bmp .gif
If bukaGambar.ShowDialog = Windows.Forms.DialogResult.OK Then
Me.PictureBox.Image = Image.FromFile(bukaGambar.FileName)
PictureBox.SizeMode = PictureBoxSizeMode.StretchImage
'biar tampilan image pas dengan kotak image yang di sediakan
Else
MsgBox("Pilih Gambar Dulu", MsgBoxStyle.Exclamation, "Error")
End If
End Sub
End Class

Imports System.Data
Imports System.Data.OleDb
Public Class FormDokter
Dim database As OleDbConnection
Dim tabel As OleDbDataAdapter
Dim data As DataSet
Dim record As New BindingSource
Dim tekan As Integer
Sub koneksi()
Try
database = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data
Source=tubes vb.mdb")
database.Open()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Sub data_record()
Try
tabel = New Data.OleDb.OleDbDataAdapter("select * from dokter", database)
data = New DataSet
tabel.Fill(data)
record.DataSource = data
record.DataMember = data.Tables(0).ToString()
DataGridView1.DataSource = record
DataGridView1.Columns(0).Width = 100
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Sub bersih()
ComboBox1.Text = ""
TextBox1.Text = ""
TextBox2.Text = ""
Call koneksi()
Call data_record()
End Sub

Private Sub FormDokter_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
Call bersih()
End Sub

Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
Try

ComboBox1.Text = DataGridView1.SelectedCells(0).Value
TextBox1.Text = DataGridView1.SelectedCells(1).Value
TextBox2.Text = DataGridView1.SelectedCells(2).Value

Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click
tekan = 2
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button2.Click
Try
Dim dml As New OleDbCommand
dml.Connection = database
dml.CommandType = CommandType.Text
dml.CommandText = "insert into dokter values('" & ComboBox1.Text & "','" &
TextBox1.Text & "','" & TextBox2.Text & "')"
dml.ExecuteNonQuery()
MsgBox("Data telah dimasukkan")
Call bersih()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox3.TextChanged
Try
tabel = New Data.OleDb.OleDbDataAdapter("select * from dokter where ID_Dokter
like '%" & TextBox3.Text & "%'", database)
data = New DataSet
tabel.Fill(data)
record.DataSource = data
record.DataMember = data.Tables(0).ToString()
DataGridView1.DataSource = record
DataGridView1.Columns(0).Width = 100
Catch ex As Exception
MsgBox(ex.ToString())
End Try

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button3.Click
Try
Dim dml As New OleDbCommand
dml.Connection = database
dml.CommandType = CommandType.Text
dml.CommandText = "delete from dokter where ID_Dokter = '" & ComboBox1.Text &
"'"
dml.ExecuteNonQuery()
MsgBox("Data dihapus")
Call bersih()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
End Class
ASCENDING
Private Sub AscendingButton_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) _
Handles AscendingButton.Click
ListBox1.Sorted = True
End Sub

DESCENDING
ListBox1.Sorted = True
ListBox1.Sorted = False
Dim i As Integer
Dim count = ListBox1.Items.Count
For i = ListBox1.Items.Count - 1 To 0 Step -1
ListBox1.Items.Add(ListBox1.Items(i))
Next
For i = 0 To count - 1
ListBox1.Items.RemoveAt(ListBox1.SelectedItem)
Next
End Sub

You might also like