Membuat Module Koneksi
Imports System.Data
Imports System.Data.Sql
Module ModuleKoneksi
Public Database As New OleDb.OleDbConnection
Public Tampil As New OleDb.OleDbCommand
Public Tampilkan As OleDb.OleDbDataReader
Public Grid As New OleDb.OleDbDataAdapter
Public Ds As New DataSet
Public Tabel, hasilcek As String
Public record As New BindingSource
Public noo As Integer
Public DMLSql As New OleDb.OleDbCommand
Public Sub Konek()
Try
Database.Close()
'Server
'Database.ConnectionString = "Provider=SQLOLEDB.1;Password=123456;Persist Security Info=True;User ID=sasa;Initial Catalog=PTJayaKarta;Data Source=192.168.10.4"
'Lokal
Database.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=apotik;Data Source=."
Database.Open()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Public Sub tutupKoneksi()
Database.Close()
End Sub
End Module
1. Membuat Halaman Utama
Public Class Cover
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
obat.Show()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
bayar.Show()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
kasir.Show()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Laporanbayar.Show()
End Sub
End Class
2. Membuat Form Entry Obat
Public Class obat
Sub bersih()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
End Sub
Sub simpanKelompok()
If Button1.Text = "Input" Then
TextBox1.Text = ""
Button1.Text = "Save"
Button2.Enabled = False
Button3.Enabled = False
Button4.Text = "Cancel"
TextBox1.Focus()
Else
If TextBox1.Text = "" Then Exit Sub
If TextBox2.Text = "" Then Exit Sub
If TextBox3.Text = "" Then Exit Sub
If TextBox4.Text = "" Then Exit Sub
Call cekrecord()
Try
If hasilcek = "False" Then
Call Konek()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "insert into Obat(kd_obat,nama_obat,jenis_obat,harga)values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & Val(TextBox4.Text) & "')"
Tampil.ExecuteNonQuery()
Call bersih()
MsgBox("Data Telah Disimpan", MsgBoxStyle.Information, "Pesan")
Else
MsgBox("Data sudah ada, silahkan cek data yang diinput", MsgBoxStyle.Critical, "Input Data")
TextBox1.Focus()
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If
End Sub
Sub cekrecord()
Call Konek()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "select * from obat where kd_obat='" & Trim(TextBox1.Text) & "'"
Tampilkan = Tampil.ExecuteReader
If Tampilkan.HasRows = True Then
hasilcek = True
Else
hasilcek = False
End If
Call tutupKoneksi()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call simpanKelompok()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Button4.Text = "Close" Then
Me.Close()
Else
Call bersih()
Call normal()
End If
End Sub
Sub normal()
Button1.Text = "Input"
Button1.Enabled = True
Button2.Text = "Edit"
Button2.Enabled = True
Button3.Text = "Delete"
Button3.Enabled = True
Button4.Text = "Close"
End Sub
Private Sub ListView1_ItemSelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs)
TextBox1.Text = e.Item.Text
End Sub
Sub BtHapuskelompok()
If Button3.Text = "Delete" Then
Button3.Text = "Hapus"
Button2.Enabled = False
Button1.Enabled = False
Button4.Text = "Cancel"
TextBox1.Focus()
Else
If TextBox1.Text = "" Then Exit Sub
If TextBox2.Text = "" Then Exit Sub
If TextBox3.Text = "" Then Exit Sub
If TextBox4.Text = "" Then Exit Sub
Try
Call Konek()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "delete from obat where kd_obat='" & Trim(TextBox1.Text) & "'"
Tampil.ExecuteNonQuery()
Call bersih()
TextBox1.Enabled = True
TextBox1.Focus()
MsgBox("Data Telah Dihapus", MsgBoxStyle.Information, "Pesan")
TextBox1.Focus()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Call BtHapuskelompok()
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(Keys.Enter) Then
If Button1.Text = "Save" Then
Call cekrecord()
If hasilcek = False Then
TextBox2.Focus()
Else
MsgBox("Kode sudah ada, silahkan ganti kode lain", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Infromasi")
TextBox1.Focus()
End If
Else
Call Konek()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "select * from obat where kd_obat='" & Trim(TextBox1.Text) & "'"
Tampilkan = Tampil.ExecuteReader
If TextBox1.Text = "" Then
MsgBox("Masukan Data Terlebih Dahulu", MsgBoxStyle.Information, "Pesan")
Else
If Tampilkan.HasRows = True Then
While Tampilkan.Read()
If IsDBNull(Tampilkan("kd_obat")) Then
TextBox2.Focus()
Else
TextBox2.Text = Tampilkan("nama_obat")
TextBox3.Text = Tampilkan("jenis_obat")
TextBox4.Text = Tampilkan("harga")
TextBox1.Enabled = False
End If
End While
Else
MsgBox("Data tidak diketemukan", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Tambah Data")
End If
End If
End If
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Call edit()
End Sub
Sub edit()
If Button2.Text = "Edit" Then
Button2.Text = "Save"
Button1.Enabled = False
Button3.Enabled = False
Button4.Text = "Cancel"
TextBox1.Focus()
Else
If TextBox1.Text = "" And TextBox2.Text = "" And TextBox3.Text = "" And TextBox4.Text = "" Then
MsgBox("Data Kurang Lengkap")
Exit Sub
End If
Try
Call Konek()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "update obat set nama_obat='" & TextBox2.Text & "',jenis_obat='" & TextBox3.Text & "',harga='" & Val(TextBox4.Text) & "' where kd_obat='" & Trim(TextBox1.Text) & "'"
Tampil.ExecuteNonQuery()
Call bersih()
MsgBox("Data Telah Diubah", MsgBoxStyle.Information, "Pesan")
TextBox1.Enabled = True
TextBox1.Focus()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If
End Sub
End Class
3. Membuat Form Pembayaran
Public Class bayar
Sub bersih()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
End Sub
Sub cekrecord()
Call Konek()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "select * from Pembayaran where no_nota='" & Trim(TextBox1.Text) & "'"
Tampilkan = Tampil.ExecuteReader
If Tampilkan.HasRows = True Then
hasilcek = True
Else
hasilcek = False
End If
Call tutupKoneksi()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call simpanKelompok()
End Sub
Sub simpanKelompok()
If Button1.Text = "Input" Then
TextBox1.Text = ""
Button1.Text = "Save"
Button2.Enabled = False
Button3.Enabled = False
Button4.Text = "Cancel"
TextBox1.Focus()
Else
If TextBox1.Text = "" Then Exit Sub
If TextBox2.Text = "" Then Exit Sub
If TextBox3.Text = "" Then Exit Sub
If TextBox4.Text = "" Then Exit Sub
If TextBox5.Text = "" Then Exit Sub
If TextBox6.Text = "" Then Exit Sub
If TextBox7.Text = "" Then Exit Sub
If TextBox8.Text = "" Then Exit Sub
Call cekrecord()
Try
If hasilcek = "False" Then
Call Konek()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "insert into Pembayaran(no_nota,no_resep,kd_obat,nama_obat,kd_pasien,nama_pasien,tgl_bayar,total)values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "'," & TextBox8.Text & ")"
Tampil.ExecuteNonQuery()
Call bersih()
MsgBox("Data Telah Disimpan", MsgBoxStyle.Information, "Pesan")
Else
MsgBox("Data sudah ada, silahkan cek data yang diinput", MsgBoxStyle.Critical, "Input Data")
TextBox1.Focus()
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Button4.Text = "Close" Then
Me.Close()
Call normal()
Else
Call bersih()
Call normal()
End If
End Sub
Sub normal()
Button1.Text = "Input"
Button1.Enabled = True
Button2.Text = "Edit"
Button2.Enabled = True
Button3.Text = "Delete"
Button3.Enabled = True
Button4.Text = "Close"
TextBox1.Enabled = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Call edit()
End Sub
Sub edit()
If Button2.Text = "Edit" Then
Button2.Text = "Save"
Button1.Enabled = False
Button3.Enabled = False
Button4.Text = "Cancel"
TextBox1.Focus()
Else
If TextBox1.Text = "" And TextBox2.Text = "" And TextBox3.Text = "" And TextBox4.Text = "" And TextBox5.Text = "" And TextBox6.Text = "" And TextBox7.Text = "" And TextBox8.Text = "" Then
MsgBox("Data Kurang Lengkap")
Exit Sub
End If
Try
Call Konek()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "update Pembayaran set nama_obat='" & TextBox4.Text & "',kd_pasien='" & TextBox5.Text & "',total='" & Val(TextBox8.Text) & "',no_resep='" & TextBox2.Text & "',kd_obat='" & TextBox3.Text & "',nama_pasien='" & TextBox6.Text & "',tgl_bayar='" & TextBox7.Text & "'where no_nota='" & TextBox1.Text & "'"
Tampil.ExecuteNonQuery()
Call bersih()
TextBox1.Enabled = True
TextBox1.Focus()
MsgBox("Data Telah Diubah", MsgBoxStyle.Information, "Pesan")
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If
End Sub
Sub BtHapuskelompok()
If Button3.Text = "Delete" Then
Button3.Text = "Hapus"
Button2.Enabled = False
Button1.Enabled = False
Button4.Text = "Cancel"
TextBox1.Focus()
Else
If TextBox1.Text = "" Then Exit Sub
If TextBox2.Text = "" Then Exit Sub
If TextBox3.Text = "" Then Exit Sub
If TextBox4.Text = "" Then Exit Sub
If TextBox5.Text = "" Then Exit Sub
If TextBox6.Text = "" Then Exit Sub
If TextBox7.Text = "" Then Exit Sub
If TextBox8.Text = "" Then Exit Sub
Try
Call Konek()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "delete from Pembayaran where no_nota='" & Trim(TextBox1.Text) & "'"
Tampil.ExecuteNonQuery()
Call bersih()
TextBox1.Enabled = True
TextBox1.Focus()
MsgBox("Data Telah Dihapus", MsgBoxStyle.Information, "Pesan")
TextBox1.Focus()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
BtHapuskelompok()
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(Keys.Enter) Then
If Button1.Text = "Save" Then
Call cekrecord()
If hasilcek = False Then
TextBox2.Focus()
Else
MsgBox("Kode sudah ada, silahkan ganti kode lain", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Infromasi")
TextBox1.Focus()
End If
Else
Call Konek()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "select * from Pembayaran where no_nota='" & Trim(TextBox1.Text) & "'"
Tampilkan = Tampil.ExecuteReader
If TextBox1.Text = "" Then
MsgBox("Masukan Data Terlebih Dahulu", MsgBoxStyle.Information, "Pesan")
Else
If Tampilkan.HasRows = True Then
While Tampilkan.Read()
If IsDBNull(Tampilkan("no_nota")) Then
TextBox2.Focus()
Else
TextBox2.Text = Tampilkan("no_resep")
TextBox3.Text = Tampilkan("kd_obat")
TextBox4.Text = Tampilkan("nama_obat")
TextBox5.Text = Tampilkan("kd_pasien")
TextBox6.Text = Tampilkan("nama_pasien")
TextBox7.Text = Tampilkan("tgl_bayar")
TextBox8.Text = Tampilkan("total")
TextBox1.Enabled = False
End If
End While
Else
MsgBox("Data tidak diketemukan", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Tambah Data")
End If
End If
End If
End If
End Sub
End Class
4. Membuat Form Kasir
Public Class kasir
Sub bersih()
TextBox1.Text = ""
TextBox2.Text = ""
End Sub
Sub normal()
Button1.Text = "Input"
Button1.Enabled = True
Button2.Text = "Edit"
Button2.Enabled = True
Button3.Text = "Delete"
Button3.Enabled = True
Button4.Text = "Close"
End Sub
Sub cekrecord()
Call Konek()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "select * from Kasir where kd_kasir='" & Trim(TextBox1.Text) & "'"
Tampilkan = Tampil.ExecuteReader
If Tampilkan.HasRows = True Then
hasilcek = True
Else
hasilcek = False
End If
Call tutupKoneksi()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call simpanKelompok()
End Sub
Sub simpanKelompok()
If Button1.Text = "Input" Then
Button1.Text = "Save"
Button2.Enabled = False
Button3.Enabled = False
Button4.Text = "Cancel"
TextBox1.Focus()
Else
If TextBox1.Text = "" Then Exit Sub
If TextBox2.Text = "" Then Exit Sub
Call cekrecord()
Try
If hasilcek = "False" Then
Call Konek()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "insert into Kasir (kd_kasir,nama_kasir)values ('" & TextBox1.Text & "','" & TextBox2.Text & "')"
Tampil.ExecuteNonQuery()
Call bersih()
MsgBox("Data Telah Disimpan", MsgBoxStyle.Information, "Pesan")
Else
MsgBox("Data sudah ada, silahkan cek data yang diinput", MsgBoxStyle.Critical, "Input Data")
TextBox1.Focus()
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Button4.Text = "Close" Then
Me.Close()
Else
Call bersih()
Call normal()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Call BtHapuskelompok()
End Sub
Sub BtHapuskelompok()
If Button3.Text = "Delete" Then
Button3.Text = "Hapus"
Button2.Enabled = False
Button1.Enabled = False
Button4.Text = "Cancel"
TextBox1.Focus()
Else
If TextBox1.Text = "" Then Exit Sub
If TextBox2.Text = "" Then Exit Sub
Try
Call Konek()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "delete from Kasir where kd_kasir='" & Trim(TextBox1.Text) & "'"
Tampil.ExecuteNonQuery()
Call bersih()
TextBox1.Enabled = True
TextBox1.Focus()
MsgBox("Data Telah Dihapus")
TextBox1.Focus()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Call edit()
End Sub
Sub edit()
If Button2.Text = "Edit" Then
Button2.Text = "Save"
Button1.Enabled = False
Button3.Enabled = False
Button4.Text = "Cancel"
TextBox1.Focus()
Else
If TextBox1.Text = "" And TextBox2.Text = "" Then
MsgBox("Data Kurang Lengkap")
Exit Sub
End If
Try
Call Konek()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "update Kasir set nama_kasir='" & TextBox2.Text & "' where kd_kasir='" & Trim(TextBox1.Text) & "'"
Tampil.ExecuteNonQuery()
Call bersih()
TextBox1.Enabled = True
TextBox1.Focus()
MsgBox("Data Telah Diubah", MsgBoxStyle.Information, "Pesan")
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(Keys.Enter) Then
If Button1.Text = "Save" Then
Call cekrecord()
If hasilcek = False Then
TextBox2.Focus()
Else
MsgBox("Kode sudah ada, silahkan ganti kode lain", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Infromasi")
TextBox1.Focus()
End If
Else
Call Konek()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "select * from Kasir where kd_kasir='" & Trim(TextBox1.Text) & "'"
Tampilkan = Tampil.ExecuteReader
If TextBox1.Text = "" Then
MsgBox("Masukan Data Terlebih Dahulu", MsgBoxStyle.Information, "Pesan")
Else
If Tampilkan.HasRows = True Then
While Tampilkan.Read()
If IsDBNull(Tampilkan("kd_kasir")) Then
TextBox2.Focus()
Else
TextBox2.Text = Tampilkan("nama_kasir")
TextBox2.Focus()
TextBox1.Enabled = False
End If
End While
Else
MsgBox("Data tidak diketemukan", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Tambah Data")
End If
End If
End If
End If
End Sub
End Class
Selengkapnya...
Rabu, 08 Juni 2011
Tugas UAS
Langganan:
Postingan (Atom)