PROGRAM STUDI SISTEM INFORMASI

PRAKTIKUM PEMROGRAMAN DESKTOP
Mata Kuliah Kelas Hari, tanggal Waktu Semester/Tahun Sifat Dosen : : : : : : : Pemrograman Desktop Ole Jumat 90 menit Praktikum 1. Mochamad Subianto, S.Kom., M.Cs.,

1. Buat table dalam database dengan struktur sebagai berikut

2. Buat tampilan login seperti berikut

Universitas Ma Chung

Page 1 of 5

Prodi Sistem Informasi 2013

3. Buat tampilan menu seperti berikut

4. Buat Tampilan sebagai berikut

5. Gunakan sintax berikut pada form standard harga
Public Class StandardHarga Dim xadapter As New MySqlDataAdapter Dim xview As New DataView Dim xset As New DataSet Dim DataGridViewCellStyle2 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle Dim statusTx As Boolean Dim x As Integer = 0 Private Sub Standard_Harga_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ConnectionDatabase() refrestDataGrid() Universitas Ma Chung Page 2 of 5 Prodi Sistem Informasi 2013

clearText() End Sub Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click statusTx = True For Each xTextBox As Object In GroupBox4.Controls If TypeOf xTextBox Is TextBox Then If xTextBox.text = "" Then statusTx = False End If End If Next If statusTx.Equals(True) Then If btnSave.Text.Equals("Save") Then If MessageBox.Show("Anda yakin untuk Menyimpan data ", "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = Windows.Forms.DialogResult.OK Then Try xCommand = New MySqlCommand("INSERT INTO standard_harga (Range_Ukuran, Standard_Harga) " & _ "VALUES(" & tbRange_Ukuran.Text & ",'" & FormatCurrency(CDbl(tbStandard_Harga.Text)) & "')", xConnection) xCommand.ExecuteNonQuery() refrestDataGrid() DataGridSelected(tbRange_Ukuran.Text) clearText() tbRange_Ukuran.Select() tbRange_Ukuran.SelectAll() Catch ex As Exception MsgBox("Data sudah ada" & vbCrLf & "System tidak bisa memasukkan data RANGE UKURAN yang sama", MsgBoxStyle.Critical, "Worning") DataGridSelected(tbRange_Ukuran.Text) tbRange_Ukuran.Select() tbRange_Ukuran.SelectAll() End Try End If Else If MessageBox.Show("Anda yakin untuk Merubah data ", "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = Windows.Forms.DialogResult.OK Then xCommand = New MySqlCommand("UPDATE standard_harga set Standard_Harga='" & FormatCurrency(CDbl(tbStandard_Harga.Text)) & "' where Range_Ukuran=" & tbRange_Ukuran.Text, xConnection) xCommand.ExecuteNonQuery() refrestDataGrid() DataGridSelected(tbRange_Ukuran.Text) clearText() tbRange_Ukuran.Select() tbRange_Ukuran.SelectAll() End If End If End If End Sub Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click If MessageBox.Show("Anda yakin untuk DELETE data " + tbRange_Ukuran.Text, "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = Windows.Forms.DialogResult.OK Then xCommand = New MySqlCommand("Delete from standard_harga where Range_Ukuran=" & tbRange_Ukuran.Text, xConnection) Universitas Ma Chung Page 3 of 5 Prodi Sistem Informasi 2013

xCommand.ExecuteNonQuery() refrestDataGrid() clearText() End If End Sub Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click clearText() End Sub Private Sub tbRange_Ukuran_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tbRange_Ukuran.KeyUp If e.KeyData = Keys.Enter Then tbStandard_Harga.Select() tbStandard_Harga.SelectAll() End If End Sub Private Sub tbStandard_Harga_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tbStandard_Harga.KeyUp If e.KeyCode = Keys.Enter Then btnSave.Select() End If End Sub Private Sub tbStandard_Harga_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles tbStandard_Harga.Validated Try tbStandard_Harga.Text = FormatCurrency(CDbl(tbStandard_Harga.Text)) If tbRange_Ukuran.Text <> "" Then btnSave.Enabled = True btnDelete.Enabled = True Else tbRange_Ukuran.Select() tbRange_Ukuran.SelectAll() End If Catch ex As Exception tbStandard_Harga.Select() tbStandard_Harga.SelectAll() End Try End Sub Private Sub dgView_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgView.CellClick Try tbRange_Ukuran.Text = dgView.Item(0, e.RowIndex).Value tbStandard_Harga.Text = dgView.Item(1, e.RowIndex).Value tbStandard_Harga.Text = FormatCurrency(tbStandard_Harga.Text) btnSave.Text = "Update" tbRange_Ukuran.ReadOnly = True btnDelete.Enabled = True btnSave.Enabled = True btnDelete.Enabled = True Catch ex As Exception 'MsgBox(ex.Message) End Try End Sub Private Sub clearText() For Each xObject As Object In GroupBox1.Controls If TypeOf xObject Is TextBox Then xObject.text = "" Universitas Ma Chung Page 4 of 5 Prodi Sistem Informasi 2013

End If Next btnSave.Text = "Save" btnDelete.Enabled = False btnSave.Enabled = False btnDelete.Enabled = False tbRange_Ukuran.ReadOnly = False tbStandard_Harga.Text = 0 End Sub Private Sub DataGridSelected(ByVal key As String) x = 0 While dgView.Item(1, x).Value <> "" If dgView.Item(0, x).Value = key Then dgView.Rows(x).Selected = True dgView.CurrentCell = dgView.Rows(x).Cells(0) Else dgView.Rows(x).Selected = False End If x += 1 End While End Sub Private Sub refrestDataGrid() xset.Clear() xadapter = New MySqlDataAdapter("select * from standard_harga order by Range_ukuran", xConnection) xadapter.Fill(xset, "standard_harga") xview = xset.Tables("standard_harga").DefaultView dgView.DataSource = xview dgView.Columns.Item(0).Width = 55 dgView.Columns.Item(1).Width = 90 'dgView.Columns.Item(1).ValueType = Format.vbCurrency dgView.Columns.Item(0).HeaderText = "Range Ukuran" dgView.Columns.Item(1).HeaderText = "Standard Harga" DataGridViewCellStyle2.Alignment = DataGridViewContentAlignment.MiddleRight dgView.Columns.Item(0).DefaultCellStyle = DataGridViewCellStyle2 dgView.Columns.Item(1).DefaultCellStyle = DataGridViewCellStyle2 End Sub Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click Me.Close() End Sub

Universitas Ma Chung

Page 5 of 5

Prodi Sistem Informasi 2013

Sign up to vote on this title
UsefulNot useful