1. Buatlah form baru untuk form master tipe vlla dengan cara sebagai berikut :
1. Kemudian klik OK, ubahlah property sebagai berikut :
• Text : Master Tipe Villa
• WindowState : Maximized
• FormBorderStyle : None
1. Tambahkan split container dengan ketentuan sebagai berikut :
• Name : splUtama
• Dock : Fill
• SplitterDistance : 350
• FixedPanel : Panel1
• IsSplitterFixed : True
1. Tambahkan 2 label dengan ketentuan sebagai berikut :
• Text : Id Tipe :
• Text : Tipe :
1. Tambahkan textbox dengan ketentuan sebagai berikut :
• Name : textId
• Text : OTOMATIS
1. Kemudian tambahkan textbox dengan ketentuan sebagai berikut :
• Name : textNama
• MaxLength : 30
1. Setelah itu tambahkanlah button dengan ketentuan sebagai berikut :
a) Tombol new :
• Name : tombolNew
• Text : New
b) Tombol simpan :
• Name : tombolSimpan
• Text : Simpan
c) Tombol hapus :
• Name : tombolHapus
• Text : Hapus
d) Tombol keluar :
• Name : tombolKeluar
• Text : Keluar
1. Tambahkan DataGridView dengan ketentuan sebagai berikut :
• Name : grid1
Coding untuk module1.vb
Imports System.Data.SqlClient
Module mainModule
Public QconnDb As String = "Intregated Security=SSPI;" _
& "INITIAL CATALOG =balivillas;" _
& "DATA SOURCE =."
Public strSQL As String
Public Function Koneksi() As SqlConnection
Dim conn As New SqlConnection
conn = New SqlConnection(QconnDb)
conn.Open()
Return conn
End Function
End Module
Coding untuk formMasterTipe
Imports System.Data.SqlClient
Public Class formMasterTipe
Private Sub listdata()
Dim Adapter As New SqlDataAdapter("select id_tipe as[Id]," _
& "nama tipe as[Nama Tipe]" _
& "from t_tipe_villa", mainModule.Koneksi)
Dim dt As New DataTable("tipe")
adapter.Fill(dt)
grid1.DataSource = dt
mainModule.Koneksi.close()
End Sub
Private Sub Hapus()
If Trim(textId.Text) = "" Then
textId.Text = "OTOMATIS"
End If
If Trim(textId.Text) <> "OTOMATIS" Then
strSQL = "delete from t_tipe_villa where id_tipe ='" & textId.Text & "'"
Dim command As New SqlCommand(strSQL, mainModule.Koneksi)
command.ExecuteNonQuery()
mainModule.Koneksi.close()
textId.Text = ""
textNama.Text = ""
MessageBox.Show("Data Sudah Dihapus", "Penghapusan Sukses", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
listdata()
kosongkan()
textNama.Focus()
Else
MessageBox.Show("Masukkan dulu data yang akan dihapus", _
"Tidak ada data yang akan dihapus", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
End If
End Sub
Private Sub simpan()
Dim ocommand As SqlCommand = New SqlCommand
If Trim(textId.Text) = "" Then
textId.Text = "OTOMATIS"
End If
If Trim(textNama.Text) = "" Then
MessageBox.Show("nama merk belum diisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
textNama.Focus()
Exit Sub
End If
If Trim(textId.Text) = "OTOMATIS" Then
strSQL = "Insert inti t_tipe_villa(nama_tipe) values ('" & textNama.Text & "')"
ocommand.Connection = mainModule.Koneksi
ocommand.CommandText = strSQL
ocommand.ExecuteNonQuery()
mainModule.Koneksi.close()
MessageBox.Show("Data sudah Disimpan", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Information)
textId.Text = ""
textNama.Text = ""
listdata()
kosongkan()
textNama.Focus()
Else
strSQL = "update t_tipe_villa set nama_tipe = '" & textNama.Text & "' " _
& "where id_tipe = " & textId.Text & " "
ocommand.Connection = mainModule.Koneksi
ocommand.CommandText = strSQL
ocommand.ExecuteNonQuery()
mainModule.Koneksi.close()
MessageBox.Show("Data Sudah Update", "perhatian", MessageBoxButtons.OK, MessageBoxIcon.Information)
textId.Text = ""
textNama.Text = ""
listdata()
kosongkan()
textNama.Focus()
End If
End Sub
Private Sub textId_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles textId.Validating
Dim ocommand As SqlCommand = New SqlCommand
If Trim(textId.Text) = "" Then
textId.Text = "OTOMATIS"
End If
If Trim(textId.Text) = "OTOMATIS" Then
textNama.Text = ""
Else
strSQL = "select nama_tipe from t_tipe_villa" _
& " where id_tipen = '" & textId.Text & "'"
ocommand.Connection = mainModule.Koneksi
ocommand.CommandText = strSQL
Dim xreader As SqlDataReader = ocommand.ExecuteReader
If xreader.HasRows = True Then
xreader.Read()
textNama.Text = xreader("nama_tipe")
Else
MessageBox.Show("maaf... data tipe dengan kode " _
& textId.Text & "tidak ditemukan,", _
"perhatian", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
e.Cancel = True
End If
xreader.Close()
mainModule.Koneksi.close()
End If
End Sub
Private Sub kosongkan()
textId.Text = "OTOMATIS"
textNama.Text = ""
End Sub
Private Sub grid1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grid1.CellClick
textId.Text = grid1.Item(0, grid1.CurrentRow.Index).Value.ToString
textNama.Text = grid1.Item(1, grid1.CurrentRow.Index).Value.ToString
End Sub
Private Sub tombolHapus_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles tombolHapus.Click
If MessageBox.Show("Hapus...?", "perhatian", _
MessageBoxButtons.YesNo, _
MessageBoxIcon.Question) _
= Windows.Forms.DialogResult.Yes Then
Hapus()
End If
End Sub
Private Sub tombolSimpan_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles tombolSimpan.Click
simpan()
End Sub
Private Sub tombolKeluar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles tombolKeluar.Click
Me.Dispose()
End Sub
Private Sub tombolNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles tombolNew.Click
kosongkan()
textNama.Focus()
End Sub
Private Sub formMasterTipe_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
kosongkan()
listdata()
End Sub
Private Sub splUtama_Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles splUtama.Panel1.Paint
End Sub
End Class
Coding untuk formUtama
Public Class formUtama
Private Sub menuTipe_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles menuTipe.Click
formMasterTipe.TopLevel = False
formMasterTipe.Parent = Me.splUtama.Panel2
formMasterTipe.Dock = DockStyle.Fill
formMasterTipe.Show()
End Sub
Private Sub menuKeluar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles menuKeluar.Click
End
End Sub
Private Sub menuKiri_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles menuKiri.DoubleClick
Select Case menuKiri.SelectedNode.Name
Case "kirikeluar"
End
Case "kiritipe'"
formMasterTipe.TopLevel = False
formMasterTipe.Parent = Me.splUtama.Panel2
formMasterTipe.Dock = DockStyle.Fill
formMasterTipe.Show()
End Select
End Sub
Private Sub menuKiri_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles menuKiri.AfterSelect
End Sub
Private Sub splUtama_Panel2_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles splUtama.Panel2.Paint
End Sub
End Class