0% found this document useful (0 votes)
22 views3 pages

Kode Oppo

ini adalah kode oppo silahkan dicek aja kwkwk

Uploaded by

Reforma Gustoni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views3 pages

Kode Oppo

ini adalah kode oppo silahkan dicek aja kwkwk

Uploaded by

Reforma Gustoni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Kode untuk module:

Imports System.Data.SqlClient
Module modKoneksi1
Public cn As New SqlConnection
Public cmd As New SqlCommand

Sub buka_database()
cn.ConnectionString = "Data Source=DESKTOP-RG04I2L\;Initial
Catalog=db_batubara;Integrated Security=True"
cn.Open()

If cn.State = ConnectionState.Open Then


MsgBox("Database terhubung")
End If
End Sub
End Module

Kode untuk form:

Imports System.Data.SqlClient
Public Class penjualan
Sub simpan_data()
cmd.Connection = cn
cmd.CommandText = "INSERT INTO tb_batubara_1 VALUES ('" & TextBox1.Text &
"','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" &
TextBox5.Text & "','" & TextBox8.Text & "','" & TextBox6.Text & "','" & ComboBox1.Text
& "')"
cmd.ExecuteNonQuery()
MessageBox.Show("Data Tersimpan")
End Sub
Sub tampil_data()
cmd.Connection = cn
cmd.CommandText = "SELECT * FROM tb_batubara_1"

Dim batubara As SqlDataReader = cmd.ExecuteReader


Dim data_batubara As New DataTable

data_batubara.Load(batubara)
dgvbarang.DataSource = data_batubara
End Sub
Sub ubah_data()
cmd.Connection = cn
cmd.CommandText = "Update tb_batubara_1 SET kode_batubara = '" & TextBox1.Text
& "', nama_customer='" & TextBox2.Text & "', alamat_lengkap='" & TextBox3.Text & "',
tanggal_pembelian='" & TextBox4.Text & "' WHERE kode_batubara='" & TextBox1.Text & "'"
cmd.ExecuteNonQuery()
MessageBox.Show("Data Berhasil diubah")
End Sub
Sub hapus_data()
cmd.Connection = cn
cmd.CommandText = "DELETE From tb_batubara_1 WHERE kode_batubara= '" &
TextBox1.Text & "'"
cmd.ExecuteNonQuery()
MessageBox.Show("Data berhasil dihapus")

End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
hapus_data()
tampil_data()

End Sub
Private Sub penjualan_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
buka_database()
tampil_data()
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text = "" Then
MsgBox("Data Tidak Boleh Kosong")
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
simpan_data()
tampil_data()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
ubah_data()
tampil_data()
End Sub

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim response As MsgBoxResult
response = MsgBox("Anda Yakin Ingin Keluar?",
MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Confirm")
If response = MsgBoxResult.Yes Then
Me.Dispose()
ElseIf response = MsgBoxResult.No Then
Exit Sub
End If

End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button5.Click
TextBox1.ResetText()
TextBox2.ResetText()
TextBox3.ResetText()
TextBox4.ResetText()
TextBox5.ResetText()
TextBox6.ResetText()
TextBox7.ResetText()
TextBox8.ResetText()
ComboBox1.ResetText()
End Sub
Private Sub dgvbarang_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles dgvbarang.DoubleClick
TextBox1.Text = dgvbarang.SelectedCells(0).Value
TextBox2.Text = dgvbarang.SelectedCells(1).Value
TextBox3.Text = dgvbarang.SelectedCells(2).Value
TextBox4.Text = dgvbarang.SelectedCells(3).Value
TextBox5.Text = dgvbarang.SelectedCells(4).Value
TextBox8.Text = dgvbarang.SelectedCells(5).Value

End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.Text = "Kalori Sangat Rendah" Then
TextBox6.Text = "186000"
ElseIf ComboBox1.Text = "Kalori Rendah" Then
TextBox6.Text = "372000"
ElseIf ComboBox1.Text = "Kalori Sedang" Then
TextBox6.Text = "558000"
ElseIf ComboBox1.Text = "Kalori Tinggi" Then
TextBox6.Text = "744000"
ElseIf ComboBox1.Text = "Kalori Sangat Tinggi" Then
TextBox6.Text = "930000"
End If
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button6.Click
TextBox8.Text = Val(TextBox5.Text) * Val(TextBox6.Text) * Val(TextBox7.Text)
End Sub
End Class

You might also like