Sei sulla pagina 1di 6

1.

Koneksi
Imports System.Data
Imports System.Data.OleDb
Module konek
Public conn As OleDbConnection
Public da As OleDbDataAdapter
Public ds As DataSet
Public Dt As DataTable
Public cmd As OleDbCommand
Public dr As OleDbDataReader

Public Sub koneksi()


Try
conn = New OleDbConnection("provider=microsoft.ace.oledb.12.0;
data source=skripsi.accdb")
conn.Open()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
End Module

2. Simpan dan edit


Call koneksi()
Call cari()
If Not dr.HasRows Then
Call koneksi()
Dim simpan As String = "insert into p1 values('" &
TextBox36.Text & "','" & txt1.Text & "', '" & txt5.Text & "','" &
txt9.Text & "','" & txt13.Text & "')"
cmd = New OleDbCommand(simpan, conn)
cmd.ExecuteNonQuery()
Else
Call koneksi()
Dim edit As String = "update p1 set Kebersihan='" &
txt1.Text & "',Ketertiban='" & txt5.Text & "',
Rumah_Percontohan_KetuaRT='" & txt9.Text & "',KetuaRT_Ramah='" &
txt13.Text & "' where nomor='" & TextBox36.Text & "'"
cmd = New OleDbCommand(edit, conn)
cmd.ExecuteNonQuery()
End If

1
3. Perhitungan
Dim jmlh1, jmlh2, jmlh3, jmlh4, t6 As String

t6 = (txt11.Text) / (txt15.Text)
txt12.Text = Round(Val(t6), 4)

jmlh1 = (Val(txt1.Text)) + ((txt2.Text)) + ((txt3.Text)) +


((txt4.Text))
jml1.Text = Round(Val(jmlh1), 4)

jmlh2 = (Val(txt5.Text)) + ((txt6.Text)) + ((txt7.Text)) +


((txt8.Text))
jml2.Text = Round(Val(jmlh2), 4)

jmlh3 = (Val(txt9.Text)) + ((txt10.Text)) + ((txt11.Text)) +


((txt12.Text))
jml3.Text = Round(Val(jmlh3), 4)

jmlh4 = (Val(txt13.Text)) + ((txt14.Text)) + ((txt15.Text)) +


((txt16.Text))
jml4.Text = Round(Val(jmlh4), 4)

Private Sub TextBox2_KeyPress(sender As Object, e As


KeyPressEventArgs) Handles TextBox2.KeyPress
On Error Resume Next
If e.KeyChar = Chr(13) Then
If TextBox2.Text > 90 Then
MsgBox("Maaf, Tidak dapat Proses")
ElseIf TextBox2.Text >= 81 Then
TextBox19.Text = "3"
TextBox3.Focus()
ElseIf TextBox2.Text >= 61 Then
TextBox19.Text = "2"
TextBox3.Focus()
ElseIf TextBox2.Text >= 30 Then
TextBox19.Text = "1"
TextBox3.Focus()
ElseIf TextBox2.Text < 30 Then
MsgBox("Maaf, Tidak dapat Proses")
End If
End If
End Sub

2
4. nomor otomatis
Sub otomatis2()

koneksi()
cmd = New OleDbCommand("select * from HFS order by nomor desc", conn)
dr = cmd.ExecuteReader
dr.Read()
If Not dr.HasRows Then
TextBox93.Text = "01"
Else
TextBox93.Text =
Val(Microsoft.VisualBasic.Mid(dr.Item("nomor").ToString, 4, 3)) + 1
If Len(TextBox93.Text) = 1 Then
TextBox93.Text = "0" & TextBox93.Text & ""

End If
End If

End Sub

5. Keypress
Private Sub TextBox1_KeyPress(sender As Object, e As
KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(13) Then
Call koneksi()
Call cari()
If dr.HasRows Then
Call ketemu()
MsgBox("Data sudah ada")
Else
Call tampilbaru()
End If
End If
End Sub

Sub cari()
cmd = New OleDbCommand("select * from alternatif where RT='" &
TextBox1.Text & "'", conn)
dr = cmd.ExecuteReader
dr.Read()
End Sub

Sub ketemu()
TextBox1.Text = dr.Item(0)
TextBox3.Text = dr.Item(1)

3
TextBox2.Text = dr.Item(2)
If dr.Item(3) = "Pria" Then
RadioButton1.Checked = True
Else
If dr.Item(3) = "Wanita" Then
RadioButton2.Checked = True
End If
End If
TextBox4.Text = dr.Item(4)
End Sub

Sub tampilbaru()
TextBox3.Text = ""
RadioButton1.Checked = False
RadioButton2.Checked = False
TextBox4.Text = ""
TextBox3.Focus()
End Sub

6. Tampilkangridview
Sub tampilgrid1()
da = New OleDbDataAdapter("select * from alternatif", conn)
ds = New DataSet
da.Fill(ds)
dgv1.DataSource = ds.Tables(0)
End Sub

7. hitung nilai keseluruhan database


Private Sub Button4_Click(sender As Object, e As EventArgs) Handles
Button4.Click
koneksi()
Dim dt As New DataTable

Dim da As New OleDbDataAdapter("select * from nilai_awal", conn)


da.Fill(dt)
For i = 0 To dt.Rows.Count - 1
Dim RT = dt.Rows(i).Item(0)
Dim keb = FormatNumber(Val(dt.Rows(i).Item(1) +
Val(dt.Rows(i).Item(2)) + Val(dt.Rows(i).Item(3)) + Val(dt.Rows(i).Item(4)) +
Val(dt.Rows(i).Item(5)) + Val(dt.Rows(i).Item(6))), 0)
Dim ket = FormatNumber(Val(dt.Rows(i).Item(7) +
Val(dt.Rows(i).Item(8)) + Val(dt.Rows(i).Item(9)) +
Val(dt.Rows(i).Item(10))), 0)

4
Dim rumah = FormatNumber(Val(dt.Rows(i).Item(11) +
Val(dt.Rows(i).Item(12)) + Val(dt.Rows(i).Item(13)) +
Val(dt.Rows(i).Item(14))), 0)
Dim ramah = FormatNumber(Val(dt.Rows(i).Item(15) +
Val(dt.Rows(i).Item(16)) + Val(dt.Rows(i).Item(17))), 0)

cmd = New OleDbCommand("Insert into proses values(' " & RT & "
',' " & keb & " ',' " & ket & " ',' " & rumah & " ',' " & ramah & " ')",
conn)
cmd.ExecuteNonQuery()

Next
Call tampilgrid()
End Sub

8. Hitung data ditext dgn datagridview


Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles
Button1.Click

koneksi()
Dim dt As New DataTable

Dim da As New OleDbDataAdapter("select * from proses", conn)


da.Fill(dt)
For i = 0 To dt.Rows.Count - 1
Dim RT = dt.Rows(i).Item(0)
Dim c1 = FormatNumber(Val(dt.Rows(i).Item(1) *
Val(TextBox2.Text)), 2)
Dim c2 = FormatNumber(Val(dt.Rows(i).Item(2) *
Val(TextBox3.Text)), 2)
Dim c3 = FormatNumber(Val(dt.Rows(i).Item(3) *
Val(TextBox4.Text)), 2)
Dim c4 = FormatNumber(Val(dt.Rows(i).Item(4) *
Val(TextBox5.Text)), 2)

cmd = New OleDbCommand("Insert into Hasil values(' " & RT & " ','
" & c1 & " ',' " & c2 & " ',' " & c3 & " ',' " & c4 & " ')", conn)
cmd.ExecuteNonQuery()
Next
Call tampilgrid()

End Sub

9. Diskon
Private Sub btn_hitung_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn_hitung.Click

5
Dim mdis As Double

j_barang.Text = Val(b_barang.Text) * Val(h_barang.Text)

If j_barang.Text > 20 Then

mdis = j_barang.Text * 0.1

Else

mdis = j_barang.Text * 0

End If

diskon.Text = mdis

bayar.Text = j_barang.Text - h_barang.Text

End Sub

Potrebbero piacerti anche