Searching...
Wednesday 24 February 2016

Membuat Aplikasi Rekam Medis Visual Studio2012 & Database SQL Server 2012


Data Diatas Terdiri dari  label, picturebox,button,panel.
Berikut script pada aplikasi diatas tersebut

  1. Public Class Home
  2.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  3.         opendb()
  4.        
  5.     End Sub
  6.     Sub tutup()
  7.         rekam_medis.Close()
  8.         pasien.Close()
  9.         dokter.Close()
  10.         Obat.Close()
  11.         poliklinik.Close()
  12.         Tindakan.Close()
  13.         kunjungan.Close()
  14.         Laboratorium.Close()
  15.         TampilDataPasien.Close()
  16.     End Sub
  17.     Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
  18.         tutup()
  19.         Laboratorium.TopLevel = False
  20.         Panel3.Controls.Add(Laboratorium)
  21.         Laboratorium.Show()
  22.         Laboratorium.BringToFront()
  23.     End Sub
  24.     Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint
  25.     End Sub
  26.     Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
  27.         Me.Hide()
  28.         first.Show()
  29.     End Sub
  30.     Private Sub Panel2_Paint(sender As Object, e As PaintEventArgs) Handles Panel2.Paint
  31.     End Sub
  32.     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  33.         tutup()
  34.         pasien.TopLevel = False
  35.         Panel3.Controls.Add(pasien)
  36.         pasien.Show()
  37.         pasien.BringToFront()
  38.     End Sub
  39.     Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
  40.         tutup()
  41.         Tindakan.TopLevel = False
  42.         Panel3.Controls.Add(Tindakan)
  43.         Tindakan.Show()
  44.         Tindakan.BringToFront()
  45.     End Sub
  46.     Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  47.         tutup()
  48.         Obat.TopLevel = False
  49.         Panel3.Controls.Add(Obat)
  50.         Obat.Show()
  51.         Obat.BringToFront()
  52.     End Sub
  53.     Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
  54.         tutup()
  55.         poliklinik.TopLevel = False
  56.         Panel3.Controls.Add(poliklinik)
  57.         poliklinik.Show()
  58.         poliklinik.BringToFront()
  59.     End Sub
  60.     Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
  61.         tutup()
  62.         kunjungan.TopLevel = False
  63.         Panel3.Controls.Add(kunjungan)
  64.         kunjungan.Show()
  65.         kunjungan.BringToFront()
  66.     End Sub
  67.     Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  68.         tutup()
  69.         dokter.TopLevel = False
  70.         Panel3.Controls.Add(dokter)
  71.         dokter.Show()
  72.         dokter.BringToFront()
  73.     End Sub
  74.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  75.         tutup()
  76.         rekam_medis.TopLevel = False
  77.         Panel3.Controls.Add(rekam_medis)
  78.         rekam_medis.Show()
  79.         rekam_medis.BringToFront()
  80.     End Sub
  81.     Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
  82.         tutup()
  83.         Cetak.TopLevel = False
  84.         Panel3.Controls.Add(Cetak)
  85.         Cetak.Show()
  86.         Cetak.BringToFront()
  87.     End Sub
  88.     Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
  89.         rekam_medis.Close()
  90.         TampilDataPasien.Close()
  91.         pasien.Close()
  92.         dokter.Close()
  93.         Obat.Close()
  94.         kunjungan.Close()
  95.         Tindakan.Close()
  96.         poliklinik.Close()
  97.     End Sub
  98. End Class

Form Diatas Terdiri dari, datagridview, button, label, textbox,panel,grupbox.
Berikut script pada form diatas
  1. Imports System.Data.SqlClient
  2. Public Class rekam_medis
  3.     Dim pasien, obat, tindakan As String
  4.     Sub bersih()
  5.         txtrekmedis.Text = ""
  6.         cbkdtindakan.Text = ""
  7.         cbkdobat.Text = ""
  8.         cbkduser.Text = ""
  9.         cbnopas.Text = ""
  10.         txtdiagnosa.Text = ""
  11.         txtkeluhan.Text = ""
  12.         txtresep.Text = ""
  13.         tglperiksa.Text = ""
  14.         txtket.Text = ""
  15.     End Sub
  16.     Sub header()
  17.         DataGridView1.Columns(0).HeaderText = "NoRekamMedis"
  18.         DataGridView1.Columns(1).HeaderText = "Kode Tindakan"
  19.         DataGridView1.Columns(2).HeaderText = "Kode Obat"
  20.         DataGridView1.Columns(3).HeaderText = "Kode User"
  21.         DataGridView1.Columns(4).HeaderText = "No Pasien"
  22.         DataGridView1.Columns(5).HeaderText = "Diagnosa"
  23.         DataGridView1.Columns(6).HeaderText = "Resep"
  24.         DataGridView1.Columns(7).HeaderText = "Keluhan"
  25.         DataGridView1.Columns(8).HeaderText = "Tgl Pemeriksa"
  26.         DataGridView1.Columns(9).HeaderText = "Keterangan"
  27.     End Sub
  28.     Sub bukatabelrekammedis()
  29.         cmd.Connection = cn
  30.         cmd.CommandText = "SELECT * FROM rekam_medis"
  31.         Dim rd As SqlDataReader = cmd.ExecuteReader
  32.         Dim dt As New DataTable
  33.         dt.Load(rd)
  34.         DataGridView1.DataSource = dt
  35.     End Sub
  36.     Sub bukatabeltindakan()
  37.         cmd = New SqlCommand("SELECT * FROM tindakan", cn)
  38.         Dim rd As SqlDataReader = cmd.ExecuteReader
  39.         While rd.Read
  40.             cbkdtindakan.Items.Add(rd("kd_tindakan") & " | " & (rd("nm_tindakan")))
  41.         End While
  42.         rd.Close()
  43.     End Sub
  44.     Sub bukatabelobat()
  45.         cmd = New SqlCommand("SELECT * FROM obat", cn)
  46.         Dim rd As SqlDataReader = cmd.ExecuteReader
  47.         While rd.Read
  48.             cbkdobat.Items.Add(rd("kd_obat") & " | " & (rd("nm_obat")))
  49.         End While
  50.         rd.Close()
  51.     End Sub
  52.     Sub bukatabeluser()
  53.         cmd = New SqlCommand("SELECT kd_user FROM login", cn)
  54.         Dim rd As SqlDataReader = cmd.ExecuteReader
  55.         While rd.Read
  56.             cbkduser.Items.Add(rd("kd_user"))
  57.         End While
  58.         rd.Close()
  59.     End Sub
  60.     Sub bukanopasien()
  61.         cmd = New SqlCommand("SELECT * FROM pasien", cn)
  62.         Dim rd As SqlDataReader = cmd.ExecuteReader
  63.         While rd.Read
  64.             cbnopas.Items.Add(rd("no_pasien") & " | " & (rd("nm_pasien")))
  65.         End While
  66.         rd.Close()
  67.     End Sub
  68.     Sub kodeotomatis()
  69.         cmd = New SqlCommand("SELECT no_rm FROM rekam_medis ORDER BY no_rm DESC", cn)
  70.         Dim rd As SqlDataReader = cmd.ExecuteReader
  71.         rd.Read()
  72.         If Not rd.HasRows Then
  73.             txtrekmedis.Text = "RM001"
  74.         Else
  75.             txtrekmedis.Text = Val(Microsoft.VisualBasic.Mid(rd.Item("no_rm").ToString, 3, 3)) + 1
  76.             If Len(txtrekmedis.Text) = 1 Then
  77.                 txtrekmedis.Text = "RM00" & txtrekmedis.Text & ""
  78.             ElseIf Len(txtrekmedis.Text) = 2 Then
  79.                 txtrekmedis.Text = "RM0" & txtrekmedis.Text & ""
  80.             ElseIf Len(txtrekmedis.Text) = 3 Then
  81.                 txtrekmedis.Text = "RM" & txtrekmedis.Text & ""
  82.             End If
  83.         End If
  84.         rd.Close()
  85.     End Sub
  86.     Private Sub btntambah_Click(sender As Object, e As EventArgs) Handles btntambah.Click
  87.         cmd.Connection = cn
  88.         cmd.CommandText = "INSERT INTO rekam_medis VALUES ('" & txtrekmedis.Text & "','" & tindakan & "','" & obat & "','" & cbkduser.Text & _
  89.             "','" & pasien & "','" & txtdiagnosa.Text & "','" & txtresep.Text & "','" & txtkeluhan.Text & "','" & tglperiksa.Value & "','" & txtket.Text & "')"
  90.         cmd.ExecuteNonQuery()
  91.         MsgBox("Data Telah Di Masukan")
  92.         bersih()
  93.         bukatabelrekammedis()
  94.         kodeotomatis()
  95.     End Sub
  96.     Private Sub btnubah_Click(sender As Object, e As EventArgs) Handles btnubah.Click
  97.         cmd.Connection = cn
  98.         cmd.CommandText = "UPDATE rekam_medis SET kd_tindakan = '" & cbkdtindakan.Text & "',kd_obat= '" & obat & "', kd_user= '" & tindakan &"', no_pasien ='" & cbnopas.Text & _
  99.             "', diagnosa = '" & txtdiagnosa.Text & "', resep = '" & txtresep.Text & "', keluhan ='" & txtkeluhan.Text & "', tgl_pemeriksaan ='" & tglperiksa.Value & "',ket = '" & txtket.Text & "' WHERE no_rm ='" & txtrekmedis.Text & "'"
  100.         cmd.ExecuteNonQuery()
  101.         MsgBox("Data Telah Di Ubah")
  102.         bersih()
  103.         bukatabelrekammedis()
  104.         kodeotomatis()
  105.     End Sub
  106.     Private Sub btnhapus_Click(sender As Object, e As EventArgs) Handles btnhapus.Click
  107.         cmd.Connection = cn
  108.         cmd.CommandText = "DELETE FROM rekam_medis WHERE no_rm ='" & txtrekmedis.Text & "'"
  109.         cmd.ExecuteNonQuery()
  110.         MsgBox("Data Telah Di Hapus")
  111.         bersih()
  112.         bukatabelrekammedis()
  113.         kodeotomatis()
  114.     End Sub
  115.     Private Sub rekam_medis_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  116.         bukatabelrekammedis()
  117.         header()
  118.         bukanopasien()
  119.         bukatabelobat()
  120.         bukatabeltindakan()
  121.         bukatabeluser()
  122.         kodeotomatis()
  123.     End Sub
  124.     Private Sub DataGridView1_CellMouseDoubleClick(sender As Object, e As DataGridViewCellMouseEventArgs)
  125.         txtrekmedis.Text = DataGridView1.SelectedCells(0).Value.ToString
  126.         cbkdtindakan.Text = DataGridView1.SelectedCells(1).Value.ToString
  127.         cbkdobat.Text = DataGridView1.SelectedCells(2).Value.ToString
  128.         cbkduser.Text = DataGridView1.SelectedCells(3).Value.ToString
  129.         cbnopas.Text = DataGridView1.SelectedCells(4).Value.ToString
  130.         txtdiagnosa.Text = DataGridView1.SelectedCells(5).Value.ToString
  131.         txtkeluhan.Text = DataGridView1.SelectedCells(6).Value.ToString
  132.         txtresep.Text = DataGridView1.SelectedCells(7).Value.ToString
  133.         tglperiksa.Text = DataGridView1.SelectedCells(8).Value.ToString
  134.         txtket.Text = DataGridView1.SelectedCells(9).Value.ToString
  135.     End Sub
  136.     Private Sub Label13_Click(sender As Object, e As EventArgs)
  137.     End Sub
  138.     Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click
  139.     End Sub
  140.     Private Sub txtcari_TextChanged(sender As Object, e As EventArgs) Handles txtcari.TextChanged
  141.         If txtcari.Text = "" Then
  142.             bukatabelrekammedis()
  143.         Else
  144.             cmd.Connection = cn
  145.             cmd.CommandText = "SELECT * FROM rekam_medis WHERE (no_rm like '" & txtcari.Text & "%') OR (kd_tindakan Like'" & txtcari.Text &"%')"
  146.             Dim rd As SqlDataReader = cmd.ExecuteReader
  147.             Dim dt As New DataTable
  148.             dt.Load(rd)
  149.             DataGridView1.DataSource = dt
  150.         End If
  151.     End Sub
  152.     Private Sub Button1_Click(sender As Object, e As EventArgs)
  153.     End Sub
  154.     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  155.     End Sub
  156.     Private Sub GroupBox1_Enter(sender As Object, e As EventArgs) Handles GroupBox1.Enter
  157.     End Sub
  158.     Private Sub cbnopas_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbnopas.SelectedIndexChanged
  159.         pasien = Mid(cbnopas.Text, 1, 6)
  160.     End Sub
  161.     Private Sub cbkdobat_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbkdobat.SelectedIndexChanged
  162.         obat = Mid(cbkdobat.Text, 1, 6)
  163.     End Sub
  164.     Private Sub cbkdtindakan_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbkdtindakan.SelectedIndexChanged
  165.         tindakan = Mid(cbkdtindakan.Text, 1, 6)
  166.     End Sub
  167. End Class

Form diatas Terdiri dari label,button,textbox,panel,datagridview,grupbox
Berikut script pada form pasien
diatas
  1. Imports System.Data.SqlClient
  2. Public Class pasien
  3.     Dim jen_kel As String
  4.     Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles txtalamat.TextChanged
  5.     End Sub
  6.     Sub tampildatapasien()
  7.         cmd.Connection = cn
  8.         cmd.CommandText = "SELECT * FROM pasien"
  9.         Dim rd As SqlDataReader = cmd.ExecuteReader
  10.         Dim dt As New DataTable
  11.         dt.Load(rd)
  12.         DataGridView1.DataSource = dt
  13.     End Sub
  14.     Private Sub pasien_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  15.         kodeotomatis()
  16.         cari()
  17.         kategori()
  18.         tampildatapasien()
  19.     End Sub
  20.     Sub bersih()
  21.         txtnopasien.Text = ""
  22.         txtnmpasien.Text = ""
  23.         txtagama.Text = ""
  24.         txtalamat.Text = ""
  25.         tgllahir.Text = ""
  26.         txtusia.Text = ""
  27.         txtnotelp.Text = ""
  28.         txtnokk.Text = ""
  29.         txthubkel.Text = ""
  30.         txtcari.Text = ""
  31.     End Sub
  32.     Sub kodeotomatis()
  33.         cmd = New SqlCommand("SELECT no_pasien FROM pasien ORDER BY no_pasien DESC", cn)
  34.         Dim rd As SqlDataReader = cmd.ExecuteReader
  35.         rd.Read()
  36.         If Not rd.HasRows Then
  37.             txtnopasien.Text = "NP001"
  38.         Else
  39.             txtnopasien.Text = Val(Microsoft.VisualBasic.Mid(rd.Item("no_pasien").ToString, 3, 3)) + 1
  40.             If Len(txtnopasien.Text) = 1 Then
  41.                 txtnopasien.Text = "NP00" & txtnopasien.Text & ""
  42.             ElseIf Len(txtnopasien.Text) = 2 Then
  43.                 txtnopasien.Text = "NP0" & txtnopasien.Text & ""
  44.             ElseIf Len(txtnopasien.Text) = 3 Then
  45.                 txtnopasien.Text = "NP" & txtnopasien.Text & ""
  46.             End If
  47.         End If
  48.         rd.Close()
  49.     End Sub
  50.     Sub kategori()
  51.         cbcari.Items.Add("Nomor Pasien")
  52.         cbcari.Items.Add("Nama Pasien")
  53.     End Sub
  54.     Sub cari()
  55.         If cbcari.Text = "Nomor Pasien" Then
  56.             cmd.Connection = cn
  57.             cmd.CommandText = "SELECT * FROM pasien WHERE no_pasien like '%" & txtcari.Text & "%'"
  58.             Dim rd As SqlDataReader = cmd.ExecuteReader
  59.             Dim dt As New DataTable
  60.             dt.Load(rd)
  61.             DataGridView1.DataSource = dt
  62.         ElseIf cbcari.Text = "Nama Pasien" Then
  63.             cmd.Connection = cn
  64.             cmd.CommandText = "SELECT * FROM pasien WHERE nm_pasien like '%" & txtcari.Text & "%'"
  65.             Dim rd As SqlDataReader = cmd.ExecuteReader
  66.             Dim dt As New DataTable
  67.             dt.Load(rd)
  68.             DataGridView1.DataSource = dt
  69.         End If
  70.     End Sub
  71.     Sub jenkel()
  72.         If rblaki.Checked Then
  73.             jen_kel = "Laki - Laki"
  74.         ElseIf rbprmpuan.Checked Then
  75.             jen_kel = "Perempuan"
  76.         End If
  77.     End Sub
  78.     Private Sub btntambah_Click(sender As Object, e As EventArgs)
  79.         jenkel()
  80.         cmd.Connection = cn
  81.         cmd.CommandText = ("INSERT INTO pasien VALUES ('" & txtnopasien.Text & "','" & txtnmpasien.Text & "','" & jen_kel & "','" & txtagama.Text & "','" & txtalamat.Text & "','" & tgllahir.Value & "','" & txtusia.Text & "','" & txtnotelp.Text & "','" & txtnokk.Text &"','" & txthubkel.Text & "')")
  82.         cmd.ExecuteNonQuery()
  83.         MsgBox("Data Berhasil Dimasukan")
  84.         bersih()
  85.         tampildatapasien()
  86.     End Sub
  87.     Private Sub btnubah_Click(sender As Object, e As EventArgs)
  88.         jenkel()
  89.         cmd.Connection = cn
  90.         cmd.CommandText = "UPDATE pasien SET nm_pasien='" & txtnmpasien.Text & "',j_kel='" & jen_kel & "',agama='" & txtagama.Text &"',alamat='" & txtalamat.Text & "',tgl_lhr='" & tgllahir.Value & "',usia='" & txtusia.Text & "',no_tlp='" & txtnotelp.Text & "',nm_kk='" & txtnokk.Text & "', hub_kel='" & txthubkel.Text & "' WHERE no_pasien='" & txtnopasien.Text & "'"
  91.         cmd.ExecuteNonQuery()
  92.         MsgBox("Data Telah Di Ubah")
  93.         bersih()
  94.         tampildatapasien()
  95.     End Sub
  96.     Private Sub DataGridView1_CellMouseDoubleClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDoubleClick
  97.         txtnopasien.Text = DataGridView1.SelectedCells(0).Value
  98.         txtnmpasien.Text = DataGridView1.SelectedCells(1).Value
  99.         If DataGridView1.SelectedCells(2).Value = "Laki - Laki" Then
  100.             rblaki.Checked = True
  101.         ElseIf DataGridView1.SelectedCells(2).Value = "perempuan" Then
  102.             rbprmpuan.Checked = True
  103.         End If
  104.         txtagama.Text = DataGridView1.SelectedCells(3).Value
  105.         txtalamat.Text = DataGridView1.SelectedCells(4).Value
  106.         tgllahir.Text = DataGridView1.SelectedCells(5).Value
  107.         txtusia.Text = DataGridView1.SelectedCells(6).Value
  108.         txtnotelp.Text = DataGridView1.SelectedCells(7).Value
  109.         txtnokk.Text = DataGridView1.SelectedCells(8).Value
  110.         txthubkel.Text = DataGridView1.SelectedCells(9).Value
  111.     End Sub
  112.     Private Sub btnhapus_Click(sender As Object, e As EventArgs)
  113.         cmd.Connection = cn
  114.         cmd.CommandText = "DELETE FROM pasien WHERE no_pasien='" & txtnopasien.Text & "'"
  115.         cmd.ExecuteNonQuery()
  116.         MsgBox("Data Telah Di Hapus")
  117.         bersih()
  118.         tampildatapasien()
  119.     End Sub
  120.     Private Sub txtcari_TextChanged(sender As Object, e As EventArgs) Handles txtcari.TextChanged
  121.         cari()
  122.     End Sub
  123.     Private Sub txtnopasien_TextChanged(sender As Object, e As EventArgs) Handles txtnopasien.TextChanged
  124.     End Sub
  125.     Private Sub txtagama_TextChanged(sender As Object, e As EventArgs) Handles txtagama.TextChanged
  126.     End Sub
  127.     Private Sub btntambah_Click_1(sender As Object, e As EventArgs) Handles btntambah.Click
  128.         jenkel()
  129.         cmd.Connection = cn
  130.         cmd.CommandText = ("INSERT INTO pasien VALUES ('" & txtnopasien.Text & "','" & txtnmpasien.Text & "','" & jen_kel & "','" & txtagama.Text & "','" & txtalamat.Text & "','" & tgllahir.Value & "','" & txtusia.Text & "','" & txtnotelp.Text & "','" & txtnokk.Text &"','" & txthubkel.Text & "')")
  131.         cmd.ExecuteNonQuery()
  132.         MsgBox("Data Berhasil Dimasukan")
  133.         bersih()
  134.         tampildatapasien()
  135.         kodeotomatis()
  136.     End Sub
  137.     Private Sub btnubah_Click_1(sender As Object, e As EventArgs) Handles btnubah.Click
  138.         jenkel()
  139.         cmd.Connection = cn
  140.         cmd.CommandText = "UPDATE pasien SET nm_pasien='" & txtnmpasien.Text & "',j_kel='" & jen_kel & "',agama='" & txtagama.Text &"',alamat='" & txtalamat.Text & "',tgl_lhr='" & tgllahir.Value & "',usia='" & txtusia.Text & "',no_tlp='" & txtnotelp.Text & "',nm_kk='" & txtnokk.Text & "', hub_kel='" & txthubkel.Text & "' WHERE no_pasien='" & txtnopasien.Text & "'"
  141.         cmd.ExecuteNonQuery()
  142.         MsgBox("Data Telah Di Ubah")
  143.         bersih()
  144.         tampildatapasien()
  145.         kodeotomatis()
  146.     End Sub
  147.     Private Sub btnhapus_Click_1(sender As Object, e As EventArgs) Handles btnhapus.Click
  148.         cmd.Connection = cn
  149.         cmd.CommandText = "DELETE FROM pasien WHERE no_pasien='" & txtnopasien.Text & "'"
  150.         cmd.ExecuteNonQuery()
  151.         MsgBox("Data Telah Di Hapus")
  152.         bersih()
  153.         tampildatapasien()
  154.         kodeotomatis()
  155.     End Sub
  156. End Class

Form diatas Terdiri dari label,button,textbox,panel,datagridview,grupbox
Berikut script pada form dokter diatas
  1. Imports System.Data.SqlClient
  2. Public Class dokter
  3.     Dim poliklinik As String
  4.     Sub bersih()
  5.         txtkddokter.Text = ""
  6.         cbkdpoliklinik.Text = ""
  7.         cbkduser.Text = ""
  8.         txtnmdokter.Text = ""
  9.         txtsip.Text = ""
  10.         txtlahir.Text = ""
  11.         txtnotelp.Text = ""
  12.         txtalamat.Text = ""
  13.     End Sub
  14.     Sub kategori()
  15.         cbcari.Items.Add("Kode Dokter")
  16.         cbcari.Items.Add("Nama Dokter")
  17.     End Sub
  18.     Sub cari()
  19.         If cbcari.Text = "Kode Dokter" Then
  20.             cmd.Connection = cn
  21.             cmd.CommandText = "SELECT * FROM dokter WHERE kd_dokter like '%" & txtcari.Text & "%'"
  22.             Dim rd As SqlDataReader = cmd.ExecuteReader
  23.             Dim dt As New DataTable
  24.             dt.Load(rd)
  25.             DataGridView1.DataSource = dt
  26.         ElseIf cbcari.Text = "Nama Dokter" Then
  27.             cmd.Connection = cn
  28.             cmd.CommandText = "SELECT * FROM dokter WHERE nm_dokter like '%" & txtcari.Text & "%'"
  29.             Dim rd As SqlDataReader = cmd.ExecuteReader
  30.             Dim dt As New DataTable
  31.             dt.Load(rd)
  32.             DataGridView1.DataSource = dt
  33.         End If
  34.     End Sub
  35.     Sub tampildata()
  36.         cmd.Connection = cn
  37.         cmd.CommandText = "SELECT * FROM dokter"
  38.         Dim rd As SqlDataReader = cmd.ExecuteReader
  39.         Dim dt As New DataTable
  40.         dt.Load(rd)
  41.         DataGridView1.DataSource = dt
  42.     End Sub
  43.     Sub kodeotomatis()
  44.         cmd = New SqlCommand("SELECT kd_dokter FROM dokter ORDER BY kd_dokter DESC", cn)
  45.         Dim rd As SqlDataReader = cmd.ExecuteReader
  46.         rd.Read()
  47.         If Not rd.HasRows Then
  48.             txtkddokter.Text = "KD001"
  49.         Else
  50.             txtkddokter.Text = Val(Microsoft.VisualBasic.Mid(rd.Item("kd_dokter").ToString, 3, 3)) + 1
  51.             If Len(txtkddokter.Text) = 1 Then
  52.                 txtkddokter.Text = "KD00" & txtkddokter.Text & ""
  53.             ElseIf Len(txtkddokter.Text) = 2 Then
  54.                 txtkddokter.Text = "KD0" & txtkddokter.Text & ""
  55.             ElseIf Len(txtkddokter.Text) = 3 Then
  56.                 txtkddokter.Text = "KD" & txtkddokter.Text & ""
  57.             End If
  58.         End If
  59.         rd.Close()
  60.     End Sub
  61.     Sub header()
  62.         DataGridView1.Columns(0).HeaderText = "Kode Dokter"
  63.         DataGridView1.Columns(1).HeaderText = "Kode Poliklinik"
  64.         DataGridView1.Columns(2).HeaderText = "Kode User"
  65.         DataGridView1.Columns(3).HeaderText = "Nama Dokter"
  66.         DataGridView1.Columns(4).HeaderText = "SIP"
  67.         DataGridView1.Columns(5).HeaderText = "Tempat Lahir"
  68.         DataGridView1.Columns(6).HeaderText = "No Telpone"
  69.         DataGridView1.Columns(7).HeaderText = "Alamat"
  70.     End Sub
  71.     Private Sub dokter_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  72.         tampildata()
  73.         header()
  74.         kodeotomatis()
  75.         bukatabelpoliklinik()
  76.         bukatabeluser()
  77.         kategori()
  78.     End Sub
  79.     Sub bukatabelpoliklinik()
  80.         cmd = New SqlCommand("SELECT * FROM poliklinik", cn)
  81.         Dim rd As SqlDataReader = cmd.ExecuteReader
  82.         While rd.Read
  83.             cbkdpoliklinik.Items.Add(rd("kd_poli") & " | " & (rd("nm_poli")))
  84.         End While
  85.         rd.Close()
  86.     End Sub
  87.     Sub bukatabeluser()
  88.         cmd = New SqlCommand("SELECT kd_user FROM login", cn)
  89.         Dim rd As SqlDataReader = cmd.ExecuteReader
  90.         While rd.Read
  91.             cbkduser.Items.Add(rd("kd_user"))
  92.         End While
  93.         rd.Close()
  94.     End Sub
  95.     Private Sub btntambah_Click(sender As Object, e As EventArgs)
  96.         cmd.Connection = cn
  97.         cmd.CommandText = "INSERT INTO dokter VALUES ('" & txtkddokter.Text & "','" & cbkdpoliklinik.Text & "','" & cbkduser.Text & "','" & txtnmdokter.Text & "','" & txtsip.Text & "','" & txtlahir.Text & "','" & txtnotelp.Text & "','" & txtalamat.Text & "')"
  98.         cmd.ExecuteNonQuery()
  99.         MsgBox("Data Sukses Di Masukan")
  100.         tampildata()
  101.         bersih()
  102.         kodeotomatis()
  103.     End Sub
  104.     Private Sub btnubah_Click(sender As Object, e As EventArgs)
  105.         cmd.Connection = cn
  106.         cmd.CommandText = "UPDATE dokter SET kd_poli = '" & cbkdpoliklinik.Text & "', kd_user = '" & cbkduser.Text & "', nm_dokter = '" & txtnmdokter.Text & "', sip = '" & txtsip.Text & "', tmpt_lhr = '" & txtlahir.Text & "', no_telp = '" & txtnotelp.Text & "', alamat = '" & txtalamat.Text & "' WHERE kd_dokter = '" & txtkddokter.Text & "'"
  107.         cmd.ExecuteNonQuery()
  108.         MsgBox(" Data Sukses Di Ubah ")
  109.         bersih()
  110.         tampildata()
  111.         kodeotomatis()
  112.     End Sub
  113.     Private Sub btnhapus_Click(sender As Object, e As EventArgs)
  114.         cmd.Connection = cn
  115.         cmd.CommandText = "DELETE FROM dokter WHERE kd_dokter='" & txtkddokter.Text & "'"
  116.         cmd.ExecuteNonQuery()
  117.         MsgBox("Data Sukses Di Hapus")
  118.         bersih()
  119.         tampildata()
  120.         kodeotomatis()
  121.     End Sub
  122.     Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
  123.     End Sub
  124.     Private Sub DataGridView1_CellMouseDoubleClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDoubleClick
  125.         txtkddokter.Text = DataGridView1.SelectedCells(0).Value.ToString
  126.         cbkdpoliklinik.Text = DataGridView1.SelectedCells(1).Value.ToString
  127.         cbkduser.Text = DataGridView1.SelectedCells(2).Value.ToString
  128.         txtnmdokter.Text = DataGridView1.SelectedCells(3).Value.ToString
  129.         txtsip.Text = DataGridView1.SelectedCells(4).Value.ToString
  130.         txtlahir.Text = DataGridView1.SelectedCells(5).Value.ToString
  131.         txtnotelp.Text = DataGridView1.SelectedCells(6).Value.ToString
  132.         txtalamat.Text = DataGridView1.SelectedCells(7).Value.ToString
  133.     End Sub
  134.     Private Sub txtcari_TextChanged(sender As Object, e As EventArgs) Handles txtcari.TextChanged
  135.         cari()
  136.     End Sub
  137.     Private Sub GroupBox1_Enter(sender As Object, e As EventArgs) Handles GroupBox1.Enter
  138.     End Sub
  139.     Private Sub btntambah_Click_1(sender As Object, e As EventArgs) Handles btntambah.Click
  140.         cmd.Connection = cn
  141.         cmd.CommandText = "INSERT INTO dokter VALUES ('" & txtkddokter.Text & "','" & poliklinik & "','" & cbkduser.Text & "','" & txtnmdokter.Text & "','" & txtsip.Text & "','" & txtlahir.Text & "','" & txtnotelp.Text & "','" & txtalamat.Text & "')"
  142.         cmd.ExecuteNonQuery()
  143.         MsgBox("Data Sukses Di Masukan")
  144.         tampildata()
  145.         bersih()
  146.         kodeotomatis()
  147.     End Sub
  148.     Private Sub btnubah_Click_1(sender As Object, e As EventArgs) Handles btnubah.Click
  149.         cmd.Connection = cn
  150.         cmd.CommandText = "UPDATE dokter SET kd_poli = '" & poliklinik & "', kd_user = '" & cbkduser.Text & "', nm_dokter = '" & txtnmdokter.Text & "', sip = '" & txtsip.Text & "', tmpt_lhr = '" & txtlahir.Text & "', no_tep = '" & txtnotelp.Text & "', alamat = '" & txtalamat.Text & "' WHERE kd_dokter = '" & txtkddokter.Text & "'"
  151.         cmd.ExecuteNonQuery()
  152.         MsgBox(" Data Sukses Di Ubah ")
  153.         bersih()
  154.         tampildata()
  155.         kodeotomatis()
  156.     End Sub
  157.     Private Sub btnhapus_Click_1(sender As Object, e As EventArgs) Handles btnhapus.Click
  158.         cmd.Connection = cn
  159.         cmd.CommandText = "DELETE FROM dokter WHERE kd_dokter='" & txtkddokter.Text & "'"
  160.         cmd.ExecuteNonQuery()
  161.         MsgBox("Data Sukses Di Hapus")
  162.         bersih()
  163.         tampildata()
  164.         kodeotomatis()
  165.     End Sub
  166.     Private Sub cbkdpoliklinik_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbkdpoliklinik.SelectedIndexChanged
  167.         poliklinik = Mid(cbkdpoliklinik.Text, 1, 6)
  168.     End Sub
  169. End Class

Form diatas Terdiri dari label,button,textbox.
Berikut script pada form login diatas
  1. Imports System.Data.SqlClient
  2. Public Class first
  3.     Private Sub Button1_Click(sender As Object, e As EventArgs)
  4.         login()
  5.     End Sub
  6.     Private Sub first_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  7.         login()
  8.     End Sub
  9.     Private Sub Button2_Click(sender As Object, e As EventArgs)
  10.         Application.Exit()
  11.     End Sub
  12.     Sub login()
  13.         cmd.Connection = cn
  14.         cmd.CommandText = "SELECT PASSWORD FROM login WHERE password = '" & TextBox1.Text & "' AND PASSWORD ='" & TextBox2.Text & "'"
  15.         Dim rd As SqlDataReader = cmd.ExecuteReader
  16.         rd.Read()
  17.         If rd.HasRows Then
  18.             Me.Hide()
  19.             Home.Show()
  20.             TextBox1.Clear()
  21.             TextBox2.Clear()
  22.         Else
  23.             MessageBox.Show("Data Salah")
  24.         End If
  25.         rd.Close()
  26.     End Sub
  27.     Private Sub TextBox2_KeyPress(sender As Object, e As KeyPressEventArgs)
  28.         If e.KeyChar = Chr(13) Then
  29.             MsgBox("Kayaknya Bisa")
  30.         End If
  31.     End Sub
  32.     Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  33.         Me.Close()
  34.     End Sub
  35. End Class

  1. Imports System.Data.SqlClient
  2. Public Class kunjungan
  3.     Sub tampildatakunjungan()
  4.         cmd.Connection = cn
  5.         cmd.CommandText = "SELECT * FROM kunjungan"
  6.         Dim rd As SqlDataReader = cmd.ExecuteReader
  7.         Dim dt As New DataTable
  8.         dt.Load(rd)
  9.         DataGridView1.DataSource = dt
  10.     End Sub
  11.     Sub kategori()
  12.         cbcari.Items.Add("Nomor Pasien")
  13.     End Sub
  14.     Sub cari()
  15.         cbcari.Text = "Nomor Pasien"
  16.         cmd.Connection = cn
  17.         cmd.CommandText = "SELECT * FROM pasien WHERE no_pasien like '%" & txtcari.Text & "%'"
  18.         Dim rd As SqlDataReader = cmd.ExecuteReader
  19.         Dim dt As New DataTable
  20.         dt.Load(rd)
  21.         DataGridView1.DataSource = dt
  22.     End Sub
  23.     Sub bukatabelpoliklinik()
  24.         cmd = New SqlCommand("SELECT kd_poli FROM poliklinik", cn)
  25.         Dim rd As SqlDataReader = cmd.ExecuteReader
  26.         While rd.Read
  27.             cbkdpol.Items.Add(rd("kd_poli"))
  28.         End While
  29.         rd.Close()
  30.     End Sub
  31.     Private Sub kunjungan_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  32.         tampildatakunjungan()
  33.         bukatabelpoliklinik()
  34.         bukatabelpasien()
  35.         bukatabeldokter()
  36.         kategori()
  37.     End Sub
  38.     Sub bukatabelpasien()
  39.         cmd = New SqlCommand("SELECT no_pasien FROM pasien", cn)
  40.         Dim rd As SqlDataReader = cmd.ExecuteReader
  41.         While rd.Read
  42.             cbnopas.Items.Add(rd("no_pasien"))
  43.         End While
  44.         rd.Close()
  45.     End Sub
  46.     Sub bukatabeldokter()
  47.         cmd = New SqlCommand("SELECT kd_dokter FROM dokter", cn)
  48.         Dim rd As SqlDataReader = cmd.ExecuteReader
  49.         While rd.Read
  50.             cbkddok.Items.Add(rd("kd_dokter"))
  51.         End While
  52.         rd.Close()
  53.     End Sub
  54.     Sub bersih()
  55.         tglkunjungan.Text = ""
  56.         cbnopas.Text = ""
  57.         cbkddok.Text = ""
  58.         cbkdpol.Text = ""
  59.         jam.Text = ""
  60.     End Sub
  61.     Private Sub btntambah_Click(sender As Object, e As EventArgs) Handles btntambah.Click
  62.         cmd.Connection = cn
  63.         cmd.CommandText = ("INSERT INTO kunjungan VALUES ('" & tglkunjungan.Value & "','" & cbkddok.Text & "','" & cbnopas.Text & "','" &cbkdpol.Text & "','" & jam.Value & "')")
  64.         cmd.ExecuteNonQuery()
  65.         MsgBox("Data Telah Di Masukan")
  66.         bersih()
  67.         tampildatakunjungan()
  68.     End Sub
  69.     Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
  70.     End Sub
  71.     Private Sub DataGridView1_CellMouseDoubleClick(sender As Object, e As DataGridViewCellMouseEventArgs) HandlesDataGridView1.CellMouseDoubleClick
  72.         tglkunjungan.Value = DataGridView1.SelectedCells(0).Value
  73.         cbnopas.Text = DataGridView1.SelectedCells(1).Value
  74.         cbkddok.Text = DataGridView1.SelectedCells(2).Value
  75.         cbkdpol.Text = DataGridView1.SelectedCells(3).Value
  76.         jam.Text = DataGridView1.SelectedCells(4).FormattedValue
  77.     End Sub
  78.     Private Sub btnhapus_Click(sender As Object, e As EventArgs) Handles btnhapus.Click
  79.         cmd.Connection = cn
  80.         cmd.CommandText = "DELETE FROM kunjungan WHERE tgl_kunjungan='" & tglkunjungan.Value & "' and no_pasien='" & cbnopas.Text & "'"
  81.         cmd.ExecuteNonQuery()
  82.         MsgBox("Data Telah Di Hapus")
  83.         bersih()
  84.         tampildatakunjungan()
  85.     End Sub
  86.     Private Sub txtcari_TextChanged(sender As Object, e As EventArgs) Handles txtcari.TextChanged
  87.         cari()
  88.     End Sub
  89. End Class

0 komentar:

Post a Comment