0% found this document useful (0 votes)
38 views

Coding Form Dokter: Imports Public Class Sub

This document contains code for a doctor coding form in Visual Basic. It includes subroutines to clear form fields, display data from an Access database, add new records, update existing records, delete records, and close the form. The form retrieves doctor data including code, name, address, city, contact number, and specialty from a database table and allows the user to view, add, edit and delete doctor records.

Uploaded by

Lasya Dwi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Coding Form Dokter: Imports Public Class Sub

This document contains code for a doctor coding form in Visual Basic. It includes subroutines to clear form fields, display data from an Access database, add new records, update existing records, delete records, and close the form. The form retrieves doctor data including code, name, address, city, contact number, and specialty from a database table and allows the user to view, add, edit and delete doctor records.

Uploaded by

Lasya Dwi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CODING FORM DOKTER

Imports System.Data.OleDb

Public Class Dokter


Sub Kosongkan()
KodeDokter.Clear()
NamaDokter.Clear()
Alamat.Clear()
Kota.Clear()
No_Kontak.Clear()
Spesialisasi.Text = ""
KodeDokter.Focus()
End Sub
Sub DataBaru()
KodeDokter.Clear()
NamaDokter.Clear()
Alamat.Clear()
Kota.Clear()
No_Kontak.Clear()
Spesialisasi.Text = ""
KodeDokter.Focus()
End Sub

Sub Tampilkan()
da = New OleDbDataAdapter("Select kode_dok as Kode, nama_dokter as Nama, alamat
as Alamat, spesialis as Spesialisasi from dokter order by 1", Conn)
ds = New DataSet
ds.Clear()
da.Fill(ds, "dokter")
dbDokter.DataSource = (ds.Tables("dokter"))
dbDokter.ReadOnly = True
End Sub

Private Sub Dokter_Load(sender As Object, e As EventArgs) Handles MyBase.Load


Call Koneksi()
Call DataBaru()
Call Tampilkan()
End Sub

Private Sub CmdSimpan_Click(sender As Object, e As EventArgs) Handles CmdSimpan.Click


If KodeDokter.Text = "" Or NamaDokter.Text = "" Or Alamat.Text = "" Or
No_Kontak.Text = "" Or Spesialisasi.Text = "" Or Kota.Text = "" Then
MsgBox("Data Belum Lengkap")
Exit Sub
Else
cmd = New OleDbCommand("Select * from dokter where kode_dok='" &
KodeDokter.Text & "'", Conn)
rd = cmd.ExecuteReader
rd.Read()
If Not rd.HasRows Then
Dim sqltambah As String = "Insert into
dokter(kode_dok,nama_dokter,alamat,kota,no_telp,spesialis) values " & _
"('" & KodeDokter.Text & "','" &
NamaDokter.Text & "','" & Alamat.Text & "','" &
Kota.Text & "','" & No_Kontak.Text & "','" & Spesialisasi.Text & "')"
cmd = New OleDbCommand(sqltambah, Conn)
cmd.ExecuteNonQuery()
Call Kosongkan()
Call Tampilkan()
Else
Dim sqledit As String = "Update dokter set " & _
"nama_dokter='" & NamaDokter.Text & "', " & _
"alamat='" & Alamat.Text & "', " & _
"kota='" & Kota.Text & "', " & _
"no_telp='" & No_Kontak.Text & "', " & _
"spesialis='" & Spesialisasi.Text & "', " & _
"where kode_dok='" & KodeDokter.Text & "'"
cmd = New OleDbCommand(sqledit, Conn)
cmd.ExecuteNonQuery()
Call Kosongkan()
Call Tampilkan()
End If
End If
End Sub

Private Sub CmdHapus_Click(sender As Object, e As EventArgs) Handles CmdHapus.Click


If KodeDokter.Text = "" Then
MsgBox("Isi kode Pasien terlebih dahulu")
KodeDokter.Focus()
Exit Sub
Else
If MessageBox.Show("Yakin akan dihapus..?", "",
MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
cmd = New OleDbCommand("Delete * from dokter where kode_dokter='" &
KodeDokter.Text & "'", Conn)
cmd.ExecuteNonQuery()
Call Kosongkan()
Call Tampilkan()
Else
Call Kosongkan()
End If
End If
End Sub

Private Sub CmdBatal_Click(sender As Object, e As EventArgs) Handles CmdBatal.Click


Call Kosongkan()
End Sub

Private Sub CmdTutup_Click(sender As Object, e As EventArgs) Handles CmdTutup.Click


Me.Close()
End Sub
End Class

You might also like